5ba655d80be641849d641d1d06a260007202e844
[quassel.git] / src / qtopia / qtopiamainwin.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by the Quassel IRC Team                         *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #include "qtopiamainwin.h"
22
23 #include "buffertreemodel.h"
24 #include "bufferviewwidget.h"
25 #include "nicklistwidget.h"
26 #include "chatline.h"
27 #include "coreconnectdlg.h"
28 #include "global.h"
29 #include "mainwidget.h"
30 #include "message.h"
31 #include "qtopiaui.h"
32 #include "signalproxy.h"
33
34 #include <Qtopia>
35 #include <QSoftMenuBar>
36
37 #define DEBUGMODE
38
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");
48
49   Global::runMode = Global::ClientOnly;
50
51   QCoreApplication::setOrganizationDomain("quassel-irc.org");
52   QCoreApplication::setApplicationName("Quassel IRC");
53   QCoreApplication::setOrganizationName("Quassel IRC Team");
54
55   QtopiaUi *gui = new QtopiaUi(this);
56   Client::init(gui);
57
58   setWindowTitle("Quassel IRC");
59   setWindowIcon(QIcon(":/qirc-icon.png"));
60   setWindowIconText("Quassel IRC");
61
62   mainWidget = new MainWidget(this);
63   setCentralWidget(mainWidget);
64
65   BufferTreeModel *model = Client::bufferModel();
66   connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
67
68   toolBar = new QToolBar(this);
69   toolBar->setIconSize(QSize(16, 16));
70   addToolBar(toolBar);
71
72   bufferViewWidget = new BufferViewWidget(this);
73   nickListWidget = new NickListWidget(this);
74
75   setupActions();
76
77   init();
78   //gui->init();
79
80 }
81
82 // at this point, client is fully initialized
83 void QtopiaMainWin::init() {
84   Client::signalProxy()->attachSignal(this, SIGNAL(requestBacklog(BufferInfo, QVariant, QVariant)));
85
86   showMaximized();
87   CoreConnectDlg *dlg = new CoreConnectDlg(this);
88   //setCentralWidget(dlg);
89   dlg->showMaximized();
90   dlg->exec();
91 }
92
93 QtopiaMainWin::~QtopiaMainWin() {
94
95
96 }
97
98 void QtopiaMainWin::closeEvent(QCloseEvent *event) {
99 #ifndef DEBUGMODE
100   QMessageBox *box = new QMessageBox(QMessageBox::Question, tr("Quit Quassel IRC?"), tr("Do you really want to quit Quassel IRC?"),
101                                      QMessageBox::Cancel, this);
102   QAbstractButton *quit = box->addButton(tr("Quit"), QMessageBox::AcceptRole);
103   box->exec();
104   if(box->clickedButton() == quit) event->accept();
105   else event->ignore();
106   box->deleteLater();
107 #else
108   event->accept();
109 #endif
110 }
111
112 void QtopiaMainWin::setupActions() {
113   showBuffersAction = toolBar->addAction(QIcon(":icon/options-hide"), "Show Buffers", this, SLOT(showBufferView()));  // FIXME provide real icon
114   showNicksAction = toolBar->addAction(QIcon(":icon/list"), "Show Nicks", this, SLOT(showNickList()));
115
116   QMenu *menu = new QMenu(this);
117   menu->addAction(showBuffersAction);
118   menu->addAction(showNicksAction);
119   QSoftMenuBar::addMenuTo(this, menu);
120 }
121
122 void QtopiaMainWin::connectedToCore() {
123   foreach(BufferInfo id, Client::allBufferInfos()) {
124     emit requestBacklog(id, 100, -1);
125   }
126
127 #ifdef DEBUGMODE
128   // FIXME just for testing: select first available buffer
129   if(Client::allBufferInfos().count() > 1) {
130     Buffer *b = Client::buffer(Client::allBufferInfos()[1]);
131     Client::bufferModel()->selectBuffer(b);
132   }
133 #endif
134 }
135
136 void QtopiaMainWin::disconnectedFromCore() {
137
138
139 }
140
141 AbstractUiMsg *QtopiaMainWin::layoutMsg(const Message &msg) {
142   return new ChatLine(msg);
143   //return 0;
144 }
145
146 void QtopiaMainWin::showBuffer(Buffer *b) {
147   mainWidget->setBuffer(b);
148   bufferViewWidget->hide();
149   nickListWidget->setBuffer(b);
150
151 }
152
153 void QtopiaMainWin::showBufferView() {
154   bufferViewWidget->showMaximized();
155
156 }
157
158 void QtopiaMainWin::showNickList() {
159   nickListWidget->showMaximized();
160 }
161
162