author | zecke <zecke> | 2004-02-08 20:25:39 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-02-08 20:25:39 (UTC) |
commit | b2c64a5e4b3bed21b1aea091625a3846b2b87d47 (patch) (side-by-side diff) | |
tree | e469488e20911e75a593ab89c74c2ae99e2b7d60 | |
parent | 4a3ca9b1d175df6eea1f38db4feb10c564af29f3 (diff) | |
download | opie-b2c64a5e4b3bed21b1aea091625a3846b2b87d47.zip opie-b2c64a5e4b3bed21b1aea091625a3846b2b87d47.tar.gz opie-b2c64a5e4b3bed21b1aea091625a3846b2b87d47.tar.bz2 |
Example network settings plugin
Fake VPN stuff
-rw-r--r-- | examples/networksettings/config.in | 4 | ||||
-rw-r--r-- | examples/networksettings/example.pro | 17 | ||||
-rw-r--r-- | examples/networksettings/exampleiface.cpp | 43 | ||||
-rw-r--r-- | examples/networksettings/exampleiface.h | 22 | ||||
-rw-r--r-- | examples/networksettings/examplemodule.cpp | 71 | ||||
-rw-r--r-- | examples/networksettings/examplemodule.h | 36 |
6 files changed, 193 insertions, 0 deletions
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 <interfaces/interface.h> + +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 <qwidget.h> + +#include <interfaces/interfaceinformationimp.h> + +#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<Interface> VirtualModule::getInterfaces() { + return m_interfaces; +} + +void VirtualModule::possibleNewInterfaces( QMap<QString, QString>& 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 <module.h> + +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<Interface> getInterfaces(); + void possibleNewInterfaces( QMap<QString, QString>& ); + 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<Interface> m_interfaces; +}; + +extern "C" { + void* create_plugin() { + return new VirtualModule(); + } +}; + +#endif |