void UINetworkRequest::cleanup()
{
    /* Cleanup network-reply: */
    cleanupNetworkReply();

    /* Unregister network-request from network-manager: */
    manager()->unregisterNetworkRequest(m_uuid);
}
/* Destructor: */
UINetworkRequest::~UINetworkRequest()
{
    /* Destroy network-reply: */
    cleanupNetworkReply();

    /* Remove network-request description from network-manager state-indicator: */
    m_pNetworkManagerIndicator->removeNetworkRequest(m_uuid);

    /* Remove network-request widget from network-manager dialog: */
    m_pNetworkManagerDialog->removeNetworkRequestWidget(m_uuid);
}
void UINetworkRequest::sltRetry()
{
    /* Cleanup current network-reply first: */
    cleanupNetworkReply();

    /* Choose first url as current: */
    m_iUrlIndex = 0;
    m_url = m_urls.at(m_iUrlIndex);

    /* Create new network-reply finally: */
    prepareNetworkReply();
}
/* Slot to retry network-request: */
void UINetworkRequest::sltRetry()
{
    /* Cleanup current network-reply first: */
    cleanupNetworkReply();

    /* Choose first network-request as current: */
    m_iCurrentRequestIndex = 0;
    m_request = m_requests[m_iCurrentRequestIndex];

    /* Create new network-reply finally: */
    prepareNetworkReply();
}
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());
        }
    }
}