From a0cc3d6e7fcfc90198a7ac8b1c5b4d19d5a78c29 Mon Sep 17 00:00:00 2001 From: Xinyu Hou Date: Thu, 27 Nov 2014 18:31:09 +0000 Subject: [PATCH] Made Bonjour install in another thread #4235 --- src/gui/gui.pro | 6 ++++-- src/gui/src/CommandProcess.cpp | 33 +++++++++++++++++++++++++++++ src/gui/src/CommandProcess.h | 38 ++++++++++++++++++++++++++++++++++ src/gui/src/MainWindow.cpp | 28 +++++++++++++++---------- 4 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 src/gui/src/CommandProcess.cpp create mode 100644 src/gui/src/CommandProcess.h diff --git a/src/gui/gui.pro b/src/gui/gui.pro index 917552aa..0576f266 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -49,7 +49,8 @@ SOURCES += src/main.cpp \ src/ZeroconfBrowser.cpp \ src/ZeroconfService.cpp \ src/DataDownloader.cpp \ - src/AddClientDialog.cpp + src/AddClientDialog.cpp \ + src/CommandProcess.cpp HEADERS += src/MainWindow.h \ src/AboutDialog.h \ src/ServerConfig.h \ @@ -84,7 +85,8 @@ HEADERS += src/MainWindow.h \ src/ZeroconfBrowser.h \ src/ZeroconfService.h \ src/DataDownloader.h \ - src/AddClientDialog.h + src/AddClientDialog.h \ + src/CommandProcess.h RESOURCES += res/Synergy.qrc RC_FILE = res/win/Synergy.rc macx { diff --git a/src/gui/src/CommandProcess.cpp b/src/gui/src/CommandProcess.cpp new file mode 100644 index 00000000..b3cda409 --- /dev/null +++ b/src/gui/src/CommandProcess.cpp @@ -0,0 +1,33 @@ +/* + * 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 "CommandProcess.h" + +#include + +CommandProcess::CommandProcess(QString cmd, QStringList arguments) : + m_Command(cmd), + m_Arguments(arguments) +{ +} + +void CommandProcess::run() +{ + QProcess process; + process.start(m_Command, m_Arguments); + process.waitForFinished(); +} diff --git a/src/gui/src/CommandProcess.h b/src/gui/src/CommandProcess.h new file mode 100644 index 00000000..ac81701c --- /dev/null +++ b/src/gui/src/CommandProcess.h @@ -0,0 +1,38 @@ +/* + * 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 COMMANDTHREAD_H +#define COMMANDTHREAD_H + +#include + +class CommandProcess : public QObject +{ + Q_OBJECT + +public: + CommandProcess(QString cmd, QStringList arguments); + +public slots: + void run(); + +private: + QString m_Command; + QStringList m_Arguments; +}; + +#endif // COMMANDTHREAD_H diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index cf9226f9..2f81dd4f 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -27,6 +27,7 @@ #include "SetupWizard.h" #include "ZeroconfService.h" #include "DataDownloader.h" +#include "CommandProcess.h" #include #include @@ -973,15 +974,17 @@ void MainWindow::on_m_pButtonApply_clicked() void MainWindow::on_m_pCheckBoxAutoConnect_toggled(bool checked) { - if (!isBonjourRunning() && checked && !m_SuppressAutoConnectWarning) { - int r = QMessageBox::information( - this, tr("Synergy"), - tr("Auto connect feature requires Bonjour.\n\n" - "Do you want to install Bonjour?"), - QMessageBox::Yes | QMessageBox::No); + if (!isBonjourRunning() && checked) { + if (!m_SuppressAutoConnectWarning) { + int r = QMessageBox::information( + this, tr("Synergy"), + tr("Auto connect feature requires Bonjour.\n\n" + "Do you want to install Bonjour?"), + QMessageBox::Yes | QMessageBox::No); - if (r == QMessageBox::Yes) { - downloadBonjour(); + if (r == QMessageBox::Yes) { + downloadBonjour(); + } } m_pCheckBoxAutoConnect->setChecked(false); @@ -1117,14 +1120,17 @@ void MainWindow::installBonjour() file.write(m_pDataDownloader->downloadedData()); file.close(); - QProcess process; QStringList arguments; arguments.append("/i"); QString winFilename = QDir::toNativeSeparators(filename); arguments.append(winFilename); arguments.append("/passive"); - process.start("msiexec", arguments); - process.waitForFinished(); + CommandProcess* cp = new CommandProcess("msiexec", arguments); + QThread* thread = new QThread; + cp->moveToThread(thread); + connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); + thread->start(); + QMetaObject::invokeMethod(cp, "run", Qt::QueuedConnection); m_DownloadMessageBox->hide(); #endif