diff --git a/src/gui/src/ActivationDialog.cpp b/src/gui/src/ActivationDialog.cpp index 5162dd11..9d3b43f3 100644 --- a/src/gui/src/ActivationDialog.cpp +++ b/src/gui/src/ActivationDialog.cpp @@ -14,67 +14,67 @@ #include #include -ActivationDialog::ActivationDialog(QWidget* parent, AppConfig& appConfig, - SubscriptionManager& subscriptionManager) : - QDialog(parent), - ui(new Ui::ActivationDialog), - m_appConfig(&appConfig), - m_subscriptionManager (&subscriptionManager) +ActivationDialog::ActivationDialog(QWidget* parent, AppConfig& appConfig, + SubscriptionManager& subscriptionManager) : + QDialog(parent), + ui(new Ui::ActivationDialog), + m_appConfig(&appConfig), + m_subscriptionManager (&subscriptionManager) { - ui->setupUi(this); - refreshSerialKey(); + ui->setupUi(this); + refreshSerialKey(); } void ActivationDialog::refreshSerialKey() { - ui->m_pTextEditSerialKey->setText(m_appConfig->serialKey()); - ui->m_pTextEditSerialKey->setFocus(); - ui->m_pTextEditSerialKey->moveCursor(QTextCursor::End); + ui->m_pTextEditSerialKey->setText(m_appConfig->serialKey()); + ui->m_pTextEditSerialKey->setFocus(); + ui->m_pTextEditSerialKey->moveCursor(QTextCursor::End); } ActivationDialog::~ActivationDialog() { - delete ui; + delete ui; } void ActivationDialog::reject() { - if (m_subscriptionManager->edition() == Edition::kUnregistered) { - CancelActivationDialog cancelActivationDialog(this); - if (QDialog::Accepted == cancelActivationDialog.exec()) { - m_subscriptionManager->skipActivation(); - m_appConfig->activationHasRun(true); - m_appConfig->saveSettings(); - } - } - QDialog::reject(); + if (m_subscriptionManager->activeLicense() == Edition::kUnregistered) { + CancelActivationDialog cancelActivationDialog(this); + if (QDialog::Accepted == cancelActivationDialog.exec()) { + m_subscriptionManager->skipActivation(); + m_appConfig->activationHasRun(true); + m_appConfig->saveSettings(); + } + } + QDialog::reject(); } void ActivationDialog::accept() { - QMessageBox message; - QString error; - - m_appConfig->activationHasRun(true); - m_appConfig->saveSettings(); + QMessageBox message; + QString error; - try { - QString serialKey = ui->m_pTextEditSerialKey->toPlainText(); - m_subscriptionManager->setSerialKey(serialKey); - } - catch (std::exception& e) { - message.critical(this, "Unknown Error", - tr("An error occurred while trying to activate Synergy. " - "Please contact the helpdesk, and provide the " - "following details.\n\n%1").arg(e.what())); - refreshSerialKey(); - return; - } + m_appConfig->activationHasRun(true); + m_appConfig->saveSettings(); - if (m_subscriptionManager->edition() != Edition::kUnregistered) { - message.information(this, "Activated!", - tr("Thanks for activating %1!").arg - (getEditionName(m_subscriptionManager->edition()))); - } - QDialog::accept(); + try { + QString serialKey = ui->m_pTextEditSerialKey->toPlainText(); + m_subscriptionManager->setSerialKey(serialKey); + } + catch (std::exception& e) { + message.critical(this, "Unknown Error", + tr("An error occurred while trying to activate Synergy. " + "Please contact the helpdesk, and provide the " + "following details.\n\n%1").arg(e.what())); + refreshSerialKey(); + return; + } + + if (m_subscriptionManager->activeLicense() != Edition::kUnregistered) { + message.information(this, "Activated!", + tr("Thanks for activating %1!").arg + (getEditionName(m_subscriptionManager->activeLicense()))); + } + QDialog::accept(); } diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 5adeab50..ad9d37d0 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -70,1351 +70,1352 @@ static const QString synergyConfigFilter(QObject::tr("Synergy Configurations (*. static const char* synergyIconFiles[] = { - ":/res/icons/16x16/synergy-disconnected.png", - ":/res/icons/16x16/synergy-disconnected.png", - ":/res/icons/16x16/synergy-connected.png", - ":/res/icons/16x16/synergy-transfering.png" + ":/res/icons/16x16/synergy-disconnected.png", + ":/res/icons/16x16/synergy-disconnected.png", + ":/res/icons/16x16/synergy-connected.png", + ":/res/icons/16x16/synergy-transfering.png" }; MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig, - SubscriptionManager& subscriptionManager) : - m_Settings(settings), - m_AppConfig(&appConfig), - m_SubscriptionManager(&subscriptionManager), - m_pSynergy(NULL), - m_SynergyState(synergyDisconnected), - m_ServerConfig(&m_Settings, 5, 3, m_AppConfig->screenName(), this), - m_pTempConfigFile(NULL), - m_pTrayIcon(NULL), - m_pTrayIconMenu(NULL), - m_AlreadyHidden(false), - m_pMenuBar(NULL), - m_pMenuFile(NULL), - m_pMenuEdit(NULL), - m_pMenuWindow(NULL), - m_pMenuHelp(NULL), - m_pZeroconfService(NULL), - m_pDataDownloader(NULL), - m_DownloadMessageBox(NULL), - m_pCancelButton(NULL), - m_SuppressAutoConfigWarning(false), - m_BonjourInstall(NULL), - m_SuppressEmptyServerWarning(false), - m_ExpectedRunningState(kStopped), - m_pSslCertificate(NULL) + SubscriptionManager& subscriptionManager) : + m_Settings(settings), + m_AppConfig(&appConfig), + m_SubscriptionManager(&subscriptionManager), + m_pSynergy(NULL), + m_SynergyState(synergyDisconnected), + m_ServerConfig(&m_Settings, 5, 3, m_AppConfig->screenName(), this), + m_pTempConfigFile(NULL), + m_pTrayIcon(NULL), + m_pTrayIconMenu(NULL), + m_AlreadyHidden(false), + m_pMenuBar(NULL), + m_pMenuFile(NULL), + m_pMenuEdit(NULL), + m_pMenuWindow(NULL), + m_pMenuHelp(NULL), + m_pZeroconfService(NULL), + m_pDataDownloader(NULL), + m_DownloadMessageBox(NULL), + m_pCancelButton(NULL), + m_SuppressAutoConfigWarning(false), + m_BonjourInstall(NULL), + m_SuppressEmptyServerWarning(false), + m_ExpectedRunningState(kStopped), + m_pSslCertificate(NULL) { - setupUi(this); + setupUi(this); - createMenuBar(); - loadSettings(); - initConnections(); + createMenuBar(); + loadSettings(); + initConnections(); - m_pWidgetUpdate->hide(); - m_VersionChecker.setApp(appPath(appConfig.synergycName())); - m_pLabelScreenName->setText(getScreenName()); - m_pLabelIpAddresses->setText(getIPAddresses()); + m_pWidgetUpdate->hide(); + m_VersionChecker.setApp(appPath(appConfig.synergycName())); + m_pLabelScreenName->setText(getScreenName()); + m_pLabelIpAddresses->setText(getIPAddresses()); #if defined(Q_OS_WIN) - // 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&))); - connect(&m_IpcClient, SIGNAL(infoMessage(const QString&)), this, SLOT(appendLogNote(const QString&))); - m_IpcClient.connectToHost(); + // 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&))); + connect(&m_IpcClient, SIGNAL(infoMessage(const QString&)), this, SLOT(appendLogNote(const QString&))); + m_IpcClient.connectToHost(); #endif - // change default size based on os + // change default size based on os #if defined(Q_OS_MAC) - resize(720, 550); - setMinimumSize(size()); + resize(720, 550); + setMinimumSize(size()); #elif defined(Q_OS_LINUX) - resize(700, 530); - setMinimumSize(size()); + resize(700, 530); + setMinimumSize(size()); #endif - m_SuppressAutoConfigWarning = true; - m_pCheckBoxAutoConfig->setChecked(appConfig.autoConfig()); - m_SuppressAutoConfigWarning = false; + m_SuppressAutoConfigWarning = true; + m_pCheckBoxAutoConfig->setChecked(appConfig.autoConfig()); + m_SuppressAutoConfigWarning = false; - m_pComboServerList->hide(); - m_pLabelPadlock->hide(); - setEdition (m_SubscriptionManager->edition()); + m_pComboServerList->hide(); + m_pLabelPadlock->hide(); + m_trialWidget->hide(); - this->m_trialWidget->hide(); - if (m_SubscriptionManager->isTrial()) { - beginTrial(); - } - - connect (this, SIGNAL(windowShown()), - this, SLOT(on_windowShown()), Qt::QueuedConnection); - - connect (m_SubscriptionManager, SIGNAL(editionChanged(Edition)), - this, SLOT(setEdition(Edition)), Qt::QueuedConnection); - - connect (m_SubscriptionManager, SIGNAL(beginTrial()), - this, SLOT(beginTrial()), Qt::QueuedConnection); - - connect (m_SubscriptionManager, SIGNAL(endTrial()), - this, SLOT(endTrial()), Qt::QueuedConnection); - - connect (m_AppConfig, SIGNAL(sslToggled(bool)), - this, SLOT(sslToggled(bool)), Qt::QueuedConnection); + connect (this, SIGNAL(windowShown()), + this, SLOT(on_windowShown()), Qt::QueuedConnection); + + connect (m_SubscriptionManager, SIGNAL(editionChanged(Edition)), + this, SLOT(setEdition(Edition)), Qt::QueuedConnection); + + connect (m_SubscriptionManager, SIGNAL(beginTrial(bool)), + this, SLOT(beginTrial(bool)), Qt::QueuedConnection); + + connect (m_SubscriptionManager, SIGNAL(endTrial(bool)), + this, SLOT(endTrial(bool)), Qt::QueuedConnection); + + connect (m_AppConfig, SIGNAL(sslToggled(bool)), + this, SLOT(sslToggled(bool)), Qt::QueuedConnection); + + m_SubscriptionManager->update(); } MainWindow::~MainWindow() { - if (appConfig().processMode() == Desktop) { - m_ExpectedRunningState = kStopped; - stopDesktop(); - } + if (appConfig().processMode() == Desktop) { + m_ExpectedRunningState = kStopped; + stopDesktop(); + } - saveSettings(); + saveSettings(); - delete m_pZeroconfService; + delete m_pZeroconfService; - if (m_DownloadMessageBox != NULL) { - delete m_DownloadMessageBox; - } + if (m_DownloadMessageBox != NULL) { + delete m_DownloadMessageBox; + } - if (m_BonjourInstall != NULL) { - delete m_BonjourInstall; - } + if (m_BonjourInstall != NULL) { + delete m_BonjourInstall; + } - delete m_pSslCertificate; + delete m_pSslCertificate; } void MainWindow::open() { - createTrayIcon(); + createTrayIcon(); - if (!autoHide()) { - showNormal(); - } + if (!autoHide()) { + showNormal(); + } - m_VersionChecker.checkLatest(); + m_VersionChecker.checkLatest(); - if (!appConfig().autoConfigPrompted()) { - promptAutoConfig(); - } + if (!appConfig().autoConfigPrompted()) { + promptAutoConfig(); + } - // 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) { - m_SuppressEmptyServerWarning = true; - startSynergy(); - m_SuppressEmptyServerWarning = false; - } + // 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) { + m_SuppressEmptyServerWarning = true; + startSynergy(); + m_SuppressEmptyServerWarning = false; + } } void MainWindow::onModeChanged(bool startDesktop, bool applyService) { - if (appConfig().processMode() == Service) - { - // 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())); + if (appConfig().processMode() == Service) + { + // 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())); - if (applyService) - { - stopDesktop(); - startSynergy(); - } - } - else if ((appConfig().processMode() == Desktop) && startDesktop) - { - stopService(); - startSynergy(); - } + if (applyService) + { + stopDesktop(); + startSynergy(); + } + } + else if ((appConfig().processMode() == Desktop) && startDesktop) + { + stopService(); + startSynergy(); + } } void MainWindow::setStatus(const QString &status) { - m_pStatusLabel->setText(status); + m_pStatusLabel->setText(status); } void MainWindow::createTrayIcon() { - m_pTrayIconMenu = new QMenu(this); + m_pTrayIconMenu = new QMenu(this); - m_pTrayIconMenu->addAction(m_pActionStartSynergy); - m_pTrayIconMenu->addAction(m_pActionStopSynergy); - m_pTrayIconMenu->addSeparator(); + 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_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); + m_pTrayIcon = new QSystemTrayIcon(this); + m_pTrayIcon->setContextMenu(m_pTrayIconMenu); - connect(m_pTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), - this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason))); + connect(m_pTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), + this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason))); - setIcon(synergyDisconnected); + setIcon(synergyDisconnected); - m_pTrayIcon->show(); + m_pTrayIcon->show(); } void MainWindow::retranslateMenuBar() { - m_pMenuFile->setTitle(tr("&File")); - m_pMenuEdit->setTitle(tr("&Edit")); - m_pMenuWindow->setTitle(tr("&Window")); - m_pMenuHelp->setTitle(tr("&Help")); + m_pMenuFile->setTitle(tr("&File")); + m_pMenuEdit->setTitle(tr("&Edit")); + m_pMenuWindow->setTitle(tr("&Window")); + m_pMenuHelp->setTitle(tr("&Help")); } void MainWindow::createMenuBar() { - 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(); + 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(); - m_pMenuBar->addAction(m_pMenuFile->menuAction()); - m_pMenuBar->addAction(m_pMenuEdit->menuAction()); + m_pMenuBar->addAction(m_pMenuFile->menuAction()); + m_pMenuBar->addAction(m_pMenuEdit->menuAction()); #if !defined(Q_OS_MAC) - m_pMenuBar->addAction(m_pMenuWindow->menuAction()); + m_pMenuBar->addAction(m_pMenuWindow->menuAction()); #endif - m_pMenuBar->addAction(m_pMenuHelp->menuAction()); + m_pMenuBar->addAction(m_pMenuHelp->menuAction()); - m_pMenuFile->addAction(m_pActionStartSynergy); - m_pMenuFile->addAction(m_pActionStopSynergy); - m_pMenuFile->addSeparator(); - m_pMenuFile->addAction(m_pActivate); - m_pMenuFile->addSeparator(); - 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); + m_pMenuFile->addAction(m_pActionStartSynergy); + m_pMenuFile->addAction(m_pActionStopSynergy); + m_pMenuFile->addSeparator(); + m_pMenuFile->addAction(m_pActivate); + m_pMenuFile->addSeparator(); + 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); - setMenuBar(m_pMenuBar); + setMenuBar(m_pMenuBar); } 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 - m_pRadioExternalConfig->setChecked(settings().value("useExternalConfig", false).toBool()); - m_pRadioInternalConfig->setChecked(settings().value("useInternalConfig", true).toBool()); + // the next two must come BEFORE loading groupServerChecked and groupClientChecked or + // disabling and/or enabling the right widgets won't automatically work + m_pRadioExternalConfig->setChecked(settings().value("useExternalConfig", false).toBool()); + m_pRadioInternalConfig->setChecked(settings().value("useInternalConfig", true).toBool()); - 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()); + 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())); - connect(&m_VersionChecker, SIGNAL(updateFound(const QString&)), this, SLOT(updateFound(const QString&))); + 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())); + connect(&m_VersionChecker, SIGNAL(updateFound(const QString&)), this, SLOT(updateFound(const QString&))); } void MainWindow::saveSettings() { - // program settings - settings().setValue("groupServerChecked", m_pGroupServer->isChecked()); - settings().setValue("useExternalConfig", m_pRadioExternalConfig->isChecked()); - settings().setValue("configFile", m_pLineEditConfigFile->text()); - settings().setValue("useInternalConfig", m_pRadioInternalConfig->isChecked()); - settings().setValue("groupClientChecked", m_pGroupClient->isChecked()); - settings().setValue("serverHostname", m_pLineEditHostname->text()); + // program settings + settings().setValue("groupServerChecked", m_pGroupServer->isChecked()); + settings().setValue("useExternalConfig", m_pRadioExternalConfig->isChecked()); + settings().setValue("configFile", m_pLineEditConfigFile->text()); + settings().setValue("useInternalConfig", m_pRadioInternalConfig->isChecked()); + settings().setValue("groupClientChecked", m_pGroupClient->isChecked()); + settings().setValue("serverHostname", m_pLineEditHostname->text()); - settings().sync(); + settings().sync(); } void MainWindow::setIcon(qSynergyState state) { - QIcon icon; - icon.addFile(synergyIconFiles[state]); + QIcon icon; + icon.addFile(synergyIconFiles[state]); - if (m_pTrayIcon) - m_pTrayIcon->setIcon(icon); + if (m_pTrayIcon) + m_pTrayIcon->setIcon(icon); } void MainWindow::trayActivated(QSystemTrayIcon::ActivationReason reason) { #ifndef Q_OS_WIN - if (reason == QSystemTrayIcon::DoubleClick) - { - if (isVisible()) - { - hide(); - } - else - { - showNormal(); - activateWindow(); - } - } + if (reason == QSystemTrayIcon::DoubleClick) + { + if (isVisible()) + { + hide(); + } + else + { + showNormal(); + activateWindow(); + } + } #endif } void MainWindow::logOutput() { - if (m_pSynergy) - { - QString text(m_pSynergy->readAllStandardOutput()); - foreach(QString line, text.split(QRegExp("\r|\n|\r\n"))) - { - if (!line.isEmpty()) - { - appendLogRaw(line); - } - } - } + if (m_pSynergy) + { + QString text(m_pSynergy->readAllStandardOutput()); + foreach(QString line, text.split(QRegExp("\r|\n|\r\n"))) + { + if (!line.isEmpty()) + { + appendLogRaw(line); + } + } + } } void MainWindow::logError() { - if (m_pSynergy) - { - appendLogRaw(m_pSynergy->readAllStandardError()); - } + if (m_pSynergy) + { + appendLogRaw(m_pSynergy->readAllStandardError()); + } } void MainWindow::updateFound(const QString &version) { - m_pWidgetUpdate->show(); - m_pLabelUpdate->setText( - tr("

