~quassel-dev/quassel/i18n-master

« back to all changes in this revision

Viewing changes to main/main_gui.cpp

  • Committer: Manuel Nickschas
  • Date: 2007-06-20 01:21:00 UTC
  • Revision ID: git-v1:077d44f36d2f5c730283ef6be839aea7dd073d56
Starting reorganization of files in preparation of separation of client and GUI.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 <iostream>
22
 
 
23
 
#include <QtGui>
24
 
#include <QApplication>
25
 
 
26
 
#include "style.h"
27
 
#include "global.h"
28
 
#include "guiproxy.h"
29
 
#include "coreconnectdlg.h"
30
 
#include "util.h"
31
 
#include "chatwidget.h"
32
 
 
33
 
#include "mainwin.h"
34
 
 
35
 
int main(int argc, char **argv) {
36
 
  QApplication app(argc, argv);
37
 
  QApplication::setOrganizationDomain("quassel-irc.org");
38
 
  QApplication::setApplicationName("Quassel IRC");
39
 
  QApplication::setOrganizationName("The Quassel Team");
40
 
 
41
 
  Global::runMode = Global::GUIOnly;
42
 
  Global::quasselDir = QDir::homePath() + "/.quassel";
43
 
 
44
 
  global = new Global();
45
 
  guiProxy = new GuiProxy();
46
 
 
47
 
  Style::init();
48
 
 
49
 
  MainWin mainWin;
50
 
  mainWin.init();
51
 
  int exitCode = app.exec();
52
 
  delete guiProxy;
53
 
  delete global;
54
 
  return exitCode;
55
 
}
56
 
 
57
 
void MainWin::syncToCore() {
58
 
  Q_ASSERT(!global->getData("CoreReady").toBool());
59
 
  // ok, we are running as standalone GUI
60
 
  coreConnectDlg = new CoreConnectDlg(this);
61
 
  if(coreConnectDlg->exec() != QDialog::Accepted) {
62
 
    //qApp->quit();
63
 
    exit(1);
64
 
  }
65
 
  VarMap state = coreConnectDlg->getCoreState().toMap();
66
 
  delete coreConnectDlg;
67
 
  VarMap data = state["CoreData"].toMap();
68
 
  QString key;
69
 
  foreach(key, data.keys()) {
70
 
    global->updateData(key, data[key]);
71
 
  }
72
 
  if(!global->getData("CoreReady").toBool()) {
73
 
    QMessageBox::critical(this, tr("Fatal Error"), tr("<b>Could not synchronize with Quassel Core!</b><br>Quassel GUI will be aborted."), QMessageBox::Abort);
74
 
    //qApp->quit();
75
 
    exit(1);
76
 
  }
77
 
  /*
78
 
  foreach(QString net, state["CoreBackLog"].toMap().keys()) {
79
 
    QByteArray logbuf = state["CoreBackLog"].toMap()[net].toByteArray();
80
 
    QDataStream in(&logbuf, QIODevice::ReadOnly); in.setVersion(QDataStream::Qt_4_2);
81
 
    while(!in.atEnd()) {
82
 
      Message msg; in >> msg;
83
 
      coreBackLog[net].append(msg);
84
 
    }
85
 
    qDebug() << net << coreBackLog[net].count();
86
 
  }
87
 
  */
88
 
  coreBuffers.clear();
89
 
  foreach(QVariant v, state["CoreBuffers"].toList()) { coreBuffers.append(v.value<BufferId>()); }
90
 
}
91
 
 
92
 
/*
93
 
 
94
 
GuiProxy::GuiProxy() {
95
 
  if(guiProxy) qFatal("Trying to instantiate more than one CoreProxy object!");
96
 
 
97
 
  blockSize = 0;
98
 
 
99
 
  connect(&socket, SIGNAL(readyRead()), this, SLOT(serverHasData()));
100
 
  connect(&socket, SIGNAL(connected()), this, SIGNAL(coreConnected()));
101
 
  connect(&socket, SIGNAL(disconnected()), this, SIGNAL(coreDisconnected()));
102
 
  connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(serverError(QAbstractSocket::SocketError)));
103
 
 
104
 
  connect(global, SIGNAL(dataPutLocally(QString)), this, SLOT(updateCoreData(QString)));
105
 
  connect(this, SIGNAL(csUpdateGlobalData(QString, QVariant)), global, SLOT(updateData(QString, QVariant)));
106
 
 
107
 
}
108
 
 
109
 
void GuiProxy::connectToCore(QString host, quint16 port) {
110
 
  socket.connectToHost(host, port);
111
 
}
112
 
 
113
 
void GuiProxy::disconnectFromCore() {
114
 
  socket.close();
115
 
}
116
 
 
117
 
void GuiProxy::serverError(QAbstractSocket::SocketError) {
118
 
  emit coreConnectionError(socket.errorString());
119
 
  //qFatal(QString("Connection error: %1").arg(socket.errorString()).toAscii());
120
 
}
121
 
 
122
 
void GuiProxy::serverHasData() {
123
 
  QVariant item;
124
 
  while(readDataFromDevice(&socket, blockSize, item)) {
125
 
    emit recvPartialItem(1,1);
126
 
    QList<QVariant> sigdata = item.toList();
127
 
    Q_ASSERT(sigdata.size() == 4);
128
 
    recv((CoreSignal)sigdata[0].toInt(), sigdata[1], sigdata[2], sigdata[3]);
129
 
    blockSize = 0;
130
 
  }
131
 
  if(blockSize > 0) {
132
 
    emit recvPartialItem(socket.bytesAvailable(), blockSize);
133
 
  }
134
 
}
135
 
*/
136
 
/*
137
 
void GuiProxy::send(GuiSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) {
138
 
  QList<QVariant> sigdata;
139
 
  sigdata.append(sig); sigdata.append(arg1); sigdata.append(arg2); sigdata.append(arg3);
140
 
  //qDebug() << "Sending signal: " << sigdata;
141
 
  writeDataToDevice(&socket, QVariant(sigdata));
142
 
}
143
 
*/
144
 
 
145
 
void GuiProxy::updateCoreData(QString key) {
146
 
  QVariant data = global->getData(key);
147
 
  send(GS_UPDATE_GLOBAL_DATA, key, data);
148
 
}