void ManagerConnection::readSessions()
{
    QMap<int, Session> list;

    int count;
    in >> count;
    for (int i = 0; i < count; i++) {
        int id;
        QString username;
        QString name;

        in >> id;
        in >> username;
        name = in.readLine();

        list.insert(id, Session(name, username));
    }

    emit sessionListReceived(list);
}
Exemple #2
0
void AnnouncementApi::handleListingResponse(QNetworkReply *reply)
{
	QJsonParseError error;
	QByteArray body = reply->readAll();
	QJsonDocument doc = QJsonDocument::fromJson(body, &error);
	if(error.error != QJsonParseError::NoError)
		throw ResponseError(QStringLiteral("Error parsing announcement response: %1").arg(error.errorString()));

	QList<Session> sessions;

	if(!doc.isArray())
		throw ResponseError(QStringLiteral("Expected array of session descriptions!"));

	for(const QJsonValue &jsv : doc.array()) {
		if(!jsv.isObject())
			throw ResponseError(QStringLiteral("Expected session description!"));
		const QJsonObject obj = jsv.toObject();

		QDateTime started = QDateTime::fromString(obj["started"].toString(), Qt::ISODate);
		started.setTimeSpec(Qt::UTC);

		sessions << Session {
			obj["host"].toString(),
			obj["port"].toInt(),
			obj["id"].toString(),
			protocol::ProtocolVersion::fromString(obj["protocol"].toString()),
			obj["title"].toString(),
			obj["users"].toInt(),
			obj["usernames"].toVariant().toStringList(),
			obj["password"].toBool(),
			obj["nsfm"].toBool(),
			obj["owner"].toString(),
			started
		};
	}

	emit sessionListReceived(sessions);
}