From 951cbe9a62089014b1a73e321e011f16f4fee7bd Mon Sep 17 00:00:00 2001 From: XinyuHou Date: Thu, 16 Apr 2015 17:15:58 +0100 Subject: [PATCH] Enable network security checkbox only when ns plugin exists #4540 --- src/gui/src/PluginManager.cpp | 43 ++++++++++++++++++++++++---------- src/gui/src/PluginManager.h | 5 +++- src/gui/src/SettingsDialog.cpp | 8 +++---- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/gui/src/PluginManager.cpp b/src/gui/src/PluginManager.cpp index 813f52e1..38b60833 100644 --- a/src/gui/src/PluginManager.cpp +++ b/src/gui/src/PluginManager.cpp @@ -74,6 +74,23 @@ PluginManager::~PluginManager() { } +bool PluginManager::exist(QString name) +{ + CoreInterface coreInterface; + QString PluginDir = coreInterface.getPluginDir(); + QString pluginName = getPluginOsSpecificName(name); + QString filename; + filename.append(PluginDir); + filename.append(QDir::separator()).append(pluginName); + QFile file(filename); + bool exist = false; + if (file.exists()) { + exist = true; + } + + return exist; +} + void PluginManager::downloadPlugins() { if (m_DataDownloader.isFinished()) { @@ -251,19 +268,6 @@ QString PluginManager::getOpenSslSetupUrl() return result; } -QString PluginManager::getPluginOsSpecificName(const QString& pluginName) -{ - QString result = pluginName; -#if defined(Q_OS_WIN) - result.append(kWinPluginExt); -#elif defined(Q_OS_MAC) - result = kMacPluginPrefix + pluginName + kMacPluginExt; -#else - result = kLinuxPluginPrefix + pluginName + kLinuxPluginExt; -#endif - return result; -} - bool PluginManager::checkOpenSslBinary() { // assume OpenSsl is unavailable on Windows, @@ -426,3 +430,16 @@ bool PluginManager::runProgram( return true; } + +QString PluginManager::getPluginOsSpecificName(const QString& pluginName) +{ + QString result = pluginName; +#if defined(Q_OS_WIN) + result.append(kWinPluginExt); +#elif defined(Q_OS_MAC) + result = kMacPluginPrefix + pluginName + kMacPluginExt; +#else + result = kLinuxPluginPrefix + pluginName + kLinuxPluginExt; +#endif + return result; +} diff --git a/src/gui/src/PluginManager.h b/src/gui/src/PluginManager.h index c7e52c30..51e58e0a 100644 --- a/src/gui/src/PluginManager.h +++ b/src/gui/src/PluginManager.h @@ -35,6 +35,8 @@ public: int downloadIndex() { return m_DownloadIndex; } + static bool exist(QString name); + public slots: void downloadPlugins(); void saveOpenSslSetup(); @@ -45,7 +47,6 @@ private: void savePlugin(); QString getPluginUrl(const QString& pluginName); QString getOpenSslSetupUrl(); - QString getPluginOsSpecificName(const QString& pluginName); bool checkOpenSslBinary(); void downloadOpenSslSetup(); bool runProgram( @@ -53,6 +54,8 @@ private: const QStringList& args, const QStringList& env); + static QString getPluginOsSpecificName(const QString& pluginName); + signals: void error(QString e); void downloadNext(); diff --git a/src/gui/src/SettingsDialog.cpp b/src/gui/src/SettingsDialog.cpp index 7f6318a5..04e83c79 100644 --- a/src/gui/src/SettingsDialog.cpp +++ b/src/gui/src/SettingsDialog.cpp @@ -18,6 +18,7 @@ #include "SettingsDialog.h" +#include "PluginManager.h" #include "CoreInterface.h" #include "SynergyLocale.h" #include "QSynergyApplication.h" @@ -30,6 +31,8 @@ #include #include +static const char networkSecurity[] = "ns"; + SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), Ui::SettingsDialogBase(), @@ -57,10 +60,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) : m_pCheckBoxElevateMode->hide(); #endif - QString pluginDir = m_CoreInterface.getPluginDir(); - QDir dir(pluginDir); - int fileNum = dir.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).count(); - if (fileNum == 0) { + if (!PluginManager::exist(networkSecurity)) { m_pGroupNetworkSecurity->setEnabled(false); m_pCheckBoxEnableCrypto->setChecked(false); }