summaryrefslogtreecommitdiffstats
path: root/kmyfirewall/kmfwidgets/kmfinterfacewidget.cpp
blob: ffed0059e0dad5ed91460e1099a9c7bdd4755acf (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//
// C++ Implementation:
//
// Description:
//
//
// Author: Christian Hubinger <chubinger@irrsinnig.org>, (C) 2006
//
// Copyright: See COPYING file that comes with this distribution
//
//


#include "kmfinterfacewidget.h"

// TQt includes
#include <tqstringlist.h>

// KDE includes
#include <tdelocale.h>
#include <kcombobox.h>
#include <tdeapplication.h>
#include <kdebug.h>
#include <tdelocale.h>
#include <kurlrequester.h>
#include <kguiitem.h>
#include <kpushbutton.h>
#include <knuminput.h>
#include <tdelistbox.h>
#include <kcombobox.h>
#include <kiconloader.h>
#include <tdeglobal.h>
#include <tdemessagebox.h>
#include <tdelistview.h>

// Prokject includes
#include "../core/kmftarget.h"
#include "../core/kmftargetconfig.h"
#include "../core/kmfundoengine.h"
namespace KMF {
KMFInterfaceWidget::KMFInterfaceWidget( TQWidget* parent, const char* name, WFlags fl )
		: KMyFirewallInterfaceWidget( parent, name, fl ) {
		connect( m_b_add_int, TQ_SIGNAL( clicked() ), this, TQ_SLOT( slotAddInterface() ) );
		connect( m_b_del_int, TQ_SIGNAL( clicked() ), this, TQ_SLOT( slotDelInterface() ) );
		
		m_cb_int_name->clear();
		m_cb_int_name->insertItem( "eth" );
		m_cb_int_name->insertItem( "ppp" );
		m_cb_int_name->insertItem( "ippp" );
		m_cb_int_name->insertItem( "ppoe" );
		m_cb_int_name->insertItem( "wlan" );
		m_cb_int_name->insertItem( "tun" );
		m_cb_int_name->insertItem( "tap" );
		m_cb_int_name->insertItem( "gre" );
		m_cb_int_name->insertItem( "lo" );
}

KMFInterfaceWidget::~KMFInterfaceWidget() {}

void KMFInterfaceWidget::loadTarget( KMFTarget* target ) {
	kdDebug() << "KMFInterfaceWidget::loadTarget( KMFTarget* target )" << endl;
	m_target = target;
	updateView();
}

void KMFInterfaceWidget::updateView(){
	kdDebug() << "KMFInterfaceWidget::updateView()" << endl;
	if ( ! m_target ) {
		return;
	}
	KMFTargetConfig *conf = m_target->config();
	kdDebug() << "Load Config:" << endl;
	kdDebug() << conf->toString() << endl;
	m_lb_int->clear();
	TQStringList ints = conf->interfaces();
	for ( TQStringList::Iterator it = ints.begin(); it != ints.end(); ++it ) {
        TQString s = *it;
        kdDebug() << "Load Interface: " << s << endl; 
        m_lb_int->insertItem( s );
    }
}

void KMFInterfaceWidget::slotAddInterface() {
	TQString int_name = m_cb_int_name->currentText();
	int int_num = m_sb_int_num->value();
	TQString str_num;
	str_num.setNum( int_num );
	TQString interface = int_name;
	if ( int_name != "lo" )
		interface += str_num;
	for ( uint i = 0;i < m_lb_int->count();i++ ) {
		TQString interf = m_lb_int->text( i );
		if ( interface == interf ) {
			KMessageBox::sorry( this, i18n( "You cannot have more then one interface with the same name." ),
								i18n( "Configuration" ) );
			return ;
		}
	}
	m_lb_int->insertItem( interface );
	
	
	KMFUndoEngine::instance()->startTransaction(
		m_target->config(),
		i18n( "Edit interfaces for target: %1.").arg( m_target->guiName() )
	);
	m_target->config()->setInterfaces( interfaces() );
	KMFUndoEngine::instance()->endTransaction();

}

void KMFInterfaceWidget::addInterface( const TQString& interface ) {
	for ( uint i = 0;i < m_lb_int->count();i++ ) {
		TQString interf = m_lb_int->text( i );
		if ( interface == interf ) {
			KMessageBox::sorry( this, i18n( "You cannot have more then one interface with the same name." ),
								i18n( "Configuration" ) );
			return ;
		}
	}
	m_lb_int->insertItem( interface );
}

void KMFInterfaceWidget::addInterfaces( TQStringList interfcaes ) {
	m_lb_int-> insertStringList( interfcaes );
}

void KMFInterfaceWidget::slotDelInterface() {
	int index = m_lb_int->currentItem();
	if ( index > -1 ) {
		switch ( TQMessageBox::warning( this, i18n( "Configuration" ),
				 i18n( "Are you sure that you want to delete\n"
						 "this interface?\n" ),
				 i18n( "&OK" ), i18n( "&Cancel" ),
				 0, 2 ) ) {

					 case 0:      // OK clicked
						m_lb_int->removeItem( index );
						KMFUndoEngine::instance()->startTransaction(
							m_target->config(),
							i18n( "Edit interfaces for target: %1.").arg( m_target->guiName() )
						);
						m_target->config()->setInterfaces( interfaces() );
						KMFUndoEngine::instance()->endTransaction();
						break;
				 }

	} else {
		KMessageBox::sorry( this, i18n( "You have to select an interface first before you can delete it." ),
							i18n( "Configuration" ) );
		return ;

	}
}

void KMFInterfaceWidget::clear() {
	m_lb_int->clear();
}

TQStringList KMFInterfaceWidget::interfaces() {
	TQStringList ifs;
	for ( uint i = 0;i < m_lb_int->count();i++ ) {
		TQString interf = m_lb_int->text( i );
		if ( !interf.isEmpty() ) {
			kdDebug() << "Found Interface " << interf << endl;
			ifs << interf;
		}
	}
	return ifs;
}

}
#include "kmfinterfacewidget.moc"