diff --git a/src/mumble/ConfigDialog.cpp b/src/mumble/ConfigDialog.cpp index 3cc4ebbce5..9f34412bbb 100644 --- a/src/mumble/ConfigDialog.cpp +++ b/src/mumble/ConfigDialog.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -84,6 +85,22 @@ ConfigDialog::ConfigDialog(QWidget *p) : QDialog(p) { restoreGeometry(Global::get().s.qbaConfigGeometry); } + // Prevent changing the profile unintentionally while filling the ComboBox + const QSignalBlocker blocker(qcbProfiles); + + 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)); + updateTabOrder(); qlwIcons->setFocus(); } @@ -205,6 +222,112 @@ void ConfigDialog::on_qlwIcons_currentItemChanged(QListWidgetItem *current, QLis } } +void ConfigDialog::switchProfile(QString &newProfile) { + Profiles &profiles = Global::get().profiles; + + 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); + } +} + +void ConfigDialog::on_qcbProfiles_currentIndexChanged(int) { + QString selectedProfile = qcbProfiles->currentText(); + bool isDefault = selectedProfile == Profiles::s_default_profile_name; + qpbProfileRename->setEnabled(!isDefault); + qpbProfileDelete->setEnabled(!isDefault); + + Profiles &profiles = Global::get().profiles; + + if (selectedProfile == profiles.activeProfileName) { + return; + } + + if (!profiles.allProfiles.contains(selectedProfile)) { + return; + } + + switchProfile(selectedProfile); +} + +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; + } + + Settings newSettings = s; + Global::get().profiles.allProfiles.insert(profileName, newSettings); + + switchProfile(profileName); +} + +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); + Global::get().profiles.activeProfileName = profileName; +} + +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::Ok) { + return; + } + + Global::get().profiles.allProfiles.remove(oldProfileName); + Global::get().s.loadProfile(Profiles::s_default_profile_name); + s = Global::get().s; + for (ConfigWidget *cw : s_existingWidgets.values()) { + cw->load(s); + } +} + void ConfigDialog::updateTabOrder() { QPushButton *okButton = dialogButtonBox->button(QDialogButtonBox::Ok); QPushButton *cancelButton = dialogButtonBox->button(QDialogButtonBox::Cancel); @@ -230,13 +353,17 @@ void ConfigDialog::updateTabOrder() { setTabOrder(cancelButton, okButton); setTabOrder(okButton, qlwIcons); setTabOrder(qlwIcons, contentFocusWidget); + setTabOrder(contentFocusWidget, qcbProfiles); + setTabOrder(qcbProfiles, qpbProfileAdd); + setTabOrder(qpbProfileAdd, qpbProfileRename); + setTabOrder(qpbProfileRename, qpbProfileDelete); if (resetButton && restoreButton && restoreAllButton) { - setTabOrder(contentFocusWidget, resetButton); + setTabOrder(qpbProfileDelete, resetButton); setTabOrder(resetButton, restoreButton); setTabOrder(restoreButton, restoreAllButton); setTabOrder(restoreAllButton, applyButton); } else { - setTabOrder(contentFocusWidget, applyButton); + setTabOrder(qpbProfileDelete, applyButton); } setTabOrder(applyButton, cancelButton); } @@ -282,6 +409,8 @@ void ConfigDialog::apply() { foreach (ConfigWidget *cw, qmWidgets) cw->save(); + // s.profiles.allProfiles[s.profiles.activeProfileName] = s + Global::get().s = s; foreach (ConfigWidget *cw, qmWidgets) diff --git a/src/mumble/ConfigDialog.h b/src/mumble/ConfigDialog.h index 5613482803..c0413f2047 100644 --- a/src/mumble/ConfigDialog.h +++ b/src/mumble/ConfigDialog.h @@ -19,6 +19,7 @@ class ConfigDialog : public QDialog, public Ui::ConfigDialog { Q_DISABLE_COPY(ConfigDialog) void updateTabOrder(); + void switchProfile(QString &newProfile); protected: static QMutex s_existingWidgetsMutex; @@ -46,6 +47,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..50e37707ea 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 - +