-rw-r--r-- | core/applets/irdaapplet/irda.cpp | 8 | ||||
-rw-r--r-- | core/applets/irdaapplet/irda.h | 2 |
2 files changed, 5 insertions, 5 deletions
diff --git a/core/applets/irdaapplet/irda.cpp b/core/applets/irdaapplet/irda.cpp index 03912aa..28a79d1 100644 --- a/core/applets/irdaapplet/irda.cpp +++ b/core/applets/irdaapplet/irda.cpp | |||
@@ -1,239 +1,239 @@ | |||
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 | #include <qpe/ir.h> | 28 | #include <qpe/ir.h> |
29 | #include <qpe/qcopenvelope_qws.h> | 29 | #include <qpe/qcopenvelope_qws.h> |
30 | 30 | ||
31 | #include <qdir.h> | 31 | #include <qdir.h> |
32 | #include <qfileinfo.h> | 32 | #include <qfileinfo.h> |
33 | #include <qpoint.h> | 33 | #include <qpoint.h> |
34 | #include <qpushbutton.h> | 34 | #include <qpushbutton.h> |
35 | #include <qpainter.h> | 35 | #include <qpainter.h> |
36 | #include <qcombobox.h> | 36 | #include <qcombobox.h> |
37 | #include <qspinbox.h> | 37 | #include <qspinbox.h> |
38 | #include <qslider.h> | 38 | #include <qslider.h> |
39 | #include <qlayout.h> | 39 | #include <qlayout.h> |
40 | #include <qframe.h> | 40 | #include <qframe.h> |
41 | #include <qpixmap.h> | 41 | #include <qpixmap.h> |
42 | #include <qstring.h> | 42 | #include <qstring.h> |
43 | #include <qfile.h> | 43 | #include <qfile.h> |
44 | #include <qtimer.h> | 44 | #include <qtimer.h> |
45 | #include <qpopupmenu.h> | 45 | #include <qpopupmenu.h> |
46 | 46 | ||
47 | #include <net/if.h> | 47 | #include <net/if.h> |
48 | #include <netinet/in.h> | 48 | #include <netinet/in.h> |
49 | #include <sys/types.h> | 49 | #include <sys/types.h> |
50 | #include <sys/socket.h> | 50 | #include <sys/socket.h> |
51 | #include <sys/ioctl.h> | 51 | #include <sys/ioctl.h> |
52 | 52 | ||
53 | 53 | ||
54 | //=========================================================================== | 54 | //=========================================================================== |
55 | 55 | ||
56 | IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) | 56 | IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) |
57 | : QWidget( parent, name ) { | 57 | : QWidget( parent, name ) { |
58 | setFixedHeight( 18 ); | 58 | setFixedHeight( 18 ); |
59 | setFixedWidth( 14 ); | 59 | setFixedWidth( 14 ); |
60 | sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); | 60 | sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); |
61 | irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); | 61 | irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); |
62 | irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); | 62 | irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); |
63 | irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" ); | 63 | irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" ); |
64 | receiveActivePixmap = Resource::loadPixmap("irdaapplet/receive"); | 64 | receiveActivePixmap = Resource::loadPixmap("irdaapplet/receive"); |
65 | receiveActive = false; | 65 | receiveActive = false; |
66 | startTimer(5000); | 66 | startTimer(5000); |
67 | timerEvent(NULL); | 67 | timerEvent(NULL); |
68 | } | 68 | } |
69 | 69 | ||
70 | IrdaApplet::~IrdaApplet() { | 70 | IrdaApplet::~IrdaApplet() { |
71 | close(sockfd); | 71 | close(sockfd); |
72 | } | 72 | } |
73 | 73 | ||
74 | int IrdaApplet::checkIrdaStatus() { | 74 | int IrdaApplet::checkIrdaStatus() { |
75 | struct ifreq ifr; | 75 | struct ifreq ifr; |
76 | 76 | ||
77 | strcpy(ifr.ifr_name, "irda0"); | 77 | strcpy(ifr.ifr_name, "irda0"); |
78 | 78 | ||
79 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) | 79 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) |
80 | return -1; | 80 | return -1; |
81 | 81 | ||
82 | return (ifr.ifr_flags & IFF_UP)?1:0; | 82 | return (ifr.ifr_flags & IFF_UP)?1:0; |
83 | } | 83 | } |
84 | 84 | ||
85 | int IrdaApplet::setIrdaStatus(int c) { | 85 | int IrdaApplet::setIrdaStatus(int c) { |
86 | struct ifreq ifr; | 86 | struct ifreq ifr; |
87 | 87 | ||
88 | strcpy(ifr.ifr_name, "irda0"); | 88 | strcpy(ifr.ifr_name, "irda0"); |
89 | 89 | ||
90 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) | 90 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) |
91 | return -1; | 91 | return -1; |
92 | 92 | ||
93 | if (c) | 93 | if (c) |
94 | ifr.ifr_flags |= IFF_UP; | 94 | ifr.ifr_flags |= IFF_UP; |
95 | else | 95 | else |
96 | ifr.ifr_flags &= ~IFF_UP; | 96 | ifr.ifr_flags &= ~IFF_UP; |
97 | 97 | ||
98 | if (ioctl(sockfd, SIOCSIFFLAGS, &ifr)) | 98 | if (ioctl(sockfd, SIOCSIFFLAGS, &ifr)) |
99 | return -1; | 99 | return -1; |
100 | 100 | ||
101 | return 0; | 101 | return 0; |
102 | } | 102 | } |
103 | 103 | ||
104 | int IrdaApplet::checkIrdaDiscoveryStatus() { | 104 | int IrdaApplet::checkIrdaDiscoveryStatus() { |
105 | QFile discovery("/proc/sys/net/irda/discovery"); | 105 | QFile discovery("/proc/sys/net/irda/discovery"); |
106 | char status; | 106 | char status; |
107 | 107 | ||
108 | discovery.open( IO_ReadOnly|IO_Raw ); | 108 | discovery.open( IO_ReadOnly|IO_Raw ); |
109 | discovery.readBlock (&status, 1); | 109 | discovery.readBlock (&status, 1); |
110 | discovery.close(); | 110 | discovery.close(); |
111 | 111 | ||
112 | return atoi(&status); | 112 | return atoi(&status); |
113 | } | 113 | } |
114 | 114 | ||
115 | int IrdaApplet::setIrdaDiscoveryStatus(int d) { | 115 | int IrdaApplet::setIrdaDiscoveryStatus(int d) { |
116 | QFile discovery("/proc/sys/net/irda/discovery"); | 116 | QFile discovery("/proc/sys/net/irda/discovery"); |
117 | 117 | ||
118 | discovery.open( IO_WriteOnly|IO_Raw ); | 118 | discovery.open( IO_WriteOnly|IO_Raw ); |
119 | 119 | ||
120 | if (d) | 120 | if (d) |
121 | discovery.putch('1'); | 121 | discovery.putch('1'); |
122 | else | 122 | else |
123 | discovery.putch('0'); | 123 | discovery.putch('0'); |
124 | 124 | ||
125 | discovery.close(); | 125 | discovery.close(); |
126 | 126 | ||
127 | return 0; | 127 | return 0; |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
131 | void IrdaApplet::mousePressEvent( QMouseEvent *) { | 131 | void IrdaApplet::mousePressEvent( QMouseEvent *) { |
132 | QPopupMenu *menu = new QPopupMenu(); | 132 | QPopupMenu *menu = new QPopupMenu(); |
133 | QString cmd; | 133 | QString cmd; |
134 | int ret=0; | 134 | int ret=0; |
135 | 135 | ||
136 | /* Refresh active state */ | 136 | /* Refresh active state */ |
137 | timerEvent(NULL); | 137 | timerEvent(NULL); |
138 | 138 | ||
139 | //menu->insertItem( tr("More..."), 4 ); | 139 | //menu->insertItem( tr("More..."), 4 ); |
140 | if (irdaactive) | 140 | if (irdaactive) |
141 | menu->insertItem( tr("Disable IrDA"), 0 ); | 141 | menu->insertItem( tr("Disable IrDA"), 0 ); |
142 | else | 142 | else |
143 | menu->insertItem( tr("Enable IrDA"), 1 ); | 143 | menu->insertItem( tr("Enable IrDA"), 1 ); |
144 | 144 | ||
145 | if (irdaDiscoveryActive) | 145 | if (irdaDiscoveryActive) |
146 | menu->insertItem( tr("Disable Discovery"), 2 ); | 146 | menu->insertItem( tr("Disable Discovery"), 2 ); |
147 | else | 147 | else |
148 | menu->insertItem( tr("Enable Discovery"), 3 ); | 148 | menu->insertItem( tr("Enable Discovery"), 3 ); |
149 | 149 | ||
150 | if( receiveActive ){ | 150 | if( receiveActive ){ |
151 | menu->insertItem( tr("Disable Receive"), 5 ); | 151 | menu->insertItem( tr("Disable Receive"), 5 ); |
152 | } else { | 152 | } else { |
153 | menu->insertItem( tr("Enable Receive"), 4 ); | 153 | menu->insertItem( tr("Enable Receive"), 4 ); |
154 | } | 154 | } |
155 | 155 | ||
156 | QPoint p = mapToGlobal( QPoint(1, menu->sizeHint().height()-1) ); | 156 | QPoint p = mapToGlobal( QPoint(1, menu->sizeHint().height()-1) ); |
157 | ret = menu->exec(p, 2); | 157 | ret = menu->exec(p, 2); |
158 | 158 | ||
159 | qDebug("ret was %d\n", ret); | 159 | qDebug("ret was %d\n", ret); |
160 | 160 | ||
161 | switch(ret) { | 161 | switch(ret) { |
162 | case 0: | 162 | case 0: |
163 | setIrdaStatus(0); | 163 | setIrdaStatus(0); |
164 | timerEvent(NULL); | 164 | timerEvent(NULL); |
165 | break; | 165 | break; |
166 | case 1: | 166 | case 1: |
167 | setIrdaStatus(1); | 167 | setIrdaStatus(1); |
168 | timerEvent(NULL); | 168 | timerEvent(NULL); |
169 | break; | 169 | break; |
170 | case 2: | 170 | case 2: |
171 | setIrdaDiscoveryStatus(0); | 171 | setIrdaDiscoveryStatus(0); |
172 | timerEvent(NULL); | 172 | timerEvent(NULL); |
173 | break; | 173 | break; |
174 | case 3: | 174 | case 3: |
175 | setIrdaDiscoveryStatus(1); | 175 | setIrdaDiscoveryStatus(1); |
176 | timerEvent(NULL); // NULL is undefined in c++ use 0 or 0l | 176 | timerEvent(NULL); // NULL is undefined in c++ use 0 or 0l |
177 | break; | 177 | break; |
178 | case 4: { // enable receive | 178 | case 4: { // enable receive |
179 | qWarning("Enable receive" ); | 179 | qWarning("Enable receive" ); |
180 | QCopEnvelope e("QPE/Obex", "receive(bool)" ); | 180 | QCopEnvelope e("QPE/Obex", "receive(int)" ); |
181 | e << true; | 181 | e << 1; |
182 | receiveActive = true; | 182 | receiveActive = true; |
183 | receiveStateChanged = true; | 183 | receiveStateChanged = true; |
184 | timerEvent(NULL); | 184 | timerEvent(NULL); |
185 | break; | 185 | break; |
186 | } | 186 | } |
187 | case 5: { // disable receive | 187 | case 5: { // disable receive |
188 | qWarning("Disable receive" ); | 188 | qWarning("Disable receive" ); |
189 | QCopEnvelope e("QPE/Obex", "receive(bool)" ); | 189 | QCopEnvelope e("QPE/Obex", "receive(int)" ); |
190 | e << false; | 190 | e << 0; |
191 | receiveActive = false; | 191 | receiveActive = false; |
192 | receiveStateChanged = true; | 192 | receiveStateChanged = true; |
193 | timerEvent(NULL); | 193 | timerEvent(NULL); |
194 | break; | 194 | break; |
195 | } | 195 | } |
196 | case 6: | 196 | case 6: |
197 | qDebug("FIXME: Bring up pretty menu...\n"); | 197 | qDebug("FIXME: Bring up pretty menu...\n"); |
198 | // With table of currently-detected devices. | 198 | // With table of currently-detected devices. |
199 | } | 199 | } |
200 | delete menu; // Can somebody explain why use a QPopupMenu* and not QPopupMenu nor QAction. with out delete we will leak cause QPopupMenu doesn't have a parent in this case | 200 | delete menu; // Can somebody explain why use a QPopupMenu* and not QPopupMenu nor QAction. with out delete we will leak cause QPopupMenu doesn't have a parent in this case |
201 | } | 201 | } |
202 | 202 | ||
203 | void IrdaApplet::timerEvent( QTimerEvent * ) { | 203 | void IrdaApplet::timerEvent( QTimerEvent * ) { |
204 | int oldactive = irdaactive; | 204 | int oldactive = irdaactive; |
205 | int olddiscovery = irdaDiscoveryActive; | 205 | int olddiscovery = irdaDiscoveryActive; |
206 | bool receiveUpdate = false; | 206 | bool receiveUpdate = false; |
207 | 207 | ||
208 | if (receiveStateChanged) { | 208 | if (receiveStateChanged) { |
209 | receiveUpdate = true; | 209 | receiveUpdate = true; |
210 | receiveStateChanged = false; | 210 | receiveStateChanged = false; |
211 | } | 211 | } |
212 | 212 | ||
213 | irdaactive = checkIrdaStatus(); | 213 | irdaactive = checkIrdaStatus(); |
214 | irdaDiscoveryActive = checkIrdaDiscoveryStatus(); | 214 | irdaDiscoveryActive = checkIrdaDiscoveryStatus(); |
215 | 215 | ||
216 | if ((irdaactive != oldactive) || (irdaDiscoveryActive != olddiscovery) || receiveUpdate ) { | 216 | if ((irdaactive != oldactive) || (irdaDiscoveryActive != olddiscovery) || receiveUpdate ) { |
217 | paintEvent(NULL); | 217 | paintEvent(NULL); |
218 | } | 218 | } |
219 | 219 | ||
220 | } | 220 | } |
221 | 221 | ||
222 | void IrdaApplet::paintEvent( QPaintEvent* ) { | 222 | void IrdaApplet::paintEvent( QPaintEvent* ) { |
223 | QPainter p(this); | 223 | QPainter p(this); |
224 | qDebug("paint irda pixmap"); | 224 | qDebug("paint irda pixmap"); |
225 | 225 | ||
226 | p.eraseRect ( 0, 0, this->width(), this->height() ); | 226 | p.eraseRect ( 0, 0, this->width(), this->height() ); |
227 | if (irdaactive > 0) { | 227 | if (irdaactive > 0) { |
228 | p.drawPixmap( 0, 1, irdaOnPixmap ); | 228 | p.drawPixmap( 0, 1, irdaOnPixmap ); |
229 | } else { | 229 | } else { |
230 | p.drawPixmap( 0, 1, irdaOffPixmap ); | 230 | p.drawPixmap( 0, 1, irdaOffPixmap ); |
231 | } | 231 | } |
232 | 232 | ||
233 | if (irdaDiscoveryActive > 0) { | 233 | if (irdaDiscoveryActive > 0) { |
234 | p.drawPixmap( 0, 1, irdaDiscoveryOnPixmap ); | 234 | p.drawPixmap( 0, 1, irdaDiscoveryOnPixmap ); |
235 | } | 235 | } |
236 | if (receiveActive) { | 236 | if (receiveActive) { |
237 | p.drawPixmap( 0, 1, receiveActivePixmap); | 237 | p.drawPixmap( 0, 1, receiveActivePixmap); |
238 | } | 238 | } |
239 | } | 239 | } |
diff --git a/core/applets/irdaapplet/irda.h b/core/applets/irdaapplet/irda.h index 97ca3c3..002d295 100644 --- a/core/applets/irdaapplet/irda.h +++ b/core/applets/irdaapplet/irda.h | |||
@@ -1,63 +1,63 @@ | |||
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 | #include <qfile.h> |
26 | 26 | ||
27 | 27 | ||
28 | class IrdaApplet : public QWidget | 28 | class IrdaApplet : public QWidget |
29 | { | 29 | { |
30 | Q_OBJECT | 30 | Q_OBJECT |
31 | public: | 31 | public: |
32 | IrdaApplet( QWidget *parent = 0, const char *name=0 ); | 32 | IrdaApplet( QWidget *parent = 0, const char *name=0 ); |
33 | ~IrdaApplet(); | 33 | ~IrdaApplet(); |
34 | 34 | ||
35 | protected: | 35 | protected: |
36 | void timerEvent(QTimerEvent *te ); | 36 | void timerEvent(QTimerEvent *te ); |
37 | 37 | ||
38 | private: | 38 | private: |
39 | void mousePressEvent( QMouseEvent * ); | 39 | void mousePressEvent( QMouseEvent * ); |
40 | void paintEvent( QPaintEvent* ); | 40 | void paintEvent( QPaintEvent* ); |
41 | int checkIrdaStatus(); | 41 | int checkIrdaStatus(); |
42 | int setIrdaStatus(int); | 42 | int setIrdaStatus(int); |
43 | int checkIrdaDiscoveryStatus(); | 43 | int checkIrdaDiscoveryStatus(); |
44 | int setIrdaDiscoveryStatus(int); | 44 | int setIrdaDiscoveryStatus(int); |
45 | int sockfd; | 45 | int sockfd; |
46 | 46 | ||
47 | private: | 47 | private: |
48 | QPixmap irdaOnPixmap; | 48 | QPixmap irdaOnPixmap; |
49 | QPixmap irdaOffPixmap; | 49 | QPixmap irdaOffPixmap; |
50 | QPixmap irdaDiscoveryOnPixmap; | 50 | QPixmap irdaDiscoveryOnPixmap; |
51 | QPixmap receiveActivePixmap; | 51 | QPixmap receiveActivePixmap; |
52 | int irdaactive; // bool and bitfields later bool irdaactive :1 ; | 52 | int irdaactive; // bool and bitfields later bool irdaactive :1 ; |
53 | int irdaDiscoveryActive; | 53 | int irdaDiscoveryActive; |
54 | bool receiveActive; | 54 | bool receiveActive : 1; |
55 | bool receiveStateChanged; | 55 | bool receiveStateChanged; |
56 | private slots: | 56 | private slots: |
57 | 57 | ||
58 | 58 | ||
59 | }; | 59 | }; |
60 | 60 | ||
61 | 61 | ||
62 | #endif // __SCREENSHOT_APPLET_H__ | 62 | #endif // __SCREENSHOT_APPLET_H__ |
63 | 63 | ||