summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/networkapplet/.cvsignore5
-rw-r--r--noncore/applets/networkapplet/config.in7
-rw-r--r--noncore/applets/networkapplet/networkapplet.cpp252
-rw-r--r--noncore/applets/networkapplet/networkapplet.h112
-rw-r--r--noncore/applets/networkapplet/networkapplet.pro15
-rw-r--r--noncore/applets/networkapplet/opie-networkapplet.control9
-rwxr-xr-xnoncore/applets/networkapplet/opie-networkapplet.postinst6
-rwxr-xr-xnoncore/applets/networkapplet/opie-networkapplet.postrm2
8 files changed, 408 insertions, 0 deletions
diff --git a/noncore/applets/networkapplet/.cvsignore b/noncore/applets/networkapplet/.cvsignore
new file mode 100644
index 0000000..99a2727
--- a/dev/null
+++ b/noncore/applets/networkapplet/.cvsignore
@@ -0,0 +1,5 @@
1*.moc
2*.~
3Makefile*
4moc_*
5opieobj
diff --git a/noncore/applets/networkapplet/config.in b/noncore/applets/networkapplet/config.in
new file mode 100644
index 0000000..00be317
--- a/dev/null
+++ b/noncore/applets/networkapplet/config.in
@@ -0,0 +1,7 @@
1 config NETWORKAPPLET
2 boolean "Network (control network interfaces on-the-fly)"
3 default "n"
4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2UI
5 comment "Network applet needs a libqpe and libopie2 (ui, net)"
6 depends !(( LIBQPE || LIBQPE-X11 ) && LIBOPIE2UI)
7
diff --git a/noncore/applets/networkapplet/networkapplet.cpp b/noncore/applets/networkapplet/networkapplet.cpp
new file mode 100644
index 0000000..3019456
--- a/dev/null
+++ b/noncore/applets/networkapplet/networkapplet.cpp
@@ -0,0 +1,252 @@
1/*
2                 This file is part of the Opie Project
3
4 =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 .=l.
6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details.
21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28
29*/
30
31#include "networkapplet.h"
32#include <opie2/otaskbarapplet.h>
33#include <qpe/qlibrary.h>
34#include <qpe/resource.h>
35#include <qpainter.h>
36#include <opie2/odebug.h>
37#include <opie2/onetwork.h>
38
39#include <qpushbutton.h>
40#include <qlabel.h>
41#include <qlayout.h>
42#include <qlineedit.h>
43#include <qtoolbutton.h>
44#include <qhostaddress.h>
45#include <qobjectlist.h>
46
47#include <assert.h>
48
49IfaceUpDownButton::IfaceUpDownButton( QWidget* parent, const char* name )
50 :QToolButton( parent, name )
51{
52 _iface = ONetwork::instance()->interface( name );
53 assert( _iface );
54 setToggleButton( true );
55 //setAutoRaise( true );
56 setOnIconSet( QIconSet( Resource::loadPixmap( "up" ) ) );
57 setOffIconSet( QIconSet( Resource::loadPixmap( "down" ) ) );
58 setOn( _iface->isUp() );
59 //setFixedWidth( 16 );
60 connect( this, SIGNAL( clicked() ), this, SLOT( clicked() ) );
61}
62
63
64IfaceUpDownButton::~IfaceUpDownButton()
65{
66}
67
68
69void IfaceUpDownButton::clicked()
70{
71 _iface->setUp( isOn() );
72 setOn( _iface->isUp() ); // it might not have worked...
73 repaint();
74}
75
76
77IfaceIPAddress::IfaceIPAddress( QWidget* parent, const char* name )
78 :QLineEdit( parent, name )
79{
80 setFont( QFont( "fixed" ) );
81 _iface = ONetwork::instance()->interface( name );
82 setFixedWidth( 105 );
83 setText( _iface->ipV4Address() );
84 connect( this, SIGNAL( returnPressed() ), this, SLOT( returnPressed() ) );
85}
86
87
88IfaceIPAddress::~IfaceIPAddress()
89{
90}
91
92
93void IfaceIPAddress::returnPressed()
94{
95 QHostAddress a;
96 a.setAddress( text() );
97 QHostAddress mask;
98 mask.setAddress( _iface->ipV4Netmask() ); // setIPV4Address destroys the netmask...
99 _iface->setIPV4Address( a );
100 _iface->setIPV4Netmask( mask ); // recover the old netmask
101 setText( _iface->ipV4Address() );
102 repaint();
103}
104
105
106NetworkAppletControl::NetworkAppletControl( OTaskbarApplet* parent, const char* name )
107 :QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), l(0)
108{
109 setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
110 l = new QVBoxLayout( this, 4, 2 );
111}
112
113
114void NetworkAppletControl::build()
115{
116 ONetwork::InterfaceIterator it = ONetwork::instance()->iterator();
117 while ( it.current() )
118 {
119 QHBoxLayout* h = new QHBoxLayout( l );
120 QLabel* symbol = new QLabel( this );
121 symbol->setPixmap( Resource::loadPixmap( guessDevice( it.current() ) ) );
122 h->addWidget( symbol );
123 symbol->show();
124
125 QLabel* name = new QLabel( it.current()->name(), this );
126 name->setFixedWidth( 35 );
127 h->addWidget( name );
128 name->show();
129
130 IfaceIPAddress* ip = new IfaceIPAddress( this, it.current()->name() );
131 h->addWidget( ip );
132 ip->show();
133
134 IfaceUpDownButton* tb = new IfaceUpDownButton( this, it.current()->name() );
135 tb->show();
136
137 h->addWidget( tb );
138
139 ++it;
140 }
141}
142
143
144NetworkAppletControl::~NetworkAppletControl()
145{
146}
147
148
149QString NetworkAppletControl::guessDevice( ONetworkInterface* iface )
150{
151 if ( iface->isWireless() )
152 return "networksettings/wlan";
153 if ( iface->isLoopback() )
154 return "networksettings/lo";
155 if ( QString( iface->name() ).contains( "usb" ) )
156 return "networksettings/usb";
157 if ( QString( iface->name() ).contains( "ir" ) )
158 return "networksettings/ir";
159
160 //TODO: Insert neat symbol and check for tunnel devices
161
162 return "networksettings/lan";
163
164}
165
166
167void NetworkAppletControl::showEvent( QShowEvent* e )
168{
169 qDebug( "showEvent" );
170 build();
171 QWidget::showEvent( e );
172}
173
174
175void NetworkAppletControl::hideEvent( QHideEvent* e )
176{
177 qDebug( "hideEvent" );
178 QWidget::hideEvent( e );
179
180 delete l;
181
182 // delete all child widgets from this frame
183 QObjectList* list = const_cast<QObjectList*>( children() );
184 QObjectListIt it(*list);
185 QObject* obj;
186 while ( (obj=it.current()) )
187 {
188 ++it;
189 delete obj;
190 }
191
192 list = const_cast<QObjectList*>( children() );
193 if ( list )
194 qWarning( "D'oh! We still have %d children...", list->count() );
195
196 // renew layout
197 l = new QVBoxLayout( this, 4, 2 );
198 resize( 0, 0 );
199}
200
201
202QSize NetworkAppletControl::sizeHint() const
203{
204 ONetwork::instance()->synchronize(); // rebuild interface database
205 qDebug( "sizeHint (#ifaces=%d)", ONetwork::instance()->count() );
206 return QSize( 14+35+105+14 + 8, ONetwork::instance()->count() * 26 );
207}
208
209
210NetworkApplet::NetworkApplet( QWidget *parent, const char *name )
211 :OTaskbarApplet( parent, name )
212{
213 _control = new NetworkAppletControl( this, "control" );
214}
215
216
217NetworkApplet::~NetworkApplet()
218{
219}
220
221
222int NetworkApplet::position()
223{
224 return 4;
225}
226
227
228void NetworkApplet::paintEvent( QPaintEvent* )
229{
230 QPainter p(this);
231 p.drawPixmap(0, 2, Resource::loadPixmap( "networkapplet/network" ) );
232}
233
234
235void NetworkApplet::mousePressEvent( QMouseEvent* )
236{
237 if ( !_control->isVisible() )
238 {
239 popup( _control );
240 }
241 else
242 {
243 _control->hide();
244 }
245}
246
247
248Q_EXPORT_INTERFACE()
249{
250 Q_CREATE_INSTANCE( OTaskbarAppletWrapper<NetworkApplet> );
251}
252
diff --git a/noncore/applets/networkapplet/networkapplet.h b/noncore/applets/networkapplet/networkapplet.h
new file mode 100644
index 0000000..7b5fa97
--- a/dev/null
+++ b/noncore/applets/networkapplet/networkapplet.h
@@ -0,0 +1,112 @@
1/*
2                 This file is part of the Opie Project
3
4 =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 .=l.
6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details.
21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28
29*/
30
31#ifndef NETWORKAPPLET_H
32#define NETWORKAPPLET_H
33
34#include <opie2/otaskbarapplet.h>
35#include <qframe.h>
36#include <qstring.h>
37#include <qtoolbutton.h>
38#include <qlineedit.h>
39
40class ONetworkInterface;
41class QShowEvent;
42class QHideEvent;
43class QVBoxLayout;
44
45class IfaceUpDownButton : public QToolButton
46{
47 Q_OBJECT
48
49 public:
50 IfaceUpDownButton( QWidget* parent, const char* name );
51 virtual ~IfaceUpDownButton();
52
53 public slots:
54 virtual void clicked();
55
56 private:
57 ONetworkInterface* _iface;
58};
59
60
61class IfaceIPAddress : public QLineEdit
62{
63 Q_OBJECT
64
65 public:
66 IfaceIPAddress( QWidget* parent, const char* name );
67 virtual ~IfaceIPAddress();
68
69 public slots:
70 virtual void returnPressed();
71
72 private:
73 ONetworkInterface* _iface;
74};
75
76class NetworkAppletControl : public QFrame
77{
78 public:
79 NetworkAppletControl( OTaskbarApplet* parent, const char* name = 0 );
80 ~NetworkAppletControl();
81
82 virtual QSize sizeHint() const;
83
84 protected:
85 virtual void showEvent( QShowEvent* );
86 virtual void hideEvent( QHideEvent* );
87 QString guessDevice( ONetworkInterface* iface );
88 void build();
89
90 private:
91 QVBoxLayout* l;
92
93};
94
95
96class NetworkApplet : public OTaskbarApplet
97{
98 public:
99 NetworkApplet( QWidget* parent = 0, const char* name = 0 );
100 ~NetworkApplet();
101
102 static int position();
103 protected:
104 virtual void paintEvent( QPaintEvent* );
105 virtual void mousePressEvent( QMouseEvent* );
106
107 private:
108 NetworkAppletControl* _control;
109};
110
111#endif
112
diff --git a/noncore/applets/networkapplet/networkapplet.pro b/noncore/applets/networkapplet/networkapplet.pro
new file mode 100644
index 0000000..ec58455
--- a/dev/null
+++ b/noncore/applets/networkapplet/networkapplet.pro
@@ -0,0 +1,15 @@
1TEMPLATE = lib
2CONFIG += qt warn_on release
3HEADERS = networkapplet.h
4SOURCES = networkapplet.cpp
5TARGET = networkapplet
6DESTDIR = $(OPIEDIR)/plugins/applets
7INCLUDEPATH += $(OPIEDIR)/include
8DEPENDPATH += $(OPIEDIR)/include
9LIBS += -lqpe -lopiecore2 -lopieui2 -lopienet2
10VERSION = 0.1.0
11MOC_DIR = moc
12OBJECTS_DIR = obj
13
14
15include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/applets/networkapplet/opie-networkapplet.control b/noncore/applets/networkapplet/opie-networkapplet.control
new file mode 100644
index 0000000..f3d1ae7
--- a/dev/null
+++ b/noncore/applets/networkapplet/opie-networkapplet.control
@@ -0,0 +1,9 @@
1Files: plugins/applets/libnetworkapplet.so*
2Priority: optional
3Section: opie/system
4Maintainer: Michael 'Mickey' Lauer <mickeyl@handhelds.org>
5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION
7Depends: opie-base, libopie2 (1.8.1), opie-networksettings
8Description: Network Applet
9 A taskbar applet for controlling network interfaces
diff --git a/noncore/applets/networkapplet/opie-networkapplet.postinst b/noncore/applets/networkapplet/opie-networkapplet.postinst
new file mode 100755
index 0000000..a549c30
--- a/dev/null
+++ b/noncore/applets/networkapplet/opie-networkapplet.postinst
@@ -0,0 +1,6 @@
1#!/bin/sh
2if pidof -s qpe >/dev/null; then
3 /opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadApplets()"
4else
5 exit 0
6fi
diff --git a/noncore/applets/networkapplet/opie-networkapplet.postrm b/noncore/applets/networkapplet/opie-networkapplet.postrm
new file mode 100755
index 0000000..ba76ffa
--- a/dev/null
+++ b/noncore/applets/networkapplet/opie-networkapplet.postrm
@@ -0,0 +1,2 @@
1#!/bin/sh
2/opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadApplets()"