summaryrefslogtreecommitdiffstats
path: root/kmyfirewall/core/kmftransaction.cpp
blob: 8fe79935db18d65c7bf4e3f73190c5ddbc7c57e7 (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
/***************************************************************************
 *                                                                         *
 *   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
*/
#include "kmftransaction.h"

// KDE includes
#include <kdebug.h>
#include <tdelocale.h>

// Project includes
#include "netfilterobject.h"
#include "kmfundoengine.h"

namespace KMF {

KMFTransaction::KMFTransaction( const TQString& transactionName, NetfilterObject* highestAffectedObject ) {
	m_transactionName = transactionName;
	m_uuID = TQUuid::createUuid();
	m_objectUuid = highestAffectedObject->uuid();
	m_undoXML = highestAffectedObject->getXMLSniplet();
	kdDebug() << "Created " << toString() <<  endl;
}

KMFTransaction::~KMFTransaction() {}

void KMFTransaction::commit() {
	NetfilterObject* obj = NetfilterObject::findObject( m_objectUuid );
	if ( ! obj )  {
		return;
	}
	m_redoXML = obj->getXMLSniplet();
}

NetfilterObject* KMFTransaction::undo() {
	NetfilterObject* obj = NetfilterObject::findObject( m_objectUuid );
	if ( ! obj ) {
		KMFUndoEngine::instance()->log( i18n("KMFTransaction::undo() No object found with uuid: %1").arg( m_objectUuid ), KMFError::WARNING, 0 );
		return 0;
	}
	if( m_undoXML.isNull() ) {
		return 0;
	}
	TQDomDocument doc;
	doc.setContent( m_undoXML );
	TQStringList * errors = new TQStringList();
	obj->loadXML( doc, *errors );
	return obj;
}

NetfilterObject* KMFTransaction::redo() {
	NetfilterObject* obj = NetfilterObject::findObject( m_objectUuid );
	if ( ! obj ) {
		KMFUndoEngine::instance()->log( i18n("KMFTransaction::redo() No object found with uuid: %1").arg( m_objectUuid ), KMFError::WARNING, 0 );
		return 0;
	}
	if ( m_redoXML.isNull() ) {
		return 0;
	}
	TQDomDocument doc;
	doc.setContent( m_redoXML );
	TQStringList * errors = new TQStringList();
	obj->loadXML( doc, *errors );
	return obj;
}

const TQString& KMFTransaction::toString() {
	TQString s = "";
	s.append( i18n("Transaction: %1 uuid: %2\n" ).arg( name() ).arg( uuid().toString() ) );
	s.append( i18n("-- Changed ObjectUuid: %1").arg( m_objectUuid.toString() ) );
	return *( new TQString( s ) );
}

}