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 | |
parent | 77134583c00446fc74515889514571924e7471ed (diff) | |
download | opie-7fcfce8388df1805327f21d4cc41d7f5f54c6e6a.zip opie-7fcfce8388df1805327f21d4cc41d7f5f54c6e6a.tar.gz opie-7fcfce8388df1805327f21d4cc41d7f5f54c6e6a.tar.bz2 |
write card log
-rw-r--r-- | core/applets/cardmon/pcmcia.cpp | 264 | ||||
-rw-r--r-- | core/applets/cardmon/pcmcia.h | 25 |
2 files changed, 76 insertions, 213 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 | |||
@@ -33,5 +33,7 @@ | |||
33 | #include <opie2/odebug.h> | 33 | #include <opie2/odebug.h> |
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> |
37 | #include <opie2/otaskbarapplet.h> | 39 | #include <opie2/otaskbarapplet.h> |
@@ -46,4 +48,5 @@ using namespace Opie::Ui; | |||
46 | #include <qfile.h> | 48 | #include <qfile.h> |
47 | #include <qtextstream.h> | 49 | #include <qtextstream.h> |
50 | #include <qmessagebox.h> | ||
48 | #include <qsound.h> | 51 | #include <qsound.h> |
49 | #include <qtimer.h> | 52 | #include <qtimer.h> |
@@ -62,10 +65,4 @@ using namespace Opie::Ui; | |||
62 | PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ) | 65 | 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 ); |
71 | connect( pcmciaChannel, | 68 | connect( pcmciaChannel, |
@@ -73,22 +70,8 @@ PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ) | |||
73 | SLOT( cardMessage(const QCString&,const QByteArray&) ) ); | 70 | SLOT( cardMessage(const QCString&,const QByteArray&) ) ); |
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 | } |
94 | 77 | ||
@@ -96,5 +79,4 @@ PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ) | |||
96 | PcmciaManager::~PcmciaManager() | 79 | PcmciaManager::~PcmciaManager() |
97 | { | 80 | { |
98 | delete popupMenu; | ||
99 | } | 81 | } |
100 | 82 | ||
@@ -135,4 +117,18 @@ void PcmciaManager::mousePressEvent( QMouseEvent * ) | |||
135 | bool execute = true; | 117 | bool execute = true; |
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 ) { |
138 | menu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( "cardmon/ide", Opie::Core::OResource::SmallIcon ) ), | 134 | menu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( "cardmon/ide", Opie::Core::OResource::SmallIcon ) ), |
@@ -140,4 +136,6 @@ void PcmciaManager::mousePressEvent( QMouseEvent * ) | |||
140 | } | 136 | } |
141 | 137 | ||
138 | |||
139 | |||
142 | if ( cardInPcmcia0 ) { | 140 | if ( cardInPcmcia0 ) { |
143 | menu-> | 141 | menu-> |
@@ -153,25 +151,10 @@ void PcmciaManager::mousePressEvent( QMouseEvent * ) | |||
153 | tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); | 151 | tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); |
154 | } | 152 | } |
153 | */ | ||
155 | 154 | ||
156 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); | 155 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); |
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; |
177 | } | 160 | } |
@@ -180,179 +163,74 @@ void PcmciaManager::mousePressEvent( QMouseEvent * ) | |||
180 | void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) | 163 | 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(); | ||
185 | } else if ( msg == "mtabChanged()" ) { | ||
186 | // odebug << "CARDMONAPPLET: mtabchanged" << oendl; | ||
187 | getStatusSd(); | ||
188 | } | ||
189 | } | ||
190 | 167 | ||
168 | /* check if a previously unknown card has been inserted */ | ||
169 | OPcmciaSystem::instance()->synchronize(); | ||
191 | 170 | ||
192 | bool PcmciaManager::getStatusPcmcia( int showPopUp ) { | 171 | if ( !OPcmciaSystem::instance()->count() ) return; |
193 | |||
194 | bool cardWas0 = cardInPcmcia0; // remember last state | ||
195 | bool cardWas1 = cardInPcmcia1; | ||
196 | |||
197 | QString fileName; | ||
198 | |||
199 | if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; } | ||
200 | else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; } | ||
201 | else { fileName = "/var/lib/pcmcia/stab"; } | ||
202 | |||
203 | QFile f( fileName ); | ||
204 | |||
205 | if ( f.open( IO_ReadOnly ) ) { | ||
206 | QStringList list; | ||
207 | QTextStream stream( &f ); | ||
208 | QString streamIn; | ||
209 | streamIn = stream.read(); | ||
210 | list = QStringList::split( "\n", streamIn ); | ||
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 | } | ||
246 | } | ||
247 | f.close(); | ||
248 | 172 | ||
249 | if ( !showPopUp | 173 | OConfig cfg( "PCMCIA" ); |
250 | && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) ) { | 174 | cfg.setGroup( "Global" ); |
251 | QString text = QString::null; | 175 | int nCards = cfg.readNumEntry( "nCards", 0 ); |
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 | 176 | ||
265 | if ( cardWas1 != cardInPcmcia1 ) { | 177 | OPcmciaSystem* sys = OPcmciaSystem::instance(); |
266 | if ( cardInPcmcia1 ) { | 178 | OPcmciaSystem::CardIterator it = sys->iterator(); |
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 | 179 | ||
180 | bool newCard = true; | ||
181 | while ( it.current() && newCard ) | ||
182 | { | ||
183 | QString name = it.currentKey(); | ||
184 | for ( int i = 0; i < nCards; ++i ) | ||
185 | { | ||
186 | QString cardSection = QString( "Card_%1" ).arg( i ); | ||
187 | cfg.setGroup( cardSection ); | ||
188 | QString cardName = cfg.readEntry( "name" ); | ||
189 | odebug << "comparing card '" << name << "' with known card '" << cardName << "'" << oendl; | ||
190 | if ( cardName == name ) | ||
191 | { | ||
192 | newCard = false; | ||
193 | break; | ||
280 | } | 194 | } |
281 | } else { | ||
282 | // no file found | ||
283 | odebug << "no file found" << oendl; | ||
284 | cardInPcmcia0 = FALSE; | ||
285 | cardInPcmcia1 = FALSE; | ||
286 | } | 195 | } |
287 | 196 | if ( !newCard ) ++it; else break; | |
288 | repaint( FALSE ); | ||
289 | return ( ( cardWas0 == cardInPcmcia0 | ||
290 | && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE ); | ||
291 | |||
292 | } | 197 | } |
198 | QString newCardName = it.currentKey(); | ||
293 | 199 | ||
294 | 200 | if ( newCard ) | |
295 | bool PcmciaManager::getStatusSd( int showPopUp ) | ||
296 | { | 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(); | ||
297 | 208 | ||
298 | bool cardWas = cardInSd; // remember last state | 209 | int result = QMessageBox::information( qApp->desktop(), |
299 | cardInSd = FALSE; | 210 | tr( "PCMCIA/CF Subsystem" ), |
300 | 211 | tr( "You have inserted a new card\n%1\nDo you want to configure this card?" ).arg( newCardName ), | |
301 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 212 | tr( "Yes" ), tr( "No" ), 0, 0, 1 ); |
213 | odebug << "result = " << result << oendl; | ||
302 | 214 | ||
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 | } | 215 | } |
316 | // else { | 216 | else |
317 | // cardInSd = FALSE; | 217 | { |
318 | // } | 218 | odebug << "pcmcia: card has been previously inserted" << oendl; |
319 | } | 219 | } |
320 | endmntent( mntfp ); | 220 | repaint( TRUE ); |
321 | } | 221 | } |
322 | 222 | ||
323 | if ( !showPopUp && cardWas != cardInSd ) { | ||
324 | QString text = QString::null; | ||
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 | } | ||
340 | #else | ||
341 | #error "Not on Linux" | ||
342 | #endif | ||
343 | repaint( FALSE ); | ||
344 | return ( ( cardWas == cardInSd ) ? FALSE : TRUE ); | ||
345 | } | ||
346 | 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(); |
358 | } | 236 | } |
diff --git a/core/applets/cardmon/pcmcia.h b/core/applets/cardmon/pcmcia.h index 58a2d42..5c20433 100644 --- a/core/applets/cardmon/pcmcia.h +++ b/core/applets/cardmon/pcmcia.h | |||
@@ -39,15 +39,8 @@ class PcmciaManager : public QWidget | |||
39 | Q_OBJECT | 39 | Q_OBJECT |
40 | public: | 40 | public: |
41 | enum { | ||
42 | PCMCIA_Socket1, | ||
43 | PCMCIA_Socket2, | ||
44 | MMC_Socket | ||
45 | }; | ||
46 | |||
47 | PcmciaManager( QWidget *parent = 0 ); | 41 | PcmciaManager( QWidget *parent = 0 ); |
48 | ~PcmciaManager(); | 42 | ~PcmciaManager(); |
49 | bool getStatusPcmcia( int showPopUp = FALSE ); | ||
50 | bool getStatusSd( int showPopUp = FALSE ); | ||
51 | static int position(); | 43 | static int position(); |
44 | |||
52 | private slots: | 45 | private slots: |
53 | void cardMessage( const QCString &msg, const QByteArray & ); | 46 | void cardMessage( const QCString &msg, const QByteArray & ); |
@@ -60,19 +53,11 @@ protected: | |||
60 | private: | 53 | private: |
61 | void execCommand( const QStringList &command ); | 54 | void execCommand( const QStringList &command ); |
55 | void popUp(QString message, QString icon = QString::null ); | ||
56 | |||
57 | private: | ||
62 | int m_commandOrig; | 58 | int m_commandOrig; |
63 | QPixmap pm; | 59 | QPixmap pm; |
64 | // pcmcia socket 0 | ||
65 | bool cardInPcmcia0; | ||
66 | QString cardInPcmcia0Name; | ||
67 | QString cardInPcmcia0Type; | ||
68 | // pcmcia socket 1 | ||
69 | bool cardInPcmcia1; | ||
70 | QString cardInPcmcia1Name; | ||
71 | QString cardInPcmcia1Type; | ||
72 | bool cardInSd; | ||
73 | QString cardSdName; // the device which is mounted | ||
74 | void iconShow(); | ||
75 | QPopupMenu *popupMenu; | 60 | QPopupMenu *popupMenu; |
76 | void popUp(QString message, QString icon = QString::null ); | 61 | |
77 | }; | 62 | }; |
78 | 63 | ||