EntryProvider: Introduce readEntryFromPath()

Inheritance: Use readEntryFromPath instead of assuming always .desktop
files

Switch project to C++17
This commit is contained in:
Albert S. 2020-09-06 22:23:36 +02:00
parent 36b6390292
commit edb781580e
3 changed files with 33 additions and 19 deletions

View File

@ -83,8 +83,26 @@ EntryConfig EntryProvider::readFromDesktopFile(const QString &path)
return result; return result;
} }
/* qsrun own's config file */ std::optional<EntryConfig> EntryProvider::readEntryFromPath(const QString &path)
EntryConfig EntryProvider::readFromFile(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 result;
EntryConfig inheritedConfig; EntryConfig inheritedConfig;
@ -163,7 +181,11 @@ EntryConfig EntryProvider::readFromFile(const QString &path)
} }
if(key == "inherit") if(key == "inherit")
{ {
inheritedConfig = readFromDesktopFile(resolveEntryPath(splitted[1])); auto entry = readEntryFromPath(resolveEntryPath(splitted[1]));
if(entry)
{
inheritedConfig = *entry;
}
} }
} }
return result.update(inheritedConfig); return result.update(inheritedConfig);
@ -201,22 +223,12 @@ QVector<EntryConfig> EntryProvider::readConfig(QStringList paths)
while(it.hasNext()) while(it.hasNext())
{ {
QString path = it.next(); QString path = it.next();
QFileInfo info(path); std::optional<EntryConfig> entry = readEntryFromPath(path);
if(info.isFile()) if(entry)
{ {
QString suffix = info.suffix(); if(!entry->hidden)
EntryConfig entry;
if(suffix == "desktop")
{ {
entry = readFromDesktopFile(path); result.append(*entry);
}
if(suffix == "qsrun")
{
entry = readFromFile(path);
}
if(!entry.hidden && entry.name != "")
{
result.append(entry);
} }
} }
} }

View File

@ -2,6 +2,7 @@
#define ENTRYPROVIDER_H #define ENTRYPROVIDER_H
#include <QIcon> #include <QIcon>
#include <QSettings> #include <QSettings>
#include <optional>
class ConfigFormatException : public std::runtime_error class ConfigFormatException : public std::runtime_error
{ {
@ -35,8 +36,9 @@ class EntryProvider
QStringList _desktopIgnoreArgs; QStringList _desktopIgnoreArgs;
QStringList userEntriesDirsPaths; QStringList userEntriesDirsPaths;
QStringList systemEntriesDirsPaths; QStringList systemEntriesDirsPaths;
EntryConfig readFromFile(const QString &path); EntryConfig readqsrunFile(const QString &path);
EntryConfig readFromDesktopFile(const QString &path); EntryConfig readFromDesktopFile(const QString &path);
std::optional<EntryConfig> readEntryFromPath(const QString &path);
QVector<EntryConfig> readConfig(QStringList paths); QVector<EntryConfig> readConfig(QStringList paths);
QString resolveEntryPath(QString path); QString resolveEntryPath(QString path);

View File

@ -23,5 +23,5 @@ SOURCES += calculationengine.cpp \
QT += widgets sql network QT += widgets sql network
QT_CONFIG -= no-pkg-config QT_CONFIG -= no-pkg-config
LIBS += -lcln LIBS += -lcln
CONFIG += link_pkgconfig CONFIG += link_pkgconfig c++17
PKGCONFIG += libqalculate PKGCONFIG += libqalculate