From 8359190a2f44c9d590690f49d4d3393785a5b412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Burdukiewicz?= Date: Tue, 31 Aug 2010 23:35:39 +0000 Subject: [PATCH] Fix bug that restore default settings when all wiimotedev actions are removed --- src/ui/settingsdialog.cpp | 1 + src/ui/wiimotedevshortcutsconfig.cpp | 10 +++++++++- src/wiimotedev/shortcuts.cpp | 28 ++++++++-------------------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/ui/settingsdialog.cpp b/src/ui/settingsdialog.cpp index 1199b21c4..59c7d37e8 100644 --- a/src/ui/settingsdialog.cpp +++ b/src/ui/settingsdialog.cpp @@ -239,6 +239,7 @@ void SettingsDialog::accept() { s.endGroup(); s.beginGroup(WiimotedevShortcuts::kSettingsGroup); + s.setValue("first_conf", false); s.setValue("enabled", wiimotedev_config_->ui_->wiimotedev_enable->isChecked()); s.setValue("only_when_focused", wiimotedev_config_->ui_->wiimotedev_focus->isChecked()); s.setValue("use_active_action", wiimotedev_config_->ui_->wiimotedev_active->isChecked()); diff --git a/src/ui/wiimotedevshortcutsconfig.cpp b/src/ui/wiimotedevshortcutsconfig.cpp index ba40ded6c..af1836bf8 100644 --- a/src/ui/wiimotedevshortcutsconfig.cpp +++ b/src/ui/wiimotedevshortcutsconfig.cpp @@ -136,6 +136,15 @@ void WiimotedevShortcutsConfig::AddShortcut(quint64 button, quint32 action) { } void WiimotedevShortcutsConfig::LoadSettings(){ + settings_.beginGroup(WiimotedevShortcuts::kSettingsGroup); + bool first_conf = settings_.value("first_conf", true).toBool(); + settings_.endGroup(); + + if (first_conf) { + DefaultSettings(); + return; + } + settings_.beginGroup(WiimotedevShortcuts::kActionsGroup); settings_.sync(); ui_->list->clear(); @@ -155,7 +164,6 @@ void WiimotedevShortcutsConfig::LoadSettings(){ ui_->list->sortItems(1, Qt::AscendingOrder); } - void WiimotedevShortcutsConfig::DefaultSettings() { ui_->list->clear(); diff --git a/src/wiimotedev/shortcuts.cpp b/src/wiimotedev/shortcuts.cpp index 8ce3f4dba..67f333546 100644 --- a/src/wiimotedev/shortcuts.cpp +++ b/src/wiimotedev/shortcuts.cpp @@ -59,27 +59,16 @@ void WiimotedevShortcuts::ReloadSettings() { settings_.beginGroup(WiimotedevShortcuts::kActionsGroup); - if (!settings_.allKeys().count()) { - actions_[WIIMOTE_BTN_LEFT] = PlayerPreviousTrack; - actions_[WIIMOTE_BTN_RIGHT] = PlayerNextTrack; - actions_[WIIMOTE_BTN_RIGHT] = PlayerNextTrack; - actions_[WIIMOTE_BTN_SHIFT_LEFT] = PlayerPreviousTrack; - actions_[WIIMOTE_BTN_SHIFT_RIGHT] = PlayerNextTrack; - actions_[WIIMOTE_BTN_PLUS] = PlayerIncVolume; - actions_[WIIMOTE_BTN_MINUS] = PlayerDecVolume; - actions_[WIIMOTE_BTN_1] = PlayerTogglePause; - actions_[WIIMOTE_BTN_2] = PlayerShowOSD; - } else { + quint64 fvalue, svalue; + bool fvalid, svalid; - quint64 fvalue, svalue; - bool fvalid, svalid; - - foreach (const QString& str, settings_.allKeys()) { - fvalue = str.toULongLong(&fvalid, 10); - svalue = settings_.value(str, 0).toULongLong(&svalid); - if (fvalid && svalid) actions_[fvalue] = svalue; - } + foreach (const QString& str, settings_.allKeys()) { + fvalue = str.toULongLong(&fvalid, 10); + svalue = settings_.value(str, 0).toULongLong(&svalid); + if (fvalid && svalid) + actions_[fvalue] = svalue; } + settings_.endGroup(); settings_.beginGroup(WiimotedevShortcuts::kSettingsGroup); @@ -88,7 +77,6 @@ void WiimotedevShortcuts::ReloadSettings() { wiimotedev_active_ = settings_.value("use_active_action", true).toBool(); wiimotedev_focus_ = settings_.value("only_when_focused", false).toBool(); wiimotedev_notification_ = settings_.value("use_notification", true).toBool(); - settings_.endGroup(); SetWiimotedevInterfaceActived(wiimotedev_enable_);