From 8503833e3d491096f6e6355d7b3a142405322782 Mon Sep 17 00:00:00 2001 From: Xinyu Hou Date: Thu, 13 Nov 2014 11:02:48 +0000 Subject: [PATCH] Added seamless download of Bonjour --- src/gui/gui.pro | 6 ++-- src/gui/src/DataDownloader.cpp | 45 ++++++++++++++++++++++++++ src/gui/src/DataDownloader.h | 48 ++++++++++++++++++++++++++++ src/gui/src/MainWindow.cpp | 58 ++++++++++++++++++++++++++++++++-- src/gui/src/MainWindow.h | 5 +++ 5 files changed, 157 insertions(+), 5 deletions(-) create mode 100644 src/gui/src/DataDownloader.cpp create mode 100644 src/gui/src/DataDownloader.h diff --git a/src/gui/gui.pro b/src/gui/gui.pro index d5613988..a2b43e97 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -46,7 +46,8 @@ SOURCES += src/main.cpp \ src/ZeroconfThread.cpp \ src/ZeroconfRegister.cpp \ src/ZeroconfBrowser.cpp \ - src/ZeroconfService.cpp + src/ZeroconfService.cpp \ + src/DataDownloader.cpp HEADERS += src/MainWindow.h \ src/AboutDialog.h \ src/ServerConfig.h \ @@ -79,7 +80,8 @@ HEADERS += src/MainWindow.h \ src/ZeroconfRegister.h \ src/ZeroconfRecord.h \ src/ZeroconfBrowser.h \ - src/ZeroconfService.h + src/ZeroconfService.h \ + src/DataDownloader.h RESOURCES += res/Synergy.qrc RC_FILE = res/win/Synergy.rc macx { diff --git a/src/gui/src/DataDownloader.cpp b/src/gui/src/DataDownloader.cpp new file mode 100644 index 00000000..739c4e9e --- /dev/null +++ b/src/gui/src/DataDownloader.cpp @@ -0,0 +1,45 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2014 Synergy Si, Inc. + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file COPYING that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "DataDownloader.h" + +DataDownloader::DataDownloader(QUrl url, QObject* parent) : + QObject(parent) +{ + connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)), + SLOT(fileDownloaded(QNetworkReply*))); + + QNetworkRequest request(url); + m_WebCtrl.get(request); +} + +DataDownloader::~DataDownloader() +{ + +} + +void DataDownloader::fileDownloaded(QNetworkReply* reply) +{ + m_DownloadedData = reply->readAll(); + reply->deleteLater(); + emit downloaded(); +} + +QByteArray DataDownloader::downloadedData() const +{ + return m_DownloadedData; +} diff --git a/src/gui/src/DataDownloader.h b/src/gui/src/DataDownloader.h new file mode 100644 index 00000000..ca27e56d --- /dev/null +++ b/src/gui/src/DataDownloader.h @@ -0,0 +1,48 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2014 Synergy Si, Inc. + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file COPYING that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef DATADOWNLOADER_H +#define DATADOWNLOADER_H + +#include +#include +#include +#include +#include + +class DataDownloader : public QObject +{ + Q_OBJECT +public: + explicit DataDownloader(QUrl url, QObject* parent = 0); + virtual ~DataDownloader(); + + QByteArray downloadedData() const; + +signals: + void downloaded(); + +private slots: + void fileDownloaded(QNetworkReply* reply); + +private: + + QNetworkAccessManager m_WebCtrl; + QByteArray m_DownloadedData; +}; + +#endif // DATADOWNLOADER_H diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 8522b98c..715d3fe4 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -26,6 +26,7 @@ #include "SettingsDialog.h" #include "SetupWizard.h" #include "ZeroconfService.h" +#include "DataDownloader.h" #include #include @@ -49,7 +50,6 @@ #if defined(Q_OS_WIN) static const char synergyConfigName[] = "synergy.sgc"; static const QString synergyConfigFilter(QObject::tr("Synergy Configurations (*.sgc);;All files (*.*)")); -static const char BonjourUrl[] = "http://synergy-project.org/bonjour/BonjourPSSetup.exe"; #else static const char synergyConfigName[] = "synergy.conf"; static const QString synergyConfigFilter(QObject::tr("Synergy Configurations (*.conf);;All files (*.*)")); @@ -62,6 +62,9 @@ static const char* synergyIconFiles[] = ":/res/icons/16x16/synergy-connected.png" }; +static const char bonjourUrl[] = "http://synergy-project.org/bonjour/BonjourPSSetup.exe"; +static const char bonjourInstaller[] = "BonjourSetup.exe"; + MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) : m_Settings(settings), m_AppConfig(appConfig), @@ -77,7 +80,9 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) : m_pMenuEdit(NULL), m_pMenuWindow(NULL), m_pMenuHelp(NULL), - m_pZeroconfService(NULL) + m_pZeroconfService(NULL), + m_pDataDownloader(NULL), + m_DownloadMessageBox(NULL) { setupUi(this); @@ -123,6 +128,10 @@ MainWindow::~MainWindow() saveSettings(); delete m_pZeroconfService; + + if (m_DownloadMessageBox != NULL) { + delete m_DownloadMessageBox; + } } void MainWindow::open() @@ -972,10 +981,53 @@ bool MainWindow::isBonjourRunning() void MainWindow::downloadBonjour() { #if defined(Q_OS_WIN) - QDesktopServices::openUrl(QUrl(BonjourUrl)); + QUrl url(bonjourUrl); + if (m_pDataDownloader != NULL) { + delete m_pDataDownloader; + m_pDataDownloader = NULL; + } + + m_pDataDownloader = new DataDownloader(url, this); + + if (m_DownloadMessageBox == NULL) { + m_DownloadMessageBox = new QMessageBox(); + m_DownloadMessageBox->setModal(false); + m_DownloadMessageBox->setStandardButtons(0); + m_DownloadMessageBox->setText("Installing Bonjour"); + m_DownloadMessageBox->resize(100, 10); + } + + m_DownloadMessageBox->show(); + + connect(m_pDataDownloader, SIGNAL(downloaded()), SLOT(installBonjour())); #endif } +void MainWindow::installBonjour() +{ + QString tempLocation = QDesktopServices::storageLocation( + QDesktopServices::TempLocation); + QString filename = tempLocation; + filename.append("\\").append(bonjourInstaller); + QFile file(filename); + if (!file.open(QIODevice::WriteOnly)) { + m_DownloadMessageBox->hide(); + + QMessageBox::critical( + this, "Synergy", + "Failed to download Bonjour installer to location: " + + tempLocation + "\n" + "Please download the installer manually from this link: \n" + + bonjourUrl); + return; + } + + file.write(m_pDataDownloader->downloadedData()); + file.close(); + + m_DownloadMessageBox->hide(); +} + void MainWindow::promptAutoConnect() { int r = QMessageBox::warning( diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index ac3aba8a..a0669741 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -45,11 +45,13 @@ class QTabWidget; class QCheckBox; class QRadioButton; class QTemporaryFile; +class QMessageBox; class LogDialog; class QSynergyApplication; class SetupWizard; class ZeroconfService; +class DataDownloader; class MainWindow : public QMainWindow, public Ui::MainWindowBase { @@ -169,10 +171,13 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase QMenu* m_pMenuWindow; QMenu* m_pMenuHelp; ZeroconfService* m_pZeroconfService; + DataDownloader* m_pDataDownloader; + QMessageBox* m_DownloadMessageBox; private slots: void on_m_pAutoConnectCheckBox_toggled(bool checked); void on_m_pButtonApply_clicked(); + void installBonjour(); }; #endif