]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/undomanager.cpp
Use a KIO Job for applying the view properties recursively to sub directories.
[dolphin.git] / src / undomanager.cpp
index 4173b3c5e90b0af21d75ff2f73d3911faf550cf7..e6946cfe31af4209493d04730e6a190b39f95452 100644 (file)
@@ -24,7 +24,7 @@
 #include <qtimer.h>
 #include <assert.h>
 
-#include "dolphin.h"
+#include "dolphinmainwindow.h"
 #include "dolphinstatusbar.h"
 #include "progressindicator.h"
 
@@ -37,6 +37,8 @@ DolphinCommand::DolphinCommand() :
     // Instead of expressing this implementation detail to the interface by adding a
     // Type::Undefined just Type::Copy is used to assure that all members have
     // a defined state.
+    //
+    // KDE4TODO: QList doesn't require a default constructor iirc - so remove this
 }
 
 DolphinCommand::DolphinCommand(Type type,
@@ -84,7 +86,7 @@ void UndoManager::addCommand(const DolphinCommand& command)
     }
 
     emit undoAvailable(true);
-    emit undoTextChanged(i18n("Undo: %1").arg(commandText(command)));
+    emit undoTextChanged(i18n("Undo: %1",commandText(command)));
 
     // prevent an endless growing of the Undo history
     if (m_historyIndex > 10000) {
@@ -106,7 +108,9 @@ void UndoManager::endMacro()
     m_recordMacro = false;
 }
 
-void UndoManager::undo()
+// KDE4 TODO: consider switching to KCommandHistory (kdeui) for the command history, and to
+// KonqCommandRecorder etc. from libkonq/konq_undo.*
+void UndoManager::undo(DolphinMainWindow* mainWindow)
 {
     if (m_recordMacro) {
         endMacro();
@@ -120,34 +124,38 @@ void UndoManager::undo()
     int macroCount = 1;
     calcStepsCount(macroCount, progressCount);
 
-    m_progressIndicator = new ProgressIndicator(i18n("Executing undo operation..."),
-                                                i18n("Executed undo operation."),
-                                                progressCount);
+    /*
+     * KDE4, ### TODO Only here to avoid possible crash 
+     */
+    ProgressIndicator progressIndicator(mainWindow, i18n("Executing undo operation..."),
+                                        i18n("Executed undo operation."),
+                                        progressCount);
 
     for (int i = 0; i < macroCount; ++i) {
         const DolphinCommand command = m_history[m_historyIndex];
+
         --m_historyIndex;
         if (m_historyIndex < 0) {
             emit undoAvailable(false);
             emit undoTextChanged(i18n("Undo"));
         }
         else {
-            emit undoTextChanged(i18n("Undo: %1").arg(commandText(m_history[m_historyIndex])));
+            emit undoTextChanged(i18n("Undo: %1",commandText(m_history[m_historyIndex])));
         }
 
         if (m_historyIndex < static_cast<int>(m_history.count()) - 1) {
             emit redoAvailable(true);
-            emit redoTextChanged(i18n("Redo: %1").arg(commandText(command)));
+            emit redoTextChanged(i18n("Redo: %1",commandText(command)));
         }
         else {
             emit redoAvailable(false);
             emit redoTextChanged(i18n("Redo"));
         }
 
-        KUrl::List sourceURLs = command.source();
-        KUrl::List::Iterator it = sourceURLs.begin();
-        const KUrl::List::Iterator end = sourceURLs.end();
-        const QString destURL(command.destination().prettyURL(+1));
+        KUrl::List sourceUrls = command.source();
+        KUrl::List::Iterator it = sourceUrls.begin();
+        const KUrl::List::Iterator end = sourceUrls.end();
+        const QString destUrl(command.destination().prettyUrl(KUrl::AddTrailingSlash));
 
         KIO::Job* job = 0;
         switch (command.type()) {
@@ -155,8 +163,8 @@ void UndoManager::undo()
             case DolphinCommand::Copy: {
                 KUrl::List list;
                 while (it != end) {
-                    const KUrl deleteURL(destURL + (*it).filename());
-                    list.append(deleteURL);
+                    const KUrl deleteUrl(destUrl + (*it).fileName());
+                    list.append(deleteUrl);
                     ++it;
                 }
                 job = KIO::del(list, false, false);
@@ -165,18 +173,18 @@ void UndoManager::undo()
 
             case DolphinCommand::Move: {
                 KUrl::List list;
-                const KUrl newDestURL((*it).directory());
+                const KUrl newDestUrl((*it).directory());
                 while (it != end) {
-                    const KUrl newSourceURL(destURL + (*it).filename());
-                    list.append(newSourceURL);
+                    const KUrl newSourceUrl(destUrl + (*it).fileName());
+                    list.append(newSourceUrl);
                     ++it;
                 }
-                job = KIO::move(list, newDestURL, false);
+                job = KIO::move(list, newDestUrl, false);
                 break;
             }
 
             case DolphinCommand::Rename: {
-                assert(sourceURLs.count() == 1);
+                assert(sourceUrls.count() == 1);
                 KIO::NetAccess::move(command.destination(), (*it));
                 break;
             }
@@ -185,19 +193,19 @@ void UndoManager::undo()
                 while (it != end) {
                     // TODO: use KIO::special for accessing the trash protocol. See
                     // also Dolphin::slotJobResult() for further details.
-                    const QString originalFileName((*it).filename().section('-', 1));
-                    KUrl newDestURL(destURL + originalFileName);
-                    KIO::NetAccess::move(*it, newDestURL);
+                    const QString originalFileName((*it).fileName().section('-', 1));
+                    KUrl newDestUrl(destUrl + originalFileName);
+                    KIO::NetAccess::move(*it, newDestUrl);
                     ++it;
 
-                    m_progressIndicator->execOperation();
+                    progressIndicator.execOperation();
                 }
                 break;
             }
 
             case DolphinCommand::CreateFolder:
             case DolphinCommand::CreateFile: {
-                KIO::NetAccess::del(command.destination(), &Dolphin::mainWin());
+                KIO::NetAccess::del(command.destination(), mainWindow);
                 break;
             }
         }
@@ -207,17 +215,14 @@ void UndoManager::undo()
             // information to the Dolphin statusbar.
             connect(job, SIGNAL(percent(KIO::Job*, unsigned long)),
                     this, SLOT(slotPercent(KIO::Job*, unsigned long)));
-            KIO::NetAccess::synchronousRun(job, &Dolphin::mainWin());
+            KIO::NetAccess::synchronousRun(job, mainWindow);
         }
 
-        m_progressIndicator->execOperation();
+        progressIndicator.execOperation();
     }
-
-    delete m_progressIndicator;
-    m_progressIndicator = 0;
 }
 
