void ResourceHandleManager::add(ResourceHandle* job, FrameQtClient* frameClient)
{
    ResourceHandleInternal* d = job->getInternal();
    DeprecatedString url = d->m_request.url().url();

    KIO::Job* kioJob = 0;

    if (job->method() == "POST") {
        DeprecatedString postData = job->postData().flattenToString().deprecatedString();
        QByteArray postDataArray(postData.ascii(), postData.length());

        kioJob = KIO::http_post(KUrl(url), postDataArray, false);
        kioJob->addMetaData("PropagateHttpHeader", "true");
        kioJob->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded");
    } else
        kioJob = KIO::get(KUrl(url), false, false);

    Q_ASSERT(kioJob != 0);

    QObject::connect(kioJob, SIGNAL(data(KIO::Job*, const QByteArray&)), this, SLOT(slotData(KIO::Job*, const QByteArray&)));
    QObject::connect(kioJob, SIGNAL(mimetype(KIO::Job*, const QString&)), this, SLOT(slotMimetype(KIO::Job*, const QString&)));
    QObject::connect(kioJob, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*)));

    m_jobToKioMap.insert(job, kioJob);
    m_kioToJobMap.insert(kioJob, job);

    if (!m_frameClient)
        m_frameClient = frameClient;
    else
        ASSERT(m_frameClient == frameClient);
}
Example #2
0
void MainWindow::fileSaveAs()
{
    WebTab *w = currentTab();
    KUrl srcUrl = w->url();
    
    // First, try with suggested file name...
    QString name = w->page()->suggestedFileName();

    // Second, with KUrl fileName...
    if (name.isEmpty())
    {
        name = srcUrl.fileName();
    }
    
    // Last chance...
    if(name.isEmpty())
    {
        name = srcUrl.host() + QString(".html");
    }
    
    const QString destUrl = KFileDialog::getSaveFileName(name, QString(), this);
    if (destUrl.isEmpty()) 
        return;
    
    KIO::Job *job = KIO::file_copy(srcUrl, KUrl(destUrl), -1, KIO::Overwrite);
    job->addMetaData("MaxCacheSize", "0");  // Don't store in http cache.
    job->addMetaData("cache", "cache");     // Use entry from cache if available.
    job->uiDelegate()->setAutoErrorHandlingEnabled(true);
}
Example #3
0
void KNNetAccess::startJobSmtp()
{
    if(smtpJobQueue.isEmpty())
        return;

    currentSmtpJob = smtpJobQueue.first();
    smtpJobQueue.remove(smtpJobQueue.begin());
    currentSmtpJob->prepareForExecution();
    if(currentSmtpJob->success())
    {
        KNLocalArticle *art = static_cast<KNLocalArticle *>(currentSmtpJob->data());
        // create url query part
        QString query("headers=0&from=");
        query += KURL::encode_string(art->from()->email());
        QStrList emails;
        art->to()->emails(&emails);
        for(char *e = emails.first(); e; e = emails.next())
        {
            query += "&to=" + KURL::encode_string(e);
        }
        // create url
        KURL destination;
        KNServerInfo *account = currentSmtpJob->account();
        if(account->encryption() == KNServerInfo::SSL)
            destination.setProtocol("smtps");
        else
            destination.setProtocol("smtp");
        destination.setHost(account->server());
        destination.setPort(account->port());
        destination.setQuery(query);
        if(account->needsLogon())
        {
            destination.setUser(account->user());
            destination.setPass(account->pass());
        }
        KIO::Job *job = KIO::storedPut(art->encodedContent(true), destination, -1, false, false, false);
        connect(job, SIGNAL(result(KIO::Job *)),
                SLOT(slotJobResult(KIO::Job *)));
        if(account->encryption() == KNServerInfo::TLS)
            job->addMetaData("tls", "on");
        else
            job->addMetaData("tls", "off");
        currentSmtpJob->setJob(job);

        kdDebug(5003) << "KNNetAccess::startJobSmtp(): job started" << endl;
    }
    else
    {
        threadDoneSmtp();
    }
}
Example #4
0
void KIO_Delete::deleteItem( const KornMailId *item, KURL kurl, KIO::MetaData metadata, const KIO_Protocol *& protocol )
{
	KIO::Job* job = 0;

	kurl = dynamic_cast<const KornStringId*>( item )->getId();
	
	protocol->deleteMailKURL( kurl, metadata );
	
	if( kurl.port() == 0 )
		kurl.setPort( protocol->defaultPort( _kio->_ssl ) );
		
	if( protocol->deleteFunction() == KIO_Protocol::get )
	{
		job = KIO::get( kurl, true, false );
		
		if( protocol->connectionBased() )
			KIO::Scheduler::assignJobToSlave( _slave, dynamic_cast< KIO::SimpleJob* >( job ) );
		else
			KIO::Scheduler::scheduleJob( dynamic_cast< KIO::SimpleJob* >( job ) );
	}
	else if( protocol->deleteFunction() == KIO_Protocol::del )
	{
		job = KIO::del( kurl, false, false );
	}
	else
		return; //Unknown deleteFunction
		
	connect( job, SIGNAL( result( KIO::Job* ) ), this, SLOT( slotResult( KIO::Job* ) ) );
		
	job->addMetaData( metadata );
	
	_jobs->append( dynamic_cast< KIO::Job* >( job ) );
}
Example #5
0
void TweetJob::start()
{
    kDebug() << "starting job" << m_url;
    QByteArray data;
    QOAuth::ParamMap params;

    data = "source=kdemicroblog";
    params.insert("source", "kdemicroblog");
    {
        QMapIterator<QString, QVariant> i(m_parameters);
        while (i.hasNext()) {
            i.next();
            if (!i.value().toString().isEmpty()) {
                if (i.key() == "status") {
                    const QByteArray status = i.value().toString().toUtf8().toPercentEncoding();
                    params.insert("status", status);
                    data = data.append("&status=" + status);
                } else {
                    const QByteArray key = i.key().toLatin1();
                    const QByteArray value = i.value().toString().toLatin1();
                    params.insert(key, value);
                    data = data.append("&"+key+"="+value);
                }
            }
        }
    }
    KIO::Job *job = KIO::http_post(m_url, data, KIO::HideProgressInfo);
    job->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded");

    m_source->oAuthHelper()->sign(job, m_url.pathOrUrl(), params, KOAuth::POST);
    connect(job, SIGNAL(data(KIO::Job*,QByteArray)),
            this, SLOT(recv(KIO::Job*,QByteArray)));
    connect(job, SIGNAL(result(KJob*)), this, SLOT(result(KJob*)));
}
void KexiUserFeedbackAgent::sendData()
{
    kDebug();
    if (d->areas == NoAreas) {
        return;
    }
    if (KGlobal::mainComponent().aboutData()->programName() != i18n(KEXI_APP_NAME)) {
        // Do not send feedback if this is not really Kexi but a test app based on Kexi
        return;
    }
    if (!d->redirectChecked) {
        sendRedirectQuestion();
        return;
    }

    QByteArray postData;
    foreach (const QByteArray& key, d->keys) {
        Area area = d->areasForKeys.value(key);
        if (area != NoAreas && (d->areas & area)) {
            if (!postData.isEmpty()) {
                postData += ',';
            }
            postData += (QByteArray("\"") + key + "\":\""
                        + escapeJson(d->data.value(key).toString()).toUtf8() + '"');
        }
    }
    kDebug() << postData;
    
    KIO::Job* sendJob = KIO::storedHttpPost(postData, KUrl(d->url + "/send"), KIO::HideProgressInfo);
    connect(sendJob, SIGNAL(result(KFakeJob*)), this, SLOT(sendDataFinished(KJob*)));
    sendJob->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded");
}
void KexiUserFeedbackAgent::sendRedirectQuestion()
{
    QByteArray postData = "get_url";
    kDebug() << postData;
    KIO::Job* sendJob = KIO::storedHttpPost(postData, KUrl(d->url + "/send"), KIO::HideProgressInfo);
    connect(sendJob, SIGNAL(result(KFakeJob*)), this, SLOT(sendRedirectQuestionFinished(KJob*)));
    sendJob->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded");
}
Example #8
0
static bool downloadResource (const KUrl& srcUrl, const QString& suggestedName = QString(),
                              QWidget* parent = 0, const KIO::MetaData& metaData = KIO::MetaData())
{
    const KUrl& destUrl = promptUser(parent, srcUrl, suggestedName);

    if (!destUrl.isValid())
        return false;

    KIO::Job *job = KIO::file_copy(srcUrl, destUrl);

    if (!metaData.isEmpty())
        job->setMetaData(metaData);

    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((parent ? parent->window() : 0));
    job->ui()->setAutoErrorHandlingEnabled(true);
    return true;
}
Example #9
0
static bool downloadResource (const KUrl& srcUrl, const QString& suggestedName = QString(),
                              QWidget* parent = 0, const KIO::MetaData& metaData = KIO::MetaData())
{
    const QString fileName = suggestedName.isEmpty() ? srcUrl.fileName() : suggestedName;
    // convert filename to URL using fromPath to avoid trouble with ':' in filenames (#184202)
    KUrl destUrl = KFileDialog::getSaveFileName(KUrl::fromPath(fileName), QString(), parent);
    if (!destUrl.isValid())
        return false;

    // Using KIO::copy rather than file_copy, to benefit from "dest already exists" dialogs.
    KIO::Job *job = KIO::copy(srcUrl, destUrl);

    if (!metaData.isEmpty())
        job->setMetaData(metaData);

    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((parent ? parent->window() : 0));
    job->ui()->setAutoErrorHandlingEnabled(true);
    return true;
}
Example #10
0
KIO::Job *GroupDavGlobals::createRemoveJob(KPIM::GroupwareDataAdaptor *adaptor, const KURL &/*uploadurl*/,
        KPIM::GroupwareUploadItem *deletedItem)
{
    if(!deletedItem) return 0;
    //kdDebug(7000) << "Delete: " << endl << format.toICalString(*it) << endl;
    KURL url(deletedItem->url());
    if(adaptor)
    {
        adaptor->adaptUploadUrl(url);
    }
    KIO::Job *delJob = 0;
    if(!url.isEmpty())
    {
        kdDebug(5700) << "Delete: " <<   url.url() << endl;
        delJob = KIO::file_delete(url, false);
    }
    if(delJob && adaptor && adaptor->idMapper())
    {
        kdDebug(5800) << "Adding If-Match metadata: " << adaptor->idMapper()->fingerprint(deletedItem->uid()) << endl;
        delJob->addMetaData("customHTTPHeader", "If-Match: " + adaptor->idMapper()->fingerprint(deletedItem->uid()));
    }
    return delJob;

    /*  QStringList urls;
      KPIM::GroupwareUploadItem::List::const_iterator it;
      kdDebug(5800) << " GroupDavGlobals::createRemoveJob, BaseURL="<<uploadurl.url()<<endl;
      for ( it = deletedItems.constBegin(); it != deletedItems.constEnd(); ++it ) {
        //kdDebug(7000) << "Delete: " << endl << format.toICalString(*it) << endl;
        KURL url( (*it)->url() );
        if ( adaptor ) {
          adaptor->adaptUploadUrl( url );
        }*/
    /*    KURL url( uploadurl );
        url.setPath( (*it)->url().path() );
        if ( !(*it)->url().isEmpty() )*/
    /*    if ( !url.isEmpty() ) {
    kdDebug() << "Deleting item at "<< url.url() << endl;
          urls << url.url();
        }
        kdDebug(5700) << "Delete (Mod) : " <<   url.url() << endl;
      }
      return KIO::file_del( urls, false, false );*/
}
Example #11
0
void LdapConfigWidget::sendQuery()
{
  LDAPUrl _url;

  mQResult.clear();
  mCancelled = true;

  _url.setProtocol( ( mSecSSL && mSecSSL->isChecked() ) ? "ldaps" : "ldap" );
  if ( mHost ) _url.setHost( mHost->text() );
  if ( mPort ) _url.setPort( mPort->value() );
  _url.setDn( "" );
  _url.setAttributes( mAttr );
  _url.setScope( LDAPUrl::Base );
  if ( mVer ) _url.setExtension( "x-ver", QString::number( mVer->value() ) );
  if ( mSecTLS && mSecTLS->isChecked() ) _url.setExtension( "x-tls", "" );

  kdDebug(5700) << "sendQuery url: " << _url.prettyURL() << endl;
  mLdif.startParsing();
  KIO::Job *job = KIO::get( _url, true, false );
  job->addMetaData("no-auth-prompt","true");
  connect( job, SIGNAL( data( KIO::Job*, const QByteArray& ) ),
    this, SLOT( loadData( KIO::Job*, const QByteArray& ) ) );
  connect( job, SIGNAL( result( KIO::Job* ) ),
    this, SLOT( loadResult( KIO::Job* ) ) );

  if ( mProg == NULL )
    mProg = new KProgressDialog( this, 0, i18n("LDAP Query"), _url.prettyURL(), true );
  else
    mProg->setLabel( _url.prettyURL() );
  mProg->progressBar()->setValue( 0 );
  mProg->progressBar()->setTotalSteps( 1 );
  mProg->exec();
  if ( mCancelled ) {
    kdDebug(5700) << "query cancelled!" << endl;
    job->kill( true );
  } else {
    if ( !mErrorMsg.isEmpty() ) KMessageBox::error( this, mErrorMsg );
  }
}
void ImageshackTalker::uploadItem(QString path, QMap<QString, QString> opts)
{
    if (m_job)
    {
        m_job->kill();
        m_job = 0;
    }

    emit signalBusy(true);
    QMap<QString, QString> args;
    args["key"] = m_appKey;
    args["fileupload"] = KUrl(path).fileName();

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

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

    if (!form.addFile(KUrl(path).fileName(), path))
    {
        emit signalBusy(false);
        return;
    }

    form.finish();
    kDebug() << "FORM" << form.formData() << "--------------------";

    // Check where to upload

    QString mime = mimeType(path);

    if (mime.startsWith("video/"))
    {
        // video file, check supported types
        QString form = mime.split("/").at(1);
    }
    else
    {
        // image file
    }

    KIO::Job *job = KIO::http_post(KUrl(m_photoApiUrl), 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_job = job;
    m_state = IMGHCK_ADDPHOTO;
    m_buffer.resize(0);
}
Example #13
0
static bool downloadResource(const KUrl& srcUrl, const KIO::MetaData& metaData = KIO::MetaData(),
                             QWidget * parent = 0, const QString & suggestedName = QString())
{
    KUrl destUrl;

    int result = KIO::R_OVERWRITE;
    const QString fileName((suggestedName.isEmpty() ? srcUrl.fileName() : suggestedName));

    do
    {
        // follow bug:184202 fixes
        destUrl = KFileDialog::getSaveFileName(KUrl(KGlobalSettings::downloadPath().append(fileName)), QString(), parent);

        if (destUrl.isEmpty())
            return false;

        if (destUrl.isLocalFile())
        {
            QFileInfo finfo(destUrl.toLocalFile());
            if (finfo.exists())
            {
                QDateTime now = QDateTime::currentDateTime();
                QPointer<KIO::RenameDialog> dlg = new KIO::RenameDialog(parent,
                        i18n("Overwrite File?"),
                        srcUrl,
                        destUrl,
                        KIO::RenameDialog_Mode(KIO::M_OVERWRITE | KIO::M_SKIP),
                        -1,
                        finfo.size(),
                        now.toTime_t(),
                        finfo.created().toTime_t(),
                        now.toTime_t(),
                        finfo.lastModified().toTime_t()
                                                                       );
                result = dlg->exec();
                delete dlg;
            }
        }
    }
    while (result == KIO::R_CANCEL && destUrl.isValid());

    // Save download history
    DownloadItem *item = rApp->downloadManager()->addDownload(srcUrl.pathOrUrl(), destUrl.pathOrUrl());

    if (!KStandardDirs::findExe("kget").isNull() && ReKonfig::kgetDownload())
    {
        //KGet integration:
        if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget"))
        {
            KToolInvocation::kdeinitExecWait("kget");
        }
        QDBusInterface kget("org.kde.kget", "/KGet", "org.kde.kget.main");
        if (!kget.isValid())
            return false;

        QDBusMessage transfer = kget.call(QL1S("addTransfer"), srcUrl.prettyUrl(), destUrl.prettyUrl(), true);
        if (transfer.arguments().isEmpty())
            return true;

        const QString transferPath = transfer.arguments().first().toString();
        item->setKGetTransferDbusPath(transferPath);
        return true;
    }

    KIO::Job *job = KIO::file_copy(srcUrl, destUrl, -1, KIO::Overwrite);
    if (item)
    {
        QObject::connect(job, SIGNAL(percent(KJob *,unsigned long)), item, SLOT(updateProgress(KJob *,unsigned long)));
        QObject::connect(job, SIGNAL(finished(KJob *)), item, SLOT(onFinished(KJob*)));
    }

    if (!metaData.isEmpty())
        job->setMetaData(metaData);

    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->uiDelegate()->setAutoErrorHandlingEnabled(true);
    return true;
}