Skip to content

Feat profiles #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 170 additions & 1 deletion 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,25 @@ ConfigDialog::ConfigDialog(QWidget *p) : QDialog(p) {
restoreGeometry(Global::get().s.qbaConfigGeometry);
}

m_profileMenu = new QMenu(this);

m_profileAddAction = new QAction(tr("&Add"), this);
QObject::connect(m_profileAddAction, &QAction::triggered, this, &ConfigDialog::profile_add);
m_profileMenu->addAction(m_profileAddAction);

m_profileRenameAction = new QAction(tr("&Rename"), this);
QObject::connect(m_profileRenameAction, &QAction::triggered, this, &ConfigDialog::profile_rename);
m_profileMenu->addAction(m_profileRenameAction);

m_profileDeleteAction = new QAction(tr("&Delete"), this);
QObject::connect(m_profileDeleteAction, &QAction::triggered, this, &ConfigDialog::profile_delete);
m_profileMenu->addAction(m_profileDeleteAction);

qtbProfileActions->setMenu(m_profileMenu);

QObject::connect(qcbProfiles, &QComboBox::currentIndexChanged, this, &ConfigDialog::profile_selected);

updateProfileList();
updateTabOrder();
qlwIcons->setFocus();
}
Expand Down Expand Up @@ -205,6 +225,151 @@ 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(tr("Default Profile"), Profiles::s_default_profile_name);

Profiles &profiles = Global::get().profiles;

std::vector< QString > profileNames;
for (auto it = profiles.allProfiles.begin(); it != profiles.allProfiles.end(); ++it) {
profileNames.push_back(it->first);
}
std::sort(profileNames.begin(), profileNames.end());
for (const QString &profile : profileNames) {
if (profile == Profiles::s_default_profile_name) {
continue;
}
qcbProfiles->addItem(profile, profile);
}

qcbProfiles->setCurrentIndex(qcbProfiles->findData(profiles.activeProfileName));

bool isDefault = qcbProfiles->currentData().toString() == Profiles::s_default_profile_name;
m_profileRenameAction->setEnabled(!isDefault);
m_profileDeleteAction->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::profile_selected(int) {
QString selectedProfile = qcbProfiles->currentData().toString();

Profiles &profiles = Global::get().profiles;

if (selectedProfile == profiles.activeProfileName) {
return;
}

auto it = profiles.allProfiles.find(selectedProfile);
if (it == profiles.allProfiles.end()) {
return;
}

switchProfile(selectedProfile, true);
}

