author | mickeyl <mickeyl> | 2004-03-01 14:24:18 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-03-01 14:24:18 (UTC) |
commit | 3cdec2fe5b3201a121cfbb2352162fe0cbae0a1d (patch) (unidiff) | |
tree | 409756ff03a1ceabfa85d37e08ed12a14c72289a /core/applets/cardmon/cardmon.cpp | |
parent | 60cc11a7c619bebec117e953f3b34bbf213d0fb2 (diff) | |
download | opie-3cdec2fe5b3201a121cfbb2352162fe0cbae0a1d.zip opie-3cdec2fe5b3201a121cfbb2352162fe0cbae0a1d.tar.gz opie-3cdec2fe5b3201a121cfbb2352162fe0cbae0a1d.tar.bz2 |
libopie1->libopie2
Diffstat (limited to 'core/applets/cardmon/cardmon.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/applets/cardmon/cardmon.cpp | 178 |
1 files changed, 125 insertions, 53 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp index 4ed09b8..8ffaada 100644 --- a/core/applets/cardmon/cardmon.cpp +++ b/core/applets/cardmon/cardmon.cpp | |||
@@ -18,11 +18,12 @@ | |||
18 | 18 | ||
19 | |||
20 | #include "cardmon.h" | 19 | #include "cardmon.h" |
21 | 20 | ||
22 | #include <qpe/resource.h> | 21 | /* OPIE */ |
23 | 22 | #include <opie2/odevice.h> | |
24 | #include <opie/odevice.h> | 23 | #include <opie2/otaskbarapplet.h> |
25 | |||
26 | #include <qpe/applnk.h> | 24 | #include <qpe/applnk.h> |
25 | #include <qpe/resource.h> | ||
27 | 26 | ||
27 | /* QT */ | ||
28 | #include <qapplication.h> | ||
28 | #include <qcopchannel_qws.h> | 29 | #include <qcopchannel_qws.h> |
@@ -32,5 +33,6 @@ | |||
32 | #include <qtextstream.h> | 33 | #include <qtextstream.h> |
34 | #include <qsound.h> | ||
33 | #include <qtimer.h> | 35 | #include <qtimer.h> |
34 | #include <qapplication.h> | ||
35 | 36 | ||
37 | /* STD */ | ||
36 | #include <stdio.h> | 38 | #include <stdio.h> |
@@ -40,3 +42,2 @@ | |||
40 | #include <fcntl.h> | 42 | #include <fcntl.h> |
41 | #include <qsound.h> | ||
42 | 43 | ||
@@ -80,3 +81,4 @@ CardMonitor::~CardMonitor() | |||
80 | { | 81 | { |
81 | if (popupMenu) { | 82 | if ( popupMenu ) |
83 | { | ||
82 | delete popupMenu; | 84 | delete popupMenu; |
@@ -87,3 +89,4 @@ void CardMonitor::popUp(QString message, QString icon) | |||
87 | { | 89 | { |
88 | if (!popupMenu) { | 90 | if ( !popupMenu ) |
91 | { | ||
89 | popupMenu = new QPopupMenu(this); | 92 | popupMenu = new QPopupMenu(this); |
@@ -92,5 +95,8 @@ void CardMonitor::popUp(QString message, QString icon) | |||
92 | popupMenu->clear(); | 95 | popupMenu->clear(); |
93 | if (icon.isEmpty()) { | 96 | if ( icon.isEmpty() ) |
97 | { | ||
94 | popupMenu->insertItem(message, 0); | 98 | popupMenu->insertItem(message, 0); |
95 | } else { | 99 | } |
100 | else | ||
101 | { | ||
96 | popupMenu->insertItem(QIconSet(Resource::loadPixmap(icon)), | 102 | popupMenu->insertItem(QIconSet(Resource::loadPixmap(icon)), |
@@ -118,3 +124,4 @@ void CardMonitor::mousePressEvent(QMouseEvent *) | |||
118 | 124 | ||
119 | if (cardInSd) { | 125 | if ( cardInSd ) |
126 | { | ||
120 | menu->insertItem(QIconSet(Resource::loadPixmap("cardmon/ide")), | 127 | menu->insertItem(QIconSet(Resource::loadPixmap("cardmon/ide")), |
@@ -123,3 +130,4 @@ void CardMonitor::mousePressEvent(QMouseEvent *) | |||
123 | 130 | ||
124 | if (cardInPcmcia0) { | 131 | if ( cardInPcmcia0 ) |
132 | { | ||
125 | menu-> | 133 | menu-> |
@@ -130,3 +138,4 @@ void CardMonitor::mousePressEvent(QMouseEvent *) | |||
130 | 138 | ||
131 | if (cardInPcmcia1) { | 139 | if ( cardInPcmcia1 ) |
140 | { | ||
132 | menu-> | 141 | menu-> |
@@ -142,6 +151,8 @@ void CardMonitor::mousePressEvent(QMouseEvent *) | |||
142 | 151 | ||
143 | if (opt == 1) { | 152 | if ( opt == 1 ) |
153 | { | ||
144 | cmd = "/sbin/cardctl eject 0"; | 154 | cmd = "/sbin/cardctl eject 0"; |
145 | err = system((const char *) cmd); | 155 | err = system((const char *) cmd); |
146 | if (err != 0) { | 156 | if ( err != 0 ) |
157 | { | ||
147 | qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", | 158 | qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", |
@@ -150,6 +161,11 @@ void CardMonitor::mousePressEvent(QMouseEvent *) | |||
150 | } | 161 | } |
151 | } else if (opt == 0) { | 162 | } |
152 | if (ODevice::inst()->system() == System_Familiar) { | 163 | else if ( opt == 0 ) |
164 | { | ||
165 | if ( ODevice::inst() ->system() == System_Familiar ) | ||
166 | { | ||
153 | cmd = "umount /dev/mmc/part1"; | 167 | cmd = "umount /dev/mmc/part1"; |
154 | } else { | 168 | } |
169 | else | ||
170 | { | ||
155 | cmd = "umount /dev/mmcda1"; | 171 | cmd = "umount /dev/mmcda1"; |
@@ -157,9 +173,13 @@ void CardMonitor::mousePressEvent(QMouseEvent *) | |||
157 | err = system((const char *) cmd); | 173 | err = system((const char *) cmd); |
158 | if (err != 0) { | 174 | if ( err != 0 ) |
175 | { | ||
159 | popUp(tr("SD/MMC card eject failed!")); | 176 | popUp(tr("SD/MMC card eject failed!")); |
160 | } | 177 | } |
161 | } else if (opt == 2) { | 178 | } |
179 | else if ( opt == 2 ) | ||
180 | { | ||
162 | cmd = "/sbin/cardctl eject 1"; | 181 | cmd = "/sbin/cardctl eject 1"; |
163 | err = system((const char *) cmd); | 182 | err = system((const char *) cmd); |
164 | if (err != 0) { | 183 | if ( err != 0 ) |
184 | { | ||
165 | qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", | 185 | qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", |
@@ -175,6 +195,9 @@ void CardMonitor::cardMessage(const QCString & msg, const QByteArray &) | |||
175 | { | 195 | { |
176 | if (msg == "stabChanged()") { | 196 | if ( msg == "stabChanged()" ) |
197 | { | ||
177 | // qDebug("Pcmcia: stabchanged"); | 198 | // qDebug("Pcmcia: stabchanged"); |
178 | getStatusPcmcia(); | 199 | getStatusPcmcia(); |
179 | } else if (msg == "mtabChanged()") { | 200 | } |
201 | else if ( msg == "mtabChanged()" ) | ||
202 | { | ||
180 | // qDebug("CARDMONAPPLET: mtabchanged"); | 203 | // qDebug("CARDMONAPPLET: mtabchanged"); |
@@ -193,7 +216,12 @@ bool CardMonitor::getStatusPcmcia(int showPopUp) | |||
193 | // one of these 3 files should exist | 216 | // one of these 3 files should exist |
194 | if (QFile::exists("/var/run/stab")) { | 217 | if ( QFile::exists( "/var/run/stab" ) ) |
218 | { | ||
195 | fileName = "/var/run/stab"; | 219 | fileName = "/var/run/stab"; |
196 | } else if (QFile::exists("/var/state/pcmcia/stab")) { | 220 | } |
221 | else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) | ||
222 | { | ||
197 | fileName = "/var/state/pcmcia/stab"; | 223 | fileName = "/var/state/pcmcia/stab"; |
198 | } else { | 224 | } |
225 | else | ||
226 | { | ||
199 | fileName = "/var/lib/pcmcia/stab"; | 227 | fileName = "/var/lib/pcmcia/stab"; |
@@ -203,3 +231,4 @@ bool CardMonitor::getStatusPcmcia(int showPopUp) | |||
203 | 231 | ||
204 | if (f.open(IO_ReadOnly)) { | 232 | if ( f.open( IO_ReadOnly ) ) |
233 | { | ||
205 | QStringList list; | 234 | QStringList list; |
@@ -210,8 +239,13 @@ bool CardMonitor::getStatusPcmcia(int showPopUp) | |||
210 | for (QStringList::Iterator line = list.begin(); line != list.end(); | 239 | for (QStringList::Iterator line = list.begin(); line != list.end(); |
211 | line++) { | 240 | line++ ) |
212 | if ((*line).startsWith("Socket 0:")) { | 241 | { |
213 | if ((*line).startsWith("Socket 0: empty") && cardInPcmcia0) { | 242 | if ( ( *line ).startsWith( "Socket 0:" ) ) |
243 | { | ||
244 | if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ) | ||
245 | { | ||
214 | cardInPcmcia0 = FALSE; | 246 | cardInPcmcia0 = FALSE; |
215 | } else if (!(*line).startsWith("Socket 0: empty") | 247 | } |
216 | && !cardInPcmcia0) { | 248 | else if ( !( *line ).startsWith( "Socket 0: empty" ) |
249 | && !cardInPcmcia0 ) | ||
250 | { | ||
217 | cardInPcmcia0Name = | 251 | cardInPcmcia0Name = |
@@ -227,7 +261,12 @@ bool CardMonitor::getStatusPcmcia(int showPopUp) | |||
227 | } | 261 | } |
228 | } else if ((*line).startsWith("Socket 1:")) { | 262 | } |
229 | if ((*line).startsWith("Socket 1: empty") && cardInPcmcia1) { | 263 | else if ( ( *line ).startsWith( "Socket 1:" ) ) |
264 | { | ||
265 | if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) | ||
266 | { | ||
230 | cardInPcmcia1 = FALSE; | 267 | cardInPcmcia1 = FALSE; |
231 | } else if (!(*line).startsWith("Socket 1: empty") | 268 | } |
232 | && !cardInPcmcia1) { | 269 | else if ( !( *line ).startsWith( "Socket 1: empty" ) |
270 | && !cardInPcmcia1 ) | ||
271 | { | ||
233 | cardInPcmcia1Name = | 272 | cardInPcmcia1Name = |
@@ -248,10 +287,15 @@ bool CardMonitor::getStatusPcmcia(int showPopUp) | |||
248 | if (!showPopUp | 287 | if (!showPopUp |
249 | && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1)) { | 288 | && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) ) |
289 | { | ||
250 | QString text = QString::null; | 290 | QString text = QString::null; |
251 | QString what = QString::null; | 291 | QString what = QString::null; |
252 | if (cardWas0 != cardInPcmcia0) { | 292 | if ( cardWas0 != cardInPcmcia0 ) |
253 | if (cardInPcmcia0) { | 293 | { |
294 | if ( cardInPcmcia0 ) | ||
295 | { | ||
254 | text += tr("New card: "); | 296 | text += tr("New card: "); |
255 | what = "on"; | 297 | what = "on"; |
256 | } else { | 298 | } |
299 | else | ||
300 | { | ||
257 | text += tr("Ejected: "); | 301 | text += tr("Ejected: "); |
@@ -263,7 +307,11 @@ bool CardMonitor::getStatusPcmcia(int showPopUp) | |||
263 | 307 | ||
264 | if (cardWas1 != cardInPcmcia1) { | 308 | if ( cardWas1 != cardInPcmcia1 ) |
265 | if (cardInPcmcia1) { | 309 | { |
310 | if ( cardInPcmcia1 ) | ||
311 | { | ||
266 | text += tr("New card: "); | 312 | text += tr("New card: "); |
267 | what = "on"; | 313 | what = "on"; |
268 | } else { | 314 | } |
315 | else | ||
316 | { | ||
269 | text += tr("Ejected: "); | 317 | text += tr("Ejected: "); |
@@ -277,4 +325,7 @@ bool CardMonitor::getStatusPcmcia(int showPopUp) | |||
277 | #endif | 325 | #endif |
326 | |||
278 | } | 327 | } |
279 | } else { | 328 | } |
329 | else | ||
330 | { | ||
280 | // no file found | 331 | // no file found |
@@ -301,4 +352,6 @@ bool CardMonitor::getStatusSd(int showPopUp) | |||
301 | 352 | ||
302 | if (mntfp) { | 353 | if ( mntfp ) |
303 | while ((me = getmntent(mntfp)) != 0) { | 354 | { |
355 | while ( ( me = getmntent( mntfp ) ) != 0 ) | ||
356 | { | ||
304 | QString fs = me->mnt_fsname; | 357 | QString fs = me->mnt_fsname; |
@@ -306,3 +359,4 @@ bool CardMonitor::getStatusSd(int showPopUp) | |||
306 | if (fs.left(14) == "/dev/mmc/part1" || fs.left(7) == "/dev/sd" | 359 | if (fs.left(14) == "/dev/mmc/part1" || fs.left(7) == "/dev/sd" |
307 | || fs.left(9) == "/dev/mmcd") { | 360 | || fs.left( 9 ) == "/dev/mmcd" ) |
361 | { | ||
308 | cardInSd = TRUE; | 362 | cardInSd = TRUE; |
@@ -317,9 +371,13 @@ bool CardMonitor::getStatusSd(int showPopUp) | |||
317 | 371 | ||
318 | if (!showPopUp && cardWas != cardInSd) { | 372 | if ( !showPopUp && cardWas != cardInSd ) |
373 | { | ||
319 | QString text = QString::null; | 374 | QString text = QString::null; |
320 | QString what = QString::null; | 375 | QString what = QString::null; |
321 | if (cardInSd) { | 376 | if ( cardInSd ) |
377 | { | ||
322 | text += "New card: SD/MMC"; | 378 | text += "New card: SD/MMC"; |
323 | what = "on"; | 379 | what = "on"; |
324 | } else { | 380 | } |
381 | else | ||
382 | { | ||
325 | text += "Ejected: SD/MMC"; | 383 | text += "Ejected: SD/MMC"; |
@@ -345,6 +403,9 @@ void CardMonitor::paintEvent(QPaintEvent *) | |||
345 | 403 | ||
346 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { | 404 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) |
405 | { | ||
347 | p.drawPixmap(0, 0, pm ); | 406 | p.drawPixmap(0, 0, pm ); |
348 | show(); | 407 | show(); |
349 | } else { | 408 | } |
409 | else | ||
410 | { | ||
350 | //p.eraseRect(rect()); | 411 | //p.eraseRect(rect()); |
@@ -353 +414,12 @@ void CardMonitor::paintEvent(QPaintEvent *) | |||
353 | } | 414 | } |
415 | |||
416 | int CardMonitor::position() | ||
417 | { | ||
418 | return 7; | ||
419 | } | ||
420 | |||
421 | Q_EXPORT_INTERFACE() | ||
422 | { | ||
423 | Q_CREATE_INSTANCE( OTaskbarAppletWrapper<CardMonitor> ); | ||
424 | } | ||
425 | |||