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