1 /***************************************************************************
2 *                                                                         *
3 *   This program is free software; you can redistribute it and/or modify  *
4 *   it under the terms of the GNU General Public License as published by  *
5 *   the Free Software Foundation; either version 3 of the License, or     *
6 *   (at your option) any later version.                                   *
7 *                                                                         *
8 ***************************************************************************/
9 
10 #pragma once
11 
12 #include <QObject>
13 #include <QSystemTrayIcon>
14 #ifdef DBUS_NOTIFY
15 #include <QtDBus>
16 #endif
17 #include <QTimer>
18 #include "dcpp/stdinc.h"
19 #include "dcpp/Singleton.h"
20 
21 #include "WulforUtil.h"
22 
23 class NotifyModule {
24 public:
25     virtual void showMessage(const QString &, const QString &, QObject *) = 0;
~NotifyModule()26     virtual ~NotifyModule() { }
27 };
28 
29 class QtNotifyModule: public NotifyModule {
30 public:
31     void showMessage(const QString &title, const QString &msg, QObject *obj);
32 };
33 #ifdef DBUS_NOTIFY
34 class DBusNotifyModule: public NotifyModule {
35 public:
36     void showMessage(const QString &title, const QString &msg, QObject *);
37 };
38 #endif
39 class Notification :
40         public QObject,
41         public dcpp::Singleton<Notification>
42 {
43 Q_OBJECT
44 friend class dcpp::Singleton<Notification>;
45 
46 public:
47 
48 enum Module{
49     QtNotify=0,
50     DBusNotify
51 };
52 
53 enum Type{
54     NICKSAY=1,
55     PM=2,
56     TRANSFER=4,
57     FAVORITE=8,
58     ANY=16
59 };
60 
61     void enableTray(bool);
62     void setToolTip(const QString &, const QString &, const QString &, const QString &);
63     void reloadSounds();
64     void resetTrayIcon();
65 
66     void setSuppressTxt(bool suppressTxt_ = false) { suppressTxt = suppressTxt_; }
67     void setSuppressSnd(bool suppressSnd_ = false) { suppressSnd = suppressSnd_; }
68 
69 
70 public Q_SLOTS:
71     void switchModule(int);
72     void showMessage(int t, const QString&, const QString&);
73 
74     void slotShowHide();
75     void slotShowSpeedLimits();
76 
77 private Q_SLOTS:
78     void slotExit();
79     void slotTrayMenuTriggered(QSystemTrayIcon::ActivationReason);
80     void slotCmdFinished(bool, QString);
81     void slotCheckTray();
82     void slotSuppressTxt();
83     void slotSuppressSnd();
84 
85 private:
86     explicit Notification(QObject *parent = 0);
87     virtual ~Notification();
88 
89     QStringList sounds;
90 
91     QSystemTrayIcon *tray;
92     NotifyModule *notify;
93 
94     bool suppressSnd;
95     bool suppressTxt;
96 
97     int checkSystemTrayCounter;
98 };
99 
100 #define Notify Notification::getInstance()
101 
102 Q_DECLARE_METATYPE(Notification*)
103 Q_DECLARE_METATYPE(Notification::Type)
104