void SmugTalker::listSubCategories(int categoryID)
{
    if (m_job)
    {
        m_job->kill();
        m_job = 0;
    }
    emit signalBusy(true);

    KUrl url(m_apiURL);
    url.addQueryItem("method", "smugmug.subcategories.get");
    url.addQueryItem("SessionID", m_sessionID);
    url.addQueryItem("CategoryID", QString::number(categoryID));

    QByteArray tmp;
    KIO::TransferJob* job = KIO::http_post(url, tmp, KIO::HideProgressInfo);
    job->addMetaData("UserAgent", m_userAgent);
    job->addMetaData("content-type",
                     "Content-Type: application/x-www-form-urlencoded");

    connect(job, SIGNAL(data(KIO::Job*,QByteArray)),
            this, SLOT(data(KIO::Job*,QByteArray)));

    connect(job, SIGNAL(result(KJob*)),
            this, SLOT(slotResult(KJob*)));

    m_state = SMUG_LISTSUBCATEGORIES;
    m_job   = job;
    m_buffer.resize(0);
}
Пример #2
0
        KJob *UPnPRouter::sendSoapQuery(const QString & query,const QString & soapact,const QString & controlurl)
        {
            // if port is not set, 0 will be returned
            // thanks to Diego R. Brogna for spotting this bug
            if (location.port()<=0)
                location.setPort(80);

            QUrl address;

            address.setScheme(QString("http"));
            address.setHost(location.host());
            address.setPort(location.port());
            address.setPath(controlurl);

            KIO::TransferJob *req = KIO::http_post( address, query.toLatin1(), KIO::HideProgressInfo );

            req->addMetaData("content-type", QString("text/xml"));
            req->addMetaData("UserAgent", QString("Konversation UPnP"));
            req->addMetaData("customHTTPHeader", QString("SOAPAction: ") + soapact);

            soap_data_out[req] = QByteArray();
            soap_data_in[req]  = QByteArray();

            connect(req, &KIO::TransferJob::data, this, &UPnPRouter::recvSoapData);
            connect(req, &KIO::TransferJob::dataReq, this, &UPnPRouter::sendSoapData);

            connect(req, &KIO::TransferJob::result, this, &UPnPRouter::onRequestFinished);

            return req;
        }
void SmugTalker::logout()
{
    if (m_job)
    {
        m_job->kill();
        m_job = 0;
    }
    emit signalBusy(true);

    KUrl url(m_apiURL);
    url.addQueryItem("method", "smugmug.logout");
    url.addQueryItem("SessionID", m_sessionID);

    QByteArray tmp;
    KIO::TransferJob* job = KIO::http_post(url, tmp, KIO::HideProgressInfo);
    job->addMetaData("UserAgent", m_userAgent);
    job->addMetaData("content-type",
                     "Content-Type: application/x-www-form-urlencoded");

    connect(job, SIGNAL(data(KIO::Job*,QByteArray)),
            this, SLOT(data(KIO::Job*,QByteArray)));

    m_state = SMUG_LOGOUT;
    m_job   = job;
    m_buffer.resize(0);

    // logout is synchronous call
    job->exec();
    slotResult(job);
}
Пример #4
0
/**
 * Request upload permission using OAuth
 *
 * TODO (Dirk) maybe this can go or be merged with a re-authentication function.
 */
