From kde-commits Mon Apr 30 23:32:18 2012 From: David Faure Date: Mon, 30 Apr 2012 23:32:18 +0000 To: kde-commits Subject: [kdelibs/frameworks] /: Ported FileUndoManager to QUrl Message-Id: <20120430233218.9AC94A60A9 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=133582887311391 Git commit 26d380c38104de62fe148e40340b1e41f626364d by David Faure. Committed on 01/05/2012 at 01:32. Pushed by dfaure into branch 'frameworks'. Ported FileUndoManager to QUrl M +2 -2 kfile/knewfilemenu.cpp M +30 -21 kio/kio/fileundomanager.cpp M +2 -2 kio/kio/fileundomanager.h M +10 -10 kio/kio/fileundomanager_p.h M +1 -1 kio/kio/kdirmodel.cpp M +10 -10 kio/tests/fileundomanagertest.cpp http://commits.kde.org/kdelibs/26d380c38104de62fe148e40340b1e41f626364d diff --git a/kfile/knewfilemenu.cpp b/kfile/knewfilemenu.cpp index 02dfe1d..e49950a 100644 --- a/kfile/knewfilemenu.cpp +++ b/kfile/knewfilemenu.cpp @@ -542,7 +542,7 @@ void KNewFileMenuPrivate::executeStrategy() KUrl dest(*it); dest.addPath(KIO::encodeFileName(chosenFileName)); = - QList lstSrc; + QList lstSrc; lstSrc.append(uSrc); KIO::Job* kjob; if (m_copyData.m_isSymlink) { @@ -774,7 +774,7 @@ void KNewFileMenuPrivate::_k_slotCreateDirectory(bool w= riteHiddenDir) job->setProperty("isMkdirJob", true); // KDE5: cast to MkdirJob in s= lotResult instead job->ui()->setWindow(m_parentWidget); job->ui()->setAutoErrorHandlingEnabled(true); - KIO::FileUndoManager::self()->recordJob( KIO::FileUndoManager::Mkdir= , KUrl(), url, job ); + KIO::FileUndoManager::self()->recordJob( KIO::FileUndoManager::Mkdir= , QList(), url, job ); = if (job) { // We want the error handling to be done by slotResult so that sub= classes can reimplement it diff --git a/kio/kio/fileundomanager.cpp b/kio/kio/fileundomanager.cpp index 5a84c62..258af65 100644 --- a/kio/kio/fileundomanager.cpp +++ b/kio/kio/fileundomanager.cpp @@ -33,6 +33,7 @@ #include #include #include +#include = #include = @@ -99,6 +100,14 @@ static QDataStream &operator>>(QDataStream &stream, Und= oCommand &cmd) * */ = +// Porting helpers. Qt 5: remove +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +#define pathOrUrl() toString() +#define toDisplayString toString +#else +#define pathOrUrl() toDisplayString(QUrl::PreferLocalFile) +#endif + class KIO::UndoJob : public KIO::Job { public: @@ -113,20 +122,20 @@ public: KIO::Job::doKill(); } = - void emitCreatingDir(const KUrl &dir) + void emitCreatingDir(const QUrl &dir) { emit description(this, i18n("Creating directory"), - qMakePair(i18n("Directory"), dir.prettyUrl())); } - void emitMoving(const KUrl &src, const KUrl &dest) + qMakePair(i18n("Directory"), dir.toDisplayString())= ); } + void emitMoving(const QUrl &src, const QUrl &dest) { emit description(this, i18n("Moving"), - qMakePair(i18nc("The source of a file operation", "= Source"), src.prettyUrl()), - qMakePair(i18nc("The destination of a file operatio= n", "Destination"), dest.prettyUrl())); } - void emitDeleting(const KUrl &url) + qMakePair(i18nc("The source of a file operation", "= Source"), src.toDisplayString()), + qMakePair(i18nc("The destination of a file operatio= n", "Destination"), dest.toDisplayString())); } + void emitDeleting(const QUrl &url) { emit description(this, i18n("Deleting"), - qMakePair(i18n("File"), url.prettyUrl())); } + qMakePair(i18n("File"), url.toDisplayString())); } void emitResult() { KIO::Job::emitResult(); } }; = -CommandRecorder::CommandRecorder(FileUndoManager::CommandType op, const KU= rl::List &src, const KUrl &dst, KIO::Job *job) +CommandRecorder::CommandRecorder(FileUndoManager::CommandType op, const QL= ist &src, const QUrl &dst, KIO::Job *job) : QObject(job) { m_cmd.m_type =3D op; @@ -244,7 +253,7 @@ FileUndoManager::~FileUndoManager() delete d; } = -void FileUndoManager::recordJob(CommandType op, const KUrl::List &src, con= st KUrl &dst, KIO::Job *job) +void FileUndoManager::recordJob(CommandType op, const QList &src, co= nst QUrl &dst, KIO::Job *job) { // This records what the job does and calls addCommand when done (void) new CommandRecorder(op, src, dst, job); @@ -447,7 +456,7 @@ void FileUndoManagerPrivate::slotResult(KJob *job) } = = -void FileUndoManagerPrivate::addDirToUpdate(const KUrl& url) +void FileUndoManagerPrivate::addDirToUpdate(const QUrl& url) { if (!m_dirsToUpdate.contains(url)) m_dirsToUpdate.prepend(url); @@ -480,7 +489,7 @@ void FileUndoManagerPrivate::undoStep() void FileUndoManagerPrivate::stepMakingDirectories() { if (!m_dirStack.isEmpty()) { - KUrl dir =3D m_dirStack.pop(); + QUrl dir =3D m_dirStack.pop(); kDebug(1203) << "creatingDir" << dir; m_currentJob =3D KIO::mkdir(dir); m_undoJob->emitCreatingDir(dir); @@ -544,12 +553,12 @@ void FileUndoManagerPrivate::stepMovingFiles() m_current.m_opStack.removeLast(); // The above KIO jobs are lowlevel, they don't trigger KDirNotify = notification // So we need to do it ourselves (but schedule it to the end of th= e undo, to compress them) - KUrl url(op.m_dst); - url.setPath(url.directory()); + QUrl url(op.m_dst); + url.setPath(QUrlPathInfo(url).directory()); addDirToUpdate(url); = url =3D op.m_src; - url.setPath(url.directory()); + url.setPath(QUrlPathInfo(url).directory()); addDirToUpdate(url); } else @@ -561,13 +570,13 @@ void FileUndoManagerPrivate::stepRemovingLinks() kDebug(1203) << "REMOVINGLINKS"; if (!m_fileCleanupStack.isEmpty()) { - KUrl file =3D m_fileCleanupStack.pop(); + QUrl file =3D m_fileCleanupStack.pop(); kDebug(1203) << "file_delete" << file; m_currentJob =3D KIO::file_delete(file, KIO::HideProgressInfo); m_undoJob->emitDeleting(file); = - KUrl url(file); - url.setPath(url.directory()); + QUrl url(file); + url.setPath(QUrlPathInfo(url).directory()); addDirToUpdate(url); } else @@ -583,7 +592,7 @@ void FileUndoManagerPrivate::stepRemovingDirectories() { if (!m_dirCleanupStack.isEmpty()) { - KUrl dir =3D m_dirCleanupStack.pop(); + QUrl dir =3D m_dirCleanupStack.pop(); kDebug(1203) << "rmdir" << dir; m_currentJob =3D KIO::rmdir(dir); m_undoJob->emitDeleting(dir); @@ -599,10 +608,10 @@ void FileUndoManagerPrivate::stepRemovingDirectories() m_undoJob->emitResult(); m_undoJob =3D 0; } - QList::ConstIterator it =3D m_dirsToUpdate.constBegin(); + QList::ConstIterator it =3D m_dirsToUpdate.constBegin(); for(; it !=3D m_dirsToUpdate.constEnd(); ++it) { kDebug() << "Notifying FilesAdded for " << *it; - org::kde::KDirNotify::emitFilesAdded((*it).url()); + org::kde::KDirNotify::emitFilesAdded((*it).toString()); } emit q->undoJobFinished(); broadcastUnlock(); @@ -762,7 +771,7 @@ void FileUndoManager::UiInterface::jobError(KIO::Job* j= ob) job->ui()->showErrorMessage(); } = -bool FileUndoManager::UiInterface::copiedFileWasModified(const KUrl& src, = const KUrl& dest, const KDateTime& srcTime, const KDateTime& destTime) +bool FileUndoManager::UiInterface::copiedFileWasModified(const QUrl& src, = const QUrl& dest, const KDateTime& srcTime, const KDateTime& destTime) { Q_UNUSED(srcTime); // not sure it should appear in the msgbox // Possible improvement: only show the time if date is today diff --git a/kio/kio/fileundomanager.h b/kio/kio/fileundomanager.h index 9fc6c5e..a8f2969 100644 --- a/kio/kio/fileundomanager.h +++ b/kio/kio/fileundomanager.h @@ -101,7 +101,7 @@ public: * Note that this is called after confirmDeletion. * Return true if we should proceed with deleting dest. */ - virtual bool copiedFileWasModified(const KUrl& src, const KUrl& de= st, const KDateTime& srcTime, const KDateTime& destTime); + virtual bool copiedFileWasModified(const QUrl& src, const QUrl& de= st, const KDateTime& srcTime, const KDateTime& destTime); = /** * \internal, for future extensions @@ -142,7 +142,7 @@ public: * @param dst destination url * @param job the job to record */ - void recordJob(CommandType op, const KUrl::List &src, const KUrl &dst,= KIO::Job *job); + void recordJob(CommandType op, const QList &src, const QUrl &dst= , KIO::Job *job); = /** * Record this CopyJob while it's happening and add a command for it s= o that the user can undo it. diff --git a/kio/kio/fileundomanager_p.h b/kio/kio/fileundomanager_p.h index f443fa1..eb63419 100644 --- a/kio/kio/fileundomanager_p.h +++ b/kio/kio/fileundomanager_p.h @@ -46,8 +46,8 @@ struct BasicOperation enum Type { File, Link, Directory }; Type m_type:2; = - KUrl m_src; - KUrl m_dst; + QUrl m_src; + QUrl m_dst; QString m_target; time_t m_mtime; }; @@ -69,8 +69,8 @@ public: = FileUndoManager::CommandType m_type; BasicOperation::Stack m_opStack; - KUrl::List m_src; - KUrl m_dst; + QList m_src; + QUrl m_dst; quint64 m_serialNumber; }; = @@ -81,7 +81,7 @@ class CommandRecorder : public QObject { Q_OBJECT public: - CommandRecorder( FileUndoManager::CommandType op, const KUrl::List &src,= const KUrl &dst, KIO::Job *job ); + CommandRecorder( FileUndoManager::CommandType op, const QList &src= , const QUrl &dst, KIO::Job *job ); virtual ~CommandRecorder(); = private Q_SLOTS: @@ -116,7 +116,7 @@ public: void broadcastLock(); void broadcastUnlock(); = - void addDirToUpdate( const KUrl& url ); + void addDirToUpdate(const QUrl& url); bool initializeFromKDesky(); = void undoStep(); @@ -145,10 +145,10 @@ public: UndoCommand m_current; KIO::Job *m_currentJob; UndoState m_undoState; - QStack m_dirStack; - QStack m_dirCleanupStack; - QStack m_fileCleanupStack; // files and links - QList m_dirsToUpdate; + QStack m_dirStack; + QStack m_dirCleanupStack; + QStack m_fileCleanupStack; // files and links + QList m_dirsToUpdate; FileUndoManager::UiInterface* m_uiInterface; = UndoJob *m_undoJob; diff --git a/kio/kio/kdirmodel.cpp b/kio/kio/kdirmodel.cpp index e7b6b43..7e451f9 100644 --- a/kio/kio/kdirmodel.cpp +++ b/kio/kio/kdirmodel.cpp @@ -790,7 +790,7 @@ bool KDirModel::setData( const QModelIndex & index, con= st QVariant & value, int KIO::Job * job =3D KIO::moveAs(item.url(), newurl, newurl.isLo= calFile() ? KIO::HideProgressInfo : KIO::DefaultFlags); job->ui()->setAutoErrorHandlingEnabled(true); // undo handling - KIO::FileUndoManager::self()->recordJob( KIO::FileUndoManager:= :Rename, item.url(), newurl, job ); + KIO::FileUndoManager::self()->recordJob( KIO::FileUndoManager:= :Rename, QList() << item.url(), newurl, job ); return true; } break; diff --git a/kio/tests/fileundomanagertest.cpp b/kio/tests/fileundomanagert= est.cpp index e7cf92e..28e26e1 100644 --- a/kio/tests/fileundomanagertest.cpp +++ b/kio/tests/fileundomanagertest.cpp @@ -131,7 +131,7 @@ public: virtual void jobError( KIO::Job* job ) { kFatal() << job->errorString() ; } - virtual bool copiedFileWasModified( const KUrl& src, const KUrl& dest,= const KDateTime& srcTime, const KDateTime& destTime ) { + virtual bool copiedFileWasModified( const QUrl& src, const QUrl& dest,= const KDateTime& srcTime, const KDateTime& destTime ) { Q_UNUSED( src ); m_dest =3D dest; Q_UNUSED( srcTime ); @@ -146,14 +146,14 @@ public: m_nextReplyToConfirmDeletion =3D b; } QList files() const { return m_files; } - KUrl dest() const { return m_dest; } + QUrl dest() const { return m_dest; } void clear() { m_dest =3D QUrl(); m_files.clear(); } private: bool m_nextReplyToConfirmDeletion; - KUrl m_dest; + QUrl m_dest; QList m_files; }; = @@ -190,7 +190,7 @@ void FileUndoManagerTest::initTestCase() = void FileUndoManagerTest::cleanupTestCase() { - KIO::Job* job =3D KIO::del( KUrl::fromPath( homeTmpDir() ), KIO::HideP= rogressInfo ); + KIO::Job* job =3D KIO::del(QUrl::fromLocalFile( homeTmpDir() ), KIO::H= ideProgressInfo); KIO::NetAccess::synchronousRun( job, 0 ); } = @@ -350,9 +350,9 @@ void FileUndoManagerTest::testMoveDirectory() = void FileUndoManagerTest::testRenameFile() { - const KUrl oldUrl( srcFile() ); - const KUrl newUrl( srcFile() + ".new" ); - QList lst; + const QUrl oldUrl =3D QUrl::fromLocalFile( srcFile() ); + const QUrl newUrl =3D QUrl::fromLocalFile( srcFile() + ".new" ); + QList lst; lst.append(oldUrl); QSignalSpy spyUndoAvailable( FileUndoManager::self(), SIGNAL(undoAvail= able(bool)) ); QVERIFY( spyUndoAvailable.isValid() ); @@ -375,9 +375,9 @@ void FileUndoManagerTest::testRenameFile() = void FileUndoManagerTest::testRenameDir() { - const KUrl oldUrl( srcSubDir() ); - const KUrl newUrl( srcSubDir() + ".new" ); - QList lst; + const QUrl oldUrl =3D QUrl::fromLocalFile( srcSubDir() ); + const QUrl newUrl =3D QUrl::fromLocalFile( srcSubDir() + ".new" ); + QList lst; lst.append(oldUrl); KIO::Job* job =3D KIO::moveAs( oldUrl, newUrl, KIO::HideProgressInfo ); job->setUiDelegate( 0 );