-rw-r--r-- | core/applets/irdaapplet/irda.cpp | 58 | ||||
-rw-r--r-- | core/applets/irdaapplet/irda.h | 5 |
2 files changed, 58 insertions, 5 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 | |||
@@ -59,6 +59,7 @@ IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) | |||
59 | sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); | 59 | sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); |
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); |
64 | } | 65 | } |
@@ -100,6 +101,34 @@ int IrdaApplet::setIrdaStatus(int c) | |||
100 | return 0; | 101 | return 0; |
101 | } | 102 | } |
102 | 103 | ||
104 | int 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 | |||
116 | int 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 | |||
103 | void IrdaApplet::mousePressEvent( QMouseEvent *) | 132 | void IrdaApplet::mousePressEvent( QMouseEvent *) |
104 | { | 133 | { |
105 | QPopupMenu *menu = new QPopupMenu(); | 134 | QPopupMenu *menu = new QPopupMenu(); |
@@ -109,14 +138,19 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) | |||
109 | /* Refresh active state */ | 138 | /* Refresh active state */ |
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 ); |
115 | else | 144 | else |
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 | ||
@@ -130,9 +164,16 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) | |||
130 | timerEvent(NULL); | 164 | timerEvent(NULL); |
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 | ||
138 | } | 179 | } |
@@ -140,9 +181,12 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) | |||
140 | void IrdaApplet::timerEvent( QTimerEvent * ) | 181 | 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 | ||
148 | } | 192 | } |
@@ -152,8 +196,12 @@ void IrdaApplet::paintEvent( QPaintEvent* ) | |||
152 | QPainter p(this); | 196 | QPainter p(this); |
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 | |||
@@ -22,6 +22,7 @@ | |||
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 | 26 | ||
26 | 27 | ||
27 | class IrdaApplet : public QWidget | 28 | class IrdaApplet : public QWidget |
@@ -40,12 +41,16 @@ private: | |||
40 | void paintEvent( QPaintEvent* ); | 41 | void paintEvent( QPaintEvent* ); |
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 | ||
45 | private: | 48 | 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 | ||
50 | private slots: | 55 | private slots: |
51 | 56 | ||