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() {
43 //qDebug() << "Available DB drivers: " << QSqlDatabase::drivers ();
44 setWindowTitle("Quassel IRC");
45 //setWindowTitle("Κυασελ Εγαρζη");
46 setWindowIcon(QIcon(":/qirc-icon.png"));
47 setWindowIconText("Quassel IRC");
49 //workspace = new QWorkspace(this);
50 //setCentralWidget(workspace);
51 statusBar()->showMessage(tr("Waiting for core..."));
55 void MainWin::init() {
56 ui.bufferWidget->init();
60 statusBar()->showMessage(tr("Ready."));
61 systray = new QSystemTrayIcon(this);
62 systray->setIcon(QIcon(":/qirc-icon.png"));
65 serverListDlg = new ServerListDlg(this);
66 serverListDlg->setVisible(serverListDlg->showOnStartup());
74 s.beginGroup("Geometry");
75 //resize(s.value("MainWinSize", QSize(500, 400)).toSize());
76 //move(s.value("MainWinPos", QPoint(50, 50)).toPoint());
77 if(s.contains("MainWinState")) restoreState(s.value("MainWinState").toByteArray());
80 s.beginGroup("Buffers");
81 QString net = s.value("CurrentNetwork", "").toString();
82 QString buf = s.value("CurrentBuffer", "").toString();
86 if(buffers.contains(net)) {
87 if(buffers[net].contains(buf)) {
98 //typedef QHash<QString, Buffer*> BufHash;
99 //foreach(BufHash h, buffers.values()) {
100 // foreach(Buffer *b, h.values()) {
104 //foreach(Buffer *buf, buffers.values()) delete buf;
107 /* This is implemented in settingspages.cpp */
109 void MainWin::setupSettingsDlg() {
114 void MainWin::setupMenus() {
115 connect(ui.actionNetworkList, SIGNAL(triggered()), this, SLOT(showServerList()));
116 connect(ui.actionEditIdentities, SIGNAL(triggered()), serverListDlg, SLOT(editIdentities()));
117 connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));
118 //ui.actionSettingsDlg->setEnabled(false);
119 connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
121 connect(ui.actionImportBacklog, SIGNAL(triggered()), this, SLOT(importBacklog()));
122 connect(this, SIGNAL(importOldBacklog()), ClientProxy::instance(), SLOT(gsImportBacklog()));
125 void MainWin::setupViews() {
127 BufferTreeModel *model = Client::bufferModel(); // FIXME Where is the delete for that? :p
128 connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
130 addBufferView(tr("All Buffers"), model, BufferViewFilter::AllNets, QStringList());
131 addBufferView(tr("All Channels"), model, BufferViewFilter::AllNets|BufferViewFilter::NoQueries|BufferViewFilter::NoServers, QStringList());
132 addBufferView(tr("All Queries"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoServers, QStringList());
133 addBufferView(tr("All Networks"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries, QStringList());
134 addBufferView(tr("Full Custom"), model, BufferViewFilter::FullCustom, QStringList());
136 ui.menuViews->addSeparator();
139 void MainWin::addBufferView(const QString &viewname, QAbstractItemModel *model, const BufferViewFilter::Modes &mode, const QStringList &nets) {
140 QDockWidget *dock = new QDockWidget(viewname, this);
141 dock->setObjectName(QString("ViewDock-" + viewname)); // should be unique for mainwindow state!
142 dock->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
143 //dock->setContentsMargins(4,4,4,4);
145 //create the view and initialize it's filter
146 BufferView *view = new BufferView(dock);
147 view->setFilteredModel(model, mode, nets);
148 dock->setWidget(view);
150 addDockWidget(Qt::LeftDockWidgetArea, dock);
151 ui.menuViews->addAction(dock->toggleViewAction());
153 netViews.append(dock);
156 AbstractUiMsg *MainWin::layoutMsg(const Message &msg) {
157 return new ChatLine(msg);
160 void MainWin::showServerList() {
161 // if(!serverListDlg) {
162 // serverListDlg = new ServerListDlg(this);
164 serverListDlg->show();
165 serverListDlg->raise();
168 void MainWin::showSettingsDlg() {
172 void MainWin::closeEvent(QCloseEvent *event)
174 //if (userReallyWantsToQuit()) {
175 ui.bufferWidget->saveState();
177 s.beginGroup("Geometry");
178 s.setValue("MainWinSize", size());
179 s.setValue("MainWinPos", pos());
180 s.setValue("MainWinState", saveState());
182 s.beginGroup("Buffers");
183 //s.setValue("CurrentNetwork", currentNetwork);
184 s.setValue("CurrentBuffer", currentBuffer);
193 void MainWin::showBuffer(BufferId id) {
194 showBuffer(Client::buffer(id));
197 void MainWin::showBuffer(Buffer *b) {
198 currentBuffer = b->bufferId().groupId();
199 //emit bufferSelected(b);
200 //qApp->processEvents();
202 ui.bufferWidget->setBuffer(b);
203 //emit bufferSelected(b);
206 void MainWin::importBacklog() {
207 if(QMessageBox::warning(this, "Import old backlog?", "Do you want to import your old file-based backlog into new the backlog database?<br>"
208 "<b>This will permanently delete the contents of your database!</b>",
209 QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) {
210 emit importOldBacklog();