Ejemplo n.º 1
0
    void Core::downloadFinished(KJob* job)
    {
        KIO::StoredTransferJob* j = (KIO::StoredTransferJob*)job;
        int err = j->error();
        if (err == KIO::ERR_USER_CANCELED)
            return;

        if (err)
        {
            gui->errorMsg(j);
        }
        else
        {
            // load in the file (target is always local)
            QString group;
            QMap<KUrl, QString>::iterator i = add_to_groups.find(j->url());
            if (i != add_to_groups.end())
            {
                group = i.value();
                add_to_groups.erase(i);
            }

            QString dir = locationHint(group);
            if (dir != QString::null)
                loadFromData(j->data(), dir, group, false, j->url());
        }
    }
Ejemplo n.º 2
0
void HTTPTracker::onAnnounceResult(KIO::Job* j)
{
    if (j->error())
    {
        KIO::StoredTransferJob* st = (KIO::StoredTransferJob*)j;
        KURL u = st->url();
        active_job = 0;

        Out(SYS_TRK|LOG_IMPORTANT) << "Error : " << st->errorString() << endl;
        if (u.queryItem("event") != "stopped")
        {
            failures++;
            requestFailed(j->errorString());
        }
        else
        {
            stopDone();
        }
    }
    else
    {
        KIO::StoredTransferJob* st = (KIO::StoredTransferJob*)j;
        KURL u = st->url();
        active_job = 0;

        if (u.queryItem("event") != "stopped")
        {
            try
            {
                if (updateData(st->data()))
                {
                    failures = 0;
                    peersReady(this);
                    requestOK();
                    if (u.queryItem("event") == "started")
                        started = true;
                }
            }
            catch (bt::Error & err)
            {
                failures++;
                requestFailed(i18n("Invalid response from tracker"));
            }
            event = QString::null;
        }
        else
        {
            failures = 0;
            stopDone();
        }
    }
    doAnnounceQueue();
}
Ejemplo n.º 3
0
    void Core::downloadFinishedSilently(KJob* job)
    {
        KIO::StoredTransferJob* j = (KIO::StoredTransferJob*)job;
        int err = j->error();
        if (err == KIO::ERR_USER_CANCELED)
        {
            // do nothing
        }
        else if (err)
        {
            canNotLoadSilently(j->errorString());
        }
        else
        {
            QString dir;
            if (custom_save_locations.contains(j))
            {
                // we have a custom save location so save to that
                dir = custom_save_locations[j].toLocalFile();
                custom_save_locations.remove(j);
            }
            else if (!Settings::useSaveDir())
            {
                // incase save dir is not set, use home director
                Out(SYS_GEN | LOG_NOTICE) << "Cannot load " << j->url() << " silently, default save location not set !" << endl;
                Out(SYS_GEN | LOG_NOTICE) << "Using home directory instead !" << endl;
                dir = QDir::homePath();
            }
            else
            {
                dir = Settings::saveDir().toLocalFile();
            }

            QString group;
            QMap<KUrl, QString>::iterator i = add_to_groups.find(j->url());
            if (i != add_to_groups.end())
            {
                group = i.value();
                add_to_groups.erase(i);
            }


            if (dir != QString::null)
                loadFromData(j->data(), dir, group, true, j->url());
        }
    }
Ejemplo n.º 4
0
void MediaManager::slotImageFetched( KJob * job )
{
    KIO::StoredTransferJob *baseJob = qobject_cast<KIO::StoredTransferJob *>( job );
    QString remote = d->queue.value(job);
    d->queue.remove( job );
    if ( job->error() ) {
        kDebug() << "Job error: " << job->error() << "\t" << job->errorString();
        QString errMsg = i18n( "Cannot download image from %1.",
                               job->errorString() );
        emit fetchError( remote, errMsg );
    } else {
        QPixmap p;
        if( !baseJob->data().startsWith(QByteArray("<?xml version=\"")) &&
            p.loadFromData( baseJob->data() ) ) {
            d->cache.insert( remote, p );
            emit imageFetched( remote, p );
        } else {
            kDebug()<<"Parse Error: \nBase Url:"<<baseJob->url()<<"\ndata:"<<baseJob->data();
            emit fetchError( remote, i18n( "The download failed. The returned file is corrupted." ) );
        }
    }
}
Ejemplo n.º 5
0
void ThumbnailPicker::slotJobResult( KJob *job ) {
    KIO::StoredTransferJob *stjob = (KIO::StoredTransferJob*)job;

    //Update Progressbar
    if ( ! ui->SearchProgress->isHidden() ) {
        ui->SearchProgress->setValue(ui->SearchProgress->value()+1);
        if ( ui->SearchProgress->value() == ui->SearchProgress->maximum() ) {
            ui->SearchProgress->hide();
            ui->SearchLabel->setText( i18n( "Search results:" ) );
        }
    }

    //If there was a problem, just return silently without adding image to list.
    if ( job->error() ) {
        qDebug() << " error=" << job->error();
        job->kill();
        return;
    }

    QPixmap *pm = new QPixmap();
    pm->loadFromData( stjob->data() );

    uint w = pm->width();
    uint h = pm->height();
    uint pad = 0; /*FIXME LATER 4* QDialogBase::marginHint() + 2*ui->SearchLabel->height() + QDialogBase::actionButton( QDialogBase::Ok )->height() + 25;*/
    uint hDesk = QApplication::desktop()->availableGeometry().height() - pad;

    if ( h > hDesk )
        *pm = pm->scaled( w*hDesk/h, hDesk, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );

    PixList.append( pm );

    //Add 50x50 image and URL to listbox
    //ui->ImageList->insertItem( shrinkImage( PixList.last(), 50 ),
    //		cjob->srcURLs().first().prettyUrl() );
    ui->ImageList->addItem( new QListWidgetItem ( QIcon(shrinkImage( PixList.last(), 50 )), stjob->url().url()));
}