]> git.sur5r.net Git - minitube/blob - src/globalshortcuts.cpp
Upload 3.9.3-2 to unstable
[minitube] / src / globalshortcuts.cpp
1 /* $BEGIN_LICENSE
2
3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
5
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
18
19 $END_LICENSE */
20
21 #include "globalshortcuts.h"
22 #include "globalshortcutbackend.h"
23
24 static GlobalShortcuts *singleton = 0;
25
26 GlobalShortcuts& GlobalShortcuts::instance() {
27     if (!singleton) singleton = new GlobalShortcuts();
28     return *singleton;
29 }
30
31 GlobalShortcuts::GlobalShortcuts(QObject *parent)
32     : QObject(parent),
33     backend(0) {
34
35     // Create actions
36     AddShortcut("play", tr("Play"), SIGNAL(Play()));
37     AddShortcut("pause", tr("Pause"), SIGNAL(Pause()));
38     AddShortcut("play_pause", tr("Play/Pause"), SIGNAL(PlayPause()), QKeySequence(Qt::Key_MediaPlay));
39     AddShortcut("stop", tr("Stop"), SIGNAL(Stop()), QKeySequence(Qt::Key_MediaStop));
40     AddShortcut("stop_after", tr("Stop playing after current track"), SIGNAL(StopAfter()));
41     AddShortcut("next_track", tr("Next track"), SIGNAL(Next()), QKeySequence(Qt::Key_MediaNext));
42     AddShortcut("prev_track", tr("Previous track"), SIGNAL(Previous()), QKeySequence(Qt::Key_MediaPrevious));
43     AddShortcut("inc_volume", tr("Increase volume"), SIGNAL(IncVolume()));
44     AddShortcut("dec_volume", tr("Decrease volume"), SIGNAL(DecVolume()));
45     AddShortcut("mute", tr("Mute"), SIGNAL(Mute()));
46     AddShortcut("seek_forward", tr("Seek forward"), SIGNAL(SeekForward()));
47     AddShortcut("seek_backward", tr("Seek backward"), SIGNAL(SeekBackward()));
48
49 }
50
51 void GlobalShortcuts::AddShortcut(const QString &id, const QString &name,
52                                   const char* signal,
53                                   const QKeySequence &default_key) {
54     Shortcut shortcut;
55     shortcut.action = new QAction(name, this);
56     shortcut.action->setShortcut(default_key);
57     shortcut.id = id;
58     shortcut.default_key = default_key;
59
60     connect(shortcut.action, SIGNAL(triggered()), this, signal);
61
62     shortcuts_[id] = shortcut;
63 }
64
65 void GlobalShortcuts::reload() {
66     if (backend) {
67         backend->Unregister();
68         backend->Register();
69     }
70 }