1 /* 2 * Strawberry Music Player 3 * This file was part of Clementine. 4 * Copyright 2010, David Sansome <me@davidsansome.com> 5 * Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net> 6 * 7 * Strawberry is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * Strawberry is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with Strawberry. If not, see <http://www.gnu.org/licenses/>. 19 * 20 */ 21 22 #ifndef GLOBALSHORTCUTSMANAGER_H 23 #define GLOBALSHORTCUTSMANAGER_H 24 25 #include "config.h" 26 27 #include <functional> 28 29 #include <QObject> 30 #include <QWidget> 31 #include <QList> 32 #include <QMap> 33 #include <QString> 34 #include <QKeySequence> 35 #include <QSettings> 36 37 #include "globalshortcutsbackend.h" 38 39 class QShortcut; 40 class QAction; 41 42 class GlobalShortcutsManager : public QWidget { 43 Q_OBJECT 44 45 public: 46 explicit GlobalShortcutsManager(QWidget *parent = nullptr); 47 48 struct Shortcut { 49 QString id; 50 QKeySequence default_key; 51 QAction *action; 52 QShortcut *shortcut; 53 }; 54 shortcuts()55 QMap<QString, Shortcut> shortcuts() const { return shortcuts_; } 56 57 #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && defined(HAVE_DBUS) 58 static bool IsKdeAvailable(); 59 static bool IsGnomeAvailable(); 60 static bool IsMateAvailable(); 61 #endif // defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) && defined(HAVE_DBUS) 62 63 #ifdef HAVE_X11_GLOBALSHORTCUTS 64 static bool IsX11Available(); 65 #endif // HAVE_X11_GLOBALSHORTCUTS 66 67 #ifdef Q_OS_MACOS 68 static bool IsMacAccessibilityEnabled(); 69 #endif // Q_OS_MACOS 70 71 bool Register(); 72 void Unregister(); 73 74 public slots: 75 void ReloadSettings(); 76 void ShowMacAccessibilityDialog(); 77 78 signals: 79 void Play(); 80 void Pause(); 81 void PlayPause(); 82 void Stop(); 83 void StopAfter(); 84 void Next(); 85 void Previous(); 86 void IncVolume(); 87 void DecVolume(); 88 void Mute(); 89 void SeekForward(); 90 void SeekBackward(); 91 void ShowHide(); 92 void ShowOSD(); 93 void TogglePrettyOSD(); 94 void CycleShuffleMode(); 95 void CycleRepeatMode(); 96 void RemoveCurrentSong(); 97 void ToggleScrobbling(); 98 void Love(); 99 100 private: 101 void AddShortcut(const QString &id, const QString &name, std::function<void()> signal, const QKeySequence &default_key = QKeySequence(0)); 102 Shortcut AddShortcut(const QString &id, const QString &name, const QKeySequence &default_key); 103 104 private: 105 QList<GlobalShortcutsBackend*> backends_; 106 QSettings settings_; 107 QList<GlobalShortcutsBackend::Type> backends_enabled_; 108 QMap<QString, Shortcut> shortcuts_; 109 }; 110 111 #endif // GLOBALSHORTCUTSMANAGER_H 112