1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
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) version 3. *
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 "networkmodel.h"
24 #include "bufferviewwidget.h"
25 #include "nicklistwidget.h"
27 #include "coreconnectdlg.h"
29 #include "mainwidget.h"
32 #include "signalproxy.h"
34 #include "ui_aboutdlg.h"
37 #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 Global::registerMetaTypes();
44 Global::runMode = Global::ClientOnly;
45 Global::defaultPort = 4242;
47 QCoreApplication::setOrganizationDomain("quassel-irc.org");
48 QCoreApplication::setApplicationName("Quassel IRC");
49 QCoreApplication::setOrganizationName("Quassel IRC Team");
51 QtopiaUi *gui = new QtopiaUi(this);
54 setWindowTitle("Quassel IRC");
55 setWindowIcon(QIcon(":/qirc-icon.png"));
56 setWindowIconText("Quassel IRC");
58 mainWidget = new MainWidget(this);
59 setCentralWidget(mainWidget);
61 NetworkModel *model = Client::networkModel();
62 connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
64 toolBar = new QToolBar(this);
65 toolBar->setIconSize(QSize(16, 16));
66 toolBar->setWindowTitle(tr("Show Toolbar"));
69 bufferViewWidget = new BufferViewWidget(this);
70 nickListWidget = new NickListWidget(this);
79 // at this point, client is fully initialized
80 void QtopiaMainWin::init() {
81 Client::signalProxy()->attachSignal(this, SIGNAL(requestBacklog(BufferInfo, QVariant, QVariant)));
84 CoreConnectDlg *dlg = new CoreConnectDlg(this);
85 //setCentralWidget(dlg);
90 QtopiaMainWin::~QtopiaMainWin() {
95 void QtopiaMainWin::closeEvent(QCloseEvent *event) {
97 QMessageBox *box = new QMessageBox(QMessageBox::Question, tr("Quit Quassel IRC?"), tr("Do you really want to quit Quassel IRC?"),
98 QMessageBox::Cancel, this);
99 QAbstractButton *quit = box->addButton(tr("Quit"), QMessageBox::AcceptRole);
101 if(box->clickedButton() == quit) event->accept();
102 else event->ignore();
109 void QtopiaMainWin::setupActions() {
110 showBuffersAction = toolBar->addAction(QIcon(":icon/options-hide"), tr("Show Buffers"), this, SLOT(showBufferView())); // FIXME provide real icon
111 showNicksAction = toolBar->addAction(QIcon(":icon/list"), tr("Show Nicks"), this, SLOT(showNickList()));
112 showNicksAction->setEnabled(false);
114 QMenu *menu = new QMenu(this);
115 menu->addAction(showBuffersAction);
116 menu->addAction(showNicksAction);
117 menu->addSeparator();
118 menu->addAction(toolBar->toggleViewAction());
119 menu->addSeparator();
120 menu->addAction(tr("About..."), this, SLOT(showAboutDlg()));
122 QSoftMenuBar::addMenuTo(this, menu);
125 void QtopiaMainWin::connectedToCore() {
126 foreach(BufferInfo id, Client::allBufferInfos()) {
127 emit requestBacklog(id, 100, -1);
131 // FIXME just for testing: select first available buffer
132 if(Client::allBufferInfos().count() > 1) {
133 Buffer *b = Client::buffer(Client::allBufferInfos()[1]);
134 Client::networkModel()->selectBuffer(b);
139 void QtopiaMainWin::disconnectedFromCore() {
144 AbstractUiMsg *QtopiaMainWin::layoutMsg(const Message &msg) {
145 return new ChatLine(msg);
149 void QtopiaMainWin::showBuffer(Buffer *b) {
150 bufferViewWidget->hide();
151 mainWidget->setBuffer(b);
152 nickListWidget->setBuffer(b);
153 showNicksAction->setEnabled(b && b->bufferType() == Buffer::ChannelType);
157 void QtopiaMainWin::showBufferView() {
158 bufferViewWidget->showMaximized();
161 void QtopiaMainWin::showNickList() {
162 nickListWidget->showMaximized();
165 void QtopiaMainWin::showAboutDlg() {
166 QDialog *dlg = new QDialog(this);
167 dlg->setAttribute(Qt::WA_DeleteOnClose);
170 dlg->showMaximized();