1
/* This file is part of Clementine.
2
Copyright 2010, David Sansome <me@davidsansome.com>
4
Clementine is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
9
Clementine is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
19
#include "wiimoteshortcutgrabber.h"
20
#include "ui_wiimoteshortcutgrabber.h"
22
WiimoteShortcutGrabber::WiimoteShortcutGrabber(quint32 action, quint32 device,
23
WiimoteSettingsPage* parent)
26
ui_(new Ui_WiimoteShortcutGrabber),
28
wiimotedev_device_(device),
29
wiimotedev_buttons_(0),
30
remember_wiimote_shifts_(0),
31
remember_nunchuk_shifts_(0)
35
if (QDBusConnection::systemBus().isConnected()) {
36
wiimotedev_iface_.reset(new OrgWiimotedevDeviceEventsInterface(
37
WIIMOTEDEV_DBUS_SERVICE_NAME,
38
WIIMOTEDEV_DBUS_EVENTS_OBJECT,
39
QDBusConnection::systemBus(),
42
connect(wiimotedev_iface_.get(), SIGNAL(dbusWiimoteGeneralButtons(uint,qulonglong)),
43
this, SLOT(DbusWiimoteGeneralButtons(uint,qulonglong)));
46
foreach (const QString& name, config_->TextActions())
47
ui_->comboBox->addItem(name);
49
ui_->comboBox->setCurrentIndex(pref_action_);
50
ui_->keep_label->setVisible(false);
52
connect(ui_->remember_shifts, SIGNAL(clicked(bool)), this, SLOT(RememberSwingChecked(bool)));
53
connect(ui_->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
54
connect(&line_, SIGNAL(frameChanged(int)), this, SLOT(Timeout(int)));
56
line_.setFrameRange(4, 0);
57
line_.setEasingCurve(QEasingCurve::Linear);
58
line_.setDuration(line_.startFrame()*1000);
61
WiimoteShortcutGrabber::~WiimoteShortcutGrabber() {
65
void WiimoteShortcutGrabber::Timeout(int secs) {
67
emit AddShortcut(wiimotedev_buttons_, ui_->comboBox->currentIndex());
72
ui_->keep_label->setText(QString(tr("Keep buttons for %1 second...")).arg(QString::number(secs))); else
73
ui_->keep_label->setText(QString(tr("Keep buttons for %1 seconds...")).arg(QString::number(secs)));
76
void WiimoteShortcutGrabber::RememberSwingChecked(bool checked) {
77
quint64 buttons = wiimotedev_buttons_;
79
ui_->keep_label->setVisible(false);
83
buttons |= remember_wiimote_shifts_ | remember_nunchuk_shifts_;
84
ui_->combo->setText(config_->GetReadableWiiremoteSequence(buttons));
86
remember_wiimote_shifts_ = 0;
87
remember_nunchuk_shifts_ = 0;
88
buttons &= ~(WIIMOTE_SHIFT_MASK | NUNCHUK_SHIFT_MASK);
89
ui_->combo->setText(config_->GetReadableWiiremoteSequence(buttons));
94
void WiimoteShortcutGrabber::DbusWiimoteGeneralButtons(uint id, qulonglong value) {
95
if (wiimotedev_device_ != id) return;
97
quint64 buttons = value & ~(
100
WIIMOTE_BTN_SHIFT_SHAKE |
101
NUNCHUK_BTN_SHIFT_SHAKE);
103
if (ui_->remember_shifts->isChecked()) {
104
if (!(buttons & WIIMOTE_SHIFT_MASK)) buttons |= remember_wiimote_shifts_;
105
if (!(buttons & NUNCHUK_SHIFT_MASK)) buttons |= remember_nunchuk_shifts_;
108
if (wiimotedev_buttons_ == buttons) return;
110
remember_wiimote_shifts_ = buttons & WIIMOTE_SHIFT_MASK;
111
remember_nunchuk_shifts_ = buttons & NUNCHUK_SHIFT_MASK;
114
if (buttons) line_.start();
116
ui_->keep_label->setVisible(buttons);
117
ui_->keep_label->setText(QString(tr("Keep buttons for %1 seconds...")).arg(QString::number(line_.startFrame())));
118
ui_->combo->setText(config_->GetReadableWiiremoteSequence(buttons));
120
wiimotedev_buttons_ = buttons;