|
|
|
@ -80,6 +80,7 @@ EntryConfig EntryProvider::readFromDesktopFile(const QString &path)
|
|
|
|
|
result.hidden = args == "true";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result.type = EntryType::SYSTEM;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -125,15 +126,15 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString key = line.mid(0, spacePos);
|
|
|
|
|
QString value = line.mid(spacePos+1);
|
|
|
|
|
QString value = line.mid(spacePos + 1);
|
|
|
|
|
|
|
|
|
|
QStringList splitted = line.split(" ");
|
|
|
|
|
if(key == "" || value == "")
|
|
|
|
|
{
|
|
|
|
|
throw new ConfigFormatException("empty key or value in .qsrun config file " + path.toStdString());
|
|
|
|
|
}
|
|
|
|
|
map[key] = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(map.contains("inherit"))
|
|
|
|
|
{
|
|
|
|
|
auto entry = readEntryFromPath(map["inherit"]);
|
|
|
|
@ -147,47 +148,75 @@ EntryConfig EntryProvider::readqsrunFile(const QString &path)
|
|
|
|
|
throw new ConfigFormatException("Error attempting to read inherited entry");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(map.contains("arguments"))
|
|
|
|
|
QString type = map["type"];
|
|
|
|
|
if(!type.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
auto args = map["arguments"].split(' ');
|
|
|
|
|
QString merged;
|
|
|
|
|
for(QString &str : args)
|
|
|
|
|
if(type == "system")
|
|
|
|
|
{
|
|
|
|
|
if(str.startsWith('"') && !str.endsWith("'"))
|
|
|
|
|
{
|
|
|
|
|
merged += str.mid(1) + " ";
|
|
|
|
|
}
|
|
|
|
|
else if(str.endsWith('"'))
|
|
|
|
|
{
|
|
|
|
|
str.chop(1);
|
|
|
|
|
merged += str;
|
|
|
|
|
result.arguments.append(merged);
|
|
|
|
|
merged = "";
|
|
|
|
|
}
|
|
|
|
|
else if(merged != "")
|
|
|
|
|
{
|
|
|
|
|
merged += str + " ";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.arguments.append(str);
|
|
|
|
|
}
|
|
|
|
|
throw new ConfigFormatException(".qsrun files cannot be designated as system entries " +
|
|
|
|
|
path.toStdString());
|
|
|
|
|
}
|
|
|
|
|
if(merged != "")
|
|
|
|
|
else if(type == "inherit")
|
|
|
|
|
{
|
|
|
|
|
throw ConfigFormatException("non-closed \" in config file " + path.toStdString());
|
|
|
|
|
result.type = EntryType::INHERIT;
|
|
|
|
|
}
|
|
|
|
|
else if(type == "user")
|
|
|
|
|
{
|
|
|
|
|
result.type = EntryType::USER;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new ConfigFormatException("Invalid value for type provided in file: " + path.toStdString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
auto assignIfSourceNotEmpty = [](QString source, QString &val) {
|
|
|
|
|
if(!source.isEmpty())
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.type = EntryType::USER;
|
|
|
|
|
}
|
|
|
|
|
if(result.type != EntryType::INHERIT)
|
|
|
|
|
{
|
|
|
|
|
if(map.contains("arguments"))
|
|
|
|
|
{
|
|
|
|
|
val = source;
|
|
|
|
|
auto args = map["arguments"].split(' ');
|
|
|
|
|
QString merged;
|
|
|
|
|
for(QString &str : args)
|
|
|
|
|
{
|
|
|
|
|
if(str.startsWith('"') && !str.endsWith("'"))
|
|
|
|
|
{
|
|
|
|
|
merged += str.mid(1) + " ";
|
|
|
|
|
}
|
|
|
|
|
else if(str.endsWith('"'))
|
|
|
|
|
{
|
|
|
|
|
str.chop(1);
|
|
|
|
|
merged += str;
|
|
|
|
|
result.arguments.append(merged);
|
|
|
|
|
merged = "";
|
|
|
|
|
}
|
|
|
|
|
else if(merged != "")
|
|
|
|
|
{
|
|
|
|
|
merged += str + " ";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.arguments.append(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(merged != "")
|
|
|
|
|
{
|
|
|
|
|
throw ConfigFormatException("non-closed \" in config file " + path.toStdString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
assignIfSourceNotEmpty(map["key"].toLower(), result.key);
|
|
|
|
|
assignIfSourceNotEmpty(map["command"], result.command);
|
|
|
|
|
assignIfSourceNotEmpty(map["icon"], result.iconPath);
|
|
|
|
|
assignIfSourceNotEmpty(map["name"], result.name);
|
|
|
|
|
auto assignIfSourceNotEmpty = [](QString source, QString &val) {
|
|
|
|
|
if(!source.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
val = source;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
assignIfSourceNotEmpty(map["key"].toLower(), result.key);
|
|
|
|
|
assignIfSourceNotEmpty(map["command"], result.command);
|
|
|
|
|
assignIfSourceNotEmpty(map["icon"], result.iconPath);
|
|
|
|
|
assignIfSourceNotEmpty(map["name"], result.name);
|
|
|
|
|
}
|
|
|
|
|
result.col = map["col"].toInt();
|
|
|
|
|
result.row = map["row"].toInt();
|
|
|
|
|
return result;
|
|
|
|
@ -216,7 +245,7 @@ QString EntryProvider::resolveEntryPath(QString path)
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVector<EntryConfig> EntryProvider::readConfig(QStringList paths, bool userentrymode)
|
|
|
|
|
QVector<EntryConfig> EntryProvider::readConfig(QStringList paths)
|
|
|
|
|
{
|
|
|
|
|
QVector<EntryConfig> result;
|
|
|
|
|
for(QString &configPath : paths)
|
|
|
|
@ -230,10 +259,6 @@ QVector<EntryConfig> EntryProvider::readConfig(QStringList paths, bool userentry
|
|
|
|
|
{
|
|
|
|
|
if(!entry->hidden)
|
|
|
|
|
{
|
|
|
|
|
if(userentrymode)
|
|
|
|
|
{
|
|
|
|
|
entry->userEntry = true;
|
|
|
|
|
}
|
|
|
|
|
entry->entryPath = path;
|
|
|
|
|
result.append(*entry);
|
|
|
|
|
}
|
|
|
|
@ -245,7 +270,7 @@ QVector<EntryConfig> EntryProvider::readConfig(QStringList paths, bool userentry
|
|
|
|
|
|
|
|
|
|
QVector<EntryConfig> EntryProvider::getUserEntries()
|
|
|
|
|
{
|
|
|
|
|
return readConfig(this->userEntriesDirsPaths, true);
|
|
|
|
|
return readConfig(this->userEntriesDirsPaths);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVector<EntryConfig> EntryProvider::getSystemEntries()
|
|
|
|
@ -255,9 +280,9 @@ QVector<EntryConfig> EntryProvider::getSystemEntries()
|
|
|
|
|
|
|
|
|
|
void EntryProvider::saveUserEntry(const EntryConfig &config)
|
|
|
|
|
{
|
|
|
|
|
if(!config.userEntry || config.entryPath.isEmpty())
|
|
|
|
|
if(config.type == EntryType::SYSTEM || config.entryPath.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error("Only user entries can be saved");
|
|
|
|
|
throw std::runtime_error("Only user/inherited entries can be saved");
|
|
|
|
|
}
|
|
|
|
|
QString transitPath = config.entryPath + ".transit";
|
|
|
|
|
QFile file{transitPath};
|
|
|
|
@ -266,24 +291,29 @@ void EntryProvider::saveUserEntry(const EntryConfig &config)
|
|
|
|
|
throw std::runtime_error("Error: Can not open file for writing");
|
|
|
|
|
}
|
|
|
|
|
QTextStream outStream(&file);
|
|
|
|
|
outStream << "type" << " " << ((config.type == EntryType::USER) ? "user" : "inherit") << endl;
|
|
|
|
|
if(!config.inherit.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
outStream << "inherit" << " " << config.inherit << endl;
|
|
|
|
|
}
|
|
|
|
|
if(!config.name.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
outStream << "name" << " " << config.name << endl;
|
|
|
|
|
}
|
|
|
|
|
if(!config.command.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
outStream << "command" << " " << config.command << endl;
|
|
|
|
|
}
|
|
|
|
|
if(!config.iconPath.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
outStream << "icon" << " " << config.iconPath << endl;
|
|
|
|
|
}
|
|
|
|
|
outStream << "row" << " " << config.row << endl;
|
|
|
|
|
outStream << "col" << " " << config.col << endl;
|
|
|
|
|
if(config.type == EntryType::USER)
|
|
|
|
|
{
|
|
|
|
|
if(!config.name.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
outStream << "name" << " " << config.name << endl;
|
|
|
|
|
}
|
|
|
|
|
if(!config.command.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
outStream << "command" << " " << config.command << endl;
|
|
|
|
|
}
|
|
|
|
|
if(!config.iconPath.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
outStream << "icon" << " " << config.iconPath << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
outStream.flush();
|
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
|
@ -298,11 +328,11 @@ void EntryProvider::saveUserEntry(const EntryConfig &config)
|
|
|
|
|
|
|
|
|
|
bool EntryProvider::deleteUserEntry(const EntryConfig &config)
|
|
|
|
|
{
|
|
|
|
|
if(!config.userEntry || config.entryPath.isEmpty())
|
|
|
|
|
if(config.type == EntryType::SYSTEM || config.entryPath.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error("Only user entries can be saved");
|
|
|
|
|
throw std::runtime_error("Only user/inherited entries can be deleted");
|
|
|
|
|
}
|
|
|
|
|
QFile file { config.entryPath };
|
|
|
|
|
QFile file{config.entryPath};
|
|
|
|
|
return file.remove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -329,6 +359,6 @@ EntryConfig &EntryConfig::update(const EntryConfig &o)
|
|
|
|
|
assignIfDestDefault(this->hidden, o.hidden);
|
|
|
|
|
assignIfDestDefault(this->inherit, o.inherit);
|
|
|
|
|
assignIfDestDefault(this->entryPath, o.entryPath);
|
|
|
|
|
assignIfDestDefault(this->userEntry, o.userEntry);
|
|
|
|
|
assignIfDestDefault(this->type, o.type);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|