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