OK, another update. This is just prior to redoing the MainWin completely.
[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   ui.setupUi(this);
33
34   setWindowTitle("Quassel IRC");
35   setWindowIcon(QIcon(":/qirc-icon.png"));
36   setWindowIconText("Quassel IRC");
37
38   QSettings s;
39   s.beginGroup("Geometry");
40   resize(s.value("MainWinSize", QSize(500, 400)).toSize());
41   move(s.value("MainWinPos", QPoint(50, 50)).toPoint());
42   s.endGroup();
43
44   //workspace = new QWorkspace(this);
45   //setCentralWidget(workspace);
46   statusBar()->showMessage(tr("Waiting for core..."));
47   setEnabled(false);
48   show();
49   syncToCore();
50   setEnabled(true);
51   serverListDlg = new ServerListDlg(this);
52   serverListDlg->setVisible(serverListDlg->showOnStartup());
53   setupMenus();
54   //identitiesAct = settingsMenu->addAction(QIcon(":/default/identity.png"), tr("&Identities..."), serverListDlg, SLOT(editIdentities()));
55   //showServerList();
56   IrcWidget *cw = new IrcWidget(this);
57   setCentralWidget(cw);
58   //workspace->addWindow(cw);
59   //cw->showMaximized();
60   statusBar()->showMessage(tr("Ready."));
61   cw->setFocus();
62 }
63
64 void MainWin::setupMenus() {
65   connect(ui.actionNetworkList, SIGNAL(activated()), this, SLOT(showServerList()));
66   connect(ui.actionEditIdentities, SIGNAL(activated()), serverListDlg, SLOT(editIdentities()));
67 }
68
69 void MainWin::syncToCore() {
70   if(global->getData("CoreReady").toBool()) return;
71   // ok, apparently we are running as standalone GUI
72   coreConnectDlg = new CoreConnectDlg(this);
73   if(coreConnectDlg->exec() != QDialog::Accepted) {
74     //qApp->quit();
75     exit(1);
76   }
77   VarMap state = coreConnectDlg->getCoreState().toMap()["CoreData"].toMap();
78   delete coreConnectDlg;
79   QString key;
80   foreach(key, state.keys()) {
81     global->updateData(key, state[key]);
82   }
83   if(!global->getData("CoreReady").toBool()) {
84     QMessageBox::critical(this, tr("Fatal Error"), tr("<b>Could not synchronize with Quassel Core!</b><br>Quassel GUI will be aborted."), QMessageBox::Abort);
85     //qApp->quit();
86     exit(1);
87   }
88 }
89
90 void MainWin::showServerList() {
91 //  if(!serverListDlg) {
92 //    serverListDlg = new ServerListDlg(this);
93 //  }
94   serverListDlg->show();
95 }
96
97 void MainWin::closeEvent(QCloseEvent *event)
98 {
99   //if (userReallyWantsToQuit()) {
100     QSettings s;
101     s.beginGroup("Geometry");
102     s.setValue("MainWinSize", size());
103     s.setValue("MainWinPos", pos());
104     s.endGroup();
105     event->accept();
106   //} else {
107     //event->ignore();
108   //}
109 }