Added seamless download of Bonjour

This commit is contained in:
Xinyu Hou 2014-11-13 11:02:48 +00:00
parent f781cce156
commit 8503833e3d
5 changed files with 157 additions and 5 deletions

View File

@ -46,7 +46,8 @@ SOURCES += src/main.cpp \
src/ZeroconfThread.cpp \ src/ZeroconfThread.cpp \
src/ZeroconfRegister.cpp \ src/ZeroconfRegister.cpp \
src/ZeroconfBrowser.cpp \ src/ZeroconfBrowser.cpp \
src/ZeroconfService.cpp src/ZeroconfService.cpp \
src/DataDownloader.cpp
HEADERS += src/MainWindow.h \ HEADERS += src/MainWindow.h \
src/AboutDialog.h \ src/AboutDialog.h \
src/ServerConfig.h \ src/ServerConfig.h \
@ -79,7 +80,8 @@ HEADERS += src/MainWindow.h \
src/ZeroconfRegister.h \ src/ZeroconfRegister.h \
src/ZeroconfRecord.h \ src/ZeroconfRecord.h \
src/ZeroconfBrowser.h \ src/ZeroconfBrowser.h \
src/ZeroconfService.h src/ZeroconfService.h \
src/DataDownloader.h
RESOURCES += res/Synergy.qrc RESOURCES += res/Synergy.qrc
RC_FILE = res/win/Synergy.rc RC_FILE = res/win/Synergy.rc
macx { macx {

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef DATADOWNLOADER_H
#define DATADOWNLOADER_H
#include <QObject>
#include <QByteArray>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
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

View File

@ -26,6 +26,7 @@
#include "SettingsDialog.h" #include "SettingsDialog.h"
#include "SetupWizard.h" #include "SetupWizard.h"
#include "ZeroconfService.h" #include "ZeroconfService.h"
#include "DataDownloader.h"
#include <QtCore> #include <QtCore>
#include <QtGui> #include <QtGui>
@ -49,7 +50,6 @@
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
static const char synergyConfigName[] = "synergy.sgc"; static const char synergyConfigName[] = "synergy.sgc";
static const QString synergyConfigFilter(QObject::tr("Synergy Configurations (*.sgc);;All files (*.*)")); static const QString synergyConfigFilter(QObject::tr("Synergy Configurations (*.sgc);;All files (*.*)"));
static const char BonjourUrl[] = "http://synergy-project.org/bonjour/BonjourPSSetup.exe";
#else #else
static const char synergyConfigName[] = "synergy.conf"; static const char synergyConfigName[] = "synergy.conf";
static const QString synergyConfigFilter(QObject::tr("Synergy Configurations (*.conf);;All files (*.*)")); 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" ":/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) : MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
m_Settings(settings), m_Settings(settings),
m_AppConfig(appConfig), m_AppConfig(appConfig),
@ -77,7 +80,9 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
m_pMenuEdit(NULL), m_pMenuEdit(NULL),
m_pMenuWindow(NULL), m_pMenuWindow(NULL),
m_pMenuHelp(NULL), m_pMenuHelp(NULL),
m_pZeroconfService(NULL) m_pZeroconfService(NULL),
m_pDataDownloader(NULL),
m_DownloadMessageBox(NULL)
{ {
setupUi(this); setupUi(this);
@ -123,6 +128,10 @@ MainWindow::~MainWindow()
saveSettings(); saveSettings();
delete m_pZeroconfService; delete m_pZeroconfService;
if (m_DownloadMessageBox != NULL) {
delete m_DownloadMessageBox;
}
} }
void MainWindow::open() void MainWindow::open()
@ -972,10 +981,53 @@ bool MainWindow::isBonjourRunning()
void MainWindow::downloadBonjour() void MainWindow::downloadBonjour()
{ {
#if defined(Q_OS_WIN) #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 #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() void MainWindow::promptAutoConnect()
{ {
int r = QMessageBox::warning( int r = QMessageBox::warning(

View File

@ -45,11 +45,13 @@ class QTabWidget;
class QCheckBox; class QCheckBox;
class QRadioButton; class QRadioButton;
class QTemporaryFile; class QTemporaryFile;
class QMessageBox;
class LogDialog; class LogDialog;
class QSynergyApplication; class QSynergyApplication;
class SetupWizard; class SetupWizard;
class ZeroconfService; class ZeroconfService;
class DataDownloader;
class MainWindow : public QMainWindow, public Ui::MainWindowBase class MainWindow : public QMainWindow, public Ui::MainWindowBase
{ {
@ -169,10 +171,13 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
QMenu* m_pMenuWindow; QMenu* m_pMenuWindow;
QMenu* m_pMenuHelp; QMenu* m_pMenuHelp;
ZeroconfService* m_pZeroconfService; ZeroconfService* m_pZeroconfService;
DataDownloader* m_pDataDownloader;
QMessageBox* m_DownloadMessageBox;
private slots: private slots:
void on_m_pAutoConnectCheckBox_toggled(bool checked); void on_m_pAutoConnectCheckBox_toggled(bool checked);
void on_m_pButtonApply_clicked(); void on_m_pButtonApply_clicked();
void installBonjour();
}; };
#endif #endif