X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/7fbae445277374fb2bacfcd7c04e8d7fbb2c3f05..ced7cbd022b68c8dedd61b5d34d27b9c1296df15:/src/undomanager.cpp diff --git a/src/undomanager.cpp b/src/undomanager.cpp index d4a4574a0..e6946cfe3 100644 --- a/src/undomanager.cpp +++ b/src/undomanager.cpp @@ -24,7 +24,7 @@ #include #include -#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, @@ -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,12 +124,16 @@ 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); @@ -190,14 +198,14 @@ void UndoManager::undo() 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]; @@ -250,8 +255,6 @@ void UndoManager::redo() emit undoAvailable(true); emit undoTextChanged(i18n("Undo: %1",commandText(command))); - Dolphin& dolphin = Dolphin::mainWin(); - KUrl::List sourceUrls = command.source(); KUrl::List::Iterator it = sourceUrls.begin(); const KUrl::List::Iterator end = sourceUrls.end(); @@ -282,21 +285,21 @@ void UndoManager::redo() const QString originalFileName((*it).fileName().section('-', 1)); KUrl originalSourceUrl(destUrl + "/" + originalFileName); KIO::Job* moveToTrashJob = KIO::trash(originalSourceUrl); - KIO::NetAccess::synchronousRun(moveToTrashJob, &dolphin); + 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(); + progressIndicator.execOperation(); KUrl::List::Iterator it = sourceUrls.begin(); assert(sourceUrls.count() == 1); KIO::CopyJob* copyJob = KIO::copyAs(*it, command.destination(), false); @@ -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)