EntryProvider: readqsrunfile(): Simplify by using QHash
Dieser Commit ist enthalten in:
Ursprung
2d79d74e06
Commit
2acfe6126a
@ -112,19 +112,31 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
|
|||||||
// TODO: better exception class
|
// TODO: better exception class
|
||||||
throw new std::runtime_error("Failed to open file");
|
throw new std::runtime_error("Failed to open file");
|
||||||
}
|
}
|
||||||
|
QHash<QString, QString> map;
|
||||||
QTextStream stream(&file);
|
QTextStream stream(&file);
|
||||||
while(!stream.atEnd())
|
while(!stream.atEnd())
|
||||||
{
|
{
|
||||||
QString line = stream.readLine();
|
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());
|
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;
|
QString merged;
|
||||||
for(QString &str : args)
|
for(QString &str : args)
|
||||||
{
|
{
|
||||||
@ -153,42 +165,22 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
|
|||||||
throw ConfigFormatException("non-closed \" in config file " + path.toStdString());
|
throw ConfigFormatException("non-closed \" in config file " + path.toStdString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(key == "name")
|
if(map.contains("inherit"))
|
||||||
{
|
{
|
||||||
result.name = splitted.mid(1).join(' ');
|
result.inherit = map["inherit"];
|
||||||
}
|
|
||||||
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];
|
|
||||||
auto entry = readEntryFromPath(resolveEntryPath(result.inherit));
|
auto entry = readEntryFromPath(resolveEntryPath(result.inherit));
|
||||||
if(entry)
|
if(entry)
|
||||||
{
|
{
|
||||||
inheritedConfig = *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);
|
return result.update(inheritedConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren