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
@@ -55,43 +55,47 @@ CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ),
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 ) {
@@ -107,39 +111,39 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) {
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);
@@ -211,31 +215,31 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) {
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;
@@ -248,25 +252,25 @@ bool CardMonitor::getStatusSd( int showPopUp ) {
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 ) {
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
@@ -42,18 +42,18 @@ private:
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