DtkCore
DTK Core module
ddesktopentry.h
1/*
2 * Copyright (C) 2019 Deepin Technology Co., Ltd.
3 * 2019 Gary Wang
4 *
5 * Author: Gary Wang <[email protected]>
6 *
7 * Maintainer: Gary Wang <[email protected]>
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#pragma once
24
25#include <dtkcore_global.h>
26
27#include <QIODevice>
28#include <QObject>
29#include <QVariant>
30
31DCORE_BEGIN_NAMESPACE
32
33class DDesktopEntryPrivate;
34class LIBDTKCORESHARED_EXPORT DDesktopEntry
35{
36 Q_GADGET
37public:
38 enum EntryType {
39 Unknown = 0,
45 FSDevice
46 };
47 Q_ENUM(EntryType)
48
49 enum ValueType {
50 Unparsed = 0, // Maybe useless, consider remove it?
51 String,
52 Strings,
53 Boolean,
54 Numeric,
55 NotExisted = 99
56 };
57 Q_ENUM(ValueType)
58
59 enum Status {
60 NoError = 0,
62 FormatError
63 };
64 Q_ENUM(Status)
65
66 explicit DDesktopEntry(const QString &filePath) noexcept;
68
69 bool save() const;
70
71 Status status() const;
72 QStringList keys(const QString &section = "Desktop Entry") const;
73 QStringList allGroups(bool sorted = false) const;
74
75 bool contains(const QString &key, const QString &section = "Desktop Entry") const;
76
77 QString name() const;
78 QString genericName() const;
79 QString ddeDisplayName() const;
80 QString comment() const;
81
82 QString rawValue(const QString &key, const QString &section = "Desktop Entry",
83 const QString &defaultValue = QString()) const;
84 QString stringValue(const QString &key, const QString &section = "Desktop Entry",
85 const QString &defaultValue = QString()) const;
86 QString localizedValue(const QString &key, const QString &localeKey = "default",
87 const QString &section = "Desktop Entry", const QString& defaultValue = QString()) const;
88 QString localizedValue(const QString &key, const QLocale &locale,
89 const QString &section = "Desktop Entry", const QString& defaultValue = QString()) const;
90 QStringList stringListValue(const QString &key, const QString &section = "Desktop Entry") const;
91
92 bool setRawValue(const QString &value, const QString &key, const QString& section = "Desktop Entry");
93 bool setStringValue(const QString &value, const QString &key, const QString& section = "Desktop Entry");
94 bool setLocalizedValue(const QString &value, const QString& localeKey,
95 const QString &key, const QString& section = "Desktop Entry");
96
97 bool removeEntry(const QString &key, const QString &section = "Desktop Entry");
98
99 static QString &escape(QString &str);
100 static QString &escapeExec(QString &str);
101 static QString &unescape(QString &str, bool unescapeSemicolons = false);
102 static QString &unescapeExec(QString &str);
103
104protected:
105 bool setStatus(const Status &status);
106
107private:
108 QScopedPointer<DDesktopEntryPrivate> d_ptr;
109
110 Q_DECLARE_PRIVATE(DDesktopEntry)
111};
112
113DCORE_END_NAMESPACE
Handling desktop entry files.
Definition: ddesktopentry.h:35
Status
Definition: ddesktopentry.h:59
@ AccessError
An access error occurred (e.g. trying to write to a read-only file).
Definition: ddesktopentry.h:61
EntryType
Definition: ddesktopentry.h:38
@ Service
KDE specific type. mentioned in the spec, so listed here too.
Definition: ddesktopentry.h:44
@ Application
The file describes application.
Definition: ddesktopentry.h:40
@ ServiceType
KDE specific type. mentioned in the spec, so listed here too.
Definition: ddesktopentry.h:43
@ Directory
The file describes directory settings.
Definition: ddesktopentry.h:42
@ Link
The file describes URL.
Definition: ddesktopentry.h:41