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) (ignore whitespace changes)
-rw-r--r-- | core/applets/cardmon/cardmon.cpp | 520 |
1 files changed, 296 insertions, 224 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 | |||
@@ -1,10 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | * cardmon.cpp | 2 | * cardmon.cpp |
3 | * | 3 | * |
4 | * --------------------- | 4 | * --------------------- |
5 | * | 5 | * |
6 | * copyright : (c) 2002 by Maximilian Reiss | 6 | * copyright : (c) 2002 by Maximilian Reiss |
7 | * email : max.reiss@gmx.de | 7 | * email : max.reiss@gmx.de |
8 | * based on two apps by Devin Butterfield | 8 | * based on two apps by Devin Butterfield |
9 | */ | 9 | */ |
10 | /*************************************************************************** | 10 | /*************************************************************************** |
@@ -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 | ||
@@ -49,15 +50,15 @@ using namespace Opie; | |||
49 | 50 | ||
50 | CardMonitor::CardMonitor(QWidget * parent):QWidget(parent), | 51 | CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ), |
51 | pm( Resource::loadPixmap("cardmon/pcmcia") ) | 52 | pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) |
52 | { | 53 | { |
53 | 54 | ||
54 | QCopChannel *pcmciaChannel = new QCopChannel("QPE/Card", this); | 55 | QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); |
55 | connect(pcmciaChannel, | 56 | connect( pcmciaChannel, |
56 | SIGNAL(received(const QCString &, const QByteArray &)), this, | 57 | SIGNAL( received( const QCString &, const QByteArray & ) ), this, |
57 | SLOT(cardMessage(const QCString &, const QByteArray &))); | 58 | SLOT( cardMessage( const QCString &, const QByteArray & ) ) ); |
58 | 59 | ||
59 | QCopChannel *sdChannel = new QCopChannel("QPE/Card", this); | 60 | QCopChannel *sdChannel = new QCopChannel( "QPE/Card", this ); |
60 | connect(sdChannel, | 61 | connect( sdChannel, |
61 | SIGNAL(received(const QCString &, const QByteArray &)), this, | 62 | SIGNAL( received( const QCString &, const QByteArray & ) ), this, |
62 | SLOT(cardMessage(const QCString &, const QByteArray &))); | 63 | SLOT( cardMessage( const QCString &, const QByteArray & ) ) ); |
63 | 64 | ||
@@ -69,8 +70,8 @@ CardMonitor::CardMonitor(QWidget * parent):QWidget(parent), | |||
69 | 70 | ||
70 | setFixedWidth ( AppLnk::smallIconSize() ); | 71 | setFixedWidth ( AppLnk::smallIconSize() ); |
71 | setFixedHeight ( AppLnk::smallIconSize() ); | 72 | setFixedHeight ( AppLnk::smallIconSize() ); |
72 | 73 | ||
73 | getStatusPcmcia(TRUE); | 74 | getStatusPcmcia( TRUE ); |
74 | getStatusSd(TRUE); | 75 | getStatusSd( TRUE ); |
75 | repaint(FALSE); | 76 | repaint( FALSE ); |
76 | popupMenu = 0; | 77 | popupMenu = 0; |
@@ -80,4 +81,5 @@ CardMonitor::~CardMonitor() | |||
80 | { | 81 | { |
81 | if (popupMenu) { | 82 | if ( popupMenu ) |
82 | delete popupMenu; | 83 | { |
84 | delete popupMenu; | ||
83 | } | 85 | } |
@@ -85,6 +87,7 @@ CardMonitor::~CardMonitor() | |||
85 | 87 | ||
86 | void CardMonitor::popUp(QString message, QString icon) | 88 | void CardMonitor::popUp( QString message, QString icon ) |
87 | { | 89 | { |
88 | if (!popupMenu) { | 90 | if ( !popupMenu ) |
89 | popupMenu = new QPopupMenu(this); | 91 | { |
92 | popupMenu = new QPopupMenu( this ); | ||
90 | } | 93 | } |
@@ -92,15 +95,18 @@ void CardMonitor::popUp(QString message, QString icon) | |||
92 | popupMenu->clear(); | 95 | popupMenu->clear(); |
93 | if (icon.isEmpty()) { | 96 | if ( icon.isEmpty() ) |
94 | popupMenu->insertItem(message, 0); | 97 | { |
95 | } else { | 98 | popupMenu->insertItem( message, 0 ); |
96 | popupMenu->insertItem(QIconSet(Resource::loadPixmap(icon)), | 99 | } |
97 | message, 0); | 100 | else |
101 | { | ||
102 | popupMenu->insertItem( QIconSet( Resource::loadPixmap( icon ) ), | ||
103 | message, 0 ); | ||
98 | } | 104 | } |
99 | 105 | ||
100 | QPoint p = mapToGlobal(QPoint(0, 0)); | 106 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); |
101 | QSize s = popupMenu->sizeHint(); | 107 | QSize s = popupMenu->sizeHint(); |
102 | popupMenu->popup(QPoint(p.x() + (width() / 2) - (s.width() / 2), | 108 | popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), |
103 | p.y() - s.height()), 0); | 109 | p.y() - s.height() ), 0 ); |
104 | 110 | ||
105 | QTimer::singleShot(2000, this, SLOT(popupTimeout())); | 111 | QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); |
106 | } | 112 | } |
@@ -112,5 +118,5 @@ void CardMonitor::popupTimeout() | |||
112 | 118 | ||
113 | void CardMonitor::mousePressEvent(QMouseEvent *) | 119 | void CardMonitor::mousePressEvent( QMouseEvent * ) |
114 | { | 120 | { |
115 | QPopupMenu *menu = new QPopupMenu(this); | 121 | QPopupMenu * menu = new QPopupMenu( this ); |
116 | QString cmd; | 122 | QString cmd; |
@@ -118,52 +124,66 @@ void CardMonitor::mousePressEvent(QMouseEvent *) | |||
118 | 124 | ||
119 | if (cardInSd) { | 125 | if ( cardInSd ) |
120 | menu->insertItem(QIconSet(Resource::loadPixmap("cardmon/ide")), | 126 | { |
121 | tr("Eject SD/MMC card"), 0); | 127 | menu->insertItem( QIconSet( Resource::loadPixmap( "cardmon/ide" ) ), |
128 | tr( "Eject SD/MMC card" ), 0 ); | ||
122 | } | 129 | } |
123 | 130 | ||
124 | if (cardInPcmcia0) { | 131 | if ( cardInPcmcia0 ) |
125 | menu-> | 132 | { |
126 | insertItem(QIconSet | 133 | menu-> |
127 | (Resource::loadPixmap("cardmon/" + cardInPcmcia0Type)), | 134 | insertItem( QIconSet |
128 | tr("Eject card 0: %1").arg(cardInPcmcia0Name), 1); | 135 | ( Resource::loadPixmap( "cardmon/" + cardInPcmcia0Type ) ), |
136 | tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 ); | ||
129 | } | 137 | } |
130 | 138 | ||
131 | if (cardInPcmcia1) { | 139 | if ( cardInPcmcia1 ) |
132 | menu-> | 140 | { |
133 | insertItem(QIconSet | 141 | menu-> |
134 | (Resource::loadPixmap("cardmon/" + cardInPcmcia1Type)), | 142 | insertItem( QIconSet |
135 | tr("Eject card 1: %1").arg(cardInPcmcia1Name), 2); | 143 | ( Resource::loadPixmap( "cardmon/" + cardInPcmcia1Type ) ), |
144 | tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); | ||
136 | } | 145 | } |
137 | 146 | ||
138 | QPoint p = mapToGlobal(QPoint(0, 0)); | 147 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); |
139 | QSize s = menu->sizeHint(); | 148 | QSize s = menu->sizeHint(); |
140 | int opt = menu->exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), | 149 | int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), |
141 | p.y() - s.height()), 0); | 150 | p.y() - s.height() ), 0 ); |
142 | 151 | ||
143 | if (opt == 1) { | 152 | if ( opt == 1 ) |
144 | cmd = "/sbin/cardctl eject 0"; | 153 | { |
145 | err = system((const char *) cmd); | 154 | cmd = "/sbin/cardctl eject 0"; |
146 | if (err != 0) { | 155 | err = system( ( const char * ) cmd ); |
147 | qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", | 156 | if ( err != 0 ) |
148 | err); | 157 | { |
149 | popUp(tr("CF/PCMCIA card eject failed!")); | 158 | qDebug( "Could not execute `/sbin/cardctl eject 0'! err=%d", |
150 | } | 159 | err ); |
151 | } else if (opt == 0) { | 160 | popUp( tr( "CF/PCMCIA card eject failed!" ) ); |
152 | if (ODevice::inst()->system() == System_Familiar) { | 161 | } |
153 | cmd = "umount /dev/mmc/part1"; | 162 | } |
154 | } else { | 163 | else if ( opt == 0 ) |
155 | cmd = "umount /dev/mmcda1"; | 164 | { |
156 | } | 165 | if ( ODevice::inst() ->system() == System_Familiar ) |
157 | err = system((const char *) cmd); | 166 | { |
158 | if (err != 0) { | 167 | cmd = "umount /dev/mmc/part1"; |
159 | popUp(tr("SD/MMC card eject failed!")); | 168 | } |
160 | } | 169 | else |
161 | } else if (opt == 2) { | 170 | { |
162 | cmd = "/sbin/cardctl eject 1"; | 171 | cmd = "umount /dev/mmcda1"; |
163 | err = system((const char *) cmd); | 172 | } |
164 | if (err != 0) { | 173 | err = system( ( const char * ) cmd ); |
165 | qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", | 174 | if ( err != 0 ) |
166 | err); | 175 | { |
167 | popUp(tr("CF/PCMCIA card eject failed!")); | 176 | popUp( tr( "SD/MMC card eject failed!" ) ); |
168 | } | 177 | } |
178 | } | ||
179 | else if ( opt == 2 ) | ||
180 | { | ||
181 | cmd = "/sbin/cardctl eject 1"; | ||
182 | err = system( ( const char * ) cmd ); | ||
183 | if ( err != 0 ) | ||
184 | { | ||
185 | qDebug( "Could not execute `/sbin/cardctl eject 1'! err=%d", | ||
186 | err ); | ||
187 | popUp( tr( "CF/PCMCIA card eject failed!" ) ); | ||
188 | } | ||
169 | } | 189 | } |
@@ -173,10 +193,13 @@ void CardMonitor::mousePressEvent(QMouseEvent *) | |||
173 | 193 | ||
174 | void CardMonitor::cardMessage(const QCString & msg, const QByteArray &) | 194 | void CardMonitor::cardMessage( const QCString & msg, const QByteArray & ) |
175 | { | 195 | { |
176 | if (msg == "stabChanged()") { | 196 | if ( msg == "stabChanged()" ) |
177 | // qDebug("Pcmcia: stabchanged"); | 197 | { |
178 | getStatusPcmcia(); | 198 | // qDebug("Pcmcia: stabchanged"); |
179 | } else if (msg == "mtabChanged()") { | 199 | getStatusPcmcia(); |
180 | // qDebug("CARDMONAPPLET: mtabchanged"); | 200 | } |
181 | getStatusSd(); | 201 | else if ( msg == "mtabChanged()" ) |
202 | { | ||
203 | // qDebug("CARDMONAPPLET: mtabchanged"); | ||
204 | getStatusSd(); | ||
182 | } | 205 | } |
@@ -184,3 +207,3 @@ void CardMonitor::cardMessage(const QCString & msg, const QByteArray &) | |||
184 | 207 | ||
185 | bool CardMonitor::getStatusPcmcia(int showPopUp) | 208 | bool CardMonitor::getStatusPcmcia( int showPopUp ) |
186 | { | 209 | { |
@@ -193,96 +216,124 @@ 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" ) ) |
195 | fileName = "/var/run/stab"; | 218 | { |
196 | } else if (QFile::exists("/var/state/pcmcia/stab")) { | 219 | fileName = "/var/run/stab"; |
197 | fileName = "/var/state/pcmcia/stab"; | 220 | } |
198 | } else { | 221 | else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) |
199 | fileName = "/var/lib/pcmcia/stab"; | 222 | { |
223 | fileName = "/var/state/pcmcia/stab"; | ||
224 | } | ||
225 | else | ||
226 | { | ||
227 | fileName = "/var/lib/pcmcia/stab"; | ||
200 | } | 228 | } |
201 | 229 | ||
202 | QFile f(fileName); | 230 | QFile f( fileName ); |
203 | 231 | ||
204 | if (f.open(IO_ReadOnly)) { | 232 | if ( f.open( IO_ReadOnly ) ) |
205 | QStringList list; | 233 | { |
206 | QTextStream stream(&f); | 234 | QStringList list; |
207 | QString streamIn; | 235 | QTextStream stream( &f ); |
208 | streamIn = stream.read(); | 236 | QString streamIn; |
209 | list = QStringList::split("\n", streamIn); | 237 | streamIn = stream.read(); |
210 | for (QStringList::Iterator line = list.begin(); line != list.end(); | 238 | list = QStringList::split( "\n", streamIn ); |
211 | line++) { | 239 | for ( QStringList::Iterator line = list.begin(); line != list.end(); |
212 | if ((*line).startsWith("Socket 0:")) { | 240 | line++ ) |
213 | if ((*line).startsWith("Socket 0: empty") && cardInPcmcia0) { | 241 | { |
214 | cardInPcmcia0 = FALSE; | 242 | if ( ( *line ).startsWith( "Socket 0:" ) ) |
215 | } else if (!(*line).startsWith("Socket 0: empty") | 243 | { |
216 | && !cardInPcmcia0) { | 244 | if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ) |
217 | cardInPcmcia0Name = | 245 | { |
218 | (*line).mid(((*line).find(':') + 1), | 246 | cardInPcmcia0 = FALSE; |
219 | (*line).length() - 9); | 247 | } |
220 | cardInPcmcia0Name.stripWhiteSpace(); | 248 | else if ( !( *line ).startsWith( "Socket 0: empty" ) |
221 | cardInPcmcia0 = TRUE; | 249 | && !cardInPcmcia0 ) |
222 | show(); | 250 | { |
223 | line++; | 251 | cardInPcmcia0Name = |
224 | int pos = (*line).find('\t') + 1; | 252 | ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), |
225 | cardInPcmcia0Type = | 253 | ( *line ).length() - 9 ); |
226 | (*line).mid(pos, (*line).find("\t", pos) - pos); | 254 | cardInPcmcia0Name.stripWhiteSpace(); |
227 | } | 255 | cardInPcmcia0 = TRUE; |
228 | } else if ((*line).startsWith("Socket 1:")) { | 256 | show(); |
229 | if ((*line).startsWith("Socket 1: empty") && cardInPcmcia1) { | 257 | line++; |
230 | cardInPcmcia1 = FALSE; | 258 | int pos = ( *line ).find( '\t' ) + 1; |
231 | } else if (!(*line).startsWith("Socket 1: empty") | 259 | cardInPcmcia0Type = |
232 | && !cardInPcmcia1) { | 260 | ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); |
233 | cardInPcmcia1Name = | 261 | } |
234 | (*line).mid(((*line).find(':') + 1), | 262 | } |
235 | (*line).length() - 9); | 263 | else if ( ( *line ).startsWith( "Socket 1:" ) ) |
236 | cardInPcmcia1Name.stripWhiteSpace(); | 264 | { |
237 | cardInPcmcia1 = TRUE; | 265 | if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) |
238 | show(); | 266 | { |
239 | line++; | 267 | cardInPcmcia1 = FALSE; |
240 | int pos = (*line).find('\t') + 1; | 268 | } |
241 | cardInPcmcia1Type = | 269 | else if ( !( *line ).startsWith( "Socket 1: empty" ) |
242 | (*line).mid(pos, (*line).find("\t", pos) - pos); | 270 | && !cardInPcmcia1 ) |
243 | } | 271 | { |
244 | } | 272 | cardInPcmcia1Name = |
245 | } | 273 | ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), |
246 | f.close(); | 274 | ( *line ).length() - 9 ); |
247 | 275 | cardInPcmcia1Name.stripWhiteSpace(); | |
248 | if (!showPopUp | 276 | cardInPcmcia1 = TRUE; |
249 | && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1)) { | 277 | show(); |
250 | QString text = QString::null; | 278 | line++; |
251 | QString what = QString::null; | 279 | int pos = ( *line ).find( '\t' ) + 1; |
252 | if (cardWas0 != cardInPcmcia0) { | 280 | cardInPcmcia1Type = |
253 | if (cardInPcmcia0) { | 281 | ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); |
254 | text += tr("New card: "); | 282 | } |
255 | what = "on"; | 283 | } |
256 | } else { | 284 | } |
257 | text += tr("Ejected: "); | 285 | f.close(); |
258 | what = "off"; | 286 | |
259 | } | 287 | if ( !showPopUp |
260 | text += cardInPcmcia0Name; | 288 | && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) ) |
261 | popUp(text, "cardmon/" + cardInPcmcia0Type); | 289 | { |
262 | } | 290 | QString text = QString::null; |
263 | 291 | QString what = QString::null; | |
264 | if (cardWas1 != cardInPcmcia1) { | 292 | if ( cardWas0 != cardInPcmcia0 ) |
265 | if (cardInPcmcia1) { | 293 | { |
266 | text += tr("New card: "); | 294 | if ( cardInPcmcia0 ) |
267 | what = "on"; | 295 | { |
268 | } else { | 296 | text += tr( "New card: " ); |
269 | text += tr("Ejected: "); | 297 | what = "on"; |
270 | what = "off"; | 298 | } |
271 | } | 299 | else |
272 | text += cardInPcmcia1Name; | 300 | { |
273 | popUp(text, "cardmon/" + cardInPcmcia1Type); | 301 | text += tr( "Ejected: " ); |
274 | } | 302 | what = "off"; |
303 | } | ||
304 | text += cardInPcmcia0Name; | ||
305 | popUp( text, "cardmon/" + cardInPcmcia0Type ); | ||
306 | } | ||
307 | |||
308 | if ( cardWas1 != cardInPcmcia1 ) | ||
309 | { | ||
310 | if ( cardInPcmcia1 ) | ||
311 | { | ||
312 | text += tr( "New card: " ); | ||
313 | what = "on"; | ||
314 | } | ||
315 | else | ||
316 | { | ||
317 | text += tr( "Ejected: " ); | ||
318 | what = "off"; | ||
319 | } | ||
320 | text += cardInPcmcia1Name; | ||
321 | popUp( text, "cardmon/" + cardInPcmcia1Type ); | ||
322 | } | ||
275 | #ifndef QT_NO_SOUND | 323 | #ifndef QT_NO_SOUND |
276 | QSound::play(Resource::findSound("cardmon/card" + what)); | 324 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); |
277 | #endif | 325 | #endif |
278 | } | 326 | |
279 | } else { | 327 | } |
280 | // no file found | 328 | } |
281 | qDebug("no file found"); | 329 | else |
282 | cardInPcmcia0 = FALSE; | 330 | { |
283 | cardInPcmcia1 = FALSE; | 331 | // no file found |
332 | qDebug( "no file found" ); | ||
333 | cardInPcmcia0 = FALSE; | ||
334 | cardInPcmcia1 = FALSE; | ||
284 | } | 335 | } |
285 | repaint( FALSE ); | 336 | repaint( FALSE ); |
286 | return ((cardWas0 == cardInPcmcia0 | 337 | return ( ( cardWas0 == cardInPcmcia0 |
287 | && cardWas1 == cardInPcmcia1) ? FALSE : TRUE); | 338 | && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE ); |
288 | 339 | ||
@@ -291,3 +342,3 @@ bool CardMonitor::getStatusPcmcia(int showPopUp) | |||
291 | 342 | ||
292 | bool CardMonitor::getStatusSd(int showPopUp) | 343 | bool CardMonitor::getStatusSd( int showPopUp ) |
293 | { | 344 | { |
@@ -299,35 +350,42 @@ bool CardMonitor::getStatusSd(int showPopUp) | |||
299 | struct mntent *me; | 350 | struct mntent *me; |
300 | FILE *mntfp = setmntent("/etc/mtab", "r"); | 351 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); |
301 | 352 | ||
302 | if (mntfp) { | 353 | if ( mntfp ) |
303 | while ((me = getmntent(mntfp)) != 0) { | 354 | { |
304 | QString fs = me->mnt_fsname; | 355 | while ( ( me = getmntent( mntfp ) ) != 0 ) |
305 | //qDebug( fs ); | 356 | { |
306 | if (fs.left(14) == "/dev/mmc/part1" || fs.left(7) == "/dev/sd" | 357 | QString fs = me->mnt_fsname; |
307 | || fs.left(9) == "/dev/mmcd") { | 358 | //qDebug( fs ); |
308 | cardInSd = TRUE; | 359 | if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd" |
309 | show(); | 360 | || fs.left( 9 ) == "/dev/mmcd" ) |
310 | } | 361 | { |
311 | // else { | 362 | cardInSd = TRUE; |
312 | // cardInSd = FALSE; | 363 | show(); |
313 | // } | 364 | } |
314 | } | 365 | // else { |
315 | endmntent(mntfp); | 366 | // cardInSd = FALSE; |
367 | // } | ||
368 | } | ||
369 | endmntent( mntfp ); | ||
316 | } | 370 | } |
317 | 371 | ||
318 | if (!showPopUp && cardWas != cardInSd) { | 372 | if ( !showPopUp && cardWas != cardInSd ) |
319 | QString text = QString::null; | 373 | { |
320 | QString what = QString::null; | 374 | QString text = QString::null; |
321 | if (cardInSd) { | 375 | QString what = QString::null; |
322 | text += "New card: SD/MMC"; | 376 | if ( cardInSd ) |
323 | what = "on"; | 377 | { |
324 | } else { | 378 | text += "New card: SD/MMC"; |
325 | text += "Ejected: SD/MMC"; | 379 | what = "on"; |
326 | what = "off"; | 380 | } |
327 | } | 381 | else |
328 | //qDebug("TEXT: " + text ); | 382 | { |
383 | text += "Ejected: SD/MMC"; | ||
384 | what = "off"; | ||
385 | } | ||
386 | //qDebug("TEXT: " + text ); | ||
329 | #ifndef QT_NO_SOUND | 387 | #ifndef QT_NO_SOUND |
330 | QSound::play(Resource::findSound("cardmon/card" + what)); | 388 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); |
331 | #endif | 389 | #endif |
332 | popUp(text, "cardmon/ide");// XX add SD pic | 390 | popUp( text, "cardmon/ide" );// XX add SD pic |
333 | } | 391 | } |
@@ -337,17 +395,31 @@ bool CardMonitor::getStatusSd(int showPopUp) | |||
337 | repaint( FALSE ); | 395 | repaint( FALSE ); |
338 | return ((cardWas == cardInSd) ? FALSE : TRUE); | 396 | return ( ( cardWas == cardInSd ) ? FALSE : TRUE ); |
339 | } | 397 | } |
340 | 398 | ||
341 | void CardMonitor::paintEvent(QPaintEvent *) | 399 | void CardMonitor::paintEvent( QPaintEvent * ) |
342 | { | 400 | { |
343 | 401 | ||
344 | QPainter p(this); | 402 | QPainter p( this ); |
345 | 403 | ||
346 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { | 404 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) |
347 | p.drawPixmap(0, 0, pm ); | 405 | { |
348 | show(); | 406 | p.drawPixmap( 0, 0, pm ); |
349 | } else { | 407 | show(); |
350 | //p.eraseRect(rect()); | 408 | } |
351 | hide(); | 409 | else |
410 | { | ||
411 | //p.eraseRect(rect()); | ||
412 | hide(); | ||
352 | } | 413 | } |
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 | |||