void ConfigDialog::profile_add() {
Profiles &profiles = Global::get().profiles;

bool ok;
QString profileName =
QInputDialog::getText(this, tr("Creating settings profile"), tr("Enter new settings profile name"),
QLineEdit::Normal, profiles.activeProfileName, &ok);

if (!ok || profileName.isEmpty()) {
return;
}

auto it = profiles.allProfiles.find(profileName);
if (it != profiles.allProfiles.end()) {
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.allProfiles[profiles.activeProfileName] = Global::get().s;
apply();
profiles.allProfiles[profileName] = Global::get().s;
switchProfile(profileName, false);
}

void ConfigDialog::profile_rename() {
QString oldProfileName = qcbProfiles->currentData().toString();

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

Profiles &profiles = Global::get().profiles;

auto it = profiles.allProfiles.find(profileName);
if (it != profiles.allProfiles.end()) {
QMessageBox::critical(this, tr("Renaming settings profile"),
tr("A settings profile with this name already exists"));
return;
}

profiles.allProfiles[profileName] = Global::get().s;
profiles.allProfiles.erase(oldProfileName);
switchProfile(profileName, false);
}

void ConfigDialog::profile_delete() {
QString oldProfileName = qcbProfiles->currentData().toString();

if (oldProfileName == Profiles::s_default_profile_name) {
return;
}

Profiles &profiles = Global::get().profiles;

auto it = profiles.allProfiles.find(oldProfileName);
if (it == profiles.allProfiles.end()) {
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;
}

profiles.allProfiles.erase(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 @@ -228,7 +393,11 @@ void ConfigDialog::updateTabOrder() {
}

setTabOrder(cancelButton, okButton);
setTabOrder(okButton, qlwIcons);
setTabOrder(okButton, qcbProfiles);

setTabOrder(qcbProfiles, qtbProfileActions);
setTabOrder(qtbProfileActions, qlwIcons);

setTabOrder(qlwIcons, contentFocusWidget);
if (resetButton && restoreButton && restoreAllButton) {
setTabOrder(contentFocusWidget, resetButton);
Expand Down
12 changes: 12 additions & 0 deletions src/mumble/ConfigDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "ui_ConfigDialog.h"

#include <QMenu>
#include <QtCore/QMutex>

class ConfigDialog : public QDialog, public Ui::ConfigDialog {
Expand All @@ -19,6 +20,13 @@ class ConfigDialog : public QDialog, public Ui::ConfigDialog {
Q_DISABLE_COPY(ConfigDialog)

void updateTabOrder();
void updateProfileList();
void switchProfile(const QString &newProfile, bool saveActiveProfile);

QMenu *m_profileMenu = nullptr;
QAction *m_profileAddAction = nullptr;
QAction *m_profileRenameAction = nullptr;
QAction *m_profileDeleteAction = nullptr;

protected:
static QMutex s_existingWidgetsMutex;
Expand Down Expand Up @@ -46,6 +54,10 @@ public slots:
void on_pageButtonBox_clicked(QAbstractButton *);
void on_dialogButtonBox_clicked(QAbstractButton *);
void on_qlwIcons_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
void profile_selected(int);
void profile_add();
void profile_rename();
void profile_delete();
void apply();
void accept() Q_DECL_OVERRIDE;
};
Expand Down
111 changes: 79 additions & 32 deletions src/mumble/ConfigDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,51 @@
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<item row="1" column="1" rowspan="2" colspan="2">
<widget class="QStackedWidget" name="qswPages">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QDialogButtonBox" name="pageButtonBox">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="dialogButtonBox">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::StandardButton::Apply|QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QListWidget" name="qlwIcons">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
Expand All @@ -35,60 +79,63 @@
</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">
<layout class="QHBoxLayout" name="horizontalLayout">
<item row="0" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QDialogButtonBox" name="pageButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<widget class="QLabel" name="label">
<property name="text">
<string>Active Profile</string>
</property>
<property name="buddy">
<cstring>qcbProfiles</cstring>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<widget class="QComboBox" name="qcbProfiles">
<property name="sizeAdjustPolicy">
<enum>QComboBox::SizeAdjustPolicy::AdjustToContents</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>474</width>
<height>22</height>
</size>
</widget>
</item>
<item>
<widget class="QToolButton" name="qtbProfileActions">
<property name="accessibleName">
<string>Profile Actions</string>
</property>
</spacer>
<property name="popupMode">
<enum>QToolButton::ToolButtonPopupMode::InstantPopup</enum>
</property>
<property name="class" stdset="0">
<string notr="true">hamburger</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="dialogButtonBox">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</widget>
</spacer>
</item>
</layout>
</item>
<item row="0" column="1">
<widget class="QStackedWidget" name="qswPages">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
Expand Down
1 change: 1 addition & 0 deletions src/mumble/Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct Global Q_DECL_FINAL {
MainWindow *mw;
TrayIcon *trayIcon;
Settings s;
Profiles profiles;
boost::shared_ptr< ServerHandler > sh;
boost::shared_ptr< AudioInput > ai;
boost::shared_ptr< AudioOutput > ao;
Expand Down
4 changes: 4 additions & 0 deletions src/mumble/GlobalShortcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,10 @@ GlobalShortcut::GlobalShortcut(QObject *p, int index, QString qsName, QVariant d
GlobalShortcutEngine::add(this);
}

void GlobalShortcut::reset() {
qlActive.clear();
}

GlobalShortcut::~GlobalShortcut() {
GlobalShortcutEngine::remove(this);
}
Loading