From 16981619457f1ad761e6a418bad7c9541b03fbdc Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Fri, 11 Jun 2010 21:36:11 +0000 Subject: [PATCH] Merge --- gui/res/SettingsDialogBase.ui | 150 ++++++++++++++++++++-------------- gui/src/AppConfig.cpp | 4 +- gui/src/AppConfig.h | 3 + gui/src/MainWindow.cpp | 42 +++++++++- gui/src/MainWindow.h | 1 + gui/src/SettingsDialog.cpp | 11 +++ gui/src/SettingsDialog.h | 1 + 7 files changed, 146 insertions(+), 66 deletions(-) diff --git a/gui/res/SettingsDialogBase.ui b/gui/res/SettingsDialogBase.ui index 1bbc1727..53cdb2f3 100644 --- a/gui/res/SettingsDialogBase.ui +++ b/gui/res/SettingsDialogBase.ui @@ -7,71 +7,13 @@ 0 0 372 - 325 + 350 Settings - - - - &Programs - - - - - - This is the synergy client program, usually called synergyc or synergyc.exe. - - - &Client: - - - m_pLineEditSynergyc - - - - - - - - - - &Browse... - - - - - - - - - - This is the synergy server program, usually called synergys or synergys.exe. - - - S&erver: - - - m_pLineEditSynergys - - - - - - - - - - Bro&wse... - - - - - - @@ -213,8 +155,90 @@ + + + + &Programs + + + + + + This is the synergy client program, usually called synergyc or synergyc.exe. + + + &Client: + + + m_pLineEditSynergyc + + + + + + + + + + &Browse... + + + + + + + + + + This is the synergy server program, usually called synergys or synergys.exe. + + + S&erver: + + + m_pLineEditSynergys + + + + + + + + + + Bro&wse... + + + + + + + + + Auto detect program paths + + + + + + + + + + m_pCheckBoxAutoDetectPaths + m_pLineEditSynergyc + m_pButtonBrowseSynergyc + m_pLineEditSynergys + m_pButtonBrowseSynergys + m_pLineEditScreenName + m_pSpinBoxPort + m_pLineEditInterface + m_pCheckBoxAutoConnect + m_pComboLogLevel + buttonBox + @@ -224,8 +248,8 @@ accept() - 257 - 380 + 266 + 340 157 @@ -240,8 +264,8 @@ reject() - 325 - 380 + 334 + 340 286 diff --git a/gui/src/AppConfig.cpp b/gui/src/AppConfig.cpp index e16f3c74..ea1b850e 100644 --- a/gui/src/AppConfig.cpp +++ b/gui/src/AppConfig.cpp @@ -6,7 +6,7 @@ #if defined(Q_OS_WIN) const char AppConfig::m_SynergysName[] = "synergys.exe"; const char AppConfig::m_SynergycName[] = "synergyc.exe"; -const char AppConfig::m_SynergyProgramDir[] = "./"; +const char AppConfig::m_SynergyProgramDir[] = "bin/"; #else const char AppConfig::m_SynergysName[] = "synergys"; const char AppConfig::m_SynergycName[] = "synergyc"; @@ -43,6 +43,7 @@ void AppConfig::loadSettings() m_Port = settings().value("port", 24800).toInt(); m_Interface = settings().value("interface").toString(); m_LogLevel = settings().value("logLevelIndex", 0).toInt(); + m_AutoDetectPaths = settings().value("autoDetectPaths", true).toBool(); } void AppConfig::saveSettings() @@ -54,5 +55,6 @@ void AppConfig::saveSettings() settings().setValue("port", m_Port); settings().setValue("interface", m_Interface); settings().setValue("logLevelIndex", m_LogLevel); + settings().setValue("autoDetectPaths", m_AutoDetectPaths); } diff --git a/gui/src/AppConfig.h b/gui/src/AppConfig.h index b9b453b3..591ba55d 100644 --- a/gui/src/AppConfig.h +++ b/gui/src/AppConfig.h @@ -24,6 +24,7 @@ class AppConfig int port() const { return m_Port; } const QString& interface() const { return m_Interface; } int logLevel() const { return m_LogLevel; } + bool autoDetectPaths() const { return m_AutoDetectPaths; } QString synergysName() const { return m_SynergysName; } QString synergycName() const { return m_SynergycName; } @@ -38,6 +39,7 @@ class AppConfig void setPort(int i) { m_Port = i; } void setInterface(const QString& s) { m_Interface = s; } void setLogLevel(int i) { m_LogLevel = i; } + void setAutoDetectPaths(bool b) { m_AutoDetectPaths = b; } void loadSettings(); void saveSettings(); @@ -51,6 +53,7 @@ class AppConfig int m_Port; QString m_Interface; int m_LogLevel; + bool m_AutoDetectPaths; static const char m_SynergysName[]; static const char m_SynergycName[]; diff --git a/gui/src/MainWindow.cpp b/gui/src/MainWindow.cpp index f30c5a5d..b485b60e 100644 --- a/gui/src/MainWindow.cpp +++ b/gui/src/MainWindow.cpp @@ -236,9 +236,39 @@ void MainWindow::startSynergy() setSynergyState(synergyConnected); } +bool MainWindow::detectPath(const QString& name, QString& path) +{ + // look in current working dir and default dir + QStringList searchDirs; + searchDirs.append("./"); + searchDirs.append(appConfig().synergyProgramDir()); + + // use the first valid path we find + for (int i = 0; i < searchDirs.length(); i++) + { + QFile f(searchDirs[i] + name); + if (f.exists()) + { + path = f.fileName(); + return true; + } + } + + // nothing found! + return false; +} + bool MainWindow::clientArgs(QStringList& args, QString& app) { - app = appConfig().synergyc(); + if (appConfig().autoDetectPaths()) + { + // actually returns bool, but ignore for now + detectPath(appConfig().synergycName(), app); + } + else + { + app = appConfig().synergyc(); + } if (!QFile::exists(app)) { @@ -266,7 +296,15 @@ bool MainWindow::clientArgs(QStringList& args, QString& app) bool MainWindow::serverArgs(QStringList& args, QString& app) { - app = appConfig().synergys(); + if (appConfig().autoDetectPaths()) + { + // actually returns bool, but ignore for now + detectPath(appConfig().synergysName(), app); + } + else + { + app = appConfig().synergys(); + } if (!QFile::exists(app)) { diff --git a/gui/src/MainWindow.h b/gui/src/MainWindow.h index 52ab49b5..0e107e3e 100644 --- a/gui/src/MainWindow.h +++ b/gui/src/MainWindow.h @@ -87,6 +87,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase bool clientArgs(QStringList& args, QString& app); bool serverArgs(QStringList& args, QString& app); void setStatus(const QString& status); + bool detectPath(const QString& name, QString& path); private: QSettings m_Settings; diff --git a/gui/src/SettingsDialog.cpp b/gui/src/SettingsDialog.cpp index df20a177..b64f3067 100644 --- a/gui/src/SettingsDialog.cpp +++ b/gui/src/SettingsDialog.cpp @@ -19,6 +19,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) : m_pSpinBoxPort->setValue(appConfig().port()); m_pLineEditInterface->setText(appConfig().interface()); m_pComboLogLevel->setCurrentIndex(appConfig().logLevel()); + m_pCheckBoxAutoDetectPaths->setChecked(appConfig().autoDetectPaths()); } QString SettingsDialog::browseForSynergyc(QWidget* parent, const QString& programDir, const QString& synergycName) @@ -56,6 +57,15 @@ bool SettingsDialog::on_m_pButtonBrowseSynergyc_clicked() return false; } +void SettingsDialog::on_m_pCheckBoxAutoDetectPaths_stateChanged(int i) +{ + bool unchecked = i == 0; + m_pLineEditSynergyc->setEnabled(unchecked); + m_pLineEditSynergys->setEnabled(unchecked); + m_pButtonBrowseSynergyc->setEnabled(unchecked); + m_pButtonBrowseSynergys->setEnabled(unchecked); +} + void SettingsDialog::accept() { appConfig().setAutoConnect(m_pCheckBoxAutoConnect->isChecked()); @@ -65,6 +75,7 @@ void SettingsDialog::accept() appConfig().setPort(m_pSpinBoxPort->value()); appConfig().setInterface(m_pLineEditInterface->text()); appConfig().setLogLevel(m_pComboLogLevel->currentIndex()); + appConfig().setAutoDetectPaths(m_pCheckBoxAutoDetectPaths->isChecked()); QDialog::accept(); } diff --git a/gui/src/SettingsDialog.h b/gui/src/SettingsDialog.h index 03842703..75ba6e1e 100644 --- a/gui/src/SettingsDialog.h +++ b/gui/src/SettingsDialog.h @@ -21,6 +21,7 @@ class SettingsDialog : public QDialog, public Ui::SettingsDialogBase protected slots: bool on_m_pButtonBrowseSynergys_clicked(); bool on_m_pButtonBrowseSynergyc_clicked(); + void on_m_pCheckBoxAutoDetectPaths_stateChanged(int i); protected: void accept();