void VK::timerRequest(VKAbstractHandler *handler) { Q_ASSERT(handler); qDebug()<<"Restart request"<<handler->name(); sendNetworkRequest(handler); }
void VK::startLongPollServer(bool updateTs) { VKHandlerLongPollServerKey* handler = new VKHandlerLongPollServerKey(this, &storage(), this); handler->setUpdateTs(updateTs); //QObject::connect(handler, &VKAbstractHandler::ready, this, &VK::sendHandlertoScript); QObject::connect(handler, &VKAbstractHandler::sendRequest, this, &VK::processHandler); sendNetworkRequest(handler); }
void ServerBrowser::loadServerList(const QUrl &url) { reply = sendNetworkRequest(url); connect(reply, SIGNAL(finished()), this, SLOT(completeDownloadServerList())); connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater())); }
void VK::getDialogs(int offset) { VKHandlerDialogs* dialogHandler = new VKHandlerDialogs(&storage(), this); dialogHandler->setOffset(offset); dialogHandler->setLongPoll(!m_longPoll->initilized()); dialogHandler->setPreviewLength(60); setDefaultSlotsForHandler(dialogHandler); QObject::connect(dialogHandler, &VKHandlerDialogs::unreadCountChanged, [this](int count) { emit this->unreadCountChanged(count); }); sendNetworkRequest(dialogHandler); }
void VK::markAsRead(QList<int> msgs) { qDebug()<<msgs; VKHandlerMarkAsRead* handler = new VKHandlerMarkAsRead(&storage(), this); handler->setMsgs(msgs); //QObject::connect(handler, &VKAbstractHandler::ready, this, &VK::sendHandlertoScript); QObject::connect(handler, &VKAbstractHandler::sendRequest, this, &VK::processHandler); sendNetworkRequest(handler); }
void VK::getMessages(int id, bool isChat, int offset, int count) { VKHandlerMessages* messagesHandler = new VKHandlerMessages(&storage(), this); if (isChat) { messagesHandler->setChatId(id); } else { messagesHandler->setUserId(id); } messagesHandler->setOffset(offset); messagesHandler->setCount(count); setDefaultSlotsForHandler(messagesHandler); sendNetworkRequest(messagesHandler); }
void VK::sendMessage(int guid, int userId, bool isChat, QString text, QString forward, QString attachments) { auto handler = new VKHandlerSendMessage(&storage(), this); handler->setGuid(guid); handler->setAttachments(attachments); handler->setForward(forward); handler->setIsChat(isChat); handler->setText(text); handler->setUserId(userId); //QObject::connect(handler, &VKAbstractHandler::ready, this, &VK::sendHandlertoScript); QObject::connect(handler, &VKAbstractHandler::sendRequest, this, &VK::processHandler); sendNetworkRequest(handler); }
void VK::requestFinished(QNetworkReply* reply) { if (reply->error() == QNetworkReply::NoError) { m_isOnline = true; auto handler = m_manager.getHandlerByReply(reply); if (handler) { QString data = reply->readAll(); qDebug()<<"VK::requestFinished:\n"<<data; QJsonParseError err; QJsonDocument document = QJsonDocument::fromJson(data.toUtf8(), &err); if (err.error != QJsonParseError::NoError) { qFatal("%s",err.errorString().toUtf8().data()); Q_ASSERT(0); } QJsonObject object = document.object(); if (object.value("error").type() != QJsonValue::Undefined) { errorHandler(object.value("error").toObject(), handler); } else { if (object.contains("response")) { QJsonValue response = object.value("response"); handler->processReply(&response); } else { qCritical()<<"no response"; Q_ASSERT(0); } } } else { qCritical()<<"error"; Q_ASSERT(0); } } else { qCritical()<<"Reply error"<<reply->errorString(); if (m_isOnline) { displayError("Connection error", ERROR_HANDLER_INFORM); } auto handler = m_manager.getHandlerByReply(reply); if (handler) { qDebug()<<"Network error, trying to reconnect"; m_manager.remove(reply); sendNetworkRequest(handler); } m_isOnline = false; } }
void VK::processHandler(VKAbstractHandler *handler) { sendNetworkRequest(handler); }