author | mickeyl <mickeyl> | 2005-05-19 14:25:34 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-05-19 14:25:34 (UTC) |
commit | 7fcfce8388df1805327f21d4cc41d7f5f54c6e6a (patch) (unidiff) | |
tree | 80409a535f74f4d5c5131f2eeb9f064a492f0cb8 /core/applets/cardmon/pcmcia.cpp | |
parent | 77134583c00446fc74515889514571924e7471ed (diff) | |
download | opie-7fcfce8388df1805327f21d4cc41d7f5f54c6e6a.zip opie-7fcfce8388df1805327f21d4cc41d7f5f54c6e6a.tar.gz opie-7fcfce8388df1805327f21d4cc41d7f5f54c6e6a.tar.bz2 |
write card log
Diffstat (limited to 'core/applets/cardmon/pcmcia.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/applets/cardmon/pcmcia.cpp | 284 |
1 files changed, 81 insertions, 203 deletions
diff --git a/core/applets/cardmon/pcmcia.cpp b/core/applets/cardmon/pcmcia.cpp index 2486f17..5183572 100644 --- a/core/applets/cardmon/pcmcia.cpp +++ b/core/applets/cardmon/pcmcia.cpp | |||
@@ -34,3 +34,5 @@ | |||
34 | #include <opie2/odevice.h> | 34 | #include <opie2/odevice.h> |
35 | #include <opie2/oconfig.h> | ||
35 | #include <opie2/oprocess.h> | 36 | #include <opie2/oprocess.h> |
37 | #include <opie2/opcmciasystem.h> | ||
36 | #include <opie2/oresource.h> | 38 | #include <opie2/oresource.h> |
@@ -47,2 +49,3 @@ using namespace Opie::Ui; | |||
47 | #include <qtextstream.h> | 49 | #include <qtextstream.h> |
50 | #include <qmessagebox.h> | ||
48 | #include <qsound.h> | 51 | #include <qsound.h> |
@@ -63,8 +66,2 @@ PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ) | |||
63 | { | 66 | { |
64 | pm = Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon ); | ||
65 | #if 0 | ||
66 | QCopChannel *channel = new QCopChannel("QPE/System", this); | ||
67 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), | ||
68 | this, SLOT(systemMsg(const QCString&,const QByteArray&)) ); | ||
69 | #endif | ||
70 | QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); | 67 | QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); |
@@ -74,20 +71,6 @@ PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ) | |||
74 | 71 | ||
75 | QCopChannel *sdChannel = new QCopChannel( "QPE/Card", this ); | ||
76 | connect( sdChannel, | ||
77 | SIGNAL( received(const QCString&,const QByteArray&) ), this, | ||
78 | SLOT( cardMessage(const QCString&,const QByteArray&) ) ); | ||
79 | |||
80 | cardInPcmcia0 = FALSE; | ||
81 | cardInPcmcia1 = FALSE; | ||
82 | cardInSd = FALSE; | ||
83 | |||
84 | setFocusPolicy( NoFocus ); | 72 | setFocusPolicy( NoFocus ); |
85 | |||
86 | setFixedWidth ( AppLnk::smallIconSize() ); | 73 | setFixedWidth ( AppLnk::smallIconSize() ); |
87 | setFixedHeight ( AppLnk::smallIconSize() ); | 74 | setFixedHeight ( AppLnk::smallIconSize() ); |
88 | 75 | pm = Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon ); | |
89 | getStatusPcmcia( TRUE ); | ||
90 | getStatusSd( TRUE ); | ||
91 | repaint( FALSE ); | ||
92 | popupMenu = 0; | ||
93 | } | 76 | } |
@@ -97,3 +80,2 @@ PcmciaManager::~PcmciaManager() | |||
97 | { | 80 | { |
98 | delete popupMenu; | ||
99 | } | 81 | } |
@@ -130,3 +112,3 @@ void PcmciaManager::popupTimeout() | |||
130 | 112 | ||
131 | void PcmciaManager::mousePressEvent( QMouseEvent * ) | 113 | void PcmciaManager::mousePressEvent( QMouseEvent* ) |
132 | { | 114 | { |
@@ -136,2 +118,16 @@ void PcmciaManager::mousePressEvent( QMouseEvent * ) | |||
136 | 118 | ||
119 | OPcmciaSystem* sys = OPcmciaSystem::instance(); | ||
120 | OPcmciaSystem::CardIterator it = sys->iterator(); | ||
121 | if ( !sys->count() ) return; | ||
122 | |||
123 | int i = 0; | ||
124 | while ( it.current() ) | ||
125 | { | ||
126 | menu->insertItem( tr( "Eject card %1: %2" ).arg( i++ ).arg( it.currentKey() ), 1 ); | ||
127 | ++it; | ||
128 | } | ||
129 | |||
130 | |||
131 | /* insert items depending on number of cards etc. | ||
132 | |||
137 | if ( cardInSd ) { | 133 | if ( cardInSd ) { |
@@ -141,2 +137,4 @@ void PcmciaManager::mousePressEvent( QMouseEvent * ) | |||
141 | 137 | ||
138 | |||
139 | |||
142 | if ( cardInPcmcia0 ) { | 140 | if ( cardInPcmcia0 ) { |
@@ -154,2 +152,3 @@ void PcmciaManager::mousePressEvent( QMouseEvent * ) | |||
154 | } | 152 | } |
153 | */ | ||
155 | 154 | ||
@@ -157,20 +156,4 @@ void PcmciaManager::mousePressEvent( QMouseEvent * ) | |||
157 | QSize s = menu->sizeHint(); | 156 | QSize s = menu->sizeHint(); |
158 | int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), | 157 | int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 ); |
159 | p.y() - s.height() ), 0 ); | 158 | qDebug( "pcmcia: menu result = %d", opt ); |
160 | |||
161 | if ( opt == 1 ) { | ||
162 | m_commandOrig = PCMCIA_Socket1; | ||
163 | cmd << "/sbin/cardctl" << "eject" << "0"; | ||
164 | } else if ( opt == 0 ) { | ||
165 | m_commandOrig = MMC_Socket; | ||
166 | cmd << "umount" << cardSdName; | ||
167 | } else if ( opt == 2 ) { | ||
168 | m_commandOrig = PCMCIA_Socket2; | ||
169 | cmd << "/sbin/cardctl" << "eject" << "1"; | ||
170 | }else | ||
171 | execute = false; | ||
172 | |||
173 | if ( execute ) | ||
174 | execCommand( cmd ); | ||
175 | |||
176 | delete menu; | 159 | delete menu; |
@@ -181,177 +164,72 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) | |||
181 | { | 164 | { |
182 | if ( msg == "stabChanged()" ) { | 165 | odebug << "PcmciaManager::cardMessage( '" << msg << "' )" << oendl; |
183 | // odebug << "Pcmcia: stabchanged" << oendl; | 166 | if ( msg != "stabChanged()" ) return; |
184 | getStatusPcmcia(); | 167 | |
185 | } else if ( msg == "mtabChanged()" ) { | 168 | /* check if a previously unknown card has been inserted */ |
186 | // odebug << "CARDMONAPPLET: mtabchanged" << oendl; | 169 | OPcmciaSystem::instance()->synchronize(); |
187 | getStatusSd(); | 170 | |
188 | } | 171 | if ( !OPcmciaSystem::instance()->count() ) return; |
189 | } | 172 | |
190 | 173 | OConfig cfg( "PCMCIA" ); | |
191 | 174 | cfg.setGroup( "Global" ); | |
192 | bool PcmciaManager::getStatusPcmcia( int showPopUp ) { | 175 | int nCards = cfg.readNumEntry( "nCards", 0 ); |
193 | 176 | ||
194 | bool cardWas0 = cardInPcmcia0; // remember last state | 177 | OPcmciaSystem* sys = OPcmciaSystem::instance(); |
195 | bool cardWas1 = cardInPcmcia1; | 178 | OPcmciaSystem::CardIterator it = sys->iterator(); |
196 | 179 | ||
197 | QString fileName; | 180 | bool newCard = true; |
198 | 181 | while ( it.current() && newCard ) | |
199 | if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; } | 182 | { |
200 | else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; } | 183 | QString name = it.currentKey(); |
201 | else { fileName = "/var/lib/pcmcia/stab"; } | 184 | for ( int i = 0; i < nCards; ++i ) |
202 | 185 | { | |
203 | QFile f( fileName ); | 186 | QString cardSection = QString( "Card_%1" ).arg( i ); |
204 | 187 | cfg.setGroup( cardSection ); | |
205 | if ( f.open( IO_ReadOnly ) ) { | 188 | QString cardName = cfg.readEntry( "name" ); |
206 | QStringList list; | 189 | odebug << "comparing card '" << name << "' with known card '" << cardName << "'" << oendl; |
207 | QTextStream stream( &f ); | 190 | if ( cardName == name ) |
208 | QString streamIn; | 191 | { |
209 | streamIn = stream.read(); | 192 | newCard = false; |
210 | list = QStringList::split( "\n", streamIn ); | 193 | break; |
211 | for ( QStringList::Iterator line = list.begin(); line != list.end(); | ||
212 | line++ ) { | ||
213 | if ( ( *line ).startsWith( "Socket 0:" ) ) { | ||
214 | if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ) { | ||
215 | cardInPcmcia0 = FALSE; | ||
216 | } else if ( !( *line ).startsWith( "Socket 0: empty" ) | ||
217 | && !cardInPcmcia0 ) { | ||
218 | cardInPcmcia0Name = | ||
219 | ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), | ||
220 | ( *line ).length() - 9 ); | ||
221 | cardInPcmcia0Name.stripWhiteSpace(); | ||
222 | cardInPcmcia0 = TRUE; | ||
223 | show(); | ||
224 | line++; | ||
225 | int pos = ( *line ).find( '\t' ) + 1; | ||
226 | cardInPcmcia0Type = | ||
227 | ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); | ||
228 | } | ||
229 | } else if ( ( *line ).startsWith( "Socket 1:" ) ) { | ||
230 | if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) { | ||
231 | cardInPcmcia1 = FALSE; | ||
232 | } else if ( !( *line ).startsWith( "Socket 1: empty" ) | ||
233 | && !cardInPcmcia1 ) { | ||
234 | cardInPcmcia1Name = | ||
235 | ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), | ||
236 | ( *line ).length() - 9 ); | ||
237 | cardInPcmcia1Name.stripWhiteSpace(); | ||
238 | cardInPcmcia1 = TRUE; | ||
239 | show(); | ||
240 | line++; | ||
241 | int pos = ( *line ).find( '\t' ) + 1; | ||
242 | cardInPcmcia1Type = | ||
243 | ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); | ||
244 | } | ||
245 | } | 194 | } |
246 | } | 195 | } |
247 | f.close(); | 196 | if ( !newCard ) ++it; else break; |
248 | |||
249 | if ( !showPopUp | ||
250 | && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) ) { | ||
251 | QString text = QString::null; | ||
252 | QString what = QString::null; | ||
253 | if ( cardWas0 != cardInPcmcia0 ) { | ||
254 | if ( cardInPcmcia0 ) { | ||
255 | text += tr( "New card: " ); | ||
256 | what = "on"; | ||
257 | } else { | ||
258 | text += tr( "Ejected: " ); | ||
259 | what = "off"; | ||
260 | } | ||
261 | text += cardInPcmcia0Name; | ||
262 | popUp( text, "cardmon/" + cardInPcmcia0Type ); | ||
263 | } | ||
264 | |||
265 | if ( cardWas1 != cardInPcmcia1 ) { | ||
266 | if ( cardInPcmcia1 ) { | ||
267 | text += tr( "New card: " ); | ||
268 | what = "on"; | ||
269 | } else { | ||
270 | text += tr( "Ejected: " ); | ||
271 | what = "off"; | ||
272 | } | ||
273 | text += cardInPcmcia1Name; | ||
274 | popUp( text, "cardmon/" + cardInPcmcia1Type ); | ||
275 | } | ||
276 | #ifndef QT_NO_SOUND | ||
277 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); | ||
278 | #endif | ||
279 | |||
280 | } | ||
281 | } else { | ||
282 | // no file found | ||
283 | odebug << "no file found" << oendl; | ||
284 | cardInPcmcia0 = FALSE; | ||
285 | cardInPcmcia1 = FALSE; | ||
286 | } | 197 | } |
198 | QString newCardName = it.currentKey(); | ||
199 | |||
200 | if ( newCard ) | ||
201 | { | ||
202 | odebug << "pcmcia: new card detected" << oendl; | ||
203 | cfg.setGroup( QString( "Card_%1" ).arg( nCards ) ); | ||
204 | cfg.writeEntry( "name", newCardName ); | ||
205 | cfg.setGroup( "Global" ); | ||
206 | cfg.writeEntry( "nCards", nCards+1 ); | ||
207 | cfg.write(); | ||
208 | |||
209 | int result = QMessageBox::information( qApp->desktop(), | ||
210 | tr( "PCMCIA/CF Subsystem" ), | ||
211 | tr( "You have inserted a new card\n%1\nDo you want to configure this card?" ).arg( newCardName ), | ||
212 | tr( "Yes" ), tr( "No" ), 0, 0, 1 ); | ||
213 | odebug << "result = " << result << oendl; | ||
287 | 214 | ||
288 | repaint( FALSE ); | ||
289 | return ( ( cardWas0 == cardInPcmcia0 | ||
290 | && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE ); | ||
291 | |||
292 | } | ||
293 | |||
294 | |||
295 | bool PcmciaManager::getStatusSd( int showPopUp ) | ||
296 | { | ||
297 | |||
298 | bool cardWas = cardInSd; // remember last state | ||
299 | cardInSd = FALSE; | ||
300 | |||
301 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | ||
302 | |||
303 | struct mntent *me; | ||
304 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); | ||
305 | |||
306 | if ( mntfp ) { | ||
307 | while ( ( me = getmntent( mntfp ) ) != 0 ) { | ||
308 | QString fs = QFile::decodeName( me->mnt_fsname ); | ||
309 | //odebug << fs << oendl; | ||
310 | if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd" | ||
311 | || fs.left( 9 ) == "/dev/mmcd" || fs.left(11) == "/dev/mmcblk" ) { | ||
312 | cardInSd = TRUE; | ||
313 | cardSdName = fs; | ||
314 | show(); | ||
315 | } | ||
316 | // else { | ||
317 | // cardInSd = FALSE; | ||
318 | // } | ||
319 | } | ||
320 | endmntent( mntfp ); | ||
321 | } | 215 | } |
322 | 216 | else | |
323 | if ( !showPopUp && cardWas != cardInSd ) { | 217 | { |
324 | QString text = QString::null; | 218 | odebug << "pcmcia: card has been previously inserted" << oendl; |
325 | QString what = QString::null; | ||
326 | if ( cardInSd ) { | ||
327 | text += tr("New card: SD/MMC"); | ||
328 | what = "on"; | ||
329 | } else { | ||
330 | text += tr("Ejected: SD/MMC"); | ||
331 | what = "off"; | ||
332 | } | ||
333 | //odebug << "TEXT: " + text << oendl; | ||
334 | #ifndef QT_NO_SOUND | ||
335 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); | ||
336 | #endif | ||
337 | |||
338 | popUp( text, "cardmon/ide" ); // XX add SD pic | ||
339 | } | 219 | } |
340 | #else | 220 | repaint( TRUE ); |
341 | #error "Not on Linux" | ||
342 | #endif | ||
343 | repaint( FALSE ); | ||
344 | return ( ( cardWas == cardInSd ) ? FALSE : TRUE ); | ||
345 | } | 221 | } |
346 | 222 | ||
223 | |||
347 | void PcmciaManager::paintEvent( QPaintEvent * ) | 224 | void PcmciaManager::paintEvent( QPaintEvent * ) |
348 | { | 225 | { |
349 | |||
350 | QPainter p( this ); | 226 | QPainter p( this ); |
351 | 227 | qDebug( "count = %d", (OPcmciaSystem::instance()->count() ) ); | |
352 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { | 228 | if ( OPcmciaSystem::instance()->count() ) |
229 | { | ||
353 | p.drawPixmap( 0, 0, pm ); | 230 | p.drawPixmap( 0, 0, pm ); |
354 | show(); | 231 | show(); |
355 | } else { | 232 | } |
356 | //p.eraseRect(rect()); | 233 | else |
234 | { | ||
357 | hide(); | 235 | hide(); |