Esempio n. 1
0
void VInfoRequest::onRequestFinished()
{
	Vreen::Reply *reply = qobject_cast<Vreen::Reply*>(sender());
	m_data = reply->response().toList().value(0).toMap();
	ensureAddress(Country);
	ensureAddress(City);
	if (m_unknownCount == 0)
		setState(InfoRequest::RequestDone);
}
Esempio n. 2
0
    void testRequest()
    {
        VREEN_CREATE_CLIENT();

        if (!client.isOnline())
            QFAIL("Client is offline!");

		Vreen::Reply *reply = client.request("getUserSettings");
        connect(reply, SIGNAL(resultReady(QVariant)), &loop, SLOT(quit()));
        loop.exec();
        QCOMPARE(reply->response().toInt() > 6, true);
    }
Esempio n. 3
0
void VInfoRequest::onAddressEnsured()
{
	Vreen::Reply *reply = qobject_cast<Vreen::Reply*>(sender());
	QString field = reply->property("field").toString();
	qptrdiff tmp = reply->property("mapper").value<qptrdiff>();
	FuncPointerHelper *helper = reinterpret_cast<FuncPointerHelper*>(tmp);
	QVariantMap data = reply->response().toList().value(0).toMap();
	QString name = data.value("name").toString();
	m_data.insert(field, name);
	helper->mapper->insert(data.value("cid").toInt(), new QString(name));
	delete helper;
	m_unknownCount--;
	if (m_unknownCount == 0)
		setState(InfoRequest::RequestDone);
}
Esempio n. 4
0
void VInfoRequest::ensureAddress(DataType type)
{
	QString method;
	QString field;
	NameMapper *mapper;
	switch (type) {
	case Country:
		method = QLatin1String("places.getCountries");
		field = QLatin1String("country");
		mapper = countries();
		break;
	case City:
		method = QLatin1String("places.getCities");
		field = QLatin1String("city");
		mapper = cities();
		break;
	default:
		return;
	}
	int id = m_data.value(field, -1).toInt();
	if (id == -1)
		return;
	if (QString *obj = mapper->object(id)) {
		m_data.insert(field, *obj);
	} else {
		QVariantMap data;
        data.insert(QLatin1String("country"), QString::number(id));
		FuncPointerHelper *helper = new FuncPointerHelper;
		helper->mapper = mapper;
		Vreen::Reply *reply = m_client->request(method, data);
		reply->setProperty("field", field);
		reply->setProperty("mapper", reinterpret_cast<qptrdiff>(helper));
		connect(this, SIGNAL(canceled()), reply, SLOT(deleteLater()));
		connect(reply, SIGNAL(resultReady(QVariant)), this, SLOT(onAddressEnsured()));
		m_unknownCount++;
	}
}