2012-06-10 16:50:54 +00:00
/*
* synergy - - mouse and keyboard sharing utility
2014-11-02 12:12:05 +00:00
* Copyright ( C ) 2012 Synergy Si Ltd .
2012-06-10 16:50:54 +00:00
* Copyright ( C ) 2008 Volker Lanz ( vl @ fidra . de )
2015-07-29 21:34:21 +00:00
*
2012-06-10 16:50:54 +00:00
* This package is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
2015-05-03 02:33:52 +00:00
* found in the file LICENSE that should have accompanied this file .
2015-07-29 21:34:21 +00:00
*
2012-06-10 16:50:54 +00:00
* 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/>.
*/
2016-09-06 15:13:50 +00:00
# define DOWNLOAD_URL "http: //symless.com/?source=gui"
2012-06-10 16:50:54 +00:00
2012-07-03 14:15:05 +00:00
# include <iostream>
2012-06-10 16:50:54 +00:00
# include "MainWindow.h"
2015-04-15 12:09:22 +00:00
# include "Fingerprint.h"
2015-04-16 16:12:42 +00:00
# include "PluginManager.h"
2012-06-10 16:50:54 +00:00
# include "AboutDialog.h"
# include "ServerConfigDialog.h"
# include "SettingsDialog.h"
# include "SetupWizard.h"
2014-08-21 17:32:40 +00:00
# include "ZeroconfService.h"
2014-11-13 11:02:48 +00:00
# include "DataDownloader.h"
2014-11-27 18:31:09 +00:00
# include "CommandProcess.h"
2015-10-23 22:37:16 +00:00
# include "SubscriptionManager.h"
2015-02-05 14:17:34 +00:00
# include "EditionType.h"
# include "QUtility.h"
2015-02-09 15:37:47 +00:00
# include "ProcessorArch.h"
2012-06-10 16:50:54 +00:00
# include <QtCore>
# include <QtGui>
# include <QtNetwork>
# include <QNetworkAccessManager>
2014-02-14 16:21:02 +00:00
# include <QMenu>
# include <QMenuBar>
# include <QMessageBox>
# include <QFileDialog>
2014-11-12 14:21:54 +00:00
# include <QDesktopServices>
2012-06-10 16:50:54 +00:00
# if defined(Q_OS_MAC)
# include <ApplicationServices/ApplicationServices.h>
# endif
# if defined(Q_OS_WIN)
2014-11-26 15:05:53 +00:00
# define _WIN32_WINNT 0x0501
2012-06-10 16:50:54 +00:00
# define WIN32_LEAN_AND_MEAN
# include <Windows.h>
# endif
# if defined(Q_OS_WIN)
static const char synergyConfigName [ ] = " synergy.sgc " ;
static const QString synergyConfigFilter ( QObject : : tr ( " Synergy Configurations (*.sgc) ; ; All files ( * . * ) " )) ;
2016-09-06 15:13:50 +00:00
static QString bonjourBaseUrl = " http://symless.com/bonjour/ " ;
2015-02-09 15:37:47 +00:00
static const char bonjourFilename32 [ ] = " Bonjour.msi " ;
static const char bonjourFilename64 [ ] = " Bonjour64.msi " ;
static const char bonjourTargetFilename [ ] = " Bonjour.msi " ;
2012-06-10 16:50:54 +00:00
# else
static const char synergyConfigName [ ] = " synergy.conf " ;
static const QString synergyConfigFilter ( QObject : : tr ( " Synergy Configurations (*.conf) ; ; All files ( * . * ) " )) ;
# endif
static const char * synergyIconFiles [ ] =
{
" :/res/icons/16x16/synergy-disconnected.png " ,
" :/res/icons/16x16/synergy-disconnected.png " ,
2015-06-01 22:59:59 +00:00
" :/res/icons/16x16/synergy-connected.png " ,
" :/res/icons/16x16/synergy-transfering.png "
2012-06-10 16:50:54 +00:00
} ;
MainWindow : : MainWindow ( QSettings & settings , AppConfig & appConfig ) :
m_Settings ( settings ) ,
m_AppConfig ( appConfig ) ,
m_pSynergy ( NULL ) ,
m_SynergyState ( synergyDisconnected ) ,
2014-08-26 14:49:27 +00:00
m_ServerConfig ( & m_Settings , 5 , 3 , m_AppConfig . screenName ( ) , this ) ,
2012-06-10 16:50:54 +00:00
m_pTempConfigFile ( NULL ) ,
m_pTrayIcon ( NULL ) ,
m_pTrayIconMenu ( NULL ) ,
2013-05-29 20:46:24 +00:00
m_AlreadyHidden ( false ) ,
m_pMenuBar ( NULL ) ,
m_pMenuFile ( NULL ) ,
m_pMenuEdit ( NULL ) ,
m_pMenuWindow ( NULL ) ,
2014-08-21 17:32:40 +00:00
m_pMenuHelp ( NULL ) ,
2014-11-13 11:02:48 +00:00
m_pZeroconfService ( NULL ) ,
m_pDataDownloader ( NULL ) ,
2014-11-13 12:09:11 +00:00
m_DownloadMessageBox ( NULL ) ,
2014-11-27 17:32:04 +00:00
m_pCancelButton ( NULL ) ,
2014-11-28 12:57:57 +00:00
m_SuppressAutoConfigWarning ( false ) ,
2014-12-02 15:03:19 +00:00
m_BonjourInstall ( NULL ) ,
2015-07-29 01:01:39 +00:00
m_SuppressEmptyServerWarning ( false ) ,
m_ExpectedRunningState ( kStopped )
2012-06-10 16:50:54 +00:00
{
setupUi ( this ) ;
createMenuBar ( ) ;
loadSettings ( ) ;
initConnections ( ) ;
2013-06-05 14:47:42 +00:00
m_pWidgetUpdate - > hide ( ) ;
2013-05-29 20:46:24 +00:00
m_VersionChecker . setApp ( appPath ( appConfig . synergycName ( ) ) ) ;
2012-07-28 20:41:40 +00:00
m_pLabelScreenName - > setText ( getScreenName ( ) ) ;
m_pLabelIpAddresses - > setText ( getIPAddresses ( ) ) ;
2012-06-10 16:50:54 +00:00
2012-07-14 17:01:29 +00:00
# if defined(Q_OS_WIN)
2012-07-13 14:38:58 +00:00
// ipc must always be enabled, so that we can disable command when switching to desktop mode.
connect ( & m_IpcClient , SIGNAL ( readLogLine ( const QString & ) ) , this , SLOT ( appendLogRaw ( const QString & ) ) ) ;
connect ( & m_IpcClient , SIGNAL ( errorMessage ( const QString & ) ) , this , SLOT ( appendLogError ( const QString & ) ) ) ;
2012-07-14 17:01:29 +00:00
connect ( & m_IpcClient , SIGNAL ( infoMessage ( const QString & ) ) , this , SLOT ( appendLogNote ( const QString & ) ) ) ;
2012-07-13 14:38:58 +00:00
m_IpcClient . connectToHost ( ) ;
2012-07-14 17:01:29 +00:00
# endif
2012-07-29 00:10:18 +00:00
2014-02-14 16:21:02 +00:00
// change default size based on os
2012-07-29 00:10:18 +00:00
# if defined(Q_OS_MAC)
2012-07-30 16:11:28 +00:00
resize ( 720 , 550 ) ;
setMinimumSize ( size ( ) ) ;
# elif defined(Q_OS_LINUX)
resize ( 700 , 530 ) ;
setMinimumSize ( size ( ) ) ;
2012-07-29 00:10:18 +00:00
# endif
2014-08-21 17:32:40 +00:00
2014-11-28 10:51:52 +00:00
m_SuppressAutoConfigWarning = true ;
m_pCheckBoxAutoConfig - > setChecked ( appConfig . autoConfig ( ) ) ;
m_SuppressAutoConfigWarning = false ;
2014-11-18 15:29:31 +00:00
m_pComboServerList - > hide ( ) ;
2015-02-12 15:50:08 +00:00
2015-11-18 23:05:05 +00:00
setEdition ( m_AppConfig . edition ( ) ) ;
2015-02-13 10:14:11 +00:00
m_pLabelPadlock - > hide ( ) ;
2015-04-16 16:12:42 +00:00
2015-04-21 16:56:01 +00:00
updateLocalFingerprint ( ) ;
2012-06-10 16:50:54 +00:00
}
MainWindow : : ~ MainWindow ( )
{
2014-08-21 17:32:40 +00:00
if ( appConfig ( ) . processMode ( ) = = Desktop ) {
2015-07-29 01:01:39 +00:00
m_ExpectedRunningState = kStopped ;
2012-07-28 22:13:14 +00:00
stopDesktop ( ) ;
}
2012-06-10 16:50:54 +00:00
saveSettings ( ) ;
2014-08-21 17:32:40 +00:00
delete m_pZeroconfService ;
2014-11-13 11:02:48 +00:00
if ( m_DownloadMessageBox ! = NULL ) {
delete m_DownloadMessageBox ;
}
2014-11-28 12:57:57 +00:00
if ( m_BonjourInstall ! = NULL ) {
delete m_BonjourInstall ;
}
2012-06-10 16:50:54 +00:00
}
2014-03-21 09:22:18 +00:00
void MainWindow : : open ( )
2012-07-13 14:38:58 +00:00
{
createTrayIcon ( ) ;
2015-04-23 16:32:18 +00:00
if ( ! autoHide ( ) ) {
showNormal ( ) ;
}
2012-07-13 14:38:58 +00:00
2013-05-29 20:46:24 +00:00
m_VersionChecker . checkLatest ( ) ;
2014-01-27 16:50:41 +00:00
2014-11-28 10:51:52 +00:00
if ( ! appConfig ( ) . autoConfigPrompted ( ) ) {
promptAutoConfig ( ) ;
2014-11-25 15:21:30 +00:00
}
2014-03-21 09:22:18 +00:00
// only start if user has previously started. this stops the gui from
// 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 ) {
2014-12-02 15:03:19 +00:00
m_SuppressEmptyServerWarning = true ;
2014-01-27 16:50:41 +00:00
startSynergy ( ) ;
2014-12-02 15:03:19 +00:00
m_SuppressEmptyServerWarning = false ;
2014-01-27 16:50:41 +00:00
}
2012-07-13 14:38:58 +00:00
}
2012-07-28 22:13:14 +00:00
void MainWindow : : onModeChanged ( bool startDesktop , bool applyService )
2012-06-10 16:50:54 +00:00
{
2012-07-13 14:00:42 +00:00
if ( appConfig ( ) . processMode ( ) = = Service )
{
2012-07-13 18:44:43 +00:00
// ensure that the apply button actually does something, since desktop
// mode screws around with connecting/disconnecting the action.
disconnect ( m_pButtonToggleStart , SIGNAL ( clicked ( ) ) , m_pActionStartSynergy , SLOT ( trigger ( ) ) ) ;
connect ( m_pButtonToggleStart , SIGNAL ( clicked ( ) ) , m_pActionStartSynergy , SLOT ( trigger ( ) ) ) ;
2012-07-28 22:13:14 +00:00
if ( applyService )
2012-07-13 18:44:43 +00:00
{
2012-07-28 22:13:14 +00:00
stopDesktop ( ) ;
2012-07-13 18:44:43 +00:00
startSynergy ( ) ;
}
2012-07-13 14:00:42 +00:00
}
2012-07-28 22:13:14 +00:00
else if ( ( appConfig ( ) . processMode ( ) = = Desktop ) & & startDesktop )
2012-07-13 14:00:42 +00:00
{
2012-07-28 22:13:14 +00:00
stopService ( ) ;
2012-06-10 16:50:54 +00:00
startSynergy ( ) ;
2012-07-13 14:00:42 +00:00
}
2012-06-10 16:50:54 +00:00
}
void MainWindow : : setStatus ( const QString & status )
{
m_pStatusLabel - > setText ( status ) ;
}
void MainWindow : : createTrayIcon ( )
{
m_pTrayIconMenu = new QMenu ( this ) ;
m_pTrayIconMenu - > addAction ( m_pActionStartSynergy ) ;
m_pTrayIconMenu - > addAction ( m_pActionStopSynergy ) ;
m_pTrayIconMenu - > addSeparator ( ) ;
m_pTrayIconMenu - > addAction ( m_pActionMinimize ) ;
m_pTrayIconMenu - > addAction ( m_pActionRestore ) ;
m_pTrayIconMenu - > addSeparator ( ) ;
m_pTrayIconMenu - > addAction ( m_pActionQuit ) ;
m_pTrayIcon = new QSystemTrayIcon ( this ) ;
m_pTrayIcon - > setContextMenu ( m_pTrayIconMenu ) ;
2012-07-28 23:27:28 +00:00
connect ( m_pTrayIcon , SIGNAL ( activated ( QSystemTrayIcon : : ActivationReason ) ) ,
this , SLOT ( trayActivated ( QSystemTrayIcon : : ActivationReason ) ) ) ;
2012-06-10 16:50:54 +00:00
setIcon ( synergyDisconnected ) ;
m_pTrayIcon - > show ( ) ;
}
2013-05-29 20:46:24 +00:00
void MainWindow : : retranslateMenuBar ( )
{
m_pMenuFile - > setTitle ( tr ( " &File " ) ) ;
m_pMenuEdit - > setTitle ( tr ( " &Edit " ) ) ;
m_pMenuWindow - > setTitle ( tr ( " &Window " ) ) ;
m_pMenuHelp - > setTitle ( tr ( " &Help " ) ) ;
}
2012-06-10 16:50:54 +00:00
void MainWindow : : createMenuBar ( )
{
2013-05-29 20:46:24 +00:00
m_pMenuBar = new QMenuBar ( this ) ;
m_pMenuFile = new QMenu ( " " , m_pMenuBar ) ;
m_pMenuEdit = new QMenu ( " " , m_pMenuBar ) ;
m_pMenuWindow = new QMenu ( " " , m_pMenuBar ) ;
m_pMenuHelp = new QMenu ( " " , m_pMenuBar ) ;
retranslateMenuBar ( ) ;
2012-06-10 16:50:54 +00:00
2013-05-29 20:46:24 +00:00
m_pMenuBar - > addAction ( m_pMenuFile - > menuAction ( ) ) ;
m_pMenuBar - > addAction ( m_pMenuEdit - > menuAction ( ) ) ;
2012-06-10 16:50:54 +00:00
# if !defined(Q_OS_MAC)
2013-05-29 20:46:24 +00:00
m_pMenuBar - > addAction ( m_pMenuWindow - > menuAction ( ) ) ;
2012-06-10 16:50:54 +00:00
# endif
2013-05-29 20:46:24 +00:00
m_pMenuBar - > addAction ( m_pMenuHelp - > menuAction ( ) ) ;
2012-06-10 16:50:54 +00:00
2013-05-29 20:46:24 +00:00
m_pMenuFile - > addAction ( m_pActionStartSynergy ) ;
m_pMenuFile - > addAction ( m_pActionStopSynergy ) ;
m_pMenuFile - > addSeparator ( ) ;
m_pMenuFile - > addAction ( m_pActionWizard ) ;
m_pMenuFile - > addAction ( m_pActionSave ) ;
m_pMenuFile - > addSeparator ( ) ;
m_pMenuFile - > addAction ( m_pActionQuit ) ;
m_pMenuEdit - > addAction ( m_pActionSettings ) ;
m_pMenuWindow - > addAction ( m_pActionMinimize ) ;
m_pMenuWindow - > addAction ( m_pActionRestore ) ;
m_pMenuHelp - > addAction ( m_pActionAbout ) ;
2012-06-10 16:50:54 +00:00
2013-05-29 20:46:24 +00:00
setMenuBar ( m_pMenuBar ) ;
2012-06-10 16:50:54 +00:00
}
void MainWindow : : loadSettings ( )
{
// the next two must come BEFORE loading groupServerChecked and groupClientChecked or
// disabling and/or enabling the right widgets won't automatically work
2014-02-14 16:21:02 +00:00
m_pRadioExternalConfig - > setChecked ( settings ( ) . value ( " useExternalConfig " , false ) . toBool ( ) ) ;
m_pRadioInternalConfig - > setChecked ( settings ( ) . value ( " useInternalConfig " , true ) . toBool ( ) ) ;
2012-06-10 16:50:54 +00:00
m_pGroupServer - > setChecked ( settings ( ) . value ( " groupServerChecked " , false ) . toBool ( ) ) ;
m_pLineEditConfigFile - > setText ( settings ( ) . value ( " configFile " , QDir : : homePath ( ) + " / " + synergyConfigName ) . toString ( ) ) ;
m_pGroupClient - > setChecked ( settings ( ) . value ( " groupClientChecked " , true ) . toBool ( ) ) ;
m_pLineEditHostname - > setText ( settings ( ) . value ( " serverHostname " ) . toString ( ) ) ;
}
void MainWindow : : initConnections ( )
{
connect ( m_pActionMinimize , SIGNAL ( triggered ( ) ) , this , SLOT ( hide ( ) ) ) ;
connect ( m_pActionRestore , SIGNAL ( triggered ( ) ) , this , SLOT ( showNormal ( ) ) ) ;
connect ( m_pActionStartSynergy , SIGNAL ( triggered ( ) ) , this , SLOT ( startSynergy ( ) ) ) ;
connect ( m_pActionStopSynergy , SIGNAL ( triggered ( ) ) , this , SLOT ( stopSynergy ( ) ) ) ;
connect ( m_pActionQuit , SIGNAL ( triggered ( ) ) , qApp , SLOT ( quit ( ) ) ) ;
2013-05-29 20:46:24 +00:00
connect ( & m_VersionChecker , SIGNAL ( updateFound ( const QString & ) ) , this , SLOT ( updateFound ( const QString & ) ) ) ;
2012-06-10 16:50:54 +00:00
}
void MainWindow : : saveSettings ( )
{
// program settings
settings ( ) . setValue ( " groupServerChecked " , m_pGroupServer - > isChecked ( ) ) ;
2014-02-14 16:21:02 +00:00
settings ( ) . setValue ( " useExternalConfig " , m_pRadioExternalConfig - > isChecked ( ) ) ;
2012-06-10 16:50:54 +00:00
settings ( ) . setValue ( " configFile " , m_pLineEditConfigFile - > text ( ) ) ;
2014-02-14 16:21:02 +00:00
settings ( ) . setValue ( " useInternalConfig " , m_pRadioInternalConfig - > isChecked ( ) ) ;
2012-06-10 16:50:54 +00:00
settings ( ) . setValue ( " groupClientChecked " , m_pGroupClient - > isChecked ( ) ) ;
settings ( ) . setValue ( " serverHostname " , m_pLineEditHostname - > text ( ) ) ;
settings ( ) . sync ( ) ;
}
void MainWindow : : setIcon ( qSynergyState state )
{
QIcon icon ;
icon . addFile ( synergyIconFiles [ state ] ) ;
if ( m_pTrayIcon )
m_pTrayIcon - > setIcon ( icon ) ;
}
2012-07-28 23:27:28 +00:00
void MainWindow : : trayActivated ( QSystemTrayIcon : : ActivationReason reason )
2012-06-10 16:50:54 +00:00
{
2013-10-15 15:46:02 +00:00
# ifndef Q_OS_WIN
2012-06-10 16:50:54 +00:00
if ( reason = = QSystemTrayIcon : : DoubleClick )
{
if ( isVisible ( ) )
{
hide ( ) ;
}
else
{
showNormal ( ) ;
activateWindow ( ) ;
}
}
2013-10-15 15:46:02 +00:00
# endif
2012-06-10 16:50:54 +00:00
}
void MainWindow : : logOutput ( )
{
if ( m_pSynergy )
{
QString text ( m_pSynergy - > readAllStandardOutput ( ) ) ;
foreach ( QString line , text . split ( QRegExp ( " \r | \n | \r \n " ) ) )
{
if ( ! line . isEmpty ( ) )
{
2015-07-29 21:34:21 +00:00
appendLogRaw ( line ) ;
2012-06-10 16:50:54 +00:00
}
}
}
}
void MainWindow : : logError ( )
{
if ( m_pSynergy )
{
2012-07-04 23:27:03 +00:00
appendLogRaw ( m_pSynergy - > readAllStandardError ( ) ) ;
2012-06-10 16:50:54 +00:00
}
}
void MainWindow : : updateFound ( const QString & version )
{
2013-06-05 14:47:42 +00:00
m_pWidgetUpdate - > show ( ) ;
m_pLabelUpdate - > setText (
tr ( " <p>Your version of Synergy is out of date. "
" Version <b>%1</b> is now available to "
" <a href= \" %2 \" >download</a>.</p> " )
2013-06-05 15:41:14 +00:00
. arg ( version ) . arg ( DOWNLOAD_URL ) ) ;
2012-06-10 16:50:54 +00:00
}
2015-06-30 02:37:36 +00:00
void MainWindow : : appendLogInfo ( const QString & text )
2012-07-04 23:27:03 +00:00
{
2015-07-06 22:50:21 +00:00
appendLogRaw ( getTimeStamp ( ) + " INFO: " + text ) ;
2012-07-04 23:27:03 +00:00
}
2014-11-27 10:36:43 +00:00
void MainWindow : : appendLogDebug ( const QString & text ) {
2015-07-09 20:26:31 +00:00
if ( appConfig ( ) . logLevel ( ) > = 4 ) {
2015-07-06 22:50:21 +00:00
appendLogRaw ( getTimeStamp ( ) + " DEBUG: " + text ) ;
2014-11-27 10:36:43 +00:00
}
}
2012-07-04 23:27:03 +00:00
void MainWindow : : appendLogError ( const QString & text )
{
2015-07-06 22:50:21 +00:00
appendLogRaw ( getTimeStamp ( ) + " ERROR: " + text ) ;
2012-07-04 23:27:03 +00:00
}
void MainWindow : : appendLogRaw ( const QString & text )
2012-06-10 16:50:54 +00:00
{
2012-07-28 18:54:50 +00:00
foreach ( QString line , text . split ( QRegExp ( " \r | \n | \r \n " ) ) ) {
if ( ! line . isEmpty ( ) ) {
2012-06-10 16:50:54 +00:00
m_pLogOutput - > append ( line ) ;
2012-07-28 18:54:50 +00:00
updateStateFromLogLine ( line ) ;
}
}
}
void MainWindow : : updateStateFromLogLine ( const QString & line )
2015-06-01 18:57:43 +00:00
{
checkConnected ( line ) ;
checkFingerprint ( line ) ;
}
void MainWindow : : checkConnected ( const QString & line )
2012-07-28 18:54:50 +00:00
{
// TODO: implement ipc connection state messages to replace this hack.
if ( line . contains ( " started server " ) | |
2013-10-16 15:30:42 +00:00
line . contains ( " connected to server " ) | |
line . contains ( " watchdog status: ok " ) )
2012-07-28 18:54:50 +00:00
{
setSynergyState ( synergyConnected ) ;
2015-04-23 16:32:18 +00:00
2015-07-20 23:19:46 +00:00
if ( ! appConfig ( ) . startedBefore ( ) & & isVisible ( ) ) {
2015-04-23 16:32:18 +00:00
QMessageBox : : information (
this , " Synergy " ,
2015-10-02 09:34:15 +00:00
tr ( " Synergy is now connected. You can close the "
" config window and Synergy will remain connected in "
2015-04-23 16:32:18 +00:00
" the background. " ) ) ;
appConfig ( ) . setStartedBefore ( true ) ;
appConfig ( ) . saveSettings ( ) ;
}
2012-07-28 18:54:50 +00:00
}
2015-04-15 12:09:22 +00:00
}
void MainWindow : : checkFingerprint ( const QString & line )
{
2015-04-14 16:29:08 +00:00
QRegExp fingerprintRegex ( " .*server fingerprint: ([A-F0-9:]+) " ) ;
2015-04-15 12:09:22 +00:00
if ( ! fingerprintRegex . exactMatch ( line ) ) {
return ;
}
2015-04-14 16:29:08 +00:00
2015-04-15 12:09:22 +00:00
QString fingerprint = fingerprintRegex . cap ( 1 ) ;
2015-04-20 15:28:26 +00:00
if ( Fingerprint : : trustedServers ( ) . isTrusted ( fingerprint ) ) {
2015-04-15 12:09:22 +00:00
return ;
}
2015-04-14 16:29:08 +00:00
2015-07-30 23:51:00 +00:00
static bool messageBoxAlreadyShown = false ;
if ( ! messageBoxAlreadyShown ) {
2015-08-07 22:55:58 +00:00
stopSynergy ( ) ;
2015-07-30 23:51:00 +00:00
messageBoxAlreadyShown = true ;
QMessageBox : : StandardButton fingerprintReply =
QMessageBox : : information (
this , tr ( " Security question " ) ,
tr ( " Do you trust this fingerprint? \n \n "
" %1 \n \n "
" This is a server fingerprint. You should compare this "
" fingerprint to the one on your server's screen. If the "
" two don't match exactly, then it's probably not the server "
" you're expecting (it could be a malicious user). \n \n "
" To automatically trust this fingerprint for future "
" connections, click Yes. To reject this fingerprint and "
" disconnect from the server, click No. " )
. arg ( fingerprint ) ,
QMessageBox : : Yes | QMessageBox : : No ) ;
if ( fingerprintReply = = QMessageBox : : Yes ) {
// restart core process after trusting fingerprint.
Fingerprint : : trustedServers ( ) . trust ( fingerprint ) ;
startSynergy ( ) ;
}
2015-07-31 00:15:02 +00:00
messageBoxAlreadyShown = false ;
2015-04-15 12:09:22 +00:00
}
2012-06-10 16:50:54 +00:00
}
2015-04-23 16:32:18 +00:00
bool MainWindow : : autoHide ( )
2015-04-23 14:37:07 +00:00
{
if ( ( appConfig ( ) . processMode ( ) = = Desktop ) & &
appConfig ( ) . getAutoHide ( ) ) {
hide ( ) ;
2015-04-23 16:32:18 +00:00
return true ;
2015-04-23 14:37:07 +00:00
}
2015-04-23 16:32:18 +00:00
return false ;
2015-04-23 14:37:07 +00:00
}
2015-07-06 22:50:21 +00:00
QString MainWindow : : getTimeStamp ( )
{
QDateTime current = QDateTime : : currentDateTime ( ) ;
return ' [ ' + current . toString ( Qt : : ISODate ) + ' ] ' ;
}
2015-07-30 22:52:14 +00:00
void MainWindow : : restartSynergy ( )
{
stopSynergy ( ) ;
startSynergy ( ) ;
}
2016-04-28 14:16:40 +00:00
void MainWindow : : proofreadInfo ( )
{
setEdition ( m_AppConfig . edition ( ) ) ;
int oldState = m_SynergyState ;
m_SynergyState = synergyDisconnected ;
setSynergyState ( ( qSynergyState ) oldState ) ;
}
2012-06-10 16:50:54 +00:00
void MainWindow : : clearLog ( )
{
2014-02-14 16:21:02 +00:00
m_pLogOutput - > clear ( ) ;
2012-06-10 16:50:54 +00:00
}
void MainWindow : : startSynergy ( )
{
bool desktopMode = appConfig ( ) . processMode ( ) = = Desktop ;
bool serviceMode = appConfig ( ) . processMode ( ) = = Service ;
2015-07-29 21:34:21 +00:00
appendLogDebug ( " starting process " ) ;
m_ExpectedRunningState = kStarted ;
2012-07-28 22:58:51 +00:00
setSynergyState ( synergyConnecting ) ;
2012-06-10 16:50:54 +00:00
QString app ;
QStringList args ;
args < < " -f " < < " --no-tray " < < " --debug " < < appConfig ( ) . logLevelText ( ) ;
2014-08-21 17:32:40 +00:00
args < < " --name " < < getScreenName ( ) ;
2012-06-10 16:50:54 +00:00
if ( desktopMode )
{
setSynergyProcess ( new QProcess ( this ) ) ;
}
2012-07-05 18:05:35 +00:00
else
{
// tell client/server to talk to daemon through ipc.
args < < " --ipc " ;
2012-07-28 13:34:35 +00:00
# if defined(Q_OS_WIN)
// tell the client/server to shut down when a ms windows desk
// is switched; this is because we may need to elevate or not
// based on which desk the user is in (login always needs
// elevation, where as default desk does not).
2016-06-07 16:20:22 +00:00
// Note that this is only enabled when synergy is set to elevate
// 'as needed' (e.g. on a UAC dialog popup) in order to prevent
// unnecessary restarts when synergy was started elevated or
// when it is not allowed to elevate. In these cases restarting
// the server is fruitless.
if ( appConfig ( ) . elevateMode ( ) = = ElevateAsNeeded ) {
args < < " --stop-on-desk-switch " ;
}
2012-07-28 13:34:35 +00:00
# endif
2012-07-05 18:05:35 +00:00
}
2012-06-10 16:50:54 +00:00
2013-10-22 18:10:14 +00:00
# ifndef Q_OS_LINUX
2014-10-14 16:20:57 +00:00
2015-07-10 00:05:43 +00:00
if ( m_ServerConfig . enableDragAndDrop ( ) ) {
args < < " --enable-drag-drop " ;
}
2014-10-14 16:20:57 +00:00
2013-10-22 18:10:14 +00:00
# endif
2013-09-18 08:34:32 +00:00
2015-02-12 15:50:08 +00:00
if ( m_AppConfig . getCryptoEnabled ( ) ) {
args < < " --enable-crypto " ;
}
2015-03-04 11:51:56 +00:00
# if defined(Q_OS_WIN)
2015-04-15 12:09:22 +00:00
// on windows, the profile directory changes depending on the user that
// launched the process (e.g. when launched with elevation). setting the
// profile dir on launch ensures it uses the same profile dir is used
// no matter how its relaunched.
args < < " --profile-dir " < < getProfileRootForArg ( ) ;
2015-03-04 11:51:56 +00:00
# endif
2015-03-04 11:15:07 +00:00
2012-06-10 16:50:54 +00:00
if ( ( synergyType ( ) = = synergyClient & & ! clientArgs ( args , app ) )
| | ( synergyType ( ) = = synergyServer & & ! serverArgs ( args , app ) ) )
{
2015-10-23 22:37:16 +00:00
stopSynergy ( ) ;
return ;
2012-06-10 16:50:54 +00:00
}
if ( desktopMode )
{
connect ( synergyProcess ( ) , SIGNAL ( finished ( int , QProcess : : ExitStatus ) ) , this , SLOT ( synergyFinished ( int , QProcess : : ExitStatus ) ) ) ;
connect ( synergyProcess ( ) , SIGNAL ( readyReadStandardOutput ( ) ) , this , SLOT ( logOutput ( ) ) ) ;
connect ( synergyProcess ( ) , SIGNAL ( readyReadStandardError ( ) ) , this , SLOT ( logError ( ) ) ) ;
}
// put a space between last log output and new instance.
if ( ! m_pLogOutput - > toPlainText ( ) . isEmpty ( ) )
2012-07-04 23:27:03 +00:00
appendLogRaw ( " " ) ;
2012-06-10 16:50:54 +00:00
2015-06-30 02:37:36 +00:00
appendLogInfo ( " starting " + QString ( synergyType ( ) = = synergyServer ? " server " : " client " ) ) ;
2012-06-10 16:50:54 +00:00
2015-03-04 11:15:07 +00:00
qDebug ( ) < < args ;
2012-06-10 16:50:54 +00:00
// show command if debug log level...
2015-07-09 20:26:31 +00:00
if ( appConfig ( ) . logLevel ( ) > = 4 ) {
2015-06-30 02:37:36 +00:00
appendLogInfo ( QString ( " command: %1 %2 " ) . arg ( app , args . join ( " " ) ) ) ;
2012-06-10 16:50:54 +00:00
}
2015-06-30 02:37:36 +00:00
appendLogInfo ( " config file: " + configFilename ( ) ) ;
appendLogInfo ( " log level: " + appConfig ( ) . logLevelText ( ) ) ;
2012-06-10 16:50:54 +00:00
if ( appConfig ( ) . logToFile ( ) )
2015-06-30 02:37:36 +00:00
appendLogInfo ( " log file: " + appConfig ( ) . logFilename ( ) ) ;
2012-06-10 16:50:54 +00:00
if ( desktopMode )
{
synergyProcess ( ) - > start ( app , args ) ;
2014-01-27 16:58:22 +00:00
if ( ! synergyProcess ( ) - > waitForStarted ( ) )
2012-06-10 16:50:54 +00:00
{
show ( ) ;
QMessageBox : : warning ( this , tr ( " Program can not be started " ) , QString ( tr ( " The executable<br><br>%1<br><br>could not be successfully started, although it does exist. Please check if you have sufficient permissions to run this program. " ) . arg ( app ) ) ) ;
return ;
}
}
if ( serviceMode )
{
QString command ( app + " " + args . join ( " " ) ) ;
2014-10-27 17:10:12 +00:00
m_IpcClient . sendCommand ( command , appConfig ( ) . elevateMode ( ) ) ;
2012-06-10 16:50:54 +00:00
}
}
bool MainWindow : : clientArgs ( QStringList & args , QString & app )
{
app = appPath ( appConfig ( ) . synergycName ( ) ) ;
if ( ! QFile : : exists ( app ) )
{
show ( ) ;
QMessageBox : : warning ( this , tr ( " Synergy client not found " ) ,
tr ( " The executable for the synergy client does not exist. " ) ) ;
return false ;
}
2013-10-16 17:20:32 +00:00
# if defined(Q_OS_WIN)
2013-10-03 14:24:58 +00:00
// wrap in quotes so a malicious user can't start \Program.exe as admin.
app = QString ( " \" %1 \" " ) . arg ( app ) ;
2013-10-16 16:52:30 +00:00
# endif
2013-10-03 14:24:58 +00:00
2012-06-10 16:50:54 +00:00
if ( appConfig ( ) . logToFile ( ) )
{
appConfig ( ) . persistLogDir ( ) ;
2014-06-18 12:59:30 +00:00
args < < " --log " < < appConfig ( ) . logFilenameCmd ( ) ;
2012-06-10 16:50:54 +00:00
}
2014-11-28 10:51:52 +00:00
// check auto config first, if it is disabled or no server detected,
2014-11-25 15:00:51 +00:00
// use line edit host name if it is not empty
2014-11-28 10:51:52 +00:00
if ( m_pCheckBoxAutoConfig - > isChecked ( ) ) {
2014-11-25 15:00:51 +00:00
if ( m_pComboServerList - > count ( ) ! = 0 ) {
2014-11-13 14:57:21 +00:00
QString serverIp = m_pComboServerList - > currentText ( ) ;
args < < serverIp + " : " + QString : : number ( appConfig ( ) . port ( ) ) ;
2014-11-25 15:00:51 +00:00
return true ;
2014-11-13 14:57:21 +00:00
}
}
2014-11-18 16:39:20 +00:00
2014-11-25 15:00:51 +00:00
if ( m_pLineEditHostname - > text ( ) . isEmpty ( ) ) {
show ( ) ;
2014-12-02 15:03:19 +00:00
if ( ! m_SuppressEmptyServerWarning ) {
QMessageBox : : warning ( this , tr ( " Hostname is empty " ) ,
2014-11-25 15:00:51 +00:00
tr ( " Please fill in a hostname for the synergy client to connect to. " ) ) ;
2014-12-02 15:03:19 +00:00
}
2014-11-25 15:00:51 +00:00
return false ;
2014-11-13 14:57:21 +00:00
}
2012-06-10 16:50:54 +00:00
2014-11-25 15:00:51 +00:00
args < < m_pLineEditHostname - > text ( ) + " : " + QString : : number ( appConfig ( ) . port ( ) ) ;
2012-06-10 16:50:54 +00:00
return true ;
}
QString MainWindow : : configFilename ( )
{
QString filename ;
if ( m_pRadioInternalConfig - > isChecked ( ) )
{
// TODO: no need to use a temporary file, since we need it to
// be permenant (since it'll be used for Windows services, etc).
m_pTempConfigFile = new QTemporaryFile ( ) ;
if ( ! m_pTempConfigFile - > open ( ) )
{
2015-02-05 11:44:33 +00:00
QMessageBox : : critical ( this , tr ( " Cannot write configuration file " ) , tr ( " The temporary configuration file required to start synergy can not be written. " ) ) ;
2014-02-14 16:21:02 +00:00
return " " ;
2012-06-10 16:50:54 +00:00
}
serverConfig ( ) . save ( * m_pTempConfigFile ) ;
filename = m_pTempConfigFile - > fileName ( ) ;
m_pTempConfigFile - > close ( ) ;
}
else
{
if ( ! QFile : : exists ( m_pLineEditConfigFile - > text ( ) ) )
{
if ( QMessageBox : : warning ( this , tr ( " Configuration filename invalid " ) ,
tr ( " You have not filled in a valid configuration file for the synergy server. "
" Do you want to browse for the configuration file now? " ) , QMessageBox : : Yes | QMessageBox : : No ) ! = QMessageBox : : Yes
| | ! on_m_pButtonBrowseConfigFile_clicked ( ) )
2014-02-14 16:21:02 +00:00
return " " ;
2012-06-10 16:50:54 +00:00
}
filename = m_pLineEditConfigFile - > text ( ) ;
}
return filename ;
}
QString MainWindow : : address ( )
{
2014-08-21 17:32:40 +00:00
QString i = appConfig ( ) . interface ( ) ;
return ( ! i . isEmpty ( ) ? i : " " ) + " : " + QString : : number ( appConfig ( ) . port ( ) ) ;
2012-06-10 16:50:54 +00:00
}
QString MainWindow : : appPath ( const QString & name )
{
return appConfig ( ) . synergyProgramDir ( ) + name ;
}
bool MainWindow : : serverArgs ( QStringList & args , QString & app )
{
2015-11-17 22:17:00 +00:00
int edition ;
2015-11-17 22:51:04 +00:00
SubscriptionManager subscriptionManager ( this , appConfig ( ) , edition ) ;
2015-11-19 00:05:08 +00:00
if ( subscriptionManager . fileExists ( ) )
2015-10-23 22:37:16 +00:00
{
2015-11-17 22:17:00 +00:00
if ( ! subscriptionManager . checkSubscription ( ) ) {
2015-10-23 22:37:16 +00:00
return false ;
}
2015-11-17 22:17:00 +00:00
else {
setEdition ( edition ) ;
2015-10-23 22:37:16 +00:00
}
}
2015-11-17 22:17:00 +00:00
2012-06-10 16:50:54 +00:00
app = appPath ( appConfig ( ) . synergysName ( ) ) ;
if ( ! QFile : : exists ( app ) )
{
QMessageBox : : warning ( this , tr ( " Synergy server not found " ) ,
tr ( " The executable for the synergy server does not exist. " ) ) ;
return false ;
}
2013-10-16 17:20:32 +00:00
# if defined(Q_OS_WIN)
2013-10-03 14:24:58 +00:00
// wrap in quotes so a malicious user can't start \Program.exe as admin.
app = QString ( " \" %1 \" " ) . arg ( app ) ;
2013-10-16 16:52:30 +00:00
# endif
2013-10-03 14:24:58 +00:00
2012-06-10 16:50:54 +00:00
if ( appConfig ( ) . logToFile ( ) )
{
appConfig ( ) . persistLogDir ( ) ;
2014-05-28 11:59:14 +00:00
2014-06-18 12:59:30 +00:00
args < < " --log " < < appConfig ( ) . logFilenameCmd ( ) ;
2012-06-10 16:50:54 +00:00
}
2014-05-28 12:05:05 +00:00
QString configFilename = this - > configFilename ( ) ;
# if defined(Q_OS_WIN)
// wrap in quotes in case username contains spaces.
configFilename = QString ( " \" %1 \" " ) . arg ( configFilename ) ;
# endif
args < < " -c " < < configFilename < < " --address " < < address ( ) ;
2012-06-10 16:50:54 +00:00
2015-10-19 18:18:43 +00:00
# if defined(Q_OS_WIN)
// pass in physical resolution and primary screen center
// TODO: get this information in the core binary even when
// high DPI is used
int height = QApplication : : desktop ( ) - > height ( ) ;
int width = QApplication : : desktop ( ) - > width ( ) ;
QRect rec = QApplication : : desktop ( ) - > screenGeometry ( ) ;
int heightCenter = rec . height ( ) / 2 ;
int widthCenter = rec . width ( ) / 2 ;
appendLogDebug ( tr ( " screen resolution: %1 %2 primary screen center: %3 %4 " )
. arg ( width ) . arg ( height ) . arg ( widthCenter ) . arg ( heightCenter ) ) ;
args < < " --res-w " < < QString : : number ( width ) ;
args < < " --res-h " < < QString : : number ( height ) ;
args < < " --prm-wc " < < QString : : number ( widthCenter ) ;
args < < " --prm-hc " < < QString : : number ( heightCenter ) ;
# endif
2012-06-10 16:50:54 +00:00
return true ;
}
void MainWindow : : stopSynergy ( )
{
2015-07-29 21:34:21 +00:00
appendLogDebug ( " stopping process " ) ;
m_ExpectedRunningState = kStopped ;
2012-07-28 22:13:14 +00:00
if ( appConfig ( ) . processMode ( ) = = Service )
{
stopService ( ) ;
2012-07-28 18:54:50 +00:00
}
2012-07-28 22:13:14 +00:00
else if ( appConfig ( ) . processMode ( ) = = Desktop )
2012-06-10 16:50:54 +00:00
{
2012-07-28 22:13:14 +00:00
stopDesktop ( ) ;
2012-06-10 16:50:54 +00:00
}
2012-07-28 18:54:50 +00:00
setSynergyState ( synergyDisconnected ) ;
2012-06-10 16:50:54 +00:00
// HACK: deleting the object deletes the physical file, which is
// bad, since it could be in use by the Windows service!
//delete m_pTempConfigFile;
m_pTempConfigFile = NULL ;
// reset so that new connects cause auto-hide.
2013-05-29 20:46:24 +00:00
m_AlreadyHidden = false ;
2012-06-10 16:50:54 +00:00
}
2012-07-28 22:13:14 +00:00
void MainWindow : : stopService ( )
{
// send empty command to stop service from laucning anything.
2014-10-27 17:10:12 +00:00
m_IpcClient . sendCommand ( " " , appConfig ( ) . elevateMode ( ) ) ;
2012-07-28 22:13:14 +00:00
}
void MainWindow : : stopDesktop ( )
{
2015-07-29 21:34:21 +00:00
QMutexLocker locker ( & m_StopDesktopMutex ) ;
2012-07-28 22:13:14 +00:00
if ( ! synergyProcess ( ) ) {
return ;
}
2015-06-30 02:37:36 +00:00
appendLogInfo ( " stopping synergy desktop process " ) ;
2012-07-28 22:13:14 +00:00
2015-07-29 22:03:35 +00:00
if ( synergyProcess ( ) - > isOpen ( ) ) {
2012-07-28 22:13:14 +00:00
synergyProcess ( ) - > close ( ) ;
2015-07-29 22:03:35 +00:00
}
2012-07-28 22:13:14 +00:00
delete synergyProcess ( ) ;
setSynergyProcess ( NULL ) ;
}
2012-06-10 16:50:54 +00:00
void MainWindow : : synergyFinished ( int exitCode , QProcess : : ExitStatus )
{
2015-07-29 21:34:21 +00:00
if ( exitCode = = 0 ) {
appendLogInfo ( QString ( " process exited normally " ) ) ;
2012-06-10 16:50:54 +00:00
}
2015-07-29 21:34:21 +00:00
else {
appendLogError ( QString ( " process exited with error code: %1 " ) . arg ( exitCode ) ) ;
2015-07-29 01:01:39 +00:00
}
2015-07-29 21:34:21 +00:00
if ( m_ExpectedRunningState = = kStarted ) {
2015-07-29 22:15:19 +00:00
QTimer : : singleShot ( 1000 , this , SLOT ( startSynergy ( ) ) ) ;
2015-07-29 21:34:21 +00:00
appendLogInfo ( QString ( " detected process not running, auto restarting " ) ) ;
}
else {
setSynergyState ( synergyDisconnected ) ;
}
2012-06-10 16:50:54 +00:00
}
void MainWindow : : setSynergyState ( qSynergyState state )
{
if ( synergyState ( ) = = state )
return ;
if ( state = = synergyConnected | | state = = synergyConnecting )
{
disconnect ( m_pButtonToggleStart , SIGNAL ( clicked ( ) ) , m_pActionStartSynergy , SLOT ( trigger ( ) ) ) ;
connect ( m_pButtonToggleStart , SIGNAL ( clicked ( ) ) , m_pActionStopSynergy , SLOT ( trigger ( ) ) ) ;
m_pButtonToggleStart - > setText ( tr ( " &Stop " ) ) ;
2013-10-16 15:30:42 +00:00
m_pButtonApply - > setEnabled ( true ) ;
2012-06-10 16:50:54 +00:00
}
2015-06-02 20:42:27 +00:00
else if ( state = = synergyDisconnected )
2012-06-10 16:50:54 +00:00
{
disconnect ( m_pButtonToggleStart , SIGNAL ( clicked ( ) ) , m_pActionStopSynergy , SLOT ( trigger ( ) ) ) ;
connect ( m_pButtonToggleStart , SIGNAL ( clicked ( ) ) , m_pActionStartSynergy , SLOT ( trigger ( ) ) ) ;
m_pButtonToggleStart - > setText ( tr ( " &Start " ) ) ;
2013-10-15 15:46:02 +00:00
m_pButtonApply - > setEnabled ( false ) ;
2012-06-10 16:50:54 +00:00
}
2015-06-02 20:42:27 +00:00
bool connected = false ;
if ( state = = synergyConnected | | state = = synergyTransfering ) {
connected = true ;
}
2012-07-29 00:47:49 +00:00
m_pActionStartSynergy - > setEnabled ( ! connected ) ;
m_pActionStopSynergy - > setEnabled ( connected ) ;
2012-06-10 16:50:54 +00:00
switch ( state )
{
2012-07-28 22:58:51 +00:00
case synergyConnected : {
2015-02-13 10:14:11 +00:00
if ( m_AppConfig . getCryptoEnabled ( ) ) {
m_pLabelPadlock - > show ( ) ;
}
else {
m_pLabelPadlock - > hide ( ) ;
}
2013-10-16 15:30:42 +00:00
setStatus ( tr ( " Synergy is running. " ) ) ;
2015-04-23 16:32:18 +00:00
2012-06-10 16:50:54 +00:00
break ;
2012-07-28 22:58:51 +00:00
}
2012-06-10 16:50:54 +00:00
case synergyConnecting :
2015-02-13 10:14:11 +00:00
m_pLabelPadlock - > hide ( ) ;
2012-06-10 16:50:54 +00:00
setStatus ( tr ( " Synergy is starting. " ) ) ;
break ;
case synergyDisconnected :
2015-02-13 10:14:11 +00:00
m_pLabelPadlock - > hide ( ) ;
2012-06-10 16:50:54 +00:00
setStatus ( tr ( " Synergy is not running. " ) ) ;
break ;
2015-06-01 22:59:59 +00:00
case synergyTransfering :
break ;
2012-06-10 16:50:54 +00:00
}
setIcon ( state ) ;
m_SynergyState = state ;
}
void MainWindow : : setVisible ( bool visible )
{
2013-10-15 15:46:02 +00:00
QMainWindow : : setVisible ( visible ) ;
2012-06-10 16:50:54 +00:00
m_pActionMinimize - > setEnabled ( visible ) ;
m_pActionRestore - > setEnabled ( ! visible ) ;
2014-02-14 16:21:02 +00:00
# if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 // lion
2012-06-10 16:50:54 +00:00
// dock hide only supported on lion :(
ProcessSerialNumber psn = { 0 , kCurrentProcess } ;
GetCurrentProcess ( & psn ) ;
if ( visible )
TransformProcessType ( & psn , kProcessTransformToForegroundApplication ) ;
else
TransformProcessType ( & psn , kProcessTransformToBackgroundApplication ) ;
# endif
}
2012-07-28 20:41:40 +00:00
QString MainWindow : : getIPAddresses ( )
{
QList < QHostAddress > addresses = QNetworkInterface : : allAddresses ( ) ;
bool hinted = false ;
QString result ;
for ( int i = 0 ; i < addresses . size ( ) ; i + + ) {
if ( addresses [ i ] . protocol ( ) = = QAbstractSocket : : IPv4Protocol & &
addresses [ i ] ! = QHostAddress ( QHostAddress : : LocalHost ) ) {
QString address = addresses [ i ] . toString ( ) ;
QString format = " %1, " ;
// usually 192.168.x.x is a useful ip for the user, so indicate
// this by making it bold.
if ( ! hinted & & address . startsWith ( " 192.168 " ) ) {
hinted = true ;
format = " <b>%1</b>, " ;
}
result + = format . arg ( address ) ;
}
}
if ( result = = " " ) {
2012-07-28 22:58:51 +00:00
return tr ( " Unknown " ) ;
2012-07-28 20:41:40 +00:00
}
// remove trailing comma.
result . chop ( 2 ) ;
return result ;
}
QString MainWindow : : getScreenName ( )
{
if ( appConfig ( ) . screenName ( ) = = " " ) {
return QHostInfo : : localHostName ( ) ;
}
else {
return appConfig ( ) . screenName ( ) ;
}
}
2013-05-29 20:46:24 +00:00
void MainWindow : : changeEvent ( QEvent * event )
{
if ( event ! = 0 )
{
switch ( event - > type ( ) )
{
case QEvent : : LanguageChange :
2015-02-05 14:17:34 +00:00
{
2013-05-29 20:46:24 +00:00
retranslateUi ( this ) ;
retranslateMenuBar ( ) ;
2016-04-28 14:16:40 +00:00
proofreadInfo ( ) ;
2015-02-12 15:50:08 +00:00
2015-02-05 14:17:34 +00:00
break ;
}
2013-05-29 20:46:24 +00:00
default :
QMainWindow : : changeEvent ( event ) ;
}
}
}
2014-08-21 17:32:40 +00:00
void MainWindow : : updateZeroconfService ( )
{
2015-07-29 21:31:47 +00:00
QMutexLocker locker ( & m_UpdateZeroconfMutex ) ;
2014-11-24 11:59:24 +00:00
2014-11-11 15:57:25 +00:00
if ( isBonjourRunning ( ) ) {
if ( ! m_AppConfig . wizardShouldRun ( ) ) {
if ( m_pZeroconfService ) {
delete m_pZeroconfService ;
m_pZeroconfService = NULL ;
}
2014-08-21 17:32:40 +00:00
2014-11-28 10:51:52 +00:00
if ( m_AppConfig . autoConfig ( ) | | synergyType ( ) = = synergyServer ) {
2014-11-11 15:57:25 +00:00
m_pZeroconfService = new ZeroconfService ( this ) ;
}
2014-08-26 11:22:09 +00:00
}
2014-08-21 17:32:40 +00:00
}
}
2014-11-13 14:57:21 +00:00
void MainWindow : : serverDetected ( const QString name )
{
if ( m_pComboServerList - > findText ( name ) = = - 1 ) {
2014-11-13 16:22:44 +00:00
// Note: the first added item triggers startSynergy
2014-11-13 14:57:21 +00:00
m_pComboServerList - > addItem ( name ) ;
}
2014-11-18 15:29:31 +00:00
if ( m_pComboServerList - > count ( ) > 1 ) {
m_pComboServerList - > show ( ) ;
}
2014-11-13 14:57:21 +00:00
}
2015-02-05 14:17:34 +00:00
void MainWindow : : setEdition ( int type )
{
QString title ;
if ( type = = Basic ) {
title = " Synergy Basic " ;
}
else if ( type = = Pro ) {
title = " Synergy Pro " ;
}
2015-10-30 18:57:12 +00:00
else if ( type = = Trial ) {
title = " Synergy Trial " ;
}
2015-02-05 14:17:34 +00:00
else {
title = " Synergy (UNREGISTERED) " ;
}
setWindowTitle ( title ) ;
}
2015-04-21 16:56:01 +00:00
void MainWindow : : updateLocalFingerprint ( )
{
if ( Fingerprint : : local ( ) . fileExists ( ) ) {
m_pLabelFingerprint - > setVisible ( true ) ;
m_pLabelLocalFingerprint - > setVisible ( true ) ;
m_pLabelLocalFingerprint - > setText ( Fingerprint : : local ( ) . readFirst ( ) ) ;
}
else {
m_pLabelFingerprint - > setVisible ( false ) ;
m_pLabelLocalFingerprint - > setVisible ( false ) ;
}
}
2014-08-21 17:32:40 +00:00
void MainWindow : : on_m_pGroupClient_toggled ( bool on )
{
m_pGroupServer - > setChecked ( ! on ) ;
2014-11-19 16:29:30 +00:00
if ( on ) {
updateZeroconfService ( ) ;
}
2014-08-21 17:32:40 +00:00
}
void MainWindow : : on_m_pGroupServer_toggled ( bool on )
{
m_pGroupClient - > setChecked ( ! on ) ;
2014-11-19 16:29:30 +00:00
if ( on ) {
updateZeroconfService ( ) ;
}
2014-08-21 17:32:40 +00:00
}
2012-06-10 16:50:54 +00:00
bool MainWindow : : on_m_pButtonBrowseConfigFile_clicked ( )
{
QString fileName = QFileDialog : : getOpenFileName ( this , tr ( " Browse for a synergys config file " ) , QString ( ) , synergyConfigFilter ) ;
if ( ! fileName . isEmpty ( ) )
{
m_pLineEditConfigFile - > setText ( fileName ) ;
return true ;
}
return false ;
}
bool MainWindow : : on_m_pActionSave_triggered ( )
{
QString fileName = QFileDialog : : getSaveFileName ( this , tr ( " Save configuration as... " ) ) ;
if ( ! fileName . isEmpty ( ) & & ! serverConfig ( ) . save ( fileName ) )
{
QMessageBox : : warning ( this , tr ( " Save failed " ) , tr ( " Could not save configuration to file. " ) ) ;
return true ;
}
return false ;
}
void MainWindow : : on_m_pActionAbout_triggered ( )
{
AboutDialog dlg ( this , appPath ( appConfig ( ) . synergycName ( ) ) ) ;
dlg . exec ( ) ;
}
void MainWindow : : on_m_pActionSettings_triggered ( )
{
2012-07-28 22:58:51 +00:00
ProcessMode lastProcessMode = appConfig ( ) . processMode ( ) ;
2012-06-10 16:50:54 +00:00
SettingsDialog dlg ( this , appConfig ( ) ) ;
dlg . exec ( ) ;
2012-07-28 22:58:51 +00:00
if ( lastProcessMode ! = appConfig ( ) . processMode ( ) )
{
onModeChanged ( true , true ) ;
}
2012-06-10 16:50:54 +00:00
}
2014-08-21 17:32:40 +00:00
void MainWindow : : autoAddScreen ( const QString name )
{
2014-11-28 10:51:52 +00:00
if ( ! m_ServerConfig . ignoreAutoConfigClient ( ) ) {
2014-11-18 14:16:29 +00:00
int r = m_ServerConfig . autoAddScreen ( name ) ;
if ( r ! = kAutoAddScreenOk ) {
switch ( r ) {
case kAutoAddScreenManualServer :
showConfigureServer (
tr ( " Please add the server (%1) to the grid. " )
. arg ( appConfig ( ) . screenName ( ) ) ) ;
break ;
case kAutoAddScreenManualClient :
showConfigureServer (
tr ( " Please drag the new client screen (%1) "
" to the desired position on the grid. " )
. arg ( name ) ) ;
break ;
}
2014-08-21 17:32:40 +00:00
}
2014-11-25 15:04:25 +00:00
else {
2015-07-30 22:52:14 +00:00
restartSynergy ( ) ;
2014-11-25 15:04:25 +00:00
}
2014-08-21 17:32:40 +00:00
}
}
void MainWindow : : showConfigureServer ( const QString & message )
2012-06-10 16:50:54 +00:00
{
ServerConfigDialog dlg ( this , serverConfig ( ) , appConfig ( ) . screenName ( ) ) ;
2014-08-21 17:32:40 +00:00
dlg . message ( message ) ;
2012-06-10 16:50:54 +00:00
dlg . exec ( ) ;
}
2014-08-21 17:32:40 +00:00
void MainWindow : : on_m_pButtonConfigureServer_clicked ( )
{
showConfigureServer ( ) ;
}
2012-07-28 02:59:20 +00:00
void MainWindow : : on_m_pActionWizard_triggered ( )
2012-06-10 16:50:54 +00:00
{
2013-05-29 20:46:24 +00:00
SetupWizard wizard ( * this , false ) ;
wizard . exec ( ) ;
2012-06-10 16:50:54 +00:00
}
2012-07-28 18:54:50 +00:00
void MainWindow : : on_m_pButtonApply_clicked ( )
{
2015-07-30 22:52:14 +00:00
restartSynergy ( ) ;
2012-07-28 18:54:50 +00:00
}
2014-08-26 11:22:09 +00:00
2015-02-15 03:22:08 +00:00
# if defined(Q_OS_WIN)
2014-11-11 14:08:55 +00:00
bool MainWindow : : isServiceRunning ( QString name )
{
SC_HANDLE hSCManager ;
hSCManager = OpenSCManager ( NULL , NULL , SC_MANAGER_CONNECT ) ;
if ( hSCManager = = NULL ) {
2015-06-30 22:05:24 +00:00
appendLogError ( " failed to open a service controller manager, error: " +
2014-11-11 14:08:55 +00:00
GetLastError ( ) ) ;
return false ;
}
SC_HANDLE hService ;
int length = name . length ( ) ;
wchar_t * array = new wchar_t [ length + 1 ] ;
name . toWCharArray ( array ) ;
array [ length ] = ' \0 ' ;
hService = OpenService ( hSCManager , array , SERVICE_QUERY_STATUS ) ;
2014-11-12 11:54:45 +00:00
delete [ ] array ;
2014-11-11 14:08:55 +00:00
if ( hService = = NULL ) {
2014-11-27 10:36:43 +00:00
appendLogDebug ( " failed to open service: " + name ) ;
2014-11-11 14:08:55 +00:00
return false ;
}
SERVICE_STATUS status ;
if ( QueryServiceStatus ( hService , & status ) ) {
if ( status . dwCurrentState = = SERVICE_RUNNING ) {
return true ;
}
}
2015-02-15 03:22:08 +00:00
# else
bool MainWindow : : isServiceRunning ( )
{
2014-11-11 14:08:55 +00:00
# endif
return false ;
}
2014-11-11 15:57:25 +00:00
bool MainWindow : : isBonjourRunning ( )
{
bool result = false ;
# if defined(Q_OS_WIN)
result = isServiceRunning ( " Bonjour Service " ) ;
# else
result = true ;
# endif
return result ;
}
2014-11-12 14:21:54 +00:00
void MainWindow : : downloadBonjour ( )
{
# if defined(Q_OS_WIN)
2014-11-26 15:05:53 +00:00
QUrl url ;
2015-05-25 18:41:53 +00:00
int arch = getProcessorArch ( ) ;
if ( arch = = kProcessorArchWin32 ) {
2015-02-09 15:37:47 +00:00
url . setUrl ( bonjourBaseUrl + bonjourFilename32 ) ;
2015-06-30 22:05:24 +00:00
appendLogInfo ( " downloading 32-bit Bonjour " ) ;
2014-11-26 15:05:53 +00:00
}
2015-05-25 18:41:53 +00:00
else if ( arch = = kProcessorArchWin64 ) {
2015-02-09 15:37:47 +00:00
url . setUrl ( bonjourBaseUrl + bonjourFilename64 ) ;
2015-06-30 22:05:24 +00:00
appendLogInfo ( " downloading 64-bit Bonjour " ) ;
2014-11-26 15:05:53 +00:00
}
else {
2015-02-09 15:37:47 +00:00
QMessageBox : : critical (
2014-11-26 15:05:53 +00:00
this , tr ( " Synergy " ) ,
2015-02-09 15:37:47 +00:00
tr ( " Failed to detect system architecture. " ) ) ;
2014-11-26 15:05:53 +00:00
return ;
}
2015-02-09 15:37:47 +00:00
if ( m_pDataDownloader = = NULL ) {
m_pDataDownloader = new DataDownloader ( this ) ;
connect ( m_pDataDownloader , SIGNAL ( isComplete ( ) ) , SLOT ( installBonjour ( ) ) ) ;
2014-11-13 11:02:48 +00:00
}
2015-02-09 15:37:47 +00:00
m_pDataDownloader - > download ( url ) ;
2014-11-13 11:02:48 +00:00
if ( m_DownloadMessageBox = = NULL ) {
2014-11-20 11:41:17 +00:00
m_DownloadMessageBox = new QMessageBox ( this ) ;
2014-11-27 19:11:01 +00:00
m_DownloadMessageBox - > setWindowTitle ( " Synergy " ) ;
2014-11-28 10:54:51 +00:00
m_DownloadMessageBox - > setIcon ( QMessageBox : : Information ) ;
2014-11-20 11:41:17 +00:00
m_DownloadMessageBox - > setText ( " Installing Bonjour, please wait... " ) ;
2014-11-13 12:09:11 +00:00
m_DownloadMessageBox - > setStandardButtons ( 0 ) ;
m_pCancelButton = m_DownloadMessageBox - > addButton (
tr ( " Cancel " ) , QMessageBox : : RejectRole ) ;
2014-11-13 11:02:48 +00:00
}
2014-11-13 12:09:11 +00:00
m_DownloadMessageBox - > exec ( ) ;
2014-11-13 11:02:48 +00:00
2014-11-13 12:09:11 +00:00
if ( m_DownloadMessageBox - > clickedButton ( ) = = m_pCancelButton ) {
2015-02-09 15:37:47 +00:00
m_pDataDownloader - > cancel ( ) ;
2014-11-13 12:09:11 +00:00
}
2014-11-12 14:21:54 +00:00
# endif
}
2014-11-12 16:44:25 +00:00
2014-11-13 11:02:48 +00:00
void MainWindow : : installBonjour ( )
{
2014-11-13 13:28:46 +00:00
# if defined(Q_OS_WIN)
2014-11-13 11:02:48 +00:00
QString tempLocation = QDesktopServices : : storageLocation (
QDesktopServices : : TempLocation ) ;
QString filename = tempLocation ;
2015-02-09 15:37:47 +00:00
filename . append ( " \\ " ) . append ( bonjourTargetFilename ) ;
2014-11-13 11:02:48 +00:00
QFile file ( filename ) ;
if ( ! file . open ( QIODevice : : WriteOnly ) ) {
m_DownloadMessageBox - > hide ( ) ;
2014-11-26 15:05:53 +00:00
QMessageBox : : warning (
2014-11-13 11:02:48 +00:00
this , " Synergy " ,
2015-02-09 15:37:47 +00:00
tr ( " Failed to download Bonjour installer to location: %1 " )
. arg ( tempLocation ) ) ;
2014-11-13 11:02:48 +00:00
return ;
}
2015-02-09 15:37:47 +00:00
file . write ( m_pDataDownloader - > data ( ) ) ;
2014-11-13 11:02:48 +00:00
file . close ( ) ;
2014-11-26 16:42:32 +00:00
QStringList arguments ;
arguments . append ( " /i " ) ;
QString winFilename = QDir : : toNativeSeparators ( filename ) ;
arguments . append ( winFilename ) ;
arguments . append ( " /passive " ) ;
2014-11-28 12:57:57 +00:00
if ( m_BonjourInstall = = NULL ) {
m_BonjourInstall = new CommandProcess ( " msiexec " , arguments ) ;
}
2014-11-28 15:23:08 +00:00
QThread * thread = new QThread ;
2014-11-28 12:57:57 +00:00
connect ( m_BonjourInstall , SIGNAL ( finished ( ) ) , this ,
SLOT ( bonjourInstallFinished ( ) ) ) ;
2014-11-28 15:23:08 +00:00
connect ( m_BonjourInstall , SIGNAL ( finished ( ) ) , thread , SLOT ( quit ( ) ) ) ;
connect ( thread , SIGNAL ( finished ( ) ) , thread , SLOT ( deleteLater ( ) ) ) ;
m_BonjourInstall - > moveToThread ( thread ) ;
thread - > start ( ) ;
2014-11-28 12:57:57 +00:00
QMetaObject : : invokeMethod ( m_BonjourInstall , " run " , Qt : : QueuedConnection ) ;
2014-11-13 12:27:28 +00:00
2014-11-13 11:02:48 +00:00
m_DownloadMessageBox - > hide ( ) ;
2014-11-13 13:28:46 +00:00
# endif
2014-11-13 11:02:48 +00:00
}
2014-11-28 10:51:52 +00:00
void MainWindow : : promptAutoConfig ( )
2014-11-12 16:44:25 +00:00
{
2014-11-28 11:21:45 +00:00
if ( ! isBonjourRunning ( ) ) {
2014-11-27 19:08:30 +00:00
int r = QMessageBox : : question (
this , tr ( " Synergy " ) ,
2014-11-28 10:51:52 +00:00
tr ( " Do you want to enable auto config and install Bonjour? \n \n "
2014-11-27 19:08:30 +00:00
" This feature helps you establish the connection. " ) ,
QMessageBox : : Yes | QMessageBox : : No ) ;
if ( r = = QMessageBox : : Yes ) {
2014-11-28 10:51:52 +00:00
m_AppConfig . setAutoConfig ( true ) ;
2014-11-27 19:08:30 +00:00
downloadBonjour ( ) ;
}
else {
2014-11-28 10:51:52 +00:00
m_AppConfig . setAutoConfig ( false ) ;
m_pCheckBoxAutoConfig - > setChecked ( false ) ;
2014-11-27 19:08:30 +00:00
}
2014-11-12 16:44:25 +00:00
}
2014-11-28 10:51:52 +00:00
m_AppConfig . setAutoConfigPrompted ( true ) ;
2014-11-12 16:44:25 +00:00
}
2014-11-13 14:57:21 +00:00
void MainWindow : : on_m_pComboServerList_currentIndexChanged ( QString )
{
if ( m_pComboServerList - > count ( ) ! = 0 ) {
2015-07-30 22:52:14 +00:00
restartSynergy ( ) ;
2014-11-13 14:57:21 +00:00
}
}
2014-11-28 10:51:52 +00:00
void MainWindow : : on_m_pCheckBoxAutoConfig_toggled ( bool checked )
{
if ( ! isBonjourRunning ( ) & & checked ) {
if ( ! m_SuppressAutoConfigWarning ) {
int r = QMessageBox : : information (
this , tr ( " Synergy " ) ,
tr ( " Auto config feature requires Bonjour. \n \n "
" Do you want to install Bonjour? " ) ,
QMessageBox : : Yes | QMessageBox : : No ) ;
if ( r = = QMessageBox : : Yes ) {
downloadBonjour ( ) ;
}
}
m_pCheckBoxAutoConfig - > setChecked ( false ) ;
return ;
}
m_pLineEditHostname - > setDisabled ( checked ) ;
appConfig ( ) . setAutoConfig ( checked ) ;
updateZeroconfService ( ) ;
if ( ! checked ) {
m_pComboServerList - > clear ( ) ;
m_pComboServerList - > hide ( ) ;
}
}
2014-11-28 12:57:57 +00:00
void MainWindow : : bonjourInstallFinished ( )
{
2015-06-30 02:37:36 +00:00
appendLogInfo ( " Bonjour install finished " ) ;
2014-11-28 12:57:57 +00:00
2014-11-28 16:34:16 +00:00
m_pCheckBoxAutoConfig - > setChecked ( true ) ;
2014-11-28 12:57:57 +00:00
}
2015-03-04 11:15:07 +00:00
2015-04-15 12:09:22 +00:00
QString MainWindow : : getProfileRootForArg ( )
2015-03-04 11:15:07 +00:00
{
2015-04-15 12:09:22 +00:00
CoreInterface coreInterface ;
QString dir = coreInterface . getProfileDir ( ) ;
2015-03-04 11:15:07 +00:00
2015-04-15 12:09:22 +00:00
// HACK: strip our app name since we're returning the root dir.
# if defined(Q_OS_WIN)
dir . replace ( " \\ Synergy " , " " ) ;
2015-03-04 11:15:07 +00:00
# else
2015-04-15 12:09:22 +00:00
dir . replace ( " /.synergy " , " " ) ;
2015-03-04 11:15:07 +00:00
# endif
2015-04-15 12:09:22 +00:00
return QString ( " \" %1 \" " ) . arg ( dir ) ;
2015-03-04 11:15:07 +00:00
}