2010-08-25 15:02:53 +02:00
|
|
|
/* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
2010-08-31 01:57:31 +02:00
|
|
|
#include "wiimotedev/consts.h"
|
2010-08-25 15:02:53 +02:00
|
|
|
#include "wiimotedev/shortcuts.h"
|
|
|
|
|
2010-08-25 16:58:22 +02:00
|
|
|
const char* WiimotedevShortcuts::kActionsGroup = "WiimotedevActions";
|
|
|
|
const char* WiimotedevShortcuts::kSettingsGroup = "WiimotedevSettings";
|
2010-08-25 15:02:53 +02:00
|
|
|
|
2010-08-30 19:31:42 +02:00
|
|
|
WiimotedevShortcuts::WiimotedevShortcuts(QObject* parent)
|
2010-08-25 15:02:53 +02:00
|
|
|
:QObject(parent),
|
2010-08-30 19:31:42 +02:00
|
|
|
player_(qobject_cast<Player*>(parent)),
|
|
|
|
wiimotedev_active_(true),
|
2010-08-25 16:58:22 +02:00
|
|
|
wiimotedev_buttons_(0),
|
|
|
|
wiimotedev_device_(1),
|
2010-08-26 17:37:07 +02:00
|
|
|
wiimotedev_enable_(true),
|
2010-08-25 18:19:54 +02:00
|
|
|
wiimotedev_focus_(false),
|
2010-08-30 19:31:42 +02:00
|
|
|
wiimotedev_iface_(NULL),
|
2010-08-25 18:19:54 +02:00
|
|
|
wiimotedev_notification_(true)
|
2010-08-25 15:02:53 +02:00
|
|
|
{
|
|
|
|
ReloadSettings();
|
2010-08-30 19:31:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void WiimotedevShortcuts::SetWiimotedevInterfaceActived(bool actived) {
|
|
|
|
if (!QDBusConnection::systemBus().isConnected())
|
|
|
|
return;
|
2010-08-25 15:02:53 +02:00
|
|
|
|
2010-08-30 19:31:42 +02:00
|
|
|
if (actived && !wiimotedev_iface_) {
|
2010-08-31 01:57:31 +02:00
|
|
|
wiimotedev_iface_.reset(new OrgWiimotedevDeviceEventsInterface(
|
2010-08-30 19:31:42 +02:00
|
|
|
WIIMOTEDEV_DBUS_SERVICE_NAME, WIIMOTEDEV_DBUS_EVENTS_OBJECT,
|
|
|
|
QDBusConnection::systemBus(), this));
|
2010-08-29 19:19:59 +02:00
|
|
|
|
2010-08-31 01:57:31 +02:00
|
|
|
connect(wiimotedev_iface_.get(), SIGNAL(dbusWiimoteGeneralButtons(uint,qulonglong)),
|
|
|
|
this, SLOT(DbusWiimoteGeneralButtons(uint,qulonglong)));
|
2010-08-29 19:19:59 +02:00
|
|
|
}
|
2010-08-30 19:31:42 +02:00
|
|
|
|
|
|
|
if (!actived && wiimotedev_iface_)
|
|
|
|
wiimotedev_iface_.reset();
|
2010-08-25 15:02:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void WiimotedevShortcuts::ReloadSettings() {
|
2010-08-28 21:31:38 +02:00
|
|
|
settings_.sync();
|
2010-08-26 17:37:07 +02:00
|
|
|
actions_.clear();
|
2010-08-25 16:58:22 +02:00
|
|
|
|
2010-08-31 03:37:17 +02:00
|
|
|
settings_.beginGroup(WiimotedevShortcuts::kActionsGroup);
|
2010-08-25 16:58:22 +02:00
|
|
|
|
2010-08-31 03:37:17 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
foreach (const QString& str, settings_.allKeys()) {
|
|
|
|
fvalue = str.toULongLong(&fvalid, 10);
|
|
|
|
svalue = settings_.value(str, 0).toULongLong(&svalid);
|
|
|
|
if (fvalid && svalid) actions_[fvalue] = svalue;
|
|
|
|
}
|
2010-08-25 16:58:22 +02:00
|
|
|
}
|
|
|
|
settings_.endGroup();
|
|
|
|
|
|
|
|
settings_.beginGroup(WiimotedevShortcuts::kSettingsGroup);
|
2010-08-31 03:37:17 +02:00
|
|
|
wiimotedev_enable_ = settings_.value("enabled", false).toBool();
|
|
|
|
wiimotedev_device_ = settings_.value("device", 1).toInt();
|
|
|
|
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();
|
2010-08-25 18:19:54 +02:00
|
|
|
|
2010-08-25 16:58:22 +02:00
|
|
|
settings_.endGroup();
|
2010-08-30 19:31:42 +02:00
|
|
|
|
|
|
|
SetWiimotedevInterfaceActived(wiimotedev_enable_);
|
2010-08-25 15:02:53 +02:00
|
|
|
}
|
|
|
|
|
2010-08-31 01:57:31 +02:00
|
|
|
void WiimotedevShortcuts::DbusWiimoteGeneralButtons(uint id, qulonglong value) {
|
2010-08-30 19:31:42 +02:00
|
|
|
if (id != wiimotedev_device_ || !wiimotedev_enable_ || !player_) return;
|
2010-08-25 15:02:53 +02:00
|
|
|
|
2010-08-31 22:35:11 +02:00
|
|
|
quint64 buttons = value & ~(
|
|
|
|
WIIMOTE_TILT_MASK |
|
|
|
|
NUNCHUK_TILT_MASK |
|
|
|
|
WIIMOTE_BTN_SHIFT_SHAKE |
|
|
|
|
NUNCHUK_BTN_SHIFT_SHAKE);
|
2010-08-25 15:02:53 +02:00
|
|
|
|
|
|
|
if (wiimotedev_buttons_ == buttons) return;
|
|
|
|
|
2010-08-26 17:37:07 +02:00
|
|
|
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;
|
|
|
|
}
|
2010-08-25 15:02:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
wiimotedev_buttons_ = buttons;
|
|
|
|
}
|