summaryrefslogtreecommitdiffstats
path: root/kmyfirewall/genericinterface/kmfgenericinterface_part.cpp
blob: de9635b139d6fcc8ebbf2fec64743dcc205b6fb5 (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/***************************************************************************
 *                                                                         *
 *   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
*/


#include "kmfgenericinterface_part.h"


// QT includes
#include <tqlabel.h>

// KDE includes
#include <kinstance.h>
#include <tdeaction.h>
#include <kstdaction.h>
#include <tdelocale.h>
#include <tdeaboutdata.h>
#include <tdemessagebox.h>
#include <kiconloader.h>
#include <tdeparts/genericfactory.h>

// Project includes
#include "kmfgenericinterface.h"

#include "../core/kmfnetwork.h"

#include "../kmfwidgets/kmfmainwindow.h"
namespace KMF {
KMFGenericInterfacePart::KMFGenericInterfacePart( TQWidget *parentWidget, const char *  widgetName ,
        TQObject *parent, const char *name,
        const TQStringList & /*args*/ )
		: KParts::ReadWritePart( parent, name ) {
	setInstance( KMFGenericInterfacePartFactory::instance() );

	m_genericinterface = new KMFGenericInterface( parentWidget, widgetName );

	
	m_app = dynamic_cast<KMFMainWindow*>( parent );
	if ( ! m_app ) {
		KMessageBox::error(0,"Oops wrong parent class found for kmfinstallerplugin!!!");
	}

	m_genericinterface->loadDoc( m_app->network() );
	connect( m_genericinterface, TQT_SIGNAL( sigTargetChanged() ),
		this, TQT_SLOT( slotTargetChanged() ) );
	
	connect( m_app, TQT_SIGNAL( sigUpdateView() ),
		m_genericinterface, TQT_SIGNAL( sigUpdateView() ) );

	connect( m_app, TQT_SIGNAL( sigUpdateView( NetfilterObject* ) ),
		m_genericinterface, TQT_SIGNAL( sigUpdateView( NetfilterObject* ) ) );

	connect( m_app, TQT_SIGNAL( sigEnableActions( bool ) ),
		this, TQT_SLOT( slotEnableActions( bool ) ) );

	
	m_actionGoMyNetwork = new TDEAction( i18n( "&My Network" ), TQIconSet( BarIcon( "network", KMFGenericInterfacePartFactory::instance() ) ),
	                                 0 , this, TQT_SLOT( slotGoMyNetwork() ), actionCollection(), "my_network" );

	m_actionGoAccessControl = new TDEAction( i18n( "&Access Control" ), TQIconSet( BarIcon( "services", KMFGenericInterfacePartFactory::instance() ) ),
	                                 0 , this, TQT_SLOT( slotGoAccessControl() ), actionCollection(), "access_control" );


	m_actionGoSpecialHosts = new TDEAction( i18n( "&Special Hosts Control" ), TQIconSet( BarIcon( "network_local", KMFGenericInterfacePartFactory::instance() ) ),
	                                 0 , this, TQT_SLOT( slotGoSpecialHosts() ), actionCollection(), "special_hosts" );


	m_actionGoICMPOptions = new TDEAction( i18n( "&ICMP Options" ), TQIconSet( BarIcon( "pipe", KMFGenericInterfacePartFactory::instance() ) ),
	                                 0 , this, TQT_SLOT( slotGoICMPOptions() ), actionCollection(), "icmp_options" );

	
	m_actionGoNATConfiguration = new TDEAction( i18n( "&NAT Configuration" ), TQIconSet( BarIcon( "filesaveas", KMFGenericInterfacePartFactory::instance() ) ),
	                                 0 , this, TQT_SLOT( slotGoNATConfiguration() ), actionCollection(), "nat_configuration" );
	
	m_actionGoLogging = new TDEAction( i18n( "&Logging" ), TQIconSet( BarIcon( "log", KMFGenericInterfacePartFactory::instance() ) ),
	                                 0 , this, TQT_SLOT( slotGoLogging() ), actionCollection(), "logging_options" );


	setWidget( m_genericinterface );
	setXMLFile( "kmfgenericinterfacepartui.rc" );

	// we are read-write by default
	setReadWrite( true );

	// we are not modified since we haven't done anything yet
	setModified( false );

}

KMFGenericInterfacePart::~KMFGenericInterfacePart() {
	closeURL();
}

void KMFGenericInterfacePart::slotTargetChanged() {
	m_app->updateCaption();
}

void KMFGenericInterfacePart::setReadWrite( bool rw ) {
	ReadWritePart::setReadWrite( rw );
}

void KMFGenericInterfacePart::slotGoMyNetwork() {
	kdDebug() << "slotGoMyNetwork()" << endl;
	m_genericinterface->showPage( 0 );
}

void KMFGenericInterfacePart::slotGoAccessControl() {
	kdDebug() << "slotGoAccessControl()" << endl;
	m_genericinterface->showPage( 1 );
}

void KMFGenericInterfacePart::slotGoSpecialHosts() {
	kdDebug() << "slotGoSpecialHosts()" << endl;
	m_genericinterface->showPage( 2 );
}

void KMFGenericInterfacePart::slotGoICMPOptions() {
	kdDebug() << "slotGoICMPOptions()" << endl;
	m_genericinterface->showPage( 3 );
}

void KMFGenericInterfacePart::slotGoNATConfiguration() {
	kdDebug() << "slotGoNATConfiguration()" << endl;
	m_genericinterface->showPage( 4 );
}

void KMFGenericInterfacePart::slotGoLogging() {
	kdDebug() << "slotGoLogging()" << endl;
	m_genericinterface->showPage( 5 );
}


void KMFGenericInterfacePart::setModified( bool modified ) {
	// get a handle on our Save action and make sure it is valid
// 	TDEAction * save = actionCollection() ->action( KStdAction::stdName( KStdAction::Save ) );
// 	if ( !save )
// 		return ;
// 
// 	// if so, we either enable or disable it based on the current
// 	// state
// 	if ( modified )
// 		save->setEnabled( true );
// 	else
// 		save->setEnabled( false );

	// in any event, we want our parent to do it's thing
	ReadWritePart::setModified( modified );
}

bool KMFGenericInterfacePart::openFile() {
	// m_file is always local so we can use TQFile on it
	//     TQFile file(m_file);
	//     if (file.open(IO_ReadOnly) == false)
	//         return false;
	//
	//     // our example widget is text-based, so we use TQTextStream instead
	//     // of a raw TQDataStream
	//     TQTextStream stream(&file);
	//     TQString str;
	//     while (!stream.eof())
	//         str += stream.readLine() + "\n";
	//
	//     file.close();
	//
	//     // now that we have the entire file, display it
	// //     m_widget->setText(str);
	//
	//     // just for fun, set the status bar
	//     emit setStatusBarText( m_url.prettyURL() );

	return true;
}

bool KMFGenericInterfacePart::saveFile() {
	// if we aren't read-write, return immediately
	/*    if (isReadWrite() == false)
	        return false;

	    // m_file is always local, so we use TQFile
	    TQFile file(m_file);
	    if (file.open(IO_WriteOnly) == false)
	        return false;

	    // use TQTextStream to dump the text to the file
	    TQTextStream stream(&file);
	    stream << m_widget->text();

	    file.close();
	*/ 
	return true;
}

void KMFGenericInterfacePart::slotEnableActions( bool ) {
	kdDebug() << "void KMFGenericInterfacePart::slotEnableActions( bool )" << endl;
}

// bool KMFGenericInterfacePart::closeURL()
// {
//     return true;
// }

// It's usually safe to leave the factory code alone.. with the
// notable exception of the TDEAboutData data
#include <tdeaboutdata.h>
#include <tdelocale.h>

TDEInstance* KMFGenericInterfacePartFactory::s_instance = 0L;
TDEAboutData* KMFGenericInterfacePartFactory::s_about = 0L;

KMFGenericInterfacePartFactory::KMFGenericInterfacePartFactory()
		: KParts::Factory() {}

KMFGenericInterfacePartFactory::~KMFGenericInterfacePartFactory() {
	delete s_instance;
	delete s_about;

	s_instance = 0L;
}

KParts::Part* KMFGenericInterfacePartFactory::createPartObject( TQWidget *parentWidget, const char *widgetName,
        TQObject *parent, const char *name,
        const char *classname, const TQStringList& args) {
	// Create an instance of our Part
	KMFGenericInterfacePart * obj = new KMFGenericInterfacePart( parentWidget, widgetName, parent, name ,args );

	// See if we are to be read-write or not
	if ( TQCString( classname ) == "KParts::ReadOnlyPart" )
		obj->setReadWrite( false );

	return obj;
}

TDEInstance* KMFGenericInterfacePartFactory::instance() {
	if ( !s_instance ) {
		s_about = new TDEAboutData( "kmfgenericinterfacepart", I18N_NOOP( "kmfgenericinterfacepartPart" ), "0.1" );
		s_about->addAuthor( "Christian Hubinger", 0, "chubinger@irrsinnig.org" );
		s_instance = new TDEInstance( s_about );
	}
	return s_instance;
}

extern "C" {
	void* init_libkmfgenericinterfacepart() {
		return new KMFGenericInterfacePartFactory;
	}
}

}

#include "kmfgenericinterface_part.moc"