#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,
}
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) {
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);
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(KUrl::AddTrailingSlash));
+ 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()) {
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);
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;
}
// 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);
+ 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;
}
}
// 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 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);
+ 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;
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)