EntryProvider: readqsrunfile(): Simplify by using QHash

This commit is contained in:
Albert S. 2020-10-04 15:46:03 +02:00
parent 2d79d74e06
commit 2acfe6126a

View File

@ -112,19 +112,31 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
// TODO: better exception class
throw new std::runtime_error("Failed to open file");
}
QHash<QString, QString> map;
QTextStream stream(&file);
while(!stream.atEnd())
{
QString line = stream.readLine();
QStringList splitted = line.split(" ");
if(splitted.length() < 2)
int spacePos = line.indexOf(' ');
if(spacePos == -1)
{
throw new ConfigFormatException("misformated line in .qsrun config file " + path.toStdString());
}
QString key = splitted[0];
if(key == "arguments")
QString key = line.mid(0, spacePos);
QString value = line.mid(spacePos+1);
QStringList splitted = line.split(" ");
if(key == "" || value == "")
{
auto args = splitted.mid(1);
throw new ConfigFormatException("empty key or value in .qsrun config file " + path.toStdString());
}
map[key] = value;
}
if(map.contains("arguments"))
{
auto args = map["arguments"].split(' ');
QString merged;
for(QString &str : args)
{
@ -153,42 +165,22 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
throw ConfigFormatException("non-closed \" in config file " + path.toStdString());
}
}
if(key == "name")
if(map.contains("inherit"))
{
result.name = splitted.mid(1).join(' ');
}
if(key == "icon")
{
result.iconPath = splitted[1];
}
if(key == "row")
{
result.row = splitted[1].toInt();
}
if(key == "col")
{
result.col = splitted[1].toInt();
}
if(key == "command")
{
result.command = splitted[1];
}
if(key == "key")
{
// QKeySequence sequence(splitted[1]);
// result.keySequence = sequence;
result.key = splitted[1].toLower();
}
if(key == "inherit")
{
result.inherit = splitted[1];
result.inherit = map["inherit"];
auto entry = readEntryFromPath(resolveEntryPath(result.inherit));
if(entry)
{
inheritedConfig = *entry;
}
}
}
result.key = map["key"].toLower();
result.command = map["command"];
result.col = map["col"].toInt();
result.row = map["row"].toInt();
result.iconPath = map["icon"];
result.name = map["name"];
return result.update(inheritedConfig);
}