void FbTalker::getUploadPermission()
{
    if (m_job)
    {
        m_job->kill();
        m_job = 0;
    }
    emit signalBusy(true);
    if (m_loginInProgress)
        emit signalLoginProgress(8);

    QMap<QString, QString> args;
    args["access_token"] = m_accessToken;
    args["ext_perm"]     = "photo_upload";

    QByteArray tmp(getCallString(args).toUtf8());
    KIO::TransferJob* job = KIO::http_post(KUrl(m_apiURL,"users.hasAppPermission"), tmp, KIO::HideProgressInfo);
    job->addMetaData("UserAgent", m_userAgent);
    job->addMetaData("content-type",
                     "Content-Type: application/x-www-form-urlencoded");

    connect(job, SIGNAL(data(KIO::Job*,QByteArray)),
            this, SLOT(data(KIO::Job*,QByteArray)));

    connect(job, SIGNAL(result(KJob*)),
            this, SLOT(slotResult(KJob*)));

    m_state = FB_GETUPLOADPERM;
    m_job   = job;
    m_buffer.resize(0);
}
void SmugTalker::listAlbums(const QString& nickName)
{
    if (m_job)
    {
        m_job->kill();
        m_job = 0;
    }
    emit signalBusy(true);

    KUrl url(m_apiURL);
    url.addQueryItem("method", "smugmug.albums.get");
    url.addQueryItem("SessionID", m_sessionID);
    url.addQueryItem("Heavy", "1");
    if (!nickName.isEmpty())
        url.addQueryItem("NickName", nickName);

    QByteArray tmp;
    KIO::TransferJob* job = KIO::http_post(url, tmp, KIO::HideProgressInfo);
    job->addMetaData("UserAgent", m_userAgent);
    job->addMetaData("content-type",
                     "Content-Type: application/x-www-form-urlencoded");

    connect(job, SIGNAL(data(KIO::Job*,QByteArray)),
            this, SLOT(data(KIO::Job*,QByteArray)));

    connect(job, SIGNAL(result(KJob*)),
            this, SLOT(slotResult(KJob*)));

    m_state = SMUG_LISTALBUMS;
    m_job   = job;
    m_buffer.resize(0);
}
Пример #6
0
void FbTalker::listFriends()
{
    if (m_job)
    {
        m_job->kill();
        m_job = 0;
    }
    emit signalBusy(true);

    QMap<QString, QString> args;
    args["access_token"] = m_accessToken;

    QByteArray tmp(getCallString(args).toUtf8());
    KIO::TransferJob* job = KIO::http_post(KUrl(m_apiURL,"friends.get"), tmp, KIO::HideProgressInfo);
    job->addMetaData("UserAgent", m_userAgent);
    job->addMetaData("content-type",
                     "Content-Type: application/x-www-form-urlencoded");

    connect(job, SIGNAL(data(KIO::Job*,QByteArray)),
            this, SLOT(data(KIO::Job*,QByteArray)));

    connect(job, SIGNAL(result(KJob*)),
            this, SLOT(slotResult(KJob*)));

    m_state = FB_LISTFRIENDS;
    m_job   = job;
    m_buffer.resize(0);
}
Пример #7
0
void FbTalker::logout()
{
    if (m_job)
    {
        m_job->kill();
        m_job = 0;
    }
    emit signalBusy(true);

    QMap<QString, QString> args;
    args["access_token"] = m_accessToken;

    QByteArray tmp(getCallString(args).toUtf8());
    KIO::TransferJob* job = KIO::http_post(KUrl(m_apiURL,"auth.expireSession"), tmp, KIO::HideProgressInfo);
    job->addMetaData("UserAgent", m_userAgent);
    job->addMetaData("content-type",
                     "Content-Type: application/x-www-form-urlencoded");

    connect(job, SIGNAL(data(KIO::Job*,QByteArray)),
            this, SLOT(data(KIO::Job*,QByteArray)));

    m_state = FB_LOGOUT;
    m_job   = job;
    m_buffer.resize(0);

    // logout is synchronous call
    job->exec();
    slotResult(job);
}
Пример #8
0
void FbTalker::listPhotos(long long userID, const QString &albumID)
{
    if (m_job)
    {
        m_job->kill();
        m_job = 0;
    }
    emit signalBusy(true);

    QMap<QString, QString> args;
    args["access_token"] = m_accessToken;
    if (!albumID.isEmpty())
        args["aid"]      = albumID;
    else if (userID != 0)
        args["subj_id"]  = QString::number(userID);
    else
        args["subj_id"]  = QString::number(m_user.id);

    QByteArray tmp(getCallString(args).toUtf8());
    KIO::TransferJob* job = KIO::http_post(KUrl(m_apiURL,"photos.get"), tmp, KIO::HideProgressInfo);
    job->addMetaData("UserAgent", m_userAgent);
    job->addMetaData("content-type",
                     "Content-Type: application/x-www-form-urlencoded");

    connect(job, SIGNAL(data(KIO::Job*,QByteArray)),
            this, SLOT(data(KIO::Job*,QByteArray)));

    connect(job, SIGNAL(result(KJob*)),
            this, SLOT(slotResult(KJob*)));

    m_state = FB_LISTPHOTOS;
    m_job   = job;
    m_buffer.resize(0);
}
Пример #9
0
void DccTransferRecv::slotLocalGotResult( KIO::Job* job )
{
    kdDebug() << "DccTransferRecv::slotLocalGotResult() [BEGIN]" << endl;

    KIO::TransferJob* transferJob = static_cast<KIO::TransferJob*>( job );
    disconnect( transferJob, 0, 0, 0 );

    switch ( transferJob->error() )
    {
        case 0:                                   // no error
            kdDebug() << "DccTransferRecv::slotLocalGotResult(): job->error() returned 0." << endl
                << "DccTransferRecv::slotLocalGotResult(): Why was I called in spite of no error?" << endl;
            break;
        case KIO::ERR_FILE_ALREADY_EXIST:
            askAndPrepareLocalKio( i18n( "<b>The file already exists.</b><br>"
                "%1<br>" )
                .arg( m_fileURL.prettyURL() ),
                DccResumeDialog::RA_Overwrite | DccResumeDialog::RA_Rename | DccResumeDialog::RA_Cancel,
                DccResumeDialog::RA_Overwrite );
            break;
        default:
            askAndPrepareLocalKio( i18n( "<b>Could not open the file.<br>"
                "Error: %1</b><br>"
                "%2<br>" )
                .arg( transferJob->error() )
                .arg( m_fileURL.prettyURL() ),
                DccResumeDialog::RA_Rename | DccResumeDialog::RA_Cancel,
                DccResumeDialog::RA_Rename );
    }

    kdDebug() << "DccTransferRecv::slotLocalGotResult() [END]" << endl;
}
Пример #10
0
void JobRemoteTest::putAndGet()
{
    const QString filePath = remoteTmpDir() + "putAndGetFile";
    KUrl u(filePath);
    KIO::TransferJob* job = KIO::put( u, 0600, KIO::Overwrite | KIO::HideProgressInfo );
    QDateTime mtime = QDateTime::currentDateTime().addSecs( -30 ); // 30 seconds ago
    mtime.setTime_t(mtime.toTime_t()); // hack for losing the milliseconds
    job->setModificationTime(mtime);
    job->setUiDelegate( 0 );
    connect( job, SIGNAL( result(KJob*) ),
            this, SLOT( slotResult(KJob*) ) );
    connect( job, SIGNAL(dataReq(KIO::Job*, QByteArray&)),
             this, SLOT(slotDataReq(KIO::Job*, QByteArray&)) );
    m_result = -1;
    m_dataReqCount = 0;
    enterLoop();
    QVERIFY( m_result == 0 ); // no error

    m_result = -1;

    KIO::StoredTransferJob* getJob = KIO::storedGet( u, KIO::NoReload, KIO::HideProgressInfo );
    getJob->setUiDelegate( 0 );
    connect( getJob, SIGNAL( result( KJob* ) ),
            this, SLOT( slotGetResult( KJob* ) ) );
    enterLoop();
    QCOMPARE( m_result, 0 ); // no error
    QCOMPARE( m_data, QByteArray("This is a test for KIO::put()\n") );
    //QCOMPARE( m_data.size(), 11 );
}
Пример #11
0
void ShareProvider::onFinishedReadingFile(KIO::Job* job, const QByteArray& data)
{
    job->disconnect(this);
    qobject_cast<KIO::FileJob *>(job)->close();

    if (data.length() == 0) {
        Q_EMIT finishedError(this, i18n("It was not possible to read the selected file"));
        return;
    }
    
    d->m_data.clear();

    AbstractSharer *sharer = d->getSharer();
    if (sharer) {
        KUrl sharerUrl = sharer->url();
        if (!sharerUrl.isValid()) {
            Q_EMIT finishedError(this, i18n("Service Url is not valid"));
            return;
        }
        KIO::TransferJob *tJob = KIO::http_post(sharer->url(), sharer->postBody(data), KIO::HideProgressInfo);
        tJob->setMetaData(sharer->headers());
        connect(tJob, SIGNAL(data(KIO::Job*,QByteArray)),
                this, SLOT(onTransferJobDataReceived(KIO::Job*,QByteArray)));
        connect(tJob, SIGNAL(result(KJob*)), this, SLOT(onTransferJobResultReceived(KJob*)));

    }
}
Пример #12
0
void ShareProvider::onTransferJobResultReceived(KJob* job)
{
    if (d->m_data.size() == 0) {
        Q_EMIT finishedError(this, i18n("Service was not available"));
        return;
    }

    KIO::TransferJob *tfJob = qobject_cast<KIO::TransferJob*>(job);
    if (tfJob) {
        QString mimeType = tfJob->mimetype();
        AbstractSharer *sharer = d->getSharer();

        if (sharer) {
            sharer->parseResponse(d->m_data);
            if (tfJob->isErrorPage() || sharer->hasError()) {
                QString errorMessage = sharer->errorMessage();
                if (!errorMessage.isEmpty()) {
                    Q_EMIT finishedError(this, errorMessage);
                } else {
                    Q_EMIT finishedError(this, tfJob->errorString());
                }
            } else {
                Q_EMIT finishedSuccess(this, sharer->imageUrl().url());
            }
        }
    }
}
Пример #13
0
void HttpContainer::fetchFinished(KJob *job)
{
    if (!job->error()) {
        // We now set the data on the source with the retrieved data and some
        // additional stats. Note that we don't include the source name, as that
        // is implied as this object *is* the DataContainer. setData is called
        // with just key/value pairs.
        setData("Contents", m_data);
        setData("Size", job->processedAmount(KJob::Bytes));

        // Since we only create TransferJobs, it's safe to just static_cast here.
        // In many real-world situations, this isn't the safest thing to do and a
        // qobject_cast with a test on the result is often safer and cleaner.
        KIO::TransferJob *tjob = static_cast<KIO::TransferJob *>(job);
        setData("Error Page", tjob->isErrorPage());
        setData("Mimetype", tjob->mimetype());

        // Let DataContainer know we have data that needs storing
        setNeedsToBeStored(true);

        // Notify DataContainer that now is a good time to check to see that
        // data has been updated. This will cause visualizations to be updated.
        checkForUpdate();

        // Clean up behind ourselves so there isn't unecessary memory usage
        m_data.clear();
    }
}
Пример #14
0
/**
 * upgrade session key to OAuth
 *
 * This method (or step) can be removed after June 2012 (a year after its
 * implementation), since it is only a convenience method for those people
 * who just upgraded and have an active session using the old authentication.
 */
