1 /***************************************************************************
2 * Copyright (C) 2005-07 by The Quassel Team *
3 * devel@quassel-irc.org *
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) any later version. *
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. *
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 ***************************************************************************/
23 #include <QSqlDatabase>
29 #include "clientproxy.h"
34 #include "serverlist.h"
35 #include "coreconnectdlg.h"
36 #include "settingsdlg.h"
37 #include "settingspages.h"
39 MainWin::MainWin() : QMainWindow() {
42 //qDebug() << "Available DB drivers: " << QSqlDatabase::drivers ();
43 setWindowTitle("Quassel IRC");
44 //setWindowTitle("Κυασελ Εγαρζη");
45 setWindowIcon(QIcon(":/qirc-icon.png"));
46 setWindowIconText("Quassel IRC");
48 //workspace = new QWorkspace(this);
49 //setCentralWidget(workspace);
50 statusBar()->showMessage(tr("Waiting for core..."));
53 void MainWin::init() {
54 ui.bufferWidget->init();
58 statusBar()->showMessage(tr("Ready."));
59 systray = new QSystemTrayIcon(this);
60 systray->setIcon(QIcon(":/qirc-icon.png"));
63 serverListDlg = new ServerListDlg(this);
64 serverListDlg->setVisible(serverListDlg->showOnStartup());
72 s.beginGroup("Geometry");
73 //resize(s.value("MainWinSize", QSize(500, 400)).toSize());
74 //move(s.value("MainWinPos", QPoint(50, 50)).toPoint());
75 if(s.contains("MainWinState")) restoreState(s.value("MainWinState").toByteArray());
78 s.beginGroup("Buffers");
79 QString net = s.value("CurrentNetwork", "").toString();
80 QString buf = s.value("CurrentBuffer", "").toString();
84 if(buffers.contains(net)) {
85 if(buffers[net].contains(buf)) {
96 //typedef QHash<QString, Buffer*> BufHash;
97 //foreach(BufHash h, buffers.values()) {
98 // foreach(Buffer *b, h.values()) {
102 //foreach(Buffer *buf, buffers.values()) delete buf;
105 /* This is implemented in settingspages.cpp */
107 void MainWin::setupSettingsDlg() {
112 void MainWin::setupMenus() {
113 connect(ui.actionNetworkList, SIGNAL(triggered()), this, SLOT(showServerList()));
114 connect(ui.actionEditIdentities, SIGNAL(triggered()), serverListDlg, SLOT(editIdentities()));
115 connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));
116 //ui.actionSettingsDlg->setEnabled(false);
117 connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
119 connect(ui.actionImportBacklog, SIGNAL(triggered()), this, SLOT(importBacklog()));
120 connect(this, SIGNAL(importOldBacklog()), ClientProxy::instance(), SLOT(gsImportBacklog()));
123 void MainWin::setupViews() {
125 BufferTreeModel *model = Client::bufferModel(); // FIXME Where is the delete for that? :p
126 connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
127 //connect(this, SIGNAL(bufferSelected(Buffer *)), model, SLOT(selectBuffer(Buffer *)));
128 //connect(this, SIGNAL(bufferUpdated(Buffer *)), model, SLOT(bufferUpdated(Buffer *)));
129 //connect(this, SIGNAL(bufferActivity(Buffer::ActivityLevel, Buffer *)), model, SLOT(bufferActivity(Buffer::ActivityLevel, Buffer *)));
131 BufferViewDock *all = new BufferViewDock(model, tr("All Buffers"), BufferViewFilter::AllNets, QStringList(), this);
132 registerBufferViewDock(all);
134 BufferViewDock *allchans = new BufferViewDock(model, tr("All Channels"), BufferViewFilter::AllNets|BufferViewFilter::NoQueries|BufferViewFilter::NoServers, QStringList(), this);
135 registerBufferViewDock(allchans);
137 BufferViewDock *allqrys = new BufferViewDock(model, tr("All Queries"), BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoServers, QStringList(), this);
138 registerBufferViewDock(allqrys);
141 BufferViewDock *allnets = new BufferViewDock(model, tr("All Networks"), BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries, QStringList(), this);
142 registerBufferViewDock(allnets);
144 BufferViewDock *fullCustom = new BufferViewDock(model, tr("Full Custom"), BufferViewFilter::FullCustom|BufferViewFilter::SomeNets, QStringList(), this);
145 registerBufferViewDock(fullCustom);
147 ui.menuViews->addSeparator();
150 void MainWin::registerBufferViewDock(BufferViewDock *dock) {
151 addDockWidget(Qt::LeftDockWidgetArea, dock);
152 dock->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
153 netViews.append(dock);
154 ui.menuViews->addAction(dock->toggleViewAction());
157 connect(this, SIGNAL(bufferSelected(Buffer *)), view, SLOT(selectBuffer(Buffer *)));
158 connect(this, SIGNAL(bufferDestroyed(Buffer *)), view, SLOT(bufferDestroyed(Buffer *)));
159 connect(view, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
160 view->setBuffers(buffers.values());
164 AbstractUiMsg *MainWin::layoutMsg(const Message &msg) {
165 return new ChatLine(msg);
168 void MainWin::showServerList() {
169 // if(!serverListDlg) {
170 // serverListDlg = new ServerListDlg(this);
172 serverListDlg->show();
173 serverListDlg->raise();
176 void MainWin::showSettingsDlg() {
180 void MainWin::closeEvent(QCloseEvent *event)
182 //if (userReallyWantsToQuit()) {
183 ui.bufferWidget->saveState();
185 s.beginGroup("Geometry");
186 s.setValue("MainWinSize", size());
187 s.setValue("MainWinPos", pos());
188 s.setValue("MainWinState", saveState());
190 s.beginGroup("Buffers");
191 //s.setValue("CurrentNetwork", currentNetwork);
192 s.setValue("CurrentBuffer", currentBuffer);
201 void MainWin::showBuffer(BufferId id) {
202 showBuffer(Client::buffer(id));
205 void MainWin::showBuffer(Buffer *b) {
206 currentBuffer = b->bufferId().groupId();
207 //emit bufferSelected(b);
208 //qApp->processEvents();
209 ui.bufferWidget->setBuffer(b);
210 //emit bufferSelected(b);
213 void MainWin::importBacklog() {
214 if(QMessageBox::warning(this, "Import old backlog?", "Do you want to import your old file-based backlog into new the backlog database?<br>"
215 "<b>This will permanently delete the contents of your database!</b>",
216 QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) {
217 emit importOldBacklog();