Skip to content

Commit

Permalink
FEAT(client): Profiles frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartmnt committed Jan 5, 2025
1 parent 6d3bd6d commit 3f48dc8
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 13 deletions.
138 changes: 136 additions & 2 deletions src/mumble/ConfigDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QScrollArea>
#include <QtCore/QMutexLocker>
#include <QtGui/QScreen>
#include <QtWidgets/QInputDialog>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QPushButton>

Expand Down Expand Up @@ -84,6 +85,7 @@ ConfigDialog::ConfigDialog(QWidget *p) : QDialog(p) {
restoreGeometry(Global::get().s.qbaConfigGeometry);
}

updateProfileList();
updateTabOrder();
qlwIcons->setFocus();
}
Expand Down Expand Up @@ -205,6 +207,134 @@ 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();

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));
}

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();
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, 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;
}

Settings settingsCopy = s;
Profiles &profiles = Global::get().profiles;
profiles.allProfiles.insert(profileName, settingsCopy);
profiles.allProfiles[profiles.activeProfileName] = Global::get().s;
apply();
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);
Expand All @@ -230,13 +360,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);
}
Expand Down
6 changes: 6 additions & 0 deletions src/mumble/ConfigDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down
67 changes: 56 additions & 11 deletions src/mumble/ConfigDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -35,51 +35,96 @@
</size>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
<enum>QListView::ResizeMode::Adjust</enum>
</property>
<property name="layoutMode">
<enum>QListView::Batched</enum>
<enum>QListView::LayoutMode::Batched</enum>
</property>
<property name="uniformItemSizes">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<item row="1" column="0">
<widget class="QGroupBox" name="qgbProfiles">
<property name="title">
<string>Profile</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="qcbProfiles"/>
</item>
<item>
<widget class="QPushButton" name="qpbProfileAdd">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="qpbProfileRename">
<property name="text">
<string>Rename</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="qpbProfileDelete">
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QDialogButtonBox" name="pageButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item>
<spacer>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>474</width>
<height>22</height>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="dialogButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::StandardButton::Apply|QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<item row="0" column="1" rowspan="2" colspan="2">
<widget class="QStackedWidget" name="qswPages">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
Expand Down

0 comments on commit 3f48dc8

Please sign in to comment.