~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/wiimotedev/wiimoteshortcutgrabber.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of Clementine.
 
2
   Copyright 2010, David Sansome <me@davidsansome.com>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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/>.
 
16
*/
 
17
 
 
18
#include "consts.h"
 
19
#include "wiimoteshortcutgrabber.h"
 
20
#include "ui_wiimoteshortcutgrabber.h"
 
21
 
 
22
WiimoteShortcutGrabber::WiimoteShortcutGrabber(quint32 action, quint32 device,
 
23
                                               WiimoteSettingsPage* parent)
 
24
 :QDialog(parent),
 
25
  pref_action_(action),
 
26
  ui_(new Ui_WiimoteShortcutGrabber),
 
27
  config_(parent),
 
28
  wiimotedev_device_(device),
 
29
  wiimotedev_buttons_(0),
 
30
  remember_wiimote_shifts_(0),
 
31
  remember_nunchuk_shifts_(0)
 
32
{
 
33
  ui_->setupUi(this);
 
34
 
 
35
  if (QDBusConnection::systemBus().isConnected()) {
 
36
    wiimotedev_iface_.reset(new OrgWiimotedevDeviceEventsInterface(
 
37
        WIIMOTEDEV_DBUS_SERVICE_NAME,
 
38
        WIIMOTEDEV_DBUS_EVENTS_OBJECT,
 
39
        QDBusConnection::systemBus(),
 
40
        this));
 
41
 
 
42
    connect(wiimotedev_iface_.get(), SIGNAL(dbusWiimoteGeneralButtons(uint,qulonglong)),
 
43
            this, SLOT(DbusWiimoteGeneralButtons(uint,qulonglong)));
 
44
  }
 
45
 
 
46
  foreach (const QString& name, config_->TextActions())
 
47
    ui_->comboBox->addItem(name);
 
48
 
 
49
  ui_->comboBox->setCurrentIndex(pref_action_);
 
50
  ui_->keep_label->setVisible(false);
 
51
 
 
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)));
 
55
 
 
56
  line_.setFrameRange(4, 0);
 
57
  line_.setEasingCurve(QEasingCurve::Linear);
 
58
  line_.setDuration(line_.startFrame()*1000);
 
59
}
 
60
 
 
61
WiimoteShortcutGrabber::~WiimoteShortcutGrabber() {
 
62
  delete ui_;
 
63
}
 
64
 
 
65
void WiimoteShortcutGrabber::Timeout(int secs) {
 
66
  if (!secs) {
 
67
    emit AddShortcut(wiimotedev_buttons_, ui_->comboBox->currentIndex());
 
68
    close();
 
69
  }
 
70
 
 
71
  if (secs == 1)
 
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)));
 
74
}
 
75
 
 
76
void WiimoteShortcutGrabber::RememberSwingChecked(bool checked) {
 
77
  quint64 buttons = wiimotedev_buttons_;
 
78
  line_.stop();
 
79
  ui_->keep_label->setVisible(false);
 
80
 
 
81
 
 
82
  if (checked) {
 
83
    buttons |=  remember_wiimote_shifts_ | remember_nunchuk_shifts_;
 
84
    ui_->combo->setText(config_->GetReadableWiiremoteSequence(buttons));
 
85
  } else {
 
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));
 
90
  }
 
91
}
 
92
 
 
93
 
 
94
void WiimoteShortcutGrabber::DbusWiimoteGeneralButtons(uint id, qulonglong value) {
 
95
  if (wiimotedev_device_ != id) return;
 
96
 
 
97
  quint64 buttons = value & ~(
 
98
      WIIMOTE_TILT_MASK |
 
99
      NUNCHUK_TILT_MASK |
 
100
      WIIMOTE_BTN_SHIFT_SHAKE |
 
101
      NUNCHUK_BTN_SHIFT_SHAKE);
 
102
 
 
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_;
 
106
  }
 
107
 
 
108
  if (wiimotedev_buttons_ == buttons) return;
 
109
 
 
110
  remember_wiimote_shifts_ = buttons & WIIMOTE_SHIFT_MASK;
 
111
  remember_nunchuk_shifts_ = buttons & NUNCHUK_SHIFT_MASK;
 
112
 
 
113
  line_.stop();
 
114
  if (buttons) line_.start();
 
115
 
 
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));
 
119
 
 
120
  wiimotedev_buttons_ = buttons;
 
121
}