예제 #1
0
void FileUndoManagerTest::testModifyFileBeforeUndo()
{
    // based on testCopyDirectory (so that we check that it works for files in subdirs too)
    const QString destdir = destDir();
    KUrl::List lst; lst << srcSubDir();
    const KUrl d( destdir );
    KIO::CopyJob* job = KIO::copy( lst, d, KIO::HideProgressInfo );
    job->setUiDelegate( 0 );
    FileUndoManager::self()->recordCopyJob(job);

    bool ok = KIO::NetAccess::synchronousRun( job, 0 );
    QVERIFY( ok );

    checkTestDirectory( srcSubDir() ); // src untouched
    checkTestDirectory( destSubDir() );
    const QString destFile =  destSubDir() + "/fileindir";
    setTimeStamp( destFile ); // simulate a modification of the file

    doUndo();

    // Check that TestUiInterface::copiedFileWasModified got called
    QCOMPARE( m_uiInterface->dest().toLocalFile(), destFile );

    checkTestDirectory( srcSubDir() );
    QVERIFY( !QFile::exists( destSubDir() ) );

}
예제 #2
0
void FileUndoManagerTest::testMoveFiles()
{
    kDebug() ;
    const QString destdir = destDir();
    KUrl::List lst = sourceList();
    const KUrl d( destdir );
    KIO::CopyJob* job = KIO::move( lst, d, KIO::HideProgressInfo );
    job->setUiDelegate( 0 );
    FileUndoManager::self()->recordCopyJob(job);

    bool ok = KIO::NetAccess::synchronousRun( job, 0 );
    QVERIFY( ok );

    QVERIFY( !QFile::exists( srcFile() ) ); // the source moved
    QVERIFY( QFile::exists( destFile() ) );
#ifndef Q_WS_WIN
    QVERIFY( !QFileInfo( srcLink() ).isSymLink() );
    // Don't use QFile::exists, it's a broken symlink...
    QVERIFY( QFileInfo( destLink() ).isSymLink() );
#endif

    doUndo();

    QVERIFY( QFile::exists( srcFile() ) ); // the source is back
    QVERIFY( !QFile::exists( destFile() ) );
#ifndef Q_WS_WIN
    QVERIFY( QFileInfo( srcLink() ).isSymLink() );
    QVERIFY( !QFileInfo( destLink() ).isSymLink() );
#endif
}
예제 #3
0
void JobTest::moveFileNoPermissions()
{
    kdDebug() << k_funcinfo << endl;
    const QString src = "/etc/passwd";
    const QString dest = homeTmpDir() + "passwd";
    assert(QFile::exists(src));
    assert(QFileInfo(src).isFile());
    KURL u;
    u.setPath(src);
    KURL d;
    d.setPath(dest);

    KIO::CopyJob *job = KIO::move(u, d, 0);
    job->setInteractive(false); // no skip dialog, thanks
    QMap< QString, QString > metaData;
    bool ok = KIO::NetAccess::synchronousRun(job, 0, 0, 0, &metaData);
    assert(!ok);
    assert(KIO::NetAccess::lastError() == KIO::ERR_ACCESS_DENIED);
    // OK this is fishy. Just like mv(1), KIO's behavior depends on whether
    // a direct rename(2) was used, or a full copy+del. In the first case
    // there is no destination file created, but in the second case the
    // destination file remains.
    // In fact we assume /home is a separate partition, in this test, so:
    assert(QFile::exists(dest));
    assert(QFile::exists(src));
}
예제 #4
0
KonqOperations *KonqOperations::doPasteV2(QWidget *parent, const KUrl &destUrl, const QPoint &pos)
{
    QClipboard *clipboard = QApplication::clipboard();
    const QMimeData *data = clipboard->mimeData();
    const bool move = KonqMimeData::decodeIsCutSelection(data);

    KIO::Job *job = KIO::pasteClipboard(destUrl, parent, move);
    if (job) {
        KonqOperations *op = new KonqOperations(parent);
        KIOPasteInfo *pi = new KIOPasteInfo;
        pi->mousePos = pos;
        op->setPasteInfo(pi);
        KIO::CopyJob *copyJob = qobject_cast<KIO::CopyJob*>(job);
        if (copyJob) {
            op->setOperation(job, move ? MOVE : COPY, copyJob->destUrl());
            KIO::FileUndoManager::self()->recordJob(move ? KIO::FileUndoManager::Move : KIO::FileUndoManager::Copy, KUrl::List(), destUrl, job);
            connect(copyJob, SIGNAL(copyingDone(KIO::Job*,KUrl,KUrl,time_t,bool,bool)),
                    op, SLOT(slotCopyingDone(KIO::Job*,KUrl,KUrl)));
            connect(copyJob, SIGNAL(copyingLinkDone(KIO::Job*,KUrl,QString,KUrl)),
                    op, SLOT(slotCopyingLinkDone(KIO::Job*,KUrl,QString,KUrl)));
        } else if (KIO::SimpleJob *simpleJob = qobject_cast<KIO::SimpleJob*>(job)) {
            op->setOperation(job, PUT, simpleJob->url());
            KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Put, KUrl::List(), simpleJob->url(), job);
        }
        return op;
    }

    return 0;
}
예제 #5
0
void DBPediaQuery::launchQuery(const QString &query, const QString &requestKey)
{
    //Construct dbpedia url
    QString dbPediaSPARQL = QString(QUrl::toPercentEncoding(query));
    QString dbPediaUrlString= QString("http://dbpedia.org/sparql/?format=application/xml&query=%1").arg(dbPediaSPARQL);
    KUrl dbPediaUrl = KUrl(dbPediaUrlString);

    //Add query url to request collection
    m_requests.insert(requestKey, dbPediaUrl);

    //Prepare download target location
    QString targetFileName = QString("bangarang/%1.tmp")
                                .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
    KUrl dbPediaDownloadUrl = KUrl(KStandardDirs::locateLocal("data", targetFileName, true));
    QFile downloadTarget(dbPediaDownloadUrl.path());
    downloadTarget.remove();

    //Launch query
    KIO::CopyJob *copyJob = KIO::copy(dbPediaUrl, dbPediaDownloadUrl, KIO::Overwrite | KIO::HideProgressInfo);
    copyJob->setAutoDelete(true);
    connect (copyJob,
             SIGNAL(copyingDone(KIO::Job*,KUrl,KUrl,time_t,bool,bool)),
             this,
             SLOT(resultsReturned(KIO::Job*,KUrl,KUrl,time_t,bool,bool)));
    copyJob->setUiDelegate(0);
}
예제 #6
0
bool Bundle::installPackage(const QString &archivePath, const QString &packageRoot)
{
    //kDebug() << "??????????????" << archivePath << packageRoot;
    QFile f(archivePath);
    f.open(QIODevice::ReadOnly);
    m_data = f.readAll();
    f.close();
    open();

    if (m_isValid) {
        m_tempDir->setAutoRemove(false);
        QString pluginName = "dashboard_" + m_bundleId;
        //kDebug() << "valid, so going to move it in to" << pluginName;
        KIO::CopyJob* job = KIO::move(m_tempDir->name(), QString(packageRoot + pluginName), KIO::HideProgressInfo);
        m_isValid = job->exec();

        if (m_isValid) {
            //kDebug() << "still so good ... registering";
            Plasma::PackageMetadata data;
            data.setName(m_name);
            data.setDescription(m_description);
            data.setPluginName(pluginName);
            data.setImplementationApi("dashboard");
            Plasma::Package::registerPackage(data, m_iconLocation);
        }
    }

    if (!m_isValid) {
        // make sure we clean up after ourselves afterwards on failure
        m_tempDir->setAutoRemove(true);
    }

    return m_isValid;
}
예제 #7
0
void TreeLog::onSaveLog()
{
	const QUrl url = QFileDialog::getSaveFileUrl();

	if (!url.isEmpty())
	{
		QTemporaryFile tempFile;

		if (!tempFile.open())
		{
			KMessageBox::error(this, xi18nc("@info", "Could not create temporary output file to save <filename>%1</filename>.", url.fileName()), i18nc("@title:window", "Error Saving Log File"));
			return;
		}

		QTextStream stream(&tempFile);

		for (qint32 idx = 0; idx < treeLog().topLevelItemCount(); idx++)
		{
			QTreeWidgetItem* item = treeLog().topLevelItem(idx);
			stream << item->text(1) << ": " << item->text(2) << "\n";
		}

		tempFile.close();

		KIO::CopyJob* job = KIO::move(QUrl::fromLocalFile(tempFile.fileName()), url, KIO::HideProgressInfo);
		job->exec();
		if ( job->error() )
			job->ui()->showErrorMessage();
	}
}
예제 #8
0
void KPrHtmlExport::copyFromTmpToDest()
{
    KIO::CopyJob *job = KIO::moveAs(m_tmpDirPath, m_parameters.destination);
    job->setWriteIntoExistingDirectories(true);
    job->setUiDelegate(new KPrHtmlExportUiDelegate);
    connect(job, SIGNAL(result(KJob*)), this, SLOT(moveResult(KJob*)));
    job->exec();
}
예제 #9
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*)));
    }
}
예제 #10
0
void FileUndoManagerTest::testCopyFiles()
{
    kDebug() ;
    // Initially inspired from JobTest::copyFileToSamePartition()
    const QString destdir = destDir();
    KUrl::List lst = sourceList();
    const KUrl d( destdir );
    KIO::CopyJob* job = KIO::copy( lst, d, KIO::HideProgressInfo );
    job->setUiDelegate( 0 );
    FileUndoManager::self()->recordCopyJob(job);

    QSignalSpy spyUndoAvailable( FileUndoManager::self(), SIGNAL(undoAvailable(bool)) );
    QVERIFY( spyUndoAvailable.isValid() );
    QSignalSpy spyTextChanged( FileUndoManager::self(), SIGNAL(undoTextChanged(QString)) );
    QVERIFY( spyTextChanged.isValid() );

    bool ok = KIO::NetAccess::synchronousRun( job, 0 );
    QVERIFY( ok );

    QVERIFY( QFile::exists( destFile() ) );
#ifndef Q_WS_WIN
    // Don't use QFile::exists, it's a broken symlink...
    QVERIFY( QFileInfo( destLink() ).isSymLink() );
#endif

    // might have to wait for dbus signal here... but this is currently disabled.
    //QTest::qWait( 20 );
    QVERIFY( FileUndoManager::self()->undoAvailable() );
    QCOMPARE( spyUndoAvailable.count(), 1 );
    QCOMPARE( spyTextChanged.count(), 1 );
    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(), KUrl(destFile()).url() );
    QVERIFY( QFile::exists( destFile() ) ); // nothing happened yet

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

    QVERIFY( !FileUndoManager::self()->undoAvailable() );
    QVERIFY( spyUndoAvailable.count() >= 2 ); // it's in fact 3, due to lock/unlock emitting it as well
    QCOMPARE( spyTextChanged.count(), 2 );
    QCOMPARE( m_uiInterface->files().count(), 1 ); // confirmDeletion was called
    QCOMPARE( m_uiInterface->files()[0].url(), KUrl(destFile()).url() );

    // Check that undo worked
    QVERIFY( !QFile::exists( destFile() ) );
