QT += network \
xml \
phonon
+unix:!mac {
+ QT += dbus
+}
include(src/qtsingleapplication/qtsingleapplication.pri)
HEADERS += src/MainWindow.h \
src/SearchView.h \
src/flickcharm.h \
src/videodefinition.h \
src/fontutils.h \
- src/thlibrary/thblackbar.h
+ src/thlibrary/thblackbar.h \
+ src/gnomeglobalshortcutbackend.h \
+ src/globalshortcuts.h \
+ src/globalshortcutbackend.h
SOURCES += src/main.cpp \
src/MainWindow.cpp \
src/SearchView.cpp \
src/videodefinition.cpp \
src/constants.cpp \
src/fontutils.cpp \
- src/thlibrary/thblackbar.cpp
+ src/thlibrary/thblackbar.cpp \
+ src/gnomeglobalshortcutbackend.cpp \
+ src/globalshortcuts.cpp \
+ src/globalshortcutbackend.cpp
RESOURCES += resources.qrc
DESTDIR = build/target/
OBJECTS_DIR = build/obj/
#include "global.h"
#include "videodefinition.h"
#include "fontutils.h"
+#include "globalshortcuts.h"
+#ifdef Q_WS_X11
+#include "gnomeglobalshortcutbackend.h"
+#endif
+#ifdef APP_MAC
+#include "local/mac/mac_startup.h"
+#endif
MainWindow::MainWindow() :
aboutView(0),
showWidget(searchView);
setCentralWidget(views);
+
+ // Global shortcuts
+ GlobalShortcuts &shortcuts = GlobalShortcuts::instance();
+#ifdef Q_WS_X11
+ if (GnomeGlobalShortcutBackend::IsGsdAvailable())
+ shortcuts.setBackend(new GnomeGlobalShortcutBackend(&shortcuts));
+#endif
+#ifdef APP_MAC
+ mac::MacSetup();
+#endif
+ connect(&shortcuts, SIGNAL(PlayPause()), pauseAct, SLOT(trigger()));
+ connect(&shortcuts, SIGNAL(Stop()), this, SLOT(stop()));
+ connect(&shortcuts, SIGNAL(Next()), skipAct, SLOT(trigger()));
}
MainWindow::~MainWindow() {
#include <phonon/videowidget.h>
#include "View.h"
#include "ListModel.h"
-#include "thblackbar.h"
+#include "thlibrary/thblackbar.h"
#include "searchparams.h"
#include "playlistwidget.h"
#include "loadingwidget.h"
--- /dev/null
+#include "globalshortcutbackend.h"
+#include "globalshortcuts.h"
+
+GlobalShortcutBackend::GlobalShortcutBackend(GlobalShortcuts *parent)
+ : QObject(parent),
+ manager_(parent),
+ active_(false) { }
+
+bool GlobalShortcutBackend::Register() {
+ bool ret = DoRegister();
+ if (ret)
+ active_ = true;
+ return ret;
+}
+
+void GlobalShortcutBackend::Unregister() {
+ DoUnregister();
+ active_ = false;
+}
+
+void GlobalShortcutBackend::Reregister() {
+ Unregister();
+ Register();
+}
--- /dev/null
+#ifndef GLOBALSHORTCUTBACKEND_H
+#define GLOBALSHORTCUTBACKEND_H
+
+#include <QObject>
+
+class GlobalShortcuts;
+
+class GlobalShortcutBackend : public QObject {
+public:
+ GlobalShortcutBackend(GlobalShortcuts* parent = 0);
+ virtual ~GlobalShortcutBackend() {}
+
+ bool is_active() const { return active_; }
+
+ bool Register();
+ void Unregister();
+ void Reregister();
+
+protected:
+ virtual bool DoRegister() = 0;
+ virtual void DoUnregister() = 0;
+
+ GlobalShortcuts* manager_;
+ bool active_;
+};
+
+#endif // GLOBALSHORTCUTBACKEND_H
--- /dev/null
+#include "globalshortcuts.h"
+#include "globalshortcutbackend.h"
+
+static GlobalShortcuts *singleton = 0;
+
+GlobalShortcuts& GlobalShortcuts::instance() {
+ if (!singleton) singleton = new GlobalShortcuts();
+ return *singleton;
+}
+
+GlobalShortcuts::GlobalShortcuts(QObject *parent)
+ : QObject(parent),
+ backend(0) {
+
+ // Create actions
+ AddShortcut("play", tr("Play"), SIGNAL(Play()));
+ AddShortcut("pause", tr("Pause"), SIGNAL(Pause()));
+ AddShortcut("play_pause", tr("Play/Pause"), SIGNAL(PlayPause()), QKeySequence(Qt::Key_MediaPlay));
+ AddShortcut("stop", tr("Stop"), SIGNAL(Stop()), QKeySequence(Qt::Key_MediaStop));
+ AddShortcut("stop_after", tr("Stop playing after current track"), SIGNAL(StopAfter()));
+ AddShortcut("next_track", tr("Next track"), SIGNAL(Next()), QKeySequence(Qt::Key_MediaNext));
+ AddShortcut("prev_track", tr("Previous track"), SIGNAL(Previous()), QKeySequence(Qt::Key_MediaPrevious));
+ AddShortcut("inc_volume", tr("Increase volume"), SIGNAL(IncVolume()));
+ AddShortcut("dec_volume", tr("Decrease volume"), SIGNAL(DecVolume()));
+ AddShortcut("mute", tr("Mute"), SIGNAL(Mute()));
+ AddShortcut("seek_forward", tr("Seek forward"), SIGNAL(SeekForward()));
+ AddShortcut("seek_backward", tr("Seek backward"), SIGNAL(SeekBackward()));
+
+}
+
+void GlobalShortcuts::AddShortcut(const QString &id, const QString &name,
+ const char* signal,
+ const QKeySequence &default_key) {
+ Shortcut shortcut;
+ shortcut.action = new QAction(name, this);
+ shortcut.action->setShortcut(default_key);
+ shortcut.id = id;
+ shortcut.default_key = default_key;
+
+ connect(shortcut.action, SIGNAL(triggered()), this, signal);
+
+ shortcuts_[id] = shortcut;
+}
+
+void GlobalShortcuts::reload() {
+ if (backend) {
+ backend->Unregister();
+ backend->Register();
+ }
+}
--- /dev/null
+#ifndef GLOBALSHORTCUTS_H
+#define GLOBALSHORTCUTS_H
+
+#include <QtCore>
+#include <QAction>
+
+class GlobalShortcutBackend;
+
+class GlobalShortcuts : public QObject {
+
+ Q_OBJECT
+
+public:
+ static GlobalShortcuts& instance();
+
+ struct Shortcut {
+ QString id;
+ QKeySequence default_key;
+ QAction* action;
+ };
+
+ QMap<QString, Shortcut> shortcuts() const { return shortcuts_; }
+ void setBackend(GlobalShortcutBackend* backend) {
+ this->backend = backend;
+ reload();
+ }
+
+public slots:
+ void reload();
+
+signals:
+ void Play();
+ void Pause();
+ void PlayPause();
+ void Stop();
+ void StopAfter();
+ void Next();
+ void Previous();
+ void IncVolume();
+ void DecVolume();
+ void Mute();
+ void SeekForward();
+ void SeekBackward();
+
+private:
+ GlobalShortcuts(QObject* parent = 0);
+ void AddShortcut(const QString& id, const QString& name, const char* signal,
+ const QKeySequence& default_key = QKeySequence(0));
+
+private:
+ GlobalShortcutBackend* backend;
+
+ QMap<QString, Shortcut> shortcuts_;
+};
+
+#endif
--- /dev/null
+#include "gnomeglobalshortcutbackend.h"
+#include "globalshortcuts.h"
+
+#include <QAction>
+#include <QtDebug>
+
+#ifdef QT_DBUS_LIB
+# include <QtDBus>
+#endif
+
+const char* GnomeGlobalShortcutBackend::kGsdService = "org.gnome.SettingsDaemon";
+const char* GnomeGlobalShortcutBackend::kGsdPath = "/org/gnome/SettingsDaemon/MediaKeys";
+const char* GnomeGlobalShortcutBackend::kGsdInterface = "org.gnome.SettingsDaemon.MediaKeys";
+
+GnomeGlobalShortcutBackend::GnomeGlobalShortcutBackend(GlobalShortcuts* parent)
+ : GlobalShortcutBackend(parent),
+ interface_(NULL) { }
+
+bool GnomeGlobalShortcutBackend::IsGsdAvailable() {
+#ifdef QT_DBUS_LIB
+ return QDBusConnection::sessionBus().interface()->isServiceRegistered(
+ GnomeGlobalShortcutBackend::kGsdService);
+#else // QT_DBUS_LIB
+ return false;
+#endif
+}
+
+bool GnomeGlobalShortcutBackend::DoRegister() {
+ // qDebug() << __PRETTY_FUNCTION__;
+#ifdef QT_DBUS_LIB
+ // Check if the GSD service is available
+ if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(kGsdService))
+ return false;
+
+ if (!interface_) {
+ interface_ = new QDBusInterface(
+ kGsdService, kGsdPath, kGsdInterface, QDBusConnection::sessionBus(), this);
+ }
+
+ connect(interface_, SIGNAL(MediaPlayerKeyPressed(QString,QString)),
+ this, SLOT(GnomeMediaKeyPressed(QString,QString)));
+
+ return true;
+#else // QT_DBUS_LIB
+ return false;
+#endif
+}
+
+void GnomeGlobalShortcutBackend::DoUnregister() {
+
+#ifdef QT_DBUS_LIB
+ // Check if the GSD service is available
+ if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(kGsdService))
+ return;
+ if (!interface_)
+ return;
+
+ disconnect(interface_, SIGNAL(MediaPlayerKeyPressed(QString,QString)),
+ this, SLOT(GnomeMediaKeyPressed(QString,QString)));
+#endif
+}
+
+void GnomeGlobalShortcutBackend::GnomeMediaKeyPressed(const QString&, const QString& key) {
+ if (key == "Play") manager_->shortcuts()["play_pause"].action->trigger();
+ if (key == "Stop") manager_->shortcuts()["stop"].action->trigger();
+ if (key == "Next") manager_->shortcuts()["next_track"].action->trigger();
+ if (key == "Previous") manager_->shortcuts()["prev_track"].action->trigger();
+}
--- /dev/null
+#ifndef GNOMEGLOBALSHORTCUTBACKEND_H
+#define GNOMEGLOBALSHORTCUTBACKEND_H
+
+#include "globalshortcutbackend.h"
+
+class QDBusInterface;
+
+class GnomeGlobalShortcutBackend : public GlobalShortcutBackend {
+ Q_OBJECT
+
+public:
+ GnomeGlobalShortcutBackend(GlobalShortcuts* parent);
+ static bool IsGsdAvailable();
+ static const char* kGsdService;
+ static const char* kGsdPath;
+ static const char* kGsdInterface;
+
+protected:
+ bool DoRegister();
+ void DoUnregister();
+
+private slots:
+ void GnomeMediaKeyPressed(const QString& application, const QString& key);
+
+private:
+ QDBusInterface* interface_;
+};
+
+#endif // GNOMEGLOBALSHORTCUTBACKEND_H
#include <qtsingleapplication.h>
#include "constants.h"
#include "MainWindow.h"
+#ifdef APP_MAC
+#include "local/mac/mac_startup.h"
+#endif
int main(int argc, char **argv) {
+#ifdef APP_MAC
+ mac::MacMain();
+#endif
+
QtSingleApplication app(argc, argv);
if (app.sendMessage("Wake up!"))
return 0;
#define PLAYLISTWIDGET_H
#include <QtGui>
-#include "thblackbar.h"
+#include "thlibrary/thblackbar.h"
class PlaylistWidget : public QWidget
{