Debian Codegraph @

include/global/ddesktopentry.h

raw
1 // SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
2 //
3 // SPDX-License-Identifier: LGPL-3.0-or-later
4
5 #pragma once
6
7 #include "dtkcore_global.h"
8
9 #include <QIODevice>
10 #include <QObject>
11 #include <QVariant>
12
13 DCORE_BEGIN_NAMESPACE
14
15 class DDesktopEntryPrivate;
16 class LIBDTKCORESHARED_EXPORT DDesktopEntry
17 {
18 Q_GADGET
19 public:
20 enum EntryType {
21 Unknown = 0, //!<@~english Unknown desktop file type. Maybe is invalid.
22 Application, //!<@~english The file describes application.
23 Link, //!<@~english The file describes URL.
24 Directory, //!<@~english The file describes directory settings.
25 ServiceType, //!<@~english KDE specific type. mentioned in the spec, so listed here too.
26 Service, //!<@~english KDE specific type. mentioned in the spec, so listed here too.
27 FSDevice //!<@~english KDE specific type. mentioned in the spec, so listed here too.
28 };
29 Q_ENUM(EntryType)
30
31 enum ValueType {
32 Unparsed = 0, // Maybe useless, consider remove it?
33 String,
34 Strings,
35 Boolean,
36 Numeric,
37 NotExisted = 99
38 };
39 Q_ENUM(ValueType)
40
41 enum Status {
42 NoError = 0, //!<@~english No error occurred.
43 AccessError, //!<@~english An access error occurred (e.g. trying to write to a read-only file).
44 FormatError //!<@~english A format error occurred (e.g. loading a malformed desktop entry file).
45 };
46 Q_ENUM(Status)
47
48 explicit DDesktopEntry(const QString &filePath) noexcept;
49 ~DDesktopEntry();
50
51 bool save() const;
52
53 Status status() const;
54 QStringList keys(const QString &section = "Desktop Entry") const;
55 QStringList allGroups(bool sorted = false) const;
56
57 bool contains(const QString &key, const QString &section = "Desktop Entry") const;
58
59 QString name() const;
60 QString genericName() const;
61 QString ddeDisplayName() const;
62 QString comment() const;
63
64 QString rawValue(const QString &key, const QString &section = "Desktop Entry",
65 const QString &defaultValue = QString()) const;
66 QString stringValue(const QString &key, const QString &section = "Desktop Entry",
67 const QString &defaultValue = QString()) const;
68 QString localizedValue(const QString &key, const QString &localeKey = "default",
69 const QString &section = "Desktop Entry", const QString& defaultValue = QString()) const;
70 QString localizedValue(const QString &key, const QLocale &locale,
71 const QString &section = "Desktop Entry", const QString& defaultValue = QString()) const;
72 QStringList stringListValue(const QString &key, const QString &section = "Desktop Entry") const;
73
74 bool setRawValue(const QString &value, const QString &key, const QString& section = "Desktop Entry");
75 bool setStringValue(const QString &value, const QString &key, const QString& section = "Desktop Entry");
76 bool setLocalizedValue(const QString &value, const QString& localeKey,
77 const QString &key, const QString& section = "Desktop Entry");
78
79 bool removeEntry(const QString &key, const QString &section = "Desktop Entry");
80
81 static QString &escape(QString &str);
82 static QString &escapeExec(QString &str);
83 static QString &unescape(QString &str, bool unescapeSemicolons = false);
84 static QString &unescapeExec(QString &str);
85
86 protected:
87 bool setStatus(const Status &status);
88
89 private:
90 QScopedPointer<DDesktopEntryPrivate> d_ptr;
91
92 Q_DECLARE_PRIVATE(DDesktopEntry)
93 };
94
95 DCORE_END_NAMESPACE