summaryrefslogtreecommitdiffstats
path: root/kmyfirewall/core/kmfundoengine.h
blob: 1aa556d0eb24c6c895544ceffcdab0923bf399fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
/*
Author: Christian Hubinger <chubinger@irrsinnig.org>, (C) 2001-2008
*/
#ifndef KMFUNDOENGINE_H
#define KMFUNDOENGINE_H


// qt includes
#include "tqdict.h"
#include "tqvaluelist.h"
#include "tqptrlist.h"
#include "tqstring.h"
#include "tqobject.h"

// project includes
#include "kmftransaction.h"
#include "netfilterobject.h"
// #include "kmfnetwork.h"
#include "kmferror.h"

namespace KMF {
class KMyFirewallInterface;
class KMFTransaction;
class KMFNetwork;
/**
	@author Christian Hubinger <chubinger@irrsinnig.org>
*/

class KMFUndoEngine : public TQObject {
	TQ_OBJECT
  
	
	friend class KMFTransaction;
	friend class KMFNetwork;
	friend class KMFProtocol;
	friend class KMFProtocolCategory;
	friend class KMFProtocolLibrary;
//############# Beginn static stuff ##############	
public:
	/** return the one and only instance */
	static KMFUndoEngine* instance();
private:	
	static KMFUndoEngine* m_instance;
	
//############# End static stuff ##############
protected:
	uint MAX_UNDO;
public:
	~KMFUndoEngine();
	
	/** Set the numbers of undo/redo steps stored */
	void setMaxUndo( uint );
	
	/** Get the numbers of undo/redo steps stored */
	uint maxUndo() {
		return MAX_UNDO;
	};
	
	/** Start a transaction e.g. collection of changes that will
		be tracked to allow undo/redo */
	void startTransaction( NetfilterObject* /* highestAffectedObject */, const TQString& name );
	
	/** Abort a started transaction */
	void abortTransaction();
	
	/** Hold list of available undo transaction objects */
	TQValueList< KMFTransaction* >& undoTransactions();
	
	/** Hold list of available redo transaction objects */
	TQValueList< KMFTransaction* >& redoTransactions();
	
	/** find the transaction with id in undo/redo lists */
	KMFTransaction * findTransction( const TQUuid& id );
	
	/** End a transaction e.g. collection of changes that will
		be tracked to allow undo/redo */
	void endTransaction();
	
	/** Check if we are inside a transaction */
	bool inTransaction();
	
	/** store the provided id in the changes list. */
	void changed( const TQUuid& id );
	
	/** Remove all stored transacation */
	void clearStacks();

	/** Check if the doc is saved */
	bool isSaved();
	void saved();

	/** Undo last transaction, return list of affected objects */
	TQValueList< NetfilterObject* >& undo();
	
	/** Redo last undo-transaction, return list of affected objects */
	TQValueList< NetfilterObject* >& redo();
	
	/** Set the ap instance */
	void setKMFInterface( KMyFirewallInterface *app );
	
	/** log message entry */
	void log( const TQString&, int kmfErrorType /* = KMFError::NORMAL */, NetfilterObject*  /* obj = 0 */ );
	
// 	bool preserveObjectUuid() const {
// 		// return m_preserveObjectUuid;
// 		return true;
// 	}
	
protected:
	KMyFirewallInterface *m_app;
	
private:
//	TQString m_transactionName;
	bool m_in_transaction;
	bool is_saved;
// 	bool m_preserveObjectUuid;
	
	TQValueList< KMFTransaction* > m_undo_transactionObjects;
	TQValueList< KMFTransaction* > m_redo_transactionObjects;
	
//	TQValueList<int> m_changed_objects;	
// 	NetfilterObject *m_highestAffectedObject;
	KMFTransaction *m_currentTransaction;
	
private:
	KMFUndoEngine(); 
	KMFUndoEngine( TQObject*, const char* );
	
	/** Make the loadXML in NEtfilterObject load the uuid from xml */
// 	void setPreserveObjectUuid( bool onOff );



	
signals:
	void sigStackChanged();	
	void sigLog( const TQString& );
};
}
#endif