diff --git a/src/mumble/ConnectDialog.cpp b/src/mumble/ConnectDialog.cpp index fc96b5597..f3fad7ac4 100644 --- a/src/mumble/ConnectDialog.cpp +++ b/src/mumble/ConnectDialog.cpp @@ -732,6 +732,7 @@ ConnectDialogEdit::ConnectDialogEdit(QWidget *p, const QString &name, const QStr usPort = 0; bOk = true; + bCustomLabel = ! name.simplified().isEmpty(); connect(qleName, SIGNAL(textChanged(const QString &)), this, SLOT(validate())); connect(qleServer, SIGNAL(textChanged(const QString &)), this, SLOT(validate())); @@ -742,6 +743,29 @@ ConnectDialogEdit::ConnectDialogEdit(QWidget *p, const QString &name, const QStr validate(); } +void ConnectDialogEdit::on_qleName_textEdited(const QString& name) { + if (bCustomLabel) { + // If empty, then reset to automatic label. + // NOTE(nik@jnstw.us): You may be tempted to set qleName to qleServer, but that results in the odd + // UI behavior that clearing the field doesn't clear it; it'll immediately equal qleServer. Instead, + // leave it empty and let it update the next time qleServer updates. Code in accept will default it + // to qleServer if it isn't updated beforehand. + if (name.simplified().isEmpty()) { + bCustomLabel = false; + } + } else { + // If manually edited, set to Custom + bCustomLabel = true; + } +} + +void ConnectDialogEdit::on_qleServer_textEdited(const QString& server) { + // If using automatic label, update it + if (!bCustomLabel) { + qleName->setText(server); + } +} + void ConnectDialogEdit::validate() { qsName = qleName->text().simplified(); qsHostname = qleServer->text().simplified(); @@ -765,14 +789,18 @@ void ConnectDialogEdit::validate() { adjustSize(); } - bOk = ! qsName.isEmpty() && ! qsHostname.isEmpty() && ! qsUsername.isEmpty() && usPort; + bOk = ! qsHostname.isEmpty() && ! qsUsername.isEmpty() && usPort; qdbbButtonBox->button(QDialogButtonBox::Ok)->setEnabled(bOk); } void ConnectDialogEdit::accept() { validate(); - if (bOk) + if (bOk) { + if (qleName->text().simplified().isEmpty()) { + qleName->setText(qleServer->text()); + } QDialog::accept(); + } } void ConnectDialogEdit::on_qcbShowPassword_toggled(bool checked) { diff --git a/src/mumble/ConnectDialog.h b/src/mumble/ConnectDialog.h index 3b3466fa1..3cbb05daa 100644 --- a/src/mumble/ConnectDialog.h +++ b/src/mumble/ConnectDialog.h @@ -190,11 +190,14 @@ class ConnectDialogEdit : public QDialog, protected Ui::ConnectDialogEdit { Q_DISABLE_COPY(ConnectDialogEdit) protected: bool bOk; + bool bCustomLabel; public slots: void validate(); void accept(); void on_qcbShowPassword_toggled(bool); + void on_qleName_textEdited(const QString&); + void on_qleServer_textEdited(const QString&); public: QString qsName, qsHostname, qsUsername, qsPassword; unsigned short usPort; diff --git a/src/mumble/ConnectDialogEdit.ui b/src/mumble/ConnectDialogEdit.ui index 85180b54c..dcf3a23eb 100644 --- a/src/mumble/ConnectDialogEdit.ui +++ b/src/mumble/ConnectDialogEdit.ui @@ -6,8 +6,8 @@ 0 0 - 243 - 194 + 265 + 197 @@ -20,30 +20,6 @@ Edit Server - - - - Label - - - qleName - - - - - - - Name of the server - - - <b>Label</b><br/> -Label of the server. This is what the server will be named like in your server list and can be chosen freely. - - - Local server label - - - @@ -92,7 +68,7 @@ Port on which the server is listening. If the server is identified by a Bonjour - + &Username @@ -102,7 +78,14 @@ Port on which the server is listening. If the server is identified by a Bonjour - + + + + Password + + + + Username to send to the server @@ -116,21 +99,14 @@ Username to send to the server. Be aware that the server can impose restrictions - + QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - Password - - - - + Password to send to the server @@ -144,7 +120,7 @@ Password to be sent to the server on connect. This password is needed when conne - + @@ -154,14 +130,38 @@ Password to be sent to the server on connect. This password is needed when conne + + + + Label + + + qleName + + + + + + + Name of the server + + + <b>Label</b><br/> +Label of the server. This is what the server will be named like in your server list and can be chosen freely. + + + Local server label + + + - qleName qleServer qlePort qleUsername qlePassword + qleName qcbShowPassword qdbbButtonBox