2010-08-29 17:21:50 +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 "ui/wiimotedevshortcutgrabber.h"
|
|
|
|
#include "ui_wiimotedevshortcutgrabber.h"
|
2010-08-31 01:57:31 +02:00
|
|
|
#include "wiimotedev/consts.h"
|
2010-08-29 17:21:50 +02:00
|
|
|
|
2010-09-11 03:23:44 +02:00
|
|
|
WiimotedevShortcutGrabber::WiimotedevShortcutGrabber(quint32 action, quint32 device, QWidget *parent)
|
2010-08-31 23:56:20 +02:00
|
|
|
:QDialog(parent),
|
|
|
|
pref_action_(action),
|
|
|
|
ui_(new Ui_WiimotedevShortcutGrabber),
|
|
|
|
config_(qobject_cast<WiimotedevShortcutsConfig*>(parent)),
|
2010-09-11 03:23:44 +02:00
|
|
|
wiimotedev_device_(device),
|
2010-08-31 23:56:20 +02:00
|
|
|
wiimotedev_buttons_(0),
|
|
|
|
remember_wiimote_shifts_(0),
|
|
|
|
remember_nunchuk_shifts_(0)
|
2010-08-29 17:21:50 +02:00
|
|
|
{
|
|
|
|
ui_->setupUi(this);
|
|
|
|
|
2010-08-29 19:19:59 +02:00
|
|
|
if (QDBusConnection::systemBus().isConnected()) {
|
2010-08-31 01:57:31 +02:00
|
|
|
wiimotedev_iface_.reset(new OrgWiimotedevDeviceEventsInterface(
|
|
|
|
WIIMOTEDEV_DBUS_SERVICE_NAME,
|
|
|
|
WIIMOTEDEV_DBUS_EVENTS_OBJECT,
|
|
|
|
QDBusConnection::systemBus(),
|
|
|
|
this));
|
|
|
|
|
|
|
|
connect(wiimotedev_iface_.get(), SIGNAL(dbusWiimoteGeneralButtons(uint,qulonglong)),
|
|
|
|
this, SLOT(DbusWiimoteGeneralButtons(uint,qulonglong)));
|
2010-08-29 19:19:59 +02:00
|
|
|
}
|
2010-08-29 17:21:50 +02:00
|
|
|
|
2010-08-29 18:24:19 +02:00
|
|
|
foreach (const QString& name, config_->text_actions_.values())
|
|
|
|
ui_->comboBox->addItem(name);
|
|
|
|
|
2010-08-31 22:35:11 +02:00
|
|
|
ui_->comboBox->setCurrentIndex(pref_action_);
|
2010-08-31 23:56:20 +02:00
|
|
|
ui_->keep_label->setVisible(false);
|
2010-08-31 22:35:11 +02:00
|
|
|
|
2010-08-31 21:57:53 +02:00
|
|
|
connect(ui_->remember_shifts, SIGNAL(clicked(bool)), this, SLOT(RememberSwingChecked(bool)));
|
2010-08-31 23:56:20 +02:00
|
|
|
connect(ui_->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
|
|
|
|
connect(&line_, SIGNAL(frameChanged(int)), this, SLOT(Timeout(int)));
|
|
|
|
|
|
|
|
line_.setFrameRange(4, 0);
|
|
|
|
line_.setEasingCurve(QEasingCurve::Linear);
|
|
|
|
line_.setDuration(line_.startFrame()*1000);
|
2010-08-29 17:21:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WiimotedevShortcutGrabber::~WiimotedevShortcutGrabber() {
|
|
|
|
delete ui_;
|
|
|
|
}
|
|
|
|
|
2010-08-31 23:56:20 +02:00
|
|
|
void WiimotedevShortcutGrabber::Timeout(int secs) {
|
2010-09-01 01:50:21 +02:00
|
|
|
if (!secs) {
|
2010-09-01 01:17:38 +02:00
|
|
|
emit AddShortcut(wiimotedev_buttons_, ui_->comboBox->currentIndex());
|
2010-08-31 23:56:20 +02:00
|
|
|
close();
|
2010-09-01 00:48:16 +02:00
|
|
|
}
|
2010-08-31 23:56:20 +02:00
|
|
|
|
|
|
|
if (secs == 1)
|
2010-09-01 00:48:16 +02:00
|
|
|
ui_->keep_label->setText(QString(tr("Keep buttons for %1 second...")).arg(QString::number(secs))); else
|
|
|
|
ui_->keep_label->setText(QString(tr("Keep buttons for %1 seconds...")).arg(QString::number(secs)));
|
2010-08-31 23:56:20 +02:00
|
|
|
}
|
|
|
|
|
2010-08-31 21:57:53 +02:00
|
|
|
void WiimotedevShortcutGrabber::RememberSwingChecked(bool checked) {
|
|
|
|
quint64 buttons = wiimotedev_buttons_;
|
2010-08-31 23:56:20 +02:00
|
|
|
line_.stop();
|
|
|
|
ui_->keep_label->setVisible(false);
|
|
|
|
|
2010-08-31 21:57:53 +02:00
|
|
|
|
|
|
|
if (checked) {
|
|
|
|
buttons |= remember_wiimote_shifts_ | remember_nunchuk_shifts_;
|
|
|
|
ui_->combo->setText(config_->GetReadableWiiremoteSequence(buttons));
|
|
|
|
} else {
|
|
|
|
remember_wiimote_shifts_ = 0;
|
|
|
|
remember_nunchuk_shifts_ = 0;
|
|
|
|
buttons &= ~(WIIMOTE_SHIFT_MASK | NUNCHUK_SHIFT_MASK);
|
|
|
|
ui_->combo->setText(config_->GetReadableWiiremoteSequence(buttons));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-31 01:57:31 +02:00
|
|
|
void WiimotedevShortcutGrabber::DbusWiimoteGeneralButtons(uint id, qulonglong value) {
|
2010-08-29 17:21:50 +02:00
|
|
|
if (wiimotedev_device_ != id) return;
|
|
|
|
|
2010-08-31 21:57:53 +02:00
|
|
|
quint64 buttons = value & ~(
|
|
|
|
WIIMOTE_TILT_MASK |
|
|
|
|
NUNCHUK_TILT_MASK |
|
|
|
|
WIIMOTE_BTN_SHIFT_SHAKE |
|
|
|
|
NUNCHUK_BTN_SHIFT_SHAKE);
|
|
|
|
|
|
|
|
if (ui_->remember_shifts->isChecked()) {
|
|
|
|
if (!(buttons & WIIMOTE_SHIFT_MASK)) buttons |= remember_wiimote_shifts_;
|
|
|
|
if (!(buttons & NUNCHUK_SHIFT_MASK)) buttons |= remember_nunchuk_shifts_;
|
|
|
|
}
|
|
|
|
|
2010-08-29 17:21:50 +02:00
|
|
|
if (wiimotedev_buttons_ == buttons) return;
|
|
|
|
|
2010-08-31 21:57:53 +02:00
|
|
|
remember_wiimote_shifts_ = buttons & WIIMOTE_SHIFT_MASK;
|
|
|
|
remember_nunchuk_shifts_ = buttons & NUNCHUK_SHIFT_MASK;
|
|
|
|
|
2010-08-31 23:56:20 +02:00
|
|
|
line_.stop();
|
|
|
|
if (buttons) line_.start();
|
|
|
|
|
|
|
|
ui_->keep_label->setVisible(buttons);
|
2010-09-01 00:48:16 +02:00
|
|
|
ui_->keep_label->setText(QString(tr("Keep buttons for %1 seconds...")).arg(QString::number(line_.startFrame())));
|
2010-08-29 18:24:19 +02:00
|
|
|
ui_->combo->setText(config_->GetReadableWiiremoteSequence(buttons));
|
2010-08-29 17:21:50 +02:00
|
|
|
|
|
|
|
wiimotedev_buttons_ = buttons;
|
|
|
|
}
|