Moved elevate checkbox to settings #4130

This commit is contained in:
Xinyu Hou 2014-10-27 17:10:12 +00:00
parent d2191b6b93
commit 23670c5f9b
8 changed files with 48 additions and 47 deletions

View File

@ -311,13 +311,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="m_pElevateCheckBox">
<property name="text">
<string>&amp;Elevate</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_pButtonApply">
<property name="enabled">

View File

@ -114,6 +114,13 @@
<item row="0" column="1">
<widget class="QComboBox" name="m_pComboLanguage"/>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="m_pCheckBoxElevateMode">
<property name="text">
<string>Elevate mode</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -54,7 +54,8 @@ AppConfig::AppConfig(QSettings* settings) :
m_WizardLastRun(0),
m_CryptoPass(),
m_ProcessMode(DEFAULT_PROCESS_MODE),
m_AutoConnect(true)
m_AutoConnect(true),
m_ElevateMode(false)
{
Q_ASSERT(m_pSettings);
@ -123,6 +124,7 @@ void AppConfig::loadSettings()
m_Language = settings().value("language", QLocale::system().name()).toString();
m_StartedBefore = settings().value("startedBefore", false).toBool();
m_AutoConnect = settings().value("autoConnect", true).toBool();
m_ElevateMode = settings().value("elevateMode", false).toBool();
}
void AppConfig::saveSettings()
@ -139,6 +141,7 @@ void AppConfig::saveSettings()
settings().setValue("language", m_Language);
settings().setValue("startedBefore", m_StartedBefore);
settings().setValue("autoConnect", m_AutoConnect);
settings().setValue("elevateMode", m_ElevateMode);
}
void AppConfig::setCryptoPass(const QString &s)
@ -161,3 +164,8 @@ void AppConfig::setAutoConnect(bool autoConnect)
{
m_AutoConnect = autoConnect;
}
bool AppConfig::elevateMode()
{
return m_ElevateMode;
}

View File

@ -78,6 +78,7 @@ class AppConfig
bool detectPath(const QString& name, QString& path);
void persistLogDir();
bool elevateMode();
protected:
QSettings& settings() { return *m_pSettings; }
@ -91,6 +92,7 @@ class AppConfig
void setWizardHasRun() { m_WizardLastRun = kWizardVersion; }
void setLanguage(const QString language) { m_Language = language; }
void setStartedBefore(bool b) { m_StartedBefore = b; }
void setElevateMode(bool b) { m_ElevateMode = b; }
void loadSettings();
void saveSettings();
@ -112,6 +114,7 @@ class AppConfig
QString m_Language;
bool m_StartedBefore;
bool m_AutoConnect;
bool m_ElevateMode;
static const char m_SynergysName[];
static const char m_SynergycName[];

View File

