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 "bufferview.h"
26 #include "clientproxy.h"
27 #include "coreconnectdlg.h"
28 #include "serverlist.h"
29 #include "settingsdlg.h"
30 #include "settingspages.h"
32 MainWin::MainWin(QtGui *_gui, QWidget *parent) : QMainWindow(parent), gui(_gui) {
34 //setWindowTitle("Quassel IRC");
35 setWindowTitle(QString::fromUtf8("Κυασελ Εγαρζη"));
36 setWindowIcon(QIcon(":/qirc-icon.png"));
37 setWindowIconText("Quassel IRC");
39 statusBar()->showMessage(tr("Waiting for core..."));
43 void MainWin::init() {
44 connect(this, SIGNAL(requestBacklog(BufferId, QVariant, QVariant)), ClientProxy::instance(), SLOT(gsRequestBacklog(BufferId, QVariant, QVariant)));
45 ui.bufferWidget->init();
50 connInfo["User"] = "Default";
51 connInfo["Password"] = "password";
52 connectToCore(connInfo);
54 statusBar()->showMessage(tr("Ready."));
55 systray = new QSystemTrayIcon(this);
56 systray->setIcon(QIcon(":/qirc-icon.png"));
59 serverListDlg = new ServerListDlg(this);
60 serverListDlg->setVisible(serverListDlg->showOnStartup());
68 s.beginGroup("Geometry");
69 //resize(s.value("MainWinSize", QSize(500, 400)).toSize());
70 //move(s.value("MainWinPos", QPoint(50, 50)).toPoint());
71 if(s.contains("MainWinState")) restoreState(s.value("MainWinState").toByteArray());
74 s.beginGroup("Buffers");
75 QString net = s.value("CurrentNetwork", "").toString();
76 QString buf = s.value("CurrentBuffer", "").toString();
81 //typedef QHash<QString, Buffer*> BufHash;
82 //foreach(BufHash h, buffers.values()) {
83 // foreach(Buffer *b, h.values()) {
87 //foreach(Buffer *buf, buffers.values()) delete buf;
90 /* This is implemented in settingspages.cpp */
92 void MainWin::setupSettingsDlg() {
97 void MainWin::setupMenus() {
98 connect(ui.actionNetworkList, SIGNAL(triggered()), this, SLOT(showServerList()));
99 connect(ui.actionEditIdentities, SIGNAL(triggered()), serverListDlg, SLOT(editIdentities()));
100 connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));
101 //ui.actionSettingsDlg->setEnabled(false);
102 connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
104 connect(ui.actionImportBacklog, SIGNAL(triggered()), this, SLOT(importBacklog()));
105 connect(this, SIGNAL(importOldBacklog()), ClientProxy::instance(), SLOT(gsImportBacklog()));
108 void MainWin::setupViews() {
110 BufferTreeModel *model = Client::bufferModel();
111 connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
113 addBufferView(tr("All Buffers"), model, BufferViewFilter::AllNets, QStringList());
114 addBufferView(tr("All Channels"), model, BufferViewFilter::AllNets|BufferViewFilter::NoQueries|BufferViewFilter::NoServers, QStringList());
115 addBufferView(tr("All Queries"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoServers, QStringList());
116 addBufferView(tr("All Networks"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries, QStringList());
117 addBufferView(tr("Full Custom"), model, BufferViewFilter::FullCustom, QStringList());
119 ui.menuViews->addSeparator();
122 void MainWin::addBufferView(const QString &viewname, QAbstractItemModel *model, const BufferViewFilter::Modes &mode, const QStringList &nets) {
123 QDockWidget *dock = new QDockWidget(viewname, this);
124 dock->setObjectName(QString("ViewDock-" + viewname)); // should be unique for mainwindow state!
125 dock->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
126 //dock->setContentsMargins(4,4,4,4);
128 //create the view and initialize it's filter
129 BufferView *view = new BufferView(dock);
130 view->setFilteredModel(model, mode, nets);
131 dock->setWidget(view);
133 addDockWidget(Qt::LeftDockWidgetArea, dock);
134 ui.menuViews->addAction(dock->toggleViewAction());
136 netViews.append(dock);
139 void MainWin::connectedToCore() {
140 foreach(BufferId id, Client::allBufferIds()) {
141 emit requestBacklog(id, 100, -1);
145 void MainWin::disconnectedFromCore() {
149 AbstractUiMsg *MainWin::layoutMsg(const Message &msg) {
150 return new ChatLine(msg);
153 void MainWin::showServerList() {
154 // if(!serverListDlg) {
155 // serverListDlg = new ServerListDlg(this);
157 serverListDlg->show();
158 serverListDlg->raise();
161 void MainWin::showSettingsDlg() {
165 void MainWin::closeEvent(QCloseEvent *event)
167 //if (userReallyWantsToQuit()) {
168 ui.bufferWidget->saveState();
170 s.beginGroup("Geometry");
171 s.setValue("MainWinSize", size());
172 s.setValue("MainWinPos", pos());
173 s.setValue("MainWinState", saveState());
175 s.beginGroup("Buffers");
176 //s.setValue("CurrentNetwork", currentNetwork);
177 s.setValue("CurrentBuffer", currentBuffer);
186 void MainWin::showBuffer(BufferId id) {
187 showBuffer(Client::buffer(id));
190 void MainWin::showBuffer(Buffer *b) {
191 currentBuffer = b->bufferId().groupId();
192 //emit bufferSelected(b);
193 //qApp->processEvents();
195 ui.bufferWidget->setBuffer(b);
196 //emit bufferSelected(b);
199 void MainWin::importBacklog() {
200 if(QMessageBox::warning(this, "Import old backlog?", "Do you want to import your old file-based backlog into new the backlog database?<br>"
201 "<b>This will permanently delete the contents of your database!</b>",
202 QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) {
203 emit importOldBacklog();