Removing the new chatwidget and other cruft from trunk (which is now our 0.2 branch)
[quassel.git] / src / qtopia / qtopiamainwin.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
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 "networkmodel.h"
24 #include "bufferviewwidget.h"
25 #include "nicklistwidget.h"
26 #include "chatline.h"
27 #include "clientbacklogmanager.h"
28 #include "coreconnectdlg.h"
29 #include "global.h"
30 #include "mainwidget.h"
31 #include "message.h"
32 #include "network.h"
33 #include "qtopiaui.h"
34 #include "signalproxy.h"
35
36 #include "ui_aboutdlg.h"
37
38 #include <Qtopia>
39 #include <QSoftMenuBar>
40
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();
45
46 #include "../../version.inc"
47
48   Global::runMode = Global::ClientOnly;
49   Global::defaultPort = 4242;
50
51   Network::setDefaultCodecForServer("ISO-8859-1");
52   Network::setDefaultCodecForEncoding("UTF-8");
53   Network::setDefaultCodecForDecoding("ISO-8859-15");
54
55   QCoreApplication::setOrganizationDomain("quassel-irc.org");
56   QCoreApplication::setApplicationName("Quassel IRC");
57   QCoreApplication::setOrganizationName("Quassel Project");
58
59   QtopiaUi *gui = new QtopiaUi(this);
60   Client::init(gui);
61
62   setWindowTitle("Quassel IRC");
63   setWindowIcon(QIcon(":icons/quassel-icon.png"));
64   setWindowIconText("Quassel IRC");
65
66   mainWidget = new MainWidget(this);
67   mainWidget->setModel(Client::bufferModel());
68   mainWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
69   setCentralWidget(mainWidget);
70
71   toolBar = new QToolBar(this);
72   toolBar->setIconSize(QSize(16, 16));
73   toolBar->setWindowTitle(tr("Show Toolbar"));
74   addToolBar(toolBar);
75
76   //bufferViewWidget = new BufferViewWidget(this);
77   bufferViewWidget = 0;  // delayed creation to avoid QPainter warnings
78   nickListWidget = new NickListWidget(this);
79
80   connect(mainWidget, SIGNAL(currentChanged(BufferId)), this, SLOT(showBuffer(BufferId)));
81
82   setupActions();
83
84   init();
85   //gui->init();
86
87 }
88
89 // at this point, client is fully initialized
90 void QtopiaMainWin::init() {
91   showMaximized();
92   CoreConnectDlg *dlg = new CoreConnectDlg(this);
93   //setCentralWidget(dlg);
94   dlg->showMaximized();
95   dlg->exec();
96 }
97
98 QtopiaMainWin::~QtopiaMainWin() {
99
100
101 }
102
103 void QtopiaMainWin::closeEvent(QCloseEvent *event) {
104 #ifndef DEVELMODE
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);
108   box->exec();
109   if(box->clickedButton() == quit) event->accept();
110   else event->ignore();
111   box->deleteLater();
112 #else
113   event->accept();
114 #endif
115 }
116
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);
121
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()));
129
130   QSoftMenuBar::addMenuTo(this, menu);
131 }
132
133 void QtopiaMainWin::connectedToCore() {
134   foreach(BufferInfo id, Client::allBufferInfos()) {
135     Client::backlogManager()->requestBacklog(id.bufferId(), 500, -1);
136   }
137 }
138
139 void QtopiaMainWin::disconnectedFromCore() {
140
141
142 }
143
144 AbstractUiMsg *QtopiaMainWin::layoutMsg(const Message &msg) {
145   return new ChatLine(msg);
146   //return 0;
147 }
148
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!
153
154 }
155
156 void QtopiaMainWin::showBufferView() {
157   if(!bufferViewWidget) {
158     bufferViewWidget = new BufferViewWidget(this);
159     connect(mainWidget, SIGNAL(currentChanged(BufferId)), bufferViewWidget, SLOT(accept()));
160   }
161   bufferViewWidget->showMaximized();
162 }
163
164 void QtopiaMainWin::showNickList() {
165   nickListWidget->showMaximized();
166 }
167
168 void QtopiaMainWin::showAboutDlg() {
169   QDialog *dlg = new QDialog(this);
170   dlg->setAttribute(Qt::WA_DeleteOnClose);
171   Ui::AboutDlg ui;
172   ui.setupUi(dlg);
173   dlg->showMaximized();
174 }
175