Merge pull request #6411 from symless/v1-issue-6397-remember-host

Remember last used auto config host
This commit is contained in:
Jnewbon 2019-04-05 18:13:45 +01:00 committed by GitHub
commit b3cb57243a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 13 deletions

View File

@ -56,7 +56,8 @@ AppConfig::AppConfig(QSettings* settings) :
m_ElevateMode(defaultElevateMode),
m_CryptoEnabled(false),
m_AutoHide(false),
m_LastExpiringWarningTime(0)
m_LastExpiringWarningTime(0),
m_AutoConfigServer()
{
Q_ASSERT(m_pSettings);
@ -128,6 +129,8 @@ bool AppConfig::startedBefore() const { return m_StartedBefore; }
bool AppConfig::autoConfig() const { return m_AutoConfig; }
QString AppConfig::autoConfigServer() const { return m_AutoConfigServer; }
void AppConfig::loadSettings()
{
m_ScreenName = settings().value("screenName", QHostInfo::localHostName()).toString();
@ -140,6 +143,7 @@ void AppConfig::loadSettings()
m_Language = settings().value("language", QLocale::system().name()).toString();
m_StartedBefore = settings().value("startedBefore", false).toBool();
m_AutoConfig = settings().value("autoConfig", false).toBool();
m_AutoConfigServer = settings().value("autoConfigServer", "").toString();
QVariant elevateMode = settings().value("elevateModeEnum");
if (!elevateMode.isValid()) {
elevateMode = settings().value ("elevateMode",
@ -168,6 +172,7 @@ void AppConfig::saveSettings()
settings().setValue("language", m_Language);
settings().setValue("startedBefore", m_StartedBefore);
settings().setValue("autoConfig", m_AutoConfig);
settings().setValue("autoConfigServer", m_AutoConfigServer);
// Refer to enum ElevateMode declaration for insight in to why this
// flag is mapped this way
settings().setValue("elevateMode", m_ElevateMode == ElevateAlways);
@ -231,6 +236,11 @@ void AppConfig::setAutoConfig(bool autoConfig)
m_AutoConfig = autoConfig;
}
void AppConfig::setAutoConfigServer(QString autoConfigServer)
{
m_AutoConfigServer = autoConfigServer;
}
#ifndef SYNERGY_ENTERPRISE
void AppConfig::setEdition(Edition e) {
m_Edition = e;

View File

@ -77,6 +77,8 @@ class AppConfig: public QObject
bool startedBefore() const;
bool autoConfig() const;
void setAutoConfig(bool autoConfig);
QString autoConfigServer() const;
void setAutoConfigServer(QString autoConfigServer);
#ifndef SYNERGY_ENTERPRISE
void setEdition(Edition);
Edition edition() const;
@ -138,6 +140,7 @@ protected:
QString m_Language;
bool m_StartedBefore;
bool m_AutoConfig;
QString m_AutoConfigServer;
ElevateMode m_ElevateMode;
Edition m_Edition;
QString m_ActivateEmail;

View File

@ -180,6 +180,8 @@ MainWindow::MainWindow (QSettings& settings, AppConfig& appConfig,
#ifndef SYNERGY_ENTERPRISE
updateZeroconfService();
updateAutoConfigWidgets();
addZeroconfServer(m_AppConfig->autoConfigServer());
#endif
}
@ -751,6 +753,13 @@ bool MainWindow::clientArgs(QStringList& args, QString& app)
args << serverIp + ":" + QString::number(appConfig().port());
return true;
}
else {
show();
QMessageBox::warning(
this, tr("No server selected"),
tr("No auto config server was selected, try manual mode instead."));
return false;
}
}
#endif
@ -1071,13 +1080,8 @@ void MainWindow::changeEvent(QEvent* event)
}
}
void MainWindow::zeroconfServerDetected(const QString name)
void MainWindow::addZeroconfServer(const QString name)
{
// don't add to the server combo box if not in client mode.
if (synergyType() != synergyClient) {
return;
}
// don't add yourself to the server list.
if (getIPAddresses().contains(name)) {
return;
@ -1086,10 +1090,6 @@ void MainWindow::zeroconfServerDetected(const QString name)
if (m_pComboServerList->findText(name) == -1) {
m_pComboServerList->addItem(name);
}
if (m_pComboServerList->count() > 1) {
m_pComboServerList->show();
}
}
void MainWindow::setEdition(Edition edition)
@ -1410,3 +1410,9 @@ void MainWindow::on_m_pLabelAutoConfig_linkActivated(const QString &)
{
m_pActionSettings->trigger();
}
void MainWindow::on_m_pComboServerList_currentIndexChanged(const QString &server)
{
appConfig().setAutoConfigServer(server);
appConfig().saveSettings();
}

View File

@ -117,7 +117,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
void showConfigureServer(const QString& message);
void showConfigureServer() { showConfigureServer(""); }
void autoAddScreen(const QString name);
void zeroconfServerDetected(const QString name);
void addZeroconfServer(const QString name);
void updateLocalFingerprint();
Zeroconf& zeroconf() { return *m_pZeroconf; }
#ifndef SYNERGY_ENTERPRISE
@ -239,6 +239,8 @@ private slots:
void on_m_pLabelAutoConfig_linkActivated(const QString &link);
void on_m_pComboServerList_currentIndexChanged(const QString &arg1);
signals:
void windowShown();
};

View File

@ -81,7 +81,7 @@ void ZeroconfService::serverDetected(const QList<ZeroconfRecord>& list)
registerService(false);
m_pMainWindow->appendLogInfo(tr("zeroconf server detected: %1").arg(
record.serviceName));
m_pMainWindow->zeroconfServerDetected(record.serviceName);
m_pMainWindow->addZeroconfServer(record.serviceName);
}
}