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 "coreconnectdlg.h"
27 #include "serverlist.h"
28 #include "settingsdlg.h"
29 //#include "settingspage.h"
30 #include "signalproxy.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 Client::signalProxy()->attachSignal(this, SIGNAL(requestBacklog(BufferId, QVariant, QVariant)));
45 ui.bufferWidget->init();
49 //QVariantMap connInfo;
50 //connInfo["User"] = "Default";
51 //connInfo["Password"] = "password";
52 //connectToCore(connInfo);
54 statusBar()->showMessage(tr("Not connected to core."));
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();
79 disconnectedFromCore(); // Disable menus and stuff
80 showCoreConnectionDlg(true); // autoconnect if appropriate
81 //ui.actionConnectCore->activate(QAction::Trigger);
85 //typedef QHash<QString, Buffer*> BufHash;
86 //foreach(BufHash h, buffers.values()) {
87 // foreach(Buffer *b, h.values()) {
91 //foreach(Buffer *buf, buffers.values()) delete buf;
94 /* This is implemented in settingspages.cpp */
96 void MainWin::setupSettingsDlg() {
101 void MainWin::setupMenus() {
102 connect(ui.actionConnectCore, SIGNAL(triggered()), this, SLOT(showCoreConnectionDlg()));
103 connect(ui.actionDisconnectCore, SIGNAL(triggered()), Client::instance(), SLOT(disconnectFromCore()));
104 connect(ui.actionNetworkList, SIGNAL(triggered()), this, SLOT(showServerList()));
105 connect(ui.actionEditIdentities, SIGNAL(triggered()), serverListDlg, SLOT(editIdentities()));
106 connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));
107 ui.actionSettingsDlg->setEnabled(false);
108 connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
110 connect(ui.actionImportBacklog, SIGNAL(triggered()), this, SLOT(importBacklog()));
111 Client::signalProxy()->attachSignal(this, SIGNAL(importOldBacklog()));
114 void MainWin::setupViews() {
116 BufferTreeModel *model = Client::bufferModel();
117 connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
119 addBufferView(tr("All Buffers"), model, BufferViewFilter::AllNets, QStringList());
120 addBufferView(tr("All Channels"), model, BufferViewFilter::AllNets|BufferViewFilter::NoQueries|BufferViewFilter::NoServers, QStringList());
121 addBufferView(tr("All Queries"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoServers, QStringList());
122 addBufferView(tr("All Networks"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries, QStringList());
123 addBufferView(tr("Full Custom"), model, BufferViewFilter::FullCustom, QStringList());
125 ui.menuViews->addSeparator();
128 void MainWin::addBufferView(const QString &viewname, QAbstractItemModel *model, const BufferViewFilter::Modes &mode, const QStringList &nets) {
129 QDockWidget *dock = new QDockWidget(viewname, this);
130 dock->setObjectName(QString("ViewDock-" + viewname)); // should be unique for mainwindow state!
131 dock->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
132 //dock->setContentsMargins(4,4,4,4);
134 //create the view and initialize it's filter
135 BufferView *view = new BufferView(dock);
136 view->setFilteredModel(model, mode, nets);
137 dock->setWidget(view);
139 addDockWidget(Qt::LeftDockWidgetArea, dock);
140 ui.menuViews->addAction(dock->toggleViewAction());
142 netViews.append(dock);
145 void MainWin::connectedToCore() {
146 foreach(BufferId id, Client::allBufferIds()) {
147 emit requestBacklog(id, 100, -1);
150 ui.menuViews->setEnabled(true);
151 ui.menuCore->setEnabled(true);
152 ui.actionConnectCore->setEnabled(false);
153 ui.actionDisconnectCore->setEnabled(true);
154 ui.actionNetworkList->setEnabled(true);
155 ui.bufferWidget->show();
158 void MainWin::disconnectedFromCore() {
159 ui.menuViews->setEnabled(false);
160 ui.menuCore->setEnabled(false);
161 ui.actionDisconnectCore->setEnabled(false);
162 ui.actionNetworkList->setEnabled(false);
163 ui.bufferWidget->hide();
164 ui.actionConnectCore->setEnabled(true);
165 //qDebug() << "mainwin disconnected";
168 AbstractUiMsg *MainWin::layoutMsg(const Message &msg) {
169 return new ChatLine(msg);
172 void MainWin::showCoreConnectionDlg(bool autoConnect) {
173 coreConnectDlg = new CoreConnectDlg(this, autoConnect);
174 connect(coreConnectDlg, SIGNAL(finished(int)), this, SLOT(coreConnectionDlgFinished(int)));
175 coreConnectDlg->setModal(true);
176 if(!autoConnect || !coreConnectDlg->willDoInternalAutoConnect())
177 coreConnectDlg->show(); // avoid flicker and show dlg only if we do remote connect, which needs a progress bar
178 if(autoConnect) coreConnectDlg->doAutoConnect();
181 void MainWin::coreConnectionDlgFinished(int /*code*/) {
183 coreConnectDlg->close();
187 void MainWin::showServerList() {
188 // if(!serverListDlg) {
189 // serverListDlg = new ServerListDlg(this);
191 serverListDlg->show();
192 serverListDlg->raise();
195 void MainWin::showSettingsDlg() {
199 void MainWin::closeEvent(QCloseEvent *event)
201 //if (userReallyWantsToQuit()) {
202 ui.bufferWidget->saveState();
204 s.beginGroup("Geometry");
205 s.setValue("MainWinSize", size());
206 s.setValue("MainWinPos", pos());
207 s.setValue("MainWinState", saveState());
209 s.beginGroup("Buffers");
210 //s.setValue("CurrentNetwork", currentNetwork);
211 s.setValue("CurrentBuffer", currentBuffer);
220 void MainWin::showBuffer(BufferId id) {
221 showBuffer(Client::buffer(id));
224 void MainWin::showBuffer(Buffer *b) {
225 currentBuffer = b->bufferId().groupId();
226 //emit bufferSelected(b);
227 //qApp->processEvents();
229 ui.bufferWidget->setBuffer(b);
230 //emit bufferSelected(b);
233 void MainWin::importBacklog() {
234 if(QMessageBox::warning(this, "Import old backlog?", "Do you want to import your old file-based backlog into new the backlog database?<br>"
235 "<b>This will permanently delete the contents of your database!</b>",
236 QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) {
237 emit importOldBacklog();