Exemplo n.º 1
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);
}
Exemplo n.º 2
0
void DolphinContextMenu::openTrashContextMenu()
{
    Q_ASSERT(m_context & TrashContext);

    QAction* emptyTrashAction = new QAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18nc("@action:inmenu", "Empty Trash"), this);
    KConfig trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig);
    emptyTrashAction->setEnabled(!trashConfig.group("Status").readEntry("Empty", true));
    addAction(emptyTrashAction);

    addCustomActions();

    QAction* propertiesAction = m_mainWindow->actionCollection()->action(QStringLiteral("properties"));
    addAction(propertiesAction);

    addShowMenuBarAction();

    if (exec(m_pos) == emptyTrashAction) {
        KIO::JobUiDelegate uiDelegate;
        uiDelegate.setWindow(m_mainWindow);
        if (uiDelegate.askDeleteConfirmation(QList<QUrl>(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) {
            KIO::Job* job = KIO::emptyTrash();
            KJobWidgets::setWindow(job, m_mainWindow);
            job->ui()->setAutoErrorHandlingEnabled(true);
        }
    }
}
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);
}
Exemplo n.º 4
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*)));
}
Exemplo n.º 5
0
void IconApplet::showConfigurationInterface()
{
    KPropertiesDialog *dialog = m_dialog.data();
    m_configTarget = m_url;
    if (m_hasDesktopFile) {
        const QFileInfo fi(m_url.toLocalFile());
        if (!fi.isWritable()) {
            const QString suggestedName = fi.baseName();
            m_configTarget = KService::newServicePath(false, suggestedName);
            KIO::Job *job = KIO::file_copy(m_url, m_configTarget);
            job->exec();
        }
    }

    if (dialog) {
        KWindowSystem::setOnDesktop(dialog->winId(), KWindowSystem::currentDesktop());
        dialog->show();
        KWindowSystem::activateWindow(dialog->winId());
    } else {
        dialog = new KPropertiesDialog(m_configTarget, 0 /*no parent widget*/);
        m_dialog = dialog;
        connect(dialog, SIGNAL(applied()), this, SLOT(acceptedPropertiesDialog()));
        connect(dialog, SIGNAL(canceled()), this, SLOT(cancelledPropertiesDialog()));
        dialog->setAttribute(Qt::WA_DeleteOnClose, true);
        dialog->setWindowTitle(i18n("%1 Icon Settings", m_configTarget.fileName()));
        dialog->show();
    }
}
void ImgurTalker::slotResult(KJob* kjob)
{
    KIO::Job* job = static_cast<KIO::Job*>(kjob);

    if ( job->error() )
    {
        ImgurError err;
        err.message = tr("Upload failed");
        emit signalError(err); //job->errorString()
        kDebug() << "Error :" << job->errorString();
    }

    bool parseOk = false;

    switch(m_state)
    {
        case IE_REMOVEPHOTO:
            parseOk = parseResponseImageRemove(m_buffer);
            break;

        case IE_ADDPHOTO:
            parseOk = parseResponseImageUpload(m_buffer);
            break;
        default:
            break;
    }

    m_buffer.resize(0);

    emit signalUploadDone();
    emit signalBusy(false);

    return;
}
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");
}
Exemplo n.º 8
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 ) );
}
Exemplo n.º 9
0
void SatellitesComponent::updateTLEs()
{
    int i = 0;
    
    QProgressDialog progressDlg( i18n( "Update TLEs..." ), i18n( "Abort" ), 0, m_groups.count() );
    progressDlg.setWindowModality( Qt::WindowModal );
    progressDlg.setValue( 0 );
        
    foreach ( SatelliteGroup *group, m_groups ) {
        if ( progressDlg.wasCanceled() )
            return;

        if( group->tleUrl().isEmpty() )
            continue;
        
        progressDlg.setLabelText( i18n( "Update %1 satellites", group->name() ) );
        KIO::Job* getJob = KIO::file_copy(group->tleUrl(), group->tleFilename(), -1, KIO::Overwrite | KIO::HideProgressInfo );
        if( getJob->exec() )
        {
            group->readTLE();
            group->updateSatellitesPos();
            progressDlg.setValue( ++i );
        } else
        {
            getJob->uiDelegate()->showErrorMessage();
        }   
    }
}
Exemplo n.º 10
0
void Importer::finalizeImport()
{
    KIO::Job* job = KIO::del(d->mTempImportDir, KIO::HideProgressInfo);
    if (job->ui()) {
        job->ui()->setWindow(d->mAuthWindow);
    }
    importFinished();
}
Exemplo n.º 11
0
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");
}
Exemplo n.º 12
0
void KNewFileMenuPrivate::executeStrategy()
{
    m_tempFileToDelete = m_copyData.tempFileToDelete();
    const QString src = m_copyData.sourceFileToCopy();
    QString chosenFileName = expandTilde(m_copyData.chosenFileName(), true);

    if (src.isEmpty())
        return;
    KUrl uSrc(src);
    if (uSrc.isLocalFile()) {
        // In case the templates/.source directory contains symlinks, resolve
        // them to the target files. Fixes bug #149628.
        KFileItem item(uSrc, QString(), KFileItem::Unknown);
        if (item.isLink())
            uSrc.setPath(item.linkDest());

        if (!m_copyData.m_isSymlink) {
            // If the file is not going to be detected as a desktop file, due to a
            // known extension (e.g. ".pl"), append ".desktop". #224142.
            QFile srcFile(uSrc.toLocalFile());
            if (srcFile.open(QIODevice::ReadOnly)) {
                KMimeType::Ptr wantedMime = KMimeType::findByUrl(uSrc);
                KMimeType::Ptr mime = KMimeType::findByNameAndContent(m_copyData.m_chosenFileName, srcFile.read(1024));
                //kDebug() << "mime=" << mime->name() << "wantedMime=" << wantedMime->name();
                if (!mime->is(wantedMime->name()))
                    chosenFileName += wantedMime->mainExtension();
            }
        }
    }

    // The template is not a desktop file [or it's a URL one]
    // Copy it.
    KUrl::List::const_iterator it = m_popupFiles.constBegin();
    for (; it != m_popupFiles.constEnd(); ++it)
    {
        KUrl dest(*it);
        dest.addPath(KIO::encodeFileName(chosenFileName));

        KUrl::List lstSrc;
        lstSrc.append(uSrc);
        KIO::Job* kjob;
        if (m_copyData.m_isSymlink) {
            kjob = KIO::symlink(src, dest);
            // This doesn't work, FileUndoManager registers new links in copyingLinkDone,
            // which KIO::symlink obviously doesn't emit... Needs code in FileUndoManager.
            //KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Link, lstSrc, dest, kjob);
        } else {
            //kDebug(1203) << "KIO::copyAs(" << uSrc.url() << "," << dest.url() << ")";
            KIO::CopyJob * job = KIO::copyAs(uSrc, dest);
            job->setDefaultPermissions(true);
            kjob = job;
            KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Copy, lstSrc, dest, job);
        }
        kjob->ui()->setWindow(m_parentWidget);
        QObject::connect(kjob, SIGNAL(result(KJob*)), q, SLOT(slotResult(KJob*)));
    }
}
Exemplo n.º 13
0
void KonqPopupMenuPrivate::slotPopupEmptyTrashBin()
{
    KIO::JobUiDelegate uiDelegate;
    uiDelegate.setWindow(m_parentWidget);
    if (uiDelegate.askDeleteConfirmation(QList<QUrl>(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) {
        KIO::Job *job = KIO::emptyTrash();
        KJobWidgets::setWindow(job, m_parentWidget);
        job->ui()->setAutoErrorHandlingEnabled(true); // or connect to the result signal
    }
}
Exemplo n.º 14
0
bool NetAccess::delInternal( const KUrl & url, QWidget* window )
{
  d->bJobOK = true; // success unless further error occurs
  KIO::Job * job = KIO::del( url );
  job->ui()->setWindow (window);
  connect( job, SIGNAL( result (KJob *) ),
           this, SLOT( slotResult (KJob *) ) );
  enter_loop();
  return d->bJobOK;
}
Exemplo n.º 15
0
void ReadOnlyPart::abortLoad()
{
    m_file = "";
    if ( m_job )
    {
	KIO::Job *job = m_job;
	m_job = 0;
	job->kill();
    }
}
Exemplo n.º 16
0
void Observer::killJob(int progressId)
{
    KIO::Job *job = m_dctJobs[progressId];
    if(!job)
    {
        kdWarning() << "Can't find job to kill ! There is no job with progressId=" << progressId << " in this process" << endl;
        return;
    }
    job->kill(false /* not quietly */);
}
Exemplo n.º 17
0
void KrTrashHandler::emptyTrash()
{
    QByteArray packedArgs;
    QDataStream stream(&packedArgs, QIODevice::WriteOnly);
    stream << (int)1;
    KIO::Job *job = KIO::special(QUrl(QStringLiteral("trash:/")), packedArgs);
    KNotification::event("Trash: emptied", QString() , QPixmap() , 0l, KNotification::DefaultEvent);
    KIO::JobUiDelegate *ui = static_cast<KIO::JobUiDelegate*>(job->uiDelegate());
    ui->setWindow(krMainWindow);
    QObject::connect(job, SIGNAL(result(KJob *)), ACTIVE_PANEL->func, SLOT(refresh()));
}
Exemplo n.º 18
0
/// Helper to sanely show an error message for a job
void showJobError(KJob *job)
{
    assert(job);
    // we can be called from the KJob::kill, where we are no longer a KIO::Job
    // so better safe than sorry
    KIO::Job *kiojob = qobject_cast<KIO::Job *>(job);
    if (kiojob && kiojob->uiDelegate()) {
        kiojob->uiDelegate()->showErrorMessage();
    } else {
        qCWarning(AKONADIMIME_LOG) << "There is no GUI delegate set for a kjob, and it failed with error:" << job->errorString();
    }
}
Exemplo n.º 19
0
bool ftp_vfs::populateVfsList(const QUrl &origin, bool showHidden)
{
    QString errorMsg;
    if (!origin.isValid())
        errorMsg = i18n("Malformed URL:\n%1", origin.url());
    if (!KProtocolManager::supportsListing(origin)) {
        if (origin.scheme() == "ftp" && KProtocolManager::supportsReading(origin))
            errorMsg = i18n("Krusader does not support FTP access via HTTP.\nIf it is not the case, please check and change the proxy settings in the System Settings.");
        else
            errorMsg = i18n("Protocol not supported by Krusader:\n%1", origin.url());
    }

    if (!errorMsg.isEmpty()) {
        printf("error\n");
        if (!quietMode)
            emit error(errorMsg);
        return false;
    }

    busy = true;

    vfs_origin = origin.adjusted(QUrl::StripTrailingSlash);

    //QTimer::singleShot( 0,this,SLOT(startLister()) );
    listError = false;
    // Open the directory marked by origin
    KIO::Job *job = KIO::listDir(vfs_origin, KIO::HideProgressInfo, showHidden);
    connect(job, SIGNAL(entries(KIO::Job*, const KIO::UDSEntryList&)),
            this, SLOT(slotAddFiles(KIO::Job*, const KIO::UDSEntryList&)));
    connect(job, SIGNAL(redirection(KIO::Job*, const QUrl&)),
            this, SLOT(slotRedirection(KIO::Job*, const QUrl&)));
    connect(job, SIGNAL(permanentRedirection(KIO::Job*, const QUrl&, const QUrl&)),
            this, SLOT(slotPermanentRedirection(KIO::Job*, const QUrl&, const QUrl&)));

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

    if(!parentWindow.isNull()) {
        KIO::JobUiDelegate *ui = static_cast<KIO::JobUiDelegate*>(job->uiDelegate());
        ui->setWindow(parentWindow);
    }

    if (!quietMode) {
        emit startJob(job);
    }

    while (busy && vfs_processEvents());

    if (listError) return false;

    return true;
}
Exemplo n.º 20
0
bool ClientApp::doList( int firstArg )
{
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    KUrl dir = args->url(firstArg);
    KIO::Job * job = KIO::listDir(dir, KIO::HideProgressInfo);
    if ( !s_interactive )
        job->setUiDelegate(0);
    connect(job, SIGNAL(entries(KIO::Job*,KIO::UDSEntryList)),
            SLOT(slotEntries(KIO::Job*,KIO::UDSEntryList)));
    connect(job, SIGNAL(result(KJob *)), this, SLOT(slotResult(KJob *)));
    this->exec();
    return m_ok;
}
Exemplo n.º 21
0
QString NetAccess::mimetypeInternal( const KUrl & url, QWidget* window )
{
  d->bJobOK = true; // success unless further error occurs
  d->m_mimetype = QLatin1String("unknown");
  KIO::Job * job = KIO::mimetype( url );
  job->ui()->setWindow (window);
  connect( job, SIGNAL( result (KJob *) ),
           this, SLOT( slotResult (KJob *) ) );
  connect( job, SIGNAL( mimetype (KIO::Job *, const QString &) ),
           this, SLOT( slotMimetype (KIO::Job *, const QString &) ) );
  enter_loop();
  return d->m_mimetype;
}
Exemplo n.º 22
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();
    }
}
Exemplo n.º 23
0
bool QExtFileInfo::internalCopy(const KURL& src, const KURL& target, int permissions,
                                bool overwrite, bool resume, QWidget* window)
{
  bJobOK = true; // success unless further error occurs

  KIO::Scheduler::checkSlaveOnHold(true);
  KIO::Job * job = KIO::file_copy( src, target, permissions, overwrite, resume );
  job->setWindow (window);
  connect( job, SIGNAL( result (KIO::Job *) ),
           this, SLOT( slotResult (KIO::Job *) ) );

  enter_loop();
  return bJobOK;
}
Exemplo n.º 24
0
void KIOPasteTest::testPasteJob()
{
    QFETCH(QList<QUrl>, urls);
    QFETCH(bool, data);
    QFETCH(bool, cut);
    QFETCH(QString, expectedFileName);

    QMimeData mimeData;
    bool isDir = false;
    bool isFile = false;
    if (!urls.isEmpty()) {
        mimeData.setUrls(urls);
        QFileInfo fileInfo(urls.first().toLocalFile());
        isDir = fileInfo.isDir();
        isFile = fileInfo.isFile();
    }
    if (data) {
        mimeData.setText(QStringLiteral("Hello world"));
    }
    KIO::setClipboardDataCut(&mimeData, cut);

    QTemporaryDir destTempDir;
    QVERIFY(destTempDir.isValid());
    const QString destDir = destTempDir.path();
    KIO::Job *job = KIO::paste(&mimeData, QUrl::fromLocalFile(destDir), KIO::HideProgressInfo);
    QSignalSpy spy(job, SIGNAL(itemCreated(QUrl)));
    QVERIFY(spy.isValid());
    job->setUiDelegate(0);
    const bool expectedSuccess = !expectedFileName.isEmpty();
    QCOMPARE(job->exec(), expectedSuccess);
    if (expectedSuccess) {
        const QString destFile = destDir + '/' + expectedFileName;
        QVERIFY2(QFile::exists(destFile), qPrintable(expectedFileName));
        if (isDir) {
            QVERIFY(QFileInfo(destFile).isDir());
        } else {
            QVERIFY(QFileInfo(destFile).isFile());
            QFile file(destFile);
            QVERIFY(file.open(QIODevice::ReadOnly));
            QCOMPARE(QString(file.readAll()), QString("Hello world"));
        }
        if (cut) {
            QVERIFY(!QFile::exists(urls.first().toLocalFile()));
        } else {
            QVERIFY(QFile::exists(urls.first().toLocalFile()));
        }
        QCOMPARE(spy.count(), isFile || cut ? 1 : 2);
        QCOMPARE(spy.at(0).at(0).value<QUrl>().toLocalFile(), destFile);
    }
}
Exemplo n.º 25
0
bool ClientApp::doRemove( int firstArg )
{
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    int argc = args->count();
    KUrl::List srcLst;
    for ( int i = firstArg; i < argc; i++ )
      srcLst.append( args->url(i) );
    KIO::Job * job = KIO::del( srcLst, s_jobFlags );
    if ( !s_interactive )
        job->setUiDelegate( 0 );
    connect( job, SIGNAL( result( KJob * ) ), this, SLOT( slotResult( KJob * ) ) );
    this->exec();
    return m_ok;
}
Exemplo n.º 26
0
void KonqOperations::_del( Operation method, const KUrl::List & _selectedUrls, ConfirmationType confirmation )
{
    KUrl::List selectedUrls;
    for (KUrl::List::ConstIterator it = _selectedUrls.begin(); it != _selectedUrls.end(); ++it)
        if (KProtocolManager::supportsDeleting(*it))
            selectedUrls.append(*it);
    if (selectedUrls.isEmpty()) {
        delete this; // this one is ok, _del is always called directly
        return;
    }

    if ( confirmation == SKIP_CONFIRMATION || askDeleteConfirmation( selectedUrls, method, confirmation, parentWidget() ) )
    {
        //m_srcUrls = selectedUrls;
        KIO::Job *job;
        m_method = method;
        switch( method )
        {
        case TRASH:
        {
            job = KIO::trash( selectedUrls );
            KIO::FileUndoManager::self()->recordJob( KIO::FileUndoManager::Trash, selectedUrls, KUrl("trash:/"), job );
            break;
        }
        case EMPTYTRASH:
        {
            // Same as in ktrash --empty
            QByteArray packedArgs;
            QDataStream stream( &packedArgs, QIODevice::WriteOnly );
            stream << (int)1;
            job = KIO::special( KUrl("trash:/"), packedArgs );
            KNotification::event("Trash: emptied", QString() , QPixmap() , 0l, KNotification::DefaultEvent );
            break;
        }
        case DEL:
            job = KIO::del( selectedUrls );
            break;
        default:
            kWarning() << "Unknown operation: " << method ;
            delete this; // this one is ok, _del is always called directly
            return;
        }
        job->ui()->setWindow(parentWidget());
        connect( job, SIGNAL(result(KJob*)),
                 SLOT(slotResult(KJob*)) );
    } else {
        delete this; // this one is ok, _del is always called directly
    }
}
Exemplo n.º 27
0
bool NetAccess::dircopyInternal(const KUrl::List& src, const KUrl& target,
                                QWidget* window, bool move)
{
  d->bJobOK = true; // success unless further error occurs

  KIO::Job * job = move
                   ? KIO::move( src, target )
                   : KIO::copy( src, target );
  job->ui()->setWindow (window);
  connect( job, SIGNAL( result (KJob *) ),
           this, SLOT( slotResult (KJob *) ) );

  enter_loop();
  return d->bJobOK;
}
Exemplo n.º 28
0
void ImageshackTalker::slotResult(KJob* kjob)
{
    KIO::Job* job = static_cast<KIO::Job*>(kjob);

    if (job->error())
    {
        if (m_loginInProgress)
        {
            checkRegistrationCodeDone(job->error(), job->errorString());
            m_loginInProgress = false;
        }
        else if (m_state == IMGHCK_GETGALLERIES)
        {
            emit signalBusy(false);
            emit signalGetGalleriesDone(job->error(), job->errorString());
        }
        else if (m_state == IMGHCK_ADDPHOTO || m_state == IMGHCK_ADDPHOTOGALLERY)
        {
            emit signalBusy(false);
            emit signalAddPhotoDone(job->error(), job->errorString());
        }
        m_state = IMGHCK_DONOTHING;
        m_job = 0;
        return;
    }

    int step;
    switch (m_state)
    {
        case IMGHCK_CHECKREGCODE:
            m_job = 0;
            parseCheckRegistrationCode(m_buffer);
            break;
        case IMGHCK_ADDPHOTOGALLERY:
            step = job->property("k_step").toInt();
            if (step == STEP_UPLOADITEM)
                parseUploadPhotoDone(m_buffer);
            else
                parseAddPhotoToGalleryDone(m_buffer);
            break;
        case IMGHCK_ADDVIDEO:
        case IMGHCK_ADDPHOTO:
            m_job = 0;
            parseUploadPhotoDone(m_buffer);
            break;
        case IMGHCK_GETGALLERIES:
            m_job = 0;
            parseGetGalleries(m_buffer);
            break;
        default:
            break;
    }
}
Exemplo n.º 29
0
static bool checkNetworkAccess()
{
    if (s_networkAccess == Unknown) {
        QElapsedTimer tm;
        tm.start();
        KIO::Job *job = KIO::get(QUrl(s_iconUrl), KIO::NoReload, KIO::HideProgressInfo);
        if (job->exec()) {
            s_networkAccess = Yes;
            qDebug() << "Network access OK. Download time" << tm.elapsed() << "ms";
        } else {
            qWarning() << job->errorString();
            s_networkAccess = No;
        }
    }
    return s_networkAccess == Yes;
}
Exemplo n.º 30
0
bool NetAccess::filecopyInternal(const KUrl& src, const KUrl& target, int permissions,
                                 KIO::JobFlags flags, QWidget* window, bool move)
{
  d->bJobOK = true; // success unless further error occurs

  KIO::Scheduler::checkSlaveOnHold(true);
  KIO::Job * job = move
                   ? KIO::file_move( src, target, permissions, flags )
                   : KIO::file_copy( src, target, permissions, flags );
  job->ui()->setWindow (window);
  connect( job, SIGNAL( result (KJob *) ),
           this, SLOT( slotResult (KJob *) ) );

  enter_loop();
  return d->bJobOK;
}