diff options
author | Ken Moore <ken@ixsystems.com> | 2016-12-29 12:57:34 -0500 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2016-12-29 12:57:34 -0500 |
commit | 67f52893177748a5158bab013b9dd1b61c5744e0 (patch) | |
tree | e4a6bbb1c7b90fec7a3f3fe6a529fa8ebd891dad /src-qt5/core | |
parent | New Feature for lumina-archiver: (diff) | |
download | lumina-67f52893177748a5158bab013b9dd1b61c5744e0.tar.gz lumina-67f52893177748a5158bab013b9dd1b61c5744e0.tar.bz2 lumina-67f52893177748a5158bab013b9dd1b61c5744e0.zip |
Add a new function to the XDGDesktop class:
QString generateExec(QStringList inputfiles, QString ActionID);
This will automatically evaluate the input file's syntax and adjust as needed for the application to recognize/run the file. Similarly it will perform all the substitutions and such as necessary to end up with a fully-formatted executable command which can easily be launched with QProcess as necessary.
Diffstat (limited to 'src-qt5/core')
-rw-r--r-- | src-qt5/core/libLumina/LuminaXDG.cpp | 40 | ||||
-rw-r--r-- | src-qt5/core/libLumina/LuminaXDG.h | 4 |
2 files changed, 43 insertions, 1 deletions
diff --git a/src-qt5/core/libLumina/LuminaXDG.cpp b/src-qt5/core/libLumina/LuminaXDG.cpp index c46b943a..cb16830d 100644 --- a/src-qt5/core/libLumina/LuminaXDG.cpp +++ b/src-qt5/core/libLumina/LuminaXDG.cpp @@ -230,6 +230,46 @@ QString XDGDesktop::getDesktopExec(QString ActionID){ return out; } +QString XDGDesktop::generateExec(QStringList inputfiles, QString ActionID){ + QString exec = getDesktopExec(ActionID); + //Does the app need the input files in URL or File syntax? + bool URLsyntax = (exec.contains("%u") || exec.contains("%U")); + //Adjust the input file formats as needed + for(int i=0; i<inputfiles.length(); i++){ + bool url = inputfiles[i].contains("://") || inputfiles[i].startsWith("www") || QUrl(inputfiles[i]).isValid(); + //Run it through the QUrl class to catch/fix any URL syntax issues + if(URLsyntax){ + if(inputfiles[i].startsWith("mailto:") ){} //don't touch this syntax - already formatted + else if(url){ inputfiles[i] = QUrl(inputfiles[i]).url(); } + else{ inputfiles[i] = QUrl::fromLocalFile(inputfiles[i]).url(); } + }else{ + //if(inputfiles[i].startsWith("mailto:") ){} //don't touch this syntax - already formatted + if(url){ inputfiles[i] = QUrl(inputfiles[i]).toLocalFile(); } + else{ inputfiles[i] = QUrl::fromLocalFile(inputfiles[i]).toLocalFile(); } + } + } + //Now to the exec replacements as needed + if(exec.contains("%f")){ + if(inputfiles.isEmpty()){ exec.replace("%f",""); } + else{ exec.replace("%f", "\""+inputfiles.first()+"\""); } //Note: can only take one input + }else if(exec.contains("%F")){ + if(inputfiles.isEmpty()){ exec.replace("%F",""); } + else{ exec.replace("%F", "\""+inputfiles.join("\" \"")+"\""); } + } + if(exec.contains("%u")){ + if(inputfiles.isEmpty()){ exec.replace("%u",""); } + else{ exec.replace("%u", "\""+inputfiles.first()+"\""); } //Note: can only take one input + }else if(exec.contains("%U")){ + if(inputfiles.isEmpty()){ exec.replace("%U",""); } + else{ exec.replace("%U", "\""+inputfiles.join("\" \"")+"\""); } + } + //Sanity check for known Local/URL syntax issues from some apps + if(!URLsyntax && exec.contains("%20")){ exec.replace("%20"," "); } + //Clean up any leftover "Exec" field codes (should have already been replaced earlier) + if(exec.contains("%")){ exec = exec.remove("%U").remove("%u").remove("%F").remove("%f").remove("%i").remove("%c").remove("%k"); } + return exec.simplified(); +} + bool XDGDesktop::saveDesktopFile(bool merge){ qDebug() << "Save Desktop File:" << filePath << "Merge:" << merge; bool autofile = filePath.contains("/autostart/"); //use the "Hidden" field instead of the "NoDisplay" diff --git a/src-qt5/core/libLumina/LuminaXDG.h b/src-qt5/core/libLumina/LuminaXDG.h index 1c86cedb..fbfd6fd4 100644 --- a/src-qt5/core/libLumina/LuminaXDG.h +++ b/src-qt5/core/libLumina/LuminaXDG.h @@ -78,7 +78,9 @@ public: void sync(); //syncronize this structure with the backend file(as listed in the "filePath" variable) bool isValid(bool showAll = true); //See if this is a valid .desktop entry (showAll: don't filter out based on DE exclude/include lists) - QString getDesktopExec(QString ActionID = ""); + QString getDesktopExec(QString ActionID = ""); //Just return the exec field with minimal cleanup + QString generateExec(QStringList inputfiles = QStringList(), QString ActionID = ""); //Format the exec command to account for input files + bool saveDesktopFile(bool merge = true); //This will use the "filePath" variable for where to save the file bool setAutoStarted(bool autostart = true); |