示例#1
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;
}
示例#2
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;
}
示例#3
0
文件: pastetest.cpp 项目: KDE/kio
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);
    }
}
示例#4
0
    void pasteFileToOtherPartition()
    {
        const QString filePath = homeTmpDir() + "fileFromHome";
        const QString dest = otherTmpDir() + "fileFromHome_copied";
        QFile::remove(dest);
        createTestFile( filePath );

        QMimeData* mimeData = new QMimeData;
        KUrl fileUrl(filePath);
        fileUrl.populateMimeData(mimeData);
        QApplication::clipboard()->setMimeData(mimeData);

        KIO::Job* job = KIO::pasteClipboard(otherTmpDir(), static_cast<QWidget*>(0));
        job->setUiDelegate(0);
        bool ok = KIO::NetAccess::synchronousRun(job, 0);
        QVERIFY( ok );

        QVERIFY( QFile::exists( dest ) );
        QVERIFY( QFile::exists( filePath ) ); // still there
    }
示例#5
0
void FileUndoManagerTest::testRenameDir()
{
    const KUrl oldUrl( srcSubDir() );
    const KUrl newUrl( srcSubDir() + ".new" );
    KUrl::List lst;
    lst.append(oldUrl);
    KIO::Job* job = KIO::moveAs( oldUrl, newUrl, KIO::HideProgressInfo );
    job->setUiDelegate( 0 );
    FileUndoManager::self()->recordJob( FileUndoManager::Rename, lst, newUrl, job );

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

    QVERIFY( !QFile::exists( srcSubDir() ) );
    QVERIFY( QFileInfo( newUrl.toLocalFile() ).isDir() );

    doUndo();

    QVERIFY( QFile::exists( srcSubDir() ) );
    QVERIFY( !QFileInfo( newUrl.toLocalFile() ).isDir() );
}
示例#6
0
void FileUndoManagerTest::testTrashFiles()
{
    if ( !KProtocolInfo::isKnownProtocol( "trash" ) )
        QSKIP( "kio_trash not installed", SkipAll );

    // Trash it all at once: the file, the symlink, the subdir.
    KUrl::List lst = sourceList();
    lst.append( srcSubDir() );
    KIO::Job* job = KIO::trash( lst, KIO::HideProgressInfo );
    job->setUiDelegate( 0 );
    FileUndoManager::self()->recordJob( FileUndoManager::Trash, lst, KUrl("trash:/"), job );

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

    // Check that things got removed
    QVERIFY( !QFile::exists( srcFile() ) );
#ifndef Q_WS_WIN
    QVERIFY( !QFileInfo( srcLink() ).isSymLink() );
#endif
    QVERIFY( !QFile::exists( srcSubDir() ) );

    // check trash?
    // Let's just check that it's not empty. kio_trash has its own unit tests anyway.
    KConfig cfg( "trashrc", KConfig::SimpleConfig );
    QVERIFY( cfg.hasGroup( "Status" ) );
    QCOMPARE( cfg.group("Status").readEntry( "Empty", true ), false );

    doUndo();

    QVERIFY( QFile::exists( srcFile() ) );
#ifndef Q_WS_WIN
    QVERIFY( QFileInfo( srcLink() ).isSymLink() );
#endif
    QVERIFY( QFile::exists( srcSubDir() ) );

    // We can't check that the trash is empty; other partitions might have their own trash
}
示例#7
0
void FileUndoManagerTest::testRenameFile()
{
    const KUrl oldUrl( srcFile() );
    const KUrl newUrl( srcFile() + ".new" );
    KUrl::List lst;
    lst.append(oldUrl);
    QSignalSpy spyUndoAvailable( FileUndoManager::self(), SIGNAL(undoAvailable(bool)) );
    QVERIFY( spyUndoAvailable.isValid() );
    KIO::Job* job = KIO::moveAs( oldUrl, newUrl, KIO::HideProgressInfo );
    job->setUiDelegate( 0 );
    FileUndoManager::self()->recordJob( FileUndoManager::Rename, lst, newUrl, job );

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

    QVERIFY( !QFile::exists( srcFile() ) );
    QVERIFY( QFileInfo( newUrl.toLocalFile() ).isFile() );
    QCOMPARE(spyUndoAvailable.count(), 1);

    doUndo();

    QVERIFY( QFile::exists( srcFile() ) );
    QVERIFY( !QFileInfo( newUrl.toLocalFile() ).isFile() );
}
示例#8
0
static bool myMkdir(const QString& pathOrUrl) {
    KUrl url(pathOrUrl);
    KIO::Job* job = KIO::mkdir(url, -1);
    job->setUiDelegate(0);
    return KIO::NetAccess::synchronousRun(job, 0);
}
示例#9
0
static bool myExists(const QString& pathOrUrl) {
    KUrl url(pathOrUrl);
    KIO::Job* job = KIO::stat(url, KIO::StatJob::DestinationSide, 0, KIO::HideProgressInfo);
    job->setUiDelegate(0);
    return KIO::NetAccess::synchronousRun(job, 0);
}
示例#10
0
static void delDir(const QString& pathOrUrl) {
    KIO::Job* job = KIO::del(KUrl(pathOrUrl), KIO::HideProgressInfo);
    job->setUiDelegate(0);
    KIO::NetAccess::synchronousRun(job, 0);
}