diff --git a/src/gui/gui.pro b/src/gui/gui.pro index 4900d0df..8561eb4e 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -54,7 +54,8 @@ SOURCES += src/main.cpp \ src/CommandProcess.cpp \ src/WebClient.cpp \ src/PluginWizardPage.cpp \ - src/PluginManager.cpp + src/PluginManager.cpp \ + src/DirectoryManager.cpp HEADERS += src/MainWindow.h \ src/AboutDialog.h \ src/ServerConfig.h \ @@ -95,7 +96,8 @@ HEADERS += src/MainWindow.h \ src/EditionType.h \ src/PluginWizardPage.h \ src/ProcessorArch.h \ - src/PluginManager.h + src/PluginManager.h \ + src/DirectoryManager.h RESOURCES += res/Synergy.qrc RC_FILE = res/win/Synergy.rc macx { diff --git a/src/gui/res/SettingsDialogBase.ui b/src/gui/res/SettingsDialogBase.ui index ceabe8af..db7161d4 100644 --- a/src/gui/res/SettingsDialogBase.ui +++ b/src/gui/res/SettingsDialogBase.ui @@ -125,7 +125,7 @@ - + true diff --git a/src/gui/src/DirectoryManager.cpp b/src/gui/src/DirectoryManager.cpp new file mode 100644 index 00000000..b416ca9b --- /dev/null +++ b/src/gui/src/DirectoryManager.cpp @@ -0,0 +1,81 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2015 Synergy Si 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 COPYING that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "DirectoryManager.h" + +#include +#include +#include +#include + +static const char kGetPluginDirArg[] = "--get-plugin-dir"; +static const char kGetProfileDirArg[] = "--get-profile-dir"; + +DirectoryManager::DirectoryManager() +{ +} + +QString DirectoryManager::getPluginDir() +{ + QStringList args(kGetPluginDirArg); + return getDirViaSyntool(args); +} + +QString DirectoryManager::getProfileDir() +{ + QStringList args(kGetProfileDirArg); + return getDirViaSyntool(args); +} + +QString DirectoryManager::getDirViaSyntool(QStringList& args) +{ + QString program(QCoreApplication::applicationDirPath() + "/syntool"); + + QProcess process; + process.setReadChannel(QProcess::StandardOutput); + process.start(program, args); + bool success = process.waitForStarted(); + + QString out, error; + if (success) + { + if (process.waitForFinished()) { + out = process.readAllStandardOutput(); + error = process.readAllStandardError(); + } + } + + out = out.trimmed(); + error = error.trimmed(); + + if (out.isEmpty() || + !error.isEmpty() || + !success || + process.exitCode() != 0) + { + QMessageBox::critical( + NULL, QObject::tr("Synergy"), + QObject::tr("An error occured while calling syntool " + "with the first arg %1. Code: %2\nError: %3") + .arg(args.at(0)) + .arg(process.exitCode()) + .arg(error.isEmpty() ? "Unknown" : error)); + return ""; + } + + return out; +} diff --git a/src/gui/src/DirectoryManager.h b/src/gui/src/DirectoryManager.h new file mode 100644 index 00000000..f07d64c9 --- /dev/null +++ b/src/gui/src/DirectoryManager.h @@ -0,0 +1,36 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2015 Synergy Si 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 COPYING that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef DIRECTORYMANAGER_H +#define DIRECTORYMANAGER_H + +#include +#include + +class DirectoryManager +{ +public: + DirectoryManager(); + +static QString getPluginDir(); +static QString getProfileDir(); + +private: +static QString getDirViaSyntool(QStringList& args); +}; + +#endif // DIRECTORYMANAGER_H diff --git a/src/gui/src/PluginManager.cpp b/src/gui/src/PluginManager.cpp index 43141dc2..15e7a38d 100644 --- a/src/gui/src/PluginManager.cpp +++ b/src/gui/src/PluginManager.cpp @@ -17,19 +17,14 @@ #include "PluginManager.h" +#include "DirectoryManager.h" #include "CommandProcess.h" #include "DataDownloader.h" #include "QUtility.h" #include "ProcessorArch.h" -#include -#include #include #include -#include - -static const char kGetPluginDirArg[] = "--get-plugin-dir"; -static const char kGetProfileDirArg[] = "--get-profile-dir"; static QString kPluginsBaseUrl = "http://synergy-project.org/files/plugins/"; static const char kWinProcessorArch32[] = "Windows-x86"; @@ -61,14 +56,12 @@ PluginManager::PluginManager(QStringList pluginList) : m_DownloadIndex(-1), m_pPluginDownloader(NULL) { - QStringList args1(kGetPluginDirArg); - m_PluginDir = getDirViaSyntool(args1); + m_PluginDir = DirectoryManager::getPluginDir(); if (m_PluginDir.isEmpty()) { emit error(tr("Failed to get plugin directory.")); } - QStringList args2(kGetProfileDirArg); - m_ProfileDir = getDirViaSyntool(args2); + m_ProfileDir = DirectoryManager::getProfileDir(); if (m_ProfileDir.isEmpty()) { emit error(tr("Failed to get profile directory.")); } @@ -177,46 +170,6 @@ void PluginManager::savePlugin() file.close(); } - -QString PluginManager::getDirViaSyntool(QStringList& args) -{ - QString program(QCoreApplication::applicationDirPath() + "/syntool"); - - QProcess process; - process.setReadChannel(QProcess::StandardOutput); - process.start(program, args); - bool success = process.waitForStarted(); - - QString out, error; - if (success) - { - if (process.waitForFinished()) { - out = process.readAllStandardOutput(); - error = process.readAllStandardError(); - } - } - - out = out.trimmed(); - error = error.trimmed(); - - if (out.isEmpty() || - !error.isEmpty() || - !success || - process.exitCode() != 0) - { - QMessageBox::critical( - (QWidget*)parent(), tr("Synergy"), - tr("An error occured while calling syntool " - "with the first arg %1. Code: %2\nError: %3") - .arg(args.at(0)) - .arg(process.exitCode()) - .arg(error.isEmpty() ? "Unknown" : error)); - return ""; - } - - return out; -} - QString PluginManager::getPluginUrl(const QString& pluginName) { QString result; diff --git a/src/gui/src/PluginManager.h b/src/gui/src/PluginManager.h index 26623ad5..63c09aeb 100644 --- a/src/gui/src/PluginManager.h +++ b/src/gui/src/PluginManager.h @@ -42,7 +42,6 @@ public slots: private: void savePlugin(); - QString getDirViaSyntool(QStringList& args); QString getPluginUrl(const QString& pluginName); QString getOpenSSLBinaryUrl(); QString getPluginOSSpecificName(const QString& pluginName); diff --git a/src/gui/src/SettingsDialog.cpp b/src/gui/src/SettingsDialog.cpp index 1fee9883..5625457f 100644 --- a/src/gui/src/SettingsDialog.cpp +++ b/src/gui/src/SettingsDialog.cpp @@ -17,6 +17,8 @@ */ #include "SettingsDialog.h" + +#include "DirectoryManager.h" #include "SynergyLocale.h" #include "QSynergyApplication.h" #include "QUtility.h" @@ -26,6 +28,7 @@ #include #include #include +#include SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), @@ -54,7 +57,16 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) : m_pCheckBoxElevateMode->hide(); #endif - m_pCheckBoxEnableCrypto->setChecked(m_AppConfig.getCryptoEnabled()); + QString pluginDir = DirectoryManager::getPluginDir(); + QDir dir(pluginDir); + int fileNum = dir.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).count(); + if (fileNum == 0) { + m_pGroupNetworkSecurity->setEnabled(false); + m_pCheckBoxEnableCrypto->setChecked(false); + } + else { + m_pCheckBoxEnableCrypto->setChecked(m_AppConfig.getCryptoEnabled()); + } } void SettingsDialog::accept()