From 588494a73028c8c8c96f3a06b70cd18229fd2e46 Mon Sep 17 00:00:00 2001 From: Xinyu Hou Date: Tue, 11 Nov 2014 15:57:25 +0000 Subject: [PATCH] Check is Bonjour running before update zeroconf --- src/gui/src/MainWindow.cpp | 40 +++++++++++++++++++++++--------------- src/gui/src/MainWindow.h | 2 +- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index c416c25c..d60852c8 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -75,8 +75,7 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) : m_pMenuEdit(NULL), m_pMenuWindow(NULL), m_pMenuHelp(NULL), - m_pZeroconfService(NULL), - m_BonjourRunning(true) + m_pZeroconfService(NULL) { setupUi(this); @@ -106,13 +105,7 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) : setMinimumSize(size()); #endif -#if defined(Q_OS_WIN) - m_BonjourRunning = isServiceRunning("Bonjour Service"); -#endif - - if (m_BonjourRunning) { - updateZeroconfService(); - } + updateZeroconfService(); m_pAutoConnectCheckBox->setChecked(appConfig.autoConnect()); } @@ -784,14 +777,16 @@ void MainWindow::changeEvent(QEvent* event) void MainWindow::updateZeroconfService() { - if (!m_AppConfig.wizardShouldRun()) { - if (m_pZeroconfService) { - delete m_pZeroconfService; - m_pZeroconfService = NULL; - } + if (isBonjourRunning()) { + if (!m_AppConfig.wizardShouldRun()) { + if (m_pZeroconfService) { + delete m_pZeroconfService; + m_pZeroconfService = NULL; + } - if (m_AppConfig.autoConnect() || synergyType() == synergyServer) { - m_pZeroconfService = new ZeroconfService(this); + if (m_AppConfig.autoConnect() || synergyType() == synergyServer) { + m_pZeroconfService = new ZeroconfService(this); + } } } } @@ -937,3 +932,16 @@ bool MainWindow::isServiceRunning(QString name) #endif return false; } + +bool MainWindow::isBonjourRunning() +{ + bool result = false; + +#if defined(Q_OS_WIN) + result = isServiceRunning("Bonjour Service"); +#else + result = true; +#endif + + return result; +} diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index ad581021..1221211f 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -147,6 +147,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase void changeEvent(QEvent* event); void retranslateMenuBar(); bool isServiceRunning(QString name); + bool isBonjourRunning(); private: QSettings& m_Settings; @@ -166,7 +167,6 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase QMenu* m_pMenuWindow; QMenu* m_pMenuHelp; ZeroconfService* m_pZeroconfService; - bool m_BonjourRunning; private slots: void on_m_pAutoConnectCheckBox_toggled(bool checked);