1 /***************************************************************************
2 * Copyright (C) 2005-07 by The Quassel IRC Development 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 ***************************************************************************/
21 #include "qtopiamainwin.h"
23 #include "buffertreemodel.h"
24 #include "bufferviewwidget.h"
25 #include "nicklistwidget.h"
27 #include "coreconnectdlg.h"
29 #include "mainwidget.h"
32 #include "signalproxy.h"
35 #include <QSoftMenuBar>
39 // This constructor is the first thing to be called for a Qtopia app, so we do the init stuff
40 // here (rather than in a main.cpp).
41 QtopiaMainWin::QtopiaMainWin(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags) {
42 qRegisterMetaType<QVariant>("QVariant");
43 qRegisterMetaType<Message>("Message");
44 qRegisterMetaType<BufferInfo>("BufferInfo");
45 qRegisterMetaTypeStreamOperators<QVariant>("QVariant");
46 qRegisterMetaTypeStreamOperators<Message>("Message");
47 qRegisterMetaTypeStreamOperators<BufferInfo>("BufferInfo");
49 Global::runMode = Global::ClientOnly;
51 QCoreApplication::setOrganizationDomain("quassel-irc.org");
52 QCoreApplication::setApplicationName("Quassel IRC");
53 QCoreApplication::setOrganizationName("Quassel IRC Team");
55 QtopiaUi *gui = new QtopiaUi(this);
58 setWindowTitle("Quassel IRC");
59 setWindowIcon(QIcon(":/qirc-icon.png"));
60 setWindowIconText("Quassel IRC");
62 mainWidget = new MainWidget(this);
63 setCentralWidget(mainWidget);
65 BufferTreeModel *model = Client::bufferModel();
66 connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
68 toolBar = new QToolBar(this);
69 toolBar->setIconSize(QSize(16, 16));
72 bufferViewWidget = new BufferViewWidget(this);
73 nickListWidget = new NickListWidget(this);
82 // at this point, client is fully initialized
83 void QtopiaMainWin::init() {
84 Client::signalProxy()->attachSignal(this, SIGNAL(requestBacklog(BufferInfo, QVariant, QVariant)));
86 CoreConnectDlg *dlg = new CoreConnectDlg(this);
87 //setCentralWidget(dlg);
92 QtopiaMainWin::~QtopiaMainWin() {
97 void QtopiaMainWin::closeEvent(QCloseEvent *event) {
99 QMessageBox *box = new QMessageBox(QMessageBox::Question, tr("Quit Quassel IRC?"), tr("Do you really want to quit Quassel IRC?"),
100 QMessageBox::Cancel, this);
101 QAbstractButton *quit = box->addButton(tr("Quit"), QMessageBox::AcceptRole);
103 if(box->clickedButton() == quit) event->accept();
104 else event->ignore();
111 void QtopiaMainWin::setupActions() {
112 showBuffersAction = toolBar->addAction(QIcon(":icon/options-hide"), "Show Buffers", this, SLOT(showBufferView())); // FIXME provide real icon
113 showNicksAction = toolBar->addAction(QIcon(":icon/list"), "Show Nicks", this, SLOT(showNickList()));
115 QMenu *menu = new QMenu(this);
116 menu->addAction(showBuffersAction);
117 menu->addAction(showNicksAction);
118 QSoftMenuBar::addMenuTo(this, menu);
121 void QtopiaMainWin::connectedToCore() {
122 foreach(BufferInfo id, Client::allBufferInfos()) {
123 emit requestBacklog(id, 100, -1);
127 // FIXME just for testing: select first available buffer
128 if(Client::allBufferInfos().count() > 1) {
129 Buffer *b = Client::buffer(Client::allBufferInfos()[1]);
130 Client::bufferModel()->selectBuffer(b);
135 void QtopiaMainWin::disconnectedFromCore() {
140 AbstractUiMsg *QtopiaMainWin::layoutMsg(const Message &msg) {
141 return new ChatLine(msg);
145 void QtopiaMainWin::showBuffer(Buffer *b) {
146 mainWidget->setBuffer(b);
147 bufferViewWidget->hide();
148 nickListWidget->setBuffer(b);
152 void QtopiaMainWin::showBufferView() {
153 bufferViewWidget->showMaximized();
157 void QtopiaMainWin::showNickList() {
158 nickListWidget->showMaximized();