コード例 #1
0
bool GroupDavGlobals::interpretAddressBookDownloadItemsJob(
    KABC::AddressBookAdaptor *adaptor, KIO::Job *job, const QString &jobData)
{
    kdDebug(5800) << "GroupDavGlobals::interpretAddressBookDownloadItemsJob, vCard=" << endl;
    kdDebug(5800) << jobData << endl;
    if(!adaptor || !job) return false;

    KABC::VCardConverter conv;
    KABC::Addressee::List addrs(conv.parseVCards(jobData));

    if(addrs.count() != 1)
    {
        kdError() << "Parsed vCard does not contain exactly one addressee." << endl;
        return false;
    }

    KABC::Addressee a = addrs.first();

    KIO::SimpleJob *sjob = dynamic_cast<KIO::SimpleJob *>(job);
    KURL remoteId;
    if(sjob) remoteId = sjob->url();
    QString fingerprint = extractFingerprint(job, jobData);
    adaptor->addressbookItemDownloaded(a, a.uid(), remoteId, fingerprint,
                                       remoteId.prettyURL());
    return true;
}
コード例 #2
0
bool GroupDavGlobals::interpretCalendarDownloadItemsJob( KCal::CalendarAdaptor *adaptor,
                                         KIO::Job *job, const QString &jobData )
{
kdDebug(5800) << "GroupDavGlobals::interpretCalendarDownloadItemsJob, iCalendar=" << endl;
kdDebug(5800) << jobData << endl;
  if ( !adaptor || !job ) return false;
  KCal::CalendarLocal calendar( QString::fromLatin1("UTC") );
  KCal::ICalFormat ical;
  calendar.setTimeZoneId( adaptor->resource()->timeZoneId() );
  KCal::Incidence::List incidences;
  if ( ical.fromString( &calendar, jobData ) ) {
    KCal::Incidence::List raw = calendar.rawIncidences();
    KCal::Incidence::List::Iterator it = raw.begin();
    if ( raw.count() != 1 ) {
      kdError() << "Parsed iCalendar does not contain exactly one event." << endl;
      return false;
    }

    KCal::Incidence *inc = (raw.front())->clone();
    if ( !inc ) return false;
    KIO::SimpleJob *sjob = dynamic_cast<KIO::SimpleJob *>(job);
    KURL remoteId;
    if ( sjob ) remoteId = sjob->url();
    QString fingerprint = extractFingerprint( job, jobData );
    adaptor->calendarItemDownloaded( inc, inc->uid(), remoteId, fingerprint,
                                     remoteId.prettyURL() );
    return true;
  } else {
    kdError() << "Unable to parse iCalendar" << endl;
  }
  return false;
}
コード例 #3
0
void FileUndoManagerTest::testCreateDir()
{
    const KUrl url( srcSubDir() + ".mkdir" );
    const QString path = url.toLocalFile();
    QVERIFY( !QFile::exists(path) );

    KIO::SimpleJob* job = KIO::mkdir(url);
    job->setUiDelegate( 0 );
    FileUndoManager::self()->recordJob( FileUndoManager::Mkdir, KUrl(), url, job );
    bool ok = KIO::NetAccess::synchronousRun( job, 0 );
    QVERIFY( ok );
    QVERIFY( QFile::exists(path) );
    QVERIFY( QFileInfo(path).isDir() );

    m_uiInterface->clear();
    m_uiInterface->setNextReplyToConfirmDeletion( false ); // act like the user didn't confirm
    FileUndoManager::self()->undo();
    QCOMPARE( m_uiInterface->files().count(), 1 ); // confirmDeletion was called
    QCOMPARE( m_uiInterface->files()[0].url(), url.url() );
    QVERIFY( QFile::exists(path) ); // nothing happened yet

    // OK, now do it
    m_uiInterface->clear();
    m_uiInterface->setNextReplyToConfirmDeletion( true );
    doUndo();

    QVERIFY( !QFile::exists(path) );
}
コード例 #4
0
void FolderLister::slotListJobResult( KIO::Job *job )
{
  kdDebug(7000) << "OpenGroupware::slotListJobResult(): " << endl;
  kdDebug() << "URLS (" << mUrls.count() << "): " << mUrls.toStringList().join(" | ") << endl;
  kdDebug() << "Processed URLS (" << mProcessedPathes.count() << "): "
            << mProcessedPathes.join(" | ") << endl;
  KIO::SimpleJob *j = dynamic_cast<KIO::SimpleJob*>(job);
  if ( j ) {
    mUrls.remove( j->url() );
    mProcessedPathes.append( j->url().path(-1) );
  }

  if ( job->error() ) {
    kdError() << "Unable to retrieve folders." << endl;
  } else {
    interpretListFoldersJob( job );
  }
  kdDebug() << "After URLS (" << mUrls.count() << "): " 
            << mUrls.toStringList().join(" | ") << endl;
  kdDebug() << "After Processed URLS (" << mProcessedPathes.count() << "): "
            << mProcessedPathes.join(" | ") << endl;
  if ( mUrls.isEmpty() ) {
    kdDebug()<<"No more URLS to download, emitting foldersRead()"<<endl;
    emit foldersRead();
  }
}
コード例 #5
0
KIO::SimpleJob* KonqOperations::mkdir( QWidget *parent, const KUrl & url )
{
    KIO::SimpleJob * job = KIO::mkdir(url);
    job->ui()->setWindow(parent);
    job->ui()->setAutoErrorHandlingEnabled(true);
    KIO::FileUndoManager::self()->recordJob( KIO::FileUndoManager::Mkdir, KUrl(), url, job );
    return job;
}
コード例 #6
0
ファイル: templates.cpp プロジェクト: KDE/kile
bool Manager::removeAppData(const QString &file) {
	QFileInfo fileInfo(file);
	if(fileInfo.exists()) {
		KIO::SimpleJob* deleteJob = KIO::file_delete(QUrl::fromUserInput(file));
		KJobWidgets::setWindow(deleteJob, m_kileInfo->mainWindow());
		return deleteJob->exec();
	}
	return true;
}
コード例 #7
0
ファイル: kwebdesktop.cpp プロジェクト: serghei/kde3-kdebase
void KWebDesktopRun::slotMimetype(KIO::Job *job, const QString &_type)
{
    KIO::SimpleJob *sjob = static_cast< KIO::SimpleJob * >(job);
    // Update our URL in case of a redirection
    m_url = sjob->url();
    QString type = _type; // necessary copy if we plan to use it
    sjob->putOnHold();
    kdDebug() << "slotMimetype : " << type << endl;

    KParts::ReadOnlyPart *part = m_webDesktop->createPart(type);
    // Now open the URL in the part
    if(part)
        part->openURL(m_url);
}
コード例 #8
0
ファイル: UpnpCollectionBase.cpp プロジェクト: ErrAza/amarok
void UpnpCollectionBase::slotRemoveJob(KJob* job)
{
    KIO::SimpleJob *sj = static_cast<KIO::SimpleJob*>( job );

    m_jobSet.remove( sj );

    if( sj->error() ) {
        m_continuousJobFailureCount++;
        if( m_continuousJobFailureCount >= MAX_JOB_FAILURES_BEFORE_ABORT ) {
            debug() << prettyName() << "Had" << m_continuousJobFailureCount << "continuous job failures, something wrong with the device. Removing this collection.";
            emit remove();
        }
    }
    else {
        m_continuousJobFailureCount = 0;
    }
}
コード例 #9
0
void MediaNotifier::onMediumChange(const QString &name, bool allowNotification)
{
    kdDebug() << "MediaNotifier::onMediumChange( " << name << ", " << allowNotification << ")" << endl;

    if(!allowNotification)
        return;

    // Update user activity timestamp, otherwise the notification dialog will be shown
    // in the background due to focus stealing prevention. Entering a new media can
    // be seen as a kind of user activity after all. It'd be better to update the timestamp
    // as soon as the media is entered, but it apparently takes some time to get here.
    kapp->updateUserTimestamp();

    KURL url("system:/media/" + name);

    KIO::SimpleJob *job = KIO::stat(url, false);
    job->setInteractive(false);

    m_allowNotificationMap[job] = allowNotification;

    connect(job, SIGNAL(result(KIO::Job *)), this, SLOT(slotStatResult(KIO::Job *)));
}
コード例 #10
0
void ExchangeDelete::startDelete(const KURL &url)
{
    KIO::SimpleJob *job = KIO::file_delete(url, false);   // no GUI
    job->setWindow(mWindow);
    connect(job, SIGNAL(result(KIO::Job *)), this, SLOT(slotDeleteResult(KIO::Job *)));
}
コード例 #11
0
QNetworkReply *AccessManager::createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData)
{
    const KUrl reqUrl (req.url());

    if (!d->externalContentAllowed &&
        !KDEPrivate::AccessManagerReply::isLocalRequest(reqUrl) &&
        reqUrl.scheme() != QL1S("data")) {
        kDebug( 7044 ) << "Blocked: " << reqUrl;
        return new KDEPrivate::AccessManagerReply(op, req, QNetworkReply::ContentAccessDenied, i18n("Blocked request."), this);
    }

    // Check if the internal ignore content disposition header is set.
    const bool ignoreContentDisposition = req.hasRawHeader("x-kdewebkit-ignore-disposition");

    // Retrieve the KIO meta data...
    KIO::MetaData metaData;
    d->setMetaDataForRequest(req, metaData);

    KIO::SimpleJob *kioJob = 0;

    switch (op) {
        case HeadOperation: {
            //kDebug( 7044 ) << "HeadOperation:" << reqUrl;
            kioJob = KIO::mimetype(reqUrl, KIO::HideProgressInfo);
            break;
        }
        case GetOperation: {
            //kDebug( 7044 ) << "GetOperation:" << reqUrl;
            if (!reqUrl.path().isEmpty() || reqUrl.host().isEmpty())
                kioJob = KIO::get(reqUrl, KIO::NoReload, KIO::HideProgressInfo);
            else
                kioJob = KIO::stat(reqUrl, KIO::HideProgressInfo);

            // WORKAROUND: Avoid the brain damaged stuff QtWebKit does when a POST
            // operation is redirected! See BR# 268694.
            metaData.remove(QL1S("content-type")); // Remove the content-type from a GET/HEAD request!
            break;
        }
        case PutOperation: {
            //kDebug( 7044 ) << "PutOperation:" << reqUrl;
            if (outgoingData)
                kioJob = KIO::storedPut(outgoingData->readAll(), reqUrl, -1, KIO::HideProgressInfo);
            else
                kioJob = KIO::put(reqUrl, -1, KIO::HideProgressInfo);
            break;
        }
        case PostOperation: {
            kioJob = KIO::http_post(reqUrl, outgoingData, sizeFromRequest(req), KIO::HideProgressInfo);
            if (!metaData.contains(QL1S("content-type")))  {
                const QVariant header = req.header(QNetworkRequest::ContentTypeHeader);
                if (header.isValid()) {
                    metaData.insert(QL1S("content-type"),
                                    (QL1S("Content-Type: ") + header.toString()));
                } else {
                    metaData.insert(QL1S("content-type"),
                                    QL1S("Content-Type: application/x-www-form-urlencoded"));
                }
            }
            break;
        }
        case DeleteOperation: {
            //kDebug(7044) << "DeleteOperation:" << reqUrl;
            kioJob = KIO::http_delete(reqUrl, KIO::HideProgressInfo);
            break;
        }
        case CustomOperation: {
            const QByteArray& method = req.attribute(QNetworkRequest::CustomVerbAttribute).toByteArray();
            //kDebug(7044) << "CustomOperation:" << reqUrl << "method:" << method << "outgoing data:" << outgoingData;

            if (method.isEmpty()) {
                return new KDEPrivate::AccessManagerReply(op, req, QNetworkReply::ProtocolUnknownError, i18n("Unknown HTTP verb."), this);
            }

            if (outgoingData)
                kioJob = KIO::http_post(reqUrl, outgoingData, sizeFromRequest(req), KIO::HideProgressInfo);
            else
                kioJob = KIO::get(reqUrl, KIO::NoReload, KIO::HideProgressInfo);

            metaData.insert(QL1S("CustomHTTPMethod"), method);
            break;
        }
        default: {
            kWarning(7044) << "Unsupported KIO operation requested! Defering to QNetworkAccessManager...";
            return QNetworkAccessManager::createRequest(op, req, outgoingData);
        }
    }

    // Set the job priority
    switch (req.priority()) {
    case QNetworkRequest::HighPriority:
        KIO::Scheduler::setJobPriority(kioJob, -5);
        break;
    case QNetworkRequest::LowPriority:
        KIO::Scheduler::setJobPriority(kioJob, 5);
        break;
    default:
        break;
    }

    KDEPrivate::AccessManagerReply *reply;

    /*
      NOTE: Here we attempt to handle synchronous XHR requests. Unfortunately,
      due to the fact that QNAM is both synchronous and multi-thread while KIO
      is completely the opposite (asynchronous and not thread safe), the code
      below might cause crashes like the one reported in bug# 287778 (nested
      event loops are inherently dangerous).

      Unfortunately, all attempts to address the crash has so far failed due to
      the many regressions they caused, e.g. bug# 231932 and 297954. Hence, until
      a solution is found, we have to live with the side effects of creating
      nested event loops.
    */
    if (req.attribute(gSynchronousNetworkRequestAttribute).toBool()) {
        KUrl finalURL;
        QByteArray data;

        if (KIO::NetAccess::synchronousRun(kioJob, d->window, &data, &finalURL, &metaData)) {
            reply = new KDEPrivate::AccessManagerReply(op, req, data, finalURL, metaData, this);
            kDebug(7044) << "Synchronous XHR:" << reply << reqUrl;
        } else {
            kWarning(7044) << "Failed to create a synchronous XHR for" << reqUrl;
            reply = new KDEPrivate::AccessManagerReply(op, req, QNetworkReply::UnknownNetworkError, kioJob->errorText(), this);
        }
    } else {
        // Set the window on the the KIO ui delegate
        if (d->window) {
            kioJob->ui()->setWindow(d->window);
        }

        // Disable internal automatic redirection handling
        kioJob->setRedirectionHandlingEnabled(false);

        // Set the job priority
        switch (req.priority()) {
        case QNetworkRequest::HighPriority:
            KIO::Scheduler::setJobPriority(kioJob, -5);
            break;
        case QNetworkRequest::LowPriority:
            KIO::Scheduler::setJobPriority(kioJob, 5);
            break;
        default:
            break;
        }

        // Set the meta data for this job...
        kioJob->setMetaData(metaData);

        // Create the reply...
        reply = new KDEPrivate::AccessManagerReply(op, req, kioJob, d->emitReadyReadOnMetaDataChange, this);
        //kDebug(7044) << reply << reqUrl;
    }

    if (ignoreContentDisposition && reply) {
        //kDebug(7044) << "Content-Disposition WILL BE IGNORED!";
        reply->setIgnoreContentDisposition(ignoreContentDisposition);
    }

    return reply;
}