Example #1
0
void YandexNarodAuthorizator::onRequestFinished(QNetworkReply *reply)
{
	reply->deleteLater();
	if (reply != m_reply.data())
		return;

	QVariantMap data = Json::parse(reply->readAll()).toMap();
	QVariantMap::Iterator error = data.find(QLatin1String("error"));
	if (error != data.end() || reply->error() != QNetworkReply::NoError) {
		QString errorStr = error.value().toString();
		m_stage = Need;
		if (errorStr == QLatin1String("unsupported_grant_type"))
			emit result(Error, tr("Unsupported grant type. Inform developers."));
		else if (errorStr == QLatin1String("invalid_request"))
			emit result(Error, tr("Invalid request. Inform developers."));
		else
			emit result(Error, tr("Invalid login or/and password"));
		return;
	}
	QString accessToken = data.value(QLatin1String("access_token")).toString();
	QDateTime expiresAt;
	QVariantMap::Iterator expiresIn = data.find(QLatin1String("expires_in"));
	if (expiresIn != data.end()) {
		expiresAt = QDateTime::currentDateTime();
		expiresAt.addSecs(expiresIn.value().toInt());
	}
	debug() << accessToken << data;
	m_token = accessToken;
	m_stage = Already;
	emit result(Success);
	emit needSaveCookies();
}
Example #2
0
ContactListFrontModel::ContactListFrontModel(QObject *parent) :
	QSortFilterProxyModel(parent), m_showOffline(true)
{
	Config config;
	config.beginGroup("contactList");
	m_showOffline = config.value("showOffline", true);
	QVariantMap order = config.value("order", QVariantMap());
	for (QVariantMap::Iterator it = order.begin(); it != order.end(); ++it)
		m_order[it.key()] = it.value().toStringList();

	setFilterCaseSensitivity(Qt::CaseInsensitive);
	setSortCaseSensitivity(Qt::CaseInsensitive);
	sort(0);
	setDynamicSortFilter(true);
	onServiceChanged(m_model.name(), m_model, NULL);
	onServiceChanged(m_metaManager.name(), m_metaManager, NULL);
	connect(ServiceManager::instance(), SIGNAL(serviceChanged(QByteArray,QObject*,QObject*)),
			this, SLOT(onServiceChanged(QByteArray,QObject*,QObject*)));
}