summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/irdaapplet/irda.cpp64
-rw-r--r--core/applets/irdaapplet/irda.h5
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
@@ -60,4 +60,5 @@ IrdaApplet::IrdaApplet( QWidget *parent, const char *name )
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);
@@ -92,5 +93,5 @@ int IrdaApplet::setIrdaStatus(int c)
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
@@ -101,4 +102,32 @@ int IrdaApplet::setIrdaStatus(int c)
101} 102}
102 103
104int 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
116int 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
103void IrdaApplet::mousePressEvent( QMouseEvent *) 132void IrdaApplet::mousePressEvent( QMouseEvent *)
104{ 133{
@@ -110,5 +139,5 @@ void IrdaApplet::mousePressEvent( QMouseEvent *)
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 );
@@ -116,9 +145,14 @@ void IrdaApplet::mousePressEvent( QMouseEvent *)
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:
@@ -131,7 +165,14 @@ void IrdaApplet::mousePressEvent( QMouseEvent *)
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
@@ -141,7 +182,10 @@ 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
@@ -153,7 +197,11 @@ void IrdaApplet::paintEvent( QPaintEvent* )
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
@@ -23,4 +23,5 @@
23#include <qguardedptr.h> 23#include <qguardedptr.h>
24#include <qtimer.h> 24#include <qtimer.h>
25#include <qfile.h>
25 26
26 27
@@ -41,4 +42,6 @@ private:
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
@@ -46,5 +49,7 @@ 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
50private slots: 55private slots: