225823f6b5759e5d297ac728cfc9332575755840
[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 "chatline.h"
25 #include "coreconnectdlg.h"
26 #include "global.h"
27 #include "mainwidget.h"
28 #include "message.h"
29 #include "qtopiaui.h"
30 #include "signalproxy.h"
31
32 // This constructor is the first thing to be called for a Qtopia app, so we do the init stuff
33 // here (rather than in a main.cpp).
34 QtopiaMainWin::QtopiaMainWin(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags) {
35   qRegisterMetaType<QVariant>("QVariant");
36   qRegisterMetaType<Message>("Message");
37   qRegisterMetaType<BufferInfo>("BufferInfo");
38   qRegisterMetaTypeStreamOperators<QVariant>("QVariant");
39   qRegisterMetaTypeStreamOperators<Message>("Message");
40   qRegisterMetaTypeStreamOperators<BufferInfo>("BufferInfo");
41
42   Global::runMode = Global::ClientOnly;
43
44   QCoreApplication::setOrganizationDomain("quassel-irc.org");
45   QCoreApplication::setApplicationName("Quassel IRC");
46   QCoreApplication::setOrganizationName("Quassel IRC Team");
47
48   QSettings s(QSettings::UserScope, "quassel", "quassel");
49   s.setValue("foo", "bar");
50   
51   //Style::init();
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   QToolBar *toolBar = new QToolBar(this);
63   toolBar->setIconSize(QSize(16, 16));
64   toolBar->addAction(QIcon(":icon/trash"), "Trash");
65   addToolBar(toolBar);
66
67   init();
68   //gui->init();
69
70 }
71
72 // at this point, client is fully initialized
73 void QtopiaMainWin::init() {
74   Client::signalProxy()->attachSignal(this, SIGNAL(requestBacklog(BufferInfo, QVariant, QVariant)));
75   connect(Client::bufferModel(), SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
76
77   CoreConnectDlg *dlg = new CoreConnectDlg(this);
78   //setCentralWidget(dlg);
79   dlg->showMaximized();
80   dlg->exec();
81 }
82
83 QtopiaMainWin::~QtopiaMainWin() {
84
85
86 }
87
88 void QtopiaMainWin::connectedToCore() {
89   foreach(BufferInfo id, Client::allBufferInfos()) {
90     emit requestBacklog(id, 100, -1);
91   }
92   // FIXME just for testing: select first available buffer
93   if(Client::allBufferInfos().count() > 1) {
94     Buffer *b = Client::buffer(Client::allBufferInfos()[1]);
95     Client::bufferModel()->selectBuffer(b);
96   }
97 }
98
99 void QtopiaMainWin::disconnectedFromCore() {
100
101
102 }
103
104 AbstractUiMsg *QtopiaMainWin::layoutMsg(const Message &msg) {
105   return new ChatLine(msg);
106   //return 0;
107 }
108
109 void QtopiaMainWin::showBuffer(Buffer *b) {
110   mainWidget->setBuffer(b);
111
112 }