1 /* This file is part of Clementine.
2    Copyright 2010, David Sansome <davidsansome@gmail.com>
3    Copyright 2010, 2014, John Maguire <john.maguire@gmail.com>
4    Copyright 2010, Paweł Bara <keirangtp@gmail.com>
5    Copyright 2011, Andrea Decorte <adecorte@gmail.com>
6    Copyright 2013, Alexander Bikadorov <abiku@cs.tu-berlin.de>
7    Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
8 
9    Clementine is free software: you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation, either version 3 of the License, or
12    (at your option) any later version.
13 
14    Clementine is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with Clementine.  If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #ifndef CORE_GLOBALSHORTCUTS_H_
24 #define CORE_GLOBALSHORTCUTS_H_
25 
26 #include <QKeySequence>
27 #include <QMap>
28 #include <QSettings>
29 #include <QWidget>
30 
31 class QAction;
32 class QShortcut;
33 
34 class GlobalShortcutBackend;
35 
36 class GlobalShortcuts : public QWidget {
37   Q_OBJECT
38 
39  public:
40   explicit GlobalShortcuts(QWidget* parent = nullptr);
41 
42   static const char* kSettingsGroup;
43 
44   struct Shortcut {
45     QString id;
46     QKeySequence default_key;
47     QAction* action;
48     QShortcut* shortcut;
49   };
50 
shortcuts()51   QMap<QString, Shortcut> shortcuts() const { return shortcuts_; }
52   bool IsGsdAvailable() const;
53   bool IsMacAccessibilityEnabled() const;
54 
55  public slots:
56   void ReloadSettings();
57   void ShowMacAccessibilityDialog();
58 
59   void Unregister();
60   void Register();
61 
62 signals:
63   void Play();
64   void Pause();
65   void PlayPause();
66   void Stop();
67   void StopAfter();
68   void Next();
69   void Previous();
70   void IncVolume();
71   void DecVolume();
72   void Mute();
73   void SeekForward();
74   void SeekBackward();
75   void ShowHide();
76   void ShowOSD();
77   void TogglePrettyOSD();
78   void RateCurrentSong(int);
79   void CycleShuffleMode();
80   void CycleRepeatMode();
81   void ToggleScrobbling();
82   void Love();
83   void Ban();
84   void RemoveCurrentSong();
85 
86  private:
87   void AddShortcut(const QString& id, const QString& name, const char* signal,
88                    const QKeySequence& default_key = QKeySequence(0));
89   void AddRatingShortcut(const QString& id, const QString& name, int rating,
90                          const QKeySequence& default_key = QKeySequence(0));
91   Shortcut AddShortcut(const QString& id, const QString& name,
92                        const QKeySequence& default_key);
93 
94  private:
95   GlobalShortcutBackend* gnome_backend_;
96   GlobalShortcutBackend* kglobalaccel_backend_;
97   GlobalShortcutBackend* system_backend_;
98 
99   QMap<QString, Shortcut> shortcuts_;
100   QSettings settings_;
101 
102   bool use_gnome_;
103   bool have_kglobalaccel_;
104 };
105 
106 #endif  // CORE_GLOBALSHORTCUTS_H_
107