Subject: expand x2goclient --autostart option to support multiple apps
From: Jason Alavaliant <[email-masked]>
To: [email-masked]
Date: Mon, 11 Apr 2016 11:18:20 +1200

Package: x2goclient
Version: 4.0.5.2
Tags: patch

Hi,

Several of my users would like to be able to automatically launch 
several apps when they start their hosted applications session,  the 
existing x2goclient --autostart option only allows one app to be 
specified to be autostarted.        The attached patches expand the 
--autostart option so that multiple comma separated app names can 
specified as well to optionally allow more than one app to be 
auto-started.

Thanks
Jason

--- old/src/help.cpp	2016-04-10 22:24:10.630742017 +1200
+++ new/src/help.cpp	2016-04-10 22:25:09.328767770 +1200
@@ -137,7 +137,7 @@
   ADD_OPT ("--kbd-type=<type>", "Sets the default keyboard type.");
   ADD_OPT ("--home=<dir>", "Sets the user's home directory.");
   ADD_OPT ("--set-kbd=<0|1>", "Enables or disables overwriting the current keyboard settings.");
-  ADD_OPT ("--autostart=<app>", "Automatically launches the application \"app\" on session start in Published Applications mode.");
+  ADD_OPT ("--autostart=<app>,<app2>", "Automatically launches the application(s) \"app\" on session start in Published Applications mode.");
   ADD_OPT ("--session-conf=<file>", "Defines an alternative session config file path.");
   ADD_OPT ("--tray-icon", "Force-enables session system tray icon.");
   ADD_OPT ("--close-disconnect", "Automatically closes X2Go Client after a disconnect.");
--- old/src/onmainwindow.cpp	2016-04-10 21:30:32.098917053 +1200
+++ new/src/onmainwindow.cpp	2016-04-10 22:20:10.118831277 +1200
@@ -6362,7 +6362,7 @@
     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))
     {
@@ -6391,9 +6391,12 @@
             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)
             {
@@ -6409,9 +6412,12 @@
                 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)
             {
@@ -6476,14 +6482,26 @@
 
     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()>1)
+    {   
+        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
@@ -6842,7 +6860,7 @@
     }
     if ( setting == "--autostart")
     {
-        autostartApp=value;
+        autostartApps.append(value.split(','));
         return true;
     }
     if ( setting == "--auth-id")
--- old/src/onmainwindow.h	2016-04-10 21:32:13.095523538 +1200
+++ new/src/onmainwindow.h	2016-04-10 22:03:47.419876838 +1200
@@ -610,7 +610,7 @@
     bool embedMode;
     bool thinMode;
     QString statusString;
-    QString autostartApp;
+    QStringList autostartApps;
     bool cmdAutologin;
     int defaultLink;
     int defaultQuality;