Add SystrayNotificationBackend (untested yet and still somewhat rudimentary), evolve...
[quassel.git] / src / qtui / mainwin.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef MAINWIN_H_
22 #define MAINWIN_H_
23
24 #include "ui_mainwin.h"
25
26 #include "qtui.h"
27 #include "titlesetter.h"
28 #include "sessionsettings.h"
29
30 #include <QPixmap>
31 #include <QSystemTrayIcon>
32 #include <QTimer>
33
34 class ActionCollection;
35 class Buffer;
36 class BufferViewConfig;
37 class MsgProcessorStatusWidget;
38 class Message;
39 class NickListWidget;
40 class SystemTrayIcon;
41
42 #ifdef HAVE_DBUS
43 #  include "desktopnotifications.h"
44 #endif
45
46 //!\brief The main window of Quassel's QtUi.
47 class MainWin : public QMainWindow {
48   Q_OBJECT
49
50   public:
51     MainWin(QWidget *parent = 0);
52     virtual ~MainWin();
53
54     void init();
55
56     void addBufferView(BufferViewConfig *config = 0);
57
58     void displayTrayIconMessage(const QString &title, const QString &message);
59     inline QSystemTrayIcon *systemTrayIcon() const;
60
61 #ifdef HAVE_DBUS
62     void sendDesktopNotification(const QString &title, const QString &message);
63 #endif
64
65     virtual bool event(QEvent *event);
66   public slots:
67     void setTrayIconActivity(bool active = false);
68     void saveStateToSession(const QString &sessionId);
69     void saveStateToSessionSettings(SessionSettings &s);
70
71   protected:
72     void closeEvent(QCloseEvent *event);
73     virtual void changeEvent(QEvent *event);
74
75   protected slots:
76     void connectedToCore();
77     void setConnectedState();
78     void updateLagIndicator(int lag);
79     void securedConnection();
80     void disconnectedFromCore();
81     void setDisconnectedState();
82     void systrayActivated(QSystemTrayIcon::ActivationReason);
83
84   private slots:
85     void addBufferView(int bufferViewConfigId);
86     void removeBufferView(int bufferViewConfigId);
87     void messagesInserted(const QModelIndex &parent, int start, int end);
88     void showChannelList(NetworkId netId = NetworkId());
89     void showCoreInfoDlg();
90     void showSettingsDlg();
91     void on_actionEditNetworks_triggered();
92     void on_actionManageViews_triggered();
93     void on_actionLockDockPositions_toggled(bool lock);
94     void showAboutDlg();
95     void on_actionDebugNetworkModel_triggered(bool);
96
97     void showCoreConnectionDlg(bool autoConnect = false);
98
99     void clientNetworkCreated(NetworkId);
100     void clientNetworkRemoved(NetworkId);
101     void clientNetworkUpdated();
102     void connectOrDisconnectFromNet();
103
104     void makeTrayIconBlink();
105     void saveStatusBarStatus(bool enabled);
106
107     void loadLayout();
108     void saveLayout();
109
110 #ifdef HAVE_DBUS
111     void desktopNotificationClosed(uint id, uint reason);
112     void desktopNotificationInvoked(uint id, const QString & action);
113 #endif
114
115   signals:
116     void connectToCore(const QVariantMap &connInfo);
117     void disconnectFromCore();
118
119   private:
120     Ui::MainWin ui;
121
122     QMenu *systrayMenu;
123     QLabel *coreLagLabel;
124     QLabel *sslLabel;
125     MsgProcessorStatusWidget *msgProcessorStatusWidget;
126
127     TitleSetter _titleSetter;
128
129     void setupActions();
130     void setupMenus();
131     void setupViews();
132     void setupNickWidget();
133     void setupChatMonitor();
134     void setupInputWidget();
135     void setupTopicWidget();
136     void setupStatusBar();
137     void setupSystray();
138
139     void toggleVisibility();
140     void enableMenus();
141
142     QSystemTrayIcon *_trayIcon;
143     QPixmap activeTrayIcon;
144     QPixmap onlineTrayIcon;
145     QPixmap offlineTrayIcon;
146     bool trayIconActive;
147     QTimer *timer;
148
149     BufferId currentBuffer;
150     QString currentProfile;
151
152     QList<QDockWidget *> _netViews;
153     NickListWidget *nickListWidget;
154
155     ActionCollection *_actionCollection;
156
157 #ifdef HAVE_DBUS
158     org::freedesktop::Notifications *desktopNotifications;
159     quint32 notificationId;
160 #endif
161
162     friend class QtUi;
163 };
164
165 QSystemTrayIcon *MainWin::systemTrayIcon() const {
166   return _trayIcon;
167 }
168
169 #endif