@ -70,8 +70,6 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
m_pTrayIcon(NULL),
m_pTrayIconMenu(NULL),
m_AlreadyHidden(false),
m_ElevateProcess(false),
m_SuppressElevateWarning(false),
m_pMenuBar(NULL),
m_pMenuFile(NULL),
m_pMenuEdit(NULL),
@ -96,9 +94,6 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
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();
#else
// elevate checkbox is only useful on ms windows.
m_pElevateCheckBox->hide();
#endif
// change default size based on os
@ -162,8 +157,6 @@ void MainWindow::onModeChanged(bool startDesktop, bool applyService)
stopService();
startSynergy();
}
m_pElevateCheckBox->setEnabled(appConfig().processMode() == Service);
}
void MainWindow::setStatus(const QString &status)
@ -245,10 +238,6 @@ void MainWindow::loadSettings()
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_SuppressElevateWarning = true;
m_pElevateCheckBox->setChecked(settings().value("elevateChecked", false).toBool());
m_SuppressElevateWarning = false;
}
void MainWindow::initConnections()
@ -476,7 +465,7 @@ void MainWindow::startSynergy()
if (serviceMode)
{
QString command(app + " " + args.join(" "));
m_IpcClient.sendCommand(command, m_ElevateProcess);
m_IpcClient.sendCommand(command, appConfig().elevateMode());
}
appConfig().setStartedBefore(true);
@ -624,7 +613,7 @@ void MainWindow::stopSynergy()
void MainWindow::stopService()
{
// send empty command to stop service from laucning anything.
m_IpcClient.sendCommand("", m_ElevateProcess);
m_IpcClient.sendCommand("", appConfig().elevateMode());
}
void MainWindow::stopDesktop()
@ -896,28 +885,6 @@ void MainWindow::on_m_pActionWizard_triggered()
wizard.exec();
}
void MainWindow::on_m_pElevateCheckBox_toggled(bool checked)
{
if (checked && !m_SuppressElevateWarning) {
int r = QMessageBox::warning(
this, tr("Elevate Synergy"),
tr("Are you sure you want to elevate Synergy?\n\n"
"This allows Synergy to interact with elevated processes "
"and the UAC dialog, but can cause problems with non-elevated "
"processes. Elevate Synergy only if you really need to."),
QMessageBox::Yes | QMessageBox::No);
if (r != QMessageBox::Yes) {
m_pElevateCheckBox->setChecked(false);
return;
}
}
m_ElevateProcess = checked;
settings().setValue("elevateChecked", checked);
settings().sync();
}
void MainWindow::on_m_pButtonApply_clicked()
{
startSynergy();

View File

@ -114,7 +114,6 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
void on_m_pActionAbout_triggered();
void on_m_pActionSettings_triggered();
void on_m_pActionWizard_triggered();
void on_m_pElevateCheckBox_toggled(bool checked);
void synergyFinished(int exitCode, QProcess::ExitStatus);
void trayActivated(QSystemTrayIcon::ActivationReason reason);
void stopSynergy();
@ -160,8 +159,6 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
bool m_AlreadyHidden;
VersionChecker m_VersionChecker;
IpcClient m_IpcClient;
bool m_ElevateProcess;
bool m_SuppressElevateWarning;
QMenuBar* m_pMenuBar;
QMenu* m_pMenuFile;
QMenu* m_pMenuEdit;

View File

@ -30,7 +30,8 @@
SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) :
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
Ui::SettingsDialogBase(),
m_AppConfig(config)
m_AppConfig(config),
m_SuppressElevateWarning(false)
{
setupUi(this);
@ -48,6 +49,10 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) :
{
m_pLineEditCryptoPass->setText(appConfig().cryptoPass());
}
m_SuppressElevateWarning = true;
m_pCheckBoxElevateMode->setChecked(appConfig().elevateMode());
m_SuppressElevateWarning = false;
}
void SettingsDialog::accept()
@ -73,6 +78,7 @@ void SettingsDialog::accept()
appConfig().setCryptoEnabled(cryptoEnabled);
appConfig().setCryptoPass(cryptoPass);
appConfig().setLanguage(m_pComboLanguage->itemData(m_pComboLanguage->currentIndex()).toString());
appConfig().setElevateMode(m_pCheckBoxElevateMode->isChecked());
appConfig().saveSettings();
QDialog::accept();
}
@ -144,3 +150,21 @@ void SettingsDialog::on_m_pComboLanguage_currentIndexChanged(int index)
QString ietfCode = m_pComboLanguage->itemData(index).toString();
QSynergyApplication::getInstance()->switchTranslator(ietfCode);
}
void SettingsDialog::on_m_pCheckBoxElevateMode_toggled(bool checked)
{
if (checked && !m_SuppressElevateWarning) {
int r = QMessageBox::warning(
this, tr("Elevate Synergy"),
tr("Are you sure you want to elevate Synergy?\n\n"
"This allows Synergy to interact with elevated processes "
"and the UAC dialog, but can cause problems with non-elevated "
"processes. Elevate Synergy only if you really need to."),
QMessageBox::Yes | QMessageBox::No);
if (r != QMessageBox::Yes) {
m_pCheckBoxElevateMode->setChecked(false);
return;
}
}
}

View File

@ -44,8 +44,10 @@ class SettingsDialog : public QDialog, public Ui::SettingsDialogBase
private:
AppConfig& m_AppConfig;
SynergyLocale m_Locale;
bool m_SuppressElevateWarning;
private slots:
void on_m_pCheckBoxElevateMode_toggled(bool checked);
void on_m_pCheckBoxEnableCrypto_stateChanged(int );
void on_m_pComboLanguage_currentIndexChanged(int index);
void on_m_pCheckBoxLogToFile_stateChanged(int );