summaryrefslogtreecommitdiff
Unidiff
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
@@ -20,8 +20,10 @@
20#include "cardmon.h" 20#include "cardmon.h"
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>
27#include <qfile.h> 29#include <qfile.h>
@@ -40,51 +42,54 @@
40#include <mntent.h> 42#include <mntent.h>
41#endif 43#endif
42 44
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
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 );
59 getStatusSd(TRUE); 62 getStatusSd( TRUE );
60 repaint(FALSE); 63 repaint( FALSE );
61 popupMenu = 0; 64 popupMenu = 0;
62} 65}
63 66
64CardMonitor::~CardMonitor() { 67CardMonitor::~CardMonitor() {
65 if( popupMenu ) { delete popupMenu; } 68 if( popupMenu ) {
69 delete popupMenu;
70 }
66} 71}
67 72
68void CardMonitor::popUp( QString message, QString icon ) { 73void 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 ) );
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}
88 93
89void CardMonitor::popupTimeout() { 94void CardMonitor::popupTimeout() {
90 popupMenu->hide(); 95 popupMenu->hide();
@@ -99,61 +104,67 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) {
99 menu->insertItem( tr("Eject SD/MMC card"), 0 ); 104 menu->insertItem( tr("Eject SD/MMC card"), 0 );
100 } 105 }
101 106
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 }
106 111
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 (
115 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), 120 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ),
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 ) ) {
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;
143} 154}
144 155
145 156
146void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) { 157void 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 }
157 } 168 }
158} 169}
159 170
@@ -164,120 +175,141 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) {
164 175
165 QString fileName; 176 QString fileName;
166 177
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;
235 cardInPcmcia1 = FALSE; 256 cardInPcmcia1 = FALSE;
236 } 257 }
237 258 return ( (cardWas0 == cardInPcmcia0 && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE );
238 return ((cardWas0 == cardInPcmcia0 && cardWas1 == cardInPcmcia1) ? FALSE : TRUE);
239} 259}
240 260
241 261
242bool CardMonitor::getStatusSd( int showPopUp ) { 262bool 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;
249 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 268 FILE *mntfp = setmntent( "/etc/mtab", "r" );
250 269
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 }
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
268#error "Not on Linux" 299#error "Not on Linux"
269#endif 300#endif
270 return ((cardWas == cardInSd) ? FALSE : TRUE); 301 return ( ( cardWas == cardInSd) ? FALSE : TRUE );
271} 302}
272 303
273void CardMonitor::paintEvent( QPaintEvent * ) { 304void CardMonitor::paintEvent( QPaintEvent * ) {
305
274 QPainter p( this ); 306 QPainter p( this );
275 307
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 }
283} 315}
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
@@ -5,9 +5,9 @@ SOURCES = cardmon.cpp cardmonimpl.cpp
5 TARGET = cardmonapplet 5 TARGET = cardmonapplet
6 DESTDIR = $(OPIEDIR)/plugins/applets 6 DESTDIR = $(OPIEDIR)/plugins/applets
7INCLUDEPATH += $(OPIEDIR)/include 7INCLUDEPATH += $(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
11 11
12TRANSLATIONS = ../../../i18n/de/libcardmonapplet.ts \ 12TRANSLATIONS = ../../../i18n/de/libcardmonapplet.ts \
13 ../../../i18n/en/libcardmonapplet.ts \ 13 ../../../i18n/en/libcardmonapplet.ts \