summaryrefslogtreecommitdiff
path: root/core
authorharlekin <harlekin>2002-06-23 23:32:29 (UTC)
committer harlekin <harlekin>2002-06-23 23:32:29 (UTC)
commit340e6e7830df8dcc9cf73fb1bf8a29130e34211d (patch) (unidiff)
tree38f5c6a7c82d4c0758b8640be96c8e318008939c /core
parent5713a36f24973c01a46fdff6203acf4590927f49 (diff)
downloadopie-340e6e7830df8dcc9cf73fb1bf8a29130e34211d.zip
opie-340e6e7830df8dcc9cf73fb1bf8a29130e34211d.tar.gz
opie-340e6e7830df8dcc9cf73fb1bf8a29130e34211d.tar.bz2
now cardmon should even start
Diffstat (limited to 'core') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/cardmon/cardmon.cpp20
-rw-r--r--core/applets/cardmon/cardmon.h2
2 files changed, 13 insertions, 9 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp
index de02fe6..0addb89 100644
--- a/core/applets/cardmon/cardmon.cpp
+++ b/core/applets/cardmon/cardmon.cpp
@@ -43,115 +43,119 @@ CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ),
43 pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) { 43 pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) {
44 44
45 QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this ); 45 QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this );
46 connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), 46 connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)),
47 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 47 this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
48 48
49 QCopChannel* sdChannel = new QCopChannel( "QPE/Card", this ); 49 QCopChannel* sdChannel = new QCopChannel( "QPE/Card", this );
50 connect( sdChannel, SIGNAL(received(const QCString &, const QByteArray &)), 50 connect( sdChannel, SIGNAL(received(const QCString &, const QByteArray &)),
51 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 51 this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
52 52
53 cardInPcmcia0 = FALSE; 53 cardInPcmcia0 = FALSE;
54 cardInPcmcia1 = FALSE; 54 cardInPcmcia1 = FALSE;
55 55
56 setFixedSize( pm.size() ); 56 setFixedSize( pm.size() );
57 getStatusPcmcia(TRUE); 57 getStatusPcmcia(TRUE);
58 getStatusSd(TRUE); 58 getStatusSd(TRUE);
59 repaint(FALSE); 59 repaint(FALSE);
60 popupMenu = 0; 60 popupMenu = 0;
61} 61}
62 62
63CardMonitor::~CardMonitor() { 63CardMonitor::~CardMonitor() {
64 if( popupMenu ) { delete popupMenu; } 64 if( popupMenu ) { delete popupMenu; }
65} 65}
66 66
67void CardMonitor::popup(QString message, QString icon="") { 67void CardMonitor::popUp(QString message, QString icon="") {
68 if ( ! popupMenu ) { 68 if ( ! popupMenu ) {
69 popupMenu = new QPopupMenu(); 69 popupMenu = new QPopupMenu();
70 } 70 }
71 popupMenu->clear(); 71 popupMenu->clear();
72 if( icon == "" ) { 72 if( icon == "" ) {
73 popupMenu->insertItem( message, 0 ); 73 popupMenu->insertItem( message, 0 );
74 } else { 74 } else {
75 popupMenu->insertItem( QIconSet ( Resource::loadPixmap ( icon )), 75 popupMenu->insertItem( QIconSet ( Resource::loadPixmap ( icon )),
76 message, 0 ); 76 message, 0 );
77 } 77 }
78 78
79 QPoint p = mapToGlobal ( QPoint ( 0, 0 )); 79 QPoint p = mapToGlobal ( QPoint ( 0, 0 ));
80 QSize s = popupMenu->sizeHint ( ); 80 QSize s = popupMenu->sizeHint ( );
81 popupMenu->popup( QPoint ( 81 popupMenu->popup( QPoint (
82 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), 82 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ),
83 p. y ( ) - s. height ( ) ), 0); 83 p. y ( ) - s. height ( ) ), 0);
84 84
85 QTimer::singleShot( 2000, this, SLOT(popupMenuTimeout()) ); 85 QTimer::singleShot( 2000, this, SLOT(popupTimeout()) );
86}
87
88void CardMonitor::popupTimeout() {
89 popupMenu->hide();
86} 90}
87 91
88void CardMonitor::mousePressEvent( QMouseEvent * ) { 92void CardMonitor::mousePressEvent( QMouseEvent * ) {
89 QPopupMenu *menu = new QPopupMenu(); 93 QPopupMenu *menu = new QPopupMenu();
90 QString cmd; 94 QString cmd;
91 int err=0; 95 int err=0;
92 96
93 if ( cardInSd ) { 97 if ( cardInSd ) {
94 menu->insertItem( tr("Eject SD/MMC card"), 0 ); 98 menu->insertItem( tr("Eject SD/MMC card"), 0 );
95 } 99 }
96 100
97 if ( cardInPcmcia0 ) { 101 if ( cardInPcmcia0 ) {
98 menu->insertItem( QIconSet ( Resource::loadPixmap ( getIconName(cardInPcmcia0Type) )), 102 menu->insertItem( QIconSet ( Resource::loadPixmap ( getIconName(cardInPcmcia0Type) )),
99 tr("Eject card 0: %1").arg(cardInPcmcia0Name), 1 ); 103 tr("Eject card 0: %1").arg(cardInPcmcia0Name), 1 );
100 } 104 }
101 105
102 if ( cardInPcmcia1 ) { 106 if ( cardInPcmcia1 ) {
103 menu->insertItem( QIconSet ( Resource::loadPixmap ( getIconName(cardInPcmcia1Type) )), 107 menu->insertItem( QIconSet ( Resource::loadPixmap ( getIconName(cardInPcmcia1Type) )),
104 tr("Eject card 1: %1").arg(cardInPcmcia1Name), 2 ); 108 tr("Eject card 1: %1").arg(cardInPcmcia1Name), 2 );
105 } 109 }
106 110
107 QPoint p = mapToGlobal ( QPoint ( 0, 0 )); 111 QPoint p = mapToGlobal ( QPoint ( 0, 0 ));
108 QSize s = menu->sizeHint ( ); 112 QSize s = menu->sizeHint ( );
109 int opt = menu->exec( QPoint ( 113 int opt = menu->exec( QPoint (
110 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), 114 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ),
111 p. y ( ) - s. height ( ) ), 0); 115 p. y ( ) - s. height ( ) ), 0);
112 116
113 if ( opt == 1 ) { 117 if ( opt == 1 ) {
114 118
115 cmd = "/sbin/cardctl eject 0"; 119 cmd = "/sbin/cardctl eject 0";
116 err = system( (const char *) cmd ); 120 err = system( (const char *) cmd );
117 if ( ( err == 127 ) || ( err < 0 ) ) { 121 if ( ( err == 127 ) || ( err < 0 ) ) {
118 qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", err); 122 qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", err);
119 popup( tr("CF/PCMCIA card eject failed!")); 123 popUp( tr("CF/PCMCIA card eject failed!"));
120 } 124 }
121 } else if ( opt == 0 ) { 125 } else if ( opt == 0 ) {
122 cmd = "/etc/sdcontrol compeject"; 126 cmd = "/etc/sdcontrol compeject";
123 err = system( (const char *) cmd ); 127 err = system( (const char *) cmd );
124 if ( ( err != 0 ) ) { 128 if ( ( err != 0 ) ) {
125 qDebug("Could not execute `/etc/sdcontrol comeject'! err=%d", err); 129 qDebug("Could not execute `/etc/sdcontrol comeject'! err=%d", err);
126 popup( tr("SD/MMC card eject failed!")); 130 popUp( tr("SD/MMC card eject failed!"));
127 } 131 }
128 } else if ( opt == 2 ) { 132 } else if ( opt == 2 ) {
129 cmd = "/sbin/cardctl eject 1"; 133 cmd = "/sbin/cardctl eject 1";
130 err = system( (const char *) cmd ); 134 err = system( (const char *) cmd );
131 if ( ( err == 127 ) || ( err < 0 ) ) { 135 if ( ( err == 127 ) || ( err < 0 ) ) {
132 qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", err); 136 qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", err);
133 popup( tr("CF/PCMCIA card eject failed!")); 137 popUp( tr("CF/PCMCIA card eject failed!"));
134 } 138 }
135 } 139 }
136 140
137 delete menu; 141 delete menu;
138} 142}
139 143
140 144
141void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) { 145void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) {
142 if ( msg == "stabChanged()" ) { 146 if ( msg == "stabChanged()" ) {
143 // qDebug("Pcmcia: stabchanged"); 147 // qDebug("Pcmcia: stabchanged");
144 if ( getStatusPcmcia() ) { 148 if ( getStatusPcmcia() ) {
145 repaint(FALSE); 149 repaint(FALSE);
146 } 150 }
147 } else if ( msg == "mtabChanged()" ) { 151 } else if ( msg == "mtabChanged()" ) {
148 // qDebug("Pcmcia: mtabchanged"); 152 // qDebug("Pcmcia: mtabchanged");
149 if ( getStatusSd() ) { 153 if ( getStatusSd() ) {
150 repaint(FALSE); 154 repaint(FALSE);
151 } 155 }
152 } 156 }
153} 157}
154 158
155bool CardMonitor::getStatusPcmcia( int showPopUp ) { 159bool CardMonitor::getStatusPcmcia( int showPopUp ) {
156 160
157 bool cardWas0 = cardInPcmcia0; // remember last state 161 bool cardWas0 = cardInPcmcia0; // remember last state
@@ -199,86 +203,86 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) {
199 cardInPcmcia1 = TRUE; 203 cardInPcmcia1 = TRUE;
200 show(); 204 show();
201 line++; 205 line++;
202 int pos=(*line).find('\t')+1; 206 int pos=(*line).find('\t')+1;
203 cardInPcmcia1Type = (*line).mid( pos, (*line).find("\t", pos) - pos); 207 cardInPcmcia1Type = (*line).mid( pos, (*line).find("\t", pos) - pos);
204 } 208 }
205 } 209 }
206 } 210 }
207 f.close(); 211 f.close();
208 } else { 212 } else {
209 // no file found 213 // no file found
210 qDebug("no file found"); 214 qDebug("no file found");
211 cardInPcmcia0 = FALSE; 215 cardInPcmcia0 = FALSE;
212 cardInPcmcia1 = FALSE; 216 cardInPcmcia1 = FALSE;
213 return FALSE; 217 return FALSE;
214 218
215 } 219 }
216 220
217 if( !showPopUp && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1)) { 221 if( !showPopUp && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1)) {
218 QString text = ""; 222 QString text = "";
219 if(cardWas0 != cardInPcmcia0) { 223 if(cardWas0 != cardInPcmcia0) {
220 if(cardInPcmcia0) { text += tr("New card: "); } 224 if(cardInPcmcia0) { text += tr("New card: "); }
221 else { text += tr("Ejected: "); } 225 else { text += tr("Ejected: "); }
222 text += cardInPcmcia0Name; 226 text += cardInPcmcia0Name;
223 popup( text, getIconName( cardInPcmcia0Type ) ); 227 popUp( text, getIconName( cardInPcmcia0Type ) );
224 } 228 }
225 if(cardWas1 != cardInPcmcia1) { 229 if(cardWas1 != cardInPcmcia1) {
226 if(cardInPcmcia1) { text += tr("New card: "); } 230 if(cardInPcmcia1) { text += tr("New card: "); }
227 else { text += tr("Ejected: "); } 231 else { text += tr("Ejected: "); }
228 text += cardInPcmcia1Name; 232 text += cardInPcmcia1Name;
229 popup( text, getIconName( cardInPcmcia1Type ) ); 233 popUp( text, getIconName( cardInPcmcia1Type ) );
230 } 234 }
231 } 235 }
232 236
233 237
234 return ((cardWas0 == cardInPcmcia0 || cardWas1 == cardInPcmcia1) ? FALSE : TRUE); 238 return ((cardWas0 == cardInPcmcia0 || cardWas1 == cardInPcmcia1) ? FALSE : TRUE);
235} 239}
236 240
237 241
238bool CardMonitor::getStatusSd( int showPopUp ) { 242bool CardMonitor::getStatusSd( int showPopUp ) {
239 243
240 bool cardWas=cardInSd; // remember last state 244 bool cardWas=cardInSd; // remember last state
241 cardInSd=false; 245 cardInSd=false;
242 246
243#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 247#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
244 struct mntent *me; 248 struct mntent *me;
245 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 249 FILE *mntfp = setmntent( "/etc/mtab", "r" );
246 250
247 if ( mntfp ) { 251 if ( mntfp ) {
248 while ( (me = getmntent( mntfp )) != 0 ) { 252 while ( (me = getmntent( mntfp )) != 0 ) {
249 QString fs = me->mnt_fsname; 253 QString fs = me->mnt_fsname;
250 if ( fs.left(7)=="/dev/sd" || fs.left(9) == "/dev/mmcd" ) { 254 if ( fs.left(7)=="/dev/sd" || fs.left(9) == "/dev/mmcd" ) {
251 cardInSd=true; 255 cardInSd=true;
252 } 256 }
253 } 257 }
254 endmntent( mntfp ); 258 endmntent( mntfp );
255 } 259 }
256 if(!showPopUp && cardWas != cardInSd) { 260 if(!showPopUp && cardWas != cardInSd) {
257 QString text = ""; 261 QString text = "";
258 if(cardInSd) { text += "SD Inserted"; } 262 if(cardInSd) { text += "SD Inserted"; }
259 else { text += "SD Removed"; } 263 else { text += "SD Removed"; }
260 popup( text); // XX add SD pic 264 popUp( text); // XX add SD pic
261 } 265 }
262 266
263#else 267#else
264#error "Not on Linux" 268#error "Not on Linux"
265#endif 269#endif
266 return ((cardWas == cardInSd) ? FALSE : TRUE); 270 return ((cardWas == cardInSd) ? FALSE : TRUE);
267} 271}
268 272
269void CardMonitor::paintEvent( QPaintEvent * ) { 273void CardMonitor::paintEvent( QPaintEvent * ) {
270 QPainter p( this ); 274 QPainter p( this );
271 275
272 if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { 276 if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) {
273 p.drawPixmap( 0, 0, pm ); 277 p.drawPixmap( 0, 0, pm );
274 show(); 278 show();
275 } else { 279 } else {
276 p.eraseRect( rect() ); 280 p.eraseRect( rect() );
277 hide(); 281 hide();
278 } 282 }
279} 283}
280 284
281QString CardMonitor::getIconName( QString type ) { 285QString CardMonitor::getIconName( QString type ) {
282 if( type != "network" && 286 if( type != "network" &&
283 type != "ide" ) { 287 type != "ide" ) {
284 type="cardmon"; 288 type="cardmon";
diff --git a/core/applets/cardmon/cardmon.h b/core/applets/cardmon/cardmon.h
index e424192..3dcf235 100644
--- a/core/applets/cardmon/cardmon.h
+++ b/core/applets/cardmon/cardmon.h
@@ -30,30 +30,30 @@ public:
30 ~CardMonitor(); 30 ~CardMonitor();
31 bool getStatusPcmcia( int showPopUp = FALSE ); 31 bool getStatusPcmcia( int showPopUp = FALSE );
32 bool getStatusSd( int showPopUp = FALSE ); 32 bool getStatusSd( int showPopUp = FALSE );
33 33
34private slots: 34private slots:
35 void cardMessage( const QCString &msg, const QByteArray & ); 35 void cardMessage( const QCString &msg, const QByteArray & );
36 void popupTimeout(); 36 void popupTimeout();
37 37
38protected: 38protected:
39 void paintEvent( QPaintEvent* ); 39 void paintEvent( QPaintEvent* );
40 void mousePressEvent( QMouseEvent * ); 40 void mousePressEvent( QMouseEvent * );
41private: 41private:
42 QPixmap pm; 42 QPixmap pm;
43 // pcmcia socket 0 43 // pcmcia socket 0
44 bool cardInPcmcia0; 44 bool cardInPcmcia0;
45 QString cardInPcmcia0Name; 45 QString cardInPcmcia0Name;
46 QString cardInPcmcia0Type; 46 QString cardInPcmcia0Type;
47 // pcmcia socket 1 47 // pcmcia socket 1
48 bool cardInPcmcia1; 48 bool cardInPcmcia1;
49 QString cardInPcmcia1Name; 49 QString cardInPcmcia1Name;
50 QString cardInPcmcia1Type; 50 QString cardInPcmcia1Type;
51 bool cardInSd; 51 bool cardInSd;
52 void iconShow(); 52 void iconShow();
53 QPopupMenu *popupMenu; 53 QPopupMenu *popupMenu;
54 void popup(QString message, QString icon=""); 54 void popUp(QString message, QString icon="");
55 QString getIconName(QString type); 55 QString getIconName(QString type);
56}; 56};
57 57
58#endif 58#endif
59 59