diff --git a/src/gui/src/BonjourWindows.cpp b/src/gui/src/BonjourWindows.cpp index 09b82281..b16a0c78 100644 --- a/src/gui/src/BonjourWindows.cpp +++ b/src/gui/src/BonjourWindows.cpp @@ -34,12 +34,16 @@ #define WIN32_LEAN_AND_MEAN #include -BonjourWindows::BonjourWindows(SettingsDialog* settingsDialog, MainWindow* mainWindow) : +BonjourWindows::BonjourWindows( + SettingsDialog* settingsDialog, + MainWindow* mainWindow, + AppConfig& appConfig) : m_pSettingsDialog(settingsDialog), m_pMainWindow(mainWindow), m_pBonjourInstall(nullptr), m_pDownloadMessageBox(nullptr), - m_pDataDownloader(nullptr) + m_pDataDownloader(nullptr), + m_appConfig(appConfig) { } @@ -58,17 +62,17 @@ BonjourWindows::~BonjourWindows() } } -void BonjourWindows::download() +void BonjourWindows::downloadAndInstall() { QUrl url; int arch = getProcessorArch(); if (arch == kProcessorArchWin32) { url.setUrl(bonjourBaseUrl + bonjourFilename32); - m_pMainWindow->appendLogInfo("downloading 32-bit bonjour"); + m_pMainWindow->appendLogInfo("downloading bonjour (32-bit)"); } else if (arch == kProcessorArchWin64) { url.setUrl(bonjourBaseUrl + bonjourFilename64); - m_pMainWindow->appendLogInfo("downloading 64-bit bonjour"); + m_pMainWindow->appendLogInfo("downloading bonjour (64-bit)"); } else { QMessageBox::critical( @@ -79,7 +83,7 @@ void BonjourWindows::download() if (m_pDataDownloader == nullptr) { m_pDataDownloader = new DataDownloader(this); - connect(m_pDataDownloader, SIGNAL(isComplete()), SLOT(installBonjour())); + connect(m_pDataDownloader, SIGNAL(isComplete()), SLOT(downloadFinished())); } m_pDataDownloader->download(url); @@ -90,7 +94,7 @@ void BonjourWindows::download() } m_pDownloadMessageBox = new QMessageBox(m_pSettingsDialog); - m_pDownloadMessageBox->setWindowTitle("Synergy"); + m_pDownloadMessageBox->setWindowTitle("Synergy Auto Config"); m_pDownloadMessageBox->setIcon(QMessageBox::Information); m_pDownloadMessageBox->setText("Installing Bonjour, please wait..."); QAbstractButton* cancel = m_pDownloadMessageBox->addButton( @@ -103,8 +107,16 @@ void BonjourWindows::download() } } +void BonjourWindows::downloadFinished() +{ + m_pMainWindow->appendLogInfo("bonjour downloaded"); + install(); +} + void BonjourWindows::install() { + m_pMainWindow->appendLogInfo("installing bonjour"); + QString tempLocation = QStandardPaths::writableLocation(QStandardPaths::TempLocation); QString filename = tempLocation; @@ -137,8 +149,7 @@ void BonjourWindows::install() m_pBonjourInstall = new CommandProcess("msiexec", arguments); QThread* thread = new QThread; - connect(m_pBonjourInstall, SIGNAL(finished()), this, - SLOT(bonjourInstallFinished())); + connect(m_pBonjourInstall, SIGNAL(finished()), this, SLOT(installFinished())); connect(m_pBonjourInstall, SIGNAL(finished()), thread, SLOT(quit())); connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); @@ -184,7 +195,8 @@ bool BonjourWindows::isRunning() const void BonjourWindows::installFinished() { - m_pMainWindow->appendLogInfo("bonjour install finished"); + m_pMainWindow->appendLogInfo("bonjour installed"); + m_appConfig.setAutoConfig(true); m_pSettingsDialog->allowAutoConfig(); } diff --git a/src/gui/src/BonjourWindows.h b/src/gui/src/BonjourWindows.h index 031d0f49..7c2cbe22 100644 --- a/src/gui/src/BonjourWindows.h +++ b/src/gui/src/BonjourWindows.h @@ -32,29 +32,34 @@ class SettingsDialog; class MainWindow; class CommandProcess; class DataDownloader; +class AppConfig; class BonjourWindows : public QObject { Q_OBJECT public: - BonjourWindows(SettingsDialog* settingsDialog, MainWindow* mainWindow); + BonjourWindows(SettingsDialog* settingsDialog, MainWindow* mainWindow, AppConfig& appConfig); virtual ~BonjourWindows(); public: - void download(); - void install(); + void downloadAndInstall(); bool isRunning() const; protected slots: + void downloadFinished(); void installFinished(); +private: + void install(); + private: SettingsDialog* m_pSettingsDialog; MainWindow* m_pMainWindow; CommandProcess* m_pBonjourInstall; QMessageBox* m_pDownloadMessageBox; DataDownloader* m_pDataDownloader; + AppConfig& m_appConfig; }; #endif // Q_OS_WIN diff --git a/src/gui/src/DataDownloader.cpp b/src/gui/src/DataDownloader.cpp index 4f778489..215adc8f 100644 --- a/src/gui/src/DataDownloader.cpp +++ b/src/gui/src/DataDownloader.cpp @@ -34,6 +34,7 @@ void DataDownloader::complete(QNetworkReply* reply) { m_Data = reply->readAll(); reply->deleteLater(); + m_pReply = nullptr; if (!m_Data.isEmpty()) { m_IsFinished = true; @@ -48,7 +49,9 @@ QByteArray DataDownloader::data() const void DataDownloader::cancel() { - m_pReply->abort(); + if (m_pReply != nullptr) { + m_pReply->abort(); + } } void DataDownloader::download(QUrl url) diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index c6a8f925..ce47b315 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -97,12 +97,14 @@ MainWindow::MainWindow (QSettings& settings, AppConfig& appConfig, m_pMenuWindow(NULL), m_pMenuHelp(NULL), m_pCancelButton(NULL), - m_SuppressAutoConfigWarning(false), - m_SuppressEmptyServerWarning(false), m_ExpectedRunningState(kStopped), m_pSslCertificate(NULL), m_SecureSocket(false) { +#ifndef SYNERGY_ENTERPRISE + m_pZeroconf = new Zeroconf(this); +#endif + setupUi(this); createMenuBar(); @@ -131,11 +133,6 @@ MainWindow::MainWindow (QSettings& settings, AppConfig& appConfig, setMinimumSize(size()); #endif - m_SuppressAutoConfigWarning = true; - m_pLabelAutoDetected->setVisible(appConfig.autoConfig()); - m_pComboServerList->setVisible(appConfig.autoConfig()); - m_SuppressAutoConfigWarning = false; - m_trialWidget->hide(); // hide padlock icon @@ -179,10 +176,8 @@ MainWindow::MainWindow (QSettings& settings, AppConfig& appConfig, #endif #ifndef SYNERGY_ENTERPRISE - m_pZeroconf = new Zeroconf(this); - if (m_AppConfig->autoConfig()) { - m_pZeroconf->startService(); - } + updateZeroconfService(); + updateAutoConfigWidgets(); #endif } @@ -216,9 +211,7 @@ void MainWindow::open() // auto hiding before the user has configured synergy (which of course // confuses first time users, who think synergy has crashed). if (appConfig().startedBefore() && appConfig().processMode() == Desktop) { - m_SuppressEmptyServerWarning = true; startSynergy(); - m_SuppressEmptyServerWarning = false; } } @@ -761,15 +754,13 @@ bool MainWindow::clientArgs(QStringList& args, QString& app) if (m_pLineEditHostname->text().isEmpty()) { show(); - if (!m_SuppressEmptyServerWarning) { - QMessageBox::warning(this, tr("Hostname is empty"), - tr("Please fill in a hostname for the synergy client to connect to.")); - } + QMessageBox::warning( + this, tr("Hostname is empty"), + tr("Please fill in a hostname for the synergy client to connect to.")); return false; } args << m_pLineEditHostname->text() + ":" + QString::number(appConfig().port()); - return true; } @@ -1080,8 +1071,12 @@ void MainWindow::changeEvent(QEvent* event) void MainWindow::zeroconfServerDetected(const QString name) { + // don't add yourself to the server list. + if (getIPAddresses().contains(name)) { + return; + } + if (m_pComboServerList->findText(name) == -1) { - // Note: the first added item triggers startSynergy m_pComboServerList->addItem(name); } @@ -1180,6 +1175,10 @@ MainWindow::licenseManager() const void MainWindow::on_m_pGroupClient_toggled(bool on) { m_pGroupServer->setChecked(!on); + + // only call in either client or server toggle, but not both + // since the toggle functions call eachother indirectly. + updateZeroconfService(); } void MainWindow::on_m_pGroupServer_toggled(bool on) @@ -1219,9 +1218,43 @@ void MainWindow::on_m_pActionAbout_triggered() dlg.exec(); } +void MainWindow::updateZeroconfService() +{ +#ifndef SYNERGY_ENTERPRISE + if (m_pZeroconf != nullptr) { + if (appConfig().autoConfig()) { + m_pZeroconf->startService(); + } + else { + m_pZeroconf->stopService(); + } + } +#endif +} + +void MainWindow::updateAutoConfigWidgets() +{ + if (appConfig().autoConfig()) { + m_pLabelAutoDetected->show(); + m_pComboServerList->show(); + + m_pLabelServerName->hide(); + m_pLineEditHostname->hide(); + + } + else { + m_pLabelServerName->show(); + m_pLineEditHostname->show(); + + m_pLabelAutoDetected->hide(); + m_pComboServerList->hide(); + } +} + void MainWindow::on_m_pActionSettings_triggered() { ProcessMode lastProcessMode = appConfig().processMode(); + bool lastAutoConfig = appConfig().autoConfig(); SettingsDialog dlg(this, appConfig()); dlg.exec(); @@ -1230,6 +1263,11 @@ void MainWindow::on_m_pActionSettings_triggered() { onModeChanged(true, true); } + + if (lastAutoConfig != appConfig().autoConfig()) { + updateAutoConfigWidgets(); + updateZeroconfService(); + } } void MainWindow::autoAddScreen(const QString name) @@ -1292,13 +1330,6 @@ void MainWindow::on_m_pButtonApply_clicked() restartSynergy(); } -void MainWindow::on_m_pComboServerList_currentIndexChanged(const QString &arg1) -{ - if (m_pComboServerList->count() != 0) { - restartSynergy(); - } -} - #ifndef SYNERGY_ENTERPRISE int MainWindow::raiseActivationDialog() { diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index 84c1096c..4f881073 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -125,6 +125,8 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase int raiseActivationDialog(); #endif + void updateZeroconfService(); + public slots: void setEdition(Edition edition); #ifndef SYNERGY_ENTERPRISE @@ -224,19 +226,17 @@ public slots: QMenu* m_pMenuWindow; QMenu* m_pMenuHelp; QAbstractButton* m_pCancelButton; - bool m_SuppressAutoConfigWarning; - bool m_SuppressEmptyServerWarning; qRuningState m_ExpectedRunningState; QMutex m_StopDesktopMutex; SslCertificate* m_pSslCertificate; bool m_SecureSocket; + void updateAutoConfigWidgets(); + private slots: void on_m_pButtonApply_clicked(); void on_windowShown(); - void on_m_pComboServerList_currentIndexChanged(const QString &arg1); - signals: void windowShown(); }; diff --git a/src/gui/src/MainWindowBase.ui b/src/gui/src/MainWindowBase.ui index 429dfcd2..b4f6bb1c 100644 --- a/src/gui/src/MainWindowBase.ui +++ b/src/gui/src/MainWindowBase.ui @@ -289,9 +289,9 @@ QFormLayout::AllNonFixedFieldsGrow - + - Screen name: + Client name: @@ -305,7 +305,7 @@ - &Server IP: + &Server: m_pLineEditHostname @@ -313,7 +313,11 @@ - + + + Hostname or IP address of the server computer. + + @@ -334,7 +338,7 @@ - Auto detected: + Server: diff --git a/src/gui/src/SettingsDialog.cpp b/src/gui/src/SettingsDialog.cpp index 5ca61c3c..50f3ab23 100644 --- a/src/gui/src/SettingsDialog.cpp +++ b/src/gui/src/SettingsDialog.cpp @@ -59,10 +59,9 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) : m_pCheckBoxAutoHide->setChecked(appConfig().getAutoHide()); #if defined(Q_OS_WIN) - m_pBonjourWindows = new BonjourWindows(this, m_pMainWindow); + m_pBonjourWindows = new BonjourWindows(this, m_pMainWindow, m_appConfig); if (m_pBonjourWindows->isRunning()) { allowAutoConfig(); - m_pCheckBoxAutoConfig->setChecked(m_appConfig.autoConfig()); } m_pComboElevate->setCurrentIndex(static_cast(appConfig().elevateMode())); @@ -93,6 +92,8 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) : m_pCheckBoxEnableCrypto->setEnabled(isPro); m_pLabelProUpgrade->setVisible(!isPro); + m_pCheckBoxAutoConfig->setChecked(appConfig().autoConfig()); + #endif } @@ -107,6 +108,7 @@ void SettingsDialog::accept() appConfig().setLanguage(m_pComboLanguage->itemData(m_pComboLanguage->currentIndex()).toString()); appConfig().setElevateMode(static_cast(m_pComboElevate->currentIndex())); appConfig().setAutoHide(m_pCheckBoxAutoHide->isChecked()); + appConfig().setAutoConfig(m_pCheckBoxAutoConfig->isChecked()); appConfig().saveSettings(); QDialog::accept(); } @@ -148,6 +150,7 @@ void SettingsDialog::allowAutoConfig() { m_pLabelInstallBonjour->hide(); m_pCheckBoxAutoConfig->setEnabled(true); + m_pCheckBoxAutoConfig->setChecked(m_appConfig.autoConfig()); } void SettingsDialog::on_m_pCheckBoxLogToFile_stateChanged(int i) @@ -191,18 +194,6 @@ void SettingsDialog::on_m_pCheckBoxEnableCrypto_toggled(bool checked) void SettingsDialog::on_m_pLabelInstallBonjour_linkActivated(const QString&) { #if defined(Q_OS_WIN) - m_pBonjourWindows->download(); -#endif -} - -void SettingsDialog::on_m_pCheckBoxAutoConfig_toggled(bool checked) -{ -#ifndef SYNERGY_ENTERPRISE - if (checked) { - m_pMainWindow->zeroconf().startService(); - } - else { - m_pMainWindow->zeroconf().stopService(); - } + m_pBonjourWindows->downloadAndInstall(); #endif } diff --git a/src/gui/src/SettingsDialog.h b/src/gui/src/SettingsDialog.h index 5a524596..738bb457 100644 --- a/src/gui/src/SettingsDialog.h +++ b/src/gui/src/SettingsDialog.h @@ -58,7 +58,6 @@ class SettingsDialog : public QDialog, public Ui::SettingsDialogBase void on_m_pCheckBoxLogToFile_stateChanged(int ); void on_m_pButtonBrowseLog_clicked(); void on_m_pLabelInstallBonjour_linkActivated(const QString &link); - void on_m_pCheckBoxAutoConfig_toggled(bool checked); }; #endif diff --git a/src/gui/src/SettingsDialogBase.ui b/src/gui/src/SettingsDialogBase.ui index a1d446a1..b85417c2 100644 --- a/src/gui/src/SettingsDialogBase.ui +++ b/src/gui/src/SettingsDialogBase.ui @@ -2,6 +2,14 @@ SettingsDialogBase + + + 0 + 0 + 357 + 496 + + Settings @@ -154,12 +162,12 @@ Qt::Vertical - QSizePolicy::MinimumExpanding + QSizePolicy::Minimum 20 - 15 + 10 @@ -230,9 +238,6 @@ Qt::RichText - - true - @@ -243,6 +248,9 @@ Qt::RichText + + true + @@ -256,12 +264,12 @@ Qt::Vertical - QSizePolicy::MinimumExpanding + QSizePolicy::Minimum 20 - 15 + 10 @@ -362,7 +370,7 @@ 20 - 15 + 10 diff --git a/src/gui/src/Zeroconf.cpp b/src/gui/src/Zeroconf.cpp index 65eb81f7..b2a0e6b7 100644 --- a/src/gui/src/Zeroconf.cpp +++ b/src/gui/src/Zeroconf.cpp @@ -33,14 +33,26 @@ Zeroconf::~Zeroconf() void Zeroconf::startService() { - stopService(); + if (m_pZeroconfService != nullptr) { + m_pMainWindow->appendLogInfo("restarting zeroconf service"); + delete m_pZeroconfService; + m_pZeroconfService = nullptr; + } + else { + m_pMainWindow->appendLogInfo("starting zeroconf service"); + } + m_pZeroconfService = new ZeroconfService(m_pMainWindow); + + m_pMainWindow->appendLogInfo("started zeroconf service"); } void Zeroconf::stopService() { if (m_pZeroconfService != nullptr) { + m_pMainWindow->appendLogInfo("stopping zeroconf service"); delete m_pZeroconfService; m_pZeroconfService = nullptr; + m_pMainWindow->appendLogInfo("stopped zeroconf service"); } }