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