summaryrefslogtreecommitdiff
authorharlekin <harlekin>2002-08-29 19:50:21 (UTC)
committer harlekin <harlekin>2002-08-29 19:50:21 (UTC)
commitf1c45d053d1d6fd8158836759d4bf608c4f32411 (patch) (unidiff)
tree91429c920cd63ef254c2e1827e17ee7d4314245e
parentf3e2fa39b66dc9aa7773b863cf2a8a6b68412ae4 (diff)
downloadopie-f1c45d053d1d6fd8158836759d4bf608c4f32411.zip
opie-f1c45d053d1d6fd8158836759d4bf608c4f32411.tar.gz
opie-f1c45d053d1d6fd8158836759d4bf608c4f32411.tar.bz2
does react on mmc on ipaq now
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/cardmon/cardmon.cpp246
-rw-r--r--core/applets/cardmon/cardmon.pro2
2 files changed, 140 insertions, 108 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
@@ -23,2 +23,4 @@
23 23
24#include <opie/odevice.h>
25
24#include <qcopchannel_qws.h> 26#include <qcopchannel_qws.h>
@@ -43,11 +45,11 @@
43CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ), 45CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ),
44 pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) { 46 pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) {
45 47
46 QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this ); 48 QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this );
47 connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), 49 connect( pcmciaChannel, SIGNAL( received( const QCString &, const QByteArray &) ),
48 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 50 this, SLOT( cardMessage( const QCString &, const QByteArray &) ) );
49 51
50 QCopChannel* sdChannel = new QCopChannel( "QPE/Card", this ); 52 QCopChannel* sdChannel = new QCopChannel( "QPE/Card", this );
51 connect( sdChannel, SIGNAL(received(const QCString &, const QByteArray &)), 53 connect( sdChannel, SIGNAL( received( const QCString &, const QByteArray &) ),
52 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 54 this, SLOT( cardMessage( const QCString &, const QByteArray &) ) );
53 55
@@ -55,7 +57,8 @@ CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ),
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 );
59 getStatusSd(TRUE); 62 getStatusSd( TRUE );
60 repaint(FALSE); 63 repaint( FALSE );
61 popupMenu = 0; 64 popupMenu = 0;
@@ -64,3 +67,5 @@ CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ),
64CardMonitor::~CardMonitor() { 67CardMonitor::~CardMonitor() {
65 if( popupMenu ) { delete popupMenu; } 68 if( popupMenu ) {
69 delete popupMenu;
70 }
66} 71}
@@ -71,2 +76,3 @@ void CardMonitor::popUp( QString message, QString icon ) {
71 } 76 }
77
72 popupMenu->clear(); 78 popupMenu->clear();
@@ -75,13 +81,12 @@ void CardMonitor::popUp( QString message, QString icon ) {
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 ) );
81 QSize s = popupMenu->sizeHint ( ); 86 QSize s = popupMenu->sizeHint ();
82 popupMenu->popup( QPoint ( 87 popupMenu->popup( QPoint (
83 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), 88 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ),
84 p. y ( ) - s. height ( ) ), 0); 89 p. y ( ) - s. height ( ) ), 0);
85 90
86 QTimer::singleShot( 2000, this, SLOT(popupTimeout()) ); 91 QTimer::singleShot( 2000, this, SLOT(popupTimeout() ) );
87} 92}
@@ -102,4 +107,4 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) {
102 if ( cardInPcmcia0 ) { 107 if ( cardInPcmcia0 ) {
103 menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia0Type )), 108 menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia0Type ) ),
104 tr("Eject card 0: %1").arg(cardInPcmcia0Name), 1 ); 109 tr( "Eject card 0: %1" ).arg(cardInPcmcia0Name ), 1 );
105 } 110 }
@@ -107,8 +112,8 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) {
107 if ( cardInPcmcia1 ) { 112 if ( cardInPcmcia1 ) {
108 menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia1Type )), 113 menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia1Type ) ),
109 tr("Eject card 1: %1").arg(cardInPcmcia1Name), 2 ); 114 tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 );
110 } 115 }
111 116
112 QPoint p = mapToGlobal ( QPoint ( 0, 0 )); 117 QPoint p = mapToGlobal ( QPoint ( 0, 0 ) );
113 QSize s = menu->sizeHint ( ); 118 QSize s = menu->sizeHint ();
114 int opt = menu->exec( QPoint ( 119 int opt = menu->exec( QPoint (
@@ -118,25 +123,31 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) {
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 ) ) {
123 qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", err); 127 qDebug( "Could not execute `/sbin/cardctl eject 0'! err=%d", err );
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 ) {
127 cmd = "/etc/sdcontrol compeject"; 131 if ( ODevice::inst()->system() == OSYSTEM_Familiar ) {
128 err = system( (const char *) cmd ); 132 cmd = "umount /dev/mmc/part1";
129 if ( ( err != 0 ) ) { 133 err = system( ( const char *) cmd );
130 qDebug("Could not execute `/etc/sdcontrol comeject'! err=%d", err); 134 if ( ( err != 0 ) ) {
131 popUp( tr("SD/MMC card eject failed!")); 135 popUp( tr("SD/MMC card eject failed!") );
132 } 136 }
137 } else {
138 cmd = "/etc/sdcontrol compeject";
139 err = system( ( const char *) cmd );
140 if ( ( err != 0 ) ) {
141 qDebug( "Could not execute `/etc/sdcontrol comeject'! err=%d", err );
142 popUp( tr("SD/MMC card eject failed!") );
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 );
136 if ( ( err == 127 ) || ( err < 0 ) ) { 148 if ( ( err == 127 ) || ( err < 0 ) ) {
137 qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", err); 149 qDebug( "Could not execute `/sbin/cardctl eject 1'! err=%d", err );
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;
@@ -147,10 +158,10 @@ void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) {
147 if ( msg == "stabChanged()" ) { 158 if ( msg == "stabChanged()" ) {
148 // qDebug("Pcmcia: stabchanged"); 159 // qDebug("Pcmcia: stabchanged");
149 if ( getStatusPcmcia() ) { 160 if ( getStatusPcmcia() ) {
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 }
@@ -167,68 +178,78 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) {
167 // one of these 3 files should exist 178 // one of these 3 files should exist
168 if (QFile::exists("/var/run/stab")) { 179 if ( QFile::exists( "/var/run/stab" ) ) {
169 fileName = "/var/run/stab"; 180 fileName = "/var/run/stab";
170 } else if (QFile::exists("/var/state/pcmcia/stab")) { 181 } else if (QFile::exists( "/var/state/pcmcia/stab" ) ) {
171 fileName="/var/state/pcmcia/stab"; 182 fileName = "/var/state/pcmcia/stab";
172 } else { 183 } else {
173 fileName="/var/lib/pcmcia/stab"; 184 fileName = "/var/lib/pcmcia/stab";
174 } 185 }
175 186
176 QFile f(fileName); 187 QFile f( fileName );
177 188
178 if ( f.open(IO_ReadOnly) ) { 189 if ( f.open( IO_ReadOnly ) ) {
179 QStringList list; 190 QStringList list;
180 QTextStream stream ( &f); 191 QTextStream stream ( &f );
181 QString streamIn; 192 QString streamIn;
182 streamIn = stream.read(); 193 streamIn = stream.read();
183 list = QStringList::split("\n", streamIn); 194 list = QStringList::split( "\n", streamIn );
184 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { 195 for( QStringList::Iterator line=list.begin(); line!=list.end(); line++ ) {
185 if( (*line).startsWith("Socket 0:") ){ 196 if( (*line).startsWith( "Socket 0:" ) ){
186 if( (*line).startsWith("Socket 0: empty") && cardInPcmcia0 ){ 197 if( (*line).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ){
187 cardInPcmcia0 = FALSE; 198 cardInPcmcia0 = FALSE;
188 } else if ( !(*line).startsWith("Socket 0: empty") && !cardInPcmcia0 ){ 199 } else if ( !(*line).startsWith( "Socket 0: empty" ) && !cardInPcmcia0 ){
189 cardInPcmcia0Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 ); 200 cardInPcmcia0Name = (*line).mid( ( (*line).find( ':' ) + 1 ), (*line).length() - 9 );
190 cardInPcmcia0Name.stripWhiteSpace(); 201 cardInPcmcia0Name.stripWhiteSpace();
191 cardInPcmcia0 = TRUE; 202 cardInPcmcia0 = TRUE;
192 show(); 203 show();
193 line++; 204 line++;
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:") ){ 209 if( (*line).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) {
199 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 ) {
202 cardInPcmcia1Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 ); 212 cardInPcmcia1Name = (*line).mid(((*line).find(':') + 1), (*line).length() - 9 );
203 cardInPcmcia1Name.stripWhiteSpace(); 213 cardInPcmcia1Name.stripWhiteSpace();
204 cardInPcmcia1 = TRUE; 214 cardInPcmcia1 = TRUE;
205 show(); 215 show();
206 line++; 216 line++;
207 int pos=(*line).find('\t')+1; 217 int pos=(*line).find('\t') + 1;
208 cardInPcmcia1Type = (*line).mid( pos, (*line).find("\t", pos) - pos); 218 cardInPcmcia1Type = (*line).mid( pos, (*line).find("\t", pos) - pos );
209 } 219 }
210 } 220 }
211 } 221 }
212 f.close(); 222 f.close();
213 if( !showPopUp && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1)) { 223
214 QString text = QString::null; 224 if( !showPopUp && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1) ) {
215 QString what = QString::null; 225 QString text = QString::null;
216 if(cardWas0 != cardInPcmcia0) { 226 QString what = QString::null;
217 if(cardInPcmcia0) { text += tr("New card: "); what="on";} 227 if(cardWas0 != cardInPcmcia0) {
218 else { text += tr("Ejected: "); what="off";} 228 if(cardInPcmcia0) {
219 text += cardInPcmcia0Name; 229 text += tr( "New card: " );
220 popUp( text, "cardmon/" + cardInPcmcia0Type ); 230 what="on";
221 } 231 } else {
222 if(cardWas1 != cardInPcmcia1) { 232 text += tr( "Ejected: " );
223 if(cardInPcmcia1) { text += tr("New card: "); what="on";} 233 what="off";
224 else { text += tr("Ejected: "); what="off";} 234 }
225 text += cardInPcmcia1Name; 235 text += cardInPcmcia0Name;
226 popUp( text, "cardmon/" + cardInPcmcia1Type ); 236 popUp( text, "cardmon/" + cardInPcmcia0Type );
227 } 237 }
228 QSound::play(Resource::findSound("cardmon/card" + what));
229 }
230 238
239 if( cardWas1 != cardInPcmcia1) {
240 if( cardInPcmcia1) {
241 text += tr( "New card: " );
242 what = "on";
243 } else {
244 text += tr( "Ejected: " );
245 what = "off";
246 }
247 text += cardInPcmcia1Name;
248 popUp( text, "cardmon/" + cardInPcmcia1Type );
249 }
250 QSound::play( Resource::findSound( "cardmon/card" + what) );
251 }
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;
@@ -236,4 +257,3 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) {
236 } 257 }
237 258 return ( (cardWas0 == cardInPcmcia0 && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE );
238 return ((cardWas0 == cardInPcmcia0 && cardWas1 == cardInPcmcia1) ? FALSE : TRUE);
239} 259}
@@ -243,4 +263,3 @@ 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
@@ -251,6 +270,10 @@ 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 }
@@ -259,9 +282,17 @@ bool CardMonitor::getStatusSd( int showPopUp ) {
259 } 282 }
260 if(!showPopUp && cardWas != cardInSd) {
261 QString text = QString::null;
262 if(cardInSd) { text += "SD Inserted"; }
263 else { text += "SD Removed"; }
264 popUp( text); // XX add SD pic
265 }
266 283
284 if( !showPopUp && cardWas != cardInSd ) {
285 QString text = QString::null;
286 QString what = QString::null;
287 if( cardInSd ) {
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
297 }
267#else 298#else
@@ -269,3 +300,3 @@ bool CardMonitor::getStatusSd( int showPopUp ) {
269#endif 300#endif
270 return ((cardWas == cardInSd) ? FALSE : TRUE); 301 return ( ( cardWas == cardInSd) ? FALSE : TRUE );
271} 302}
@@ -273,2 +304,3 @@ bool CardMonitor::getStatusSd( int showPopUp ) {
273void CardMonitor::paintEvent( QPaintEvent * ) { 304void CardMonitor::paintEvent( QPaintEvent * ) {
305
274 QPainter p( this ); 306 QPainter p( this );
@@ -276,7 +308,7 @@ void CardMonitor::paintEvent( QPaintEvent * ) {
276 if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { 308 if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) {
277 p.drawPixmap( 0, 0, pm ); 309 p.drawPixmap( 0, 0, pm );
278 show(); 310 show();
279 } else { 311 } else {
280 p.eraseRect( rect() ); 312 p.eraseRect( rect() );
281 hide(); 313 hide();
282 } 314 }
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
@@ -8,3 +8,3 @@ INCLUDEPATH += $(OPIEDIR)/include
8DEPENDPATH += $(OPIEDIR)/include ../launcher 8DEPENDPATH += $(OPIEDIR)/include ../launcher
9LIBS += -lqpe 9LIBS += -lqpe -lopie
10 VERSION = 1.0.0 10 VERSION = 1.0.0