author | harlekin <harlekin> | 2002-06-13 15:51:31 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-06-13 15:51:31 (UTC) |
commit | 6a178f4ad2c3a9b92224c3506165cf03df41202e (patch) (unidiff) | |
tree | 6c22acadb425cc5016cdbbbc3c537912c0ae894b | |
parent | 27fa818887ffe4fa13365674f5a1d7e4e2eac5fc (diff) | |
download | opie-6a178f4ad2c3a9b92224c3506165cf03df41202e.zip opie-6a178f4ad2c3a9b92224c3506165cf03df41202e.tar.gz opie-6a178f4ad2c3a9b92224c3506165cf03df41202e.tar.bz2 |
update
-rw-r--r-- | core/applets/irdaapplet/irda.cpp | 265 | ||||
-rw-r--r-- | core/applets/irdaapplet/irda.h | 6 |
2 files changed, 147 insertions, 124 deletions
diff --git a/core/applets/irdaapplet/irda.cpp b/core/applets/irdaapplet/irda.cpp index 67e7f22..03912aa 100644 --- a/core/applets/irdaapplet/irda.cpp +++ b/core/applets/irdaapplet/irda.cpp | |||
@@ -25,194 +25,215 @@ | |||
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 | { | 58 | setFixedHeight( 18 ); |
59 | setFixedHeight( 18 ); | 59 | setFixedWidth( 14 ); |
60 | setFixedWidth( 14 ); | 60 | sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); |
61 | sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); | 61 | irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); |
62 | irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); | 62 | irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); |
63 | irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); | 63 | irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" ); |
64 | irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" ); | 64 | receiveActivePixmap = Resource::loadPixmap("irdaapplet/receive"); |
65 | startTimer(5000); | 65 | receiveActive = false; |
66 | timerEvent(NULL); | 66 | startTimer(5000); |
67 | timerEvent(NULL); | ||
67 | } | 68 | } |
68 | 69 | ||
69 | IrdaApplet::~IrdaApplet() | 70 | IrdaApplet::~IrdaApplet() { |
70 | { | 71 | close(sockfd); |
71 | close(sockfd); | ||
72 | } | 72 | } |
73 | 73 | ||
74 | int IrdaApplet::checkIrdaStatus() | 74 | int IrdaApplet::checkIrdaStatus() { |
75 | { | 75 | struct ifreq ifr; |
76 | struct ifreq ifr; | ||
77 | 76 | ||
78 | strcpy(ifr.ifr_name, "irda0"); | 77 | strcpy(ifr.ifr_name, "irda0"); |
79 | 78 | ||
80 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) | 79 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) |
81 | return -1; | 80 | return -1; |
82 | 81 | ||
83 | return (ifr.ifr_flags & IFF_UP)?1:0; | 82 | return (ifr.ifr_flags & IFF_UP)?1:0; |
84 | } | 83 | } |
85 | 84 | ||
86 | int IrdaApplet::setIrdaStatus(int c) | 85 | int IrdaApplet::setIrdaStatus(int c) { |
87 | { | 86 | struct ifreq ifr; |
88 | struct ifreq ifr; | ||
89 | 87 | ||
90 | strcpy(ifr.ifr_name, "irda0"); | 88 | strcpy(ifr.ifr_name, "irda0"); |
91 | 89 | ||
92 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) | 90 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) |
93 | return -1; | 91 | return -1; |
94 | 92 | ||
95 | if (c) | 93 | if (c) |
96 | ifr.ifr_flags |= IFF_UP; | 94 | ifr.ifr_flags |= IFF_UP; |
97 | else | 95 | else |
98 | ifr.ifr_flags &= ~IFF_UP; | 96 | ifr.ifr_flags &= ~IFF_UP; |
99 | 97 | ||
100 | if (ioctl(sockfd, SIOCSIFFLAGS, &ifr)) | 98 | if (ioctl(sockfd, SIOCSIFFLAGS, &ifr)) |
101 | return -1; | 99 | return -1; |
102 | 100 | ||
103 | return 0; | 101 | return 0; |
104 | } | 102 | } |
105 | 103 | ||
106 | int IrdaApplet::checkIrdaDiscoveryStatus() | 104 | int IrdaApplet::checkIrdaDiscoveryStatus() { |
107 | { | 105 | QFile discovery("/proc/sys/net/irda/discovery"); |
108 | QFile discovery("/proc/sys/net/irda/discovery"); | 106 | char status; |
109 | char status; | ||
110 | 107 | ||
111 | discovery.open( IO_ReadOnly|IO_Raw ); | 108 | discovery.open( IO_ReadOnly|IO_Raw ); |
112 | discovery.readBlock (&status, 1); | 109 | discovery.readBlock (&status, 1); |
113 | discovery.close(); | 110 | discovery.close(); |
114 | 111 | ||
115 | return atoi(&status); | 112 | return atoi(&status); |
116 | } | 113 | } |
117 | 114 | ||
118 | int IrdaApplet::setIrdaDiscoveryStatus(int d) | 115 | int IrdaApplet::setIrdaDiscoveryStatus(int d) { |
119 | { | 116 | QFile discovery("/proc/sys/net/irda/discovery"); |
120 | QFile discovery("/proc/sys/net/irda/discovery"); | ||
121 | 117 | ||
122 | discovery.open( IO_WriteOnly|IO_Raw ); | 118 | discovery.open( IO_WriteOnly|IO_Raw ); |
123 | 119 | ||
124 | if (d) | 120 | if (d) |
125 | discovery.putch('1'); | 121 | discovery.putch('1'); |
126 | else | 122 | else |
127 | discovery.putch('0'); | 123 | discovery.putch('0'); |
128 | 124 | ||
129 | discovery.close(); | 125 | discovery.close(); |
130 | 126 | ||
131 | return 0; | 127 | return 0; |
132 | } | 128 | } |
133 | 129 | ||
134 | void IrdaApplet::mousePressEvent( QMouseEvent *) | ||
135 | { | ||
136 | QPopupMenu *menu = new QPopupMenu(); | ||
137 | QString cmd; | ||
138 | int ret=0; | ||
139 | 130 | ||
140 | /* Refresh active state */ | 131 | void IrdaApplet::mousePressEvent( QMouseEvent *) { |
141 | timerEvent(NULL); | 132 | QPopupMenu *menu = new QPopupMenu(); |
133 | QString cmd; | ||
134 | int ret=0; | ||
135 | |||
136 | /* Refresh active state */ | ||
137 | timerEvent(NULL); | ||
142 | 138 | ||
143 | //menu->insertItem( tr("More..."), 4 ); | 139 | //menu->insertItem( tr("More..."), 4 ); |
144 | if (irdaactive) | 140 | if (irdaactive) |
145 | menu->insertItem( tr("Disable IrDA"), 0 ); | 141 | menu->insertItem( tr("Disable IrDA"), 0 ); |
146 | else | 142 | else |
147 | menu->insertItem( tr("Enable IrDA"), 1 ); | 143 | menu->insertItem( tr("Enable IrDA"), 1 ); |
148 | 144 | ||
149 | if (irdaDiscoveryActive) | 145 | if (irdaDiscoveryActive) |
150 | menu->insertItem( tr("Disable Discovery"), 2 ); | 146 | menu->insertItem( tr("Disable Discovery"), 2 ); |
151 | else | 147 | else |
152 | menu->insertItem( tr("Enable Discovery"), 3 ); | 148 | menu->insertItem( tr("Enable Discovery"), 3 ); |
153 | 149 | ||
154 | if( Ir::supported() ){ | 150 | if( receiveActive ){ |
155 | menu->insertItem( tr("Enable Receive"), 4 ); | 151 | menu->insertItem( tr("Disable Receive"), 5 ); |
156 | } | 152 | } else { |
157 | QPoint p = mapToGlobal( QPoint(1, menu->sizeHint().height()-1) ); | 153 | menu->insertItem( tr("Enable Receive"), 4 ); |
158 | ret = menu->exec(p, 2); | 154 | } |
159 | 155 | ||
160 | qDebug("ret was %d\n", ret); | 156 | QPoint p = mapToGlobal( QPoint(1, menu->sizeHint().height()-1) ); |
161 | 157 | ret = menu->exec(p, 2); | |
162 | switch(ret) { | 158 | |
163 | case 0: | 159 | qDebug("ret was %d\n", ret); |
164 | setIrdaStatus(0); | 160 | |
165 | timerEvent(NULL); | 161 | switch(ret) { |
166 | break; | 162 | case 0: |
167 | case 1: | 163 | setIrdaStatus(0); |
168 | setIrdaStatus(1); | 164 | timerEvent(NULL); |
169 | timerEvent(NULL); | 165 | break; |
170 | break; | 166 | case 1: |
171 | case 2: | 167 | setIrdaStatus(1); |
172 | setIrdaDiscoveryStatus(0); | 168 | timerEvent(NULL); |
173 | timerEvent(NULL); | 169 | break; |
174 | break; | 170 | case 2: |
175 | case 3: | 171 | setIrdaDiscoveryStatus(0); |
176 | setIrdaDiscoveryStatus(1); | 172 | timerEvent(NULL); |
177 | timerEvent(NULL); // NULL is undefined in c++ use 0 or 0l | 173 | break; |
178 | break; | 174 | case 3: |
179 | case 4: { // enable receive{ | 175 | setIrdaDiscoveryStatus(1); |
180 | qWarning("Enable receive" ); | 176 | timerEvent(NULL); // NULL is undefined in c++ use 0 or 0l |
181 | QCopEnvelope e("QPE/Obex", "receive(bool)" ); | 177 | break; |
182 | e << true; | 178 | case 4: { // enable receive |
183 | break; | 179 | qWarning("Enable receive" ); |
184 | } | 180 | QCopEnvelope e("QPE/Obex", "receive(bool)" ); |
185 | case 6: | 181 | e << true; |
186 | qDebug("FIXME: Bring up pretty menu...\n"); | 182 | receiveActive = true; |
187 | // With table of currently-detected devices. | 183 | receiveStateChanged = true; |
188 | } | 184 | timerEvent(NULL); |
189 | 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 | 185 | break; |
186 | } | ||
187 | case 5: { // disable receive | ||
188 | qWarning("Disable receive" ); | ||
189 | QCopEnvelope e("QPE/Obex", "receive(bool)" ); | ||
190 | e << false; | ||
191 | receiveActive = false; | ||
192 | receiveStateChanged = true; | ||
193 | timerEvent(NULL); | ||
194 | break; | ||
195 | } | ||
196 | case 6: | ||
197 | qDebug("FIXME: Bring up pretty menu...\n"); | ||
198 | // With table of currently-detected devices. | ||
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 | ||
190 | } | 201 | } |
191 | 202 | ||
192 | void IrdaApplet::timerEvent( QTimerEvent * ) | 203 | void IrdaApplet::timerEvent( QTimerEvent * ) { |
193 | { | ||
194 | int oldactive = irdaactive; | 204 | int oldactive = irdaactive; |
195 | int olddiscovery = irdaDiscoveryActive; | 205 | int olddiscovery = irdaDiscoveryActive; |
206 | bool receiveUpdate = false; | ||
207 | |||
208 | if (receiveStateChanged) { | ||
209 | receiveUpdate = true; | ||
210 | receiveStateChanged = false; | ||
211 | } | ||
196 | 212 | ||
197 | irdaactive = checkIrdaStatus(); | 213 | irdaactive = checkIrdaStatus(); |
198 | irdaDiscoveryActive = checkIrdaDiscoveryStatus(); | 214 | irdaDiscoveryActive = checkIrdaDiscoveryStatus(); |
199 | 215 | ||
200 | if ((irdaactive != oldactive) || (irdaDiscoveryActive != olddiscovery)) | 216 | if ((irdaactive != oldactive) || (irdaDiscoveryActive != olddiscovery) || receiveUpdate ) { |
201 | paintEvent(NULL); | 217 | paintEvent(NULL); |
202 | 218 | } | |
203 | } | ||
204 | 219 | ||
205 | void IrdaApplet::paintEvent( QPaintEvent* ) | 220 | } |
206 | { | ||
207 | QPainter p(this); | ||
208 | qDebug("paint irda pixmap"); | ||
209 | |||
210 | p.eraseRect ( 0, 0, this->width(), this->height() ); | ||
211 | if (irdaactive > 0) | ||
212 | p.drawPixmap( 0, 1, irdaOnPixmap ); | ||
213 | else | ||
214 | p.drawPixmap( 0, 1, irdaOffPixmap ); | ||
215 | 221 | ||
216 | if (irdaDiscoveryActive > 0) | 222 | void IrdaApplet::paintEvent( QPaintEvent* ) { |
217 | p.drawPixmap( 0, 1, irdaDiscoveryOnPixmap ); | 223 | QPainter p(this); |
224 | qDebug("paint irda pixmap"); | ||
225 | |||
226 | p.eraseRect ( 0, 0, this->width(), this->height() ); | ||
227 | if (irdaactive > 0) { | ||
228 | p.drawPixmap( 0, 1, irdaOnPixmap ); | ||
229 | } else { | ||
230 | p.drawPixmap( 0, 1, irdaOffPixmap ); | ||
231 | } | ||
232 | |||
233 | if (irdaDiscoveryActive > 0) { | ||
234 | p.drawPixmap( 0, 1, irdaDiscoveryOnPixmap ); | ||
235 | } | ||
236 | if (receiveActive) { | ||
237 | p.drawPixmap( 0, 1, receiveActivePixmap); | ||
238 | } | ||
218 | } | 239 | } |
diff --git a/core/applets/irdaapplet/irda.h b/core/applets/irdaapplet/irda.h index bb174e8..97ca3c3 100644 --- a/core/applets/irdaapplet/irda.h +++ b/core/applets/irdaapplet/irda.h | |||
@@ -19,43 +19,45 @@ | |||
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 | int irdaactive; // bool and bitfields later bool irdaactive :1 ; | 52 | int irdaactive; // bool and bitfields later bool irdaactive :1 ; |
52 | int irdaDiscoveryActive; | 53 | int irdaDiscoveryActive; |
53 | 54 | bool receiveActive; | |
55 | bool receiveStateChanged; | ||
54 | private slots: | 56 | private slots: |
55 | 57 | ||
56 | 58 | ||
57 | }; | 59 | }; |
58 | 60 | ||
59 | 61 | ||
60 | #endif // __SCREENSHOT_APPLET_H__ | 62 | #endif // __SCREENSHOT_APPLET_H__ |
61 | 63 | ||