Continuing my personal crusade against Buffer.
[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
29 #include <QSystemTrayIcon>
30 #include <QTimer>
31
32 class Buffer;
33 class BufferViewConfig;
34 class MsgProcessorStatusWidget;
35 class Message;
36 class NickListWidget;
37
38 #ifdef HAVE_DBUS
39 #  include "desktopnotifications.h"
40 #endif
41
42 //!\brief The main window of Quassel's QtUi.
43 class MainWin : public QMainWindow {
44   Q_OBJECT
45
46 public:
47   MainWin(QWidget *parent = 0);
48   virtual ~MainWin();
49
50   void init();
51   void addBufferView(BufferViewConfig *config = 0);
52
53   void displayTrayIconMessage(const QString &title, const QString &message);
54
55 #ifdef HAVE_DBUS
56   void sendDesktopNotification(const QString &title, const QString &message);
57 #endif
58
59   virtual bool event(QEvent *event);
60
61 public slots:
62   void setTrayIconActivity(bool active = false);
63
64 protected:
65   void closeEvent(QCloseEvent *event);
66   virtual void changeEvent(QEvent *event);
67                                          
68 protected slots:
69   void connectedToCore();
70   void setConnectedState();
71   void updateLagIndicator(int lag);
72   void securedConnection();
73   void disconnectedFromCore();
74   void setDisconnectedState();
75   void systrayActivated( QSystemTrayIcon::ActivationReason );
76                                                             
77 private slots:
78   void addBufferView(int bufferViewConfigId);
79   void removeBufferView(int bufferViewConfigId);
80   void messagesInserted(const QModelIndex &parent, int start, int end);
81   void showChannelList(NetworkId netId = NetworkId());
82   void showCoreInfoDlg();
83   void showSettingsDlg();
84   void on_actionEditNetworks_triggered();
85   void on_actionManageViews_triggered();
86   void on_actionLockDockPositions_toggled(bool lock);
87   void showAboutDlg();
88   void on_actionDebugNetworkModel_triggered(bool);
89   
90   void showCoreConnectionDlg(bool autoConnect = false);
91   
92   void clientNetworkCreated(NetworkId);
93   void clientNetworkRemoved(NetworkId);
94   void clientNetworkUpdated();
95   void connectOrDisconnectFromNet();
96   
97   void makeTrayIconBlink();
98   void saveStatusBarStatus(bool enabled);
99
100   void loadLayout();
101   void saveLayout();
102   
103 #ifdef HAVE_DBUS
104   void desktopNotificationClosed(uint id, uint reason);
105   void desktopNotificationInvoked(uint id, const QString & action);
106 #endif
107   
108 signals:
109   void connectToCore(const QVariantMap &connInfo);
110   void disconnectFromCore();
111   void requestBacklog(BufferInfo, QVariant, QVariant);
112   
113 private:
114   Ui::MainWin ui;
115   
116   QMenu *systrayMenu;
117   QLabel *coreLagLabel;
118   QLabel *sslLabel;
119   MsgProcessorStatusWidget *msgProcessorStatusWidget;
120   
121   TitleSetter _titleSetter;
122   
123   void setupMenus();
124   void setupViews();
125   void setupNickWidget();
126   void setupChatMonitor();
127   void setupInputWidget();
128   void setupTopicWidget();
129   void setupStatusBar();
130   void setupSystray();
131   
132   void toggleVisibility();
133   
134   void enableMenus();
135   
136   QSystemTrayIcon *systray;
137   QIcon activeTrayIcon;
138   QIcon onlineTrayIcon;
139   QIcon offlineTrayIcon;
140   bool trayIconActive;
141   QTimer *timer;
142
143   BufferId currentBuffer;
144   QString currentProfile;
145   
146   QList<QDockWidget *> _netViews;
147   NickListWidget *nickListWidget;
148   
149 #ifdef HAVE_DBUS
150   org::freedesktop::Notifications *desktopNotifications;
151   quint32 notificationId;
152 #endif
153   
154   friend class QtUi;
155 };
156
157 #endif