#ifndef Q_WS_WIN
    QVERIFY( !QFile::exists( destLink() ) );
    QVERIFY( !QFileInfo( destLink() ).isSymLink() );
#endif
}
예제 #11
0
void KDirSelectDialog::Private::slotMoveToTrash()
{
    const KUrl url = m_treeView->selectedUrl();
    KIO::JobUiDelegate job;
    if (job.askDeleteConfirmation(KUrl::List() << url, KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) {
        KIO::CopyJob* copyJob = KIO::trash(url);
        copyJob->ui()->setWindow(m_parent);
        copyJob->ui()->setAutoErrorHandlingEnabled(true);
    }
}
예제 #12
0
void Importer::slotCopyDone(KJob* _job)
{
    KIO::CopyJob* job = static_cast<KIO::CopyJob*>(_job);
    KUrl url = job->destUrl();
    if (job->error()) {
        kWarning() << "FIXME: What do we do with failed urls?";
        advance();
        d->importNext();
        return;
    }

    d->renameImportedUrl(url);
}
예제 #13
0
void Downloader::download(const QUrl &from, const QUrl &to)
{
    if (to.isLocalFile()) {
        QFile fileTarget(to.path());
        fileTarget.remove();
    }
    KIO::CopyJob *copyJob = KIO::copyAs(from, to, KIO::Overwrite | KIO::HideProgressInfo);
    copyJob->setUiDelegate(0);
    copyJob->setAutoDelete(true);
    connect (copyJob, 
             SIGNAL(copyingDone(KIO::Job*,QUrl,QUrl,time_t,bool,bool)),
             this,
             SLOT(copyingDone(KIO::Job*,QUrl,QUrl,time_t,bool,bool)));
}
예제 #14
0
void KNewFileMenuPrivate::executeStrategy()
{
    m_tempFileToDelete = m_strategy.tempFileToDelete();
    const QString src = m_strategy.sourceFileToCopy();
    QString chosenFileName = expandTilde(m_strategy.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());
    }

    // 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_strategy.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*)));
    }
    
}
예제 #15
0
void KSWizard::slotFinish()
{
  Configuration::setMouseNavigation(m_mouseNavigation->isChecked());
  Configuration::setScrollBar(m_scrollBar->isChecked());
  Configuration::setSmoothScroll(m_smoothScroll->isChecked());
  Configuration::setAutoUpdateLanguage(m_upgradeManager->isChecked());
//  Configuration::setAuthorName(m_authorName->text());
//  Configuration::setAuthorEmail(m_authorEmail->text());
  Configuration::writeConfig();

  if(m_remoteLanguages->isChecked())
  {
    m_downloadProgress->setShown(true);
    m_downloadLabel->setShown(true);
    KIO::copy(KURL("http://kslovar.berlios.de/version"), KURL(locateLocal("appdata", "version", false)))->setInteractive(false);
    KIO::CopyJob *download = KIO::copy(KURL("http://kslovar.berlios.de/languages.ldft"), KURL(locateLocal("appdata", "languages.ldft", false)), false);
    connect(download, SIGNAL(result(KIO::Job*)), this, SLOT(slotCompletedDownload(KIO::Job*)));
    connect(download, SIGNAL(percent(KIO::Job*, unsigned long)), this, SLOT(slotProgress(KIO::Job*, unsigned long)));
    download->setInteractive(false);
  }
예제 #16
0
void FileUndoManagerTest::testMoveDirectory()
{
    const QString destdir = destDir();
    KUrl::List lst; lst << srcSubDir();
    const KUrl d( destdir );
    KIO::CopyJob* job = KIO::move( lst, d, KIO::HideProgressInfo );
    job->setUiDelegate( 0 );
    FileUndoManager::self()->recordCopyJob(job);

    bool ok = KIO::NetAccess::synchronousRun( job, 0 );
    QVERIFY( ok );

    QVERIFY( !QFile::exists( srcSubDir() ) );
    checkTestDirectory( destSubDir() );

    doUndo();

    checkTestDirectory( srcSubDir() );
    QVERIFY( !QFile::exists( destSubDir() ) );
}
예제 #17
0
void JobTest::moveDirectoryNoPermissions()
{
    kdDebug() << k_funcinfo << endl;
    const QString src = "/etc/init.d";
    const QString dest = homeTmpDir() + "init.d";
    assert(QFile::exists(src));
    assert(QFileInfo(src).isDir());
    KURL u;
    u.setPath(src);
    KURL d;
    d.setPath(dest);

    KIO::CopyJob *job = KIO::move(u, d, 0);
    job->setInteractive(false); // no skip dialog, thanks
    QMap< QString, QString > metaData;
    bool ok = KIO::NetAccess::synchronousRun(job, 0, 0, 0, &metaData);
    assert(!ok);
    assert(KIO::NetAccess::lastError() == KIO::ERR_ACCESS_DENIED);
    assert(QFile::exists(dest)); // see moveFileNoPermissions
    assert(QFile::exists(src));
}
KSUpgradeManager::KSUpgradeManager(QWidget *parent, const QString &caption)
  : KDialogBase(parent, "KSDownloadManager", true, caption, Ok|Cancel), m_completedDownloads(0)
{
  KIO::CopyJob *copy;

  //Setting up the basics...
  setButtonText(ButtonCode(Ok), i18n("Upgrade"));
  setButtonText(ButtonCode(Cancel), i18n("Close"));
  enableButtonOK(false);

  m_mainWidget = new KSUpgradeManagerWdt(this);
  setMainWidget(m_mainWidget);
  m_mainWidget->downloadList->addColumn(i18n("File"));

  //Download versioning files...
  m_mainWidget->currentLabel->setText(i18n("Version files"));
  copy = KIO::copy(KURL("http://kslovar.berlios.de/version"), KURL("/tmp/version"), false);
  connect(copy, SIGNAL(result(KIO::Job*)), this, SLOT(slotCheckVersion()));
  connect(copy, SIGNAL(percent(KIO::Job*, unsigned long)), this, SLOT(slotProgress(KIO::Job*, unsigned long)));
  copy->setInteractive(false);
}
void KSUpgradeManager::slotCheckDownload(KIO::Job*, const QString &download, const QString &url)
{
  switch(m_downloadState)
  {
    case(REMOVE_BACKUP):
    {
      KIO::DeleteJob *temp = KIO::del(KURL(download+"~"), false, false);
      m_localFile = download;
      m_remoteFile = url;
      connect(temp, SIGNAL(result(KIO::Job*)), this, SLOT(slotCheckDownload(KIO::Job*)));
      temp->setInteractive(false);
      m_downloadState = BACKUP;
      break;
    }
    case(BACKUP):
    {
      KIO::CopyJob *temp = KIO::move(KURL(m_localFile), KURL(m_localFile+"~"), false);
      connect(temp, SIGNAL(result(KIO::Job*)), this, SLOT(slotCheckDownload(KIO::Job*)));
      temp->setInteractive(false);
      m_downloadState = DOWNLOAD;
      break;
    }
    case(DOWNLOAD):
    {
      KIO::CopyJob *temp = KIO::copy(KURL(m_remoteFile), KURL(m_localFile), false);
      connect(temp, SIGNAL(result(KIO::Job*)), this, SLOT(slotCheckDownload(KIO::Job*)));
      connect(temp, SIGNAL(percent(KIO::Job*, unsigned long)), this, SLOT(slotProgress(KIO::Job*, unsigned long)));
      temp->setInteractive(false);
      m_downloadState = COMPLETE;
      break;
    }
    case(DELETE_VERSION):
    {
      KIO::DeleteJob *temp = KIO::del(KURL(locateLocal("appdata", "version")), false, false);
      connect(temp, SIGNAL(result(KIO::Job*)), this, SLOT(slotCheckDownload(KIO::Job*)));
      temp->setInteractive(false);
      m_downloadState = MOVE_VERSION;
      break;
    }
    case(MOVE_VERSION):
    {
      KIO::CopyJob *temp = KIO::move(KURL("/tmp/version"), KURL(locateLocal("appdata", "version")), false);
      connect(temp, SIGNAL(result(KIO::Job*)), this, SLOT(slotCheckDownload(KIO::Job*)));
      temp->setInteractive(false);
      m_downloadState = -1;
      break;
    }
    case(COMPLETE):
    {
      m_mainWidget->downloadProgress->setProgress(0);
      m_mainWidget->currentLabel->setText(i18n("nothing"));
      m_completedDownloads++;
      m_downloadState = DELETE_VERSION;
      slotCheckDownload(0);
      KSlovar::KSInstance()->loadLanguages();
      break;
    }
  }
}
예제 #20
0
    void parseArgs(KCmdLineArgs* args)
    {
        if (args->count() > 1) {
            // Createa a temp dir containing links to url args
            mMultipleUrlsDir.reset(new KTempDir);
            mUrl = KUrl::fromPath(mMultipleUrlsDir->name());
            KUrl::List list;
            for (int pos = 0; pos < args->count(); ++pos) {
                list << args->url(pos);
            }
            KIO::CopyJob* job = KIO::link(list, mUrl);
            job->exec();
        } else {
            mUrl = args->url(0);
        }

        if (mUrl.isValid() && (args->isSet("f") || args->isSet("s"))) {
            mFullScreen = true;
            if (args->isSet("s")) {
                mSlideShow = true;
            }
        }
    }
예제 #21
0
파일: main.cpp 프로젝트: emmanuel099/kio
void KIOExec::slotRunApp()
{
    if ( fileList.isEmpty() ) {
        qDebug() << "No files downloaded -> exiting";
        mExited = true;
        QApplication::exit(1);
        return;
    }

    KService service(QStringLiteral("dummy"), command, QString());

    QList<QUrl> list;
    // Store modification times
    QList<FileInfo>::Iterator it = fileList.begin();
    for ( ; it != fileList.end() ; ++it )
    {
        QFileInfo info(QFile::encodeName(it->path));
        it->time = info.lastModified();
        QUrl url = QUrl::fromLocalFile(it->path);
        list << url;
    }

    KIO::DesktopExecParser execParser(service, list);
    QStringList params = execParser.resultingArguments();

    qDebug() << "EXEC " << params.join(QStringLiteral(" "));

#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
    // propagate the startup identification to the started process
    KStartupInfoId id;
    QByteArray startupId;
#if HAVE_X11
    if (QX11Info::isPlatformX11()) {
        startupId = QX11Info::nextStartupId();
    }
#endif
    id.initId(startupId);
    id.setupStartupEnv();
#endif

    QString exe( params.takeFirst() );
    const int exit_code = QProcess::execute( exe, params );

#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
    KStartupInfo::resetStartupEnv();
#endif

    qDebug() << "EXEC done";

    // Test whether one of the files changed
    for(it = fileList.begin(); it != fileList.end(); ++it )
    {
        QString src = it->path;
        const QUrl dest = it->url;
        QFileInfo info(src);
        if ( info.exists() && (it->time != info.lastModified()) )
        {
            if ( mTempFiles )
            {
                if ( KMessageBox::questionYesNo( 0L,
                                                 i18n( "The supposedly temporary file\n%1\nhas been modified.\nDo you still want to delete it?", dest.toDisplayString(QUrl::PreferLocalFile)),
                                                 i18n( "File Changed" ), KStandardGuiItem::del(), KGuiItem(i18n("Do Not Delete")) ) != KMessageBox::Yes )
                    continue; // don't delete the temp file
            }
            else if ( ! dest.isLocalFile() )  // no upload when it's already a local file
            {
                if ( KMessageBox::questionYesNo( 0L,
                                                 i18n( "The file\n%1\nhas been modified.\nDo you want to upload the changes?" , dest.toDisplayString()),
                                                 i18n( "File Changed" ), KGuiItem(i18n("Upload")), KGuiItem(i18n("Do Not Upload")) ) == KMessageBox::Yes )
                {
                    qDebug() << "src='" << src << "'  dest='" << dest << "'";
                    // Do it the synchronous way.
                    KIO::CopyJob* job = KIO::copy(QUrl::fromLocalFile(src), dest);
                    if ( !job->exec() )
                    {
                        KMessageBox::error( 0L, job->errorText() );
                        continue; // don't delete the temp file
                    }
                }
            }
        }

        if ((!dest.isLocalFile() || mTempFiles) && exit_code == 0) {
            // Wait for a reasonable time so that even if the application forks on startup (like OOo or amarok)
            // it will have time to start up and read the file before it gets deleted. #130709.
            qDebug() << "sleeping...";
            QThread::currentThread()->sleep(180); // 3 mn
            qDebug() << "about to delete " << src;
            QFile( QFile::encodeName(src) ).remove();
        }
    }

    mExited = true;
    QApplication::exit(exit_code);
}