ConfigReader: support multiple dirs
This commit is contained in:
förälder
3970019fac
incheckning
8484e88a27
33
config.cpp
33
config.cpp
@ -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;
|
||||
|
4
config.h
4
config.h
@ -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();
|
||||
};
|
||||
|
||||
|
23
main.cpp
23
main.cpp
@ -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)
|
||||
{
|
||||
|
Laddar…
Referens i nytt ärende
Block a user