EntryProvider: Introduce readEntryFromPath()
Inheritance: Use readEntryFromPath instead of assuming always .desktop files Switch project to C++17
This commit is contained in:
rodzic
36b6390292
commit
edb781580e
@ -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<EntryConfig> 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<EntryConfig> EntryProvider::readConfig(QStringList paths)
|
||||
while(it.hasNext())
|
||||
{
|
||||
QString path = it.next();
|
||||
QFileInfo info(path);
|
||||
if(info.isFile())
|
||||
std::optional<EntryConfig> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define ENTRYPROVIDER_H
|
||||
#include <QIcon>
|
||||
#include <QSettings>
|
||||
#include <optional>
|
||||
|
||||
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<EntryConfig> readEntryFromPath(const QString &path);
|
||||
QVector<EntryConfig> readConfig(QStringList paths);
|
||||
QString resolveEntryPath(QString path);
|
||||
|
||||
|
@ -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
|
||||
|
Ładowanie…
Reference in New Issue
Block a user