From ede57b0c81e89d143a633649bb7db74698370790 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Sat, 28 Jul 2012 18:54:50 +0000 Subject: [PATCH] Feature #3172 - Add stop service feature to GUI --- src/gui/res/MainWindowBase.ui | 35 +++++++++------ src/gui/src/MainWindow.cpp | 85 +++++++++++++++++------------------ src/gui/src/MainWindow.h | 6 ++- 3 files changed, 67 insertions(+), 59 deletions(-) diff --git a/src/gui/res/MainWindowBase.ui b/src/gui/res/MainWindowBase.ui index 69e8af6d..9b49920e 100644 --- a/src/gui/res/MainWindowBase.ui +++ b/src/gui/res/MainWindowBase.ui @@ -27,14 +27,7 @@ - - - - &Start - - - - + @@ -127,7 +120,7 @@ - + @@ -168,7 +161,7 @@ - + Log @@ -223,7 +216,7 @@ - :/res/icons/16x16/warning.png + :/res/icons/16x16/warning.png @@ -237,7 +230,21 @@ - + + + + &Start + + + + + + + &Apply + + + + &Elevate @@ -330,7 +337,9 @@ - + + + m_pButtonToggleStart diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 08321889..872c1c8e 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -119,7 +119,7 @@ void MainWindow::wizardFinished() void MainWindow::onModeChanged(bool firstRun, bool forceServiceApply) { - refreshStartButton(); + refreshApplyButton(); stopSynergy(); @@ -130,7 +130,7 @@ 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 (firstRun || forceServiceApply) + if (forceServiceApply) { startSynergy(); } @@ -149,16 +149,9 @@ void MainWindow::onModeChanged(bool firstRun, bool forceServiceApply) m_pElevateCheckBox->setEnabled(appConfig().processMode() == Service); } -void MainWindow::refreshStartButton() +void MainWindow::refreshApplyButton() { - if (appConfig().processMode() == Service) - { - m_pButtonToggleStart->setText(tr("&Apply")); - } - else - { - m_pButtonToggleStart->setText(tr("&Start")); - } + m_pButtonApply->setEnabled(appConfig().processMode() == Service); } void MainWindow::setStatus(const QString &status) @@ -294,22 +287,7 @@ void MainWindow::logOutput() { if (!line.isEmpty()) { - appendLogRaw(line); - if (line.contains("has connected") || - line.contains("connected to server")) - { - // only set connected state and hide, if we get - // "has connected" message. this is a little bit - // hacky, but it works for now (until we have IPC). - setSynergyState(synergyConnected); - - // only hide once after each new connection. - if (!m_alreadyHidden && appConfig().autoHide()) - { - hide(); - m_alreadyHidden = true; - } - } + appendLogRaw(line); } } } @@ -344,9 +322,29 @@ void MainWindow::appendLogError(const QString& text) void MainWindow::appendLogRaw(const QString& text) { - foreach(QString line, text.split(QRegExp("\r|\n|\r\n"))) - if (!line.isEmpty()) + foreach(QString line, text.split(QRegExp("\r|\n|\r\n"))) { + if (!line.isEmpty()) { m_pLogOutput->append(line); + updateStateFromLogLine(line); + } + } +} + +void MainWindow::updateStateFromLogLine(const QString &line) +{ + // TODO: implement ipc connection state messages to replace this hack. + if (line.contains("started server") || + line.contains("connected to server")) + { + setSynergyState(synergyConnected); + + // only hide once after each new connection. + if (!m_alreadyHidden && appConfig().autoHide()) + { + hide(); + m_alreadyHidden = true; + } + } } void MainWindow::clearLog() @@ -435,15 +433,7 @@ void MainWindow::startSynergy() if (!m_pLogOutput->toPlainText().isEmpty()) appendLogRaw(""); - if (desktopMode) - { - appendLogNote("starting " + QString(synergyType() == synergyServer ? "server" : "client")); - } - - if (serviceMode) - { - appendLogNote("applying service mode: " + QString(synergyType() == synergyServer ? "server" : "client")); - } + appendLogNote("starting " + QString(synergyType() == synergyServer ? "server" : "client")); // show command if debug log level... if (appConfig().logLevel() >= 4) { @@ -575,7 +565,11 @@ bool MainWindow::serverArgs(QStringList& args, QString& app) void MainWindow::stopSynergy() { - if (synergyProcess()) + if (appConfig().processMode() == Service) { + // send empty command to stop service from laucning anything. + m_IpcClient.sendCommand("", m_ElevateProcess); + } + else if (synergyProcess()) { appendLogNote("stopping synergy"); @@ -583,10 +577,10 @@ void MainWindow::stopSynergy() synergyProcess()->close(); delete synergyProcess(); setSynergyProcess(NULL); - - setSynergyState(synergyDisconnected); } + setSynergyState(synergyDisconnected); + // HACK: deleting the object deletes the physical file, which is // bad, since it could be in use by the Windows service! //delete m_pTempConfigFile; @@ -617,10 +611,6 @@ void MainWindow::synergyFinished(int exitCode, QProcess::ExitStatus) void MainWindow::setSynergyState(qSynergyState state) { - // ignore state stuff when in service mode (for now anyway). - if (appConfig().processMode() == Service) - return; - if (synergyState() == state) return; @@ -747,3 +737,8 @@ void MainWindow::on_m_pElevateCheckBox_toggled(bool checked) settings().setValue("elevateChecked", checked); settings().sync(); } + +void MainWindow::on_m_pButtonApply_clicked() +{ + startSynergy(); +} diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index 5992feee..daf73a23 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -112,7 +112,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase void logOutput(); void logError(); void updateFound(const QString& version); - void refreshStartButton(); + void refreshApplyButton(); void wizardFinished(); protected: @@ -135,6 +135,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase void setStatus(const QString& status); void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors); void onModeChanged(bool firstRun, bool forceServiceApply); + void updateStateFromLogLine(const QString& line); private: QSettings& m_Settings; @@ -151,6 +152,9 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase IpcClient m_IpcClient; bool m_ElevateProcess; bool m_SuppressElevateWarning; + +private slots: + void on_m_pButtonApply_clicked(); }; #endif