X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/7fbae445277374fb2bacfcd7c04e8d7fbb2c3f05..de4ffa3322c8d919ebdb0cdb51115bace8aa8d11:/src/undomanager.cpp diff --git a/src/undomanager.cpp b/src/undomanager.cpp index d4a4574a0..eb1ce0f37 100644 --- a/src/undomanager.cpp +++ b/src/undomanager.cpp @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "undomanager.h" @@ -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, @@ -74,13 +76,15 @@ void UndoManager::addCommand(const DolphinCommand& command) { ++m_historyIndex; + QList::iterator it = m_history.begin(); + it += m_historyIndex; if (m_recordMacro) { DolphinCommand macroCommand = command; macroCommand.m_macroIndex = m_macroCounter; - m_history.insert(m_history.at(m_historyIndex), macroCommand); + m_history.insert(it, macroCommand); } else { - m_history.insert(m_history.at(m_historyIndex), command); + m_history.insert(it, command); } emit undoAvailable(true); @@ -106,7 +110,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 +126,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 +200,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 +217,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 +240,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 +257,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 +287,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 +314,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 +354,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 +363,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)