[X2Go-Commits] [x2goclient] 01/01: Disable/Enable PulseAudio in config dialog. New command line options: --disable-pulse to disable start of PulseAudio --disable-pulse-record to disable audio input.

git-admin at x2go.org git-admin at x2go.org
Mon May 15 20:28:35 CEST 2017


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository x2goclient.

commit 1f2e09f67938ab1830d9e13c8c750d1090bc85c3
Author: Oleksandr Shneyder <o.shneyder at phoca-gmbh.de>
Date:   Mon May 15 20:27:31 2017 +0200

    Disable/Enable PulseAudio in config dialog. New command line options: --disable-pulse to disable start of PulseAudio --disable-pulse-record to disable audio input.
---
 debian/changelog     |  4 +++
 src/configdialog.cpp | 40 +++++++++++++++++++++++++++--
 src/configdialog.h   |  7 ++++++
 src/help.cpp         |  4 +++
 src/onmainwindow.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++----------
 src/onmainwindow.h   | 13 ++++++++++
 src/pulsemanager.cpp |  9 ++++---
 src/pulsemanager.h   |  8 +++---
 8 files changed, 133 insertions(+), 23 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 99cbffd..b1a0ec9 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -165,6 +165,10 @@ x2goclient (4.1.0.1-0x2go1) UNRELEASED; urgency=medium
     - Move PulseManager MsgBox functions to main window:
       GUI functions should be used only from main thread.
     - Check "norecord" option on the first start of PulseAudio.
+    - Disable/Enable PulseAudio in config dialog.
+      New command line options:
+      --disable-pulse to disable start of PulseAudio
+      --disable-pulse-record to disable audio input.
 
   [ Robert Parts ]
   * New upstream version (4.1.0.1):
diff --git a/src/configdialog.cpp b/src/configdialog.cpp
index 991e030..481948d 100644
--- a/src/configdialog.cpp
+++ b/src/configdialog.cpp
@@ -341,10 +341,27 @@ ConfigDialog::ConfigDialog ( QWidget * parent,  Qt::WindowFlags f )
     QFrame* frp = new QFrame (this);
     tabWidg->addTab (frp, tr ("PulseAudio settings"));
     QVBoxLayout* l = new QVBoxLayout (frp);
+    cbDisablePA = new QCheckBox (tr ("Disable PulseAudio"), frp);
     cbNoRecord = new QCheckBox (tr ("Disable sound input"), frp);
+    connect(cbDisablePA, SIGNAL(stateChanged(int)), this, SLOT(slot_cbDisablePAStateChanged(int)));
+    l->addWidget (cbDisablePA);
     l->addWidget (cbNoRecord);
     l->addStretch (1);
     cbNoRecord->setChecked (st.setting ()->value ("pulse/norecord", false).toBool ());
+    cbDisablePA->setChecked (st.setting ()->value ("pulse/disable", false).toBool ());
+    ONMainWindow* par= ( ONMainWindow* ) parent;
+    systemDisablePA=par->getSystemDisablePA();
+    systemDisablePARecord=par->getSystemDisablePARecord();
+    if(systemDisablePA)
+    {
+        cbDisablePA->setChecked(true);
+        cbDisablePA->setEnabled(false);
+    }
+    if(systemDisablePARecord)
+    {
+        cbNoRecord->setChecked(true);
+        cbNoRecord->setEnabled(false);
+    }
 #endif /* defined (Q_OS_WIN) || defined (Q_OS_DARWIN) */
 }
 
@@ -364,7 +381,10 @@ void ConfigDialog::slot_accepted()
     st.setting()->setValue ( "trayicon/maxdiscon", cbMaxmizeTray->isChecked() );
 #endif
 #if defined (Q_OS_WIN) || defined (Q_OS_DARWIN)
-    st.setting()->setValue ( "pulse/norecord", cbNoRecord->isChecked() );
+    if(!systemDisablePARecord)
+        st.setting()->setValue ( "pulse/norecord", cbNoRecord->isChecked() );
+    if(!systemDisablePA)
+        st.setting()->setValue ( "pulse/disable", cbDisablePA->isChecked() );
 #endif /* defined (Q_OS_WIN) || defined (Q_OS_DARWIN) */
 #ifdef USELDAP
     if ( !embedMode )
