summaryrefslogtreecommitdiff
authorsandman <sandman>2002-09-30 21:10:57 (UTC)
committer sandman <sandman>2002-09-30 21:10:57 (UTC)
commitf02403852366623aef6f53258b237e467a25e597 (patch) (unidiff)
tree091ae74adbb8aad80d2055e775cb65e3c377ae87
parentf49ad5cf3bdc1d1c06be4615a649b6be6f179b83 (diff)
downloadopie-f02403852366623aef6f53258b237e467a25e597.zip
opie-f02403852366623aef6f53258b237e467a25e597.tar.gz
opie-f02403852366623aef6f53258b237e467a25e597.tar.bz2
small change to work with the new ODevice API
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/cardmon/cardmon.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp
index 583f2da..c0a936f 100644
--- a/core/applets/cardmon/cardmon.cpp
+++ b/core/applets/cardmon/cardmon.cpp
@@ -1,259 +1,261 @@
1/* 1/*
2 * cardmon.cpp 2 * cardmon.cpp
3 * 3 *
4 * --------------------- 4 * ---------------------
5 * 5 *
6 * copyright : (c) 2002 by Maximilian Reiss 6 * copyright : (c) 2002 by Maximilian Reiss
7 * email : max.reiss@gmx.de 7 * email : max.reiss@gmx.de
8 * based on two apps by Devin Butterfield 8 * based on two apps by Devin Butterfield
9 */ 9 */
10/*************************************************************************** 10/***************************************************************************
11 * * 11 * *
12 * This program is free software; you can redistribute it and/or modify * 12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by * 13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or * 14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. * 15 * (at your option) any later version. *
16 * * 16 * *
17 ***************************************************************************/ 17 ***************************************************************************/
18 18
19 19
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> 24#include <opie/odevice.h>
25 25
26#include <qcopchannel_qws.h> 26#include <qcopchannel_qws.h>
27#include <qpainter.h> 27#include <qpainter.h>
28#include <qmessagebox.h> 28#include <qmessagebox.h>
29#include <qfile.h> 29#include <qfile.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qtimer.h> 31#include <qtimer.h>
32 32
33#include <stdio.h> 33#include <stdio.h>
34#include <unistd.h> 34#include <unistd.h>
35#include <stdlib.h> 35#include <stdlib.h>
36#include <string.h> 36#include <string.h>
37#include <fcntl.h> 37#include <fcntl.h>
38#include <qsound.h> 38#include <qsound.h>
39 39
40#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 40#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
41#include <sys/vfs.h> 41#include <sys/vfs.h>
42#include <mntent.h> 42#include <mntent.h>
43#endif 43#endif
44 44
45using namespace Opie;
46
45CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ), 47CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ),
46 pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) { 48 pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) {
47 49
48 QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this ); 50 QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this );
49 connect( pcmciaChannel, SIGNAL( received( const QCString &, const QByteArray &) ), 51 connect( pcmciaChannel, SIGNAL( received( const QCString &, const QByteArray &) ),
50 this, SLOT( cardMessage( const QCString &, const QByteArray &) ) ); 52 this, SLOT( cardMessage( const QCString &, const QByteArray &) ) );
51 53
52 QCopChannel* sdChannel = new QCopChannel( "QPE/Card", this ); 54 QCopChannel* sdChannel = new QCopChannel( "QPE/Card", this );
53 connect( sdChannel, SIGNAL( received( const QCString &, const QByteArray &) ), 55 connect( sdChannel, SIGNAL( received( const QCString &, const QByteArray &) ),
54 this, SLOT( cardMessage( const QCString &, const QByteArray &) ) ); 56 this, SLOT( cardMessage( const QCString &, const QByteArray &) ) );
55 57
56 cardInPcmcia0 = FALSE; 58 cardInPcmcia0 = FALSE;
57 cardInPcmcia1 = FALSE; 59 cardInPcmcia1 = FALSE;
58 cardInSd = FALSE; 60 cardInSd = FALSE;
59 61
60 setFixedSize( pm.size() ); 62 setFixedSize( pm.size() );
61 getStatusPcmcia( TRUE ); 63 getStatusPcmcia( TRUE );
62 getStatusSd( TRUE ); 64 getStatusSd( TRUE );
63 repaint( FALSE ); 65 repaint( FALSE );
64 popupMenu = 0; 66 popupMenu = 0;
65} 67}
66 68
67CardMonitor::~CardMonitor() { 69CardMonitor::~CardMonitor() {
68 if( popupMenu ) { 70 if( popupMenu ) {
69 delete popupMenu; 71 delete popupMenu;
70 } 72 }
71} 73}
72 74
73void CardMonitor::popUp( QString message, QString icon ) { 75void CardMonitor::popUp( QString message, QString icon ) {
74 if ( ! popupMenu ) { 76 if ( ! popupMenu ) {
75 popupMenu = new QPopupMenu(); 77 popupMenu = new QPopupMenu();
76 } 78 }
77 79
78 popupMenu->clear(); 80 popupMenu->clear();
79 if( icon.isEmpty() ) { 81 if( icon.isEmpty() ) {
80 popupMenu->insertItem( message, 0 ); 82 popupMenu->insertItem( message, 0 );
81 } else { 83 } else {
82 popupMenu->insertItem( QIconSet ( Resource::loadPixmap ( icon ) ), message, 0 ); 84 popupMenu->insertItem( QIconSet ( Resource::loadPixmap ( icon ) ), message, 0 );
83 } 85 }
84 86
85 QPoint p = mapToGlobal ( QPoint ( 0, 0 ) ); 87 QPoint p = mapToGlobal ( QPoint ( 0, 0 ) );
86 QSize s = popupMenu->sizeHint (); 88 QSize s = popupMenu->sizeHint ();
87 popupMenu->popup( QPoint ( 89 popupMenu->popup( QPoint (
88 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), 90 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ),
89 p. y ( ) - s. height ( ) ), 0); 91 p. y ( ) - s. height ( ) ), 0);
90 92
91 QTimer::singleShot( 2000, this, SLOT(popupTimeout() ) ); 93 QTimer::singleShot( 2000, this, SLOT(popupTimeout() ) );
92} 94}
93 95
94void CardMonitor::popupTimeout() { 96void CardMonitor::popupTimeout() {
95 popupMenu->hide(); 97 popupMenu->hide();
96} 98}
97 99
98void CardMonitor::mousePressEvent( QMouseEvent * ) { 100void CardMonitor::mousePressEvent( QMouseEvent * ) {
99 QPopupMenu *menu = new QPopupMenu(); 101 QPopupMenu *menu = new QPopupMenu();
100 QString cmd; 102 QString cmd;
101 int err=0; 103 int err=0;
102 104
103 if ( cardInSd ) { 105 if ( cardInSd ) {
104 menu->insertItem( tr("Eject SD/MMC card"), 0 ); 106 menu->insertItem( tr("Eject SD/MMC card"), 0 );
105 } 107 }
106 108
107 if ( cardInPcmcia0 ) { 109 if ( cardInPcmcia0 ) {
108 menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia0Type ) ), 110 menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia0Type ) ),
109 tr( "Eject card 0: %1" ).arg(cardInPcmcia0Name ), 1 ); 111 tr( "Eject card 0: %1" ).arg(cardInPcmcia0Name ), 1 );
110 } 112 }
111 113
112 if ( cardInPcmcia1 ) { 114 if ( cardInPcmcia1 ) {
113 menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia1Type ) ), 115 menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia1Type ) ),
114 tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); 116 tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 );
115 } 117 }
116 118
117 QPoint p = mapToGlobal ( QPoint ( 0, 0 ) ); 119 QPoint p = mapToGlobal ( QPoint ( 0, 0 ) );
118 QSize s = menu->sizeHint (); 120 QSize s = menu->sizeHint ();
119 int opt = menu->exec( QPoint ( 121 int opt = menu->exec( QPoint (
120 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), 122 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ),
121 p. y ( ) - s. height ( ) ), 0); 123 p. y ( ) - s. height ( ) ), 0);
122 124
123 if ( opt == 1 ) { 125 if ( opt == 1 ) {
124 cmd = "/sbin/cardctl eject 0"; 126 cmd = "/sbin/cardctl eject 0";
125 err = system( ( const char * ) cmd ); 127 err = system( ( const char * ) cmd );
126 if ( ( err == 127 ) || ( err < 0 ) ) { 128 if ( ( err == 127 ) || ( err < 0 ) ) {
127 qDebug( "Could not execute `/sbin/cardctl eject 0'! err=%d", err ); 129 qDebug( "Could not execute `/sbin/cardctl eject 0'! err=%d", err );
128 popUp( tr( "CF/PCMCIA card eject failed!" ) ); 130 popUp( tr( "CF/PCMCIA card eject failed!" ) );
129 } 131 }
130 } else if ( opt == 0 ) { 132 } else if ( opt == 0 ) {
131 if ( ODevice::inst()->system() == OSYSTEM_Familiar ) { 133 if ( ODevice::inst()->system() == System_Familiar ) {
132 cmd = "umount /dev/mmc/part1"; 134 cmd = "umount /dev/mmc/part1";
133 err = system( ( const char *) cmd ); 135 err = system( ( const char *) cmd );
134 if ( ( err != 0 ) ) { 136 if ( ( err != 0 ) ) {
135 popUp( tr("SD/MMC card eject failed!") ); 137 popUp( tr("SD/MMC card eject failed!") );
136 } 138 }
137 } else { 139 } else {
138 cmd = "/etc/sdcontrol compeject"; 140 cmd = "/etc/sdcontrol compeject";
139 err = system( ( const char *) cmd ); 141 err = system( ( const char *) cmd );
140 if ( ( err != 0 ) ) { 142 if ( ( err != 0 ) ) {
141 qDebug( "Could not execute `/etc/sdcontrol comeject'! err=%d", err ); 143 qDebug( "Could not execute `/etc/sdcontrol comeject'! err=%d", err );
142 popUp( tr("SD/MMC card eject failed!") ); 144 popUp( tr("SD/MMC card eject failed!") );
143 } 145 }
144 } 146 }
145 } else if ( opt == 2 ) { 147 } else if ( opt == 2 ) {
146 cmd = "/sbin/cardctl eject 1"; 148 cmd = "/sbin/cardctl eject 1";
147 err = system( ( const char *) cmd ); 149 err = system( ( const char *) cmd );
148 if ( ( err == 127 ) || ( err < 0 ) ) { 150 if ( ( err == 127 ) || ( err < 0 ) ) {
149 qDebug( "Could not execute `/sbin/cardctl eject 1'! err=%d", err ); 151 qDebug( "Could not execute `/sbin/cardctl eject 1'! err=%d", err );
150 popUp( tr( "CF/PCMCIA card eject failed!" ) ); 152 popUp( tr( "CF/PCMCIA card eject failed!" ) );
151 } 153 }
152 } 154 }
153 delete menu; 155 delete menu;
154} 156}
155 157
156 158
157void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) { 159void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) {
158 if ( msg == "stabChanged()" ) { 160 if ( msg == "stabChanged()" ) {
159 // qDebug("Pcmcia: stabchanged"); 161 // qDebug("Pcmcia: stabchanged");
160 if ( getStatusPcmcia() ) { 162 if ( getStatusPcmcia() ) {
161 repaint( FALSE ); 163 repaint( FALSE );
162 } 164 }
163 } else if ( msg == "mtabChanged()" ) { 165 } else if ( msg == "mtabChanged()" ) {
164 qDebug("CARDMONAPPLET: mtabchanged"); 166 qDebug("CARDMONAPPLET: mtabchanged");
165 if ( getStatusSd() ) { 167 if ( getStatusSd() ) {
166 repaint( FALSE ); 168 repaint( FALSE );
167 } 169 }
168 } 170 }
169} 171}
170 172
171bool CardMonitor::getStatusPcmcia( int showPopUp ) { 173bool CardMonitor::getStatusPcmcia( int showPopUp ) {
172 174
173 bool cardWas0 = cardInPcmcia0; // remember last state 175 bool cardWas0 = cardInPcmcia0; // remember last state
174 bool cardWas1 = cardInPcmcia1; 176 bool cardWas1 = cardInPcmcia1;
175 177
176 QString fileName; 178 QString fileName;
177 179
178 // one of these 3 files should exist 180 // one of these 3 files should exist
179 if ( QFile::exists( "/var/run/stab" ) ) { 181 if ( QFile::exists( "/var/run/stab" ) ) {
180 fileName = "/var/run/stab"; 182 fileName = "/var/run/stab";
181 } else if (QFile::exists( "/var/state/pcmcia/stab" ) ) { 183 } else if (QFile::exists( "/var/state/pcmcia/stab" ) ) {
182 fileName = "/var/state/pcmcia/stab"; 184 fileName = "/var/state/pcmcia/stab";
183 } else { 185 } else {
184 fileName = "/var/lib/pcmcia/stab"; 186 fileName = "/var/lib/pcmcia/stab";
185 } 187 }
186 188
187 QFile f( fileName ); 189 QFile f( fileName );
188 190
189 if ( f.open( IO_ReadOnly ) ) { 191 if ( f.open( IO_ReadOnly ) ) {
190 QStringList list; 192 QStringList list;
191 QTextStream stream ( &f ); 193 QTextStream stream ( &f );
192 QString streamIn; 194 QString streamIn;
193 streamIn = stream.read(); 195 streamIn = stream.read();
194 list = QStringList::split( "\n", streamIn ); 196 list = QStringList::split( "\n", streamIn );
195 for( QStringList::Iterator line=list.begin(); line!=list.end(); line++ ) { 197 for( QStringList::Iterator line=list.begin(); line!=list.end(); line++ ) {
196 if( (*line).startsWith( "Socket 0:" ) ){ 198 if( (*line).startsWith( "Socket 0:" ) ){
197 if( (*line).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ){ 199 if( (*line).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ){
198 cardInPcmcia0 = FALSE; 200 cardInPcmcia0 = FALSE;
199 } else if ( !(*line).startsWith( "Socket 0: empty" ) && !cardInPcmcia0 ){ 201 } else if ( !(*line).startsWith( "Socket 0: empty" ) && !cardInPcmcia0 ){
200 cardInPcmcia0Name = (*line).mid( ( (*line).find( ':' ) + 1 ), (*line).length() - 9 ); 202 cardInPcmcia0Name = (*line).mid( ( (*line).find( ':' ) + 1 ), (*line).length() - 9 );
201 cardInPcmcia0Name.stripWhiteSpace(); 203 cardInPcmcia0Name.stripWhiteSpace();
202 cardInPcmcia0 = TRUE; 204 cardInPcmcia0 = TRUE;
203 show(); 205 show();
204 line++; 206 line++;
205 int pos=(*line).find('\t' ) + 1; 207 int pos=(*line).find('\t' ) + 1;
206 cardInPcmcia0Type = (*line).mid( pos, (*line).find( "\t" , pos) - pos ); 208 cardInPcmcia0Type = (*line).mid( pos, (*line).find( "\t" , pos) - pos );
207 } 209 }
208 } else if( (*line).startsWith( "Socket 1:" ) ){ 210 } else if( (*line).startsWith( "Socket 1:" ) ){
209 if( (*line).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) { 211 if( (*line).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) {
210 cardInPcmcia1 = FALSE; 212 cardInPcmcia1 = FALSE;
211 } else if ( !(*line).startsWith( "Socket 1: empty" ) && !cardInPcmcia1 ) { 213 } else if ( !(*line).startsWith( "Socket 1: empty" ) && !cardInPcmcia1 ) {
212 cardInPcmcia1Name = (*line).mid(((*line).find(':') + 1), (*line).length() - 9 ); 214 cardInPcmcia1Name = (*line).mid(((*line).find(':') + 1), (*line).length() - 9 );
213 cardInPcmcia1Name.stripWhiteSpace(); 215 cardInPcmcia1Name.stripWhiteSpace();
214 cardInPcmcia1 = TRUE; 216 cardInPcmcia1 = TRUE;
215 show(); 217 show();
216 line++; 218 line++;
217 int pos=(*line).find('\t') + 1; 219 int pos=(*line).find('\t') + 1;
218 cardInPcmcia1Type = (*line).mid( pos, (*line).find("\t", pos) - pos ); 220 cardInPcmcia1Type = (*line).mid( pos, (*line).find("\t", pos) - pos );
219 } 221 }
220 } 222 }
221 } 223 }
222 f.close(); 224 f.close();
223 225
224 if( !showPopUp && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1) ) { 226 if( !showPopUp && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1) ) {
225 QString text = QString::null; 227 QString text = QString::null;
226 QString what = QString::null; 228 QString what = QString::null;
227 if(cardWas0 != cardInPcmcia0) { 229 if(cardWas0 != cardInPcmcia0) {
228 if(cardInPcmcia0) { 230 if(cardInPcmcia0) {
229 text += tr( "New card: " ); 231 text += tr( "New card: " );
230 what="on"; 232 what="on";
231 } else { 233 } else {
232 text += tr( "Ejected: " ); 234 text += tr( "Ejected: " );
233 what="off"; 235 what="off";
234 } 236 }
235 text += cardInPcmcia0Name; 237 text += cardInPcmcia0Name;
236 popUp( text, "cardmon/" + cardInPcmcia0Type ); 238 popUp( text, "cardmon/" + cardInPcmcia0Type );
237 } 239 }
238 240
239 if( cardWas1 != cardInPcmcia1) { 241 if( cardWas1 != cardInPcmcia1) {
240 if( cardInPcmcia1) { 242 if( cardInPcmcia1) {
241 text += tr( "New card: " ); 243 text += tr( "New card: " );
242 what = "on"; 244 what = "on";
243 } else { 245 } else {
244 text += tr( "Ejected: " ); 246 text += tr( "Ejected: " );
245 what = "off"; 247 what = "off";
246 } 248 }
247 text += cardInPcmcia1Name; 249 text += cardInPcmcia1Name;
248 popUp( text, "cardmon/" + cardInPcmcia1Type ); 250 popUp( text, "cardmon/" + cardInPcmcia1Type );
249 } 251 }
250 QSound::play( Resource::findSound( "cardmon/card" + what) ); 252 QSound::play( Resource::findSound( "cardmon/card" + what) );
251 } 253 }
252 } else { 254 } else {
253 // no file found 255 // no file found
254 qDebug( "no file found" ); 256 qDebug( "no file found" );
255 cardInPcmcia0 = FALSE; 257 cardInPcmcia0 = FALSE;
256 cardInPcmcia1 = FALSE; 258 cardInPcmcia1 = FALSE;
257 } 259 }
258 return ( (cardWas0 == cardInPcmcia0 && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE ); 260 return ( (cardWas0 == cardInPcmcia0 && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE );
259} 261}