From a26e6886ba50f244d90a06135b51ebca01aed0d1 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Sat, 28 Jul 2012 22:13:14 +0000 Subject: [PATCH] fixed: service process was being stopped when gui exited and in other scenarios. --- src/gui/src/MainWindow.cpp | 76 +++++++++++++++++++++++--------------- src/gui/src/MainWindow.h | 4 +- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 46e82af4..412850d2 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -97,14 +97,18 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) : MainWindow::~MainWindow() { - stopSynergy(); + if (appConfig().processMode() == Desktop) + { + stopDesktop(); + } + saveSettings(); delete m_SetupWizard; } void MainWindow::start(bool firstRun) { - onModeChanged(firstRun, false); + onModeChanged(!firstRun && appConfig().autoConnect(), false); createTrayIcon(); @@ -116,15 +120,13 @@ void MainWindow::start(bool firstRun) void MainWindow::wizardFinished() { - onModeChanged(false, true); + onModeChanged(true, true); } -void MainWindow::onModeChanged(bool firstRun, bool forceServiceApply) +void MainWindow::onModeChanged(bool startDesktop, bool applyService) { refreshApplyButton(); - stopSynergy(); - if (appConfig().processMode() == Service) { // ensure that the apply button actually does something, since desktop @@ -132,19 +134,15 @@ void MainWindow::onModeChanged(bool firstRun, bool forceServiceApply) disconnect(m_pButtonToggleStart, SIGNAL(clicked()), m_pActionStartSynergy, SLOT(trigger())); connect(m_pButtonToggleStart, SIGNAL(clicked()), m_pActionStartSynergy, SLOT(trigger())); - if (forceServiceApply) + if (applyService) { + stopDesktop(); startSynergy(); } } - else - { - // cause the service to stop creating processes. - m_IpcClient.sendCommand("", false); - } - - if ((appConfig().processMode() == Desktop) && !firstRun && appConfig().autoConnect()) + else if ((appConfig().processMode() == Desktop) && startDesktop) { + stopService(); startSynergy(); } @@ -567,18 +565,13 @@ bool MainWindow::serverArgs(QStringList& args, QString& app) void MainWindow::stopSynergy() { - if (appConfig().processMode() == Service) { - // send empty command to stop service from laucning anything. - m_IpcClient.sendCommand("", m_ElevateProcess); - } - else if (synergyProcess()) + if (appConfig().processMode() == Service) { - appendLogNote("stopping synergy"); - - if (synergyProcess()->isOpen()) - synergyProcess()->close(); - delete synergyProcess(); - setSynergyProcess(NULL); + stopService(); + } + else if (appConfig().processMode() == Desktop) + { + stopDesktop(); } setSynergyState(synergyDisconnected); @@ -592,6 +585,27 @@ void MainWindow::stopSynergy() m_alreadyHidden = false; } +void MainWindow::stopService() +{ + // send empty command to stop service from laucning anything. + m_IpcClient.sendCommand("", m_ElevateProcess); +} + +void MainWindow::stopDesktop() +{ + if (!synergyProcess()) { + return; + } + + appendLogNote("stopping synergy desktop process"); + + if (synergyProcess()->isOpen()) + synergyProcess()->close(); + + delete synergyProcess(); + setSynergyProcess(NULL); +} + void MainWindow::synergyFinished(int exitCode, QProcess::ExitStatus) { // on Windows, we always seem to have an exit code != 0. @@ -629,10 +643,14 @@ void MainWindow::setSynergyState(qSynergyState state) m_pButtonToggleStart->setText(tr("&Start")); } - m_pGroupClient->setEnabled(state == synergyDisconnected); - m_pGroupServer->setEnabled(state == synergyDisconnected); - m_pActionStartSynergy->setEnabled(state == synergyDisconnected); - m_pActionStopSynergy->setEnabled(state == synergyConnected); + // only disable controls in desktop mode. in service mode, we can use the apply button. + if (appConfig().processMode() == Desktop) + { + m_pGroupClient->setEnabled(state == synergyDisconnected); + m_pGroupServer->setEnabled(state == synergyDisconnected); + m_pActionStartSynergy->setEnabled(state == synergyDisconnected); + m_pActionStopSynergy->setEnabled(state == synergyConnected); + } switch (state) { diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index b747114c..8c77310e 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -134,10 +134,12 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase bool serverArgs(QStringList& args, QString& app); void setStatus(const QString& status); void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors); - void onModeChanged(bool firstRun, bool forceServiceApply); + void onModeChanged(bool startDesktop, bool applyService); void updateStateFromLogLine(const QString& line); QString getIPAddresses(); QString getScreenName(); + void stopService(); + void stopDesktop(); private: QSettings& m_Settings;