summaryrefslogtreecommitdiff
path: root/examples
Unidiff
Diffstat (limited to 'examples') (more/less context) (ignore whitespace changes)
-rw-r--r--examples/networksettings/config.in4
-rw-r--r--examples/networksettings/example.pro17
-rw-r--r--examples/networksettings/exampleiface.cpp43
-rw-r--r--examples/networksettings/exampleiface.h22
-rw-r--r--examples/networksettings/examplemodule.cpp71
-rw-r--r--examples/networksettings/examplemodule.h36
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 @@
1 config EXAMPLE_VPN
2 boolean "opie-networksettingsplugin-example (VPN module)"
3 default "n" if NETWORKSETUP
4 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 @@
1#TEMPLATE = app
2#
3TEMPLATE = lib
4#CONFIG += qt plugin warn_on release
5 CONFIG += qt plugin warn_on debug
6DESTDIR = $(OPIEDIR)/plugins/networksettings
7 HEADERS = exampleiface.h examplemodule.h
8 SOURCES = exampleiface.cpp examplemodule.cpp
9 INCLUDEPATH+= $(OPIEDIR)/include $(OPIEDIR)/noncore/settings/networksettings $(OPIEDIR)/noncore/settings/networksettings/interfaces
10 DEPENDPATH+= $(OPIEDIR)/include $(OPIEDIR)/noncore/settings/networksettings $(OPIEDIR)/noncore/settings/networksettings/interfaces
11LIBS += -lqpe -linterfaces
12 TARGET = example_vpn
13 VERSION = 1.0.0
14
15
16
17include ( $(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 @@
1#include "exampleiface.h"
2
3VirtualInterface::VirtualInterface( QObject* parent,
4 const char* name,
5 bool status )
6 : Interface(parent, name, status )
7{
8}
9
10VirtualInterface::~VirtualInterface() {
11}
12
13bool VirtualInterface::refresh() {
14/* we do VPN over ppp
15 * so replace the interfaceName with
16 * something actual existing
17 * I take wlan0 in my case
18 */
19 QString old = getInterfaceName();
20 qWarning("Interface name was " + old );
21 setInterfaceName( "wlan0" );
22
23 bool b =Interface::refresh();
24 setInterfaceName( old );
25
26/* new and old interface name */
27 emit updateInterface(this);
28 return b;
29}
30
31
32void VirtualInterface::start() {
33// call pptp
34 setStatus(true);
35 refresh();
36 emit updateMessage("VPN started");
37}
38
39void VirtualInterface::stop() {
40 setStatus(false );
41 refresh();
42 emit updateMessage("VPN halted");
43}
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 @@
1#ifndef EXAMPLE_IFACE_VPN_H
2#define EXAMPLE_IFACE_VPN_H
3
4#include <interfaces/interface.h>
5
6class VirtualInterface : public Interface {
7 Q_OBJECT
8
9public:
10 VirtualInterface(QObject* parent, const char* name = "vpn", bool up = false );
11 ~VirtualInterface();
12
13public slots:
14 bool refresh(); // refresh information
15 void start();
16 void stop();
17
18private:
19 bool m_isUp : 1;
20};
21
22#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 @@
1#include <qwidget.h>
2
3#include <interfaces/interfaceinformationimp.h>
4
5#include "exampleiface.h"
6#include "examplemodule.h"
7
8VirtualModule::VirtualModule() {
9 Interface* iface = new VirtualInterface( 0 );
10 iface->setHardwareName( "vpn" );
11 iface->setInterfaceName( "Test VPN" );
12 m_interfaces.append( iface );
13
14// If we set up VPN via pptp
15// and networksettins was closed and now opened
16// we need to hide the ppp device behind us
17// One can do this by calling setHandledInterfaceNames
18// setHandledInterfaceNames();
19}
20
21VirtualModule::~VirtualModule() {
22 m_interfaces.setAutoDelete( true );
23 m_interfaces.clear();
24}
25
26
27/*
28 * We're a VPN module
29 */
30bool VirtualModule::isOwner( Interface* iface ) {
31 /* check if it is our device */
32 return m_interfaces.find( iface ) != -1;
33}
34
35QWidget* VirtualModule::configure( Interface* ) {
36/* We don't have any Config for now */
37 return 0l;
38}
39
40QWidget* VirtualModule::information( Interface* iface ) {
41 return new InterfaceInformationImp(0, "Interface info", iface );
42}
43
44QList<Interface> VirtualModule::getInterfaces() {
45 return m_interfaces;
46}
47
48void VirtualModule::possibleNewInterfaces( QMap<QString, QString>& map) {
49 map.insert( QObject::tr("VPN PPTP"),
50 QObject::tr("Add new Point to Point Tunnel Protocol connection" ) );
51}
52
53
54Interface* VirtualModule::addNewInterface( const QString& ) {
55 /* check the str if we support more interfaces */
56/*
57 Interface* iface = new VirtualInterface( 0 );
58 iface->setModuleOwner( this );
59 return iface;*/
60
61// if we would support saving interfaces we could add
62// them here
63
64 return 0;
65}
66
67
68bool VirtualModule::remove( Interface* ) {
69/* we do not support removing our interface */
70 return false;
71}
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 @@
1#ifndef OPIE_EXAMPLE_NETWORK_MODULE_H
2#define OPIE_EXAMPLE_NETWORK_MODULE_H
3
4#include <module.h>
5
6class VirtualModule : Module {
7
8signals:
9 void updateInterface(Interface* i );
10
11public:
12 VirtualModule();
13 ~VirtualModule();
14
15 const QString type() {return QString::fromLatin1("vpn" );}
16 void setProfile( const QString& ) {}
17 bool isOwner( Interface* );
18 QWidget *configure( Interface* );
19 QWidget *information( Interface* );
20 QList<Interface> getInterfaces();
21 void possibleNewInterfaces( QMap<QString, QString>& );
22 Interface *addNewInterface( const QString& );
23 bool remove( Interface* iface );
24 QString getPixmapName( Interface* ) {return QString::fromLatin1("Tux"); }
25 void receive( const QCString&, const QByteArray& ar ) {} // don't listen
26private:
27 QList<Interface> m_interfaces;
28};
29
30extern "C" {
31 void* create_plugin() {
32 return new VirtualModule();
33 }
34};
35
36#endif