Compare commits

..

2 Commits

Author SHA1 Message Date
edb781580e EntryProvider: Introduce readEntryFromPath()
Inheritance: Use readEntryFromPath instead of assuming always .desktop
files

Switch project to C++17
2020-09-06 22:24:39 +02:00
36b6390292 Implement NoDisplay= of .desktop entries
Closes #9
2020-09-06 22:09:02 +02:00
3 changed files with 38 additions and 14 deletions

View File

@ -75,12 +75,34 @@ EntryConfig EntryProvider::readFromDesktopFile(const QString &path)
} }
} }
} }
if(key == "nodisplay")
{
result.hidden = args == "true";
}
} }
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;
@ -159,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);
@ -197,17 +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)
if(suffix == "desktop")
{ {
result.append(readFromDesktopFile(path)); result.append(*entry);
}
if(suffix == "qsrun")
{
result.append(readFromFile(path));
} }
} }
} }

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
{ {
@ -17,6 +18,7 @@ class ConfigFormatException : public std::runtime_error
class EntryConfig class EntryConfig
{ {
public: public:
bool hidden = false;
QString key; QString key;
QString name; QString name;
QString command; QString command;
@ -34,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