@@ -602,6 +622,18 @@ QString ConfigDialog::getXDarwinDirectory()
 }
 #endif
 
+#if defined (Q_OS_WIN) || defined (Q_OS_DARWIN)
+void ConfigDialog::slot_cbDisablePAStateChanged(int state)
+{
+    cbNoRecord->setEnabled(state==Qt::Unchecked);
+    if(systemDisablePARecord)
+    {
+        cbNoRecord->setChecked(true);
+        cbNoRecord->setEnabled(false);
+    }
+}
+#endif /* defined (Q_OS_WIN) || defined (Q_OS_DARWIN) */
+
 
 void ConfigDialog::slotAdvClicked()
 {
@@ -636,7 +668,10 @@ void ConfigDialog::slotDefaults()
 #ifdef Q_OS_WIN
     case 3:
     {
-         cbNoRecord->setChecked(false);
+         if(!systemDisablePARecord)
+             cbNoRecord->setChecked(false);
+         if(!systemDisablePA)
+             cbDisablePA->setChecked(false);
     }
     break;
 #endif /* defined (Q_OS_WIN) */
@@ -647,6 +682,7 @@ void ConfigDialog::slotDefaults()
         clientSshPort->setValue ( 22 );
 #ifdef Q_OS_DARWIN
         cbNoRecord->setChecked (false);
+        cbDisablePA->setChecked (false);
 #endif /* defined (Q_OS_DARWIN) */
 #ifndef CFGPLUGIN
         gbTrayIcon->setChecked (false);
diff --git a/src/configdialog.h b/src/configdialog.h
index 14b5cbc..d82d0d0 100644
--- a/src/configdialog.h
+++ b/src/configdialog.h
@@ -95,6 +95,9 @@ private:
 
 #if defined (Q_OS_WIN) || defined (Q_OS_DARWIN)
     QCheckBox *cbNoRecord;
+    QCheckBox *cbDisablePA;
+    bool systemDisablePA;
+    bool systemDisablePARecord;
 #endif /* defined (Q_OS_WIN) || defined (Q_OS_DARWIN) */
 
     QGroupBox *gbTrayIcon;
@@ -112,6 +115,10 @@ private slots:
     void slot_selectXDarwin();
     void slot_findXDarwin();
 #endif
+#if defined (Q_OS_WIN) || defined (Q_OS_DARWIN)
+    void slot_cbDisablePAStateChanged(int state);
+#endif /* defined (Q_OS_WIN) || defined (Q_OS_DARWIN) */
+
 private slots:
     void slotAdvClicked();
     void slotDefaults();
diff --git a/src/help.cpp b/src/help.cpp
index e3cb1de..d83f856 100644
--- a/src/help.cpp
+++ b/src/help.cpp
@@ -117,6 +117,10 @@ help::params_t help::build_params () {
   ADD_OPT ("--hide", QT_TRANSLATE_NOOP ("Help", "Starts hidden (minimized to system tray where available.)"));
   ADD_OPT ("--portable", QT_TRANSLATE_NOOP ("Help", "Starts in \"portable\" mode."));
   ADD_OPT ("--pgp-card", QT_TRANSLATE_NOOP ("Help", "Forces OpenPGP smart card authentication."));
+#if defined (Q_OS_DARWIN) || defined (Q_OS_WIN)
+  ADD_OPT ("--disable-pulse", QT_TRANSLATE_NOOP ("Help", "Disable PulseAudio."));
+  ADD_OPT ("--disable-pulse-record", QT_TRANSLATE_NOOP ("Help", "Disable sound input."));
+#endif /* defined (Q_OS_DARWIN) || defined (Q_OS_WIN) */
   ADD_OPT ("--xinerama", QT_TRANSLATE_NOOP ("Help", "Enables Xinerama by default."));
   ADD_OPT ("--ldap-printing", QT_TRANSLATE_NOOP ("Help", "Allows client side printing in LDAP mode."));
   ADD_OPT ("--thinclient", QT_TRANSLATE_NOOP ("Help", "Enables thinclient mode. Starts without a window manager."));
diff --git a/src/onmainwindow.cpp b/src/onmainwindow.cpp
index 4141570..13d0986 100644
--- a/src/onmainwindow.cpp
+++ b/src/onmainwindow.cpp
@@ -133,6 +133,10 @@ ONMainWindow::ONMainWindow ( QWidget *parent ) :QMainWindow ( parent )
     config.brokerAutologoff=false;
     config.published=false;
     cmdAutologin=false;
+#if defined (Q_OS_DARWIN) || defined (Q_OS_WIN)
+    systemDisablePARecord=false;
+    systemDisablePA=false;
+#endif /* defined (Q_OS_DARWIN) || defined (Q_OS_WIN) */
 
 
 // Try to determine the native DPI and use it for the default
@@ -2193,19 +2197,40 @@ void ONMainWindow::slotConfig()
         int i;
 
 #if defined (Q_OS_WIN) || defined (Q_OS_DARWIN)
-        X2goSettings st ("settings");
-        bool newDisableInput = st.setting ()->value ("pulse/norecord",
+        if(!systemDisablePA)
+        {
+            X2goSettings st ("settings");
+            bool disablePA = st.setting ()->value ("pulse/disable",
                                                      (QVariant) false).toBool ();
-
-        if (oldDisableInput != newDisableInput) {
-            bool ret = pulseManager->set_record (!newDisableInput);
-
-            if (!ret) {
-              x2goDebug << "Failed to change recording status of PulseManager. PulseAudio not started?" << endl;
-            }
-
-            pulseManager->restart ();
-        }
+            if(!pulseManager && !disablePA)
+	    {
+	        x2goDebug<<"PA manager not inited yet, starting PA thread";
+		QTimer::singleShot (10, this, SLOT (pulseManagerWrapper ()));
+	    }
+	    else if(pulseManager && disablePA)
+	    {
+	        if(pulseManager->is_server_running())
+		{
+		    x2goDebug<<"Stopping PulseAudio";
+		    pulseManager->shutdown();
+		}
+	    }
+	    else if(pulseManager && !disablePA)//pulse is already inited and not disabled by config dialog
+	    {
+                bool newDisableInput = st.setting ()->value ("pulse/norecord",
+                                                         (QVariant) false).toBool ();
+                if(systemDisablePARecord)
+		    newDisableInput=true;
+                if (oldDisableInput != newDisableInput) {
+                    bool ret = pulseManager->set_record (!newDisableInput);
+
+                    if (!ret) {
+                      x2goDebug << "Failed to change recording status of PulseManager. PulseAudio not started?" << endl;
+                    }
+                    pulseManager->restart ();
+                }
+	    }
+	}
 #endif /* defined (Q_OS_WIN) || defined (Q_OS_DARWIN) */
 
         if ( passForm->isVisible() && !embedMode )
@@ -6748,12 +6773,19 @@ void ONMainWindow::pulseManagerWrapper () {
       (config.confSnd && config.useSnd))
 #endif /* defined (Q_OS_WIN) */
   {
+    X2goSettings st ("settings");
+    bool disablePulse = st.setting ()->value ("pulse/disable",
+                                                     (QVariant) false).toBool ();
+    if(disablePulse||systemDisablePA)
+    {
+        x2goDebug<<"Not starting PulseAudio";
+        return;
+    }
     pulseManagerThread = new QThread (0);
     pulseManager = new PulseManager ();
     connect(pulseManager, SIGNAL(sig_pulse_user_warning(bool, const QString&, const QString&, bool)),
             this, SLOT(slotShowPAMSGDialog(bool, const QString&, const QString&, bool)));
 
-    X2goSettings st ("settings");
     bool disableInput = st.setting ()->value ("pulse/norecord",
                                                      (QVariant) false).toBool ();
     pulseManager->set_record (!disableInput);
@@ -7252,6 +7284,19 @@ bool ONMainWindow::parseParameter ( QString param )
         return true;
     }
 
+#if defined (Q_OS_DARWIN) || defined (Q_OS_WIN)
+    if (param == "--disable-pulse")
+    {
+        systemDisablePA=true;
+        return true;
+    }
+    if (param == "--disable-pulse-record")
+    {
+        systemDisablePARecord=true;
+        return true;
+    }
+#endif /* defined (Q_OS_DARWIN) || defined (Q_OS_WIN) */
+
     if (param == "--no-autoresume")
     {
         autoresume=false;
diff --git a/src/onmainwindow.h b/src/onmainwindow.h
index 9e749d3..b8e7362 100644
--- a/src/onmainwindow.h
+++ b/src/onmainwindow.h
@@ -540,6 +540,17 @@ public:
         return &config;
     }
 
+#if defined (Q_OS_DARWIN) || defined (Q_OS_WIN)
+    bool getSystemDisablePARecord()
+    {
+        return systemDisablePARecord;
+    }
+    bool getSystemDisablePA()
+    {
+        return systemDisablePA;
+    }
+#endif /* defined (Q_OS_DARWIN) || defined (Q_OS_WIN) */
+
     void runApplication(QString exec);
 
 
@@ -853,6 +864,8 @@ private:
 #if defined (Q_OS_DARWIN) || defined (Q_OS_WIN)
     QThread *pulseManagerThread;
     PulseManager *pulseManager;
+    bool systemDisablePARecord;
+    bool systemDisablePA;
 #endif /* defined (Q_OS_DARWIN) || defined (Q_OS_WIN) */
 
 
diff --git a/src/pulsemanager.cpp b/src/pulsemanager.cpp
index 4b144e2..a7d93c0 100644
--- a/src/pulsemanager.cpp
+++ b/src/pulsemanager.cpp
@@ -47,6 +47,7 @@ PulseManager::PulseManager () : app_dir_ (QApplication::applicationDirPath ()),
                                 record_ (true),
                                 playback_ (true),
                                 debug_ (false),
+                                shutdownState(false),
                                 system_pulse_ (false) {
   pulse_dir_ = QDir (QDir::homePath ());
   pulse_dir_.mkpath (pulse_dir_.absolutePath () + pulse_X2Go_ + "/tmp");
@@ -773,12 +774,12 @@ void PulseManager::slot_play_startup_sound () {
 }
 
 void PulseManager::slot_on_pulse_finished (int exit_code) {
-  if (exit_code)
+  if (exit_code && !shutdownState)
   {
     x2goDebug << "Warning! Pulseaudio's exit code is non-zero.";
     show_startup_warning(true);
   }
-
+  shutdownState=false;
   x2goDebug << "Pulseaudio finished with code:"<<exit_code;
   QByteArray ba (pulse_server_->readAllStandardOutput ());
   char *data = ba.data ();
@@ -825,6 +826,7 @@ bool PulseManager::is_server_running () const {
 void PulseManager::shutdown () {
   QEventLoop loop;
 
+  shutdownState=true;
   connect (this,  SIGNAL (sig_pulse_server_terminated ()),
            &loop, SLOT (quit ()));
 
@@ -886,10 +888,9 @@ bool PulseManager::set_record (bool record) {
   bool ret = false;
 
   if (!(is_server_running ())) {
-    record_ = record;
     ret = true;
   }
-
+  record_ = record;
   return (ret);
 }
 
diff --git a/src/pulsemanager.h b/src/pulsemanager.h
index 1472596..237ebe0 100644
--- a/src/pulsemanager.h
+++ b/src/pulsemanager.h
@@ -60,11 +60,14 @@ class PulseManager: public QObject {
     bool set_record (bool record);
     bool set_playback (bool playback);
     void set_debug (bool debug);
+    bool is_server_running () const;
+
 
 
   public slots:
     void start ();
     void restart ();
+    void shutdown ();
 
 
   private:
@@ -86,10 +89,6 @@ class PulseManager: public QObject {
     void create_client_dir ();
     void cleanup_client_dir ();
 
-    void shutdown ();
-
-    bool is_server_running () const;
-
     void show_startup_warning (bool play_startup_sound = false);
 
 
@@ -130,6 +129,7 @@ class PulseManager: public QObject {
     bool debug_;
 
     bool system_pulse_;
+    bool shutdownState;
 };
 
 #endif // PULSEMANAGER_H

--
Alioth's /srv/git/code.x2go.org/x2goclient.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2goclient.git


More information about the x2go-commits mailing list