1 /* This file is part of Clementine.
2    Copyright 2010, David Sansome <me@davidsansome.com>
3 
4    Clementine is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8 
9    Clementine is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with Clementine.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef OSD_H
19 #define OSD_H
20 
21 #include <memory>
22 
23 #include <QDateTime>
24 #include <QImage>
25 #include <QObject>
26 
27 #include "config.h"
28 #include "engines/engine_fwd.h"
29 #include "core/song.h"
30 #include "playlist/playlistsequence.h"
31 
32 class Application;
33 class OrgFreedesktopNotificationsInterface;
34 class OSDPretty;
35 class SystemTrayIcon;
36 
37 class QDBusPendingCallWatcher;
38 
39 #ifdef HAVE_DBUS
40 #include <QDBusArgument>
41 #include <QDBusPendingCall>
42 
43 QDBusArgument& operator<<(QDBusArgument& arg, const QImage& image);
44 const QDBusArgument& operator>>(const QDBusArgument& arg, QImage& image);
45 #endif
46 
47 class OSD : public QObject {
48   Q_OBJECT
49 
50  public:
51   OSD(SystemTrayIcon* tray_icon, Application* app, QObject* parent = nullptr);
52   ~OSD();
53 
54   static const char* kSettingsGroup;
55 
56   enum Behaviour {
57     Disabled = 0,
58     Native,
59     TrayPopup,
60     Pretty,
61   };
62 
63   // Implemented in the OS-specific files
64   static bool SupportsNativeNotifications();
65   static bool SupportsTrayPopups();
66 
67   void ReloadPrettyOSDSettings();
68 
69   void SetPrettyOSDToggleMode(bool toggle);
70 
71  public slots:
72   void ReloadSettings();
73 
74   void Paused();
75   void Stopped();
76   void StopAfterToggle(bool stop);
77   void PlaylistFinished();
78   void VolumeChanged(int value);
79   void MagnatuneDownloadFinished(const QStringList& albums);
80   void RepeatModeChanged(PlaylistSequence::RepeatMode mode);
81   void ShuffleModeChanged(PlaylistSequence::ShuffleMode mode);
82 
83   void ReshowCurrentSong();
84 
85   void WiiremoteActived(int id);
86   void WiiremoteDeactived(int id);
87   void WiiremoteConnected(int id);
88   void WiiremoteDisconnected(int id);
89   void WiiremoteLowBattery(int id, int live);
90   void WiiremoteCriticalBattery(int id, int live);
91 
92   void ShowPreview(const Behaviour type, const QString& line1,
93                    const QString& line2, const Song& song);
94 
95  private:
96   void ShowMessage(const QString& summary, const QString& message = QString(),
97                    const QString& icon = QString(),
98                    const QImage& image = QImage());
99 
100   // These are implemented in the OS-specific files
101   void Init();
102   void ShowMessageNative(const QString& summary, const QString& message,
103                          const QString& icon = QString(),
104                          const QImage& image = QImage());
105   QString ReplaceVariable(const QString& variable, const Song& song);
106 
107  private slots:
108 #if defined(HAVE_DBUS)
109   void CallFinished(QDBusPendingCallWatcher* watcher);
110 #endif
111   void AlbumArtLoaded(const Song& song, const QString& uri,
112                       const QImage& image);
113 
114  private:
115   SystemTrayIcon* tray_icon_;
116   Application* app_;
117   int timeout_msec_;
118   Behaviour behaviour_;
119   bool show_on_volume_change_;
120   bool show_art_;
121   bool show_on_play_mode_change_;
122   bool show_on_pause_;
123   bool use_custom_text_;
124   QString custom_text1_;
125   QString custom_text2_;
126   bool preview_mode_;
127 
128   bool force_show_next_;
129   bool ignore_next_stopped_;
130 
131   OSDPretty* pretty_popup_;
132 
133   Song last_song_;
134   QString last_image_uri_;
135   QImage last_image_;
136 
137 #ifdef HAVE_DBUS
138   std::unique_ptr<OrgFreedesktopNotificationsInterface> interface_;
139   uint notification_id_;
140   QDateTime last_notification_time_;
141 #endif
142 };
143 
144 #endif  // OSD_H
145