diff --git a/src/translations/ar.po b/src/translations/ar.po index 9ac7e34f1..c43ff2cc2 100644 --- a/src/translations/ar.po +++ b/src/translations/ar.po @@ -515,6 +515,9 @@ msgstr "اخفض الصوت 4%" msgid "Decrease volume" msgstr "" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "" diff --git a/src/translations/bg.po b/src/translations/bg.po index 3eff3a27d..253cd47ca 100644 --- a/src/translations/bg.po +++ b/src/translations/bg.po @@ -515,6 +515,9 @@ msgstr "" msgid "Decrease volume" msgstr "" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "" diff --git a/src/translations/ca.po b/src/translations/ca.po index e038ee245..e25d2297c 100644 --- a/src/translations/ca.po +++ b/src/translations/ca.po @@ -527,6 +527,9 @@ msgstr "Redueix el volum un 4%" msgid "Decrease volume" msgstr "Redueix el volum" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Retard entre visualitzacions" diff --git a/src/translations/cs.po b/src/translations/cs.po index 567f3623d..13eb5965b 100644 --- a/src/translations/cs.po +++ b/src/translations/cs.po @@ -516,6 +516,9 @@ msgstr "Sniž hlasitosto 4%" msgid "Decrease volume" msgstr "Snížit hlasitost" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "" diff --git a/src/translations/da.po b/src/translations/da.po index 6b42c0dea..0e9ba0b40 100644 --- a/src/translations/da.po +++ b/src/translations/da.po @@ -516,6 +516,9 @@ msgstr "Sænk lydstyrken med 4%" msgid "Decrease volume" msgstr "" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "" diff --git a/src/translations/de.po b/src/translations/de.po index e919a58b8..51b9ac689 100644 --- a/src/translations/de.po +++ b/src/translations/de.po @@ -526,6 +526,9 @@ msgstr "Lautstärke um 4% verringern" msgid "Decrease volume" msgstr "Lautstärke verringern" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Verzögerung zwischen Visualisierungen" diff --git a/src/translations/el.po b/src/translations/el.po index caa94f3f3..11572f10e 100644 --- a/src/translations/el.po +++ b/src/translations/el.po @@ -528,6 +528,9 @@ msgstr "Μείωση της έντασης ήχου κατά 4%" msgid "Decrease volume" msgstr "Μείωση έντασης" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Καθυστέρηση μεταξύ οπτικών εφέ" diff --git a/src/translations/en_CA.po b/src/translations/en_CA.po index 6cdcb0546..42fc8b5c1 100644 --- a/src/translations/en_CA.po +++ b/src/translations/en_CA.po @@ -517,6 +517,9 @@ msgstr "Decrease the volume by 4%" msgid "Decrease volume" msgstr "Decrease volume" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Delay between visualisations" diff --git a/src/translations/en_GB.po b/src/translations/en_GB.po index b27fa0736..2c88f2abb 100644 --- a/src/translations/en_GB.po +++ b/src/translations/en_GB.po @@ -515,6 +515,9 @@ msgstr "Decrease the volume by 4%" msgid "Decrease volume" msgstr "" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Delay between visualisations" diff --git a/src/translations/es.po b/src/translations/es.po index c4e2a7424..4fa50b6c4 100644 --- a/src/translations/es.po +++ b/src/translations/es.po @@ -527,6 +527,9 @@ msgstr "Reducir el volumen en 4%" msgid "Decrease volume" msgstr "Disminuir volumen" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Retardo entre visualizaciones" diff --git a/src/translations/fi.po b/src/translations/fi.po index 8bfdcbace..f1871d887 100644 --- a/src/translations/fi.po +++ b/src/translations/fi.po @@ -515,6 +515,9 @@ msgstr "" msgid "Decrease volume" msgstr "Vähennä äänenvoimakkuutta" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "" diff --git a/src/translations/fr.po b/src/translations/fr.po index b49ed9e34..2034cc42c 100644 --- a/src/translations/fr.po +++ b/src/translations/fr.po @@ -520,6 +520,9 @@ msgstr "Baisser le volume de 4%" msgid "Decrease volume" msgstr "Diminuer le volume" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Délai entre les visualisations" diff --git a/src/translations/gl.po b/src/translations/gl.po index 702503e11..c481ac850 100644 --- a/src/translations/gl.po +++ b/src/translations/gl.po @@ -515,6 +515,9 @@ msgstr "" msgid "Decrease volume" msgstr "" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "" diff --git a/src/translations/hu.po b/src/translations/hu.po index 8669956a5..4fa08aaa4 100644 --- a/src/translations/hu.po +++ b/src/translations/hu.po @@ -524,6 +524,9 @@ msgstr "Hangerő csökkentése 4%-kal" msgid "Decrease volume" msgstr "Hangerő csökkentése" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Megjelenítések között váltás ideje" diff --git a/src/translations/it.po b/src/translations/it.po index 621eba095..f2a2f16fe 100644 --- a/src/translations/it.po +++ b/src/translations/it.po @@ -531,6 +531,9 @@ msgstr "Riduci il volume del 4%" msgid "Decrease volume" msgstr "Riduci il volume" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Ritardo tra le visualizzazioni" diff --git a/src/translations/kk.po b/src/translations/kk.po index 1e1e46f3c..dcb997f7d 100644 --- a/src/translations/kk.po +++ b/src/translations/kk.po @@ -515,6 +515,9 @@ msgstr "" msgid "Decrease volume" msgstr "" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "" diff --git a/src/translations/lt.po b/src/translations/lt.po index da896fdcd..6baa0aabe 100644 --- a/src/translations/lt.po +++ b/src/translations/lt.po @@ -515,6 +515,9 @@ msgstr "" msgid "Decrease volume" msgstr "" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "" diff --git a/src/translations/nb.po b/src/translations/nb.po index a345f1499..606c4941d 100644 --- a/src/translations/nb.po +++ b/src/translations/nb.po @@ -515,6 +515,9 @@ msgstr "" msgid "Decrease volume" msgstr "" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "" diff --git a/src/translations/nl.po b/src/translations/nl.po index ac540913b..946498960 100644 --- a/src/translations/nl.po +++ b/src/translations/nl.po @@ -523,6 +523,9 @@ msgstr "Volume met 4% verlagen" msgid "Decrease volume" msgstr "Volume verlagen" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Vertraging tussen visualisaties" diff --git a/src/translations/oc.po b/src/translations/oc.po index 45c33bd78..c961804f4 100644 --- a/src/translations/oc.po +++ b/src/translations/oc.po @@ -515,6 +515,9 @@ msgstr "" msgid "Decrease volume" msgstr "Reduire lo volum" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "" diff --git a/src/translations/pl.po b/src/translations/pl.po index 64f34c48d..7979566b4 100644 --- a/src/translations/pl.po +++ b/src/translations/pl.po @@ -521,6 +521,9 @@ msgstr "Zmniejsz głośność o 4%" msgid "Decrease volume" msgstr "Zmniejsz głośność" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Opóźnienie pomiędzy wizualizacjami" diff --git a/src/translations/pt.po b/src/translations/pt.po index 3570d2851..388e30dba 100644 --- a/src/translations/pt.po +++ b/src/translations/pt.po @@ -525,6 +525,9 @@ msgstr "Diminuir o volume em 4%" msgid "Decrease volume" msgstr "Diminuir volume" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Atraso entre visualizações" diff --git a/src/translations/pt_BR.po b/src/translations/pt_BR.po index 6d432b28e..75579fa8d 100644 --- a/src/translations/pt_BR.po +++ b/src/translations/pt_BR.po @@ -520,6 +520,9 @@ msgstr "Diminuir volume em 4%" msgid "Decrease volume" msgstr "Diminuir volume" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Atraso entre as visualizações" diff --git a/src/translations/ro.po b/src/translations/ro.po index c5af3739d..5532aa37b 100644 --- a/src/translations/ro.po +++ b/src/translations/ro.po @@ -515,6 +515,9 @@ msgstr "Scade volumul cu 4%" msgid "Decrease volume" msgstr "" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "" diff --git a/src/translations/ru.po b/src/translations/ru.po index 4bdf09270..0b6adaf34 100644 --- a/src/translations/ru.po +++ b/src/translations/ru.po @@ -522,6 +522,9 @@ msgstr "Уменьшить громкость на 4%" msgid "Decrease volume" msgstr "Уменьшить громкость" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Задержка между визуализациями" diff --git a/src/translations/sk.po b/src/translations/sk.po index 404e9bcd8..105776867 100644 --- a/src/translations/sk.po +++ b/src/translations/sk.po @@ -524,6 +524,9 @@ msgstr "Znížiť hlasitosť o 4%" msgid "Decrease volume" msgstr "Znížiť hlasitosť" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Oneskorenie medzi vizualizáciami" diff --git a/src/translations/sl.po b/src/translations/sl.po index bf6c55dfc..9e875328a 100644 --- a/src/translations/sl.po +++ b/src/translations/sl.po @@ -523,6 +523,9 @@ msgstr "Zmanjšaj glasnost za 4%" msgid "Decrease volume" msgstr "Zmanjšaj glasnost" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Zamik med vizualizacijami" diff --git a/src/translations/sr.po b/src/translations/sr.po index 85f545679..61d4d5a2f 100644 --- a/src/translations/sr.po +++ b/src/translations/sr.po @@ -517,6 +517,9 @@ msgstr "Утишај јачину звука за 4%" msgid "Decrease volume" msgstr "Утишај звук" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Застој између визуелизација" diff --git a/src/translations/sv.po b/src/translations/sv.po index 3877b85ee..48392185b 100644 --- a/src/translations/sv.po +++ b/src/translations/sv.po @@ -519,6 +519,9 @@ msgstr "Sänk volymen med 4%" msgid "Decrease volume" msgstr "Sänk volymen" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Fördröjning mellan visualiseringar" diff --git a/src/translations/tr.po b/src/translations/tr.po index 625b1e0b5..461f50382 100644 --- a/src/translations/tr.po +++ b/src/translations/tr.po @@ -515,6 +515,9 @@ msgstr "Ses seviyesini %4 azalt" msgid "Decrease volume" msgstr "Sesi azalt" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Görselleştirmeler arasındaki gecikme" diff --git a/src/translations/translations.pot b/src/translations/translations.pot index d763f59d0..d21e4c61e 100644 --- a/src/translations/translations.pot +++ b/src/translations/translations.pot @@ -505,6 +505,9 @@ msgstr "" msgid "Decrease volume" msgstr "" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "" diff --git a/src/translations/uk.po b/src/translations/uk.po index 8a441208a..8fe3d001e 100644 --- a/src/translations/uk.po +++ b/src/translations/uk.po @@ -523,6 +523,9 @@ msgstr "Зменшити гучність на 4%" msgid "Decrease volume" msgstr "Зменшити гучність" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "Затримка між візуалізаціями" diff --git a/src/translations/zh_CN.po b/src/translations/zh_CN.po index d4f823214..42f4d4039 100644 --- a/src/translations/zh_CN.po +++ b/src/translations/zh_CN.po @@ -515,6 +515,9 @@ msgstr "" msgid "Decrease volume" msgstr "降低音量" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "" diff --git a/src/translations/zh_TW.po b/src/translations/zh_TW.po index d5665b80a..025825fa9 100644 --- a/src/translations/zh_TW.po +++ b/src/translations/zh_TW.po @@ -519,6 +519,9 @@ msgstr "減低音量4%" msgid "Decrease volume" msgstr "減低音量" +msgid "Defaults" +msgstr "" + msgid "Delay between visualizations" msgstr "在兩個視覺化效果間延遲切換" diff --git a/src/ui/settingsdialog.cpp b/src/ui/settingsdialog.cpp index d23fa2b87..d4a4b44d5 100644 --- a/src/ui/settingsdialog.cpp +++ b/src/ui/settingsdialog.cpp @@ -224,6 +224,15 @@ void SettingsDialog::accept() { #endif #ifdef ENABLE_WIIMOTEDEV + s.beginGroup(WiimotedevShortcuts::kActionsGroup); + s.clear(); + + foreach (const WiimotedevShortcutsConfig::Shortcut& shortcut, wiimotedev_config_->actions_) { + s.setValue(QString::number(shortcut.button), shortcut.action); + } + + s.endGroup(); + s.beginGroup(WiimotedevShortcuts::kSettingsGroup); s.setValue("enabled", wiimotedev_config_->ui_->wiimotedev_enable->isChecked()); s.setValue("only_when_focused", wiimotedev_config_->ui_->wiimotedev_focus->isChecked()); diff --git a/src/ui/wiimotedevshortcutsconfig.cpp b/src/ui/wiimotedevshortcutsconfig.cpp index 21c325a38..74f2e4813 100644 --- a/src/ui/wiimotedevshortcutsconfig.cpp +++ b/src/ui/wiimotedevshortcutsconfig.cpp @@ -113,7 +113,18 @@ WiimotedevShortcutsConfig::WiimotedevShortcutsConfig(QWidget* parent) ui_->wiimotedev_device->setValue(settings_.value("device", 1).toUInt()); settings_.endGroup(); + LoadSettings(); + + connect(ui_->wiimotedev_enable, SIGNAL(clicked(bool)), this, SLOT(WiimotedevEnabledChecked(bool))); + connect(ui_->list, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), SLOT(ItemClicked(QTreeWidgetItem*))); + connect(ui_->wiimotedev_delete_action, SIGNAL(clicked()), this, SLOT(DeleteAction())); + connect(ui_->wiimotedev_reload, SIGNAL(clicked()), this , SLOT(DefaultSettings())); +} + +void WiimotedevShortcutsConfig::LoadSettings(){ settings_.beginGroup(WiimotedevShortcuts::kActionsGroup); + ui_->list->clear(); + quint64 fvalue, svalue; bool fvalid, svalid; @@ -121,40 +132,70 @@ WiimotedevShortcutsConfig::WiimotedevShortcutsConfig(QWidget* parent) fvalue = str.toULongLong(&fvalid, 10); svalue = settings_.value(str, 0).toULongLong(&svalid); if (fvalid && svalid) { - new QTreeWidgetItem(ui_->list, - QStringList() << GetReadableWiiremoteSequence(fvalue) << text_actions_[svalue]); + Shortcut s; + s.object = new QTreeWidgetItem(ui_->list, QStringList() << GetReadableWiiremoteSequence(fvalue) << text_actions_[svalue]); + s.button = fvalue; + s.action = svalue; + actions_ << s; } ui_->list->sortItems(1, Qt::AscendingOrder); } settings_.endGroup(); +} - connect(ui_->wiimotedev_enable, SIGNAL(clicked(bool)), this, SLOT(WiimotedevEnabledChecked(bool))); - connect(ui_->list, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), SLOT(ItemClicked(QTreeWidgetItem*))); +void WiimotedevShortcutsConfig::DefaultSettings() +{ + settings_.beginGroup(WiimotedevShortcuts::kActionsGroup); + foreach (const QString& key, settings_.allKeys()) { + settings_.remove(key); + } + settings_.setValue(QString::number(WIIMOTE_BTN_LEFT), WiimotedevShortcuts::PlayerPreviousTrack); + settings_.setValue(QString::number(WIIMOTE_BTN_RIGHT), WiimotedevShortcuts::PlayerNextTrack); + settings_.setValue(QString::number(WIIMOTE_BTN_SHIFT_LEFT), WiimotedevShortcuts::PlayerPreviousTrack); + settings_.setValue(QString::number(WIIMOTE_BTN_SHIFT_RIGHT), WiimotedevShortcuts::PlayerNextTrack); + settings_.setValue(QString::number(WIIMOTE_BTN_PLUS), WiimotedevShortcuts::PlayerIncVolume); + settings_.setValue(QString::number(WIIMOTE_BTN_MINUS), WiimotedevShortcuts::PlayerDecVolume); + settings_.setValue(QString::number(WIIMOTE_BTN_1), WiimotedevShortcuts::PlayerTogglePause); + settings_.setValue(QString::number(WIIMOTE_BTN_2), WiimotedevShortcuts::PlayerShowOSD); + settings_.endGroup(); + settings_.sync(); + + LoadSettings(); } void WiimotedevShortcutsConfig::WiimotedevEnabledChecked(bool checked) { ui_->wiimotedev_groupbox->setEnabled(checked); } -void WiimotedevShortcutsConfig::ItemClicked(QTreeWidgetItem* item) { - current_id_ = item->data(0, Qt::UserRole).toString(); +void WiimotedevShortcutsConfig::ItemClicked(QTreeWidgetItem* selected_item) { + selected_item_ = selected_item; } QString WiimotedevShortcutsConfig::GetReadableWiiremoteSequence(quint64 value) { QMapIterator text(text_buttons_); QStringList list; - QString output; while (text.hasNext()) { text.next(); if ((text.key() & value) == text.key()) list << text.value(); } + QString output; for (int i = 0; i < (list.count() - 1); ++i) output += list.at(i) + " + "; output += list.last(); return output; } + +void WiimotedevShortcutsConfig::DeleteAction() { + for (int i = 0; i < actions_.count(); ++i) { + if (actions_.at(i).object == selected_item_) { + delete selected_item_; + actions_.removeAt(i); + break; + } + } +} diff --git a/src/ui/wiimotedevshortcutsconfig.h b/src/ui/wiimotedevshortcutsconfig.h index 9e278afe2..232b12b15 100644 --- a/src/ui/wiimotedevshortcutsconfig.h +++ b/src/ui/wiimotedevshortcutsconfig.h @@ -29,18 +29,32 @@ public: WiimotedevShortcutsConfig(QWidget* parent = 0); Ui_WiimotedevShortcutsConfig* ui_; + struct Shortcut { + QTreeWidgetItem* object; + quint64 button; + quint32 action; + }; + + QList actions_; + private: QSettings settings_; QString current_id_; - QMap < quint64, QString> text_buttons_; - QMap < quint32, QString> text_actions_; + QTreeWidgetItem* selected_item_; + + QMap text_buttons_; + QMap text_actions_; QString GetReadableWiiremoteSequence(quint64 value); private slots: + void LoadSettings(); + void DefaultSettings(); + void DeleteAction(); + void WiimotedevEnabledChecked(bool checked); - void ItemClicked(QTreeWidgetItem* item); + void ItemClicked(QTreeWidgetItem*); }; #endif // WIIMOTEDEVSHORTCUTSCONFIG_H diff --git a/src/ui/wiimotedevshortcutsconfig.ui b/src/ui/wiimotedevshortcutsconfig.ui index 350147976..0dd2f0687 100644 --- a/src/ui/wiimotedevshortcutsconfig.ui +++ b/src/ui/wiimotedevshortcutsconfig.ui @@ -174,6 +174,17 @@ + + + + Defaults + + + + :/icons/22x22/view-refresh.png:/icons/22x22/view-refresh.png + + + diff --git a/src/wiimotedev/shortcuts.cpp b/src/wiimotedev/shortcuts.cpp index 0cd9ba130..a74814b88 100644 --- a/src/wiimotedev/shortcuts.cpp +++ b/src/wiimotedev/shortcuts.cpp @@ -29,11 +29,11 @@ WiimotedevShortcuts::WiimotedevShortcuts(Player* player, QObject* parent) wiimotedev_buttons_(0), wiimotedev_device_(1), wiimotedev_active_(true), + wiimotedev_enable_(true), wiimotedev_focus_(false), wiimotedev_notification_(true) { ReloadSettings(); - wiimotedev_iface_ = new DBusDeviceEventsInterface(WIIMOTEDEV_DBUS_SERVICE_NAME, WIIMOTEDEV_DBUS_EVENTS_OBJECT, QDBusConnection::systemBus(), @@ -43,35 +43,15 @@ WiimotedevShortcuts::WiimotedevShortcuts(Player* player, QObject* parent) this, SLOT(DbusWiimoteGeneralButtons(quint32, quint64))); } -void WiimotedevShortcuts::SetEnabled(bool enabled) -{ - disconnect(this, 0, player_, 0); - if (!enabled) return; - - connect(this, SIGNAL(Next()), player_, SLOT(Next())); - connect(this, SIGNAL(Previous()), player_, SLOT(Previous())); - connect(this, SIGNAL(Play()), player_, SLOT(Play())); - connect(this, SIGNAL(Stop()), player_, SLOT(Stop())); - connect(this, SIGNAL(IncVolume()), player_, SLOT(VolumeUp())); - connect(this, SIGNAL(DecVolume()), player_, SLOT(VolumeDown())); - connect(this, SIGNAL(Mute()), player_, SLOT(Mute())); - connect(this, SIGNAL(Pause()), player_, SLOT(Pause())); - connect(this, SIGNAL(TogglePause()), player_, SLOT(PlayPause())); - connect(this, SIGNAL(SeekBackward()), player_, SLOT(SeekBackward())); - connect(this, SIGNAL(SeekForward()), player_, SLOT(SeekForward())); - connect(this, SIGNAL(ShowOSD()), player_, SLOT(ShowOSD())); -} - void WiimotedevShortcuts::ReloadSettings() { settings_.beginGroup(WiimotedevShortcuts::kActionsGroup); + actions_.clear(); if (!settings_.allKeys().count()) { SetDefaultSettings(); settings_.sync(); } - actions_.clear(); - quint64 fvalue, svalue; bool fvalid, svalid; @@ -84,8 +64,8 @@ void WiimotedevShortcuts::ReloadSettings() { settings_.endGroup(); settings_.beginGroup(WiimotedevShortcuts::kSettingsGroup); - SetEnabled(settings_.value("enabled", quint64(true)).toBool()); - wiimotedev_device_ = settings_.value("device", 1).toInt(); + wiimotedev_enable_ = settings_.value("enabled", wiimotedev_enable_).toBool(); + wiimotedev_device_ = settings_.value("device", wiimotedev_device_).toInt(); wiimotedev_active_ = settings_.value("use_active_action", wiimotedev_active_).toBool(); wiimotedev_focus_ = settings_.value("only_when_focused", wiimotedev_focus_).toBool(); wiimotedev_notification_ = settings_.value("use_notification", wiimotedev_notification_).toBool(); @@ -97,6 +77,9 @@ void WiimotedevShortcuts::SetDefaultSettings() { QSettings settings; settings.beginGroup(WiimotedevShortcuts::kActionsGroup); + foreach (const QString& key, settings_.allKeys()) { + settings_.remove(key); + } settings.setValue(QString::number(WIIMOTE_BTN_LEFT), PlayerPreviousTrack); settings.setValue(QString::number(WIIMOTE_BTN_RIGHT), PlayerNextTrack); settings.setValue(QString::number(WIIMOTE_BTN_SHIFT_LEFT), PlayerPreviousTrack); @@ -108,47 +91,41 @@ void WiimotedevShortcuts::SetDefaultSettings() settings.endGroup(); settings.beginGroup(WiimotedevShortcuts::kSettingsGroup); + foreach (const QString& key, settings_.allKeys()) { + settings_.remove(key); + } settings.setValue("enabled", true); settings.setValue("device", 1); settings.setValue("use_active_action", true); settings.setValue("only_when_focused", false); settings.setValue("use_notification", true); settings.endGroup(); - settings.sync(); } -void WiimotedevShortcuts::EmitRequest(quint32 action) { - switch (action) { - case PlayerNextTrack: emit Next(); break; - case PlayerPreviousTrack: emit Previous(); break; - case PlayerPlay: emit Play(); break; - case PlayerStop: emit Stop(); break; - case PlayerIncVolume: emit IncVolume(); break; - case PlayerDecVolume: emit DecVolume(); break; - case PlayerMute: emit Mute(); break; - case PlayerPause: emit Pause(); break; - case PlayerTogglePause: emit TogglePause(); break; - case PlayerSeekBackward: emit SeekBackward(); break; - case PlayerSeekForward: emit SeekForward(); break; - case PlayerStopAfter: emit StopAfter(); break; - case PlayerShowOSD: emit ShowOSD(); break; - } -} - void WiimotedevShortcuts::DbusWiimoteGeneralButtons(quint32 id, quint64 value) { - if (id != wiimotedev_device_) return; + if (id != wiimotedev_device_ || !wiimotedev_enable_) return; quint64 buttons = value & ~(WIIMOTE_TILT_MASK | NUNCHUK_TILT_MASK); if (wiimotedev_buttons_ == buttons) return; - QMapIterator actions(actions_); - - while (actions.hasNext()) { - actions.next(); - if (!actions.key()) continue; - if ((actions.key() & buttons) == actions.key()) EmitRequest(actions.value()); + if (actions_.contains(buttons)) { + switch (actions_.value(buttons, 0xff)) { + case PlayerNextTrack: player_->Next(); break; + case PlayerPreviousTrack: player_->Previous(); break; + case PlayerPlay: player_->Play(); break; + case PlayerStop: player_->Stop(); break; + case PlayerIncVolume: player_->VolumeUp(); break; + case PlayerDecVolume: player_->VolumeDown(); break; + case PlayerMute: player_->Mute(); break; + case PlayerPause: player_->Pause(); break; + case PlayerTogglePause: player_->PlayPause(); break; + case PlayerSeekBackward: player_->SeekBackward(); break; + case PlayerSeekForward: player_->SeekForward(); break; + case PlayerStopAfter: player_->Stop(); break; + case PlayerShowOSD: player_->ShowOSD(); break; + } } wiimotedev_buttons_ = buttons; diff --git a/src/wiimotedev/shortcuts.h b/src/wiimotedev/shortcuts.h index da90ff07f..e97c64548 100644 --- a/src/wiimotedev/shortcuts.h +++ b/src/wiimotedev/shortcuts.h @@ -35,27 +35,25 @@ public: public slots: void ReloadSettings(); void SetDefaultSettings(); - void SetEnabled(bool enabled); private slots: void DbusWiimoteGeneralButtons(quint32 id, quint64 value); private: - void EmitRequest(quint32 action); - DBusDeviceEventsInterface* wiimotedev_iface_; Player* player_; quint64 wiimotedev_buttons_; QSettings settings_; - quint32 wiimotedev_device_; + quint32 wiimotedev_device_; bool wiimotedev_active_; + bool wiimotedev_enable_; bool wiimotedev_focus_; bool wiimotedev_notification_; public: enum Action { - WiimotedevActive, + WiimotedevActive = 0, WiimotedevDeactive, PlayerNextTrack, PlayerPreviousTrack, @@ -69,26 +67,12 @@ public: PlayerSeekBackward, PlayerSeekForward, PlayerStopAfter, - PlayerShowOSD + PlayerShowOSD, + ActionNone = 0xff }; private: - QMap actions_; - -signals: - void Next(); - void Previous(); - void Play(); - void Stop(); - void IncVolume(); - void DecVolume(); - void Mute(); - void Pause(); - void TogglePause(); - void SeekBackward(); - void SeekForward(); - void StopAfter(); - void ShowOSD(); + QHash actions_; };