예제 #1
0
    bool downloadRemoteUrls(const QString& collectionName, const KUrl::List& _list, RemoteUrlHash* hash)
    {
        Q_ASSERT(hash);
        KUrl::List list;
        Q_FOREACH(const KUrl& url, _list)
        {
            if (!url.isLocalFile())
            {
                list << url;
            }
        }

        if (list.count() == 0)
        {
            return true;
        }

        logInfo( i18n("Downloading remote files for \"%1\"", collectionName) );

        mProgressDialog->progressWidget()->setTotal(list.count());
        int count = 0;
        Q_FOREACH(const KUrl& url, list)
        {
            if (mProgressDialog->isHidden())
            {
                return false;
            }
            KTemporaryFile* tempFile = new KTemporaryFile;
            // Ensure the tempFile gets deleted when mProgressDialog is closed
            tempFile->setParent(mProgressDialog);
            tempFile->setPrefix("htmlexport-");

            if (!tempFile->open())
            {
                delete tempFile;
                logError(i18n("Could not open temporary file"));
                return false;
            }
            const QString tempPath = KStandardDirs::locate("tmp", tempFile->fileName());
            KIO::Job* job          = KIO::file_copy(url, KUrl::fromPath(tempPath), -1 /* permissions */, KIO::Overwrite);
            if (KIO::NetAccess::synchronousRun(job, mProgressDialog))
            {
                hash->insert(url, tempFile->fileName());
            }
            else
            {
                logWarning(i18n("Could not download %1", url.prettyUrl()));
                hash->insert(url, QString());
            }

            ++count;
            mProgressDialog->progressWidget()->setProgress(count);
        }

        return true;
    }
예제 #2
0
void TutorialTester::sendTutorialToTargetApplication() {
    disconnect(TargetApplication::self(), SIGNAL(started()),
               this, SLOT(sendTutorialToTargetApplication()));

    //As this TutorialTester is set as parent of the KTemporaryFile object, the
    //file will be automatically removed when this TutorialTester is destroyed
    KTemporaryFile* temporaryFile = new KTemporaryFile();
    temporaryFile->setAutoRemove(true);
    temporaryFile->setParent(this);
    temporaryFile->setSuffix(".js");
    temporaryFile->open();

    const Tutorial* tutorial = mTutorialEditor->tutorial();
    try {
        Serialization(mTutorialEditor).
                    exportTutorial(tutorial, "*.js", temporaryFile->fileName());
    } catch (IOException e) {
        QString text = i18nc("@label", "There was a problem when trying to "
"save the tutorial to a temporary file (to be used by the target application "
"to test the tutorial):<nl/>%1", e.message());
        QString caption = i18nc("@title:window", "Tutorial could not be saved");
        KMessageBox::error(mTutorialEditor, text, caption);
        delete temporaryFile;
        return;
    }

    try {
        if (mStepId.isEmpty()) {
            TargetApplication::self()->remoteEditorSupport()->
                                testScriptedTutorial(temporaryFile->fileName());
        } else {
            TargetApplication::self()->remoteEditorSupport()->
                    testScriptedTutorial(temporaryFile->fileName(), mStepId);
        }
    } catch (DBusException e) {
        QString text = i18nc("@label", "There was a problem when trying to "
"tell the target application to start the tutorial:<nl/>%1", e.message());
        QString caption = i18nc("@title:window", "Tutorial could not be "
"started");
        KMessageBox::error(mTutorialEditor, text, caption);
    }
}
    KUrl tempFileForAttachment( KCal::Attachment *attachment )
    {
      if ( mTempFiles.contains( attachment ) ) {
        return mTempFiles.value( attachment );
      }
      KTemporaryFile *file = new KTemporaryFile();
      file->setParent( this );

      QStringList patterns = KMimeType::mimeType( attachment->mimeType() )->patterns();

      if ( !patterns.empty() ) {
        file->setSuffix( QString( patterns.first() ).remove( '*' ) );
      }
      file->setAutoRemove( true );
      file->open();
      // read-only not to give the idea that it could be written to
      file->setPermissions( QFile::ReadUser );
      file->write( QByteArray::fromBase64( attachment->data() ) );
      mTempFiles.insert( attachment, file->fileName() );
      file->close();
      return mTempFiles.value( attachment );
    }