]>
cloud.milkyroute.net Git - dolphin.git/blob - src/undomanager.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
25 #include <q3valuelist.h>
27 #include <kio/jobclasses.h>
29 class ProgressIndicator
;
32 * @short Represents a file manager command which can be undone and redone.
34 * A command is specified by a type, a list of source URLs and a
37 * Due to the fixed set of commands a file manager offers this class is
38 * a very simplified version of the classic command pattern.
41 * @author Peter Penz <peter.penz@gmx.at>
57 DolphinCommand(Type type
, const KUrl::List
& source
, const KUrl
& dest
);
58 ~DolphinCommand(); // non-virtual
60 DolphinCommand
& operator = (const DolphinCommand
& command
);
61 Type
type() const { return m_type
; }
62 void setSource(const KUrl::List source
) { m_source
= source
; }
63 const KUrl::List
& source() const { return m_source
; }
64 const KUrl
& destination() const { return m_dest
; }
72 friend class UndoManager
; // allow to modify m_macroIndex
76 * @short Stores all file manager commands which can be undone and redone.
78 * During the undo and redo operations a progress information is
79 * shown in the status bar.
81 * @author Peter Penz <peter.penz@gmx.at>
83 class UndoManager
: public QObject
88 static UndoManager
& instance();
91 * Adds the command \a command to the undo list. The command
92 * can be undone by invoking UndoManager::undo().
94 void addCommand(const DolphinCommand
& command
);
97 * Allows to summarize several commands into one macro, which
98 * can be undo in one stop by UndoManager::undo(). Example
100 * UndoManager& undoMan = UndoManager.instance();
101 * undoMan.beginMacro();
102 * undoMan.addCommand(...);
103 * undoMan.addCommand(...);
104 * undoMan.addCommand(...);
105 * undoMan.endMacro();
107 * It is not allowed to do nested macro recordings.
112 * Marks the end of a macro command. See UndoManager::beginMacro()
119 * Performs an undo operation on the last command which has
120 * been added by UndoManager::addCommand().
125 * Performs a redo operation on the last command where an undo
126 * operation has been applied.
132 * Is emitted if whenever the availability state
133 * of the current undo operation changes.
135 void undoAvailable(bool available
);
138 * Is emitted whenever the text of the current
139 * undo operation changes
140 * (e. g. from 'Undo: Delete' to 'Undo: Copy')
142 void undoTextChanged(const QString
& text
);
145 * Is emitted if whenever the availability state
146 * of the current redo operation changes.
148 void redoAvailable(bool available
);
151 * Is emitted whenever the text of the current
152 * redo operation changes
153 * (e. g. from 'Redo: Delete' to 'Redo: Copy')
155 void redoTextChanged(const QString
& text
);
159 virtual ~UndoManager();
160 QString
commandText(const DolphinCommand
& command
) const;
164 * Slot for the percent information of the I/O slaves.
165 * Delegates the updating of the progress information
166 * to UndoManager::updateProgress().
168 void slotPercent(KIO::Job
* job
, unsigned long percent
);
171 * Updates the progress information of the statusbar
172 * by accessing the progress indicator information.
174 void updateProgress();
180 Q3ValueList
<DolphinCommand
> m_history
;
181 ProgressIndicator
* m_progressIndicator
;
184 * Dependent from the current history index \a m_historyIndex
185 * the number of macro commands is written to the output
186 * parameter \a macroCount. The number of steps for all macro
187 * commands is written to the output parameter \a progressCount.
189 * Per default \a macroCount is 1 and \a progressCount represents
190 * the number of operations for one command.
192 void calcStepsCount(int& macroCount
,