* Use Haui's new channelwidget. Yeah, it's still just a telnet client, but it looks...
[quassel.git] / gui / mainwin.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005 by The Quassel 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 <QtGui>
22 #include <QtCore>
23
24 #include "global.h"
25
26 #include "mainwin.h"
27 #include "channelwidget.h"
28 #include "serverlist.h"
29 #include "coreconnectdlg.h"
30
31 MainWin::MainWin() : QMainWindow() {
32
33   setWindowTitle("Quassel IRC");
34   setWindowIcon(QIcon(":/qirc-icon.png"));
35   setWindowIconText("Quassel IRC");
36
37   QSettings s;
38   s.beginGroup("Geometry");
39   resize(s.value("MainWinSize", QSize(500, 400)).toSize());
40   move(s.value("MainWinPos", QPoint(50, 50)).toPoint());
41   s.endGroup();
42
43   //workspace = new QWorkspace(this);
44   //setCentralWidget(workspace);
45   //ChannelWidget *cw = new ChannelWidget(this);
46   //workspace->addWindow(cw);
47   //setCentralWidget(cw);
48   statusBar()->showMessage(tr("Waiting for core..."));
49   setEnabled(false);
50   show();
51   syncToCore();
52   setEnabled(true);
53   serverListDlg = new ServerListDlg(this);
54   serverListDlg->setVisible(serverListDlg->showOnStartup());
55   setupMenus();
56   //identitiesAct = settingsMenu->addAction(QIcon(":/default/identity.png"), tr("&Identities..."), serverListDlg, SLOT(editIdentities()));
57   //showServerList();
58   ChannelWidget *cw = new ChannelWidget(this);
59   setCentralWidget(cw);
60   //setEnabled(true);
61   statusBar()->showMessage(tr("Ready."));
62 }
63
64 void MainWin::syncToCore() {
65   if(global->getData("CoreReady").toBool()) return;
66   // ok, apparently we are running as standalone GUI
67   coreConnectDlg = new CoreConnectDlg(this);
68   if(coreConnectDlg->exec() != QDialog::Accepted) {
69     //qApp->quit();
70     exit(1);
71   }
72   VarMap state = coreConnectDlg->getCoreState().toMap()["CoreData"].toMap();
73   delete coreConnectDlg;
74   QString key;
75   foreach(key, state.keys()) {
76     global->updateData(key, state[key]);
77   }
78   if(!global->getData("CoreReady").toBool()) {
79     QMessageBox::critical(this, tr("Fatal Error"), tr("<b>Could not synchronize with Quassel Core!</b><br>Quassel GUI will be aborted."), QMessageBox::Abort);
80     //qApp->quit();
81     exit(1);
82   }
83 }
84
85 void MainWin::setupMenus() {
86   fileMenu = menuBar()->addMenu(tr("&File"));
87   serverListAct = fileMenu->addAction(QIcon(":/default/server.png"), tr("&Server List..."), this, SLOT(showServerList()), tr("F7"));
88   fileMenu->addSeparator();
89   quitAct = fileMenu->addAction(QIcon(":/default/exit.png"), tr("&Quit"), qApp, SLOT(quit()), tr("CTRL+Q"));
90
91   editMenu = menuBar()->addMenu(tr("&Edit"));
92   editMenu->setEnabled(0);
93
94   ircMenu = menuBar()->addMenu(tr("&IRC"));
95   ircMenu->setEnabled(0);
96
97   serverMenu = menuBar()->addMenu(tr("Ser&ver"));
98   serverMenu->setEnabled(0);
99
100   windowMenu = menuBar()->addMenu(tr("&Window"));
101   windowMenu->setEnabled(0);
102
103   settingsMenu = menuBar()->addMenu(tr("&Settings"));
104   identitiesAct = settingsMenu->addAction(QIcon(":/default/identity.png"), tr("&Identities..."), serverListDlg, SLOT(editIdentities()));
105   settingsMenu->addSeparator();
106   configAct = settingsMenu->addAction(QIcon(":/default/configure.png"), tr("&Configure Quassel..."));
107   configAct->setEnabled(0);
108
109   helpMenu = menuBar()->addMenu(tr("&Help"));
110   aboutAct = helpMenu->addAction(tr("&About"));
111   aboutAct->setEnabled(0);
112   aboutQtAct = helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));
113
114   //toolBar = new QToolBar("Test", this);
115   //toolBar->addAction(identitiesAct);
116   //addToolBar(Qt::TopToolBarArea, toolBar);
117 }
118
119 void MainWin::showServerList() {
120 //  if(!serverListDlg) {
121 //    serverListDlg = new ServerListDlg(this);
122 //  }
123   serverListDlg->show();
124 }
125
126 void MainWin::closeEvent(QCloseEvent *event)
127 {
128   //if (userReallyWantsToQuit()) {
129     QSettings s;
130     s.beginGroup("Geometry");
131     s.setValue("MainWinSize", size());
132     s.setValue("MainWinPos", pos());
133     s.endGroup();
134     event->accept();
135   //} else {
136     //event->ignore();
137   //}
138 }