Basic infrastructure for file transfers
[quassel.git] / src / core / coresession.cpp
index 9b1395b..7fb524a 100644 (file)
@@ -34,6 +34,7 @@
 #include "corenetwork.h"
 #include "corenetworkconfig.h"
 #include "coresessioneventprocessor.h"
+#include "coretransfermanager.h"
 #include "coreusersettings.h"
 #include "ctcpparser.h"
 #include "eventstringifier.h"
@@ -66,6 +67,7 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent)
     _ircListHelper(new CoreIrcListHelper(this)),
     _networkConfig(new CoreNetworkConfig("GlobalNetworkConfig", this)),
     _coreInfo(this),
+    _transferManager(new CoreTransferManager(this)),
     _eventManager(new CoreEventManager(this)),
     _eventStringifier(new EventStringifier(this)),
     _sessionEventProcessor(new CoreSessionEventProcessor(this)),
@@ -120,6 +122,7 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent)
     p->synchronize(networkConfig());
     p->synchronize(&_coreInfo);
     p->synchronize(&_ignoreListManager);
+    p->synchronize(transferManager());
     // Restore session state
     if (restoreState)
         restoreSessionState();
@@ -208,10 +211,7 @@ void CoreSession::restoreSessionState()
 
 void CoreSession::addClient(RemotePeer *peer)
 {
-    QVariantMap reply;
-    reply["MsgType"] = "SessionInit";
-    reply["SessionState"] = sessionState();
-    peer->writeSocketData(reply);
+    peer->dispatch(sessionState());
     signalProxy()->addPeer(peer);
 }
 
@@ -350,7 +350,7 @@ void CoreSession::processMessages()
 
         // recheck if there exists a buffer to store a redirected message in
         for (int i = 0; i < redirectedMessages.count(); i++) {
-            const RawMessage &rawMsg = _messageQueue.at(i);
+            const RawMessage &rawMsg = redirectedMessages.at(i);
             if (bufferInfoCache.contains(rawMsg.networkId) && bufferInfoCache[rawMsg.networkId].contains(rawMsg.target)) {
                 bufferInfo = bufferInfoCache[rawMsg.networkId][rawMsg.target];
             }
@@ -375,34 +375,20 @@ void CoreSession::processMessages()
 }
 
 
-QVariant CoreSession::sessionState()
+Protocol::SessionState CoreSession::sessionState() const
 {
-    QVariantMap v;
-
-    v["CoreFeatures"] = (int)Quassel::features();
-
-    QVariantList bufs;
-    foreach(BufferInfo id, buffers()) bufs << qVariantFromValue(id);
-    v["BufferInfos"] = bufs;
-    QVariantList networkids;
-    foreach(NetworkId id, _networks.keys()) networkids << qVariantFromValue(id);
-    v["NetworkIds"] = networkids;
-
-    quint32 ircusercount = 0;
-    quint32 ircchannelcount = 0;
-    foreach(Network *net, _networks.values()) {
-        ircusercount += net->ircUserCount();
-        ircchannelcount += net->ircChannelCount();
-    }
-    v["IrcUserCount"] = ircusercount;
-    v["IrcChannelCount"] = ircchannelcount;
+    QVariantList bufferInfos;
+    QVariantList networkIds;
+    QVariantList identities;
 
-    QList<QVariant> idlist;
-    foreach(Identity *i, _identities.values()) idlist << qVariantFromValue(*i);
-    v["Identities"] = idlist;
+    foreach(const BufferInfo &id, buffers())
+        bufferInfos << QVariant::fromValue(id);
+    foreach(const NetworkId &id, _networks.keys())
+        networkIds << QVariant::fromValue(id);
+    foreach(const Identity *i, _identities.values())
+        identities << QVariant::fromValue(*i);
 
-    //v["Payload"] = QByteArray(100000000, 'a');  // for testing purposes
-    return v;
+    return Protocol::SessionState(identities, bufferInfos, networkIds);
 }