Resolved Auto-conf server select #4218

This commit is contained in:
Xinyu Hou 2014-11-13 14:57:21 +00:00
parent 6cb589d18e
commit f0cb271902
4 changed files with 50 additions and 7 deletions

View File

@ -241,12 +241,22 @@
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="QCheckBox" name="m_pAutoConnectCheckBox"> <widget class="QCheckBox" name="m_pCheckBoxAutoConnect">
<property name="text"> <property name="text">
<string>Auto connect</string> <string>Auto connect</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0">
<widget class="QLabel" name="m_pLabelServerList">
<property name="text">
<string>Server list:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="m_pComboServerList"/>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -116,7 +116,7 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
promptAutoConnect(); promptAutoConnect();
} }
m_pAutoConnectCheckBox->setChecked(appConfig.autoConnect()); m_pCheckBoxAutoConnect->setChecked(appConfig.autoConnect());
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -517,7 +517,20 @@ bool MainWindow::clientArgs(QStringList& args, QString& app)
args << "--log" << appConfig().logFilenameCmd(); args << "--log" << appConfig().logFilenameCmd();
} }
if (m_pCheckBoxAutoConnect->isChecked()) {
if (m_pComboServerList->count() == 0) {
QMessageBox::warning(this, tr("No server detected"),
tr("Sorry, Synergy doesn't detect any server."));
return false;
}
else {
QString serverIp = m_pComboServerList->currentText();
args << serverIp + ":" + QString::number(appConfig().port());
}
}
else {
args << m_pLineEditHostname->text() + ":" + QString::number(appConfig().port()); args << m_pLineEditHostname->text() + ":" + QString::number(appConfig().port());
}
return true; return true;
} }
@ -804,6 +817,13 @@ void MainWindow::updateZeroconfService()
} }
} }
void MainWindow::serverDetected(const QString name)
{
if (m_pComboServerList->findText(name) == -1) {
m_pComboServerList->addItem(name);
}
}
void MainWindow::on_m_pGroupClient_toggled(bool on) void MainWindow::on_m_pGroupClient_toggled(bool on)
{ {
m_pGroupServer->setChecked(!on); m_pGroupServer->setChecked(!on);
@ -905,7 +925,7 @@ void MainWindow::on_m_pButtonApply_clicked()
startSynergy(); startSynergy();
} }
void MainWindow::on_m_pAutoConnectCheckBox_toggled(bool checked) void MainWindow::on_m_pCheckBoxAutoConnect_toggled(bool checked)
{ {
if (!isBonjourRunning() && checked) { if (!isBonjourRunning() && checked) {
int r = QMessageBox::warning( int r = QMessageBox::warning(
@ -918,13 +938,17 @@ void MainWindow::on_m_pAutoConnectCheckBox_toggled(bool checked)
downloadBonjour(); downloadBonjour();
} }
m_pAutoConnectCheckBox->setChecked(false); m_pCheckBoxAutoConnect->setChecked(false);
return; return;
} }
m_pLineEditHostname->setDisabled(checked); m_pLineEditHostname->setDisabled(checked);
appConfig().setAutoConnect(checked); appConfig().setAutoConnect(checked);
updateZeroconfService(); updateZeroconfService();
if (!checked) {
m_pComboServerList->clear();
}
} }
bool MainWindow::isServiceRunning(QString name) bool MainWindow::isServiceRunning(QString name)
@ -1051,3 +1075,10 @@ void MainWindow::promptAutoConnect()
m_AppConfig.setAutoConnectPrompted(true); m_AppConfig.setAutoConnectPrompted(true);
} }
void MainWindow::on_m_pComboServerList_currentIndexChanged(QString )
{
if (m_pComboServerList->count() != 0) {
startSynergy();
}
}

View File

@ -101,6 +101,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
void showConfigureServer() { showConfigureServer(""); } void showConfigureServer() { showConfigureServer(""); }
void autoAddScreen(const QString name); void autoAddScreen(const QString name);
void updateZeroconfService(); void updateZeroconfService();
void serverDetected(const QString name);
public slots: public slots:
void appendLogRaw(const QString& text); void appendLogRaw(const QString& text);
@ -177,7 +178,8 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
QAbstractButton* m_pCancelButton; QAbstractButton* m_pCancelButton;
private slots: private slots:
void on_m_pAutoConnectCheckBox_toggled(bool checked); void on_m_pComboServerList_currentIndexChanged(QString );
void on_m_pCheckBoxAutoConnect_toggled(bool checked);
void on_m_pButtonApply_clicked(); void on_m_pButtonApply_clicked();
void installBonjour(); void installBonjour();
}; };

View File

@ -73,9 +73,9 @@ void ZeroconfService::serverDetected(const QList<ZeroconfRecord>& list)
{ {
foreach (ZeroconfRecord record, list) { foreach (ZeroconfRecord record, list) {
registerService(false); registerService(false);
m_pMainWindow->m_pLineEditHostname->setText(record.serviceName);
m_pMainWindow->appendLogNote(tr("zeroconf server detected: %1").arg( m_pMainWindow->appendLogNote(tr("zeroconf server detected: %1").arg(
record.serviceName)); record.serviceName));
m_pMainWindow->serverDetected(record.serviceName);
} }
if (!list.isEmpty()) { if (!list.isEmpty()) {