Your version of Synergy is out of date. " - "Version %1 is now available to " - "download.

") - .arg(version).arg(DOWNLOAD_URL)); + m_pWidgetUpdate->show(); + m_pLabelUpdate->setText( + tr("

Your version of Synergy is out of date. " + "Version %1 is now available to " + "download.

") + .arg(version).arg(DOWNLOAD_URL)); } void MainWindow::appendLogInfo(const QString& text) { - appendLogRaw(getTimeStamp() + " INFO: " + text); + appendLogRaw(getTimeStamp() + " INFO: " + text); } void MainWindow::appendLogDebug(const QString& text) { - if (appConfig().logLevel() >= 4) { - appendLogRaw(getTimeStamp() + " DEBUG: " + text); - } + if (appConfig().logLevel() >= 4) { + appendLogRaw(getTimeStamp() + " DEBUG: " + text); + } } void MainWindow::appendLogError(const QString& text) { - appendLogRaw(getTimeStamp() + " ERROR: " + text); + appendLogRaw(getTimeStamp() + " ERROR: " + text); } void MainWindow::appendLogRaw(const QString& text) { - foreach(QString line, text.split(QRegExp("\r|\n|\r\n"))) { - if (!line.isEmpty()) { - m_pLogOutput->append(line); - updateStateFromLogLine(line); - } - } + foreach(QString line, text.split(QRegExp("\r|\n|\r\n"))) { + if (!line.isEmpty()) { + m_pLogOutput->append(line); + updateStateFromLogLine(line); + } + } } void MainWindow::updateStateFromLogLine(const QString &line) { - checkConnected(line); - checkFingerprint(line); + checkConnected(line); + checkFingerprint(line); } void MainWindow::checkConnected(const QString& line) { - // TODO: implement ipc connection state messages to replace this hack. - if (line.contains("started server") || - line.contains("connected to server") || - line.contains("watchdog status: ok")) - { - setSynergyState(synergyConnected); + // TODO: implement ipc connection state messages to replace this hack. + if (line.contains("started server") || + line.contains("connected to server") || + line.contains("watchdog status: ok")) + { + setSynergyState(synergyConnected); - if (!appConfig().startedBefore() && isVisible()) { - QMessageBox::information( - this, "Synergy", - tr("Synergy is now connected. You can close the " - "config window and Synergy will remain connected in " - "the background.")); + if (!appConfig().startedBefore() && isVisible()) { + QMessageBox::information( + this, "Synergy", + tr("Synergy is now connected. You can close the " + "config window and Synergy will remain connected in " + "the background.")); - appConfig().setStartedBefore(true); - appConfig().saveSettings(); - } - } + appConfig().setStartedBefore(true); + appConfig().saveSettings(); + } + } } void MainWindow::checkFingerprint(const QString& line) { - QRegExp fingerprintRegex(".*server fingerprint: ([A-F0-9:]+)"); - if (!fingerprintRegex.exactMatch(line)) { - return; - } + QRegExp fingerprintRegex(".*server fingerprint: ([A-F0-9:]+)"); + if (!fingerprintRegex.exactMatch(line)) { + return; + } - QString fingerprint = fingerprintRegex.cap(1); - if (Fingerprint::trustedServers().isTrusted(fingerprint)) { - return; - } + QString fingerprint = fingerprintRegex.cap(1); + if (Fingerprint::trustedServers().isTrusted(fingerprint)) { + return; + } - static bool messageBoxAlreadyShown = false; + static bool messageBoxAlreadyShown = false; - if (!messageBoxAlreadyShown) { - stopSynergy(); + if (!messageBoxAlreadyShown) { + stopSynergy(); - 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); + 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(); - } + if (fingerprintReply == QMessageBox::Yes) { + // restart core process after trusting fingerprint. + Fingerprint::trustedServers().trust(fingerprint); + startSynergy(); + } - messageBoxAlreadyShown = false; - } + messageBoxAlreadyShown = false; + } } bool MainWindow::autoHide() { - if ((appConfig().processMode() == Desktop) && - appConfig().getAutoHide()) { - hide(); - return true; - } + if ((appConfig().processMode() == Desktop) && + appConfig().getAutoHide()) { + hide(); + return true; + } - return false; + return false; } QString MainWindow::getTimeStamp() { - QDateTime current = QDateTime::currentDateTime(); - return '[' + current.toString(Qt::ISODate) + ']'; + QDateTime current = QDateTime::currentDateTime(); + return '[' + current.toString(Qt::ISODate) + ']'; } void MainWindow::restartSynergy() { - stopSynergy(); - startSynergy(); + stopSynergy(); + startSynergy(); } void MainWindow::proofreadInfo() { - setEdition(m_AppConfig->edition()); // Why is this here? + setEdition(m_AppConfig->edition()); // Why is this here? - int oldState = m_SynergyState; - m_SynergyState = synergyDisconnected; - setSynergyState((qSynergyState)oldState); + int oldState = m_SynergyState; + m_SynergyState = synergyDisconnected; + setSynergyState((qSynergyState)oldState); } void MainWindow::showEvent(QShowEvent* event) { - QMainWindow::showEvent(event); - emit windowShown(); + QMainWindow::showEvent(event); + emit windowShown(); } void MainWindow::clearLog() { - m_pLogOutput->clear(); + m_pLogOutput->clear(); } void MainWindow::startSynergy() { - bool desktopMode = appConfig().processMode() == Desktop; - bool serviceMode = appConfig().processMode() == Service; + bool desktopMode = appConfig().processMode() == Desktop; + bool serviceMode = appConfig().processMode() == Service; - appendLogDebug("starting process"); - m_ExpectedRunningState = kStarted; - setSynergyState(synergyConnecting); + appendLogDebug("starting process"); + m_ExpectedRunningState = kStarted; + setSynergyState(synergyConnecting); - QString app; - QStringList args; + QString app; + QStringList args; - args << "-f" << "--no-tray" << "--debug" << appConfig().logLevelText(); + args << "-f" << "--no-tray" << "--debug" << appConfig().logLevelText(); - args << "--name" << getScreenName(); + args << "--name" << getScreenName(); - if (desktopMode) - { - setSynergyProcess(new QProcess(this)); - } - else - { - // tell client/server to talk to daemon through ipc. - args << "--ipc"; + if (desktopMode) + { + setSynergyProcess(new QProcess(this)); + } + else + { + // tell client/server to talk to daemon through ipc. + args << "--ipc"; #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). - // 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"; - } + // 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). + // 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"; + } #endif - } + } #ifndef Q_OS_LINUX - if (m_ServerConfig.enableDragAndDrop()) { - args << "--enable-drag-drop"; - } + if (m_ServerConfig.enableDragAndDrop()) { + args << "--enable-drag-drop"; + } #endif - if (m_AppConfig->getCryptoEnabled()) { - args << "--enable-crypto"; - } + if (m_AppConfig->getCryptoEnabled()) { + args << "--enable-crypto"; + } #if defined(Q_OS_WIN) - // 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(); + // 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(); #endif - if ((synergyType() == synergyClient && !clientArgs(args, app)) - || (synergyType() == synergyServer && !serverArgs(args, app))) - { - stopSynergy(); - return; - } + if ((synergyType() == synergyClient && !clientArgs(args, app)) + || (synergyType() == synergyServer && !serverArgs(args, app))) + { + stopSynergy(); + return; + } - 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())); - } + 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()) - appendLogRaw(""); + // put a space between last log output and new instance. + if (!m_pLogOutput->toPlainText().isEmpty()) + appendLogRaw(""); - appendLogInfo("starting " + QString(synergyType() == synergyServer ? "server" : "client")); + appendLogInfo("starting " + QString(synergyType() == synergyServer ? "server" : "client")); - qDebug() << args; + qDebug() << args; - // show command if debug log level... - if (appConfig().logLevel() >= 4) { - appendLogInfo(QString("command: %1 %2").arg(app, args.join(" "))); - } + // show command if debug log level... + if (appConfig().logLevel() >= 4) { + appendLogInfo(QString("command: %1 %2").arg(app, args.join(" "))); + } - appendLogInfo("config file: " + configFilename()); - appendLogInfo("log level: " + appConfig().logLevelText()); + appendLogInfo("config file: " + configFilename()); + appendLogInfo("log level: " + appConfig().logLevelText()); - if (appConfig().logToFile()) - appendLogInfo("log file: " + appConfig().logFilename()); + if (appConfig().logToFile()) + appendLogInfo("log file: " + appConfig().logFilename()); - if (desktopMode) - { - synergyProcess()->start(app, args); - if (!synergyProcess()->waitForStarted()) - { - show(); - QMessageBox::warning(this, tr("Program can not be started"), QString(tr("The executable