void FbTalker::exchangeSession(const QString& sessionKey)
{
    if (m_job)
    {
        m_job->kill();
        m_job = 0;
    }
    emit signalBusy(true);
    emit signalLoginProgress(1, 9, i18n("Upgrading to OAuth..."));

    QMap<QString, QString> args;
    args["client_id"]     = m_appID;
    args["client_secret"] = m_secretKey;
    args["sessions"]      = sessionKey;

    QByteArray tmp(getCallString(args).toUtf8());
    KIO::TransferJob* job = KIO::http_post(KUrl("https://graph.facebook.com/oauth/exchange_sessions"), tmp, KIO::HideProgressInfo);
    job->addMetaData("UserAgent", m_userAgent);
    job->addMetaData("content-type",
                     "Content-Type: application/x-www-form-urlencoded");

    connect(job, SIGNAL(data(KIO::Job*,QByteArray)),
            this, SLOT(data(KIO::Job*,QByteArray)));

    connect(job, SIGNAL(result(KJob*)),
            this, SLOT(slotResult(KJob*)));

    m_state = FB_EXCHANGESESSION;
    m_job   = job;
    m_buffer.resize(0);
}
Пример #15
0
void ImageshackTalker::checkRegistrationCode()
{
    if (m_job)
    {
        m_job->kill();
        m_job = 0;
    }

    emit signalBusy(true);
    emit signalLoginInProgress(2, 4, i18n("Checking the web server"));

    QString args = "login="******"&xml=yes");

    QByteArray tmp = args.toUtf8();
    KIO::TransferJob* job = KIO::http_post(KUrl(m_loginApiUrl), tmp, KIO::HideProgressInfo);
    job->addMetaData("UserAgent", m_userAgent);
    job->addMetaData("content-type",
                     "Content-Type: application/x-www-form-urlencoded");

    connect(job, SIGNAL(data(KIO::Job*,QByteArray)),
            this, SLOT(data(KIO::Job*,QByteArray)));

    connect(job, SIGNAL(result(KJob*)),
            this, SLOT(slotResult(KJob*)));

    m_state = IMGHCK_CHECKREGCODE;
    m_job   = job;
    m_buffer.resize(0);

}
Пример #16
0
 void _k_contentTypeCheckFailed(KJob* job)
 {
     KIO::TransferJob* tJob = qobject_cast<KIO::TransferJob*>(job);
     // On error simply call downloadResource which will probably fail as well.
     if (tJob && tJob->error()) {
         (void)downloadResource(tJob->url(), QString(), window, tJob->metaData());
     }
 }
