1 /***************************************************************************
2  UndoTransactionGuard.h  -  guard class for undo transactions
3 			     -------------------
4     begin                : Sat May 26, 2001
5     copyright            : (C) 2001 by Thomas Eschenbacher
6     email                : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
7 
8  ***************************************************************************/
9 
10 /***************************************************************************
11  *                                                                         *
12  *   This program is free software; you can redistribute it and/or modify  *
13  *   it under the terms of the GNU General Public License as published by  *
14  *   the Free Software Foundation; either version 2 of the License, or     *
15  *   (at your option) any later version.                                   *
16  *                                                                         *
17  ***************************************************************************/
18 
19 #ifndef UNDO_TRANSACTION_GUARD_H
20 #define UNDO_TRANSACTION_GUARD_H
21 
22 #include "config.h"
23 
24 #include <QtGlobal>
25 
26 class QString;
27 
28 namespace Kwave {
29 
30     class SignalManager;
31     class UndoAction;
32     class Plugin;
33 
34     /**
35      * @class UndoTransactionGuard
36      * A simple guard class for opening and closing an undo transaction
37      * operating on a SignalManager. Several nested UndoTransactionGuards
38      * (or undo transactions) are allowed.
39      */
40     class Q_DECL_EXPORT UndoTransactionGuard
41     {
42 
43     public:
44 	/**
45 	 * Constructor. Also determines the name of the transaction if
46 	 * it is the first of several nested transactions.
47 	 * @param manager reference to the SignalManager we operate on
48 	 * @param name the name of the transaction as a user-readable and
49 	 *        localized string. [optional]
50 	 */
51 	explicit UndoTransactionGuard(Kwave::SignalManager &manager,
52 	                              const QString &name = QString());
53 
54 	/**
55 	 * Constructor for use from a plugin. Also determines the name of the
56 	 * transaction if it is the first of several nested transactions.
57 	 * @param plugin reference to the plugin (you should pass
58 	 *               <code>*this</code>.
59 	 * @param name the name of the transaction as a user-readable and
60 	 *        localized string. [optional] If you pass null or omit this
61 	 *        parameter, the name of the plugin will be used instead.
62 	 */
63 	explicit UndoTransactionGuard(Kwave::Plugin &plugin,
64 	                              const QString &name = QString());
65 
66 	/** Destructor. */
67 	virtual ~UndoTransactionGuard();
68 
69 	/**
70 	 * Tries to free memory for a new undo action and stores all needed
71 	 * data if successful.
72 	 * @param action UndoAction to that is to be registered
73 	 * @return true if the action is allowed, false if the user has
74 	 *         chosen to abort the operation if the memory limit of
75 	 *         the undo buffer would be exceeded. The return value
76 	 *         will also be false if the action is null.
77 	 * @note If undo is currently not enabled, the passed UndoAction
78 	 *       will be ignored and not freed, the return value will
79 	 *       be false. So it is safer not to call this function if
80 	 *       undo is not enabled.
81 	 */
82 	bool registerUndoAction(UndoAction *action);
83 
84 	/**
85 	 * Aborts the undo transaction, discards all undo data and restores
86 	 * the previous "modified" state of the signal.
87 	 */
88 	void abort();
89 
90     private:
91 
92 	/** Reference to the responsible SignalManager */
93 	Kwave::SignalManager &m_manager;
94 
95 	/** the initial "modified" state of the signal */
96 	bool m_initial_modified;
97 
98     };
99 
100 }
101 
102 #endif /* UNDO_TRANSACTION_GUARD_H */
103 
104 //***************************************************************************
105 //***************************************************************************
106