%1

could not be successfully started, although it does exist. Please check if you have sufficient permissions to run this program.").arg(app))); - return; - } - } + if (desktopMode) + { + synergyProcess()->start(app, args); + if (!synergyProcess()->waitForStarted()) + { + show(); + QMessageBox::warning(this, tr("Program can not be started"), QString(tr("The executable

%1

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(" ")); - m_IpcClient.sendCommand(command, appConfig().elevateMode()); - } + if (serviceMode) + { + QString command(app + " " + args.join(" ")); + m_IpcClient.sendCommand(command, appConfig().elevateMode()); + } } void MainWindow::sslToggled (bool enabled) { - if (enabled) { - m_pSslCertificate = new SslCertificate(this); - m_pSslCertificate->generateCertificate(); - } - updateLocalFingerprint(); + if (enabled) { + m_pSslCertificate = new SslCertificate(this); + m_pSslCertificate->generateCertificate(); + } + updateLocalFingerprint(); } bool MainWindow::clientArgs(QStringList& args, QString& app) { - app = appPath(appConfig().synergycName()); + 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; - } + 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; + } #if defined(Q_OS_WIN) - // wrap in quotes so a malicious user can't start \Program.exe as admin. - app = QString("\"%1\"").arg(app); + // wrap in quotes so a malicious user can't start \Program.exe as admin. + app = QString("\"%1\"").arg(app); #endif - if (appConfig().logToFile()) - { - appConfig().persistLogDir(); - args << "--log" << appConfig().logFilenameCmd(); - } + if (appConfig().logToFile()) + { + appConfig().persistLogDir(); + args << "--log" << appConfig().logFilenameCmd(); + } - // check auto config first, if it is disabled or no server detected, - // use line edit host name if it is not empty - if (m_pCheckBoxAutoConfig->isChecked()) { - if (m_pComboServerList->count() != 0) { - QString serverIp = m_pComboServerList->currentText(); - args << serverIp + ":" + QString::number(appConfig().port()); - return true; - } - } + // check auto config first, if it is disabled or no server detected, + // use line edit host name if it is not empty + if (m_pCheckBoxAutoConfig->isChecked()) { + if (m_pComboServerList->count() != 0) { + QString serverIp = m_pComboServerList->currentText(); + args << serverIp + ":" + QString::number(appConfig().port()); + return true; + } + } - 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.")); - } - return false; - } + 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.")); + } + return false; + } - args << m_pLineEditHostname->text() + ":" + QString::number(appConfig().port()); + args << m_pLineEditHostname->text() + ":" + QString::number(appConfig().port()); - return true; + 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()) - { - QMessageBox::critical(this, tr("Cannot write configuration file"), tr("The temporary configuration file required to start synergy can not be written.")); - return ""; - } + 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()) + { + QMessageBox::critical(this, tr("Cannot write configuration file"), tr("The temporary configuration file required to start synergy can not be written.")); + return ""; + } - serverConfig().save(*m_pTempConfigFile); - filename = m_pTempConfigFile->fileName(); + 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()) - return ""; - } + 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()) + return ""; + } - filename = m_pLineEditConfigFile->text(); - } - return filename; + filename = m_pLineEditConfigFile->text(); + } + return filename; } QString MainWindow::address() { - QString i = appConfig().interface(); - return (!i.isEmpty() ? i : "") + ":" + QString::number(appConfig().port()); + QString i = appConfig().interface(); + return (!i.isEmpty() ? i : "") + ":" + QString::number(appConfig().port()); } QString MainWindow::appPath(const QString& name) { - return appConfig().synergyProgramDir() + name; + return appConfig().synergyProgramDir() + name; } bool MainWindow::serverArgs(QStringList& args, QString& app) { - app = appPath(appConfig().synergysName()); + 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; - } + if (!QFile::exists(app)) + { + QMessageBox::warning(this, tr("Synergy server not found"), + tr("The executable for the synergy server does not exist.")); + return false; + } #if defined(Q_OS_WIN) - // wrap in quotes so a malicious user can't start \Program.exe as admin. - app = QString("\"%1\"").arg(app); + // wrap in quotes so a malicious user can't start \Program.exe as admin. + app = QString("\"%1\"").arg(app); #endif - if (appConfig().logToFile()) - { - appConfig().persistLogDir(); + if (appConfig().logToFile()) + { + appConfig().persistLogDir(); - args << "--log" << appConfig().logFilenameCmd(); - } + args << "--log" << appConfig().logFilenameCmd(); + } - QString configFilename = this->configFilename(); + QString configFilename = this->configFilename(); #if defined(Q_OS_WIN) - // wrap in quotes in case username contains spaces. - configFilename = QString("\"%1\"").arg(configFilename); + // wrap in quotes in case username contains spaces. + configFilename = QString("\"%1\"").arg(configFilename); #endif - args << "-c" << configFilename << "--address" << address(); + args << "-c" << configFilename << "--address" << address(); #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(); + // 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; + 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)); + 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); + 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 - return true; + return true; } void MainWindow::stopSynergy() { - appendLogDebug("stopping process"); + appendLogDebug("stopping process"); - m_ExpectedRunningState = kStopped; + m_ExpectedRunningState = kStopped; - if (appConfig().processMode() == Service) - { - stopService(); - } - else if (appConfig().processMode() == Desktop) - { - stopDesktop(); - } + if (appConfig().processMode() == Service) + { + stopService(); + } + else if (appConfig().processMode() == Desktop) + { + stopDesktop(); + } - setSynergyState(synergyDisconnected); + setSynergyState(synergyDisconnected); - // 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; + // 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. - m_AlreadyHidden = false; + // reset so that new connects cause auto-hide. + m_AlreadyHidden = false; } void MainWindow::stopService() { - // send empty command to stop service from laucning anything. - m_IpcClient.sendCommand("", appConfig().elevateMode()); + // send empty command to stop service from laucning anything. + m_IpcClient.sendCommand("", appConfig().elevateMode()); } void MainWindow::stopDesktop() { - QMutexLocker locker(&m_StopDesktopMutex); - if (!synergyProcess()) { - return; - } + QMutexLocker locker(&m_StopDesktopMutex); + if (!synergyProcess()) { + return; + } - appendLogInfo("stopping synergy desktop process"); + appendLogInfo("stopping synergy desktop process"); - if (synergyProcess()->isOpen()) { - synergyProcess()->close(); - } + if (synergyProcess()->isOpen()) { + synergyProcess()->close(); + } - delete synergyProcess(); - setSynergyProcess(NULL); + delete synergyProcess(); + setSynergyProcess(NULL); } void MainWindow::synergyFinished(int exitCode, QProcess::ExitStatus) { - if (exitCode == 0) { - appendLogInfo(QString("process exited normally")); - } - else { - appendLogError(QString("process exited with error code: %1").arg(exitCode)); - } + if (exitCode == 0) { + appendLogInfo(QString("process exited normally")); + } + else { + appendLogError(QString("process exited with error code: %1").arg(exitCode)); + } - if (m_ExpectedRunningState == kStarted) { - QTimer::singleShot(1000, this, SLOT(startSynergy())); - appendLogInfo(QString("detected process not running, auto restarting")); - } - else { - setSynergyState(synergyDisconnected); - } + if (m_ExpectedRunningState == kStarted) { + QTimer::singleShot(1000, this, SLOT(startSynergy())); + appendLogInfo(QString("detected process not running, auto restarting")); + } + else { + setSynergyState(synergyDisconnected); + } } void MainWindow::setSynergyState(qSynergyState state) { - if (synergyState() == state) - return; + 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")); - m_pButtonApply->setEnabled(true); - } - else if (state == synergyDisconnected) - { - disconnect (m_pButtonToggleStart, SIGNAL(clicked()), m_pActionStopSynergy, SLOT(trigger())); - connect (m_pButtonToggleStart, SIGNAL(clicked()), m_pActionStartSynergy, SLOT(trigger())); - m_pButtonToggleStart->setText(tr("&Start")); - m_pButtonApply->setEnabled(false); - } + 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")); + m_pButtonApply->setEnabled(true); + } + else if (state == synergyDisconnected) + { + disconnect (m_pButtonToggleStart, SIGNAL(clicked()), m_pActionStopSynergy, SLOT(trigger())); + connect (m_pButtonToggleStart, SIGNAL(clicked()), m_pActionStartSynergy, SLOT(trigger())); + m_pButtonToggleStart->setText(tr("&Start")); + m_pButtonApply->setEnabled(false); + } - bool connected = false; - if (state == synergyConnected || state == synergyTransfering) { - connected = true; - } + bool connected = false; + if (state == synergyConnected || state == synergyTransfering) { + connected = true; + } - m_pActionStartSynergy->setEnabled(!connected); - m_pActionStopSynergy->setEnabled(connected); + m_pActionStartSynergy->setEnabled(!connected); + m_pActionStopSynergy->setEnabled(connected); - switch (state) - { - case synergyConnected: { - if (m_AppConfig->getCryptoEnabled()) { - m_pLabelPadlock->show(); - } - else { - m_pLabelPadlock->hide(); - } + switch (state) + { + case synergyConnected: { + if (m_AppConfig->getCryptoEnabled()) { + m_pLabelPadlock->show(); + } + else { + m_pLabelPadlock->hide(); + } - setStatus(tr("Synergy is running.")); + setStatus(tr("Synergy is running.")); - break; - } - case synergyConnecting: - m_pLabelPadlock->hide(); - setStatus(tr("Synergy is starting.")); - break; - case synergyDisconnected: - m_pLabelPadlock->hide(); - setStatus(tr("Synergy is not running.")); - break; - case synergyTransfering: - break; - } + break; + } + case synergyConnecting: + m_pLabelPadlock->hide(); + setStatus(tr("Synergy is starting.")); + break; + case synergyDisconnected: + m_pLabelPadlock->hide(); + setStatus(tr("Synergy is not running.")); + break; + case synergyTransfering: + break; + } - setIcon(state); + setIcon(state); - m_SynergyState = state; + m_SynergyState = state; } void MainWindow::setVisible(bool visible) { - QMainWindow::setVisible(visible); - m_pActionMinimize->setEnabled(visible); - m_pActionRestore->setEnabled(!visible); + QMainWindow::setVisible(visible); + m_pActionMinimize->setEnabled(visible); + m_pActionRestore->setEnabled(!visible); #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 // lion - // dock hide only supported on lion :( - ProcessSerialNumber psn = { 0, kCurrentProcess }; - GetCurrentProcess(&psn); - if (visible) - TransformProcessType(&psn, kProcessTransformToForegroundApplication); - else - TransformProcessType(&psn, kProcessTransformToBackgroundApplication); + // dock hide only supported on lion :( + ProcessSerialNumber psn = { 0, kCurrentProcess }; + GetCurrentProcess(&psn); + if (visible) + TransformProcessType(&psn, kProcessTransformToForegroundApplication); + else + TransformProcessType(&psn, kProcessTransformToBackgroundApplication); #endif } QString MainWindow::getIPAddresses() { - QList addresses = QNetworkInterface::allAddresses(); + QList 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)) { + 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, "; + 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 = "%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 = "%1, "; + } - result += format.arg(address); - } - } + result += format.arg(address); + } + } - if (result == "") { - return tr("Unknown"); - } + if (result == "") { + return tr("Unknown"); + } - // remove trailing comma. - result.chop(2); + // remove trailing comma. + result.chop(2); - return result; + return result; } QString MainWindow::getScreenName() { - if (appConfig().screenName() == "") { - return QHostInfo::localHostName(); - } - else { - return appConfig().screenName(); - } + if (appConfig().screenName() == "") { + return QHostInfo::localHostName(); + } + else { + return appConfig().screenName(); + } } void MainWindow::changeEvent(QEvent* event) { - if (event != 0) - { - switch (event->type()) - { - case QEvent::LanguageChange: - { - retranslateUi(this); - retranslateMenuBar(); + if (event != 0) + { + switch (event->type()) + { + case QEvent::LanguageChange: + { + retranslateUi(this); + retranslateMenuBar(); - proofreadInfo(); + proofreadInfo(); - break; - } - default: - QMainWindow::changeEvent(event); - } - } + break; + } + default: + QMainWindow::changeEvent(event); + } + } } void MainWindow::updateZeroconfService() { - QMutexLocker locker(&m_UpdateZeroconfMutex); + QMutexLocker locker(&m_UpdateZeroconfMutex); - if (isBonjourRunning()) { - if (!m_AppConfig->wizardShouldRun()) { - if (m_pZeroconfService) { - delete m_pZeroconfService; - m_pZeroconfService = NULL; - } + if (isBonjourRunning()) { + if (!m_AppConfig->wizardShouldRun()) { + if (m_pZeroconfService) { + delete m_pZeroconfService; + m_pZeroconfService = NULL; + } - if (m_AppConfig->autoConfig() || synergyType() == synergyServer) { - m_pZeroconfService = new ZeroconfService(this); - } - } - } + if (m_AppConfig->autoConfig() || synergyType() == synergyServer) { + m_pZeroconfService = new ZeroconfService(this); + } + } + } } void MainWindow::serverDetected(const QString name) { - if (m_pComboServerList->findText(name) == -1) { - // Note: the first added item triggers startSynergy - m_pComboServerList->addItem(name); - } + if (m_pComboServerList->findText(name) == -1) { + // Note: the first added item triggers startSynergy + m_pComboServerList->addItem(name); + } - if (m_pComboServerList->count() > 1) { - m_pComboServerList->show(); - } + if (m_pComboServerList->count() > 1) { + m_pComboServerList->show(); + } } void MainWindow::setEdition(Edition edition) { - setWindowTitle(getEditionName(edition)); - if (m_AppConfig->getCryptoEnabled()) { - m_pSslCertificate = new SslCertificate(this); - m_pSslCertificate->generateCertificate(); - } - updateLocalFingerprint(); - saveSettings(); + setWindowTitle(getEditionName(edition)); + if (m_AppConfig->getCryptoEnabled()) { + m_pSslCertificate = new SslCertificate(this); + m_pSslCertificate->generateCertificate(); + } + updateLocalFingerprint(); + saveSettings(); } -void MainWindow::beginTrial() +void MainWindow::beginTrial(bool isExpiring) { - this->m_trialWidget->show(); + if (isExpiring) { + this->m_trialWidget->show(); + } } -void MainWindow::endTrial() +void MainWindow::endTrial(bool isExpired) { - this->m_trialWidget->hide(); + if (!isExpired) { + this->m_trialWidget->hide(); + } } void MainWindow::updateLocalFingerprint() { - if (m_AppConfig->getCryptoEnabled() && 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); - } + if (m_AppConfig->getCryptoEnabled() && 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); + } } SubscriptionManager& MainWindow::subscriptionManager() const { - return *m_SubscriptionManager; + return *m_SubscriptionManager; } void MainWindow::on_m_pGroupClient_toggled(bool on) { - m_pGroupServer->setChecked(!on); - if (on) { - updateZeroconfService(); - } + m_pGroupServer->setChecked(!on); + if (on) { + updateZeroconfService(); + } } void MainWindow::on_m_pGroupServer_toggled(bool on) { - m_pGroupClient->setChecked(!on); - if (on) { - updateZeroconfService(); - } + m_pGroupClient->setChecked(!on); + if (on) { + updateZeroconfService(); + } } bool MainWindow::on_m_pButtonBrowseConfigFile_clicked() { - QString fileName = QFileDialog::getOpenFileName(this, tr("Browse for a synergys config file"), QString(), synergyConfigFilter); + QString fileName = QFileDialog::getOpenFileName(this, tr("Browse for a synergys config file"), QString(), synergyConfigFilter); - if (!fileName.isEmpty()) - { - m_pLineEditConfigFile->setText(fileName); - return true; - } + if (!fileName.isEmpty()) + { + m_pLineEditConfigFile->setText(fileName); + return true; + } - return false; + return false; } bool MainWindow::on_m_pActionSave_triggered() { - QString fileName = QFileDialog::getSaveFileName(this, tr("Save configuration as...")); + 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; - } + if (!fileName.isEmpty() && !serverConfig().save(fileName)) + { + QMessageBox::warning(this, tr("Save failed"), tr("Could not save configuration to file.")); + return true; + } - return false; + return false; } void MainWindow::on_m_pActionAbout_triggered() { - AboutDialog dlg(this, appPath(appConfig().synergycName())); - dlg.exec(); + AboutDialog dlg(this, appPath(appConfig().synergycName())); + dlg.exec(); } void MainWindow::on_m_pActionSettings_triggered() { - ProcessMode lastProcessMode = appConfig().processMode(); + ProcessMode lastProcessMode = appConfig().processMode(); - SettingsDialog dlg(this, appConfig()); - dlg.exec(); + SettingsDialog dlg(this, appConfig()); + dlg.exec(); - if (lastProcessMode != appConfig().processMode()) - { - onModeChanged(true, true); - } + if (lastProcessMode != appConfig().processMode()) + { + onModeChanged(true, true); + } } void MainWindow::autoAddScreen(const QString name) { - if (!m_ServerConfig.ignoreAutoConfigClient()) { - 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; + if (!m_ServerConfig.ignoreAutoConfigClient()) { + 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; - } - } - else { - restartSynergy(); - } - } + case kAutoAddScreenManualClient: + showConfigureServer( + tr("Please drag the new client screen (%1) " + "to the desired position on the grid.") + .arg(name)); + break; + } + } + else { + restartSynergy(); + } + } } void MainWindow::showConfigureServer(const QString& message) { - ServerConfigDialog dlg(this, serverConfig(), appConfig().screenName()); - dlg.message(message); - dlg.exec(); + ServerConfigDialog dlg(this, serverConfig(), appConfig().screenName()); + dlg.message(message); + dlg.exec(); } void MainWindow::on_m_pButtonConfigureServer_clicked() { - showConfigureServer(); + showConfigureServer(); } void MainWindow::on_m_pActivate_triggered() { - ActivationDialog activationDialog(this, appConfig(), subscriptionManager()); - activationDialog.exec(); + ActivationDialog activationDialog(this, appConfig(), subscriptionManager()); + activationDialog.exec(); } void MainWindow::on_m_pButtonApply_clicked() { - restartSynergy(); + restartSynergy(); } #if defined(Q_OS_WIN) bool MainWindow::isServiceRunning(QString name) { - SC_HANDLE hSCManager; - hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT); - if (hSCManager == NULL) { - appendLogError("failed to open a service controller manager, error: " + - GetLastError()); - return false; - } + SC_HANDLE hSCManager; + hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT); + if (hSCManager == NULL) { + appendLogError("failed to open a service controller manager, error: " + + GetLastError()); + return false; + } - SC_HANDLE hService; - int length = name.length(); - wchar_t* array = new wchar_t[length + 1]; - name.toWCharArray(array); - array[length] = '\0'; + 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); + hService = OpenService(hSCManager, array, SERVICE_QUERY_STATUS); - delete[] array; + delete[] array; - if (hService == NULL) { - appendLogDebug("failed to open service: " + name); - return false; - } + if (hService == NULL) { + appendLogDebug("failed to open service: " + name); + return false; + } - SERVICE_STATUS status; - if (QueryServiceStatus(hService, &status)) { - if (status.dwCurrentState == SERVICE_RUNNING) { - return true; - } - } + SERVICE_STATUS status; + if (QueryServiceStatus(hService, &status)) { + if (status.dwCurrentState == SERVICE_RUNNING) { + return true; + } + } #else bool MainWindow::isServiceRunning() { #endif - return false; + return false; } bool MainWindow::isBonjourRunning() { - bool result = false; + bool result = false; #if defined(Q_OS_WIN) - result = isServiceRunning("Bonjour Service"); + result = isServiceRunning("Bonjour Service"); #else - result = true; + result = true; #endif - return result; + return result; } void MainWindow::downloadBonjour() { #if defined(Q_OS_WIN) - QUrl url; - int arch = getProcessorArch(); - if (arch == kProcessorArchWin32) { - url.setUrl(bonjourBaseUrl + bonjourFilename32); - appendLogInfo("downloading 32-bit Bonjour"); - } - else if (arch == kProcessorArchWin64) { - url.setUrl(bonjourBaseUrl + bonjourFilename64); - appendLogInfo("downloading 64-bit Bonjour"); - } - else { - QMessageBox::critical( - this, tr("Synergy"), - tr("Failed to detect system architecture.")); - return; - } + QUrl url; + int arch = getProcessorArch(); + if (arch == kProcessorArchWin32) { + url.setUrl(bonjourBaseUrl + bonjourFilename32); + appendLogInfo("downloading 32-bit Bonjour"); + } + else if (arch == kProcessorArchWin64) { + url.setUrl(bonjourBaseUrl + bonjourFilename64); + appendLogInfo("downloading 64-bit Bonjour"); + } + else { + QMessageBox::critical( + this, tr("Synergy"), + tr("Failed to detect system architecture.")); + return; + } - if (m_pDataDownloader == NULL) { - m_pDataDownloader = new DataDownloader(this); - connect(m_pDataDownloader, SIGNAL(isComplete()), SLOT(installBonjour())); - } + if (m_pDataDownloader == NULL) { + m_pDataDownloader = new DataDownloader(this); + connect(m_pDataDownloader, SIGNAL(isComplete()), SLOT(installBonjour())); + } - m_pDataDownloader->download(url); + m_pDataDownloader->download(url); - if (m_DownloadMessageBox == NULL) { - m_DownloadMessageBox = new QMessageBox(this); - m_DownloadMessageBox->setWindowTitle("Synergy"); - m_DownloadMessageBox->setIcon(QMessageBox::Information); - m_DownloadMessageBox->setText("Installing Bonjour, please wait..."); - m_DownloadMessageBox->setStandardButtons(0); - m_pCancelButton = m_DownloadMessageBox->addButton( - tr("Cancel"), QMessageBox::RejectRole); - } + if (m_DownloadMessageBox == NULL) { + m_DownloadMessageBox = new QMessageBox(this); + m_DownloadMessageBox->setWindowTitle("Synergy"); + m_DownloadMessageBox->setIcon(QMessageBox::Information); + m_DownloadMessageBox->setText("Installing Bonjour, please wait..."); + m_DownloadMessageBox->setStandardButtons(0); + m_pCancelButton = m_DownloadMessageBox->addButton( + tr("Cancel"), QMessageBox::RejectRole); + } - m_DownloadMessageBox->exec(); + m_DownloadMessageBox->exec(); - if (m_DownloadMessageBox->clickedButton() == m_pCancelButton) { - m_pDataDownloader->cancel(); - } + if (m_DownloadMessageBox->clickedButton() == m_pCancelButton) { + m_pDataDownloader->cancel(); + } #endif } void MainWindow::installBonjour() { #if defined(Q_OS_WIN) - QString tempLocation = QDesktopServices::storageLocation( - QDesktopServices::TempLocation); - QString filename = tempLocation; - filename.append("\\").append(bonjourTargetFilename); - QFile file(filename); - if (!file.open(QIODevice::WriteOnly)) { - m_DownloadMessageBox->hide(); + QString tempLocation = QDesktopServices::storageLocation( + QDesktopServices::TempLocation); + QString filename = tempLocation; + filename.append("\\").append(bonjourTargetFilename); + QFile file(filename); + if (!file.open(QIODevice::WriteOnly)) { + m_DownloadMessageBox->hide(); - QMessageBox::warning( - this, "Synergy", - tr("Failed to download Bonjour installer to location: %1") - .arg(tempLocation)); - return; - } + QMessageBox::warning( + this, "Synergy", + tr("Failed to download Bonjour installer to location: %1") + .arg(tempLocation)); + return; + } - file.write(m_pDataDownloader->data()); - file.close(); + file.write(m_pDataDownloader->data()); + file.close(); - QStringList arguments; - arguments.append("/i"); - QString winFilename = QDir::toNativeSeparators(filename); - arguments.append(winFilename); - arguments.append("/passive"); - if (m_BonjourInstall == NULL) { - m_BonjourInstall = new CommandProcess("msiexec", arguments); - } + QStringList arguments; + arguments.append("/i"); + QString winFilename = QDir::toNativeSeparators(filename); + arguments.append(winFilename); + arguments.append("/passive"); + if (m_BonjourInstall == NULL) { + m_BonjourInstall = new CommandProcess("msiexec", arguments); + } - QThread* thread = new QThread; - connect(m_BonjourInstall, SIGNAL(finished()), this, - SLOT(bonjourInstallFinished())); - connect(m_BonjourInstall, SIGNAL(finished()), thread, SLOT(quit())); - connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); + QThread* thread = new QThread; + connect(m_BonjourInstall, SIGNAL(finished()), this, + SLOT(bonjourInstallFinished())); + connect(m_BonjourInstall, SIGNAL(finished()), thread, SLOT(quit())); + connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); - m_BonjourInstall->moveToThread(thread); - thread->start(); + m_BonjourInstall->moveToThread(thread); + thread->start(); - QMetaObject::invokeMethod(m_BonjourInstall, "run", Qt::QueuedConnection); + QMetaObject::invokeMethod(m_BonjourInstall, "run", Qt::QueuedConnection); - m_DownloadMessageBox->hide(); + m_DownloadMessageBox->hide(); #endif } void MainWindow::promptAutoConfig() { - if (!isBonjourRunning()) { - int r = QMessageBox::question( - this, tr("Synergy"), - tr("Do you want to enable auto config and install Bonjour?\n\n" - "This feature helps you establish the connection."), - QMessageBox::Yes | QMessageBox::No); + if (!isBonjourRunning()) { + int r = QMessageBox::question( + this, tr("Synergy"), + tr("Do you want to enable auto config and install Bonjour?\n\n" + "This feature helps you establish the connection."), + QMessageBox::Yes | QMessageBox::No); - if (r == QMessageBox::Yes) { - m_AppConfig->setAutoConfig(true); - downloadBonjour(); - } - else { - m_AppConfig->setAutoConfig(false); - m_pCheckBoxAutoConfig->setChecked(false); - } - } + if (r == QMessageBox::Yes) { + m_AppConfig->setAutoConfig(true); + downloadBonjour(); + } + else { + m_AppConfig->setAutoConfig(false); + m_pCheckBoxAutoConfig->setChecked(false); + } + } - m_AppConfig->setAutoConfigPrompted(true); + m_AppConfig->setAutoConfigPrompted(true); } void MainWindow::on_m_pComboServerList_currentIndexChanged(QString ) { - if (m_pComboServerList->count() != 0) { - restartSynergy(); - } + if (m_pComboServerList->count() != 0) { + restartSynergy(); + } } 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 (!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(); - } - } + if (r == QMessageBox::Yes) { + downloadBonjour(); + } + } - m_pCheckBoxAutoConfig->setChecked(false); - return; - } + m_pCheckBoxAutoConfig->setChecked(false); + return; + } - m_pLineEditHostname->setDisabled(checked); - appConfig().setAutoConfig(checked); - updateZeroconfService(); + m_pLineEditHostname->setDisabled(checked); + appConfig().setAutoConfig(checked); + updateZeroconfService(); - if (!checked) { - m_pComboServerList->clear(); - m_pComboServerList->hide(); - } + if (!checked) { + m_pComboServerList->clear(); + m_pComboServerList->hide(); + } } void MainWindow::bonjourInstallFinished() { - appendLogInfo("Bonjour install finished"); + appendLogInfo("Bonjour install finished"); - m_pCheckBoxAutoConfig->setChecked(true); + m_pCheckBoxAutoConfig->setChecked(true); } void MainWindow::on_windowShown() { - if (!m_AppConfig->activationHasRun() && (m_AppConfig->edition() == kUnregistered)) { - ActivationDialog activationDialog (this, appConfig(), subscriptionManager()); - activationDialog.exec(); - } + if (!m_AppConfig->activationHasRun() && (m_AppConfig->edition() == kUnregistered)) { + ActivationDialog activationDialog (this, appConfig(), subscriptionManager()); + activationDialog.exec(); + } } QString MainWindow::getProfileRootForArg() { - CoreInterface coreInterface; - QString dir = coreInterface.getProfileDir(); + CoreInterface coreInterface; + QString dir = coreInterface.getProfileDir(); - // HACK: strip our app name since we're returning the root dir. + // HACK: strip our app name since we're returning the root dir. #if defined(Q_OS_WIN) - dir.replace("\\Synergy", ""); + dir.replace("\\Synergy", ""); #else - dir.replace("/.synergy", ""); + dir.replace("/.synergy", ""); #endif - return QString("\"%1\"").arg(dir); + return QString("\"%1\"").arg(dir); } diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index 22cddabe..c00afdba 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -62,174 +62,174 @@ class SubscriptionManager; class MainWindow : public QMainWindow, public Ui::MainWindowBase { - Q_OBJECT + Q_OBJECT - friend class QSynergyApplication; - friend class SetupWizard; - friend class ActivationDialog; - friend class SettingsDialog; - - public: - enum qSynergyState - { - synergyDisconnected, - synergyConnecting, - synergyConnected, - synergyTransfering - }; + friend class QSynergyApplication; + friend class SetupWizard; + friend class ActivationDialog; + friend class SettingsDialog; - enum qSynergyType - { - synergyClient, - synergyServer - }; + public: + enum qSynergyState + { + synergyDisconnected, + synergyConnecting, + synergyConnected, + synergyTransfering + }; - enum qLevel { - Error, - Info - }; + enum qSynergyType + { + synergyClient, + synergyServer + }; - enum qRuningState { - kStarted, - kStopped - }; + enum qLevel { + Error, + Info + }; - public: - MainWindow(QSettings& settings, AppConfig& appConfig, - SubscriptionManager& subscriptionManager); - ~MainWindow(); + enum qRuningState { + kStarted, + kStopped + }; - public: - void setVisible(bool visible); - int synergyType() const { return m_pGroupClient->isChecked() ? synergyClient : synergyServer; } - int synergyState() const { return m_SynergyState; } - QString hostname() const { return m_pLineEditHostname->text(); } - QString configFilename(); - QString address(); - QString appPath(const QString& name); - void open(); - void clearLog(); - VersionChecker& versionChecker() { return m_VersionChecker; } - QString getScreenName(); - ServerConfig& serverConfig() { return m_ServerConfig; } - void showConfigureServer(const QString& message); - void showConfigureServer() { showConfigureServer(""); } - void autoAddScreen(const QString name); - void updateZeroconfService(); - void serverDetected(const QString name); - void updateLocalFingerprint(); - SubscriptionManager& subscriptionManager() const; + public: + MainWindow(QSettings& settings, AppConfig& appConfig, + SubscriptionManager& subscriptionManager); + ~MainWindow(); - public slots: - void setEdition(Edition edition); - void beginTrial(); - void endTrial(); - void appendLogRaw(const QString& text); - void appendLogInfo(const QString& text); - void appendLogDebug(const QString& text); - void appendLogError(const QString& text); - void startSynergy(); + public: + void setVisible(bool visible); + int synergyType() const { return m_pGroupClient->isChecked() ? synergyClient : synergyServer; } + int synergyState() const { return m_SynergyState; } + QString hostname() const { return m_pLineEditHostname->text(); } + QString configFilename(); + QString address(); + QString appPath(const QString& name); + void open(); + void clearLog(); + VersionChecker& versionChecker() { return m_VersionChecker; } + QString getScreenName(); + ServerConfig& serverConfig() { return m_ServerConfig; } + void showConfigureServer(const QString& message); + void showConfigureServer() { showConfigureServer(""); } + void autoAddScreen(const QString name); + void updateZeroconfService(); + void serverDetected(const QString name); + void updateLocalFingerprint(); + SubscriptionManager& subscriptionManager() const; - protected slots: - void sslToggled(bool enabled); - void on_m_pGroupClient_toggled(bool on); - void on_m_pGroupServer_toggled(bool on); - bool on_m_pButtonBrowseConfigFile_clicked(); - void on_m_pButtonConfigureServer_clicked(); - bool on_m_pActionSave_triggered(); - void on_m_pActionAbout_triggered(); - void on_m_pActionSettings_triggered(); - void on_m_pActivate_triggered(); - void synergyFinished(int exitCode, QProcess::ExitStatus); - void trayActivated(QSystemTrayIcon::ActivationReason reason); - void stopSynergy(); - void logOutput(); - void logError(); - void updateFound(const QString& version); - void bonjourInstallFinished(); + public slots: + void setEdition(Edition edition); + void beginTrial(bool isExpiring); + void endTrial(bool isExpired); + void appendLogRaw(const QString& text); + void appendLogInfo(const QString& text); + void appendLogDebug(const QString& text); + void appendLogError(const QString& text); + void startSynergy(); - protected: - QSettings& settings() { return m_Settings; } - AppConfig& appConfig() { return *m_AppConfig; } - QProcess* synergyProcess() { return m_pSynergy; } - void setSynergyProcess(QProcess* p) { m_pSynergy = p; } - void initConnections(); - void createMenuBar(); - void createStatusBar(); - void createTrayIcon(); - void loadSettings(); - void saveSettings(); - void setIcon(qSynergyState state); - void setSynergyState(qSynergyState state); - bool checkForApp(int which, QString& app); - bool clientArgs(QStringList& args, QString& app); - bool serverArgs(QStringList& args, QString& app); - void setStatus(const QString& status); - void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors); - void onModeChanged(bool startDesktop, bool applyService); - void updateStateFromLogLine(const QString& line); - QString getIPAddresses(); - void stopService(); - void stopDesktop(); - void changeEvent(QEvent* event); - void retranslateMenuBar(); + protected slots: + void sslToggled(bool enabled); + void on_m_pGroupClient_toggled(bool on); + void on_m_pGroupServer_toggled(bool on); + bool on_m_pButtonBrowseConfigFile_clicked(); + void on_m_pButtonConfigureServer_clicked(); + bool on_m_pActionSave_triggered(); + void on_m_pActionAbout_triggered(); + void on_m_pActionSettings_triggered(); + void on_m_pActivate_triggered(); + void synergyFinished(int exitCode, QProcess::ExitStatus); + void trayActivated(QSystemTrayIcon::ActivationReason reason); + void stopSynergy(); + void logOutput(); + void logError(); + void updateFound(const QString& version); + void bonjourInstallFinished(); + + protected: + QSettings& settings() { return m_Settings; } + AppConfig& appConfig() { return *m_AppConfig; } + QProcess* synergyProcess() { return m_pSynergy; } + void setSynergyProcess(QProcess* p) { m_pSynergy = p; } + void initConnections(); + void createMenuBar(); + void createStatusBar(); + void createTrayIcon(); + void loadSettings(); + void saveSettings(); + void setIcon(qSynergyState state); + void setSynergyState(qSynergyState state); + bool checkForApp(int which, QString& app); + bool clientArgs(QStringList& args, QString& app); + bool serverArgs(QStringList& args, QString& app); + void setStatus(const QString& status); + void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors); + void onModeChanged(bool startDesktop, bool applyService); + void updateStateFromLogLine(const QString& line); + QString getIPAddresses(); + void stopService(); + void stopDesktop(); + void changeEvent(QEvent* event); + void retranslateMenuBar(); #if defined(Q_OS_WIN) - bool isServiceRunning(QString name); + bool isServiceRunning(QString name); #else - bool isServiceRunning(); + bool isServiceRunning(); #endif - bool isBonjourRunning(); - void downloadBonjour(); - void promptAutoConfig(); - QString getProfileRootForArg(); - void checkConnected(const QString& line); - void checkFingerprint(const QString& line); - bool autoHide(); - QString getTimeStamp(); - void restartSynergy(); - void proofreadInfo(); + bool isBonjourRunning(); + void downloadBonjour(); + void promptAutoConfig(); + QString getProfileRootForArg(); + void checkConnected(const QString& line); + void checkFingerprint(const QString& line); + bool autoHide(); + QString getTimeStamp(); + void restartSynergy(); + void proofreadInfo(); - void showEvent (QShowEvent*); + void showEvent (QShowEvent*); - private: - QSettings& m_Settings; - AppConfig* m_AppConfig; - SubscriptionManager* m_SubscriptionManager; - QProcess* m_pSynergy; - int m_SynergyState; - ServerConfig m_ServerConfig; - QTemporaryFile* m_pTempConfigFile; - QSystemTrayIcon* m_pTrayIcon; - QMenu* m_pTrayIconMenu; - bool m_AlreadyHidden; - VersionChecker m_VersionChecker; - IpcClient m_IpcClient; - QMenuBar* m_pMenuBar; - QMenu* m_pMenuFile; - QMenu* m_pMenuEdit; - QMenu* m_pMenuWindow; - QMenu* m_pMenuHelp; - ZeroconfService* m_pZeroconfService; - DataDownloader* m_pDataDownloader; - QMessageBox* m_DownloadMessageBox; - QAbstractButton* m_pCancelButton; - QMutex m_UpdateZeroconfMutex; - bool m_SuppressAutoConfigWarning; - CommandProcess* m_BonjourInstall; - bool m_SuppressEmptyServerWarning; - qRuningState m_ExpectedRunningState; - QMutex m_StopDesktopMutex; - SslCertificate* m_pSslCertificate; + private: + QSettings& m_Settings; + AppConfig* m_AppConfig; + SubscriptionManager* m_SubscriptionManager; + QProcess* m_pSynergy; + int m_SynergyState; + ServerConfig m_ServerConfig; + QTemporaryFile* m_pTempConfigFile; + QSystemTrayIcon* m_pTrayIcon; + QMenu* m_pTrayIconMenu; + bool m_AlreadyHidden; + VersionChecker m_VersionChecker; + IpcClient m_IpcClient; + QMenuBar* m_pMenuBar; + QMenu* m_pMenuFile; + QMenu* m_pMenuEdit; + QMenu* m_pMenuWindow; + QMenu* m_pMenuHelp; + ZeroconfService* m_pZeroconfService; + DataDownloader* m_pDataDownloader; + QMessageBox* m_DownloadMessageBox; + QAbstractButton* m_pCancelButton; + QMutex m_UpdateZeroconfMutex; + bool m_SuppressAutoConfigWarning; + CommandProcess* m_BonjourInstall; + bool m_SuppressEmptyServerWarning; + qRuningState m_ExpectedRunningState; + QMutex m_StopDesktopMutex; + SslCertificate* m_pSslCertificate; private slots: - void on_m_pCheckBoxAutoConfig_toggled(bool checked); - void on_m_pComboServerList_currentIndexChanged(QString ); - void on_m_pButtonApply_clicked(); - void installBonjour(); - void on_windowShown(); + void on_m_pCheckBoxAutoConfig_toggled(bool checked); + void on_m_pComboServerList_currentIndexChanged(QString ); + void on_m_pButtonApply_clicked(); + void installBonjour(); + void on_windowShown(); signals: - void windowShown(); + void windowShown(); }; #endif diff --git a/src/gui/src/SubscriptionManager.cpp b/src/gui/src/SubscriptionManager.cpp index 86d42536..684ac82a 100644 --- a/src/gui/src/SubscriptionManager.cpp +++ b/src/gui/src/SubscriptionManager.cpp @@ -22,75 +22,82 @@ #include SubscriptionManager::SubscriptionManager(AppConfig* appConfig) : - m_AppConfig(appConfig), - m_serialKey(appConfig->edition()) { - try { - setSerialKey(m_AppConfig->serialKey()); - } catch (...) { - m_AppConfig->setSerialKey(""); - } + m_AppConfig(appConfig), + m_serialKey(appConfig->edition()) { + try { + setSerialKey(m_AppConfig->serialKey()); + } catch (...) { + m_AppConfig->setSerialKey(""); + m_AppConfig->saveSettings(); + } } SerialKey SubscriptionManager::setSerialKey(QString serialKeyString) { - SerialKey serialKey (serialKeyString.toStdString()); - if (!serialKey.isValid (::time(0))) { - throw std::runtime_error ("Invalid serial key"); - } + SerialKey serialKey (serialKeyString.toStdString()); + if (!serialKey.isValid (::time(0))) { + throw std::runtime_error ("Invalid serial key"); + } - if (serialKey != m_serialKey) { - using std::swap; - swap (serialKey, m_serialKey); - - m_AppConfig->setSerialKey (serialKeyString); - notifyActivation ("serial:" + serialKeyString); - emit serialKeyChanged (m_serialKey); + if (serialKey != m_serialKey) { + using std::swap; + swap (serialKey, m_serialKey); - if (m_serialKey.edition() != serialKey.edition()) { - m_AppConfig->setEdition (m_serialKey.edition()); - emit editionChanged (m_serialKey.edition()); - } + m_AppConfig->setSerialKey (serialKeyString); + notifyActivation ("serial:" + serialKeyString); + emit serialKeyChanged (m_serialKey); - if (m_serialKey.isTrial() != serialKey.isTrial()) { - if (m_serialKey.isTrial()) { - emit beginTrial(); - } else { - emit endTrial(); - } - } - } + if (m_serialKey.edition() != serialKey.edition()) { + m_AppConfig->setEdition (m_serialKey.edition()); + emit editionChanged (m_serialKey.edition()); + } - return serialKey; + if (serialKey.isTrial()) { + emit endTrial(false); + } + + if (m_serialKey.isTrial()) { + emit beginTrial(m_serialKey.isExpiring(::time(0))); + } + + m_AppConfig->saveSettings(); + } + + return serialKey; } -Edition SubscriptionManager::edition() const +Edition SubscriptionManager::activeLicense() const { - return m_serialKey.edition(); + return m_serialKey.edition(); } -bool SubscriptionManager::isTrial() const +void SubscriptionManager::update() const { - return m_serialKey.isTrial(); + emit serialKeyChanged (m_serialKey); + emit editionChanged (m_serialKey.edition()); + if (m_serialKey.isTrial()) { + emit beginTrial(m_serialKey.isExpiring(::time(0))); + } } void SubscriptionManager::skipActivation() { - notifyActivation ("skip:unknown"); + notifyActivation ("skip:unknown"); } void SubscriptionManager::notifyActivation(QString identity) { - ActivationNotifier* notifier = new ActivationNotifier(); - notifier->setIdentity(identity); + ActivationNotifier* notifier = new ActivationNotifier(); + notifier->setIdentity(identity); - QThread* thread = new QThread(); - connect(notifier, SIGNAL(finished()), thread, SLOT(quit())); - connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater())); - connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); + QThread* thread = new QThread(); + connect(notifier, SIGNAL(finished()), thread, SLOT(quit())); + connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater())); + connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); - notifier->moveToThread(thread); - thread->start(); + notifier->moveToThread(thread); + thread->start(); - QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection); + QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection); } diff --git a/src/gui/src/SubscriptionManager.h b/src/gui/src/SubscriptionManager.h index eff9112d..56c3e48c 100644 --- a/src/gui/src/SubscriptionManager.h +++ b/src/gui/src/SubscriptionManager.h @@ -25,25 +25,25 @@ class AppConfig; class SubscriptionManager: public QObject { - Q_OBJECT + Q_OBJECT public: - SubscriptionManager(AppConfig* appConfig); - SerialKey setSerialKey(QString serialKey); - Edition edition() const; - bool isTrial() const; - void skipActivation(); + SubscriptionManager(AppConfig* appConfig); + SerialKey setSerialKey(QString serialKey); + void update() const; + Edition activeLicense() const; + void skipActivation(); private: - void notifyActivation(QString identity); - + void notifyActivation(QString identity); + private: - AppConfig* m_AppConfig; - SerialKey m_serialKey; - + AppConfig* m_AppConfig; + SerialKey m_serialKey; + signals: - void serialKeyChanged (SerialKey); - void editionChanged (Edition); - void beginTrial (); - void endTrial (); + void serialKeyChanged (SerialKey) const; + void editionChanged (Edition) const; + void beginTrial (bool expiring) const; + void endTrial (bool expired) const; }; diff --git a/src/lib/shared/SerialKey.cpp b/src/lib/shared/SerialKey.cpp index 7b4f4805..fb4544d4 100644 --- a/src/lib/shared/SerialKey.cpp +++ b/src/lib/shared/SerialKey.cpp @@ -1,11 +1,11 @@ /* * synergy -- mouse and keyboard sharing utility * Copyright (C) 2016 Symless Ltd. - * + * * 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 LICENSE 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 @@ -26,194 +26,194 @@ using namespace std; SerialKey::SerialKey(Edition edition): - m_userLimit(1), - m_warnTime(ULLONG_MAX), - m_expireTime(ULLONG_MAX), - m_edition(edition), - m_trial(false), - m_valid(true) + m_userLimit(1), + m_warnTime(ULLONG_MAX), + m_expireTime(ULLONG_MAX), + m_edition(edition), + m_trial(false), + m_valid(true) { } SerialKey::SerialKey(std::string serial) : - m_userLimit(1), - m_warnTime(0), - m_expireTime(0), - m_edition(Edition::kBasic), - m_trial(true), - m_valid(false) + m_userLimit(1), + m_warnTime(0), + m_expireTime(0), + m_edition(Edition::kBasic), + m_trial(true), + m_valid(false) { - string plainText = decode(serial); - if (!plainText.empty()) { - parse(plainText); - } + string plainText = decode(serial); + if (!plainText.empty()) { + parse(plainText); + } } bool SerialKey::isValid(time_t currentTime) const { - bool result = false; - - if (m_valid) { - if (m_trial) { - if (currentTime < m_expireTime) { - result = true; - } - } - else { - result = true; - } - } - - return result; + bool result = false; + + if (m_valid) { + if (m_trial) { + if (currentTime < m_expireTime) { + result = true; + } + } + else { + result = true; + } + } + + return result; } bool SerialKey::isExpiring(time_t currentTime) const { - bool result = false; - - if (m_valid) { - if (m_warnTime <= currentTime && currentTime < m_expireTime) { - result = true; - } - } - - return result; + bool result = false; + + if (m_valid) { + if (m_warnTime <= currentTime && currentTime < m_expireTime) { + result = true; + } + } + + return result; } bool SerialKey::isExpired(time_t currentTime) const { - bool result = false; - - if (m_valid) { - if (m_expireTime <= currentTime) { - result = true; - } - } - - return result; + bool result = false; + + if (m_valid) { + if (m_expireTime <= currentTime) { + result = true; + } + } + + return result; } bool SerialKey::isTrial() const { - return m_trial; + return m_trial; } -Edition +Edition SerialKey::edition() const { - return m_edition; + return m_edition; } time_t SerialKey::daysLeft(time_t currentTime) const { - unsigned long long timeLeft = 0; - unsigned long long const day = 60 * 60 * 24; - - if (currentTime < m_expireTime) { - timeLeft = m_expireTime - currentTime; - } + unsigned long long timeLeft = 0; + unsigned long long const day = 60 * 60 * 24; - unsigned long long dayLeft = 0; - dayLeft = timeLeft % day != 0 ? 1 : 0; - - return timeLeft / day + dayLeft; + if (currentTime < m_expireTime) { + timeLeft = m_expireTime - currentTime; + } + + unsigned long long dayLeft = 0; + dayLeft = timeLeft % day != 0 ? 1 : 0; + + return timeLeft / day + dayLeft; } std::string SerialKey::decode(const std::string& serial) const { - static const char* const lut = "0123456789ABCDEF"; - string output; - size_t len = serial.length(); - if (len & 1) { - return output; - } - - output.reserve(len / 2); - for (size_t i = 0; i < len; i += 2) { - - char a = serial[i]; - char b = serial[i + 1]; - - const char* p = std::lower_bound(lut, lut + 16, a); - const char* q = std::lower_bound(lut, lut + 16, b); - - if (*q != b || *p != a) { - return output; - } - - output.push_back(static_cast(((p - lut) << 4) | (q - lut))); - } - - return output; + static const char* const lut = "0123456789ABCDEF"; + string output; + size_t len = serial.length(); + if (len & 1) { + return output; + } + + output.reserve(len / 2); + for (size_t i = 0; i < len; i += 2) { + + char a = serial[i]; + char b = serial[i + 1]; + + const char* p = std::lower_bound(lut, lut + 16, a); + const char* q = std::lower_bound(lut, lut + 16, b); + + if (*q != b || *p != a) { + return output; + } + + output.push_back(static_cast(((p - lut) << 4) | (q - lut))); + } + + return output; } void SerialKey::parse(std::string plainSerial) { - string parityStart = plainSerial.substr(0, 1); - string parityEnd = plainSerial.substr(plainSerial.length() - 1, 1); - - // check for parity chars { and }, record parity result, then remove them. - if (parityStart == "{" && parityEnd == "}") { - plainSerial = plainSerial.substr(1, plainSerial.length() - 2); - - // tokenize serialised subscription. - vector parts; - std::string::size_type pos = 0; - bool look = true; - while (look) { - std::string::size_type start = pos; - pos = plainSerial.find(";", pos); - if (pos == string::npos) { - pos = plainSerial.length(); - look = false; - } - parts.push_back(plainSerial.substr(start, pos - start)); - pos += 1; - } + string parityStart = plainSerial.substr(0, 1); + string parityEnd = plainSerial.substr(plainSerial.length() - 1, 1); - if ((parts.size() == 8) - && (parts.at(0).find("v1") != string::npos)) { - // e.g.: {v1;basic;Bob;1;email;company name;1398297600;1398384000} - m_edition = getEdition(parts.at(1)); - m_name = parts.at(2); - m_trial = false; - sscanf(parts.at(3).c_str(), "%d", &m_userLimit); - m_email = parts.at(4); - m_company = parts.at(5); - sscanf(parts.at(6).c_str(), "%lld", &m_warnTime); - sscanf(parts.at(7).c_str(), "%lld", &m_expireTime); - m_valid = true; - } - else if ((parts.size() == 9) - && (parts.at(0).find("v2") != string::npos)) { - // e.g.: {v2;trial;basic;Bob;1;email;company name;1398297600;1398384000} - m_trial = parts.at(1) == "trial" ? true : false; - m_edition = getEdition(parts.at(2)); - m_name = parts.at(3); - sscanf(parts.at(4).c_str(), "%d", &m_userLimit); - m_email = parts.at(5); - m_company = parts.at(6); - sscanf(parts.at(7).c_str(), "%lld", &m_warnTime); - sscanf(parts.at(8).c_str(), "%lld", &m_expireTime); - m_valid = true; - } - } + // check for parity chars { and }, record parity result, then remove them. + if (parityStart == "{" && parityEnd == "}") { + plainSerial = plainSerial.substr(1, plainSerial.length() - 2); + + // tokenize serialised subscription. + vector parts; + std::string::size_type pos = 0; + bool look = true; + while (look) { + std::string::size_type start = pos; + pos = plainSerial.find(";", pos); + if (pos == string::npos) { + pos = plainSerial.length(); + look = false; + } + parts.push_back(plainSerial.substr(start, pos - start)); + pos += 1; + } + + if ((parts.size() == 8) + && (parts.at(0).find("v1") != string::npos)) { + // e.g.: {v1;basic;Bob;1;email;company name;1398297600;1398384000} + m_edition = parseEdition(parts.at(1)); + m_name = parts.at(2); + m_trial = false; + sscanf(parts.at(3).c_str(), "%d", &m_userLimit); + m_email = parts.at(4); + m_company = parts.at(5); + sscanf(parts.at(6).c_str(), "%lld", &m_warnTime); + sscanf(parts.at(7).c_str(), "%lld", &m_expireTime); + m_valid = true; + } + else if ((parts.size() == 9) + && (parts.at(0).find("v2") != string::npos)) { + // e.g.: {v2;trial;basic;Bob;1;email;company name;1398297600;1398384000} + m_trial = parts.at(1) == "trial" ? true : false; + m_edition = parseEdition(parts.at(2)); + m_name = parts.at(3); + sscanf(parts.at(4).c_str(), "%d", &m_userLimit); + m_email = parts.at(5); + m_company = parts.at(6); + sscanf(parts.at(7).c_str(), "%lld", &m_warnTime); + sscanf(parts.at(8).c_str(), "%lld", &m_expireTime); + m_valid = true; + } + } } Edition -SerialKey::getEdition(std::string editionStr) +SerialKey::parseEdition(std::string editionStr) { - Edition e = Edition::kBasic; - if (editionStr == "pro") { - e = Edition::kPro; - } - - return e; + Edition e = Edition::kBasic; + if (editionStr == "pro") { + e = Edition::kPro; + } + + return e; } diff --git a/src/lib/shared/SerialKey.h b/src/lib/shared/SerialKey.h index 03d0ab98..de9a4450 100644 --- a/src/lib/shared/SerialKey.h +++ b/src/lib/shared/SerialKey.h @@ -1,11 +1,11 @@ /* * synergy -- mouse and keyboard sharing utility * Copyright (C) 2016 Symless Ltd. - * + * * 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 LICENSE 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 @@ -26,61 +26,61 @@ #endif class SerialKey { - friend bool operator== (SerialKey const&, SerialKey const&); + friend bool operator== (SerialKey const&, SerialKey const&); public: - explicit SerialKey(Edition edition = Edition::kUnregistered); - explicit SerialKey(std::string serial); - - bool isValid(time_t currentTime) const; - bool isExpiring(time_t currentTime) const; - bool isExpired(time_t currentTime) const; - bool isTrial() const; - time_t daysLeft(time_t currentTime) const; - Edition edition() const; + explicit SerialKey(Edition edition = Edition::kUnregistered); + explicit SerialKey(std::string serial); + + bool isValid(time_t currentTime) const; + bool isExpiring(time_t currentTime) const; + bool isExpired(time_t currentTime) const; + bool isTrial() const; + time_t daysLeft(time_t currentTime) const; + Edition edition() const; private: - std::string decode(const std::string& serial) const; - void parse(std::string plainSerial); - Edition getEdition(std::string editionStr); + std::string decode(const std::string& serial) const; + void parse(std::string plainSerial); + Edition parseEdition(std::string editionStr); #ifdef TEST_ENV private: - FRIEND_TEST(SerialKeyTests, decode_empty_returnEmptyString); - FRIEND_TEST(SerialKeyTests, decode_invalidDigit_returnEmptyString); - FRIEND_TEST(SerialKeyTests, decode_validSerial_returnPlainText); - FRIEND_TEST(SerialKeyTests, parse_noParty_invalid); - FRIEND_TEST(SerialKeyTests, parse_invalidPartsLenghth_invalid); - FRIEND_TEST(SerialKeyTests, parse_validV1Serial_valid); - FRIEND_TEST(SerialKeyTests, parse_validV2Serial_valid); + FRIEND_TEST(SerialKeyTests, decode_empty_returnEmptyString); + FRIEND_TEST(SerialKeyTests, decode_invalidDigit_returnEmptyString); + FRIEND_TEST(SerialKeyTests, decode_validSerial_returnPlainText); + FRIEND_TEST(SerialKeyTests, parse_noParty_invalid); + FRIEND_TEST(SerialKeyTests, parse_invalidPartsLenghth_invalid); + FRIEND_TEST(SerialKeyTests, parse_validV1Serial_valid); + FRIEND_TEST(SerialKeyTests, parse_validV2Serial_valid); #endif - + private: - std::string m_name; - std::string m_email; - std::string m_company; - unsigned m_userLimit; - unsigned long long m_warnTime; - unsigned long long m_expireTime; - Edition m_edition; - bool m_trial; - bool m_valid; + std::string m_name; + std::string m_email; + std::string m_company; + unsigned m_userLimit; + unsigned long long m_warnTime; + unsigned long long m_expireTime; + Edition m_edition; + bool m_trial; + bool m_valid; }; inline bool operator== (SerialKey const& lhs, SerialKey const& rhs) { - return (lhs.m_name == rhs.m_name) && - (lhs.m_email == rhs.m_email) && - (lhs.m_company == rhs.m_company) && - (lhs.m_userLimit == rhs.m_userLimit) && - (lhs.m_warnTime == rhs.m_warnTime) && - (lhs.m_expireTime == rhs.m_expireTime) && - (lhs.m_edition == rhs.m_edition) && - (lhs.m_trial == rhs.m_trial) && - (lhs.m_valid == rhs.m_valid); + return (lhs.m_name == rhs.m_name) && + (lhs.m_email == rhs.m_email) && + (lhs.m_company == rhs.m_company) && + (lhs.m_userLimit == rhs.m_userLimit) && + (lhs.m_warnTime == rhs.m_warnTime) && + (lhs.m_expireTime == rhs.m_expireTime) && + (lhs.m_edition == rhs.m_edition) && + (lhs.m_trial == rhs.m_trial) && + (lhs.m_valid == rhs.m_valid); } inline bool operator!= (SerialKey const& lhs, SerialKey const& rhs) { - return !(lhs == rhs); + return !(lhs == rhs); }