aboutsummaryrefslogtreecommitdiff
path: root/libLumina/LuminaUtils.cpp
diff options
context:
space:
mode:
authorKen Moore <moorekou@gmail.com>2015-09-17 08:40:24 -0400
committerKen Moore <moorekou@gmail.com>2015-09-17 08:40:24 -0400
commite339182d31dc2e8850c4c13c5ce1274bf1df7052 (patch)
tree462baba4f8a9ab10d4360ac2e83ce2d23692e97f /libLumina/LuminaUtils.cpp
parentFix a rogue empty zorder assignment in the mainUI.ui file (something left beh... (diff)
downloadlumina-e339182d31dc2e8850c4c13c5ce1274bf1df7052.tar.gz
lumina-e339182d31dc2e8850c4c13c5ce1274bf1df7052.tar.bz2
lumina-e339182d31dc2e8850c4c13c5ce1274bf1df7052.zip
Add a LUtils function for assembling the command to open a terminal in a particular directory. It appears that most Linux-DE terminal apps do not properly apply the universal "-e" flag, so add special handling of the following terminal applications:
mate-terminal, lxterminal, gnome-terminal, xfce4-terminal, konsole This makes those application work properly now, but it *could* break in the future if the app devs decide to modify the CLI flags for their app.
Diffstat (limited to 'libLumina/LuminaUtils.cpp')
-rw-r--r--libLumina/LuminaUtils.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/libLumina/LuminaUtils.cpp b/libLumina/LuminaUtils.cpp
index f45c3813..60605e65 100644
--- a/libLumina/LuminaUtils.cpp
+++ b/libLumina/LuminaUtils.cpp
@@ -107,6 +107,40 @@ bool LUtils::isValidBinary(QString& bin){
return good;
}
+QString LUtils::GenerateOpenTerminalExec(QString term, QString dirpath){
+ //Check the input terminal application (default/fallback - determined by calling application)
+ if(!LUtils::isValidBinary(term)){
+ if(term.endsWith(".desktop")){
+ //Pull the binary name out of the shortcut
+ bool ok = false;
+ XDGDesktop DF = LXDG::loadDesktopFile(term,ok);
+ if(!ok){ term = "xterm"; }
+ else{ term= DF.exec.section(" ",0,0); } //only take the binary name - not any other flags
+ }else{
+ term = "xterm"; //fallback
+ }
+ }
+ //Now create the calling command for the designated terminal
+ // NOTE: While the "-e" routine is supposed to be universal, many terminals do not properly use it
+ // so add some special/known terminals here as necessary
+ QString exec;
+ if(term=="mate-terminal" || term=="lxterminal" || term=="gnome-terminal"){
+ exec = term+" --working-directory=\""+dirpath+"\"";
+ }else if(term=="xfce4-terminal"){
+ exec = term+" --default-working-directory=\""+dirpath+"\"";
+ }else if(term=="konsole"){
+ exec = term+" --workdir \""+dirpath+"\"";
+ }else{
+ //-e is the parameter for most of the terminal appliction to execute an external command.
+ //In this case we start a shell in the selected directory
+ //Need the user's shell first
+ QString shell = QString(getenv("SHELL"));
+ if(!LUtils::isValidBinary(shell)){ shell = "/bin/sh"; } //universal fallback for a shell
+ exec = term + " -e \"cd " + dirpath + " && " + shell + " \" ";
+ }
+ return exec;
+}
+
QStringList LUtils::listSubDirectories(QString dir, bool recursive){
//This is a recursive method for returning the full paths of all subdirectories (if recursive flag is enabled)
QDir maindir(dir);
bgstack15