3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
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.
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.
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/>.
21 #include "gnomeglobalshortcutbackend.h"
22 #include "globalshortcuts.h"
28 const char* GnomeGlobalShortcutBackend::kGsdService = "org.gnome.SettingsDaemon";
29 const char* GnomeGlobalShortcutBackend::kGsdPath = "/org/gnome/SettingsDaemon/MediaKeys";
30 const char* GnomeGlobalShortcutBackend::kGsdInterface = "org.gnome.SettingsDaemon.MediaKeys";
32 GnomeGlobalShortcutBackend::GnomeGlobalShortcutBackend(GlobalShortcuts* parent)
33 : GlobalShortcutBackend(parent),
36 bool GnomeGlobalShortcutBackend::IsGsdAvailable() {
37 return QDBusConnection::sessionBus().interface()->isServiceRegistered(
38 GnomeGlobalShortcutBackend::kGsdService);
41 bool GnomeGlobalShortcutBackend::DoRegister() {
42 // qDebug() << __PRETTY_FUNCTION__;
43 // Check if the GSD service is available
44 if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(kGsdService))
48 interface_ = new QDBusInterface(
49 kGsdService, kGsdPath, kGsdInterface, QDBusConnection::sessionBus(), this);
52 connect(interface_, SIGNAL(MediaPlayerKeyPressed(QString,QString)),
53 this, SLOT(GnomeMediaKeyPressed(QString,QString)));
58 void GnomeGlobalShortcutBackend::DoUnregister() {
59 // Check if the GSD service is available
60 if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(kGsdService))
65 disconnect(interface_, SIGNAL(MediaPlayerKeyPressed(QString,QString)),
66 this, SLOT(GnomeMediaKeyPressed(QString,QString)));
69 void GnomeGlobalShortcutBackend::GnomeMediaKeyPressed(const QString&, const QString& key) {
70 if (key == "Play") manager_->shortcuts()["play_pause"].action->trigger();
71 if (key == "Stop") manager_->shortcuts()["stop"].action->trigger();
72 if (key == "Next") manager_->shortcuts()["next_track"].action->trigger();
73 if (key == "Previous") manager_->shortcuts()["prev_track"].action->trigger();