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"
33 #include "serverlist.h"
34 #include "coreconnectdlg.h"
35 #include "settingsdlg.h"
36 #include "settingspages.h"
38 MainWin::MainWin() : QMainWindow() {
41 //qDebug() << "Available DB drivers: " << QSqlDatabase::drivers ();
42 setWindowTitle("Quassel IRC");
43 //setWindowTitle("Κυασελ Εγαρζη");
44 setWindowIcon(QIcon(":/qirc-icon.png"));
45 setWindowIconText("Quassel IRC");
47 //workspace = new QWorkspace(this);
48 //setCentralWidget(workspace);
49 statusBar()->showMessage(tr("Waiting for core..."));
52 void MainWin::init() {
54 connect(guiProxy, SIGNAL(csServerState(QString, QVariant)), this, SLOT(recvNetworkState(QString, QVariant)));
55 connect(guiProxy, SIGNAL(csServerConnected(QString)), this, SLOT(networkConnected(QString)));
56 connect(guiProxy, SIGNAL(csServerDisconnected(QString)), this, SLOT(networkDisconnected(QString)));
57 connect(guiProxy, SIGNAL(csDisplayMsg(Message)), this, SLOT(recvMessage(Message)));
58 connect(guiProxy, SIGNAL(csDisplayStatusMsg(QString, QString)), this, SLOT(recvStatusMsg(QString, QString)));
59 connect(guiProxy, SIGNAL(csTopicSet(QString, QString, QString)), this, SLOT(setTopic(QString, QString, QString)));
60 connect(guiProxy, SIGNAL(csNickAdded(QString, QString, VarMap)), this, SLOT(addNick(QString, QString, VarMap)));
61 connect(guiProxy, SIGNAL(csNickRemoved(QString, QString)), this, SLOT(removeNick(QString, QString)));
62 connect(guiProxy, SIGNAL(csNickRenamed(QString, QString, QString)), this, SLOT(renameNick(QString, QString, QString)));
63 connect(guiProxy, SIGNAL(csNickUpdated(QString, QString, VarMap)), this, SLOT(updateNick(QString, QString, VarMap)));
64 connect(guiProxy, SIGNAL(csOwnNickSet(QString, QString)), this, SLOT(setOwnNick(QString, QString)));
65 connect(guiProxy, SIGNAL(csBacklogData(BufferId, QList<QVariant>, bool)), this, SLOT(recvBacklogData(BufferId, QList<QVariant>, bool)));
66 connect(guiProxy, SIGNAL(csUpdateBufferId(BufferId)), this, SLOT(updateBufferId(BufferId)));
67 connect(this, SIGNAL(sendInput(BufferId, QString)), guiProxy, SLOT(gsUserInput(BufferId, QString)));
68 connect(this, SIGNAL(requestBacklog(BufferId, QVariant, QVariant)), guiProxy, SLOT(gsRequestBacklog(BufferId, QVariant, QVariant)));
70 //layoutThread = new LayoutThread();
71 //layoutThread->start();
72 //while(!layoutThread->isRunning()) {};
74 ui.bufferWidget->init();
78 statusBar()->showMessage(tr("Ready."));
79 systray = new QSystemTrayIcon(this);
80 systray->setIcon(QIcon(":/qirc-icon.png"));
83 serverListDlg = new ServerListDlg(this);
84 serverListDlg->setVisible(serverListDlg->showOnStartup());
92 s.beginGroup("Geometry");
93 //resize(s.value("MainWinSize", QSize(500, 400)).toSize());
94 //move(s.value("MainWinPos", QPoint(50, 50)).toPoint());
95 if(s.contains("MainWinState")) restoreState(s.value("MainWinState").toByteArray());
98 s.beginGroup("Buffers");
99 QString net = s.value("CurrentNetwork", "").toString();
100 QString buf = s.value("CurrentBuffer", "").toString();
104 if(buffers.contains(net)) {
105 if(buffers[net].contains(buf)) {
106 showBuffer(net, buf);
115 MainWin::~MainWin() {
116 //typedef QHash<QString, Buffer*> BufHash;
117 //foreach(BufHash h, buffers.values()) {
118 // foreach(Buffer *b, h.values()) {
122 //foreach(Buffer *buf, buffers.values()) delete buf;
125 /* This is implemented in settingspages.cpp */
127 void MainWin::setupSettingsDlg() {
132 void MainWin::setupMenus() {
133 connect(ui.actionNetworkList, SIGNAL(triggered()), this, SLOT(showServerList()));
134 connect(ui.actionEditIdentities, SIGNAL(triggered()), serverListDlg, SLOT(editIdentities()));
135 connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));
136 //ui.actionSettingsDlg->setEnabled(false);
137 connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
139 connect(ui.actionImportBacklog, SIGNAL(triggered()), this, SLOT(importBacklog()));
140 connect(this, SIGNAL(importOldBacklog()), ClientProxy::instance(), SLOT(gsImportBacklog()));
143 void MainWin::setupViews() {
145 BufferTreeModel *model = Client::bufferModel(); // FIXME Where is the delete for that? :p
146 connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
147 //connect(this, SIGNAL(bufferSelected(Buffer *)), model, SLOT(selectBuffer(Buffer *)));
148 //connect(this, SIGNAL(bufferUpdated(Buffer *)), model, SLOT(bufferUpdated(Buffer *)));
149 //connect(this, SIGNAL(bufferActivity(Buffer::ActivityLevel, Buffer *)), model, SLOT(bufferActivity(Buffer::ActivityLevel, Buffer *)));
151 BufferViewDock *all = new BufferViewDock(model, tr("All Buffers"), BufferViewFilter::AllNets);
152 registerBufferViewDock(all);
154 BufferViewDock *allchans = new BufferViewDock(model, tr("All Channels"), BufferViewFilter::AllNets|BufferViewFilter::NoQueries|BufferViewFilter::NoServers);
155 registerBufferViewDock(allchans);
157 BufferViewDock *allqrys = new BufferViewDock(model, tr("All Queries"), BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoServers);
158 registerBufferViewDock(allqrys);
161 BufferViewDock *allnets = new BufferViewDock(model, tr("All Networks"), BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries);
162 registerBufferViewDock(allnets);
165 ui.menuViews->addSeparator();
168 void MainWin::registerBufferViewDock(BufferViewDock *dock) {
169 addDockWidget(Qt::LeftDockWidgetArea, dock);
170 dock->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
171 netViews.append(dock);
172 ui.menuViews->addAction(dock->toggleViewAction());
175 connect(this, SIGNAL(bufferSelected(Buffer *)), view, SLOT(selectBuffer(Buffer *)));
176 connect(this, SIGNAL(bufferDestroyed(Buffer *)), view, SLOT(bufferDestroyed(Buffer *)));
177 connect(view, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
178 view->setBuffers(buffers.values());
182 void MainWin::showServerList() {
183 // if(!serverListDlg) {
184 // serverListDlg = new ServerListDlg(this);
186 serverListDlg->show();
187 serverListDlg->raise();
190 void MainWin::showSettingsDlg() {
194 void MainWin::closeEvent(QCloseEvent *event)
196 //if (userReallyWantsToQuit()) {
197 ui.bufferWidget->saveState();
199 s.beginGroup("Geometry");
200 s.setValue("MainWinSize", size());
201 s.setValue("MainWinPos", pos());
202 s.setValue("MainWinState", saveState());
204 s.beginGroup("Buffers");
205 //s.setValue("CurrentNetwork", currentNetwork);
206 s.setValue("CurrentBuffer", currentBuffer);
215 void MainWin::showBuffer(BufferId id) {
216 showBuffer(Client::buffer(id));
219 void MainWin::showBuffer(Buffer *b) {
220 currentBuffer = b->bufferId().groupId();
221 //emit bufferSelected(b);
222 //qApp->processEvents();
223 ui.bufferWidget->setBuffer(b);
224 //emit bufferSelected(b);
227 void MainWin::importBacklog() {
228 if(QMessageBox::warning(this, "Import old backlog?", "Do you want to import your old file-based backlog into new the backlog database?<br>"
229 "<b>This will permanently delete the contents of your database!</b>",
230 QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) {
231 emit importOldBacklog();