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