本文整理汇总了C++中kio::CopyJob类的典型用法代码示例。如果您正苦于以下问题:C++ CopyJob类的具体用法?C++ CopyJob怎么用?C++ CopyJob使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CopyJob类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testModifyFileBeforeUndo
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: testMoveFiles
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: moveFileNoPermissions
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: KonqOperations
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: launchQuery
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: installPackage
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: onSaveLog
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: copyFromTmpToDest
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: executeStrategy
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: testCopyFiles
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:
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: slotCopyDone
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: download
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: executeStrategy
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: slotFinish
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);
}