-rw-r--r-- | core/applets/cardmon/cardmon.cpp | 74 | ||||
-rw-r--r-- | core/applets/cardmon/cardmon.pro | 2 |
2 files changed, 54 insertions, 22 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp index e94f1dc..367ef3b 100644 --- a/core/applets/cardmon/cardmon.cpp +++ b/core/applets/cardmon/cardmon.cpp | |||
@@ -21,6 +21,8 @@ | |||
21 | 21 | ||
22 | #include <qpe/resource.h> | 22 | #include <qpe/resource.h> |
23 | 23 | ||
24 | #include <opie/odevice.h> | ||
25 | |||
24 | #include <qcopchannel_qws.h> | 26 | #include <qcopchannel_qws.h> |
25 | #include <qpainter.h> | 27 | #include <qpainter.h> |
26 | #include <qmessagebox.h> | 28 | #include <qmessagebox.h> |
@@ -53,6 +55,7 @@ CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ), | |||
53 | 55 | ||
54 | cardInPcmcia0 = FALSE; | 56 | cardInPcmcia0 = FALSE; |
55 | cardInPcmcia1 = FALSE; | 57 | cardInPcmcia1 = FALSE; |
58 | cardInSd = FALSE; | ||
56 | 59 | ||
57 | setFixedSize( pm.size() ); | 60 | setFixedSize( pm.size() ); |
58 | getStatusPcmcia(TRUE); | 61 | getStatusPcmcia(TRUE); |
@@ -62,19 +65,21 @@ CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ), | |||
62 | } | 65 | } |
63 | 66 | ||
64 | CardMonitor::~CardMonitor() { | 67 | CardMonitor::~CardMonitor() { |
65 | if( popupMenu ) { delete popupMenu; } | 68 | if( popupMenu ) { |
69 | delete popupMenu; | ||
70 | } | ||
66 | } | 71 | } |
67 | 72 | ||
68 | void CardMonitor::popUp( QString message, QString icon ) { | 73 | void CardMonitor::popUp( QString message, QString icon ) { |
69 | if ( ! popupMenu ) { | 74 | if ( ! popupMenu ) { |
70 | popupMenu = new QPopupMenu(); | 75 | popupMenu = new QPopupMenu(); |
71 | } | 76 | } |
77 | |||
72 | popupMenu->clear(); | 78 | popupMenu->clear(); |
73 | if( icon.isEmpty() ) { | 79 | if( icon.isEmpty() ) { |
74 | popupMenu->insertItem( message, 0 ); | 80 | popupMenu->insertItem( message, 0 ); |
75 | } else { | 81 | } else { |
76 | popupMenu->insertItem( QIconSet ( Resource::loadPixmap ( icon )), | 82 | popupMenu->insertItem( QIconSet ( Resource::loadPixmap ( icon ) ), message, 0 ); |
77 | message, 0 ); | ||
78 | } | 83 | } |
79 | 84 | ||
80 | QPoint p = mapToGlobal ( QPoint ( 0, 0 )); | 85 | QPoint p = mapToGlobal ( QPoint ( 0, 0 )); |
@@ -116,7 +121,6 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) { | |||
116 | p. y ( ) - s. height ( ) ), 0); | 121 | p. y ( ) - s. height ( ) ), 0); |
117 | 122 | ||
118 | if ( opt == 1 ) { | 123 | if ( opt == 1 ) { |
119 | |||
120 | cmd = "/sbin/cardctl eject 0"; | 124 | cmd = "/sbin/cardctl eject 0"; |
121 | err = system( (const char *) cmd ); | 125 | err = system( (const char *) cmd ); |
122 | if ( ( err == 127 ) || ( err < 0 ) ) { | 126 | if ( ( err == 127 ) || ( err < 0 ) ) { |
@@ -124,12 +128,20 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) { | |||
124 | popUp( tr("CF/PCMCIA card eject failed!")); | 128 | popUp( tr("CF/PCMCIA card eject failed!")); |
125 | } | 129 | } |
126 | } else if ( opt == 0 ) { | 130 | } else if ( opt == 0 ) { |
131 | if ( ODevice::inst()->system() == OSYSTEM_Familiar ) { | ||
132 | cmd = "umount /dev/mmc/part1"; | ||
133 | err = system( ( const char *) cmd ); | ||
134 | if ( ( err != 0 ) ) { | ||
135 | popUp( tr("SD/MMC card eject failed!") ); | ||
136 | } | ||
137 | } else { | ||
127 | cmd = "/etc/sdcontrol compeject"; | 138 | cmd = "/etc/sdcontrol compeject"; |
128 | err = system( (const char *) cmd ); | 139 | err = system( (const char *) cmd ); |
129 | if ( ( err != 0 ) ) { | 140 | if ( ( err != 0 ) ) { |
130 | qDebug("Could not execute `/etc/sdcontrol comeject'! err=%d", err); | 141 | qDebug("Could not execute `/etc/sdcontrol comeject'! err=%d", err); |
131 | popUp( tr("SD/MMC card eject failed!")); | 142 | popUp( tr("SD/MMC card eject failed!")); |
132 | } | 143 | } |
144 | } | ||
133 | } else if ( opt == 2 ) { | 145 | } else if ( opt == 2 ) { |
134 | cmd = "/sbin/cardctl eject 1"; | 146 | cmd = "/sbin/cardctl eject 1"; |
135 | err = system( (const char *) cmd ); | 147 | err = system( (const char *) cmd ); |
@@ -138,7 +150,6 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) { | |||
138 | popUp( tr("CF/PCMCIA card eject failed!")); | 150 | popUp( tr("CF/PCMCIA card eject failed!")); |
139 | } | 151 | } |
140 | } | 152 | } |
141 | |||
142 | delete menu; | 153 | delete menu; |
143 | } | 154 | } |
144 | 155 | ||
@@ -150,7 +161,7 @@ void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) { | |||
150 | repaint(FALSE); | 161 | repaint(FALSE); |
151 | } | 162 | } |
152 | } else if ( msg == "mtabChanged()" ) { | 163 | } else if ( msg == "mtabChanged()" ) { |
153 | // qDebug("Pcmcia: mtabchanged"); | 164 | qDebug("CARDMONAPPLET: mtabchanged"); |
154 | if ( getStatusSd() ) { | 165 | if ( getStatusSd() ) { |
155 | repaint(FALSE); | 166 | repaint(FALSE); |
156 | } | 167 | } |
@@ -194,8 +205,7 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) { | |||
194 | int pos=(*line).find('\t')+1; | 205 | int pos=(*line).find('\t')+1; |
195 | cardInPcmcia0Type = (*line).mid( pos, (*line).find("\t", pos) - pos); | 206 | cardInPcmcia0Type = (*line).mid( pos, (*line).find("\t", pos) - pos); |
196 | } | 207 | } |
197 | } | 208 | } else if( (*line).startsWith( "Socket 1:" ) ){ |
198 | else if( (*line).startsWith("Socket 1:") ){ | ||
199 | if( (*line).startsWith("Socket 1: empty") && cardInPcmcia1 ){ | 209 | if( (*line).startsWith("Socket 1: empty") && cardInPcmcia1 ){ |
200 | cardInPcmcia1 = FALSE; | 210 | cardInPcmcia1 = FALSE; |
201 | } else if ( !(*line).startsWith("Socket 1: empty") && !cardInPcmcia1 ){ | 211 | } else if ( !(*line).startsWith("Socket 1: empty") && !cardInPcmcia1 ){ |
@@ -210,31 +220,41 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) { | |||
210 | } | 220 | } |
211 | } | 221 | } |
212 | f.close(); | 222 | f.close(); |
223 | |||
213 | if( !showPopUp && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1)) { | 224 | if( !showPopUp && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1)) { |
214 | QString text = QString::null; | 225 | QString text = QString::null; |
215 | QString what = QString::null; | 226 | QString what = QString::null; |
216 | if(cardWas0 != cardInPcmcia0) { | 227 | if(cardWas0 != cardInPcmcia0) { |
217 | if(cardInPcmcia0) { text += tr("New card: "); what="on";} | 228 | if(cardInPcmcia0) { |
218 | else { text += tr("Ejected: "); what="off";} | 229 | text += tr( "New card: " ); |
230 | what="on"; | ||
231 | } else { | ||
232 | text += tr( "Ejected: " ); | ||
233 | what="off"; | ||
234 | } | ||
219 | text += cardInPcmcia0Name; | 235 | text += cardInPcmcia0Name; |
220 | popUp( text, "cardmon/" + cardInPcmcia0Type ); | 236 | popUp( text, "cardmon/" + cardInPcmcia0Type ); |
221 | } | 237 | } |
238 | |||
222 | if(cardWas1 != cardInPcmcia1) { | 239 | if(cardWas1 != cardInPcmcia1) { |
223 | if(cardInPcmcia1) { text += tr("New card: "); what="on";} | 240 | if( cardInPcmcia1) { |
224 | else { text += tr("Ejected: "); what="off";} | 241 | text += tr( "New card: " ); |
242 | what = "on"; | ||
243 | } else { | ||
244 | text += tr( "Ejected: " ); | ||
245 | what = "off"; | ||
246 | } | ||
225 | text += cardInPcmcia1Name; | 247 | text += cardInPcmcia1Name; |
226 | popUp( text, "cardmon/" + cardInPcmcia1Type ); | 248 | popUp( text, "cardmon/" + cardInPcmcia1Type ); |
227 | } | 249 | } |
228 | QSound::play(Resource::findSound("cardmon/card" + what)); | 250 | QSound::play(Resource::findSound("cardmon/card" + what)); |
229 | } | 251 | } |
230 | |||
231 | } else { | 252 | } else { |
232 | // no file found | 253 | // no file found |
233 | qDebug("no file found"); | 254 | qDebug("no file found"); |
234 | cardInPcmcia0 = FALSE; | 255 | cardInPcmcia0 = FALSE; |
235 | cardInPcmcia1 = FALSE; | 256 | cardInPcmcia1 = FALSE; |
236 | } | 257 | } |
237 | |||
238 | return ((cardWas0 == cardInPcmcia0 && cardWas1 == cardInPcmcia1) ? FALSE : TRUE); | 258 | return ((cardWas0 == cardInPcmcia0 && cardWas1 == cardInPcmcia1) ? FALSE : TRUE); |
239 | } | 259 | } |
240 | 260 | ||
@@ -242,7 +262,6 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) { | |||
242 | bool CardMonitor::getStatusSd( int showPopUp ) { | 262 | bool CardMonitor::getStatusSd( int showPopUp ) { |
243 | 263 | ||
244 | bool cardWas=cardInSd; // remember last state | 264 | bool cardWas=cardInSd; // remember last state |
245 | cardInSd=false; | ||
246 | 265 | ||
247 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 266 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
248 | struct mntent *me; | 267 | struct mntent *me; |
@@ -251,19 +270,31 @@ bool CardMonitor::getStatusSd( int showPopUp ) { | |||
251 | if ( mntfp ) { | 270 | if ( mntfp ) { |
252 | while ( (me = getmntent( mntfp )) != 0 ) { | 271 | while ( (me = getmntent( mntfp )) != 0 ) { |
253 | QString fs = me->mnt_fsname; | 272 | QString fs = me->mnt_fsname; |
254 | if ( fs.left(7)=="/dev/sd" || fs.left(9) == "/dev/mmcd" ) { | 273 | qDebug( fs ); |
255 | cardInSd=true; | 274 | if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd" || fs.left( 9 ) == "/dev/mmcd" ) { |
275 | cardInSd = TRUE; | ||
276 | show(); | ||
277 | } else { | ||
278 | cardInSd = FALSE; | ||
256 | } | 279 | } |
257 | } | 280 | } |
258 | endmntent( mntfp ); | 281 | endmntent( mntfp ); |
259 | } | 282 | } |
283 | |||
260 | if(!showPopUp && cardWas != cardInSd) { | 284 | if(!showPopUp && cardWas != cardInSd) { |
261 | QString text = QString::null; | 285 | QString text = QString::null; |
262 | if(cardInSd) { text += "SD Inserted"; } | 286 | QString what = QString::null; |
263 | else { text += "SD Removed"; } | 287 | if( cardInSd ) { |
264 | popUp( text); // XX add SD pic | 288 | text += "SD Inserted"; |
289 | what = "on"; | ||
290 | } else { | ||
291 | text += "SD Removed"; | ||
292 | what = "off"; | ||
293 | } | ||
294 | qDebug("TEXT: " + text ); | ||
295 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); | ||
296 | popUp( text, "cardmon/ide" ); // XX add SD pic | ||
265 | } | 297 | } |
266 | |||
267 | #else | 298 | #else |
268 | #error "Not on Linux" | 299 | #error "Not on Linux" |
269 | #endif | 300 | #endif |
@@ -271,6 +302,7 @@ bool CardMonitor::getStatusSd( int showPopUp ) { | |||
271 | } | 302 | } |
272 | 303 | ||
273 | void CardMonitor::paintEvent( QPaintEvent * ) { | 304 | void CardMonitor::paintEvent( QPaintEvent * ) { |
305 | |||
274 | QPainter p( this ); | 306 | QPainter p( this ); |
275 | 307 | ||
276 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { | 308 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { |
diff --git a/core/applets/cardmon/cardmon.pro b/core/applets/cardmon/cardmon.pro index aa34042..b2a2a4a 100644 --- a/core/applets/cardmon/cardmon.pro +++ b/core/applets/cardmon/cardmon.pro | |||
@@ -6,7 +6,7 @@ TARGET = cardmonapplet | |||
6 | DESTDIR = $(OPIEDIR)/plugins/applets | 6 | DESTDIR = $(OPIEDIR)/plugins/applets |
7 | INCLUDEPATH += $(OPIEDIR)/include | 7 | INCLUDEPATH += $(OPIEDIR)/include |
8 | DEPENDPATH += $(OPIEDIR)/include ../launcher | 8 | DEPENDPATH += $(OPIEDIR)/include ../launcher |
9 | LIBS += -lqpe | 9 | LIBS += -lqpe -lopie |
10 | VERSION = 1.0.0 | 10 | VERSION = 1.0.0 |
11 | 11 | ||
12 | TRANSLATIONS = ../../../i18n/de/libcardmonapplet.ts \ | 12 | TRANSLATIONS = ../../../i18n/de/libcardmonapplet.ts \ |