summaryrefslogtreecommitdiff
path: root/core/applets/cardmon/cardmon.cpp
Unidiff
Diffstat (limited to 'core/applets/cardmon/cardmon.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/applets/cardmon/cardmon.cpp46
1 files changed, 18 insertions, 28 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp
index 0addb89..0bd1ed3 100644
--- a/core/applets/cardmon/cardmon.cpp
+++ b/core/applets/cardmon/cardmon.cpp
@@ -24,24 +24,25 @@
24#include <qcopchannel_qws.h> 24#include <qcopchannel_qws.h>
25#include <qpainter.h> 25#include <qpainter.h>
26#include <qmessagebox.h> 26#include <qmessagebox.h>
27#include <qfile.h> 27#include <qfile.h>
28#include <qtextstream.h> 28#include <qtextstream.h>
29#include <qtimer.h> 29#include <qtimer.h>
30 30
31#include <stdio.h> 31#include <stdio.h>
32#include <unistd.h> 32#include <unistd.h>
33#include <stdlib.h> 33#include <stdlib.h>
34#include <string.h> 34#include <string.h>
35#include <fcntl.h> 35#include <fcntl.h>
36#include <qsound.h>
36 37
37#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 38#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
38#include <sys/vfs.h> 39#include <sys/vfs.h>
39#include <mntent.h> 40#include <mntent.h>
40#endif 41#endif
41 42
42CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ), 43CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ),
43 pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) { 44 pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) {
44 45
45 QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this ); 46 QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this );
46 connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), 47 connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)),
47 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 48 this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
@@ -90,30 +91,30 @@ void CardMonitor::popupTimeout() {
90} 91}
91 92
92void CardMonitor::mousePressEvent( QMouseEvent * ) { 93void CardMonitor::mousePressEvent( QMouseEvent * ) {
93 QPopupMenu *menu = new QPopupMenu(); 94 QPopupMenu *menu = new QPopupMenu();
94 QString cmd; 95 QString cmd;
95 int err=0; 96 int err=0;
96 97
97 if ( cardInSd ) { 98 if ( cardInSd ) {
98 menu->insertItem( tr("Eject SD/MMC card"), 0 ); 99 menu->insertItem( tr("Eject SD/MMC card"), 0 );
99 } 100 }
100 101
101 if ( cardInPcmcia0 ) { 102 if ( cardInPcmcia0 ) {
102 menu->insertItem( QIconSet ( Resource::loadPixmap ( getIconName(cardInPcmcia0Type) )), 103 menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia0Type )),
103 tr("Eject card 0: %1").arg(cardInPcmcia0Name), 1 ); 104 tr("Eject card 0: %1").arg(cardInPcmcia0Name), 1 );
104 } 105 }
105 106
106 if ( cardInPcmcia1 ) { 107 if ( cardInPcmcia1 ) {
107 menu->insertItem( QIconSet ( Resource::loadPixmap ( getIconName(cardInPcmcia1Type) )), 108 menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia1Type )),
108 tr("Eject card 1: %1").arg(cardInPcmcia1Name), 2 ); 109 tr("Eject card 1: %1").arg(cardInPcmcia1Name), 2 );
109 } 110 }
110 111
111 QPoint p = mapToGlobal ( QPoint ( 0, 0 )); 112 QPoint p = mapToGlobal ( QPoint ( 0, 0 ));
112 QSize s = menu->sizeHint ( ); 113 QSize s = menu->sizeHint ( );
113 int opt = menu->exec( QPoint ( 114 int opt = menu->exec( QPoint (
114 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), 115 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ),
115 p. y ( ) - s. height ( ) ), 0); 116 p. y ( ) - s. height ( ) ), 0);
116 117
117 if ( opt == 1 ) { 118 if ( opt == 1 ) {
118 119
119 cmd = "/sbin/cardctl eject 0"; 120 cmd = "/sbin/cardctl eject 0";
@@ -200,51 +201,50 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) {
200 } else if ( !(*line).startsWith("Socket 1: empty") && !cardInPcmcia1 ){ 201 } else if ( !(*line).startsWith("Socket 1: empty") && !cardInPcmcia1 ){
201 cardInPcmcia1Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 ); 202 cardInPcmcia1Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 );
202 cardInPcmcia1Name.stripWhiteSpace(); 203 cardInPcmcia1Name.stripWhiteSpace();
203 cardInPcmcia1 = TRUE; 204 cardInPcmcia1 = TRUE;
204 show(); 205 show();
205 line++; 206 line++;
206 int pos=(*line).find('\t')+1; 207 int pos=(*line).find('\t')+1;
207 cardInPcmcia1Type = (*line).mid( pos, (*line).find("\t", pos) - pos); 208 cardInPcmcia1Type = (*line).mid( pos, (*line).find("\t", pos) - pos);
208 } 209 }
209 } 210 }
210 } 211 }
211 f.close(); 212 f.close();
212 } else {
213 // no file found
214 qDebug("no file found");
215 cardInPcmcia0 = FALSE;
216 cardInPcmcia1 = FALSE;
217 return FALSE;
218
219 }
220
221 if( !showPopUp && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1)) { 213 if( !showPopUp && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1)) {
222 QString text = ""; 214 QString text = "";
215 QString what = "";
223 if(cardWas0 != cardInPcmcia0) { 216 if(cardWas0 != cardInPcmcia0) {
224 if(cardInPcmcia0) { text += tr("New card: "); } 217 if(cardInPcmcia0) { text += tr("New card: "); what="on";}
225 else { text += tr("Ejected: "); } 218 else { text += tr("Ejected: "); what="off";}
226 text += cardInPcmcia0Name; 219 text += cardInPcmcia0Name;
227 popUp( text, getIconName( cardInPcmcia0Type ) ); 220 popUp( text, "cardmon/" + cardInPcmcia0Type );
228 } 221 }
229 if(cardWas1 != cardInPcmcia1) { 222 if(cardWas1 != cardInPcmcia1) {
230 if(cardInPcmcia1) { text += tr("New card: "); } 223 if(cardInPcmcia1) { text += tr("New card: "); what="on";}
231 else { text += tr("Ejected: "); } 224 else { text += tr("Ejected: "); what="off";}
232 text += cardInPcmcia1Name; 225 text += cardInPcmcia1Name;
233 popUp( text, getIconName( cardInPcmcia1Type ) ); 226 popUp( text, "cardmon/" + cardInPcmcia1Type );
234 } 227 }
228 QSound::play(Resource::findSound("cardmon/card" + what));
235 } 229 }
236 230
231 } else {
232 // no file found
233 qDebug("no file found");
234 cardInPcmcia0 = FALSE;
235 cardInPcmcia1 = FALSE;
236 }
237 237
238 return ((cardWas0 == cardInPcmcia0 || cardWas1 == cardInPcmcia1) ? FALSE : TRUE); 238 return ((cardWas0 == cardInPcmcia0 && cardWas1 == cardInPcmcia1) ? FALSE : TRUE);
239} 239}
240 240
241 241
242bool CardMonitor::getStatusSd( int showPopUp ) { 242bool CardMonitor::getStatusSd( int showPopUp ) {
243 243
244 bool cardWas=cardInSd; // remember last state 244 bool cardWas=cardInSd; // remember last state
245 cardInSd=false; 245 cardInSd=false;
246 246
247#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 247#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
248 struct mntent *me; 248 struct mntent *me;
249 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 249 FILE *mntfp = setmntent( "/etc/mtab", "r" );
250 250
@@ -272,22 +272,12 @@ bool CardMonitor::getStatusSd( int showPopUp ) {
272 272
273void CardMonitor::paintEvent( QPaintEvent * ) { 273void CardMonitor::paintEvent( QPaintEvent * ) {
274 QPainter p( this ); 274 QPainter p( this );
275 275
276 if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { 276 if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) {
277 p.drawPixmap( 0, 0, pm ); 277 p.drawPixmap( 0, 0, pm );
278 show(); 278 show();
279 } else { 279 } else {
280 p.eraseRect( rect() ); 280 p.eraseRect( rect() );
281 hide(); 281 hide();
282 } 282 }
283} 283}
284
285QString CardMonitor::getIconName( QString type ) {
286 if( type != "network" &&
287 type != "ide" ) {
288 type="cardmon";
289 }
290 return "cardmon/"+type;
291}
292
293