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
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() {
55
connect(guiProxy, SIGNAL(csServerState(QString, QVariant)), this, SLOT(recvNetworkState(QString, QVariant)));
56
connect(guiProxy, SIGNAL(csServerConnected(QString)), this, SLOT(networkConnected(QString)));
57
connect(guiProxy, SIGNAL(csServerDisconnected(QString)), this, SLOT(networkDisconnected(QString)));
58
connect(guiProxy, SIGNAL(csDisplayMsg(Message)), this, SLOT(recvMessage(Message)));
59
connect(guiProxy, SIGNAL(csDisplayStatusMsg(QString, QString)), this, SLOT(recvStatusMsg(QString, QString)));
60
connect(guiProxy, SIGNAL(csTopicSet(QString, QString, QString)), this, SLOT(setTopic(QString, QString, QString)));
61
connect(guiProxy, SIGNAL(csNickAdded(QString, QString, VarMap)), this, SLOT(addNick(QString, QString, VarMap)));
62
connect(guiProxy, SIGNAL(csNickRemoved(QString, QString)), this, SLOT(removeNick(QString, QString)));
63
connect(guiProxy, SIGNAL(csNickRenamed(QString, QString, QString)), this, SLOT(renameNick(QString, QString, QString)));
64
connect(guiProxy, SIGNAL(csNickUpdated(QString, QString, VarMap)), this, SLOT(updateNick(QString, QString, VarMap)));
65
connect(guiProxy, SIGNAL(csOwnNickSet(QString, QString)), this, SLOT(setOwnNick(QString, QString)));
66
connect(guiProxy, SIGNAL(csBacklogData(BufferId, QList<QVariant>, bool)), this, SLOT(recvBacklogData(BufferId, QList<QVariant>, bool)));
67
connect(guiProxy, SIGNAL(csUpdateBufferId(BufferId)), this, SLOT(updateBufferId(BufferId)));
68
connect(this, SIGNAL(sendInput(BufferId, QString)), guiProxy, SLOT(gsUserInput(BufferId, QString)));
69
connect(this, SIGNAL(requestBacklog(BufferId, QVariant, QVariant)), guiProxy, SLOT(gsRequestBacklog(BufferId, QVariant, QVariant)));
71
//layoutThread = new LayoutThread();
72
//layoutThread->start();
73
//while(!layoutThread->isRunning()) {};
75
ui.bufferWidget->init();
79
statusBar()->showMessage(tr("Ready."));
80
systray = new QSystemTrayIcon(this);
81
systray->setIcon(QIcon(":/qirc-icon.png"));
84
serverListDlg = new ServerListDlg(this);
85
serverListDlg->setVisible(serverListDlg->showOnStartup());
93
s.beginGroup("Geometry");
94
//resize(s.value("MainWinSize", QSize(500, 400)).toSize());
95
//move(s.value("MainWinPos", QPoint(50, 50)).toPoint());
96
if(s.contains("MainWinState")) restoreState(s.value("MainWinState").toByteArray());
99
s.beginGroup("Buffers");
100
QString net = s.value("CurrentNetwork", "").toString();
101
QString buf = s.value("CurrentBuffer", "").toString();
105
if(buffers.contains(net)) {
106
if(buffers[net].contains(buf)) {
107
showBuffer(net, buf);
116
MainWin::~MainWin() {
117
//typedef QHash<QString, Buffer*> BufHash;
118
//foreach(BufHash h, buffers.values()) {
119
// foreach(Buffer *b, h.values()) {
123
//foreach(Buffer *buf, buffers.values()) delete buf;
126
/* This is implemented in settingspages.cpp */
128
void MainWin::setupSettingsDlg() {
133
void MainWin::setupMenus() {
134
connect(ui.actionNetworkList, SIGNAL(triggered()), this, SLOT(showServerList()));
135
connect(ui.actionEditIdentities, SIGNAL(triggered()), serverListDlg, SLOT(editIdentities()));
136
connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));
137
//ui.actionSettingsDlg->setEnabled(false);
138
connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
140
connect(ui.actionImportBacklog, SIGNAL(triggered()), this, SLOT(importBacklog()));
141
connect(this, SIGNAL(importOldBacklog()), ClientProxy::instance(), SLOT(gsImportBacklog()));
144
void MainWin::setupViews() {
146
BufferTreeModel *model = Client::bufferModel(); // FIXME Where is the delete for that? :p
147
connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
148
//connect(this, SIGNAL(bufferSelected(Buffer *)), model, SLOT(selectBuffer(Buffer *)));
149
//connect(this, SIGNAL(bufferUpdated(Buffer *)), model, SLOT(bufferUpdated(Buffer *)));
150
//connect(this, SIGNAL(bufferActivity(Buffer::ActivityLevel, Buffer *)), model, SLOT(bufferActivity(Buffer::ActivityLevel, Buffer *)));
152
BufferViewDock *all = new BufferViewDock(model, tr("All Buffers"), BufferViewFilter::AllNets);
153
registerBufferViewDock(all);
155
BufferViewDock *allchans = new BufferViewDock(model, tr("All Channels"), BufferViewFilter::AllNets|BufferViewFilter::NoQueries|BufferViewFilter::NoServers);
156
registerBufferViewDock(allchans);
158
BufferViewDock *allqrys = new BufferViewDock(model, tr("All Queries"), BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoServers);
159
registerBufferViewDock(allqrys);
162
BufferViewDock *allnets = new BufferViewDock(model, tr("All Networks"), BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries);
163
registerBufferViewDock(allnets);
166
ui.menuViews->addSeparator();
169
void MainWin::registerBufferViewDock(BufferViewDock *dock) {
170
addDockWidget(Qt::LeftDockWidgetArea, dock);
171
dock->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
172
netViews.append(dock);
173
ui.menuViews->addAction(dock->toggleViewAction());
176
connect(this, SIGNAL(bufferSelected(Buffer *)), view, SLOT(selectBuffer(Buffer *)));
177
connect(this, SIGNAL(bufferDestroyed(Buffer *)), view, SLOT(bufferDestroyed(Buffer *)));
178
connect(view, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
179
view->setBuffers(buffers.values());
183
void MainWin::showServerList() {
184
// if(!serverListDlg) {
185
// serverListDlg = new ServerListDlg(this);
187
serverListDlg->show();
188
serverListDlg->raise();
191
void MainWin::showSettingsDlg() {
195
void MainWin::closeEvent(QCloseEvent *event)
197
//if (userReallyWantsToQuit()) {
198
ui.bufferWidget->saveState();
200
s.beginGroup("Geometry");
201
s.setValue("MainWinSize", size());
202
s.setValue("MainWinPos", pos());
203
s.setValue("MainWinState", saveState());
205
s.beginGroup("Buffers");
206
//s.setValue("CurrentNetwork", currentNetwork);
207
s.setValue("CurrentBuffer", currentBuffer);
216
void MainWin::showBuffer(BufferId id) {
217
showBuffer(Client::buffer(id));
220
void MainWin::showBuffer(Buffer *b) {
221
currentBuffer = b->bufferId().groupId();
222
//emit bufferSelected(b);
223
//qApp->processEvents();
224
ui.bufferWidget->setBuffer(b);
225
//emit bufferSelected(b);
228
void MainWin::importBacklog() {
229
if(QMessageBox::warning(this, "Import old backlog?", "Do you want to import your old file-based backlog into new the backlog database?<br>"
230
"<b>This will permanently delete the contents of your database!</b>",
231
QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) {
232
emit importOldBacklog();