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>
33 #include "bufferviewwidget.h"
34 #include "serverlist.h"
35 #include "coreconnectdlg.h"
36 #include "settingsdlg.h"
37 #include "settingspages.h"
39 LayoutThread *layoutThread;
41 MainWin::MainWin() : QMainWindow() {
44 //qDebug() << "Available DB drivers: " << QSqlDatabase::drivers ();
45 setWindowTitle("Quassel IRC");
46 //setWindowTitle("Κυασελ Εγαρζη");
47 setWindowIcon(QIcon(":/qirc-icon.png"));
48 setWindowIconText("Quassel IRC");
50 //workspace = new QWorkspace(this);
51 //setCentralWidget(workspace);
52 statusBar()->showMessage(tr("Waiting for core..."));
55 void MainWin::init() {
57 connect(guiProxy, SIGNAL(csServerState(QString, QVariant)), this, SLOT(recvNetworkState(QString, QVariant)));
58 connect(guiProxy, SIGNAL(csServerConnected(QString)), this, SLOT(networkConnected(QString)));
59 connect(guiProxy, SIGNAL(csServerDisconnected(QString)), this, SLOT(networkDisconnected(QString)));
60 connect(guiProxy, SIGNAL(csDisplayMsg(Message)), this, SLOT(recvMessage(Message)));
61 connect(guiProxy, SIGNAL(csDisplayStatusMsg(QString, QString)), this, SLOT(recvStatusMsg(QString, QString)));
62 connect(guiProxy, SIGNAL(csTopicSet(QString, QString, QString)), this, SLOT(setTopic(QString, QString, QString)));
63 connect(guiProxy, SIGNAL(csNickAdded(QString, QString, VarMap)), this, SLOT(addNick(QString, QString, VarMap)));
64 connect(guiProxy, SIGNAL(csNickRemoved(QString, QString)), this, SLOT(removeNick(QString, QString)));
65 connect(guiProxy, SIGNAL(csNickRenamed(QString, QString, QString)), this, SLOT(renameNick(QString, QString, QString)));
66 connect(guiProxy, SIGNAL(csNickUpdated(QString, QString, VarMap)), this, SLOT(updateNick(QString, QString, VarMap)));
67 connect(guiProxy, SIGNAL(csOwnNickSet(QString, QString)), this, SLOT(setOwnNick(QString, QString)));
68 connect(guiProxy, SIGNAL(csBacklogData(BufferId, QList<QVariant>, bool)), this, SLOT(recvBacklogData(BufferId, QList<QVariant>, bool)));
69 connect(guiProxy, SIGNAL(csUpdateBufferId(BufferId)), this, SLOT(updateBufferId(BufferId)));
70 connect(this, SIGNAL(sendInput(BufferId, QString)), guiProxy, SLOT(gsUserInput(BufferId, QString)));
71 connect(this, SIGNAL(requestBacklog(BufferId, QVariant, QVariant)), guiProxy, SLOT(gsRequestBacklog(BufferId, QVariant, QVariant)));
73 //layoutThread = new LayoutThread();
74 //layoutThread->start();
75 //while(!layoutThread->isRunning()) {};
77 ui.bufferWidget->init();
81 statusBar()->showMessage(tr("Ready."));
82 systray = new QSystemTrayIcon(this);
83 systray->setIcon(QIcon(":/qirc-icon.png"));
86 serverListDlg = new ServerListDlg(this);
87 serverListDlg->setVisible(serverListDlg->showOnStartup());
95 s.beginGroup("Geometry");
96 //resize(s.value("MainWinSize", QSize(500, 400)).toSize());
97 //move(s.value("MainWinPos", QPoint(50, 50)).toPoint());
98 if(s.contains("MainWinState")) restoreState(s.value("MainWinState").toByteArray());
101 s.beginGroup("Buffers");
102 QString net = s.value("CurrentNetwork", "").toString();
103 QString buf = s.value("CurrentBuffer", "").toString();
107 if(buffers.contains(net)) {
108 if(buffers[net].contains(buf)) {
109 showBuffer(net, buf);
118 MainWin::~MainWin() {
119 //typedef QHash<QString, Buffer*> BufHash;
120 //foreach(BufHash h, buffers.values()) {
121 // foreach(Buffer *b, h.values()) {
125 //foreach(Buffer *buf, buffers.values()) delete buf;
128 /* This is implemented in settingspages.cpp */
130 void MainWin::setupSettingsDlg() {
135 void MainWin::setupMenus() {
136 connect(ui.actionNetworkList, SIGNAL(triggered()), this, SLOT(showServerList()));
137 connect(ui.actionEditIdentities, SIGNAL(triggered()), serverListDlg, SLOT(editIdentities()));
138 connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));
139 //ui.actionSettingsDlg->setEnabled(false);
140 connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
142 connect(ui.actionImportBacklog, SIGNAL(triggered()), this, SLOT(importBacklog()));
143 connect(this, SIGNAL(importOldBacklog()), ClientProxy::instance(), SLOT(gsImportBacklog()));
146 void MainWin::setupViews() {
147 BufferTreeModel *model = Client::bufferModel(); // FIXME Where is the delete for that? :p
148 connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
149 //connect(this, SIGNAL(bufferSelected(Buffer *)), model, SLOT(selectBuffer(Buffer *)));
150 //connect(this, SIGNAL(bufferUpdated(Buffer *)), model, SLOT(bufferUpdated(Buffer *)));
151 //connect(this, SIGNAL(bufferActivity(Buffer::ActivityLevel, Buffer *)), model, SLOT(bufferActivity(Buffer::ActivityLevel, Buffer *)));
153 BufferViewDock *all = new BufferViewDock(model, tr("All Buffers"), BufferViewFilter::AllNets);
154 registerBufferViewDock(all);
156 BufferViewDock *allchans = new BufferViewDock(model, tr("All Channels"), BufferViewFilter::AllNets|BufferViewFilter::NoQueries|BufferViewFilter::NoServers);
157 registerBufferViewDock(allchans);
159 BufferViewDock *allqrys = new BufferViewDock(model, tr("All Queries"), BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoServers);
160 registerBufferViewDock(allqrys);
163 BufferViewDock *allnets = new BufferViewDock(model, tr("All Networks"), BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries);
164 registerBufferViewDock(allnets);
167 ui.menuViews->addSeparator();
170 void MainWin::registerBufferViewDock(BufferViewDock *dock) {
171 addDockWidget(Qt::LeftDockWidgetArea, dock);
172 dock->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
173 netViews.append(dock);
174 ui.menuViews->addAction(dock->toggleViewAction());
177 connect(this, SIGNAL(bufferSelected(Buffer *)), view, SLOT(selectBuffer(Buffer *)));
178 connect(this, SIGNAL(bufferDestroyed(Buffer *)), view, SLOT(bufferDestroyed(Buffer *)));
179 connect(view, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
180 view->setBuffers(buffers.values());
184 void MainWin::showServerList() {
185 // if(!serverListDlg) {
186 // serverListDlg = new ServerListDlg(this);
188 serverListDlg->show();
189 serverListDlg->raise();
192 void MainWin::showSettingsDlg() {
196 void MainWin::closeEvent(QCloseEvent *event)
198 //if (userReallyWantsToQuit()) {
199 ui.bufferWidget->saveState();
201 s.beginGroup("Geometry");
202 s.setValue("MainWinSize", size());
203 s.setValue("MainWinPos", pos());
204 s.setValue("MainWinState", saveState());
206 s.beginGroup("Buffers");
207 //s.setValue("CurrentNetwork", currentNetwork);
208 s.setValue("CurrentBuffer", currentBuffer);
217 void MainWin::showBuffer(BufferId id) {
218 showBuffer(Client::buffer(id));
221 void MainWin::showBuffer(Buffer *b) {
222 currentBuffer = b->bufferId().groupId();
223 //emit bufferSelected(b);
224 //qApp->processEvents();
225 ui.bufferWidget->setBuffer(b);
226 //emit bufferSelected(b); // FIXME do we need this?
229 void MainWin::importBacklog() {
230 if(QMessageBox::warning(this, "Import old backlog?", "Do you want to import your old file-based backlog into new the backlog database?<br>"
231 "<b>This will permanently delete the contents of your database!</b>",
232 QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) {
233 emit importOldBacklog();