diff --git a/entryprovider.cpp b/entryprovider.cpp index da97b16..4335db0 100644 --- a/entryprovider.cpp +++ b/entryprovider.cpp @@ -83,8 +83,26 @@ EntryConfig EntryProvider::readFromDesktopFile(const QString &path) return result; } -/* qsrun own's config file */ -EntryConfig EntryProvider::readFromFile(const QString &path) +std::optional EntryProvider::readEntryFromPath(const QString &path) +{ + QFileInfo info(path); + if(info.isFile()) + { + QString suffix = info.suffix(); + if(suffix == "desktop") + { + return readFromDesktopFile(path); + } + if(suffix == "qsrun") + { + return readqsrunFile(path); + } + } + return {}; +} + +/* qsrun's own format */ +EntryConfig EntryProvider::readqsrunFile(const QString &path) { EntryConfig result; EntryConfig inheritedConfig; @@ -163,7 +181,11 @@ EntryConfig EntryProvider::readFromFile(const QString &path) } if(key == "inherit") { - inheritedConfig = readFromDesktopFile(resolveEntryPath(splitted[1])); + auto entry = readEntryFromPath(resolveEntryPath(splitted[1])); + if(entry) + { + inheritedConfig = *entry; + } } } return result.update(inheritedConfig); @@ -201,22 +223,12 @@ QVector EntryProvider::readConfig(QStringList paths) while(it.hasNext()) { QString path = it.next(); - QFileInfo info(path); - if(info.isFile()) + std::optional entry = readEntryFromPath(path); + if(entry) { - QString suffix = info.suffix(); - EntryConfig entry; - if(suffix == "desktop") + if(!entry->hidden) { - entry = readFromDesktopFile(path); - } - if(suffix == "qsrun") - { - entry = readFromFile(path); - } - if(!entry.hidden && entry.name != "") - { - result.append(entry); + result.append(*entry); } } } diff --git a/entryprovider.h b/entryprovider.h index 49f35bb..4184ba4 100644 --- a/entryprovider.h +++ b/entryprovider.h @@ -2,6 +2,7 @@ #define ENTRYPROVIDER_H #include #include +#include class ConfigFormatException : public std::runtime_error { @@ -35,8 +36,9 @@ class EntryProvider QStringList _desktopIgnoreArgs; QStringList userEntriesDirsPaths; QStringList systemEntriesDirsPaths; - EntryConfig readFromFile(const QString &path); + EntryConfig readqsrunFile(const QString &path); EntryConfig readFromDesktopFile(const QString &path); + std::optional readEntryFromPath(const QString &path); QVector readConfig(QStringList paths); QString resolveEntryPath(QString path); diff --git a/qsrun.pro b/qsrun.pro index 23923a8..8ed264f 100644 --- a/qsrun.pro +++ b/qsrun.pro @@ -23,5 +23,5 @@ SOURCES += calculationengine.cpp \ QT += widgets sql network QT_CONFIG -= no-pkg-config LIBS += -lcln -CONFIG += link_pkgconfig +CONFIG += link_pkgconfig c++17 PKGCONFIG += libqalculate