author | harlekin <harlekin> | 2002-05-18 21:55:22 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-05-18 21:55:22 (UTC) |
commit | be9add24a65c8ad89bc5425aa4d42c4b598a50be (patch) (unidiff) | |
tree | 1ba0f046ef932b6f72c08a35f5e99073ebf031b9 | |
parent | 1d935738d89d038e05013d8d099bcf4da14073ea (diff) | |
download | opie-be9add24a65c8ad89bc5425aa4d42c4b598a50be.zip opie-be9add24a65c8ad89bc5425aa4d42c4b598a50be.tar.gz opie-be9add24a65c8ad89bc5425aa4d42c4b598a50be.tar.bz2 |
patch by Daniel Foster <daniel-l@34SP.com>
-rw-r--r-- | core/applets/irdaapplet/irda.cpp | 64 | ||||
-rw-r--r-- | core/applets/irdaapplet/irda.h | 5 |
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 | |||
@@ -61,2 +61,3 @@ IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) | |||
61 | irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); | 61 | irdaOffPixmap = Resource::loadPixmap( "irdaapplet/irdaoff" ); |
62 | irdaDiscoveryOnPixmap = Resource::loadPixmap( "irdaapplet/magglass" ); | ||
62 | startTimer(5000); | 63 | startTimer(5000); |
@@ -93,3 +94,3 @@ int IrdaApplet::setIrdaStatus(int 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; |
@@ -102,2 +103,30 @@ int IrdaApplet::setIrdaStatus(int c) | |||
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 *) |
@@ -111,3 +140,3 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) | |||
111 | 140 | ||
112 | //menu->insertItem( tr("More..."), 2 ); | 141 | //menu->insertItem( tr("More..."), 4 ); |
113 | if (irdaactive) | 142 | if (irdaactive) |
@@ -117,7 +146,12 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) | |||
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) { |
@@ -132,5 +166,12 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) | |||
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 | } |
@@ -142,5 +183,8 @@ void IrdaApplet::timerEvent( QTimerEvent * ) | |||
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); |
@@ -154,6 +198,10 @@ void IrdaApplet::paintEvent( QPaintEvent* ) | |||
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 | |||
@@ -24,2 +24,3 @@ | |||
24 | #include <qtimer.h> | 24 | #include <qtimer.h> |
25 | #include <qfile.h> | ||
25 | 26 | ||
@@ -42,2 +43,4 @@ private: | |||
42 | int setIrdaStatus(int); | 43 | int setIrdaStatus(int); |
44 | int checkIrdaDiscoveryStatus(); | ||
45 | int setIrdaDiscoveryStatus(int); | ||
43 | int sockfd; | 46 | int sockfd; |
@@ -47,3 +50,5 @@ private: | |||
47 | QPixmap irdaOffPixmap; | 50 | QPixmap irdaOffPixmap; |
51 | QPixmap irdaDiscoveryOnPixmap; | ||
48 | int irdaactive; | 52 | int irdaactive; |
53 | int irdaDiscoveryActive; | ||
49 | 54 | ||