More neato stuff. A preliminary TabWidget now allows us to display multiple buffers,
[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   statusBar()->showMessage(tr("Waiting for core..."));
46   setEnabled(false);
47   show();
48   syncToCore();
49   setEnabled(true);
50   serverListDlg = new ServerListDlg(this);
51   serverListDlg->setVisible(serverListDlg->showOnStartup());
52   setupMenus();
53   //identitiesAct = settingsMenu->addAction(QIcon(":/default/identity.png"), tr("&Identities..."), serverListDlg, SLOT(editIdentities()));
54   //showServerList();
55   IrcWidget *cw = new IrcWidget(this);
56   setCentralWidget(cw);
57   //workspace->addWindow(cw);
58   //cw->showMaximized();
59   statusBar()->showMessage(tr("Ready."));
60   cw->setFocus();
61 }
62
63 void MainWin::syncToCore() {
64   if(global->getData("CoreReady").toBool()) return;
65   // ok, apparently we are running as standalone GUI
66   coreConnectDlg = new CoreConnectDlg(this);
67   if(coreConnectDlg->exec() != QDialog::Accepted) {
68     //qApp->quit();
69     exit(1);
70   }
71   VarMap state = coreConnectDlg->getCoreState().toMap()["CoreData"].toMap();
72   delete coreConnectDlg;
73   QString key;
74   foreach(key, state.keys()) {
75     global->updateData(key, state[key]);
76   }
77   if(!global->getData("CoreReady").toBool()) {
78     QMessageBox::critical(this, tr("Fatal Error"), tr("<b>Could not synchronize with Quassel Core!</b><br>Quassel GUI will be aborted."), QMessageBox::Abort);
79     //qApp->quit();
80     exit(1);
81   }
82 }
83
84 void MainWin::setupMenus() {
85   fileMenu = menuBar()->addMenu(tr("&File"));
86   serverListAct = fileMenu->addAction(QIcon(":/default/server.png"), tr("&Server List..."), this, SLOT(showServerList()), tr("F7"));
87   fileMenu->addSeparator();
88   quitAct = fileMenu->addAction(QIcon(":/default/exit.png"), tr("&Quit"), qApp, SLOT(quit()), tr("CTRL+Q"));
89
90   editMenu = menuBar()->addMenu(tr("&Edit"));
91   editMenu->setEnabled(0);
92
93   ircMenu = menuBar()->addMenu(tr("&IRC"));
94   ircMenu->setEnabled(0);
95
96   serverMenu = menuBar()->addMenu(tr("Ser&ver"));
97   serverMenu->setEnabled(0);
98
99   windowMenu = menuBar()->addMenu(tr("&Window"));
100   windowMenu->setEnabled(0);
101
102   settingsMenu = menuBar()->addMenu(tr("&Settings"));
103   identitiesAct = settingsMenu->addAction(QIcon(":/default/identity.png"), tr("&Identities..."), serverListDlg, SLOT(editIdentities()));
104   settingsMenu->addSeparator();
105   configAct = settingsMenu->addAction(QIcon(":/default/configure.png"), tr("&Configure Quassel..."));
106   configAct->setEnabled(0);
107
108   helpMenu = menuBar()->addMenu(tr("&Help"));
109   aboutAct = helpMenu->addAction(tr("&About"));
110   aboutAct->setEnabled(0);
111   aboutQtAct = helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));
112
113   //toolBar = new QToolBar("Test", this);
114   //toolBar->addAction(identitiesAct);
115   //addToolBar(Qt::TopToolBarArea, toolBar);
116 }
117
118 void MainWin::showServerList() {
119 //  if(!serverListDlg) {
120 //    serverListDlg = new ServerListDlg(this);
121 //  }
122   serverListDlg->show();
123 }
124
125 void MainWin::closeEvent(QCloseEvent *event)
126 {
127   //if (userReallyWantsToQuit()) {
128     QSettings s;
129     s.beginGroup("Geometry");
130     s.setValue("MainWinSize", size());
131     s.setValue("MainWinPos", pos());
132     s.endGroup();
133     event->accept();
134   //} else {
135     //event->ignore();
136   //}
137 }