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 QtGui::QtGui() : AbstractUi() {
40 mainWin = new MainWin(this);
41 connect(mainWin, SIGNAL(connectToCore(const VarMap &)), this, SIGNAL(connectToCore(const VarMap &)));
42 connect(mainWin, SIGNAL(disconnectFromCore()), this, SIGNAL(disconnectFromCore()));
54 AbstractUiMsg *QtGui::layoutMsg(const Message &msg) {
55 return mainWin->layoutMsg(msg);
58 void QtGui::connectedToCore() {
59 mainWin->connectedToCore();
62 void QtGui::disconnectedFromCore() {
63 mainWin->disconnectedFromCore();
66 MainWin::MainWin(QtGui *_gui, QWidget *parent) : QMainWindow(parent), gui(_gui) {
68 setWindowTitle("Quassel IRC");
69 //setWindowTitle("Κυασελ Εγαρζη");
70 setWindowIcon(QIcon(":/qirc-icon.png"));
71 setWindowIconText("Quassel IRC");
73 statusBar()->showMessage(tr("Waiting for core..."));
77 void MainWin::init() {
78 connect(this, SIGNAL(requestBacklog(BufferId, QVariant, QVariant)), ClientProxy::instance(), SLOT(gsRequestBacklog(BufferId, QVariant, QVariant)));
79 ui.bufferWidget->init();
84 connInfo["User"] = "Default";
85 connInfo["Password"] = "password";
86 connectToCore(connInfo);
88 statusBar()->showMessage(tr("Ready."));
89 systray = new QSystemTrayIcon(this);
90 systray->setIcon(QIcon(":/qirc-icon.png"));
93 serverListDlg = new ServerListDlg(this);
94 serverListDlg->setVisible(serverListDlg->showOnStartup());
102 s.beginGroup("Geometry");
103 //resize(s.value("MainWinSize", QSize(500, 400)).toSize());
104 //move(s.value("MainWinPos", QPoint(50, 50)).toPoint());
105 if(s.contains("MainWinState")) restoreState(s.value("MainWinState").toByteArray());
108 s.beginGroup("Buffers");
109 QString net = s.value("CurrentNetwork", "").toString();
110 QString buf = s.value("CurrentBuffer", "").toString();
114 if(buffers.contains(net)) {
115 if(buffers[net].contains(buf)) {
116 showBuffer(net, buf);
126 MainWin::~MainWin() {
127 //typedef QHash<QString, Buffer*> BufHash;
128 //foreach(BufHash h, buffers.values()) {
129 // foreach(Buffer *b, h.values()) {
133 //foreach(Buffer *buf, buffers.values()) delete buf;
136 /* This is implemented in settingspages.cpp */
138 void MainWin::setupSettingsDlg() {
143 void MainWin::setupMenus() {
144 connect(ui.actionNetworkList, SIGNAL(triggered()), this, SLOT(showServerList()));
145 connect(ui.actionEditIdentities, SIGNAL(triggered()), serverListDlg, SLOT(editIdentities()));
146 connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg()));
147 //ui.actionSettingsDlg->setEnabled(false);
148 connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
150 connect(ui.actionImportBacklog, SIGNAL(triggered()), this, SLOT(importBacklog()));
151 connect(this, SIGNAL(importOldBacklog()), ClientProxy::instance(), SLOT(gsImportBacklog()));
154 void MainWin::setupViews() {
156 BufferTreeModel *model = Client::bufferModel();
157 connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
159 addBufferView(tr("All Buffers"), model, BufferViewFilter::AllNets, QStringList());
160 addBufferView(tr("All Channels"), model, BufferViewFilter::AllNets|BufferViewFilter::NoQueries|BufferViewFilter::NoServers, QStringList());
161 addBufferView(tr("All Queries"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoServers, QStringList());
162 addBufferView(tr("All Networks"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries, QStringList());
163 addBufferView(tr("Full Custom"), model, BufferViewFilter::FullCustom, QStringList());
165 ui.menuViews->addSeparator();
168 void MainWin::addBufferView(const QString &viewname, QAbstractItemModel *model, const BufferViewFilter::Modes &mode, const QStringList &nets) {
169 QDockWidget *dock = new QDockWidget(viewname, this);
170 dock->setObjectName(QString("ViewDock-" + viewname)); // should be unique for mainwindow state!
171 dock->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
172 //dock->setContentsMargins(4,4,4,4);
174 //create the view and initialize it's filter
175 BufferView *view = new BufferView(dock);
176 view->setFilteredModel(model, mode, nets);
177 dock->setWidget(view);
179 addDockWidget(Qt::LeftDockWidgetArea, dock);
180 ui.menuViews->addAction(dock->toggleViewAction());
182 netViews.append(dock);
185 void MainWin::connectedToCore() {
186 foreach(BufferId id, Client::allBufferIds()) {
187 emit requestBacklog(id, 100, -1);
191 void MainWin::disconnectedFromCore() {
195 AbstractUiMsg *MainWin::layoutMsg(const Message &msg) {
196 return new ChatLine(msg);
199 void MainWin::showServerList() {
200 // if(!serverListDlg) {
201 // serverListDlg = new ServerListDlg(this);
203 serverListDlg->show();
204 serverListDlg->raise();
207 void MainWin::showSettingsDlg() {
211 void MainWin::closeEvent(QCloseEvent *event)
213 //if (userReallyWantsToQuit()) {
214 ui.bufferWidget->saveState();
216 s.beginGroup("Geometry");
217 s.setValue("MainWinSize", size());
218 s.setValue("MainWinPos", pos());
219 s.setValue("MainWinState", saveState());
221 s.beginGroup("Buffers");
222 //s.setValue("CurrentNetwork", currentNetwork);
223 s.setValue("CurrentBuffer", currentBuffer);
232 void MainWin::showBuffer(BufferId id) {
233 showBuffer(Client::buffer(id));
236 void MainWin::showBuffer(Buffer *b) {
237 currentBuffer = b->bufferId().groupId();
238 //emit bufferSelected(b);
239 //qApp->processEvents();
241 ui.bufferWidget->setBuffer(b);
242 //emit bufferSelected(b);
245 void MainWin::importBacklog() {
246 if(QMessageBox::warning(this, "Import old backlog?", "Do you want to import your old file-based backlog into new the backlog database?<br>"
247 "<b>This will permanently delete the contents of your database!</b>",
248 QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes) {
249 emit importOldBacklog();