diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cb079cf2b..81040372b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -487,6 +487,9 @@ if(NOT APPLE AND NOT WIN32) list(APPEND SOURCES wiimotedev/interface.cpp) list(APPEND HEADERS wiimotedev/interface.h) + list(APPEND SOURCES wiimotedev/shortcuts.cpp) + list(APPEND HEADERS wiimotedev/shortcuts.h) + list(APPEND SOURCES ui/wiimotedevshortcutsconfig.cpp) list(APPEND HEADERS ui/wiimotedevshortcutsconfig.h) list(APPEND UI ui/wiimotedevshortcutsconfig.ui) diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 224c90d1c..0cb08d644 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -69,7 +69,7 @@ #include "widgets/trackslider.h" #ifdef ENABLE_WIIMOTEDEV -#include "wiimotedev/interface.h" +# include "wiimotedev/shortcuts.h" #endif #ifdef HAVE_GSTREAMER @@ -138,8 +138,7 @@ MainWindow::MainWindow(NetworkAccessManager* network, Engine::Type engine, QWidg organise_dialog_(new OrganiseDialog(task_manager_)), queue_manager_(new QueueManager), #ifdef ENABLE_WIIMOTEDEV - wiimotedev_buttons_(0), - wiimotedev_iface_(NULL), + wiimotedev_shortcuts_(NULL), #endif #ifdef ENABLE_VISUALISATIONS visualisation_(new VisualisationContainer), @@ -580,10 +579,7 @@ MainWindow::MainWindow(NetworkAccessManager* network, Engine::Type engine, QWidg library_->StartThreads(); #ifdef ENABLE_WIIMOTEDEV - wiimotedev_iface_ = new DBusDeviceEventsInterface(WIIMOTEDEV_DBUS_SERVICE_NAME, WIIMOTEDEV_DBUS_EVENTS_OBJECT, - QDBusConnection::systemBus(), this); - - connect(wiimotedev_iface_, SIGNAL(dbusWiimoteButtons(quint32,quint64)), this, SLOT(DbusWiimoteButtons(quint32,quint64))); + wiimotedev_shortcuts_ = new WiimotedevShortcuts(player_, this); #endif } @@ -1427,34 +1423,3 @@ void MainWindow::PlaylistCopyToDevice() { organise_dialog_->SetCopy(true); organise_dialog_->show(); } - -#ifdef ENABLE_WIIMOTEDEV -void MainWindow::DbusWiimoteButtons(quint32 id, quint64 value) { - if (!id) return; - - quint64 buttons = value & ~WIIMOTE_TILT_MASK; - if (wiimotedev_buttons_ == buttons) return; - - if ((!(wiimotedev_buttons_ & WIIMOTE_BTN_SHIFT_LEFT) && - (value & WIIMOTE_BTN_SHIFT_LEFT)) || - (!(wiimotedev_buttons_ & WIIMOTE_BTN_LEFT) && - (value & WIIMOTE_BTN_LEFT))) player_->Previous(); - - - if ((!(wiimotedev_buttons_ & WIIMOTE_BTN_SHIFT_RIGHT) && - (value & WIIMOTE_BTN_SHIFT_RIGHT)) || - (!(wiimotedev_buttons_ & WIIMOTE_BTN_RIGHT) && - (value & WIIMOTE_BTN_RIGHT))) player_->Next(); - - if (!(wiimotedev_buttons_ & WIIMOTE_BTN_PLUS) && - (value & WIIMOTE_BTN_PLUS)) player_->VolumeUp(); - - if (!(wiimotedev_buttons_ & WIIMOTE_BTN_MINUS) && - (value & WIIMOTE_BTN_MINUS)) player_->VolumeDown(); - - if (!(wiimotedev_buttons_ & WIIMOTE_BTN_A) && - (value & WIIMOTE_BTN_A)) player_->PlayPause(); - - wiimotedev_buttons_ = buttons; -} -#endif diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index d9bc93131..3160417c1 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -34,7 +34,6 @@ class AddStreamDialog; class AlbumCoverManager; class CommandlineOptions; class Database; -class DBusDeviceEventsInterface; class DeviceManager; class EditTagDialog; class Equalizer; @@ -58,6 +57,7 @@ class Song; class SystemTrayIcon; class TaskManager; class TranscodeDialog; +class WiimotedevShortcuts; class VisualisationContainer; class Ui_MainWindow; @@ -171,10 +171,6 @@ class MainWindow : public QMainWindow, public PlatformInterface { void SongSaveComplete(); -#ifdef ENABLE_WIIMOTEDEV - void DbusWiimoteButtons(quint32 id, quint64 value); -#endif - private: void SaveGeometry(); void AddFilesToPlaylist(bool clear_first, const QList& urls); @@ -216,8 +212,7 @@ class MainWindow : public QMainWindow, public PlatformInterface { #endif #ifdef ENABLE_WIIMOTEDEV - DBusDeviceEventsInterface* wiimotedev_iface_; - quint64 wiimotedev_buttons_; + WiimotedevShortcuts *wiimotedev_shortcuts_; #endif QMenu* playlist_menu_; diff --git a/src/wiimotedev/shortcuts.cpp b/src/wiimotedev/shortcuts.cpp new file mode 100644 index 000000000..2d83d8d05 --- /dev/null +++ b/src/wiimotedev/shortcuts.cpp @@ -0,0 +1,116 @@ +/* This file is part of Clementine. + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#include + +#include "wiimotedev/shortcuts.h" +#include "wiimotedev/interface.h" + +const char* WiimotedevShortcuts::kSettingsGroup = "Wiimotedev"; + +WiimotedevShortcuts::WiimotedevShortcuts(Player *player, QObject *parent) + :QObject(parent), + player_(player), + wiimotedev_iface_(NULL), + wiimotedev_buttons_(0) +{ + settings_.beginGroup(WiimotedevShortcuts::kSettingsGroup); + ReloadSettings(); + + wiimotedev_iface_ = new DBusDeviceEventsInterface(WIIMOTEDEV_DBUS_SERVICE_NAME, + WIIMOTEDEV_DBUS_EVENTS_OBJECT, + QDBusConnection::systemBus(), + this); + + connect(wiimotedev_iface_, SIGNAL(dbusWiimoteGeneralButtons(quint32,quint64)), + this, SLOT(DbusWiimoteGeneralButtons(quint32, quint64))); +} + +void WiimotedevShortcuts::SetEnabled(bool enabled) +{ + if (!enabled) { + disconnect(this, 0, player_, 0); + 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_.sync(); + quint64 value; + if (value = settings_.value(QString::fromUtf8("next_track"), quint64(WIIMOTE_BTN_RIGHT)).toInt()) actions_[PlayerNextTrack] = value; + if (value = settings_.value(QString::fromUtf8("previous_track"), quint64(WIIMOTE_BTN_LEFT)).toInt()) actions_[PlayerPreviousTrack] = value; + if (value = settings_.value(QString::fromUtf8("play"), quint64(0)).toInt()) actions_[PlayerPlay] = value; + if (value = settings_.value(QString::fromUtf8("stop"), quint64(0)).toInt()) actions_[PlayerStop] = value; + if (value = settings_.value(QString::fromUtf8("inc_volume"), quint64(WIIMOTE_BTN_PLUS)).toInt()) actions_[PlayerIncVolume] = value; + if (value = settings_.value(QString::fromUtf8("dec_volume"), quint64(WIIMOTE_BTN_MINUS)).toInt()) actions_[PlayerDecVolume] = value; + if (value = settings_.value(QString::fromUtf8("mute"), quint64(0)).toInt()) actions_[PlayerMute] = value; + if (value = settings_.value(QString::fromUtf8("pause"), quint64(0)).toInt()) actions_[PlayerPause] = value; + if (value = settings_.value(QString::fromUtf8("togglepause"), quint64(WIIMOTE_BTN_1)).toInt()) actions_[PlayerTogglePause] = value; + if (value = settings_.value(QString::fromUtf8("seek_backward"), quint64(WIIMOTE_BTN_UP)).toInt()) actions_[PlayerSeekBackward] = value; + if (value = settings_.value(QString::fromUtf8("seek_forward"), quint64(WIIMOTE_BTN_DOWN)).toInt()) actions_[PlayerSeekForward] = value; + if (value = settings_.value(QString::fromUtf8("show_osd"), quint64(WIIMOTE_BTN_2)).toInt()) actions_[PlayerShowOSD] = value; + + SetEnabled(settings_.value(QString::fromUtf8("enabled"), quint64(true)).toBool()); +} + +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 != 1) return; + + quint64 buttons = value & ~(WIIMOTE_TILT_MASK | NUNCHUK_TILT_MASK); + + if (wiimotedev_buttons_ == buttons) return; + + QMapIterator< quint32, quint64> actions(actions_); + + while (actions.hasNext()) { + actions.next(); + if (actions.value() == 0) continue; + if ((actions.value() & buttons) == actions.value()) EmitRequest(actions.key()); + } + + wiimotedev_buttons_ = buttons; +} diff --git a/src/wiimotedev/shortcuts.h b/src/wiimotedev/shortcuts.h new file mode 100644 index 000000000..e69323b2a --- /dev/null +++ b/src/wiimotedev/shortcuts.h @@ -0,0 +1,85 @@ +/* This file is part of Clementine. + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#ifndef SHORTCUTS_H +#define SHORTCUTS_H + +#include +#include +#include "core/player.h" + +class DBusDeviceEventsInterface; +class QSettings; + +class WiimotedevShortcuts :public QObject { + Q_OBJECT +public: + static const char* kSettingsGroup; + + WiimotedevShortcuts(Player *player = 0, QObject *parent = 0); + +public slots: + void ReloadSettings(); + void SetEnabled(bool enabled); + +private Q_SLOTS: + void DbusWiimoteGeneralButtons(quint32 id, quint64 value); + +private: + void EmitRequest(quint32 action); + + DBusDeviceEventsInterface* wiimotedev_iface_; + Player* player_; + quint64 wiimotedev_buttons_; + QSettings settings_; + +private: + enum action { + PlayerNextTrack, + PlayerPreviousTrack, + PlayerPlay, + PlayerStop, + PlayerIncVolume, + PlayerDecVolume, + PlayerMute, + PlayerPause, + PlayerTogglePause, + PlayerSeekBackward, + PlayerSeekForward, + PlayerStopAfter, + PlayerShowOSD + }; + + QMap < quint32, quint64> 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(); + +}; + +#endif // SHORTCUTS_H