author | mickeyl <mickeyl> | 2003-04-16 22:25:44 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-16 22:25:44 (UTC) |
commit | fb1101a35d081e47df547c01a645af59f4730969 (patch) (side-by-side diff) | |
tree | 0da82e9d4a8cefbf8146480be2d17b6ccc912e5d /noncore | |
parent | 0ac702419b3b8450b689e0ee2500f34b577f1a72 (diff) | |
download | opie-fb1101a35d081e47df547c01a645af59f4730969.zip opie-fb1101a35d081e47df547c01a645af59f4730969.tar.gz opie-fb1101a35d081e47df547c01a645af59f4730969.tar.bz2 |
introducing networkapplet - monolithic now, but at some point of time pluggable
long term plan: merge wirelessapplet with networkapplet
-rw-r--r-- | noncore/applets/networkapplet/.cvsignore | 5 | ||||
-rw-r--r-- | noncore/applets/networkapplet/config.in | 7 | ||||
-rw-r--r-- | noncore/applets/networkapplet/networkapplet.cpp | 252 | ||||
-rw-r--r-- | noncore/applets/networkapplet/networkapplet.h | 112 | ||||
-rw-r--r-- | noncore/applets/networkapplet/networkapplet.pro | 15 | ||||
-rw-r--r-- | noncore/applets/networkapplet/opie-networkapplet.control | 9 | ||||
-rwxr-xr-x | noncore/applets/networkapplet/opie-networkapplet.postinst | 6 | ||||
-rwxr-xr-x | noncore/applets/networkapplet/opie-networkapplet.postrm | 2 |
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 @@ +*.moc +*.~ +Makefile* +moc_* +opieobj 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 @@ + config NETWORKAPPLET + boolean "Network (control network interfaces on-the-fly)" + default "n" + depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2UI + comment "Network applet needs a libqpe and libopie2 (ui, net)" + depends !(( LIBQPE || LIBQPE-X11 ) && LIBOPIE2UI) + 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 @@ +/* + This file is part of the Opie Project + + =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + +*/ + +#include "networkapplet.h" +#include <opie2/otaskbarapplet.h> +#include <qpe/qlibrary.h> +#include <qpe/resource.h> +#include <qpainter.h> +#include <opie2/odebug.h> +#include <opie2/onetwork.h> + +#include <qpushbutton.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qlineedit.h> +#include <qtoolbutton.h> +#include <qhostaddress.h> +#include <qobjectlist.h> + +#include <assert.h> + +IfaceUpDownButton::IfaceUpDownButton( QWidget* parent, const char* name ) + :QToolButton( parent, name ) +{ + _iface = ONetwork::instance()->interface( name ); + assert( _iface ); + setToggleButton( true ); + //setAutoRaise( true ); + setOnIconSet( QIconSet( Resource::loadPixmap( "up" ) ) ); + setOffIconSet( QIconSet( Resource::loadPixmap( "down" ) ) ); + setOn( _iface->isUp() ); + //setFixedWidth( 16 ); + connect( this, SIGNAL( clicked() ), this, SLOT( clicked() ) ); +} + + +IfaceUpDownButton::~IfaceUpDownButton() +{ +} + + +void IfaceUpDownButton::clicked() +{ + _iface->setUp( isOn() ); + setOn( _iface->isUp() ); // it might not have worked... + repaint(); +} + + +IfaceIPAddress::IfaceIPAddress( QWidget* parent, const char* name ) + :QLineEdit( parent, name ) +{ + setFont( QFont( "fixed" ) ); + _iface = ONetwork::instance()->interface( name ); + setFixedWidth( 105 ); + setText( _iface->ipV4Address() ); + connect( this, SIGNAL( returnPressed() ), this, SLOT( returnPressed() ) ); +} + + +IfaceIPAddress::~IfaceIPAddress() +{ +} + + +void IfaceIPAddress::returnPressed() +{ + QHostAddress a; + a.setAddress( text() ); + QHostAddress mask; + mask.setAddress( _iface->ipV4Netmask() ); // setIPV4Address destroys the netmask... + _iface->setIPV4Address( a ); + _iface->setIPV4Netmask( mask ); // recover the old netmask + setText( _iface->ipV4Address() ); + repaint(); +} + + +NetworkAppletControl::NetworkAppletControl( OTaskbarApplet* parent, const char* name ) + :QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), l(0) +{ + setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); + l = new QVBoxLayout( this, 4, 2 ); +} + + +void NetworkAppletControl::build() +{ + ONetwork::InterfaceIterator it = ONetwork::instance()->iterator(); + while ( it.current() ) + { + QHBoxLayout* h = new QHBoxLayout( l ); + QLabel* symbol = new QLabel( this ); + symbol->setPixmap( Resource::loadPixmap( guessDevice( it.current() ) ) ); + h->addWidget( symbol ); + symbol->show(); + + QLabel* name = new QLabel( it.current()->name(), this ); + name->setFixedWidth( 35 ); + h->addWidget( name ); + name->show(); + + IfaceIPAddress* ip = new IfaceIPAddress( this, it.current()->name() ); + h->addWidget( ip ); + ip->show(); + + IfaceUpDownButton* tb = new IfaceUpDownButton( this, it.current()->name() ); + tb->show(); + + h->addWidget( tb ); + + ++it; + } +} + + +NetworkAppletControl::~NetworkAppletControl() +{ +} + + +QString NetworkAppletControl::guessDevice( ONetworkInterface* iface ) +{ + if ( iface->isWireless() ) + return "networksettings/wlan"; + if ( iface->isLoopback() ) + return "networksettings/lo"; + if ( QString( iface->name() ).contains( "usb" ) ) + return "networksettings/usb"; + if ( QString( iface->name() ).contains( "ir" ) ) + return "networksettings/ir"; + + //TODO: Insert neat symbol and check for tunnel devices + + return "networksettings/lan"; + +} + + +void NetworkAppletControl::showEvent( QShowEvent* e ) +{ + qDebug( "showEvent" ); + build(); + QWidget::showEvent( e ); +} + + +void NetworkAppletControl::hideEvent( QHideEvent* e ) +{ + qDebug( "hideEvent" ); + QWidget::hideEvent( e ); + + delete l; + + // delete all child widgets from this frame + QObjectList* list = const_cast<QObjectList*>( children() ); + QObjectListIt it(*list); + QObject* obj; + while ( (obj=it.current()) ) + { + ++it; + delete obj; + } + + list = const_cast<QObjectList*>( children() ); + if ( list ) + qWarning( "D'oh! We still have %d children...", list->count() ); + + // renew layout + l = new QVBoxLayout( this, 4, 2 ); + resize( 0, 0 ); +} + + +QSize NetworkAppletControl::sizeHint() const +{ + ONetwork::instance()->synchronize(); // rebuild interface database + qDebug( "sizeHint (#ifaces=%d)", ONetwork::instance()->count() ); + return QSize( 14+35+105+14 + 8, ONetwork::instance()->count() * 26 ); +} + + +NetworkApplet::NetworkApplet( QWidget *parent, const char *name ) + :OTaskbarApplet( parent, name ) +{ + _control = new NetworkAppletControl( this, "control" ); +} + + +NetworkApplet::~NetworkApplet() +{ +} + + +int NetworkApplet::position() +{ + return 4; +} + + +void NetworkApplet::paintEvent( QPaintEvent* ) +{ + QPainter p(this); + p.drawPixmap(0, 2, Resource::loadPixmap( "networkapplet/network" ) ); +} + + +void NetworkApplet::mousePressEvent( QMouseEvent* ) +{ + if ( !_control->isVisible() ) + { + popup( _control ); + } + else + { + _control->hide(); + } +} + + +Q_EXPORT_INTERFACE() +{ + Q_CREATE_INSTANCE( OTaskbarAppletWrapper<NetworkApplet> ); +} + 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 @@ +/* + This file is part of the Opie Project + + =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This program is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + +*/ + +#ifndef NETWORKAPPLET_H +#define NETWORKAPPLET_H + +#include <opie2/otaskbarapplet.h> +#include <qframe.h> +#include <qstring.h> +#include <qtoolbutton.h> +#include <qlineedit.h> + +class ONetworkInterface; +class QShowEvent; +class QHideEvent; +class QVBoxLayout; + +class IfaceUpDownButton : public QToolButton +{ + Q_OBJECT + + public: + IfaceUpDownButton( QWidget* parent, const char* name ); + virtual ~IfaceUpDownButton(); + + public slots: + virtual void clicked(); + + private: + ONetworkInterface* _iface; +}; + + +class IfaceIPAddress : public QLineEdit +{ + Q_OBJECT + + public: + IfaceIPAddress( QWidget* parent, const char* name ); + virtual ~IfaceIPAddress(); + + public slots: + virtual void returnPressed(); + + private: + ONetworkInterface* _iface; +}; + +class NetworkAppletControl : public QFrame +{ + public: + NetworkAppletControl( OTaskbarApplet* parent, const char* name = 0 ); + ~NetworkAppletControl(); + + virtual QSize sizeHint() const; + + protected: + virtual void showEvent( QShowEvent* ); + virtual void hideEvent( QHideEvent* ); + QString guessDevice( ONetworkInterface* iface ); + void build(); + + private: + QVBoxLayout* l; + +}; + + +class NetworkApplet : public OTaskbarApplet +{ + public: + NetworkApplet( QWidget* parent = 0, const char* name = 0 ); + ~NetworkApplet(); + + static int position(); + protected: + virtual void paintEvent( QPaintEvent* ); + virtual void mousePressEvent( QMouseEvent* ); + + private: + NetworkAppletControl* _control; +}; + +#endif + 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 @@ +TEMPLATE = lib +CONFIG += qt warn_on release +HEADERS = networkapplet.h +SOURCES = networkapplet.cpp +TARGET = networkapplet +DESTDIR = $(OPIEDIR)/plugins/applets +INCLUDEPATH += $(OPIEDIR)/include +DEPENDPATH += $(OPIEDIR)/include +LIBS += -lqpe -lopiecore2 -lopieui2 -lopienet2 +VERSION = 0.1.0 +MOC_DIR = moc +OBJECTS_DIR = obj + + +include ( $(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 @@ +Files: plugins/applets/libnetworkapplet.so* +Priority: optional +Section: opie/system +Maintainer: Michael 'Mickey' Lauer <mickeyl@handhelds.org> +Architecture: arm +Version: $QPE_VERSION-$SUB_VERSION +Depends: opie-base, libopie2 (1.8.1), opie-networksettings +Description: Network Applet + 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 @@ +#!/bin/sh +if pidof -s qpe >/dev/null; then + /opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadApplets()" +else + exit 0 +fi 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 @@ +#!/bin/sh +/opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadApplets()" |