2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-03-21 20:02:56 +01:00
|
|
|
#include "globalshortcuts.h"
|
|
|
|
#include "qxtglobalshortcut.h"
|
|
|
|
|
2010-04-13 15:55:54 +02:00
|
|
|
#include "mac_startup.h"
|
|
|
|
|
2010-03-25 23:37:00 +01:00
|
|
|
#include <QtDebug>
|
|
|
|
|
2010-03-22 00:19:56 +01:00
|
|
|
#ifdef QT_DBUS_LIB
|
|
|
|
# include <QtDBus>
|
|
|
|
#endif
|
2010-03-21 20:02:56 +01:00
|
|
|
|
|
|
|
const char* GlobalShortcuts::kGsdService = "org.gnome.SettingsDaemon";
|
|
|
|
const char* GlobalShortcuts::kGsdPath = "/org/gnome/SettingsDaemon/MediaKeys";
|
|
|
|
const char* GlobalShortcuts::kGsdInterface = "org.gnome.SettingsDaemon.MediaKeys";
|
|
|
|
|
|
|
|
GlobalShortcuts::GlobalShortcuts(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlobalShortcuts::Init() {
|
2010-04-13 15:55:54 +02:00
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
mac::SetShortcutHandler(this);
|
|
|
|
return;
|
|
|
|
#endif
|
2010-03-21 20:02:56 +01:00
|
|
|
if (RegisterGnome()) return;
|
2010-03-25 23:37:00 +01:00
|
|
|
if (RegisterQxt()) return;
|
2010-03-21 20:02:56 +01:00
|
|
|
}
|
|
|
|
|
2010-05-17 02:31:39 +02:00
|
|
|
bool GlobalShortcuts::IsGsdAvailable() const {
|
|
|
|
#ifdef QT_DBUS_LIB
|
|
|
|
return QDBusConnection::sessionBus().interface()->isServiceRegistered(kGsdService);
|
|
|
|
#else // QT_DBUS_LIB
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-03-21 20:02:56 +01:00
|
|
|
bool GlobalShortcuts::RegisterGnome() {
|
2010-03-22 00:19:56 +01:00
|
|
|
#ifdef QT_DBUS_LIB
|
2010-03-21 20:02:56 +01:00
|
|
|
// Check if the GSD service is available
|
|
|
|
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(kGsdService))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QDBusInterface* interface = new QDBusInterface(
|
|
|
|
kGsdService, kGsdPath, kGsdInterface, QDBusConnection::sessionBus(), this);
|
|
|
|
|
|
|
|
connect(interface, SIGNAL(MediaPlayerKeyPressed(QString,QString)),
|
|
|
|
this, SLOT(GnomeMediaKeyPressed(QString,QString)));
|
|
|
|
|
|
|
|
return true;
|
2010-03-22 00:19:56 +01:00
|
|
|
#else // QT_DBUS_LIB
|
|
|
|
return false;
|
|
|
|
#endif
|
2010-03-21 20:02:56 +01:00
|
|
|
}
|
|
|
|
|
2010-03-25 23:37:00 +01:00
|
|
|
bool GlobalShortcuts::RegisterQxt() {
|
2010-04-12 14:36:30 +02:00
|
|
|
#ifndef Q_OS_DARWIN
|
2010-03-21 20:02:56 +01:00
|
|
|
QxtGlobalShortcut* play_pause = new QxtGlobalShortcut(QKeySequence("Media Play"), this);
|
|
|
|
QxtGlobalShortcut* stop = new QxtGlobalShortcut(QKeySequence("Media Stop"), this);
|
|
|
|
QxtGlobalShortcut* next = new QxtGlobalShortcut(QKeySequence("Media Next"), this);
|
|
|
|
QxtGlobalShortcut* prev = new QxtGlobalShortcut(QKeySequence("Media Previous"), this);
|
|
|
|
|
|
|
|
connect(play_pause, SIGNAL(activated()), SIGNAL(PlayPause()));
|
|
|
|
connect(stop, SIGNAL(activated()), SIGNAL(Stop()));
|
|
|
|
connect(next, SIGNAL(activated()), SIGNAL(Next()));
|
|
|
|
connect(prev, SIGNAL(activated()), SIGNAL(Previous()));
|
2010-04-12 14:36:30 +02:00
|
|
|
#endif
|
2010-03-22 00:19:56 +01:00
|
|
|
|
|
|
|
return true;
|
2010-03-21 20:02:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GlobalShortcuts::GnomeMediaKeyPressed(const QString&, const QString& key) {
|
|
|
|
if (key == "Play") emit PlayPause();
|
|
|
|
if (key == "Stop") emit Stop();
|
|
|
|
if (key == "Next") emit Next();
|
|
|
|
if (key == "Previous") emit Previous();
|
|
|
|
}
|
2010-04-13 15:55:54 +02:00
|
|
|
|
|
|
|
void GlobalShortcuts::MacMediaKeyPressed(const QString& key) {
|
|
|
|
if (key == "Play") emit PlayPause();
|
|
|
|
// Stop doesn't exist on a mac keyboard.
|
|
|
|
if (key == "Next") emit Next();
|
|
|
|
if (key == "Previous") emit Previous();
|
|
|
|
}
|