diff --git a/src/mumble/ConfigDialog.cpp b/src/mumble/ConfigDialog.cpp index 3cc4ebbce5..c5b8259d9e 100644 --- a/src/mumble/ConfigDialog.cpp +++ b/src/mumble/ConfigDialog.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -84,6 +85,7 @@ ConfigDialog::ConfigDialog(QWidget *p) : QDialog(p) { restoreGeometry(Global::get().s.qbaConfigGeometry); } + updateProfileList(); updateTabOrder(); qlwIcons->setFocus(); } @@ -205,6 +207,137 @@ void ConfigDialog::on_qlwIcons_currentItemChanged(QListWidgetItem *current, QLis } } +void ConfigDialog::updateProfileList() { + // Prevent changing the profile unintentionally while filling the ComboBox + const QSignalBlocker blocker(qcbProfiles); + + qcbProfiles->clear(); + + // Always sort the default profile before anything else + qcbProfiles->addItem(Profiles::s_default_profile_name); + + QStringList profiles = Global::get().profiles.allProfiles.keys(); + profiles.sort(); + for (const QString &profile : profiles) { + if (profile == Profiles::s_default_profile_name) { + continue; + } + qcbProfiles->addItem(profile); + } + + qcbProfiles->setCurrentIndex(qcbProfiles->findText(Global::get().profiles.activeProfileName)); + + bool isDefault = qcbProfiles->currentText() == Profiles::s_default_profile_name; + qpbProfileRename->setEnabled(!isDefault); + qpbProfileDelete->setEnabled(!isDefault); +} + +void ConfigDialog::switchProfile(const QString &newProfile, bool saveActiveProfile) { + Profiles &profiles = Global::get().profiles; + + if (saveActiveProfile) { + profiles.allProfiles[profiles.activeProfileName] = Global::get().s; + } + Global::get().s.loadProfile(newProfile); + s = Global::get().s; + for (ConfigWidget *cw : s_existingWidgets.values()) { + cw->load(s); + } + + updateProfileList(); +} + +void ConfigDialog::on_qcbProfiles_currentIndexChanged(int) { + QString selectedProfile = qcbProfiles->currentText(); + + Profiles &profiles = Global::get().profiles; + + if (selectedProfile == profiles.activeProfileName) { + return; + } + + if (!profiles.allProfiles.contains(selectedProfile)) { + return; + } + + switchProfile(selectedProfile, true); +} + +void ConfigDialog::on_qpbProfileAdd_clicked() { + bool ok; + QString profileName = + QInputDialog::getText(this, tr("Creating settings profile"), tr("Enter new settings profile name"), + QLineEdit::Normal, Global::get().profiles.activeProfileName, &ok); + + if (!ok || profileName.isEmpty()) { + return; + } + + if (Global::get().profiles.allProfiles.contains(profileName)) { + QMessageBox::critical(this, tr("Creating settings profile"), + tr("A settings profile with this name already exists")); + return; + } + + // Instead of "resetting" when creating a new profile, use the currently + // (possibly not applied) settings for the new profile + Profiles &profiles = Global::get().profiles; + profiles.allProfiles[profiles.activeProfileName] = Global::get().s; + apply(); + profiles.allProfiles.insert(profileName, Global::get().s); + switchProfile(profileName, false); +} + +void ConfigDialog::on_qpbProfileRename_clicked() { + QString oldProfileName = qcbProfiles->currentText(); + + if (oldProfileName == Profiles::s_default_profile_name) { + return; + } + + bool ok; + QString profileName = + QInputDialog::getText(this, tr("Renaming settings profile"), tr("Enter new settings profile name"), + QLineEdit::Normal, oldProfileName, &ok); + + if (!ok || profileName.isEmpty()) { + return; + } + + if (Global::get().profiles.allProfiles.contains(profileName)) { + QMessageBox::critical(this, tr("Renaming settings profile"), + tr("A settings profile with this name already exists")); + return; + } + + Global::get().profiles.allProfiles.insert(profileName, Global::get().s); + Global::get().profiles.allProfiles.remove(oldProfileName); + switchProfile(profileName, false); +} + +void ConfigDialog::on_qpbProfileDelete_clicked() { + QString oldProfileName = qcbProfiles->currentText(); + + if (oldProfileName == Profiles::s_default_profile_name) { + return; + } + + if (!Global::get().profiles.allProfiles.contains(oldProfileName)) { + return; + } + + QMessageBox::StandardButton confirmation = QMessageBox::question( + this, tr("Delete settings profile"), + tr("Are you sure you want to permanently delete settings profile '%1'").arg(oldProfileName)); + + if (confirmation != QMessageBox::Yes) { + return; + } + + Global::get().profiles.allProfiles.remove(oldProfileName); + switchProfile(Profiles::s_default_profile_name, false); +} + void ConfigDialog::updateTabOrder() { QPushButton *okButton = dialogButtonBox->button(QDialogButtonBox::Ok); QPushButton *cancelButton = dialogButtonBox->button(QDialogButtonBox::Cancel); @@ -229,7 +362,13 @@ void ConfigDialog::updateTabOrder() { setTabOrder(cancelButton, okButton); setTabOrder(okButton, qlwIcons); - setTabOrder(qlwIcons, contentFocusWidget); + setTabOrder(qlwIcons, qcbProfiles); + + setTabOrder(qcbProfiles, qpbProfileAdd); + setTabOrder(qpbProfileAdd, qpbProfileRename); + setTabOrder(qpbProfileRename, qpbProfileDelete); + + setTabOrder(qpbProfileDelete, contentFocusWidget); if (resetButton && restoreButton && restoreAllButton) { setTabOrder(contentFocusWidget, resetButton); setTabOrder(resetButton, restoreButton); diff --git a/src/mumble/ConfigDialog.h b/src/mumble/ConfigDialog.h index 5613482803..379a8f63bd 100644 --- a/src/mumble/ConfigDialog.h +++ b/src/mumble/ConfigDialog.h @@ -19,6 +19,8 @@ class ConfigDialog : public QDialog, public Ui::ConfigDialog { Q_DISABLE_COPY(ConfigDialog) void updateTabOrder(); + void updateProfileList(); + void switchProfile(const QString &newProfile, bool saveActiveProfile); protected: static QMutex s_existingWidgetsMutex; @@ -46,6 +48,10 @@ public slots: void on_pageButtonBox_clicked(QAbstractButton *); void on_dialogButtonBox_clicked(QAbstractButton *); void on_qlwIcons_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous); + void on_qcbProfiles_currentIndexChanged(int); + void on_qpbProfileAdd_clicked(); + void on_qpbProfileRename_clicked(); + void on_qpbProfileDelete_clicked(); void apply(); void accept() Q_DECL_OVERRIDE; }; diff --git a/src/mumble/ConfigDialog.ui b/src/mumble/ConfigDialog.ui index 2cbe3f2c0e..81ff3eafb5 100644 --- a/src/mumble/ConfigDialog.ui +++ b/src/mumble/ConfigDialog.ui @@ -35,34 +35,79 @@ - QListView::Adjust + QListView::ResizeMode::Adjust - QListView::Batched + QListView::LayoutMode::Batched true - + + + + Profile + + + + 0 + + + 9 + + + 0 + + + 0 + + + + + + + + Add + + + + + + + Rename + + + + + + + Delete + + + + + + + - Qt::Horizontal + Qt::Orientation::Horizontal - + - Qt::Horizontal + Qt::Orientation::Horizontal - 474 - 22 + 40 + 20 @@ -70,16 +115,16 @@ - Qt::Horizontal + Qt::Orientation::Horizontal - QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::StandardButton::Apply|QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok - +