Save mainwindow state without segfaulting occasionally...
[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
28 #include <QSystemTrayIcon>
29 #include <QTimer>
30
31 class ServerListDlg;
32 class CoreConnectDlg;
33 class Buffer;
34 class BufferViewConfig;
35 class SettingsDlg;
36 class QtUi;
37 class Message;
38 class NickListWidget;
39 class DebugConsole;
40
41
42 //!\brief The main window of Quassel's QtUi.
43 class MainWin : public QMainWindow {
44   Q_OBJECT
45
46   public:
47     MainWin(QtUi *gui, QWidget *parent = 0);
48     virtual ~MainWin();
49
50     void init();
51     void addBufferView(BufferViewConfig *config = 0);
52
53     AbstractUiMsg *layoutMsg(const Message &);
54     void displayTrayIconMessage(const QString &title, const QString &message);
55
56     virtual bool event(QEvent *event);
57
58   public slots:
59     void setTrayIconActivity(bool active = false);
60
61   protected:
62     void closeEvent(QCloseEvent *event);
63     virtual void changeEvent(QEvent *event);
64
65   protected slots:
66     void connectedToCore();
67     void setConnectedState();
68     void securedConnection();
69     void disconnectedFromCore();
70     void setDisconnectedState();
71     void systrayActivated( QSystemTrayIcon::ActivationReason );
72
73   private slots:
74     void addBufferView(int bufferViewConfigId);
75     void removeBufferView(int bufferViewConfigId);
76     void receiveMessage(const Message &msg);
77     void showSettingsDlg();
78     void showNetworkDlg();
79     void showManageViewsDlg();
80     void showAboutDlg();
81     void showDebugConsole();
82
83     void showCoreConnectionDlg(bool autoConnect = false);
84     void coreConnectionDlgFinished(int result);
85
86     void clientNetworkCreated(NetworkId);
87     void clientNetworkRemoved(NetworkId);
88     void clientNetworkUpdated();
89     void connectOrDisconnectFromNet();
90
91     void changeTopic(const QString &topic);
92     void makeTrayIconBlink();
93     void saveStatusBarStatus(bool enabled);
94
95     void loadLayout();
96     void saveLayout();
97   
98   signals:
99     void connectToCore(const QVariantMap &connInfo);
100     void disconnectFromCore();
101     void requestBacklog(BufferInfo, QVariant, QVariant);
102
103   private:
104     Ui::MainWin ui;
105     QtUi *gui;
106
107     QMenu *systrayMenu;
108     QLabel *sslLabel;
109
110     void setupMenus();
111     void setupViews();
112     void setupNickWidget();
113     void setupChatMonitor();
114     void setupInputWidget();
115     void setupTopicWidget();
116     void setupStatusBar();
117     void setupSystray();
118
119     void setupSettingsDlg();
120
121     void toggleVisibility();
122
123     void enableMenus();
124
125     QSystemTrayIcon *systray;
126     QIcon activeTrayIcon;
127     QIcon onlineTrayIcon;
128     QIcon offlineTrayIcon;
129     bool trayIconActive;
130     QTimer *timer;
131
132     CoreConnectDlg *coreConnectDlg;
133     SettingsDlg *settingsDlg;
134     DebugConsole *debugConsole;
135
136     BufferId currentBuffer;
137     QString currentProfile;
138
139     QList<QDockWidget *> _netViews;
140     NickListWidget *nickListWidget;
141
142     QAction *actionEditNetworks;
143     QList<QAction *> networkActions;
144
145     friend class QtUi;
146 };
147
148 #endif