ConfigReader: support multiple dirs
This commit is contained in:
		
							
								
								
									
										11
									
								
								config.cpp
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								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,7 +154,9 @@ EntryConfig ConfigReader::readFromFile(const QString &path)
 | 
			
		||||
QVector<EntryConfig> ConfigReader::readConfig()
 | 
			
		||||
{
 | 
			
		||||
	QVector<EntryConfig> result;
 | 
			
		||||
	QDirIterator it(this->configDirectory);
 | 
			
		||||
	for(QString &configPath : configPaths)
 | 
			
		||||
	{
 | 
			
		||||
		QDirIterator it(configPath);
 | 
			
		||||
		while(it.hasNext())
 | 
			
		||||
		{
 | 
			
		||||
			QString path = it.next();
 | 
			
		||||
@@ -173,5 +176,7 @@ QVector<EntryConfig> ConfigReader::readConfig()
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	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)
 | 
			
		||||
		{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user