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 "clientbacklogmanager.h"
28 #include "coreconnectdlg.h"
30 #include "mainwidget.h"
34 #include "signalproxy.h"
36 #include "ui_aboutdlg.h"
39 #include <QSoftMenuBar>
41 // This constructor is the first thing to be called for a Qtopia app, so we do the init stuff
42 // here (rather than in a main.cpp).
43 QtopiaMainWin::QtopiaMainWin(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags) {
44 Global::registerMetaTypes();
46 #include "../../version.inc"
48 Global::runMode = Global::ClientOnly;
49 Global::defaultPort = 4242;
51 Network::setDefaultCodecForServer("ISO-8859-1");
52 Network::setDefaultCodecForEncoding("UTF-8");
53 Network::setDefaultCodecForDecoding("ISO-8859-15");
55 QCoreApplication::setOrganizationDomain("quassel-irc.org");
56 QCoreApplication::setApplicationName("Quassel IRC");
57 QCoreApplication::setOrganizationName("Quassel Project");
59 QtopiaUi *gui = new QtopiaUi(this);
62 setWindowTitle("Quassel IRC");
63 setWindowIcon(QIcon(":icons/quassel-icon.png"));
64 setWindowIconText("Quassel IRC");
66 mainWidget = new MainWidget(this);
67 mainWidget->setModel(Client::bufferModel());
68 mainWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
69 setCentralWidget(mainWidget);
71 toolBar = new QToolBar(this);
72 toolBar->setIconSize(QSize(16, 16));
73 toolBar->setWindowTitle(tr("Show Toolbar"));
76 //bufferViewWidget = new BufferViewWidget(this);
77 bufferViewWidget = 0; // delayed creation to avoid QPainter warnings
78 nickListWidget = new NickListWidget(this);
80 connect(mainWidget, SIGNAL(currentChanged(BufferId)), this, SLOT(showBuffer(BufferId)));
89 // at this point, client is fully initialized
90 void QtopiaMainWin::init() {
92 CoreConnectDlg *dlg = new CoreConnectDlg(this);
93 //setCentralWidget(dlg);
98 QtopiaMainWin::~QtopiaMainWin() {
103 void QtopiaMainWin::closeEvent(QCloseEvent *event) {
105 QMessageBox *box = new QMessageBox(QMessageBox::Question, tr("Quit Quassel IRC?"), tr("Do you really want to quit Quassel IRC?"),
106 QMessageBox::Cancel, this);
107 QAbstractButton *quit = box->addButton(tr("Quit"), QMessageBox::AcceptRole);
109 if(box->clickedButton() == quit) event->accept();
110 else event->ignore();
117 void QtopiaMainWin::setupActions() {
118 showBuffersAction = toolBar->addAction(QIcon(":icon/options-hide"), tr("Show Buffers"), this, SLOT(showBufferView())); // FIXME provide real icon
119 showNicksAction = toolBar->addAction(QIcon(":icon/list"), tr("Show Nicks"), this, SLOT(showNickList()));
120 showNicksAction->setEnabled(false);
122 QMenu *menu = new QMenu(this);
123 menu->addAction(showBuffersAction);
124 menu->addAction(showNicksAction);
125 menu->addSeparator();
126 menu->addAction(toolBar->toggleViewAction());
127 menu->addSeparator();
128 menu->addAction(tr("About..."), this, SLOT(showAboutDlg()));
130 QSoftMenuBar::addMenuTo(this, menu);
133 void QtopiaMainWin::connectedToCore() {
134 foreach(BufferInfo id, Client::allBufferInfos()) {
135 Client::backlogManager()->requestBacklog(id.bufferId(), 500, -1);
139 void QtopiaMainWin::disconnectedFromCore() {
144 AbstractUiMsg *QtopiaMainWin::layoutMsg(const Message &msg) {
145 return new ChatLine(msg);
149 void QtopiaMainWin::showBuffer(BufferId id) {
150 nickListWidget->setBuffer(id);
151 Buffer *b = Client::buffer(id);
152 //showNicksAction->setEnabled(b && b->bufferInfo().type() == BufferInfo::ChannelBuffer); FIXME enable again when we have a nicklist!
156 void QtopiaMainWin::showBufferView() {
157 if(!bufferViewWidget) {
158 bufferViewWidget = new BufferViewWidget(this);
159 connect(mainWidget, SIGNAL(currentChanged(BufferId)), bufferViewWidget, SLOT(accept()));
161 bufferViewWidget->showMaximized();
164 void QtopiaMainWin::showNickList() {
165 nickListWidget->showMaximized();
168 void QtopiaMainWin::showAboutDlg() {
169 QDialog *dlg = new QDialog(this);
170 dlg->setAttribute(Qt::WA_DeleteOnClose);
173 dlg->showMaximized();