/***************************************************************************
- * Copyright (C) 2005-07 by The Quassel IRC Development Team *
+ * Copyright (C) 2005-07 by the Quassel IRC Team *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
+ * (at your option) version 3. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#include "signalproxy.h"
#include "storage.h"
-#include "synchronizer.h"
#include "networkinfo.h"
#include "ircuser.h"
#include "ircchannel.h"
#include "util.h"
+#include <QtScript>
CoreSession::CoreSession(UserId uid, Storage *_storage, QObject *parent)
: QObject(parent),
user(uid),
_signalProxy(new SignalProxy(SignalProxy::Server, 0, this)),
- storage(_storage)
+ storage(_storage),
+ scriptEngine(new QScriptEngine(this))
{
-
+
QSettings s;
s.beginGroup(QString("SessionData/%1").arg(user));
mutex.lock();
p->attachSlot(SIGNAL(requestNetworkStates()), this, SLOT(serverStateRequested()));
p->attachSlot(SIGNAL(requestConnect(QString)), this, SLOT(connectToNetwork(QString)));
p->attachSlot(SIGNAL(sendInput(BufferInfo, QString)), this, SLOT(msgFromGui(BufferInfo, QString)));
- p->attachSlot(SIGNAL(importOldBacklog()), storage, SLOT(importOldBacklog()));
p->attachSlot(SIGNAL(requestBacklog(BufferInfo, QVariant, QVariant)), this, SLOT(sendBacklog(BufferInfo, QVariant, QVariant)));
p->attachSignal(this, SIGNAL(displayMsg(Message)));
p->attachSignal(this, SIGNAL(displayStatusMsg(QString, QString)));
p->attachSignal(this, SIGNAL(sessionDataChanged(const QString &, const QVariant &)), SIGNAL(coreSessionDataChanged(const QString &, const QVariant &)));
p->attachSlot(SIGNAL(clientSessionDataChanged(const QString &, const QVariant &)), this, SLOT(storeSessionData(const QString &, const QVariant &)));
/* Autoconnect. (When) do we actually do this?
+ --> session restore should be enough!
QStringList list;
QVariantMap networks = retrieveSessionData("Networks").toMap();
foreach(QString net, networks.keys()) {
} qDebug() << list;
if(list.count()) connectToIrc(list);
*/
+
+ initScriptEngine();
}
CoreSession::~CoreSession() {
return user;
}
+QVariant CoreSession::state() const {
+ QVariantMap res;
+ QList<QVariant> conn;
+ foreach(Server *server, servers.values()) {
+ if(server->isConnected()) {
+ QVariantMap m;
+ m["Network"] = server->networkName();
+ m["State"] = server->state();
+ conn << m;
+ }
+ }
+ res["ConnectedServers"] = conn;
+ return res;
+}
+
+void CoreSession::restoreState(const QVariant &previousState) {
+ // Session restore
+ QVariantMap state = previousState.toMap();
+ if(state.contains("ConnectedServers")) {
+ foreach(QVariant v, state["ConnectedServers"].toList()) {
+ QVariantMap m = v.toMap();
+ QString net = m["Network"].toString();
+ if(!net.isEmpty()) connectToNetwork(net, m["State"]);
+ }
+ }
+}
+
+
void CoreSession::storeSessionData(const QString &key, const QVariant &data) {
QSettings s;
s.beginGroup(QString("SessionData/%1").arg(user));
}
// FIXME switch to NetworkIDs
-void CoreSession::connectToNetwork(QString network) {
+void CoreSession::connectToNetwork(QString network, const QVariant &previousState) {
uint networkid = getNetworkId(network);
+ if(networkid == 0) {
+ qWarning() << "unable to connect to Network" << network << "(User:" << userId() << "): unable to determine NetworkId";
+ return;
+ }
if(!servers.contains(networkid)) {
- Server *server = new Server(userId(), networkid, network);
+ Server *server = new Server(userId(), networkid, network, previousState);
servers[networkid] = server;
attachServer(server);
server->start();
}
if(log.count() > 0) emit backlogData(id, log, true);
}
+
+
+void CoreSession::initScriptEngine() {
+ signalProxy()->attachSlot(SIGNAL(scriptRequest(QString)), this, SLOT(scriptRequest(QString)));
+ signalProxy()->attachSignal(this, SIGNAL(scriptResult(QString)));
+
+ QScriptValue storage_ = scriptEngine->newQObject(storage);
+ scriptEngine->globalObject().setProperty("storage", storage_);
+}
+
+void CoreSession::scriptRequest(QString script) {
+ emit scriptResult(scriptEngine->evaluate(script).toString());
+}
+