-rw-r--r-- | core/applets/cardmon/cardmon.cpp | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp index c0a936f..74e8837 100644 --- a/core/applets/cardmon/cardmon.cpp +++ b/core/applets/cardmon/cardmon.cpp | |||
@@ -71,20 +71,20 @@ CardMonitor::~CardMonitor() { | |||
71 | delete popupMenu; | 71 | delete popupMenu; |
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | void CardMonitor::popUp( QString message, QString icon ) { | 75 | void CardMonitor::popUp( QString message, QString icon ) { |
76 | if ( ! popupMenu ) { | 76 | if ( ! popupMenu ) { |
77 | popupMenu = new QPopupMenu(); | 77 | popupMenu = new QPopupMenu(); |
78 | } | 78 | } |
79 | 79 | ||
80 | popupMenu->clear(); | 80 | popupMenu->clear(); |
81 | if( icon.isEmpty() ) { | 81 | if( icon.isEmpty() ) { |
82 | popupMenu->insertItem( message, 0 ); | 82 | popupMenu->insertItem( message, 0 ); |
83 | } else { | 83 | } else { |
84 | popupMenu->insertItem( QIconSet ( Resource::loadPixmap ( icon ) ), message, 0 ); | 84 | popupMenu->insertItem( QIconSet ( Resource::loadPixmap ( icon ) ), message, 0 ); |
85 | } | 85 | } |
86 | 86 | ||
87 | QPoint p = mapToGlobal ( QPoint ( 0, 0 ) ); | 87 | QPoint p = mapToGlobal ( QPoint ( 0, 0 ) ); |
88 | QSize s = popupMenu->sizeHint (); | 88 | QSize s = popupMenu->sizeHint (); |
89 | popupMenu->popup( QPoint ( | 89 | popupMenu->popup( QPoint ( |
90 | p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), | 90 | p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), |
@@ -110,28 +110,28 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) { | |||
110 | menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia0Type ) ), | 110 | menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia0Type ) ), |
111 | tr( "Eject card 0: %1" ).arg(cardInPcmcia0Name ), 1 ); | 111 | tr( "Eject card 0: %1" ).arg(cardInPcmcia0Name ), 1 ); |
112 | } | 112 | } |
113 | 113 | ||
114 | if ( cardInPcmcia1 ) { | 114 | if ( cardInPcmcia1 ) { |
115 | menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia1Type ) ), | 115 | menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia1Type ) ), |
116 | tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); | 116 | tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); |
117 | } | 117 | } |
118 | 118 | ||
119 | QPoint p = mapToGlobal ( QPoint ( 0, 0 ) ); | 119 | QPoint p = mapToGlobal ( QPoint ( 0, 0 ) ); |
120 | QSize s = menu->sizeHint (); | 120 | QSize s = menu->sizeHint (); |
121 | int opt = menu->exec( QPoint ( | 121 | int opt = menu->exec( QPoint ( |
122 | p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), | 122 | p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), |
123 | p. y ( ) - s. height ( ) ), 0); | 123 | p. y ( ) - s. height ( ) ), 0); |
124 | 124 | ||
125 | if ( opt == 1 ) { | 125 | if ( opt == 1 ) { |
126 | cmd = "/sbin/cardctl eject 0"; | 126 | cmd = "/sbin/cardctl eject 0"; |
127 | err = system( ( const char * ) cmd ); | 127 | err = system( ( const char * ) cmd ); |
128 | if ( ( err == 127 ) || ( err < 0 ) ) { | 128 | if ( ( err == 127 ) || ( err < 0 ) ) { |
129 | qDebug( "Could not execute `/sbin/cardctl eject 0'! err=%d", err ); | 129 | qDebug( "Could not execute `/sbin/cardctl eject 0'! err=%d", err ); |
130 | popUp( tr( "CF/PCMCIA card eject failed!" ) ); | 130 | popUp( tr( "CF/PCMCIA card eject failed!" ) ); |
131 | } | 131 | } |
132 | } else if ( opt == 0 ) { | 132 | } else if ( opt == 0 ) { |
133 | if ( ODevice::inst()->system() == System_Familiar ) { | 133 | if ( ODevice::inst()->system() == System_Familiar ) { |
134 | cmd = "umount /dev/mmc/part1"; | 134 | cmd = "umount /dev/mmc/part1"; |
135 | err = system( ( const char *) cmd ); | 135 | err = system( ( const char *) cmd ); |
136 | if ( ( err != 0 ) ) { | 136 | if ( ( err != 0 ) ) { |
137 | popUp( tr("SD/MMC card eject failed!") ); | 137 | popUp( tr("SD/MMC card eject failed!") ); |
@@ -144,16 +144,16 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) { | |||
144 | popUp( tr("SD/MMC card eject failed!") ); | 144 | popUp( tr("SD/MMC card eject failed!") ); |
145 | } | 145 | } |
146 | } | 146 | } |
147 | } else if ( opt == 2 ) { | 147 | } else if ( opt == 2 ) { |
148 | cmd = "/sbin/cardctl eject 1"; | 148 | cmd = "/sbin/cardctl eject 1"; |
149 | err = system( ( const char *) cmd ); | 149 | err = system( ( const char *) cmd ); |
150 | if ( ( err == 127 ) || ( err < 0 ) ) { | 150 | if ( ( err == 127 ) || ( err < 0 ) ) { |
151 | qDebug( "Could not execute `/sbin/cardctl eject 1'! err=%d", err ); | 151 | qDebug( "Could not execute `/sbin/cardctl eject 1'! err=%d", err ); |
152 | popUp( tr( "CF/PCMCIA card eject failed!" ) ); | 152 | popUp( tr( "CF/PCMCIA card eject failed!" ) ); |
153 | } | 153 | } |
154 | } | 154 | } |
155 | delete menu; | 155 | delete menu; |
156 | } | 156 | } |
157 | 157 | ||
158 | 158 | ||
159 | void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) { | 159 | void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) { |
@@ -201,26 +201,26 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) { | |||
201 | } else if ( !(*line).startsWith( "Socket 0: empty" ) && !cardInPcmcia0 ){ | 201 | } else if ( !(*line).startsWith( "Socket 0: empty" ) && !cardInPcmcia0 ){ |
202 | cardInPcmcia0Name = (*line).mid( ( (*line).find( ':' ) + 1 ), (*line).length() - 9 ); | 202 | cardInPcmcia0Name = (*line).mid( ( (*line).find( ':' ) + 1 ), (*line).length() - 9 ); |
203 | cardInPcmcia0Name.stripWhiteSpace(); | 203 | cardInPcmcia0Name.stripWhiteSpace(); |
204 | cardInPcmcia0 = TRUE; | 204 | cardInPcmcia0 = TRUE; |
205 | show(); | 205 | show(); |
206 | line++; | 206 | line++; |
207 | int pos=(*line).find('\t' ) + 1; | 207 | int pos=(*line).find('\t' ) + 1; |
208 | cardInPcmcia0Type = (*line).mid( pos, (*line).find( "\t" , pos) - pos ); | 208 | cardInPcmcia0Type = (*line).mid( pos, (*line).find( "\t" , pos) - pos ); |
209 | } | 209 | } |
210 | } else if( (*line).startsWith( "Socket 1:" ) ){ | 210 | } else if( (*line).startsWith( "Socket 1:" ) ){ |
211 | if( (*line).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) { | 211 | if( (*line).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) { |
212 | cardInPcmcia1 = FALSE; | 212 | cardInPcmcia1 = FALSE; |
213 | } else if ( !(*line).startsWith( "Socket 1: empty" ) && !cardInPcmcia1 ) { | 213 | } else if ( !(*line).startsWith( "Socket 1: empty" ) && !cardInPcmcia1 ) { |
214 | cardInPcmcia1Name = (*line).mid(((*line).find(':') + 1), (*line).length() - 9 ); | 214 | cardInPcmcia1Name = (*line).mid(((*line).find(':') + 1), (*line).length() - 9 ); |
215 | cardInPcmcia1Name.stripWhiteSpace(); | 215 | cardInPcmcia1Name.stripWhiteSpace(); |
216 | cardInPcmcia1 = TRUE; | 216 | cardInPcmcia1 = TRUE; |
217 | show(); | 217 | show(); |
218 | line++; | 218 | line++; |
219 | int pos=(*line).find('\t') + 1; | 219 | int pos=(*line).find('\t') + 1; |
220 | cardInPcmcia1Type = (*line).mid( pos, (*line).find("\t", pos) - pos ); | 220 | cardInPcmcia1Type = (*line).mid( pos, (*line).find("\t", pos) - pos ); |
221 | } | 221 | } |
222 | } | 222 | } |
223 | } | 223 | } |
224 | f.close(); | 224 | f.close(); |
225 | 225 | ||
226 | if( !showPopUp && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1) ) { | 226 | if( !showPopUp && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1) ) { |
@@ -232,25 +232,25 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) { | |||
232 | what="on"; | 232 | what="on"; |
233 | } else { | 233 | } else { |
234 | text += tr( "Ejected: " ); | 234 | text += tr( "Ejected: " ); |
235 | what="off"; | 235 | what="off"; |
236 | } | 236 | } |
237 | text += cardInPcmcia0Name; | 237 | text += cardInPcmcia0Name; |
238 | popUp( text, "cardmon/" + cardInPcmcia0Type ); | 238 | popUp( text, "cardmon/" + cardInPcmcia0Type ); |
239 | } | 239 | } |
240 | 240 | ||
241 | if( cardWas1 != cardInPcmcia1) { | 241 | if( cardWas1 != cardInPcmcia1) { |
242 | if( cardInPcmcia1) { | 242 | if( cardInPcmcia1) { |
243 | text += tr( "New card: " ); | 243 | text += tr( "New card: " ); |
244 | what = "on"; | 244 | what = "on"; |
245 | } else { | 245 | } else { |
246 | text += tr( "Ejected: " ); | 246 | text += tr( "Ejected: " ); |
247 | what = "off"; | 247 | what = "off"; |
248 | } | 248 | } |
249 | text += cardInPcmcia1Name; | 249 | text += cardInPcmcia1Name; |
250 | popUp( text, "cardmon/" + cardInPcmcia1Type ); | 250 | popUp( text, "cardmon/" + cardInPcmcia1Type ); |
251 | } | 251 | } |
252 | QSound::play( Resource::findSound( "cardmon/card" + what) ); | 252 | QSound::play( Resource::findSound( "cardmon/card" + what) ); |
253 | } | 253 | } |
254 | } else { | 254 | } else { |
255 | // no file found | 255 | // no file found |
256 | qDebug( "no file found" ); | 256 | qDebug( "no file found" ); |
@@ -261,27 +261,29 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) { | |||
261 | } | 261 | } |
262 | 262 | ||
263 | 263 | ||
264 | bool CardMonitor::getStatusSd( int showPopUp ) { | 264 | bool CardMonitor::getStatusSd( int showPopUp ) { |
265 | 265 | ||
266 | bool cardWas = cardInSd; // remember last state | 266 | bool cardWas = cardInSd; // remember last state |
267 | cardInSd = FALSE; | ||
267 | 268 | ||
268 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 269 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
269 | struct mntent *me; | 270 | struct mntent *me; |
270 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); | 271 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); |
271 | 272 | ||
272 | if ( mntfp ) { | 273 | if ( mntfp ) { |
273 | while ( ( me = getmntent( mntfp ) ) != 0 ) { | 274 | while ( ( me = getmntent( mntfp ) ) != 0 ) { |
274 | QString fs = me->mnt_fsname; | 275 | QString fs = me->mnt_fsname; |
275 | //qDebug( fs ); | 276 | //qDebug( fs ); |
276 | if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd" || fs.left( 9 ) == "/dev/mmcd" ) { | 277 | if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd" || fs.left( 9 ) == "/dev/mmcd" ) { |
277 | cardInSd = TRUE; | 278 | cardInSd = TRUE; |
278 | show(); | 279 | show(); |
279 | } else { | ||
280 | cardInSd = FALSE; | ||
281 | } | 280 | } |
281 | // else { | ||
282 | // cardInSd = FALSE; | ||
283 | // } | ||
282 | } | 284 | } |
283 | endmntent( mntfp ); | 285 | endmntent( mntfp ); |
284 | } | 286 | } |
285 | 287 | ||
286 | if( !showPopUp && cardWas != cardInSd ) { | 288 | if( !showPopUp && cardWas != cardInSd ) { |
287 | QString text = QString::null; | 289 | QString text = QString::null; |