summaryrefslogtreecommitdiffstats
path: root/kmyfirewall/ipteditor/kmfnewchaindlg.cpp
blob: cd896e17b9c8c80500580f2037a4eb4d3876616e (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
/***************************************************************************
 begin                : Sat Mar 9 2002
 copyright            : (C) 2002 by Christian Hubinger
 email                : chubinger@irrsinnig.org
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "kmfnewchaindlg.h"

// qt includes
#include <tqstring.h>
#include <tqradiobutton.h>
#include <tqlineedit.h>
#include <tqnamespace.h>
#include <tqevent.h>

// kde includes
#include <tdelocale.h>
#include <kdebug.h>
#include <tdemessagebox.h>

// my includes
#include "../core/xmlnames.h"
#include "../core/kmfdoc.h"
#include "../core/kmfiptdoc.h"
#include "../core/kmferror.h"
#include "../core/kmfcheckinput.h"
#include "../core/kmferrorhandler.h"
#include "../core/kmfnetwork.h"
#include "../core/kmfundoengine.h"
namespace KMF {
KMFNewChainDlg::KMFNewChainDlg ( TQWidget *parent, const char *name, bool modal, WFlags fl ) : KMyFirewallChainEditorNewChain ( parent, name, modal, fl ) {
	kmfdoc = 0;
	m_err = new KMFError();
	m_err_handler = new KMFErrorHandler ( "KMFNewChainDlg" );
	m_check_input = new KMFCheckInput();
}

KMFNewChainDlg::~KMFNewChainDlg() {}

void KMFNewChainDlg::keyPressEvent ( TQKeyEvent * e ) {
	// kdDebug() << "KMFNewChainDlg::keyPressEvent ( TQKeyEvent * " <<  e->key()  << ")" << endl;
	if ( e->key() == TQt::Key_Enter ||
			e->key() == TQt::Key_Return ) {
		accept();
		e-> accept();
	}
	if ( e->key() == TQt::Key_Escape ||
			e->key() == TQt::Key_Backspace ) {
		TQDialog::reject();
		e-> accept();
	}
}

void KMFNewChainDlg::loadDoc ( KMFIPTDoc* doc ) {
	kmfdoc = doc;
}
/** No descriptions */
void KMFNewChainDlg::accept() {
	if ( kmfdoc == 0 ) {
		KMessageBox::error ( 0, i18n ( "KMFNewChainDlg: kmfdoc = 0. This happened because of a bug." ) );
		return ;
	}
	TQStringList StringList;
	TQString name = t_name->text();
	TQString target = "DROP";
	if ( !name.isEmpty() ) {
		m_check_input->checkInput ( name, "CHAINNAME", m_err );
		if ( ! m_err_handler->showError ( m_err ) ) {
			return;
		}

		IPTChain* chain = 0;
		TQString table = Constants::FilterTable_Name;
		if ( c_filter->isChecked() ) {
			table = Constants::FilterTable_Name;
		} else if ( c_nat->isChecked() ) {
			table = Constants::NatTable_Name;
		} else if ( c_mangle->isChecked() ) {
			table = Constants::MangleTable_Name;
		} else {
			return;
		}

		KMFUndoEngine::instance()->startTransaction (
			kmfdoc->table ( table ),
			i18n ( "Added Chain: %1 to Table: %1" ).arg ( name ).arg ( table )
		);
		chain = kmfdoc->table ( table )->addChain ( name, target, false, m_err );
		if ( m_err_handler->showError ( m_err ) ) {
			kmfdoc->table ( table )->changed();
			KMFUndoEngine::instance()->endTransaction();
			emit sigUpdateView();
		} else {
			KMFUndoEngine::instance()->abortTransaction();
			return;
		}
		TQDialog::accept();
	} else {
		KMessageBox::sorry ( 0, i18n ( "You must set a name for your chain." ) );
		return;
	}
}

}

#include "kmfnewchaindlg.moc"