Now QuasselTopia can actually send text, not only receive!
[quassel.git] / src / qtopia / qtopiamainwin.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by The Quassel IRC Development 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) any later version.                                   *
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
36 // This constructor is the first thing to be called for a Qtopia app, so we do the init stuff
37 // here (rather than in a main.cpp).
38 QtopiaMainWin::QtopiaMainWin(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags) {
39   qRegisterMetaType<QVariant>("QVariant");
40   qRegisterMetaType<Message>("Message");
41   qRegisterMetaType<BufferInfo>("BufferInfo");
42   qRegisterMetaTypeStreamOperators<QVariant>("QVariant");
43   qRegisterMetaTypeStreamOperators<Message>("Message");
44   qRegisterMetaTypeStreamOperators<BufferInfo>("BufferInfo");
45
46   Global::runMode = Global::ClientOnly;
47
48   QCoreApplication::setOrganizationDomain("quassel-irc.org");
49   QCoreApplication::setApplicationName("Quassel IRC");
50   QCoreApplication::setOrganizationName("Quassel IRC Team");
51
52   QtopiaUi *gui = new QtopiaUi(this);
53   Client::init(gui);
54
55   setWindowTitle("Quassel IRC");
56   setWindowIcon(QIcon(":/qirc-icon.png"));
57   setWindowIconText("Quassel IRC");
58
59   mainWidget = new MainWidget(this);
60   setCentralWidget(mainWidget);
61
62   BufferTreeModel *model = Client::bufferModel();
63   connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
64
65   toolBar = new QToolBar(this);
66   toolBar->setIconSize(QSize(16, 16));
67   addToolBar(toolBar);
68
69   bufferViewWidget = new BufferViewWidget(this);
70   nickListWidget = new NickListWidget(this);
71
72   setupActions();
73
74   init();
75   //gui->init();
76
77 }
78
79 // at this point, client is fully initialized
80 void QtopiaMainWin::init() {
81   Client::signalProxy()->attachSignal(this, SIGNAL(requestBacklog(BufferInfo, QVariant, QVariant)));
82
83   CoreConnectDlg *dlg = new CoreConnectDlg(this);
84   //setCentralWidget(dlg);
85   dlg->showMaximized();
86   dlg->exec();
87 }
88
89 QtopiaMainWin::~QtopiaMainWin() {
90
91
92 }
93
94 void QtopiaMainWin::setupActions() {
95   showBuffersAction = toolBar->addAction(QIcon(":icon/options-hide"), "Show Buffers", this, SLOT(showBufferView()));  // FIXME provide real icon
96   showNicksAction = toolBar->addAction(QIcon(":icon/list"), "Show Nicks", this, SLOT(showNickList()));
97
98 }
99
100 void QtopiaMainWin::connectedToCore() {
101   foreach(BufferInfo id, Client::allBufferInfos()) {
102     emit requestBacklog(id, 100, -1);
103   }
104   // FIXME just for testing: select first available buffer
105   if(Client::allBufferInfos().count() > 1) {
106     Buffer *b = Client::buffer(Client::allBufferInfos()[1]);
107     Client::bufferModel()->selectBuffer(b);
108   }
109 }
110
111 void QtopiaMainWin::disconnectedFromCore() {
112
113
114 }
115
116 AbstractUiMsg *QtopiaMainWin::layoutMsg(const Message &msg) {
117   return new ChatLine(msg);
118   //return 0;
119 }
120
121 void QtopiaMainWin::showBuffer(Buffer *b) {
122   mainWidget->setBuffer(b);
123   bufferViewWidget->hide();
124   //nickListWidget->
125
126 }
127
128 void QtopiaMainWin::showBufferView() {
129   bufferViewWidget->showMaximized();
130
131 }
132
133 void QtopiaMainWin::showNickList() {
134   nickListWidget->showMaximized();
135 }
136
137