Subject: Refreshed x2goclient autostart multiple app patch with bug fix

From: Jason Alavaliant <[email-masked]>
Date: Sun, 25 Sep 2016 20:33:15 +1300

It's been a while since I submitted the original proposed patches for 
the x2goclient to allow it to support autostarting multiple 
applications.    I note the original patches no longer applied to git 
master so I've refreshed them in git format-patch format and also fixed 
an off by one error that stopped the autostart option working when only 
one app was specified.

Thanks

Jason

>From 836f8f7423ee9699c0c307754f52d412c70a91e9 Mon Sep 17 00:00:00 2001
From: Jason Alavaliant <[email-masked]>
Date: Sun, 25 Sep 2016 20:17:17 +1300
Subject: [PATCH] Patch autostart option to support multiple autostart app at
 the same time

---
 src/help.cpp         |  2 +-
 src/onmainwindow.cpp | 48 +++++++++++++++++++++++++++++++++---------------
 src/onmainwindow.h   |  2 +-
 3 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/src/help.cpp b/src/help.cpp
index a708d81..5da345b 100644
--- a/src/help.cpp
+++ b/src/help.cpp
@@ -139,7 +139,7 @@ help::params_t help::build_params () {
   ADD_OPT ("--kbd-type=<type>", QT_TRANSLATE_NOOP ("Help", "Sets the default keyboard type."));
   ADD_OPT ("--home=<dir>", QT_TRANSLATE_NOOP ("Help", "Sets the user's home directory."));
   ADD_OPT ("--set-kbd=<0|1>", QT_TRANSLATE_NOOP ("Help", "Enables or disables overwriting the current keyboard settings."));
-  ADD_OPT ("--autostart=<app>", QT_TRANSLATE_NOOP ("Help", "Automatically launches the application \"app\" on session start in Published Applications mode."));
+  ADD_OPT ("--autostart=<app>,<app2>", QT_TRANSLATE_NOOP ("Help", "Automatically launches the application(s) \"app\" on session start in Published Applications mode."));
   ADD_OPT ("--session-conf=<file>", QT_TRANSLATE_NOOP ("Help", "Defines an alternative session config file path."));
   ADD_OPT ("--tray-icon", QT_TRANSLATE_NOOP ("Help", "Force-enables session system tray icon."));
   ADD_OPT ("--close-disconnect", QT_TRANSLATE_NOOP ("Help", "Automatically closes X2Go Client after a disconnect."));
diff --git a/src/onmainwindow.cpp b/src/onmainwindow.cpp
index 4b3fb05..5f77c0d 100644
--- a/src/onmainwindow.cpp
+++ b/src/onmainwindow.cpp
@@ -6747,7 +6747,7 @@ void ONMainWindow::slotReadApplications(bool result, QString output,
     applications.clear();
     QString locallong=QLocale::system().name();
     QString localshort=QLocale::system().name().split("_")[0];
-    bool startAppFound=false;
+    QStringList startAppsFound;
 
     foreach(QString appstr, output.split("</desktop>",QString::SkipEmptyParts))
     {
@@ -6776,9 +6776,12 @@ void ONMainWindow::slotReadApplications(bool result, QString output,
             if (line.indexOf("Name=")!=-1 && !localname)
             {
                 app.name=line.split("=")[1];
-                if (app.name==autostartApp)
-                    startAppFound=true;
-                //                 x2goDebug<<"name: "<<app.name<<endl;
+                for (int i=0; i<autostartApps.length(); ++i)
+                {
+                    if (app.name==autostartApps[i])
+                        startAppsFound.append(app.name);
+                    //                 x2goDebug<<"name: "<<app.name<<endl;
+                }
             }
             if (line.indexOf("Comment=")!=-1 && !localcomment)
             {
@@ -6794,9 +6797,12 @@ void ONMainWindow::slotReadApplications(bool result, QString output,
                 app.exec.replace("%u","",Qt::CaseInsensitive);
                 app.exec.replace("%i","",Qt::CaseInsensitive);
                 app.exec.replace("%c",app.name,Qt::CaseInsensitive);
-                if (app.exec==autostartApp)
-                    startAppFound=true;
-                //                 x2goDebug<<"exec: "<<app.exec<<endl;
+                for (int i=0; i<autostartApps.length(); ++i)
+                {
+                    if (app.exec==autostartApps[i])
+                        startAppsFound.append(app.exec);
+                    //                 x2goDebug<<"exec: "<<app.exec<<endl;
+                }
             }
             if (line.indexOf("Categories=")!=-1)
             {
@@ -6861,14 +6867,26 @@ void ONMainWindow::slotReadApplications(bool result, QString output,
 
     qSort(applications.begin(), applications.end(),Application::lessThen);
     plugAppsInTray();
-    if (runStartApp && autostartApp.length()>1)
-    {
-        if (!startAppFound) {
-            x2goDebug<<"Autostart application "<<autostartApp<< " not found in desktop files.";
-        }
-        else
+    if (runStartApp && autostartApps.length()>0)
+    {   
+        for (int i=0; i<autostartApps.length(); ++i)
         {
-            runApplication(autostartApp);
+            bool startAppFound = False;
+            for (int j=0; j<startAppsFound.length(); ++j)
+            {
+                if (startAppsFound[j] == autostartApps[i]) 
+                {
+                    startAppFound = True;
+                }
+            }
+            if (!startAppFound) {
+                x2goDebug<<"Autostart application "<<autostartApps[i]<< " not found in desktop files.";
+            }
+            else
+            {
+                runApplication(autostartApps[i]);
+            }
+            
         }
     }
     else
@@ -7233,7 +7251,7 @@ bool ONMainWindow::parseParameter ( QString param )
     }
     if ( setting == "--autostart")
     {
-        autostartApp=value;
+        autostartApps.append(value.split(','));
         return true;
     }
     if ( setting == "--auth-id")
diff --git a/src/onmainwindow.h b/src/onmainwindow.h
index 344f7d1..e0e4d26 100644
--- a/src/onmainwindow.h
+++ b/src/onmainwindow.h
@@ -624,7 +624,7 @@ private:
     bool embedMode;
     bool thinMode;
     QString statusString;
-    QString autostartApp;
+    QStringList autostartApps;
     bool cmdAutologin;
     int defaultLink;
     int defaultQuality;
-- 
2.9.3

---

From: Mihai Moldovan <[email-masked]>
Date: Thu, 29 Sep 2016 02:30:12 +0200

> an off by one error that stopped the autostart option working when only 

Applied it with a few changes here and there (for instance, sanitizing the list
by trimming the strings, whitespace removal.)

Mihai