- QVariantMap users;
- QVariantMap channels;
-
- QHash<QString, IrcUser *>::const_iterator userIter = _ircUsers.constBegin();
- QHash<QString, IrcUser *>::const_iterator userIterEnd = _ircUsers.constEnd();
- while (userIter != userIterEnd) {
- users[userIter.value()->hostmask()] = userIter.value()->toVariantMap();
- userIter++;
+
+ if (_ircUsers.count()) {
+ QHash<QString, QVariantList> users;
+ QHash<QString, IrcUser *>::const_iterator it = _ircUsers.begin();
+ QHash<QString, IrcUser *>::const_iterator end = _ircUsers.end();
+ while (it != end) {
+ const QVariantMap &map = it.value()->toVariantMap();
+ QVariantMap::const_iterator mapiter = map.begin();
+ while (mapiter != map.end()) {
+ users[mapiter.key()] << mapiter.value();
+ ++mapiter;
+ }
+ ++it;
+ }
+ // Can't have a container with a value type != QVariant in a QVariant :(
+ // However, working directly on a QVariantMap is awkward for appending, thus the detour via the hash above.
+ QVariantMap userMap;
+ foreach(const QString &key, users.keys())
+ userMap[key] = users[key];
+ usersAndChannels["Users"] = userMap;