+ writeMessage(QVariant(packedFunc));
+}
+
+
+// Handle the changed format for Network's initData
+// cf. Network::initIrcUsersAndChannels()
+void LegacyPeer::fromLegacyIrcUsersAndChannels(QVariantMap &initData)
+{
+ const QVariantMap &legacyMap = initData["IrcUsersAndChannels"].toMap();
+ QVariantMap newMap;
+
+ QHash<QString, QVariantList> users;
+ foreach(const QVariant &v, legacyMap["users"].toMap().values()) {
+ const QVariantMap &map = v.toMap();
+ foreach(const QString &key, map.keys())
+ users[key] << map[key];
+ }
+ QVariantMap userMap;
+ foreach(const QString &key, users.keys())
+ userMap[key] = users[key];
+ newMap["Users"] = userMap;
+
+ QHash<QString, QVariantList> channels;
+ foreach(const QVariant &v, legacyMap["channels"].toMap().values()) {
+ const QVariantMap &map = v.toMap();
+ foreach(const QString &key, map.keys())
+ channels[key] << map[key];
+ }
+ QVariantMap channelMap;
+ foreach(const QString &key, channels.keys())
+ channelMap[key] = channels[key];
+ newMap["Channels"] = channelMap;
+
+ initData["IrcUsersAndChannels"] = newMap;
+}
+
+
+void LegacyPeer::toLegacyIrcUsersAndChannels(QVariantMap &initData)
+{
+ const QVariantMap &usersAndChannels = initData["IrcUsersAndChannels"].toMap();
+ QVariantMap legacyMap;
+
+ // toMap() and toList() are cheap, so no need to copy to a hash
+
+ QVariantMap userMap;
+ const QVariantMap &users = usersAndChannels["Users"].toMap();
+
+ int size = users["nick"].toList().size(); // we know this key exists
+ for(int i = 0; i < size; i++) {
+ QVariantMap map;
+ foreach(const QString &key, users.keys())
+ map[key] = users[key].toList().at(i);
+ QString hostmask = QString("%1!%2@%3").arg(map["nick"].toString(), map["user"].toString(), map["host"].toString());
+ userMap[hostmask.toLower()] = map;
+ }
+ legacyMap["users"] = userMap;
+
+ QVariantMap channelMap;
+ const QVariantMap &channels = usersAndChannels["Channels"].toMap();
+
+ size = channels["name"].toList().size();
+ for(int i = 0; i < size; i++) {
+ QVariantMap map;
+ foreach(const QString &key, channels.keys())
+ map[key] = channels[key].toList().at(i);
+ channelMap[map["name"].toString().toLower()] = map;
+ }
+ legacyMap["channels"] = channelMap;
+
+ initData["IrcUsersAndChannels"] = legacyMap;