void ResourceHandleManager::remove(ResourceHandle* job)
{
    ResourceHandleInternal* d = job->getInternal();
    if (!d || !d->m_client)
        return;

    KIO::Job* kioJob = 0;

    // Check if we know about 'job'...
    QMap<ResourceHandle*, KIO::Job*>::const_iterator it = m_jobToKioMap.find(job);
    if (it != m_jobToKioMap.end())
        kioJob = it.value();

    if (!kioJob)
        return;

    QString headers = kioJob->queryMetaData("HTTP-Headers");
    if (job->method() == "GET")
        d->m_charset = job->extractCharsetFromHeaders(headers);
    else if (job->method() == "POST") {
        // Will take care of informing our client...
        // This must be called before didFinishLoading(),
        // otherwhise assembleResponseHeaders() is called too early...
        RefPtr<PlatformResponseQt> response(new PlatformResponseQt());
        response->data = headers;
        response->url = job->url().url();

        job->receivedResponse(response);
    }

    d->m_client->receivedAllData(job, 0);
    d->m_client->didFinishLoading(job);

    m_jobToKioMap.remove(job);
    m_kioToJobMap.remove(kioJob);
}
Ejemplo n.º 2
0
void GalleryTalker::slotResult(KJob *job)
{
    KIO::Job *tempjob = static_cast<KIO::Job*>(job);

    if (tempjob->error())
    {
        if (m_state == GE_LOGIN)
        {
            emit signalLoginFailed(tempjob->errorString());
        }
        else
        {
            if (m_state == GE_ADDPHOTO)
            {
                emit signalAddPhotoFailed(tempjob->errorString());
            }
            else
            {
                tempjob->ui()->setWindow(m_parent);
                tempjob->ui()->showErrorMessage();
            }
        }
        emit signalBusy(false);
        return;
    }

    switch (m_state)
    {
        case(GE_LOGIN):
            parseResponseLogin(m_talker_buffer);
            break;
        case(GE_LISTALBUMS):
            parseResponseListAlbums(m_talker_buffer);
            break;
        case(GE_LISTPHOTOS):
            parseResponseListPhotos(m_talker_buffer);
            break;
        case(GE_CREATEALBUM):
            parseResponseCreateAlbum(m_talker_buffer);
            break;
        case(GE_ADDPHOTO):
            parseResponseAddPhoto(m_talker_buffer);
            break;
    }

    if (m_state == GE_LOGIN && m_loggedIn)
    {
        const QStringList cookielist = (tempjob->queryMetaData("setcookies")).split('\n');
        m_cookie = "Cookie:";


        if(!cookielist.isEmpty())
        {
            QRegExp rx("^GALLERYSID=.+");
            QString app;
            foreach(const QString &str, cookielist)
            {
                if(str.contains("Set-Cookie: "))
                {
                    const QStringList cl = str.split(' ');
                    int n = cl.lastIndexOf(rx);
                    if(n!= -1)
                    {
                        app = cl.at(n);
                    }
                }
            }
            m_cookie += app;
        }

        tempjob->kill();
        listAlbums();
    }