ConfigReader: support multiple dirs

Šī revīzija ir iekļauta:
Albert S. 2019-05-30 10:57:33 +02:00
vecāks 3970019fac
revīzija 8484e88a27
3 mainīti faili ar 25 papildinājumiem un 35 dzēšanām

Parādīt failu

@ -18,9 +18,10 @@
#include <QDebug>
#include <QTextStream>
ConfigReader::ConfigReader(QString directory)
ConfigReader::ConfigReader(QStringList paths)
{
this->configDirectory = directory;
this->configPaths = paths;
desktopIgnoreArgs << "%F" << "%f" << "%U" << "%u";
}
@ -153,24 +154,28 @@ EntryConfig ConfigReader::readFromFile(const QString &path)
QVector<EntryConfig> ConfigReader::readConfig()
{
QVector<EntryConfig> result;
QDirIterator it(this->configDirectory);
while(it.hasNext())
for(QString &configPath : configPaths)
{
QString path = it.next();
QFileInfo info(path);
if(info.isFile())
QDirIterator it(configPath);
while(it.hasNext())
{
QString suffix = info.completeSuffix();
if(suffix == "desktop")
QString path = it.next();
QFileInfo info(path);
if(info.isFile())
{
result.append(readFromDesktopFile(path));
QString suffix = info.completeSuffix();
if(suffix == "desktop")
{
result.append(readFromDesktopFile(path));
}
if(suffix == "qsrun")
{
result.append(readFromFile(path));
}
if(suffix == "qsrun")
{
result.append(readFromFile(path));
}
}
}
}
return result;

Parādīt failu

@ -40,12 +40,12 @@ class EntryConfig
class ConfigReader
{
private:
QString configDirectory;
QStringList configPaths;
EntryConfig readFromFile(const QString &path);
EntryConfig readFromDesktopFile(const QString &path);
QStringList desktopIgnoreArgs;
public:
ConfigReader(QString path);
ConfigReader(QStringList paths);
QVector<EntryConfig> readConfig();
};

Parādīt failu

@ -37,20 +37,18 @@ int main(int argc, char *argv[])
}
qRegisterMetaType<QVector<QString> >("QVector<QString>");
QDir dir(configDirectoryPath);
QDir dir;
if(!dir.exists(configDirectoryPath))
{
QMessageBox::warning(nullptr, "Directory not found", configDirectoryPath + " was not found!");
return 1;
}
QSettings settings(configDirectoryPath + "qsrun.config", QSettings::NativeFormat);
QString systemApplicationsPath = settings.value("General/systemApplicationsPath", "/usr/share/applications/").toString();
QVector<EntryConfig> configs;
try
{
ConfigReader reader(configDirectoryPath);
ConfigReader reader({configDirectoryPath});
configs = reader.readConfig();
}
catch(std::exception &e)
@ -59,23 +57,10 @@ int main(int argc, char *argv[])
}
Window w(configs);
/*
* TODO: Reconsider the need
* QFuture<void> future = QtConcurrent::run([&w] {
ConfigReader systemConfigReader("/usr/share/applications/");
QList<EntryConfig> systemconfigs = systemConfigReader.readConfig();
if(systemconfigs.count() > 0)
{
w.setSystemConfig(systemconfigs);
w.systemConfigReady();
}
});*/
try
{
ConfigReader systemConfigReader(systemApplicationsPath);
QStringList systemApplicationsPaths = settings.value("sysAppsPaths", "/usr/share/applications/").toStringList();
ConfigReader systemConfigReader(systemApplicationsPaths);
QVector<EntryConfig> systemconfigs = systemConfigReader.readConfig();
if(systemconfigs.count() > 0)
{