author | harlekin <harlekin> | 2002-06-13 15:51:31 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-06-13 15:51:31 (UTC) |
commit | 6a178f4ad2c3a9b92224c3506165cf03df41202e (patch) (unidiff) | |
tree | 6c22acadb425cc5016cdbbbc3c537912c0ae894b /core/applets/irdaapplet/irda.cpp | |
parent | 27fa818887ffe4fa13365674f5a1d7e4e2eac5fc (diff) | |
download | opie-6a178f4ad2c3a9b92224c3506165cf03df41202e.zip opie-6a178f4ad2c3a9b92224c3506165cf03df41202e.tar.gz opie-6a178f4ad2c3a9b92224c3506165cf03df41202e.tar.bz2 |
update
Diffstat (limited to 'core/applets/irdaapplet/irda.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/applets/irdaapplet/irda.cpp | 69 |
1 files changed, 45 insertions, 24 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 | |||
@@ -51,43 +51,41 @@ | |||
51 | #include <sys/ioctl.h> | 51 | #include <sys/ioctl.h> |
52 | 52 | ||
53 | 53 | ||
54 | //=========================================================================== | 54 | //=========================================================================== |
55 | 55 | ||
56 | IrdaApplet::IrdaApplet( QWidget *parent, const char *name ) | 56 | IrdaApplet::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 | ||
69 | IrdaApplet::~IrdaApplet() | 70 | IrdaApplet::~IrdaApplet() { |
70 | { | ||
71 | close(sockfd); | 71 | close(sockfd); |
72 | } | 72 | } |
73 | 73 | ||
74 | int IrdaApplet::checkIrdaStatus() | 74 | int 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"); |
79 | 78 | ||
80 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) | 79 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) |
81 | return -1; | 80 | return -1; |
82 | 81 | ||
83 | return (ifr.ifr_flags & IFF_UP)?1:0; | 82 | return (ifr.ifr_flags & IFF_UP)?1:0; |
84 | } | 83 | } |
85 | 84 | ||
86 | int IrdaApplet::setIrdaStatus(int c) | 85 | int 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"); |
91 | 89 | ||
92 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) | 90 | if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) |
93 | return -1; | 91 | return -1; |
@@ -100,26 +98,24 @@ int IrdaApplet::setIrdaStatus(int c) | |||
100 | if (ioctl(sockfd, SIOCSIFFLAGS, &ifr)) | 98 | if (ioctl(sockfd, SIOCSIFFLAGS, &ifr)) |
101 | return -1; | 99 | return -1; |
102 | 100 | ||
103 | return 0; | 101 | return 0; |
104 | } | 102 | } |
105 | 103 | ||
106 | int IrdaApplet::checkIrdaDiscoveryStatus() | 104 | int 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 | ||
111 | discovery.open( IO_ReadOnly|IO_Raw ); | 108 | discovery.open( IO_ReadOnly|IO_Raw ); |
112 | discovery.readBlock (&status, 1); | 109 | discovery.readBlock (&status, 1); |
113 | discovery.close(); | 110 | discovery.close(); |
114 | 111 | ||
115 | return atoi(&status); | 112 | return atoi(&status); |
116 | } | 113 | } |
117 | 114 | ||
118 | int IrdaApplet::setIrdaDiscoveryStatus(int d) | 115 | int 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 ); |
123 | 119 | ||
124 | if (d) | 120 | if (d) |
125 | discovery.putch('1'); | 121 | discovery.putch('1'); |
@@ -128,14 +124,14 @@ int IrdaApplet::setIrdaDiscoveryStatus(int d) | |||
128 | 124 | ||
129 | discovery.close(); | 125 | discovery.close(); |
130 | 126 | ||
131 | return 0; | 127 | return 0; |
132 | } | 128 | } |
133 | 129 | ||
134 | void IrdaApplet::mousePressEvent( QMouseEvent *) | 130 | |
135 | { | 131 | void 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; |
139 | 135 | ||
140 | /* Refresh active state */ | 136 | /* Refresh active state */ |
141 | timerEvent(NULL); | 137 | timerEvent(NULL); |
@@ -148,15 +144,18 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) | |||
148 | 144 | ||
149 | if (irdaDiscoveryActive) | 145 | if (irdaDiscoveryActive) |
150 | menu->insertItem( tr("Disable Discovery"), 2 ); | 146 | menu->insertItem( tr("Disable Discovery"), 2 ); |
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 | ||
160 | qDebug("ret was %d\n", ret); | 159 | qDebug("ret was %d\n", ret); |
161 | 160 | ||
162 | switch(ret) { | 161 | switch(ret) { |
@@ -173,46 +172,68 @@ void IrdaApplet::mousePressEvent( QMouseEvent *) | |||
173 | timerEvent(NULL); | 172 | timerEvent(NULL); |
174 | break; | 173 | break; |
175 | case 3: | 174 | case 3: |
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: |
186 | qDebug("FIXME: Bring up pretty menu...\n"); | 197 | qDebug("FIXME: Bring up pretty menu...\n"); |
187 | // With table of currently-detected devices. | 198 | // With table of currently-detected devices. |
188 | } | 199 | } |
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 | ||
192 | void IrdaApplet::timerEvent( QTimerEvent * ) | 203 | void 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 | ||
205 | void IrdaApplet::paintEvent( QPaintEvent* ) | 222 | void 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 | } | ||