3 This file is part of Musique.
4 Copyright 2013, Flavio Tordini <flavio.tordini@gmail.com>
6 Musique 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 Musique 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 Musique. If not, see <http://www.gnu.org/licenses/>.
21 #include "gnomeglobalshortcutbackend.h"
22 #include "globalshortcuts.h"
23 #include "constants.h"
32 const char* GnomeGlobalShortcutBackend::kGsdService = "org.gnome.SettingsDaemon";
33 const char* GnomeGlobalShortcutBackend::kGsdPath = "/org/gnome/SettingsDaemon/MediaKeys";
34 const char* GnomeGlobalShortcutBackend::kGsdInterface = "org.gnome.SettingsDaemon.MediaKeys";
36 GnomeGlobalShortcutBackend::GnomeGlobalShortcutBackend(GlobalShortcuts* parent)
37 : GlobalShortcutBackend(parent),
40 bool GnomeGlobalShortcutBackend::IsGsdAvailable() {
42 return QDBusConnection::sessionBus().interface()->isServiceRegistered(
43 GnomeGlobalShortcutBackend::kGsdService);
49 bool GnomeGlobalShortcutBackend::DoRegister() {
50 // qDebug() << __PRETTY_FUNCTION__;
52 // Check if the GSD service is available
53 if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(kGsdService))
57 interface_ = new QDBusInterface(
58 kGsdService, kGsdPath, kGsdInterface, QDBusConnection::sessionBus(), this);
61 QDBusMessage reply = interface_->call("GrabMediaPlayerKeys", Constants::NAME, (unsigned int) 0);
62 if (reply.type() == QDBusMessage::ErrorMessage) {
63 qWarning() << "Failed to grab media player keys. Error:" << reply.errorMessage();
66 connect(interface_, SIGNAL(MediaPlayerKeyPressed(QString,QString)),
67 this, SLOT(GnomeMediaKeyPressed(QString,QString)));
75 void GnomeGlobalShortcutBackend::DoUnregister() {
78 // Check if the GSD service is available
79 if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(kGsdService))
84 disconnect(interface_, SIGNAL(MediaPlayerKeyPressed(QString,QString)),
85 this, SLOT(GnomeMediaKeyPressed(QString,QString)));
87 interface_->call("ReleaseMediaPlayerKeys", Constants::NAME);
91 void GnomeGlobalShortcutBackend::GnomeMediaKeyPressed(const QString&, const QString& key) {
92 if (key == "Play") manager_->shortcuts()["play_pause"].action->trigger();
93 if (key == "Stop") manager_->shortcuts()["stop"].action->trigger();
94 if (key == "Next") manager_->shortcuts()["next_track"].action->trigger();
95 if (key == "Previous") manager_->shortcuts()["prev_track"].action->trigger();