bool SmugTalker::addPhoto(const QString& imgPath, int albumID,
                          const QString& caption)
{
    if (m_job)
    {
        m_job->kill();
        m_job = 0;
    }
    emit signalBusy(true);

    QString imgName = QFileInfo(imgPath).fileName();
    // load temporary image to buffer
    QFile imgFile(imgPath);
    if (!imgFile.open(QIODevice::ReadOnly))
    {
        emit signalBusy(false);
        return false;
    }
    long long imgSize = imgFile.size();
    QByteArray imgData = imgFile.readAll();
    imgFile.close();
    KMD5 imgMD5(imgData);

    MPForm form;

    form.addPair("ByteCount", QString::number(imgSize));
    form.addPair("MD5Sum", QString(imgMD5.hexDigest()));
    form.addPair("AlbumID", QString::number(albumID));
    form.addPair("ResponseType", "REST");
    if (!caption.isEmpty())
        form.addPair("Caption", caption);

    if (!form.addFile(imgName, imgPath))
        return false;

    form.finish();

    QString customHdr;
    KUrl url("http://upload.smugmug.com/photos/xmladd.mg");
    KIO::TransferJob *job = KIO::http_post(url, form.formData(),
            KIO::HideProgressInfo);
    job->addMetaData("content-type", form.contentType());
    job->addMetaData("UserAgent", m_userAgent);
    customHdr += "X-Smug-SessionID: " + m_sessionID + "\r\n";
    customHdr += "X-Smug-Version: " + m_apiVersion + "\r\n";
    job->addMetaData("customHTTPHeader", customHdr);

    connect(job, SIGNAL(data(KIO::Job*,QByteArray)),
            this, SLOT(data(KIO::Job*,QByteArray)));

    connect(job, SIGNAL(result(KJob*)),
            this, SLOT(slotResult(KJob*)));

    m_state = SMUG_ADDPHOTO;
    m_job   = job;
    m_buffer.resize(0);
    return true;
}
Пример #18
0
void FreeBusyDownloadJob::start()
{
  KIO::TransferJob *job = KIO::get( mUrl, KIO::NoReload, KIO::HideProgressInfo );

  job->ui()->setWindow( mParent );

  connect( job, SIGNAL(result(KJob*)), SLOT(slotResult(KJob*)) );
  connect( job, SIGNAL(data(KIO::Job*,QByteArray)), SLOT(slotData(KIO::Job*,QByteArray)) );
}
Пример #19
0
void Resource::revokeAccess(const QString &id, const QString &name, const QString &password)
{
    QUrl url = baseUrl;
    url.setPath(url.path() + "/authorizations/" + id);
    KIO::TransferJob *job = KIO::http_delete(url, KIO::HideProgressInfo);
    job->addMetaData("customHTTPHeader", "Authorization: Basic " + QString (name + ':' + password).toUtf8().toBase64());
    /* And we don't care if it's successful ;) */
    job->start();
}
Пример #20
0
KIO::TransferJob * Resource::getTransferJob(const QString &uri, const QString &token) const
{
    QUrl url = baseUrl;
    url = url.adjusted(QUrl::StripTrailingSlash);
    url.setPath(url.path() + '/' + uri);
    KIO::TransferJob *job = KIO::get(url, KIO::Reload, KIO::HideProgressInfo);
    if (!token.isEmpty())
        job->addMetaData("customHTTPHeader", "Authorization: token " + token);
    return job;
}
Пример #21
0
bool FbTalker::addPhoto(const QString& imgPath,
                        const QString& albumID,
                        const QString& caption)
{

    kDebug() << "Adding photo " << imgPath << " to album with id "
             << albumID << " using caption '" << caption << "'";

    if (m_job)
    {
        m_job->kill();
        m_job = 0;
    }
    emit signalBusy(true);

    QMap<QString, QString> args;
    args["access_token"] = m_accessToken;
    args["name"]         = KUrl(imgPath).fileName();
    if (!albumID.isEmpty())
        args["aid"]      = albumID;
    if (!caption.isEmpty())
        args["caption"]  = caption;

    MPForm form;
    for (QMap<QString, QString>::const_iterator it = args.constBegin();
         it != args.constEnd();
         ++it)
    {
        form.addPair(it.key(), it.value());
    }

    if (!form.addFile(args["name"], imgPath))
    {
        emit signalBusy(false);
        return false;
    }
    form.finish();

    kDebug() << "FORM: " << endl << form.formData();

    KIO::TransferJob* job = KIO::http_post(KUrl(m_apiURL,"photos.upload"), form.formData(), KIO::HideProgressInfo);
    job->addMetaData("UserAgent",    m_userAgent);
    job->addMetaData("content-type", form.contentType());

    connect(job, SIGNAL(data(KIO::Job*,QByteArray)),
            this, SLOT(data(KIO::Job*,QByteArray)));

    connect(job, SIGNAL(result(KJob*)),
            this, SLOT(slotResult(KJob*)));

    m_state = FB_ADDPHOTO;
    m_job   = job;
    m_buffer.resize(0);
    return true;
}
Пример #22
0
QImage ImageLoader::loadImage(const QUrl &url, bool *ok, bool selectPictureSize)
{
    QImage image;

    if (url.isEmpty()) {
        return image;
    }

    (*ok) = false;

    if (url.isLocalFile()) {
        if (image.load(url.toLocalFile())) {
            (*ok) = true;
        }
    } else {
        QByteArray imageData;
        KIO::TransferJob *job = KIO::get(url, KIO::NoReload);
        QObject::connect(job, &KIO::TransferJob::data,
        [&imageData](KIO::Job *, const QByteArray & data) {
            imageData.append(data);
        });
        if (job->exec()) {
            if (image.loadFromData(imageData)) {
                (*ok) = true;
            }
        }
    }

    if (!(*ok)) {
        // image does not exist (any more)
        KMessageBox::sorry(mParent, i18n("This contact's image cannot be found."));
        return image;
    }

    if (selectPictureSize) {
        QPixmap pixmap = QPixmap::fromImage(image);
        image = KPixmapRegionSelectorDialog::getSelectedImage(pixmap, 1, 1, mParent);
        if (image.isNull()) {
            (*ok) = false;
            return image;
        }
    }

    if (image.height() > 720 || image.width() > 720) {
        if (image.height() > image.width()) {
            image = image.scaledToHeight(720);
        } else {
            image = image.scaledToWidth(720);
        }
    }

    (*ok) = true;

    return image;
}
Пример #23
0
void GData::createComment( KBlog::BlogPost *post, KBlog::BlogComment *comment )
{
  kDebug();

  if ( !comment ) {
    kError() << "comment is null pointer";
    return;
  }

  if ( !post ) {
    kError() << "post is null pointer";
    return;
  }

  Q_D( GData );
  if ( !d->authenticate() ){
    kError() << "Authentication failed.";
    emit errorComment( Atom, i18n( "Authentication failed." ), post, comment );
    return;
  }
  QString atomMarkup = "<entry xmlns='http://www.w3.org/2005/Atom'>";
  atomMarkup += "<title type=\"text\">" + comment->title() + "</title>";
  atomMarkup += "<content type=\"html\">" + comment->content() + "</content>";
  atomMarkup += "<author>";
  atomMarkup += "<name>" + comment->name() + "</name>";
  atomMarkup += "<email>" + comment->email() + "</email>";
  atomMarkup += "</author></entry>";

  QByteArray postData;
  kDebug() <<  postData;
  QDataStream stream( &postData, QIODevice::WriteOnly );
  stream.writeRawData( atomMarkup.toUtf8(), atomMarkup.toUtf8().length() );

  KIO::TransferJob *job = KIO::http_post(
    KUrl( "http://www.blogger.com/feeds/" + blogId() + "/" + post->postId() + "/comments/default" ),
    postData, KIO::HideProgressInfo );

  d->mCreateCommentMap[ job ][post] = comment;

  if ( !job ) {
    kWarning() << "Unable to create KIO job for http://www.blogger.com/feeds/"
               << blogId() << "/" << post->postId() << "/comments/default";
  }

  job->addMetaData( "content-type", "Content-Type: application/atom+xml; charset=utf-8" );
  job->addMetaData( "ConnectTimeout", "50" );
  job->addMetaData( "customHTTPHeader",
                    "Authorization: GoogleLogin auth=" + d->mAuthenticationString );
  job->addMetaData( "UserAgent", userAgent() );

  connect( job, SIGNAL(data(KIO::Job*,const QByteArray&)),
           this, SLOT(slotCreateCommentData(KIO::Job*,const QByteArray&)) );
  connect( job, SIGNAL(result(KJob*)),
           this, SLOT(slotCreateComment(KJob*)) );
}
Пример #24
0
void KRun::slotStart()
{
//    if ( !inherits( "KHTMLRun" ) )
//        foundMimeType( "text/html" );

    QString externalHandler = KProtocolManager::externalProtocolHandler( m_strURL.protocol() );
    if ( !externalHandler.isEmpty() )
    {
	if ( externalHandler.left( 1 ) == "@" )
	{
	    m_strURL = externalHandler.mid( 1 ) +
		       m_strURL.url().mid( m_strURL.url().find( ':' ) + 1 );
	}
	else
	{
	    if ( externalHandler.left( 1 ) != "!" )
    		exec( externalHandler, m_strURL.url() );

    	    emit error(); // stop the spinning wheel, err, the enabled stop button

    	    delete this; // pretend you don't see this :)
    	    return;
	}
    } 

    KIO::TransferJob *job = 0;

    // eeeeek!
    if ( inherits( "KHTMLRun" ) )
    {
	KHTMLRun *run = static_cast<KHTMLRun *>( this );

	if ( run->urlArgs().postData.size() > 0 )
	{
	    job = KIO::http_post( m_strURL, run->urlArgs().postData, false );
	    job->addMetaData( "content-type", run->urlArgs().contentType() );
	}
	else
	    job = KIO::get( m_strURL, false, false );

	job->addMetaData( run->urlArgs().metaData() );
    }
    else
	job = KIO::get( m_strURL, false, true );

    // ###
    connect( job, SIGNAL( data( KIO::Job *, const QByteArray & ) ),
             this, SLOT( slotJobData( KIO::Job *, const QByteArray & ) ) );
    connect( job, SIGNAL( result( KIO::Job * ) ),
             this, SLOT( slotJobResult( KIO::Job * ) ) );
    connect( job, SIGNAL( mimetype( KIO::Job *, const QString & ) ),
             this, SLOT( slotFoundMime( KIO::Job *, const QString & ) ) );

    m_job = job;
}
Пример #25
0
QString ManPageDocumentation::getManPageContent()
{
    KIO::TransferJob  * transferJob = KIO::get(m_url, KIO::NoReload, KIO::HideProgressInfo);
    connect( transferJob, SIGNAL(data(KIO::Job*,QByteArray)),
             this, SLOT(readDataFromManPage(KIO::Job*,QByteArray)) );
    if (transferJob->exec()){
        return m_manPageBuffer;
    } else {
        return i18n("Could not find any documentation for '%1'", m_name);
    }
}
Пример #26
0
void FavIconRequestJob::slotResult(KJob *job)
{
    KIO::TransferJob *tjob = static_cast<KIO::TransferJob *>(job);
    const QUrl iconUrl = tjob->url();
    KIO::FavIconsCache *cache = KIO::FavIconsCache::instance();
    if (!job->error()) {
        QBuffer buffer(&d->m_iconData);
        buffer.open(QIODevice::ReadOnly);
        QImageReader ir(&buffer);
        QSize desired(16, 16);
        if (ir.canRead()) {
            while (ir.imageCount() > 1
                    && ir.currentImageRect() != QRect(0, 0, desired.width(), desired.height())) {
                if (!ir.jumpToNextImage()) {
                    break;
                }
            }
            ir.setScaledSize(desired);
            const QImage img = ir.read();
            if (!img.isNull()) {
                cache->ensureCacheExists();
                const QString localPath = cache->cachePathForIconUrl(iconUrl);
                qCDebug(FAVICONS_LOG) << "Saving image to" << localPath;
                QSaveFile saveFile(localPath);
                if (saveFile.open(QIODevice::WriteOnly) &&
                        img.save(&saveFile, "PNG") && saveFile.commit()) {
                    d->m_iconFile = localPath;
                } else {
                    setError(KIO::ERR_COULD_NOT_WRITE);
                    setErrorText(i18n("Error saving image to %1", localPath));
                }
            } else {
                qCDebug(FAVICONS_LOG) << "QImageReader read() returned a null image";
            }
        } else {
            qCDebug(FAVICONS_LOG) << "QImageReader canRead returned false";
        }
    } else if (job->error() == KJob::KilledJobError) { // we killed it in slotData
        setError(KIO::ERR_SLAVE_DEFINED);
        setErrorText(i18n("Icon file too big, download aborted"));
    } else {
        setError(job->error());
        setErrorText(job->errorString()); // not errorText(), because "this" is a KJob, with no errorString building logic
    }
    d->m_iconData.clear(); // release memory
    if (d->m_iconFile.isEmpty()) {
        qCDebug(FAVICONS_LOG) << "adding" << iconUrl << "to failed downloads due to error:" << errorString();
        cache->addFailedDownload(iconUrl);
    } else {
        cache->removeFailedDownload(iconUrl);
    }
    KCompositeJob::removeSubjob(job);
    emitResult();
}
Пример #27
0
void KSVGLoader::postUrl(::KURL url, const QByteArray &data, const QString &mimeType,  KJS::ExecState *exec, KJS::Object &callBackFunction, KJS::Object &status)
{
	KIO::TransferJob *job = KIO::http_post(url, data, false);
	job->addMetaData("content-type", mimeType);

	m_postUrlData.job = job;
	m_postUrlData.exec = exec;
	m_postUrlData.status = &status;
	m_postUrlData.callBackFunction = &callBackFunction;

	connect(job, SIGNAL(result(KIO::Job *)), SLOT(slotResult(KIO::Job *)));
}
Пример #28
0
KIO::TransferJob *GroupDavGlobals::createDownloadJob( KPIM::GroupwareDataAdaptor *adaptor,
                    const KURL &url, KPIM::FolderLister::ContentType /*ctype*/ )
{
kdDebug()<<"GroupDavGlobals::createDownloadJob, url="<<url.url()<<endl;
  KIO::TransferJob *job = KIO::get( url, false, false );
  if ( adaptor ) {
    QString mt = adaptor->mimeType();
    job->addMetaData( "accept", mt );
  }
  job->addMetaData( "PropagateHttpHeader", "true" );
  return job;
}
Пример #29
0
void FlickrTalker::addPhotoToPhotoSet(const QString& photoId,
                                      const QString& photoSetId)
{
    if (m_job)
    {
        m_job->kill();
        m_job = 0;
    }

    kDebug() << "addPhotoToPhotoSet invoked";
    KUrl url(m_apiUrl);

    /* If the photoset id starts with the special string "UNDEFINED_", it means
     * it doesn't exist yet on Flickr and needs to be created. Note that it's
     * not necessary to subsequently add the photo to the photo set, as this
     * is done in the set creation call to Flickr. */
    if (photoSetId.startsWith(QLatin1String("UNDEFINED_")))
    {
        createPhotoSet("", m_selectedPhotoSet.title, m_selectedPhotoSet.description, photoId);
    }
    else
    {
        url.addQueryItem("auth_token", m_token);

        url.addQueryItem("photoset_id", photoSetId);

        url.addQueryItem("api_key", m_apikey);

        url.addQueryItem("method", "flickr.photosets.addPhoto");

        url.addQueryItem("photo_id", photoId);

        QString md5 = getApiSig(m_secret, url);
        url.addQueryItem("api_sig", md5);

        QByteArray tmp;
        kDebug() << "Add photo to Photo set url: " << url;
        KIO::TransferJob* job = KIO::http_post(url, tmp, KIO::HideProgressInfo);
        job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded");

        connect(job, SIGNAL(data(KIO::Job*,QByteArray)),
                this, SLOT(data(KIO::Job*,QByteArray)));

        connect(job, SIGNAL(result(KJob*)),
                this, SLOT(slotResult(KJob*)));

        m_state = FE_ADDPHOTOTOPHOTOSET;
        m_job   = job;
        m_buffer.resize(0);
        emit signalBusy(true);
    }
}
Пример #30
0
void KWebPage::downloadRequest(const QNetworkRequest& request)
{
    KIO::TransferJob* job = KIO::get(request.url());
    connect(job, SIGNAL(mimetype(KIO::Job*,QString)),
            this, SLOT(_k_receivedContentType(KIO::Job*,QString)));
    connect(job, SIGNAL(result(KJob*)),
            this, SLOT(_k_receivedContentTypeResult(KJob*)));

    job->setMetaData(request.attribute(static_cast<QNetworkRequest::Attribute>(KIO::AccessManager::MetaData)).toMap());
    job->addMetaData(QL1S("MaxCacheSize"), QL1S("0")); // Don't store in http cache.
    job->addMetaData(QL1S("cache"), QL1S("cache")); // Use entry from cache if available.
    job->ui()->setWindow(d->windowWidget());
}