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