-void UndoManager::redo()
+void UndoManager::redo(DolphinMainWindow *mainWindow)
 {
     if (m_recordMacro) {
         endMacro();
@@ -233,9 +238,9 @@ void UndoManager::redo()
     int macroCount = 1;
     calcStepsCount(macroCount, progressCount);
 
-    m_progressIndicator = new ProgressIndicator(i18n("Executing redo operation..."),
-                                                i18n("Executed redo operation."),
-                                                progressCount);
+    ProgressIndicator progressIndicator(mainWindow, i18n("Executing redo operation..."),
+                                        i18n("Executed redo operation."),
+                                        progressCount);
 
     for (int i = 0; i < macroCount; ++i) {
         const DolphinCommand command = m_history[m_historyIndex];
@@ -244,61 +249,59 @@ void UndoManager::redo()
             emit redoTextChanged(i18n("Redo"));
         }
         else {
-            emit redoTextChanged(i18n("Redo: %1").arg(commandText(m_history[m_historyIndex + 1])));
+            emit redoTextChanged(i18n("Redo: %1",commandText(m_history[m_historyIndex + 1])));
         }
 
         emit undoAvailable(true);
-        emit undoTextChanged(i18n("Undo: %1").arg(commandText(command)));
-
-        Dolphin& dolphin = Dolphin::mainWin();
+        emit undoTextChanged(i18n("Undo: %1",commandText(command)));
 
-        KUrl::List sourceURLs = command.source();
-        KUrl::List::Iterator it = sourceURLs.begin();
-        const KUrl::List::Iterator end = sourceURLs.end();
+        KUrl::List sourceUrls = command.source();
+        KUrl::List::Iterator it = sourceUrls.begin();
+        const KUrl::List::Iterator end = sourceUrls.end();
 
         KIO::Job* job = 0;
         switch (command.type()) {
             case DolphinCommand::Link: {
-                job = KIO::link(sourceURLs, command.destination(), false);
+                job = KIO::link(sourceUrls, command.destination(), false);
                 break;
             }
 
             case DolphinCommand::Copy: {
-                job = KIO::copy(sourceURLs, command.destination(), false);
+                job = KIO::copy(sourceUrls, command.destination(), false);
                 break;
             }
 
             case DolphinCommand::Rename:
             case DolphinCommand::Move: {
-                job = KIO::move(sourceURLs, command.destination(), false);
+                job = KIO::move(sourceUrls, command.destination(), false);
                 break;
             }
 
             case DolphinCommand::Trash: {
-                const QString destURL(command.destination().prettyURL());
+                const QString destUrl(command.destination().prettyUrl());
                 while (it != end) {
                    // TODO: use KIO::special for accessing the trash protocol. See
                     // also Dolphin::slotJobResult() for further details.
-                    const QString originalFileName((*it).filename().section('-', 1));
-                    KUrl originalSourceURL(destURL + "/" + originalFileName);
-                    KIO::Job* moveToTrashJob = KIO::trash(originalSourceURL);
-                    KIO::NetAccess::synchronousRun(moveToTrashJob, &dolphin);
+                    const QString originalFileName((*it).fileName().section('-', 1));
+                    KUrl originalSourceUrl(destUrl + "/" + originalFileName);
+                    KIO::Job* moveToTrashJob = KIO::trash(originalSourceUrl);
+                    KIO::NetAccess::synchronousRun(moveToTrashJob, mainWindow);
                     ++it;
 
-                    m_progressIndicator->execOperation();
+                    progressIndicator.execOperation();
                  }
                 break;
             }
 
             case DolphinCommand::CreateFolder: {
-                KIO::NetAccess::mkdir(command.destination(), &dolphin);
+                KIO::NetAccess::mkdir(command.destination(), mainWindow);
                 break;
             }
 
             case DolphinCommand::CreateFile: {
-                m_progressIndicator->execOperation();
-                KUrl::List::Iterator it = sourceURLs.begin();
-                assert(sourceURLs.count() == 1);
+                progressIndicator.execOperation();
+                KUrl::List::Iterator it = sourceUrls.begin();
+                assert(sourceUrls.count() == 1);
                 KIO::CopyJob* copyJob = KIO::copyAs(*it, command.destination(), false);
                 copyJob->setDefaultPermissions(true);
                 job = copyJob;
@@ -309,33 +312,28 @@ void UndoManager::redo()
         if (job != 0) {
             // Execute the jobs in a synchronous manner and forward the progress
             // information to the Dolphin statusbar.
-            connect(job, SIGNAL(percent(KIO::Job*, unsigned long)),
-                    this, SLOT(slotPercent(KIO::Job*, unsigned long)));
-            KIO::NetAccess::synchronousRun(job, &dolphin);
+            connect(job, SIGNAL(percent(KJob*, unsigned long)),
+                    this, SLOT(slotPercent(KJob*, unsigned long)));
+            KIO::NetAccess::synchronousRun(job, mainWindow);
         }
 
         ++m_historyIndex;
-        m_progressIndicator->execOperation();
+        progressIndicator.execOperation();
     }
 
     --m_historyIndex;
 
-    delete m_progressIndicator;
-    m_progressIndicator = 0;
 }
 
 UndoManager::UndoManager() :
     m_recordMacro(false),
     m_historyIndex(-1),
-    m_macroCounter(0),
-    m_progressIndicator(0)
+    m_macroCounter(0)
 {
 }
 
 UndoManager::~UndoManager()
 {
-    delete m_progressIndicator;
-    m_progressIndicator = 0;
 }
 
 QString UndoManager::commandText(const DolphinCommand& command) const
@@ -354,7 +352,7 @@ QString UndoManager::commandText(const DolphinCommand& command) const
     return text;
 }
 
-void UndoManager::slotPercent(KIO::Job* /* job */, unsigned long /* percent */)
+void UndoManager::slotPercent(KJob* /* job */, unsigned long /* percent */)
 {
     // It is not allowed to update the progress indicator in the context
     // of this slot, hence do an asynchronous triggering.
@@ -363,7 +361,10 @@ void UndoManager::slotPercent(KIO::Job* /* job */, unsigned long /* percent */)
 
 void UndoManager::updateProgress()
 {
-    m_progressIndicator->execOperation();
+    /*
+     * ### XXX, TODO, KDE4 make this work when switchting to KonqUndoManager
+     */
+    //m_progressIndicator->execOperation();
 }
 
 void UndoManager::calcStepsCount(int& macroCount, int& progressCount)