db8de04e3c539fd8e0904fd2aa45a1ff4de495cb
[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
23 #include "global.h"
24
25 #include "mainwin.h"
26 #include "channelwidget.h"
27 #include "serverlist.h"
28 #include "coreconnectdlg.h"
29
30 MainWin::MainWin() : QMainWindow() {
31
32   setWindowTitle("Quassel IRC");
33   setWindowIcon(QIcon(":/qirc-icon.png"));
34   setWindowIconText("Quassel IRC");
35   //workspace = new QWorkspace(this);
36   //setCentralWidget(workspace);
37   //ChannelWidget *cw = new ChannelWidget(this);
38   //workspace->addWindow(cw);
39   //setCentralWidget(cw);
40   statusBar()->showMessage(tr("Waiting for core..."));
41   setEnabled(false);
42   show();
43   syncToCore();
44   setEnabled(true);
45   serverListDlg = new ServerListDlg(this);
46   serverListDlg->setVisible(serverListDlg->showOnStartup());
47   setupMenus();
48   //identitiesAct = settingsMenu->addAction(QIcon(":/default/identity.png"), tr("&Identities..."), serverListDlg, SLOT(editIdentities()));
49   //showServerList();
50   ChannelWidget *cw = new ChannelWidget(this);
51   setCentralWidget(cw);
52   //setEnabled(true);
53   statusBar()->showMessage(tr("Ready."));
54 }
55
56 void MainWin::syncToCore() {
57   if(global->getData("CoreReady").toBool()) return;
58   // ok, apparently we are running as standalone GUI
59   coreConnectDlg = new CoreConnectDlg(this);
60   if(coreConnectDlg->exec() != QDialog::Accepted) {
61     //qApp->quit();
62     exit(1);
63   }
64   VarMap state = coreConnectDlg->getCoreState().toMap()["CoreData"].toMap();
65   delete coreConnectDlg;
66   QString key;
67   foreach(key, state.keys()) {
68     global->updateData(key, state[key]);
69   }
70   if(!global->getData("CoreReady").toBool()) {
71     QMessageBox::critical(this, tr("Fatal Error"), tr("<b>Could not synchronize with Quassel Core!</b><br>Quassel GUI will be aborted."), QMessageBox::Abort);
72     //qApp->quit();
73     exit(1);
74   }
75 }
76
77 void MainWin::setupMenus() {
78   fileMenu = menuBar()->addMenu(tr("&File"));
79   serverListAct = fileMenu->addAction(QIcon(":/default/server.png"), tr("&Server List..."), this, SLOT(showServerList()), tr("F7"));
80   fileMenu->addSeparator();
81   quitAct = fileMenu->addAction(QIcon(":/default/exit.png"), tr("&Quit"), qApp, SLOT(quit()), tr("CTRL+Q"));
82
83   editMenu = menuBar()->addMenu(tr("&Edit"));
84   editMenu->setEnabled(0);
85
86   ircMenu = menuBar()->addMenu(tr("&IRC"));
87   ircMenu->setEnabled(0);
88
89   serverMenu = menuBar()->addMenu(tr("Ser&ver"));
90   serverMenu->setEnabled(0);
91
92   windowMenu = menuBar()->addMenu(tr("&Window"));
93   windowMenu->setEnabled(0);
94
95   settingsMenu = menuBar()->addMenu(tr("&Settings"));
96   identitiesAct = settingsMenu->addAction(QIcon(":/default/identity.png"), tr("&Identities..."), serverListDlg, SLOT(editIdentities()));
97   settingsMenu->addSeparator();
98   configAct = settingsMenu->addAction(QIcon(":/default/configure.png"), tr("&Configure Quassel..."));
99   configAct->setEnabled(0);
100
101   helpMenu = menuBar()->addMenu(tr("&Help"));
102   aboutAct = helpMenu->addAction(tr("&About"));
103   aboutAct->setEnabled(0);
104   aboutQtAct = helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));
105
106   //toolBar = new QToolBar("Test", this);
107   //toolBar->addAction(identitiesAct);
108   //addToolBar(Qt::TopToolBarArea, toolBar);
109 }
110
111 void MainWin::showServerList() {
112 //  if(!serverListDlg) {
113 //    serverListDlg = new ServerListDlg(this);
114 //  }
115   serverListDlg->show();
116 }
117