void UINetworkRequest::sltCancel() { /* Abort network-reply if present: */ if (m_pReply) { if (m_fRunning) m_pReply->abort(); else emit sigCanceled(m_uuid); } }
void UINetworkRequest::sltHandleNetworkReplyFinish() { /* Mark network-reply as non-running: */ m_fRunning = false; /* Make sure network-reply still valid: */ if (!m_pReply) return; /* If network-request was canceled: */ if (m_pReply->error() == UINetworkReply::OperationCanceledError) { /* Notify network-manager: */ emit sigCanceled(m_uuid); } /* If network-reply has no errors: */ else if (m_pReply->error() == UINetworkReply::NoError) { /* Check if redirection required: */ QUrl redirect = m_pReply->attribute(UINetworkReply::RedirectionTargetAttribute).toUrl(); if (redirect.isValid()) { /* Cleanup current network-reply first: */ cleanupNetworkReply(); /* Choose redirect-source as current url: */ m_url = redirect; /* Create new network-reply finally: */ prepareNetworkReply(); } else { /* Notify own network-request listeners: */ emit sigFinished(); /* Notify common network-request listeners: */ emit sigFinished(m_uuid); } } /* If some error occured: */ else { /* Check if we have other urls in queue: */ if (m_iUrlIndex < m_urls.size() - 1) { /* Cleanup current network-reply first: */ cleanupNetworkReply(); /* Choose next url as current: */ ++m_iUrlIndex; m_url = m_urls.at(m_iUrlIndex); /* Create new network-reply finally: */ prepareNetworkReply(); } else { /* Notify own network-request listeners: */ emit sigFailed(m_pReply->errorString()); /* Notify common network-request listeners: */ emit sigFailed(m_uuid, m_pReply->errorString()); } } }
/* Network-reply finish handler: */ void UINetworkRequest::sltHandleNetworkReplyFinish() { /* Set as non-running: */ m_fRunning = false; /* Make sure network-reply still valid: */ if (!m_pReply) return; /* If network-request was canceled: */ if (m_pReply->error() == QNetworkReply::OperationCanceledError) { /* Notify network-manager: */ emit sigCanceled(m_uuid); } /* If network-reply has no errors: */ else if (m_pReply->error() == QNetworkReply::NoError) { /* Check if redirection required: */ QUrl redirect = m_pReply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); if (redirect.isValid()) { /* Cleanup current network-reply first: */ cleanupNetworkReply(); /* Choose redirect-source as current: */ m_request.setUrl(redirect); /* Create new network-reply finally: */ prepareNetworkReply(); } else { /* Notify particular network-request listeners: */ emit sigFinished(); /* Notify general network-requests listeners: */ emit sigFinished(m_uuid); } } /* If some error occured: */ else { /* Check if we have other requests in set: */ if (m_iCurrentRequestIndex < m_requests.size() - 1) { /* Cleanup current network-reply first: */ cleanupNetworkReply(); /* Choose next network-request as current: */ ++m_iCurrentRequestIndex; m_request = m_requests[m_iCurrentRequestIndex]; /* Create new network-reply finally: */ prepareNetworkReply(); } else { /* Notify particular network-request listeners: */ emit sigFailed(m_pReply->errorString()); /* Notify general network-requests listeners: */ emit sigFailed(m_uuid, m_pReply->errorString()); } } }