summaryrefslogtreecommitdiff
path: root/core/applets
authormickeyl <mickeyl>2005-05-19 14:25:34 (UTC)
committer mickeyl <mickeyl>2005-05-19 14:25:34 (UTC)
commit7fcfce8388df1805327f21d4cc41d7f5f54c6e6a (patch) (unidiff)
tree80409a535f74f4d5c5131f2eeb9f064a492f0cb8 /core/applets
parent77134583c00446fc74515889514571924e7471ed (diff)
downloadopie-7fcfce8388df1805327f21d4cc41d7f5f54c6e6a.zip
opie-7fcfce8388df1805327f21d4cc41d7f5f54c6e6a.tar.gz
opie-7fcfce8388df1805327f21d4cc41d7f5f54c6e6a.tar.bz2
write card log
Diffstat (limited to 'core/applets') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/cardmon/pcmcia.cpp284
-rw-r--r--core/applets/cardmon/pcmcia.h35
2 files changed, 91 insertions, 228 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
@@ -32,7 +32,9 @@
32/* OPIE */ 32/* OPIE */
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>
38#include <qpe/applnk.h> 40#include <qpe/applnk.h>
@@ -45,6 +47,7 @@ using namespace Opie::Ui;
45#include <qpainter.h> 47#include <qpainter.h>
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>
50 53
@@ -61,41 +64,20 @@ using namespace Opie::Ui;
61 64
62PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ) 65PcmciaManager::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,
72 SIGNAL( received(const QCString&,const QByteArray&) ), this, 69 SIGNAL( received(const QCString&,const QByteArray&) ), this,
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
95 78
96PcmciaManager::~PcmciaManager() 79PcmciaManager::~PcmciaManager()
97{ 80{
98 delete popupMenu;
99} 81}
100 82
101 83
@@ -128,17 +110,33 @@ void PcmciaManager::popupTimeout()
128} 110}
129 111
130 112
131void PcmciaManager::mousePressEvent( QMouseEvent * ) 113void PcmciaManager::mousePressEvent( QMouseEvent* )
132{ 114{
133 QPopupMenu * menu = new QPopupMenu( this ); 115 QPopupMenu * menu = new QPopupMenu( this );
134 QStringList cmd; 116 QStringList cmd;
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 ) ),
139 tr( "Eject SD/MMC card" ), 0 ); 135 tr( "Eject SD/MMC card" ), 0 );
140 } 136 }
141 137
138
139
142 if ( cardInPcmcia0 ) { 140 if ( cardInPcmcia0 ) {
143 menu-> 141 menu->
144 insertItem( QIconSet 142 insertItem( QIconSet
@@ -152,208 +150,88 @@ void PcmciaManager::mousePressEvent( QMouseEvent * )
152 ( Opie::Core::OResource::loadPixmap( "cardmon/" + cardInPcmcia1Type, Opie::Core::OResource::SmallIcon ) ), 150 ( Opie::Core::OResource::loadPixmap( "cardmon/" + cardInPcmcia1Type, Opie::Core::OResource::SmallIcon ) ),
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}
178 161
179 162
180void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) 163void 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" );
192bool 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
295bool 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
347void PcmciaManager::paintEvent( QPaintEvent * ) 224void 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 }
359} 237}
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
@@ -37,43 +37,28 @@
37class PcmciaManager : public QWidget 37class PcmciaManager : public QWidget
38{ 38{
39 Q_OBJECT 39 Q_OBJECT
40public: 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();
52private slots: 44
53 void cardMessage( const QCString &msg, const QByteArray & ); 45 private slots:
46 void cardMessage( const QCString& msg, const QByteArray& );
54 void popupTimeout(); 47 void popupTimeout();
55 48
56protected: 49 protected:
57 void paintEvent( QPaintEvent* ); 50 void paintEvent( QPaintEvent* );
58 void mousePressEvent( QMouseEvent * ); 51 void mousePressEvent( QMouseEvent * );
59 52
60private: 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
79#endif 64#endif