From b2c64a5e4b3bed21b1aea091625a3846b2b87d47 Mon Sep 17 00:00:00 2001 From: zecke Date: Sun, 08 Feb 2004 20:25:39 +0000 Subject: Example network settings plugin Fake VPN stuff --- (limited to 'examples/networksettings') diff --git a/examples/networksettings/config.in b/examples/networksettings/config.in new file mode 100644 index 0000000..18fbf05 --- a/dev/null +++ b/examples/networksettings/config.in @@ -0,0 +1,4 @@ + config EXAMPLE_VPN + boolean "opie-networksettingsplugin-example (VPN module)" + default "n" if NETWORKSETUP + depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE && NETWORKSETUP && NETWORKSETUP-CORE && INTERFACES diff --git a/examples/networksettings/example.pro b/examples/networksettings/example.pro new file mode 100644 index 0000000..1239ecd --- a/dev/null +++ b/examples/networksettings/example.pro @@ -0,0 +1,17 @@ +#TEMPLATE = app +# +TEMPLATE = lib +#CONFIG += qt plugin warn_on release +CONFIG += qt plugin warn_on debug +DESTDIR = $(OPIEDIR)/plugins/networksettings +HEADERS = exampleiface.h examplemodule.h +SOURCES = exampleiface.cpp examplemodule.cpp +INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/noncore/settings/networksettings $(OPIEDIR)/noncore/settings/networksettings/interfaces +DEPENDPATH += $(OPIEDIR)/include $(OPIEDIR)/noncore/settings/networksettings $(OPIEDIR)/noncore/settings/networksettings/interfaces +LIBS += -lqpe -linterfaces +TARGET = example_vpn +VERSION = 1.0.0 + + + +include ( $(OPIEDIR)/include.pro ) diff --git a/examples/networksettings/exampleiface.cpp b/examples/networksettings/exampleiface.cpp new file mode 100644 index 0000000..5267a9c --- a/dev/null +++ b/examples/networksettings/exampleiface.cpp @@ -0,0 +1,43 @@ +#include "exampleiface.h" + +VirtualInterface::VirtualInterface( QObject* parent, + const char* name, + bool status ) + : Interface(parent, name, status ) +{ +} + +VirtualInterface::~VirtualInterface() { +} + +bool VirtualInterface::refresh() { +/* we do VPN over ppp + * so replace the interfaceName with + * something actual existing + * I take wlan0 in my case + */ + QString old = getInterfaceName(); + qWarning("Interface name was " + old ); + setInterfaceName( "wlan0" ); + + bool b =Interface::refresh(); + setInterfaceName( old ); + +/* new and old interface name */ + emit updateInterface(this); + return b; +} + + +void VirtualInterface::start() { +// call pptp + setStatus(true); + refresh(); + emit updateMessage("VPN started"); +} + +void VirtualInterface::stop() { + setStatus(false ); + refresh(); + emit updateMessage("VPN halted"); +} diff --git a/examples/networksettings/exampleiface.h b/examples/networksettings/exampleiface.h new file mode 100644 index 0000000..e5a757b --- a/dev/null +++ b/examples/networksettings/exampleiface.h @@ -0,0 +1,22 @@ +#ifndef EXAMPLE_IFACE_VPN_H +#define EXAMPLE_IFACE_VPN_H + +#include + +class VirtualInterface : public Interface { + Q_OBJECT + +public: + VirtualInterface(QObject* parent, const char* name = "vpn", bool up = false ); + ~VirtualInterface(); + +public slots: + bool refresh(); // refresh information + void start(); + void stop(); + +private: + bool m_isUp : 1; +}; + +#endif diff --git a/examples/networksettings/examplemodule.cpp b/examples/networksettings/examplemodule.cpp new file mode 100644 index 0000000..d7fd718 --- a/dev/null +++ b/examples/networksettings/examplemodule.cpp @@ -0,0 +1,71 @@ +#include + +#include + +#include "exampleiface.h" +#include "examplemodule.h" + +VirtualModule::VirtualModule() { + Interface* iface = new VirtualInterface( 0 ); + iface->setHardwareName( "vpn" ); + iface->setInterfaceName( "Test VPN" ); + m_interfaces.append( iface ); + +// If we set up VPN via pptp +// and networksettins was closed and now opened +// we need to hide the ppp device behind us +// One can do this by calling setHandledInterfaceNames +// setHandledInterfaceNames(); +} + +VirtualModule::~VirtualModule() { + m_interfaces.setAutoDelete( true ); + m_interfaces.clear(); +} + + +/* + * We're a VPN module + */ +bool VirtualModule::isOwner( Interface* iface ) { + /* check if it is our device */ + return m_interfaces.find( iface ) != -1; +} + +QWidget* VirtualModule::configure( Interface* ) { +/* We don't have any Config for now */ + return 0l; +} + +QWidget* VirtualModule::information( Interface* iface ) { + return new InterfaceInformationImp(0, "Interface info", iface ); +} + +QList VirtualModule::getInterfaces() { + return m_interfaces; +} + +void VirtualModule::possibleNewInterfaces( QMap& map) { + map.insert( QObject::tr("VPN PPTP"), + QObject::tr("Add new Point to Point Tunnel Protocol connection" ) ); +} + + +Interface* VirtualModule::addNewInterface( const QString& ) { + /* check the str if we support more interfaces */ +/* + Interface* iface = new VirtualInterface( 0 ); + iface->setModuleOwner( this ); + return iface;*/ + +// if we would support saving interfaces we could add +// them here + + return 0; +} + + +bool VirtualModule::remove( Interface* ) { +/* we do not support removing our interface */ + return false; +} diff --git a/examples/networksettings/examplemodule.h b/examples/networksettings/examplemodule.h new file mode 100644 index 0000000..f14a653 --- a/dev/null +++ b/examples/networksettings/examplemodule.h @@ -0,0 +1,36 @@ +#ifndef OPIE_EXAMPLE_NETWORK_MODULE_H +#define OPIE_EXAMPLE_NETWORK_MODULE_H + +#include + +class VirtualModule : Module { + +signals: + void updateInterface(Interface* i ); + +public: + VirtualModule(); + ~VirtualModule(); + + const QString type() {return QString::fromLatin1("vpn" );} + void setProfile( const QString& ) {} + bool isOwner( Interface* ); + QWidget *configure( Interface* ); + QWidget *information( Interface* ); + QList getInterfaces(); + void possibleNewInterfaces( QMap& ); + Interface *addNewInterface( const QString& ); + bool remove( Interface* iface ); + QString getPixmapName( Interface* ) {return QString::fromLatin1("Tux"); } + void receive( const QCString&, const QByteArray& ar ) {} // don't listen +private: + QList m_interfaces; +}; + +extern "C" { + void* create_plugin() { + return new VirtualModule(); + } +}; + +#endif -- cgit v0.9.0.2