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 "settingspage.h"
31 #include "signalproxy.h"
33 MainWin::MainWin(QtGui *_gui, QWidget *parent) : QMainWindow(parent), gui(_gui) {
35 //setWindowTitle("Quassel IRC");
36 setWindowTitle(QString::fromUtf8("Κυασελ Εγαρζη"));
37 setWindowIcon(QIcon(":/qirc-icon.png"));
38 setWindowIconText("Quassel IRC");
40 statusBar()->showMessage(tr("Waiting for core..."));
44 void MainWin::init() {
45 //connect(this, SIGNAL(requestBacklog(BufferId, QVariant, QVariant)), ClientProxy::instance(), SLOT(gsRequestBacklog(BufferId, QVariant, QVariant)));
46 Client::signalProxy()->attachSignal(this, SIGNAL(requestBacklog(BufferId, QVariant, QVariant)));
47 ui.bufferWidget->init();
51 //QVariantMap connInfo;
52 //connInfo["User"] = "Default";
53 //connInfo["Password"] = "password";
54 //connectToCore(connInfo);
56 statusBar()->showMessage(tr("Not connected to core."));
57 systray = new QSystemTrayIcon(this);
58 systray->setIcon(QIcon(":/qirc-icon.png"));
61 serverListDlg = new ServerListDlg(this);
62 serverListDlg->setVisible(serverListDlg->showOnStartup());
70 s.beginGroup("Geometry");
71 //resize(s.value("MainWinSize", QSize(500, 400)).toSize());
72 //move(s.value("MainWinPos", QPoint(50, 50)).toPoint());
73 if(s.contains("MainWinState")) restoreState(s.value("MainWinState").toByteArray());
76 //s.beginGroup("Buffers");
77 //QString net = s.value("CurrentNetwork", "").toString();
78 //QString buf = s.value("CurrentBuffer", "").toString();
81 disconnectedFromCore(); // Disable menus and stuff
82 showCoreConnectionDlg(true); // autoconnect if appropriate
83 //ui.actionConnectCore->activate(QAction::Trigger);
87 //typedef QHash<QString, Buffer*> BufHash;
88 //foreach(BufHash h, buffers.values()) {
89 // foreach(Buffer *b, h.values()) {
93 //foreach(Buffer *buf, buffers.values()) delete buf;
96 /* This is implemented in settingspages.cpp */
98 void MainWin::setupSettingsDlg() {
103 void MainWin::setupMenus() {
104 connect(ui.actionConnectCore, SIGNAL(triggered()), this, SLOT(showCoreConnectionDlg()));
105 connect(ui.actionDisconnectCore, SIGNAL(triggered()), Client::instance(), SLOT(disconnectFromCore()));
106 connect(ui.actionNetworkList, SIGNAL(triggered()), this, SLOT(showServerList()));
107 connect(ui.actionEditIdentities, SIGNAL(triggered()), serverListDlg, SLOT(editIdentities()));
108 connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));
109 ui.actionSettingsDlg->setEnabled(false);
110 connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
112 connect(ui.actionImportBacklog, SIGNAL(triggered()), this, SLOT(importBacklog()));
113 //connect(this, SIGNAL(importOldBacklog()), ClientProxy::instance(), SLOT(gsImportBacklog()));
114 Client::signalProxy()->attachSignal(this, SIGNAL(importOldBacklog()));
117 void MainWin::setupViews() {
119 BufferTreeModel *model = Client::bufferModel();
120 connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
122 addBufferView(tr("All Buffers"), model, BufferViewFilter::AllNets, QStringList());
123 addBufferView(tr("All Channels"), model, BufferViewFilter::AllNets|BufferViewFilter::NoQueries|BufferViewFilter::NoServers, QStringList());
124 addBufferView(tr("All Queries"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoServers, QStringList());
125 addBufferView(tr("All Networks"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries, QStringList());
126 addBufferView(tr("Full Custom"), model, BufferViewFilter::FullCustom, QStringList());
128 ui.menuViews->addSeparator();
131 void MainWin::addBufferView(const QString &viewname, QAbstractItemModel *model, const BufferViewFilter::Modes &mode, const QStringList &nets) {
132 QDockWidget *dock = new QDockWidget(viewname, this);
133 dock->setObjectName(QString("ViewDock-" + viewname)); // should be unique for mainwindow state!
134 dock->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
135 //dock->setContentsMargins(4,4,4,4);
137 //create the view and initialize it's filter
138 BufferView *view = new BufferView(dock);
139 view->setFilteredModel(model, mode, nets);
140 dock->setWidget(view);
142 addDockWidget(Qt::LeftDockWidgetArea, dock);
143 ui.menuViews->addAction(dock->toggleViewAction());
145 netViews.append(dock);
148 void MainWin::connectedToCore() {
149 foreach(BufferId id, Client::allBufferIds()) {
150 emit requestBacklog(id, 100, -1);
153 ui.menuViews->setEnabled(true);
154 ui.menuCore->setEnabled(true);
155 ui.actionConnectCore->setEnabled(false);
156 ui.actionDisconnectCore->setEnabled(true);
157 ui.actionNetworkList->setEnabled(true);
158 ui.bufferWidget->show();
161 void MainWin::disconnectedFromCore() {
162 ui.menuViews->setEnabled(false);
163 ui.menuCore->setEnabled(false);
164 ui.actionDisconnectCore->setEnabled(false);
165 ui.actionNetworkList->setEnabled(false);
166 ui.bufferWidget->hide();
167 ui.actionConnectCore->setEnabled(true);
168 //qDebug() << "mainwin disconnected";
171 AbstractUiMsg *MainWin::layoutMsg(const Message &msg) {
172 return new ChatLine(msg);
175 void MainWin::showCoreConnectionDlg(bool autoConnect) {
176 coreConnectDlg = new CoreConnectDlg(this, autoConnect);
177 connect(coreConnectDlg, SIGNAL(finished(int)), this, SLOT(coreConnectionDlgFinished(int)));
178 coreConnectDlg->setModal(true);
179 if(!autoConnect || !coreConnectDlg->willDoInternalAutoConnect())
180 coreConnectDlg->show(); // avoid flicker and show dlg only if we do remote connect, which needs a progress bar
181 if(autoConnect) coreConnectDlg->doAutoConnect();
184 void MainWin::coreConnectionDlgFinished(int /*code*/) {
186 coreConnectDlg->close();
190 void MainWin::showServerList() {
191 // if(!serverListDlg) {
192 // serverListDlg = new ServerListDlg(this);
194 serverListDlg->show();
195 serverListDlg->raise();
198 void MainWin::showSettingsDlg() {
202 void MainWin::closeEvent(QCloseEvent *event)
204 //if (userReallyWantsToQuit()) {
205 ui.bufferWidget->saveState();
207 s.beginGroup("Geometry");
208 s.setValue("MainWinSize", size());
209 s.setValue("MainWinPos", pos());
210 s.setValue("MainWinState", saveState());
212 s.beginGroup("Buffers");
213 //s.setValue("CurrentNetwork", currentNetwork);
214 s.setValue("CurrentBuffer", currentBuffer);
223 void MainWin::showBuffer(BufferId id) {
224 showBuffer(Client::buffer(id));
227 void MainWin::showBuffer(Buffer *b) {
228 currentBuffer = b->bufferId().groupId();
229 //emit bufferSelected(b);
230 //qApp->processEvents();
232 ui.bufferWidget->setBuffer(b);
233 //emit bufferSelected(b);
236 void MainWin::importBacklog() {
237 if(QMessageBox::warning(this, "Import old backlog?", "Do you want to import your old file-based backlog into new the backlog database?<br>"
238 "<b>This will permanently delete the contents of your database!</b>",
239 QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) {
240 emit importOldBacklog();