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