Albert S
79d15fb628
Introduce EntryType, allowing to distnguish between: - inherietd entries: Those inherit their values from other entries, typcally system entries. They do not allow overwriting the value, except row/col. - system entries: those not created by the user in any way, usually .desktop files in /usr/share/applications/... - user entries: those that have been created by the user. they can however also inherit, and overwrite inherited values. inherited are used for the "favourites" feature.
64 linhas
1.4 KiB
C++
64 linhas
1.4 KiB
C++
#ifndef ENTRYPROVIDER_H
|
|
#define ENTRYPROVIDER_H
|
|
#include <QIcon>
|
|
#include <QSettings>
|
|
#include <optional>
|
|
|
|
class ConfigFormatException : public std::runtime_error
|
|
{
|
|
public:
|
|
ConfigFormatException() : std::runtime_error("Error in configuration file, misformated line?")
|
|
{
|
|
}
|
|
ConfigFormatException(const std::string &str) : std::runtime_error(str)
|
|
{
|
|
}
|
|
};
|
|
|
|
enum EntryType
|
|
{
|
|
USER,
|
|
INHERIT,
|
|
SYSTEM
|
|
};
|
|
|
|
class EntryConfig
|
|
{
|
|
public:
|
|
EntryType type = SYSTEM;
|
|
bool hidden = false;
|
|
QString entryPath;
|
|
QString key;
|
|
QString name;
|
|
QString command;
|
|
QString iconPath;
|
|
QStringList arguments;
|
|
QString inherit;
|
|
int row = 0;
|
|
int col = 0;
|
|
|
|
EntryConfig &update(const EntryConfig &o);
|
|
};
|
|
|
|
class EntryProvider
|
|
{
|
|
protected:
|
|
QStringList _desktopIgnoreArgs;
|
|
QStringList userEntriesDirsPaths;
|
|
QStringList systemEntriesDirsPaths;
|
|
EntryConfig readqsrunFile(const QString &path);
|
|
EntryConfig readFromDesktopFile(const QString &path);
|
|
std::optional<EntryConfig> readEntryFromPath(const QString &path);
|
|
QVector<EntryConfig> readConfig(QStringList paths);
|
|
QString resolveEntryPath(QString path);
|
|
|
|
public:
|
|
EntryProvider(QStringList userEntriesDirsPaths, QStringList systemEntriesDirsPaths);
|
|
QVector<EntryConfig> getUserEntries();
|
|
QVector<EntryConfig> getSystemEntries();
|
|
void saveUserEntry(const EntryConfig &config);
|
|
bool deleteUserEntry(const EntryConfig &config);
|
|
};
|
|
|
|
#endif // ENTRYPROVIDER_H
|