[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdelibs/frameworks] /: Ported FileUndoManager to QUrl
From:       David Faure <faure () kde ! org>
Date:       2012-04-30 23:32:18
Message-ID: 20120430233218.9AC94A60A9 () git ! kde ! org
[Download RAW message or body]

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<KUrl> lstSrc;
+        QList<QUrl> lstSrc;
         lstSrc.append(uSrc);
         KIO::Job* kjob;
         if (m_copyData.m_isSymlink) {
@@ -774,7 +774,7 @@ void KNewFileMenuPrivate::_k_slotCreateDirectory(bool \
                writeHiddenDir)
       job->setProperty("isMkdirJob", true); // KDE5: cast to MkdirJob in slotResult \
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<QUrl>(), url, job );  
       if (job) {
         // We want the error handling to be done by slotResult so that subclasses \
                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 <klocale.h>
 #include <kmessagebox.h>
 #include <kjobtrackerinterface.h>
+#include <qurlpathinfo.h>
 
 #include <QtDBus/QtDBus>
 
@@ -99,6 +100,14 @@ static QDataStream &operator>>(QDataStream &stream, UndoCommand \
                &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 operation", \
                "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 operation", "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 KUrl::List \
&src, const KUrl &dst, KIO::Job *job) \
+CommandRecorder::CommandRecorder(FileUndoManager::CommandType op, const QList<QUrl> \
&src, const QUrl &dst, KIO::Job *job)  : QObject(job)
 {
   m_cmd.m_type = op;
@@ -244,7 +253,7 @@ FileUndoManager::~FileUndoManager()
     delete d;
 }
 
-void FileUndoManager::recordJob(CommandType op, const KUrl::List &src, const KUrl \
&dst, KIO::Job *job) +void FileUndoManager::recordJob(CommandType op, const \
QList<QUrl> &src, const 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 = m_dirStack.pop();
+        QUrl dir = m_dirStack.pop();
         kDebug(1203) << "creatingDir" << dir;
         m_currentJob = 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 the 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 = 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 = m_fileCleanupStack.pop();
+        QUrl file = m_fileCleanupStack.pop();
         kDebug(1203) << "file_delete" << file;
         m_currentJob = 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 = m_dirCleanupStack.pop();
+        QUrl dir = m_dirCleanupStack.pop();
         kDebug(1203) << "rmdir" << dir;
         m_currentJob = KIO::rmdir(dir);
         m_undoJob->emitDeleting(dir);
@@ -599,10 +608,10 @@ void FileUndoManagerPrivate::stepRemovingDirectories()
             m_undoJob->emitResult();
             m_undoJob = 0;
         }
-        QList<KUrl>::ConstIterator it = m_dirsToUpdate.constBegin();
+        QList<QUrl>::ConstIterator it = m_dirsToUpdate.constBegin();
         for(; it != 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* job)
     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& dest, const \
KDateTime& srcTime, const KDateTime& destTime); +        virtual bool \
copiedFileWasModified(const QUrl& src, const QUrl& dest, 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<QUrl> &src, const QUrl &dst, \
KIO::Job *job);  
     /**
      * Record this CopyJob while it's happening and add a command for it so 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<QUrl> 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<QUrl> &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<KUrl> m_dirStack;
-    QStack<KUrl> m_dirCleanupStack;
-    QStack<KUrl> m_fileCleanupStack; // files and links
-    QList<KUrl> m_dirsToUpdate;
+    QStack<QUrl> m_dirStack;
+    QStack<QUrl> m_dirCleanupStack;
+    QStack<QUrl> m_fileCleanupStack; // files and links
+    QList<QUrl> 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, const \
                QVariant & value, int
             KIO::Job * job = KIO::moveAs(item.url(), newurl, newurl.isLocalFile() ? \
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<QUrl>() << item.url(), newurl, job );  return \
true;  }
         break;
diff --git a/kio/tests/fileundomanagertest.cpp b/kio/tests/fileundomanagertest.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 = dest;
         Q_UNUSED( srcTime );
@@ -146,14 +146,14 @@ public:
         m_nextReplyToConfirmDeletion = b;
     }
     QList<QUrl> files() const { return m_files; }
-    KUrl dest() const { return m_dest; }
+    QUrl dest() const { return m_dest; }
     void clear() {
         m_dest = QUrl();
         m_files.clear();
     }
 private:
     bool m_nextReplyToConfirmDeletion;
-    KUrl m_dest;
+    QUrl m_dest;
     QList<QUrl> m_files;
 };
 
@@ -190,7 +190,7 @@ void FileUndoManagerTest::initTestCase()
 
 void FileUndoManagerTest::cleanupTestCase()
 {
-    KIO::Job* job = KIO::del( KUrl::fromPath( homeTmpDir() ), KIO::HideProgressInfo \
); +    KIO::Job* job = KIO::del(QUrl::fromLocalFile( homeTmpDir() ), \
KIO::HideProgressInfo);  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<KUrl> lst;
+    const QUrl oldUrl = QUrl::fromLocalFile( srcFile() );
+    const QUrl newUrl = QUrl::fromLocalFile( srcFile() + ".new" );
+    QList<QUrl> lst;
     lst.append(oldUrl);
     QSignalSpy spyUndoAvailable( FileUndoManager::self(), \
SIGNAL(undoAvailable(bool)) );  QVERIFY( spyUndoAvailable.isValid() );
@@ -375,9 +375,9 @@ void FileUndoManagerTest::testRenameFile()
 
 void FileUndoManagerTest::testRenameDir()
 {
-    const KUrl oldUrl( srcSubDir() );
-    const KUrl newUrl( srcSubDir() + ".new" );
-    QList<KUrl> lst;
+    const QUrl oldUrl = QUrl::fromLocalFile( srcSubDir() );
+    const QUrl newUrl = QUrl::fromLocalFile( srcSubDir() + ".new" );
+    QList<QUrl> lst;
     lst.append(oldUrl);
     KIO::Job* job = KIO::moveAs( oldUrl, newUrl, KIO::HideProgressInfo );
     job->setUiDelegate( 0 );


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic