Browse Source

Add a command line option to launch the client in the background

Allow passing a --background argument to force the app in the background
even if systray is not available.

Fixes #737
J-P Nurmi 7 years ago
parent
commit
ee8bcb2a5b
3 changed files with 14 additions and 3 deletions
  1. 10 1
      src/gui/application.cpp
  2. 2 0
      src/gui/application.h
  3. 2 2
      src/gui/main.cpp

+ 10 - 1
src/gui/application.cpp

@@ -72,7 +72,8 @@ namespace {
         "                         (to be used with --logdir)\n"
         "  --logflush           : flush the log file after every write.\n"
         "  --logdebug           : also output debug-level messages in the log.\n"
-        "  --confdir <dirname>  : Use the given configuration folder.\n";
+        "  --confdir <dirname>  : Use the given configuration folder.\n"
+        "  --background         : launch the application in the background.\n";
 
     QString applicationTrPath()
     {
@@ -106,6 +107,7 @@ Application::Application(int &argc, char **argv)
     , _logDebug(false)
     , _userTriggeredConnect(false)
     , _debugMode(false)
+    , _backgroundMode(false)
 {
     _startedAt.start();
 
@@ -467,6 +469,8 @@ void Application::parseOptions(const QStringList &options)
         } else if (option == QLatin1String("--debug")) {
             _logDebug = true;
             _debugMode = true;
+        } else if (option == QLatin1String("--background")) {
+            _backgroundMode = true;
         } else if (option == QLatin1String("--version")) {
             _versionOnly = true;
         } else {
@@ -540,6 +544,11 @@ bool Application::debugMode()
     return _debugMode;
 }
 
+bool Application::backgroundMode() const
+{
+    return _backgroundMode;
+}
+
 void Application::setHelp()
 {
     _helpOnly = true;

+ 2 - 0
src/gui/application.h

@@ -63,6 +63,7 @@ public:
     void showHelp();
     void showHint(std::string errorHint);
     bool debugMode();
+    bool backgroundMode() const;
     bool versionOnly(); // only display the version?
     void showVersion();
 
@@ -112,6 +113,7 @@ private:
     bool _logDebug;
     bool _userTriggeredConnect;
     bool _debugMode;
+    bool _backgroundMode;
 
     ClientProxy _proxy;
 

+ 2 - 2
src/gui/main.cpp

@@ -132,7 +132,7 @@ int main(int argc, char **argv)
             if (!app.sendMessage(QLatin1String("MSG_PARSEOPTIONS:") + msg))
                 return -1;
         }
-        if (!app.sendMessage(QLatin1String("MSG_SHOWSETTINGS"))) {
+        if (!app.backgroundMode() && !app.sendMessage(QLatin1String("MSG_SHOWSETTINGS"))) {
             return -1;
         }
         return 0;
@@ -164,7 +164,7 @@ int main(int argc, char **argv)
                     warnSystray();
                 }
             }
-            if (!QSystemTrayIcon::isSystemTrayAvailable() && desktopSession != "ubuntu") {
+            if (!app.backgroundMode() && !QSystemTrayIcon::isSystemTrayAvailable() && desktopSession != "ubuntu") {
                 app.showSettingsDialog();
             }
         }