#include <qtimer.h>
#include <assert.h>
-#include "dolphin.h"
+#include "dolphinmainwindow.h"
#include "dolphinstatusbar.h"
#include "progressindicator.h"
// 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,
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();
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);
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;
}
}
// 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();
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];
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();
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);
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
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.
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)