summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/applets/irdaapplet/irda.cpp69
-rw-r--r--core/applets/irdaapplet/irda.h4
2 files changed, 48 insertions, 25 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
@@ -54,25 +54,24 @@
54//=========================================================================== 54//===========================================================================
55 55
56IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) 56IrdaApplet::IrdaApplet( QWidget *parent, const char *name )
57 : QWidget( parent, name ) 57 : QWidget( parent, name ) {
58{
59 setFixedHeight( 18 ); 58 setFixedHeight( 18 );
60 setFixedWidth( 14 ); 59 setFixedWidth( 14 );
61 sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); 60 sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
62 irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" ); 61 irdaOnPixmap = Resource::loadPixmap( "irdaapplet/irdaon" );
63 irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); 62 irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" );
64 irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" ); 63 irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" );
64 receiveActivePixmap = Resource::loadPixmap("irdaapplet/receive");
65 receiveActive = false;
65 startTimer(5000); 66 startTimer(5000);
66 timerEvent(NULL); 67 timerEvent(NULL);
67} 68}
68 69
69IrdaApplet::~IrdaApplet() 70IrdaApplet::~IrdaApplet() {
70{
71 close(sockfd); 71 close(sockfd);
72} 72}
73 73
74int IrdaApplet::checkIrdaStatus() 74int IrdaApplet::checkIrdaStatus() {
75{
76 struct ifreq ifr; 75 struct ifreq ifr;
77 76
78 strcpy(ifr.ifr_name, "irda0"); 77 strcpy(ifr.ifr_name, "irda0");
@@ -83,8 +82,7 @@ int IrdaApplet::checkIrdaStatus()
83 return (ifr.ifr_flags & IFF_UP)?1:0; 82 return (ifr.ifr_flags & IFF_UP)?1:0;
84} 83}
85 84
86int IrdaApplet::setIrdaStatus(int c) 85int IrdaApplet::setIrdaStatus(int c) {
87{
88 struct ifreq ifr; 86 struct ifreq ifr;
89 87
90 strcpy(ifr.ifr_name, "irda0"); 88 strcpy(ifr.ifr_name, "irda0");
@@ -103,8 +101,7 @@ int IrdaApplet::setIrdaStatus(int c)
103 return 0; 101 return 0;
104} 102}
105 103
106int IrdaApplet::checkIrdaDiscoveryStatus() 104int IrdaApplet::checkIrdaDiscoveryStatus() {
107{
108 QFile discovery("/proc/sys/net/irda/discovery"); 105 QFile discovery("/proc/sys/net/irda/discovery");
109 char status; 106 char status;
110 107
@@ -115,8 +112,7 @@ int IrdaApplet::checkIrdaDiscoveryStatus()
115 return atoi(&status); 112 return atoi(&status);
116} 113}
117 114
118int IrdaApplet::setIrdaDiscoveryStatus(int d) 115int IrdaApplet::setIrdaDiscoveryStatus(int d) {
119{
120 QFile discovery("/proc/sys/net/irda/discovery"); 116 QFile discovery("/proc/sys/net/irda/discovery");
121 117
122 discovery.open( IO_WriteOnly|IO_Raw ); 118 discovery.open( IO_WriteOnly|IO_Raw );
@@ -131,8 +127,8 @@ int IrdaApplet::setIrdaDiscoveryStatus(int d)
131 return 0; 127 return 0;
132} 128}
133 129
134void IrdaApplet::mousePressEvent( QMouseEvent *) 130
135{ 131void IrdaApplet::mousePressEvent( QMouseEvent *) {
136 QPopupMenu *menu = new QPopupMenu(); 132 QPopupMenu *menu = new QPopupMenu();
137 QString cmd; 133 QString cmd;
138 int ret=0; 134 int ret=0;
@@ -151,9 +147,12 @@ void IrdaApplet::mousePressEvent( QMouseEvent *)
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 ){
151 menu->insertItem( tr("Disable Receive"), 5 );
152 } else {
155 menu->insertItem( tr("Enable Receive"), 4 ); 153 menu->insertItem( tr("Enable Receive"), 4 );
156 } 154 }
155
157 QPoint p = mapToGlobal( QPoint(1, menu->sizeHint().height()-1) ); 156 QPoint p = mapToGlobal( QPoint(1, menu->sizeHint().height()-1) );
158 ret = menu->exec(p, 2); 157 ret = menu->exec(p, 2);
159 158
@@ -176,10 +175,22 @@ void IrdaApplet::mousePressEvent( QMouseEvent *)
176 setIrdaDiscoveryStatus(1); 175 setIrdaDiscoveryStatus(1);
177 timerEvent(NULL); // NULL is undefined in c++ use 0 or 0l 176 timerEvent(NULL); // NULL is undefined in c++ use 0 or 0l
178 break; 177 break;
179 case 4: { // enable receive{ 178 case 4: { // enable receive
180 qWarning("Enable receive" ); 179 qWarning("Enable receive" );
181 QCopEnvelope e("QPE/Obex", "receive(bool)" ); 180 QCopEnvelope e("QPE/Obex", "receive(bool)" );
182 e << true; 181 e << true;
182 receiveActive = true;
183 receiveStateChanged = true;
184 timerEvent(NULL);
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);
183 break; 194 break;
184 } 195 }
185 case 6: 196 case 6:
@@ -189,30 +200,40 @@ void IrdaApplet::mousePressEvent( QMouseEvent *)
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 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
192void IrdaApplet::timerEvent( QTimerEvent * ) 203void 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);
218 }
202 219
203} 220}
204 221
205void IrdaApplet::paintEvent( QPaintEvent* ) 222void IrdaApplet::paintEvent( QPaintEvent* ) {
206{
207 QPainter p(this); 223 QPainter p(this);
208 qDebug("paint irda pixmap"); 224 qDebug("paint irda pixmap");
209 225
210 p.eraseRect ( 0, 0, this->width(), this->height() ); 226 p.eraseRect ( 0, 0, this->width(), this->height() );
211 if (irdaactive > 0) 227 if (irdaactive > 0) {
212 p.drawPixmap( 0, 1, irdaOnPixmap ); 228 p.drawPixmap( 0, 1, irdaOnPixmap );
213 else 229 } else {
214 p.drawPixmap( 0, 1, irdaOffPixmap ); 230 p.drawPixmap( 0, 1, irdaOffPixmap );
231 }
215 232
216 if (irdaDiscoveryActive > 0) 233 if (irdaDiscoveryActive > 0) {
217 p.drawPixmap( 0, 1, irdaDiscoveryOnPixmap ); 234 p.drawPixmap( 0, 1, irdaDiscoveryOnPixmap );
218} 235}
236 if (receiveActive) {
237 p.drawPixmap( 0, 1, receiveActivePixmap);
238 }
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
@@ -48,9 +48,11 @@ 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;
54private slots: 56private slots:
55 57
56 58