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