author | harlekin <harlekin> | 2002-05-18 21:55:22 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-05-18 21:55:22 (UTC) |
commit | be9add24a65c8ad89bc5425aa4d42c4b598a50be (patch) (unidiff) | |
tree | 1ba0f046ef932b6f72c08a35f5e99073ebf031b9 | |
parent | 1d935738d89d038e05013d8d099bcf4da14073ea (diff) | |
download | opie-be9add24a65c8ad89bc5425aa4d42c4b598a50be.zip opie-be9add24a65c8ad89bc5425aa4d42c4b598a50be.tar.gz opie-be9add24a65c8ad89bc5425aa4d42c4b598a50be.tar.bz2 |
patch by Daniel Foster <daniel-l@34SP.com>
-rw-r--r-- | core/applets/irdaapplet/irda.cpp | 64 | ||||
-rw-r--r-- | core/applets/irdaapplet/irda.h | 5 |
2 files changed, 61 insertions, 8 deletions
diff --git a/core/applets/irdaapplet/irda.cpp b/core/applets/irdaapplet/irda.cpp index 2eff2a9..a197957 100644 --- a/core/applets/irdaapplet/irda.cpp +++ b/core/applets/irdaapplet/irda.cpp | |||
@@ -1,159 +1,207 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2002 David Woodhouse <dwmw2@infradead.org> | 2 | ** Copyright (C) 2002 David Woodhouse <dwmw2@infradead.org> |
3 | ** Heavily based on volumeapplet, (C) 2002 L.J. Potter ljp@llornkcor.com | 3 | ** Heavily based on volumeapplet, (C) 2002 L.J. Potter ljp@llornkcor.com |
4 | ** All rights reserved. | 4 | ** All rights reserved. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #include "irda.h" | 16 | #include "irda.h" |
17 | #include <qapplication.h> | 17 | #include <qapplication.h> |
18 | #include <stdlib.h> | 18 | #include <stdlib.h> |
19 | 19 | ||
20 | 20 | ||
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
23 | #include <qpe/timestring.h> | 23 | #include <qpe/timestring.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | #include <qpe/config.h> | 25 | #include <qpe/config.h> |
26 | #include <qpe/applnk.h> | 26 | #include <qpe/applnk.h> |
27 | #include <qpe/config.h> | 27 | #include <qpe/config.h> |
28 | 28 | ||
29 | #include <qdir.h> | 29 | #include <qdir.h> |
30 | #include <qfileinfo.h> | 30 | #include <qfileinfo.h> |
31 | #include <qpoint.h> | 31 | #include <qpoint.h> |
32 | #include <qpushbutton.h> | 32 | #include <qpushbutton.h> |
33 | #include <qpainter.h> | 33 | #include <qpainter.h> |
34 | #include <qcombobox.h> | 34 | #include <qcombobox.h> |
35 | #include <qspinbox.h> | 35 | #include <qspinbox.h> |
36 | #include <qslider.h> | 36 | #include <qslider.h> |
37 | #include <qlayout.h> | 37 | #include <qlayout.h> |
38 | #include <qframe.h> | 38 | #include <qframe.h> |
39 | #include <qpixmap.h> | 39 | #include <qpixmap.h> |
40 | #include <qstring.h> | 40 | #include <qstring.h> |
41 | #include <qfile.h> | 41 | #include <qfile.h> |
42 | #include <qtimer.h> | 42 | #include <qtimer.h> |
43 | #include <qpopupmenu.h> | 43 | #include <qpopupmenu.h> |
44 | 44 | ||
45 | #include <net/if.h> | 45 | #include <net/if.h> |
46 | #include <netinet/in.h> | 46 | #include <netinet/in.h> |
47 | #include <sys/types.h> | 47 | #include <sys/types.h> |
48 | #include <sys/socket.h> | 48 | #include <sys/socket.h> |
49 | #include <sys/ioctl.h> | 49 | #include <sys/ioctl.h> |
50 | 50 | ||
51 | 51 | ||
52 | //=========================================================================== | 52 | //=========================================================================== |
53 | 53 | ||
54 | IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) | 54 | IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) |
55 | : QWidget( parent, name ) | 55 | : QWidget( parent, name ) |
56 | { | 56 | { |
57 | setFixedHeight( 18 ); | 57 | setFixedHeight( 18 ); |
58 | setFixedWidth( 14 ); | 58 | setFixedWidth( 14 ); |
59 | sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); | 59 | sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); |
60 | irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); | 60 | irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); |
61 | irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); | 61 | irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); |
62 | irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" ); | ||
62 | startTimer(5000); | 63 | startTimer(5000); |
63 | timerEvent(NULL); | 64 | timerEvent(NULL); |
64 | } | 65 | } |
65 | 66 | ||
66 | IrdaApplet::~IrdaApplet() | 67 | IrdaApplet::~IrdaApplet() |
67 | { | 68 | { |
68 | close(sockfd); | 69 | close(sockfd); |
69 | } | 70 | } |
70 | 71 | ||
71 | int IrdaApplet::checkIrdaStatus() | 72 | int IrdaApplet::checkIrdaStatus() |
72 | { | 73 | { |
73 | struct ifreq ifr; | 74 | struct ifreq ifr; |
74 | 75 | ||
75 | strcpy(ifr.ifr_name, "irda0"); | 76 | strcpy(ifr.ifr_name, "irda0"); |
76 | 77 | ||
77 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) | 78 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) |
78 | return -1; | 79 | return -1; |
79 | 80 | ||
80 | return (ifr.ifr_flags & IFF_UP)?1:0; | 81 | return (ifr.ifr_flags & IFF_UP)?1:0; |
81 | } | 82 | } |
82 | 83 | ||
83 | int IrdaApplet::setIrdaStatus(int c) | 84 | int IrdaApplet::setIrdaStatus(int c) |
84 | { | 85 | { |
85 | struct ifreq ifr; | 86 | struct ifreq ifr; |
86 | 87 | ||
87 | strcpy(ifr.ifr_name, "irda0"); | 88 | strcpy(ifr.ifr_name, "irda0"); |
88 | 89 | ||
89 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) | 90 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) |
90 | return -1; | 91 | return -1; |
91 | 92 | ||
92 | if (c) | 93 | if (c) |
93 | ifr.ifr_flags |= IFF_UP; | 94 | ifr.ifr_flags |= IFF_UP; |
94 | else | 95 | else |
95 | ifr.ifr_flags &= ~IFF_UP; | 96 | ifr.ifr_flags &= ~IFF_UP; |
96 | 97 | ||
97 | if (ioctl(sockfd, SIOCSIFFLAGS, &ifr)) | 98 | if (ioctl(sockfd, SIOCSIFFLAGS, &ifr)) |
98 | return -1; | 99 | return -1; |
99 | 100 | ||
100 | return 0; | 101 | return 0; |
101 | } | 102 | } |
102 | 103 | ||
104 | int IrdaApplet::checkIrdaDiscoveryStatus() | ||
105 | { | ||
106 | QFile discovery("/proc/sys/net/irda/discovery"); | ||
107 | char status; | ||
108 | |||
109 | discovery.open( IO_ReadOnly|IO_Raw ); | ||
110 | discovery.readBlock (&status, 1); | ||
111 | discovery.close(); | ||
112 | |||
113 | return atoi(&status); | ||
114 | } | ||
115 | |||
116 | int IrdaApplet::setIrdaDiscoveryStatus(int d) | ||
117 | { | ||
118 | QFile discovery("/proc/sys/net/irda/discovery"); | ||
119 | |||
120 | discovery.open( IO_WriteOnly|IO_Raw ); | ||
121 | |||
122 | if (d) | ||
123 | discovery.putch('1'); | ||
124 | else | ||
125 | discovery.putch('0'); | ||
126 | |||
127 | discovery.close(); | ||
128 | |||
129 | return 0; | ||
130 | } | ||
131 | |||
103 | void IrdaApplet::mousePressEvent( QMouseEvent *) | 132 | void IrdaApplet::mousePressEvent( QMouseEvent *) |
104 | { | 133 | { |
105 | QPopupMenu *menu = new QPopupMenu(); | 134 | QPopupMenu *menu = new QPopupMenu(); |
106 | QString cmd; | 135 | QString cmd; |
107 | int ret=0; | 136 | int ret=0; |
108 | 137 | ||
109 | /* Refresh active state */ | 138 | /* Refresh active state */ |
110 | timerEvent(NULL); | 139 | timerEvent(NULL); |
111 | 140 | ||
112 | //menu->insertItem( tr("More..."), 2 ); | 141 | //menu->insertItem( tr("More..."), 4 ); |
113 | if (irdaactive) | 142 | if (irdaactive) |
114 | menu->insertItem( tr("Disable IrDA"), 0 ); | 143 | menu->insertItem( tr("Disable IrDA"), 0 ); |
115 | else | 144 | else |
116 | menu->insertItem( tr("Enable IrDA"), 1 ); | 145 | menu->insertItem( tr("Enable IrDA"), 1 ); |
117 | 146 | ||
147 | if (irdaDiscoveryActive) | ||
148 | menu->insertItem( tr("Disable Discovery"), 2 ); | ||
149 | else | ||
150 | menu->insertItem( tr("Enable Discovery"), 3 ); | ||
151 | |||
118 | QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); | 152 | QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); |
119 | ret = menu->exec(p, 1); | 153 | ret = menu->exec(p, 2); |
120 | 154 | ||
121 | qDebug("ret was %d\n", ret); | 155 | qDebug("ret was %d\n", ret); |
122 | 156 | ||
123 | switch(ret) { | 157 | switch(ret) { |
124 | case 0: | 158 | case 0: |
125 | setIrdaStatus(0); | 159 | setIrdaStatus(0); |
126 | timerEvent(NULL); | 160 | timerEvent(NULL); |
127 | break; | 161 | break; |
128 | case 1: | 162 | case 1: |
129 | setIrdaStatus(1); | 163 | setIrdaStatus(1); |
130 | timerEvent(NULL); | 164 | timerEvent(NULL); |
131 | break; | 165 | break; |
132 | case 2: | 166 | case 2: |
167 | setIrdaDiscoveryStatus(0); | ||
168 | timerEvent(NULL); | ||
169 | break; | ||
170 | case 3: | ||
171 | setIrdaDiscoveryStatus(1); | ||
172 | timerEvent(NULL); | ||
173 | break; | ||
174 | case 4: | ||
133 | qDebug("FIXME: Bring up pretty menu...\n"); | 175 | qDebug("FIXME: Bring up pretty menu...\n"); |
134 | // With 'discovery' button to enable/disable, | 176 | // With table of currently-detected devices. |
135 | // and table of currently-detected devices. | ||
136 | } | 177 | } |
137 | 178 | ||
138 | } | 179 | } |
139 | 180 | ||
140 | void IrdaApplet::timerEvent( QTimerEvent * ) | 181 | void IrdaApplet::timerEvent( QTimerEvent * ) |
141 | { | 182 | { |
142 | int oldactive = irdaactive; | 183 | int oldactive = irdaactive; |
184 | int olddiscovery = irdaDiscoveryActive; | ||
143 | 185 | ||
144 | irdaactive = checkIrdaStatus(); | 186 | irdaactive = checkIrdaStatus(); |
145 | if (irdaactive != oldactive) | 187 | irdaDiscoveryActive = checkIrdaDiscoveryStatus(); |
188 | |||
189 | if ((irdaactive != oldactive) || (irdaDiscoveryActive != olddiscovery)) | ||
146 | paintEvent(NULL); | 190 | paintEvent(NULL); |
147 | 191 | ||
148 | } | 192 | } |
149 | 193 | ||
150 | void IrdaApplet::paintEvent( QPaintEvent* ) | 194 | void IrdaApplet::paintEvent( QPaintEvent* ) |
151 | { | 195 | { |
152 | QPainter p(this); | 196 | QPainter p(this); |
153 | qDebug("paint irda pixmap"); | 197 | qDebug("paint irda pixmap"); |
154 | 198 | ||
199 | p.eraseRect ( 0, 0, this->width(), this->height() ); | ||
155 | if (irdaactive > 0) | 200 | if (irdaactive > 0) |
156 | p.drawPixmap( 0, 1, irdaOnPixmap ); | 201 | p.drawPixmap( 0, 1, irdaOnPixmap ); |
157 | else | 202 | else |
158 | p.drawPixmap( 0, 1, irdaOffPixmap ); | 203 | p.drawPixmap( 0, 1, irdaOffPixmap ); |
204 | |||
205 | if (irdaDiscoveryActive > 0) | ||
206 | p.drawPixmap( 0, 1, irdaDiscoveryOnPixmap ); | ||
159 | } | 207 | } |
diff --git a/core/applets/irdaapplet/irda.h b/core/applets/irdaapplet/irda.h index d762ff3..2f84909 100644 --- a/core/applets/irdaapplet/irda.h +++ b/core/applets/irdaapplet/irda.h | |||
@@ -1,57 +1,62 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2002 L.J. Potter ljp@llornkcor.com | 2 | ** Copyright (C) 2002 L.J. Potter ljp@llornkcor.com |
3 | ** All rights reserved. | 3 | ** All rights reserved. |
4 | ** | 4 | ** |
5 | ** This file may be distributed and/or modified under the terms of the | 5 | ** This file may be distributed and/or modified under the terms of the |
6 | ** GNU General Public License version 2 as published by the Free Software | 6 | ** GNU General Public License version 2 as published by the Free Software |
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 7 | ** Foundation and appearing in the file LICENSE.GPL included in the |
8 | ** packaging of this file. | 8 | ** packaging of this file. |
9 | ** | 9 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
12 | ** | 12 | ** |
13 | **********************************************************************/ | 13 | **********************************************************************/ |
14 | 14 | ||
15 | #ifndef __SCREENSHOT_APPLET_H__ | 15 | #ifndef __SCREENSHOT_APPLET_H__ |
16 | #define __SCREENSHOT_APPLET_H__ | 16 | #define __SCREENSHOT_APPLET_H__ |
17 | 17 | ||
18 | 18 | ||
19 | 19 | ||
20 | #include <qwidget.h> | 20 | #include <qwidget.h> |
21 | #include <qframe.h> | 21 | #include <qframe.h> |
22 | #include <qpixmap.h> | 22 | #include <qpixmap.h> |
23 | #include <qguardedptr.h> | 23 | #include <qguardedptr.h> |
24 | #include <qtimer.h> | 24 | #include <qtimer.h> |
25 | #include <qfile.h> | ||
25 | 26 | ||
26 | 27 | ||
27 | class IrdaApplet : public QWidget | 28 | class IrdaApplet : public QWidget |
28 | { | 29 | { |
29 | Q_OBJECT | 30 | Q_OBJECT |
30 | public: | 31 | public: |
31 | IrdaApplet( QWidget *parent = 0, const char *name=0 ); | 32 | IrdaApplet( QWidget *parent = 0, const char *name=0 ); |
32 | ~IrdaApplet(); | 33 | ~IrdaApplet(); |
33 | 34 | ||
34 | protected: | 35 | protected: |
35 | void timerEvent(QTimerEvent *te ); | 36 | void timerEvent(QTimerEvent *te ); |
36 | 37 | ||
37 | public slots: | 38 | public slots: |
38 | private: | 39 | private: |
39 | void mousePressEvent( QMouseEvent * ); | 40 | void mousePressEvent( QMouseEvent * ); |
40 | void paintEvent( QPaintEvent* ); | 41 | void paintEvent( QPaintEvent* ); |
41 | int checkIrdaStatus(); | 42 | int checkIrdaStatus(); |
42 | int setIrdaStatus(int); | 43 | int setIrdaStatus(int); |
44 | int checkIrdaDiscoveryStatus(); | ||
45 | int setIrdaDiscoveryStatus(int); | ||
43 | int sockfd; | 46 | int sockfd; |
44 | 47 | ||
45 | private: | 48 | private: |
46 | QPixmap irdaOnPixmap; | 49 | QPixmap irdaOnPixmap; |
47 | QPixmap irdaOffPixmap; | 50 | QPixmap irdaOffPixmap; |
51 | QPixmap irdaDiscoveryOnPixmap; | ||
48 | int irdaactive; | 52 | int irdaactive; |
53 | int irdaDiscoveryActive; | ||
49 | 54 | ||
50 | private slots: | 55 | private slots: |
51 | 56 | ||
52 | 57 | ||
53 | }; | 58 | }; |
54 | 59 | ||
55 | 60 | ||
56 | #endif // __SCREENSHOT_APPLET_H__ | 61 | #endif // __SCREENSHOT_APPLET_H__ |
57 | 62 | ||