Skip to content
Permalink
Browse files

Enable LookConfig to detect changes to user themes folder

LookConfig now uses a QFileSystemWatcher to react to changes
to the user themes folder. This way changes are directly visible
in the themes combobox. To prevent flooding with change events
when copying in a full directory we defer the update until 200ms
have passed after the last change we were notified of.
  • Loading branch information...
hacst committed Sep 8, 2015
1 parent 426edb6 commit 47631f728decbef1a5f16ed9faf85dcff677a92a
Showing with 68 additions and 27 deletions.
  1. +53 −26 src/mumble/LookConfig.cpp
  2. +14 −0 src/mumble/LookConfig.h
  3. +1 −1 src/mumble/ThemeInfo.cpp
@@ -84,10 +84,24 @@ LookConfig::LookConfig(Settings &st) : ConfigWidget(st) {

QDir userThemeDirectory = Themes::getUserThemesDirectory();
if (userThemeDirectory.exists()) {
m_themeDirectoryWatcher = new QFileSystemWatcher(this);

// Use a timer to cut down floods of directory changes. We only want
// to trigger a refresh after nothing has happened for 200ms in the
// watched directory.
m_themeDirectoryDebouncer = new QTimer(this);
m_themeDirectoryDebouncer->setSingleShot(true);
m_themeDirectoryDebouncer->setInterval(200);
m_themeDirectoryDebouncer->connect(m_themeDirectoryWatcher, SIGNAL(directoryChanged(QString)), SLOT(start()));

connect(m_themeDirectoryDebouncer, SIGNAL(timeout()), SLOT(themeDirectoryChanged()));
m_themeDirectoryWatcher->addPath(userThemeDirectory.path());

QUrl userThemeDirectoryUrl = QUrl::fromLocalFile(userThemeDirectory.path());
qlThemesDirectory->setText(tr("<a href=\"%1\">Browse</a>").arg(userThemeDirectoryUrl.toString()));
qlThemesDirectory->setOpenExternalLinks(true);
}

}

QString LookConfig::title() const {
@@ -98,6 +112,34 @@ QIcon LookConfig::icon() const {
return QIcon(QLatin1String("skin:config_ui.png"));
}

void LookConfig::reloadThemes(const boost::optional<ThemeInfo::StyleInfo> configuredStyle) {
const ThemeMap themes = Themes::getThemes();

int selectedThemeEntry = 0;

qcbTheme->clear();
qcbTheme->addItem(tr("None"));
for (ThemeMap::const_iterator theme = themes.begin();
theme != themes.end();
++theme) {

for (ThemeInfo::StylesMap::const_iterator styleit = theme->styles.begin();
styleit != theme->styles.end();
++styleit) {

if (configuredStyle
&& configuredStyle->themeName == styleit->themeName
&& configuredStyle->name == styleit->name) {
selectedThemeEntry = qcbTheme->count();
}

qcbTheme->addItem(theme->name + QLatin1String(" - ") + styleit->name, QVariant::fromValue(*styleit));
}
}

qcbTheme->setCurrentIndex(selectedThemeEntry);
}

void LookConfig::load(const Settings &r) {
loadComboBox(qcbLanguage, 0);
loadComboBox(qcbChannelDrag, 0);
@@ -143,33 +185,8 @@ void LookConfig::load(const Settings &r) {
loadCheckBox(qcbChatBarUseSelection, r.bChatBarUseSelection);
loadCheckBox(qcbFilterHidesEmptyChannels, r.bFilterHidesEmptyChannels);


qcbTheme->clear();

const boost::optional<ThemeInfo::StyleInfo> configuredStyle = Themes::getConfiguredStyle(r);
const ThemeMap themes = Themes::getThemes();

int selectedThemeEntry = 0;
qcbTheme->addItem(tr("None"));
for (ThemeMap::const_iterator theme = themes.begin();
theme != themes.end();
++theme) {

for (ThemeInfo::StylesMap::const_iterator styleit = theme->styles.begin();
styleit != theme->styles.end();
++styleit) {

if (configuredStyle
&& configuredStyle->themeName == styleit->themeName
&& configuredStyle->name == styleit->name) {
selectedThemeEntry = qcbTheme->count();
}

qcbTheme->addItem(theme->name + QLatin1String(" - ") + styleit->name, QVariant::fromValue(*styleit));
}
}

qcbTheme->setCurrentIndex(selectedThemeEntry);
reloadThemes(configuredStyle);
}

void LookConfig::save() const {
@@ -233,3 +250,13 @@ bool LookConfig::expert(bool b) {
qcbShowContextMenuInMenuBar->setVisible(b);
return true;
}

void LookConfig::themeDirectoryChanged() {
qWarning() << "Theme directory changed";
QVariant themeData = qcbTheme->itemData(qcbTheme->currentIndex());
if (themeData.isNull()) {
reloadThemes(boost::none);
} else {
reloadThemes(themeData.value<ThemeInfo::StyleInfo>());
}
}
@@ -32,9 +32,13 @@
#define MUMBLE_MUMBLE_LOOKCONFIG_H_

#include "ConfigDialog.h"
#include "ThemeInfo.h"

#include "ui_LookConfig.h"

class QFileSystemWatcher;
class QTimer;

class LookConfig : public ConfigWidget, Ui::LookConfig {
private:
Q_OBJECT
@@ -43,11 +47,21 @@ class LookConfig : public ConfigWidget, Ui::LookConfig {
LookConfig(Settings &st);
virtual QString title() const Q_DECL_OVERRIDE;
virtual QIcon icon() const Q_DECL_OVERRIDE;

public slots:
void accept() const Q_DECL_OVERRIDE;
void save() const Q_DECL_OVERRIDE;
void load(const Settings &r) Q_DECL_OVERRIDE;
bool expert(bool) Q_DECL_OVERRIDE;
void themeDirectoryChanged();
private:
/// Reload themes combobox and select given configuredStyle in it
void reloadThemes(const boost::optional<ThemeInfo::StyleInfo> configuredStyle);

/// Timer to prevent change event floods from triggering theme reloads
QTimer *m_themeDirectoryDebouncer;
/// Watcher to keep theme list up to date with user theme directory
QFileSystemWatcher* m_themeDirectoryWatcher;
};

#endif
@@ -95,7 +95,7 @@ boost::optional<ThemeInfo> loadLegacyThemeInfo(const QDir &themeDirectory) {
}

if (theme.styles.isEmpty()) {
qWarning() << themeDirectory << " does not seem to contain a old-style theme, skipping";
qWarning() << themeDirectory.absolutePath() << " does not seem to contain a old-style theme, skipping";
return boost::none;
}

0 comments on commit 47631f7

Please sign in to comment.
You can’t perform that action at this time.