]> git.sur5r.net Git - minitube/blob - src/gnomeglobalshortcutbackend.cpp
Imported Upstream version 1.2
[minitube] / src / gnomeglobalshortcutbackend.cpp
1 #include "gnomeglobalshortcutbackend.h"
2 #include "globalshortcuts.h"
3
4 #include <QAction>
5 #include <QtDebug>
6 #include <QtDBus>
7
8 const char* GnomeGlobalShortcutBackend::kGsdService = "org.gnome.SettingsDaemon";
9 const char* GnomeGlobalShortcutBackend::kGsdPath = "/org/gnome/SettingsDaemon/MediaKeys";
10 const char* GnomeGlobalShortcutBackend::kGsdInterface = "org.gnome.SettingsDaemon.MediaKeys";
11
12 GnomeGlobalShortcutBackend::GnomeGlobalShortcutBackend(GlobalShortcuts* parent)
13     : GlobalShortcutBackend(parent),
14     interface_(NULL) { }
15
16 bool GnomeGlobalShortcutBackend::IsGsdAvailable() {
17     return QDBusConnection::sessionBus().interface()->isServiceRegistered(
18             GnomeGlobalShortcutBackend::kGsdService);
19 }
20
21 bool GnomeGlobalShortcutBackend::DoRegister() {
22     // qDebug() << __PRETTY_FUNCTION__;
23     // Check if the GSD service is available
24     if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(kGsdService))
25         return false;
26
27     if (!interface_) {
28         interface_ = new QDBusInterface(
29                 kGsdService, kGsdPath, kGsdInterface, QDBusConnection::sessionBus(), this);
30     }
31
32     connect(interface_, SIGNAL(MediaPlayerKeyPressed(QString,QString)),
33             this, SLOT(GnomeMediaKeyPressed(QString,QString)));
34
35     return true;
36 }
37
38 void GnomeGlobalShortcutBackend::DoUnregister() {
39     // Check if the GSD service is available
40     if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(kGsdService))
41         return;
42     if (!interface_)
43         return;
44
45     disconnect(interface_, SIGNAL(MediaPlayerKeyPressed(QString,QString)),
46                this, SLOT(GnomeMediaKeyPressed(QString,QString)));
47 }
48
49 void GnomeGlobalShortcutBackend::GnomeMediaKeyPressed(const QString&, const QString& key) {
50     if (key == "Play")     manager_->shortcuts()["play_pause"].action->trigger();
51     if (key == "Stop")     manager_->shortcuts()["stop"].action->trigger();
52     if (key == "Next")     manager_->shortcuts()["next_track"].action->trigger();
53     if (key == "Previous") manager_->shortcuts()["prev_track"].action->trigger();
54 }