summaryrefslogtreecommitdiff
authorharlekin <harlekin>2002-06-23 21:59:16 (UTC)
committer harlekin <harlekin>2002-06-23 21:59:16 (UTC)
commit64f2b33735d6df230820af5aa0f47d8db29e6e35 (patch) (unidiff)
treef6b6e62a3a2153c96c18df7055367049600192aa
parent8e6c9f9b93d5c95fe1a40689817e86d478a8c944 (diff)
downloadopie-64f2b33735d6df230820af5aa0f47d8db29e6e35.zip
opie-64f2b33735d6df230820af5aa0f47d8db29e6e35.tar.gz
opie-64f2b33735d6df230820af5aa0f47d8db29e6e35.tar.bz2
fixed first start and cleanups
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/cardmon/cardmon.cpp80
-rw-r--r--core/applets/cardmon/cardmon.h11
-rw-r--r--core/applets/cardmon/opie-cardmon.control2
3 files changed, 51 insertions, 42 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp
index 93bc97a..de02fe6 100644
--- a/core/applets/cardmon/cardmon.cpp
+++ b/core/applets/cardmon/cardmon.cpp
@@ -50,41 +50,39 @@ CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ),
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;
54 cardInPcmcia1 = FALSE;
55
53 setFixedSize( pm.size() ); 56 setFixedSize( pm.size() );
54 getStatusPcmcia(TRUE); 57 getStatusPcmcia(TRUE);
55 getStatusSd(TRUE); 58 getStatusSd(TRUE);
56 repaint(FALSE); 59 repaint(FALSE);
57 popUpMenu = 0; 60 popupMenu = 0;
58 popUpMenuTimer = 0;
59} 61}
60 62
61CardMonitor::~CardMonitor() { 63CardMonitor::~CardMonitor() {
64 if( popupMenu ) { delete popupMenu; }
62} 65}
63 66
64void CardMonitor::popUp(QString message) { 67void CardMonitor::popup(QString message, QString icon="") {
65 if ( ! popUpMenu ) { 68 if ( ! popupMenu ) {
66 popUpMenu = new QPopupMenu(); 69 popupMenu = new QPopupMenu();
70 }
71 popupMenu->clear();
72 if( icon == "" ) {
73 popupMenu->insertItem( message, 0 );
74 } else {
75 popupMenu->insertItem( QIconSet ( Resource::loadPixmap ( icon )),
76 message, 0 );
67 } 77 }
68 popUpMenu->clear();
69 popUpMenu->insertItem( message, 0 );
70 78
71 QPoint p = mapToGlobal ( QPoint ( 0, 0 )); 79 QPoint p = mapToGlobal ( QPoint ( 0, 0 ));
72 QSize s = popUpMenu->sizeHint ( ); 80 QSize s = popupMenu->sizeHint ( );
73 popUpMenu->popup( QPoint ( 81 popupMenu->popup( QPoint (
74 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), 82 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ),
75 p. y ( ) - s. height ( ) ), 0); 83 p. y ( ) - s. height ( ) ), 0);
76 84
77 if ( ! popUpMenuTimer ) { 85 QTimer::singleShot( 2000, this, SLOT(popupMenuTimeout()) );
78 popUpMenuTimer = new QTimer( this );
79 connect( popUpMenuTimer, SIGNAL(timeout()), this, SLOT(popUpTimeout()) );
80 }
81 timerEvent(0);
82 popUpMenuTimer->start( 2000 );
83}
84
85void CardMonitor::popUpTimeout() {
86 popUpMenu->hide();
87 popUpMenuTimer->stop();
88} 86}
89 87
90void CardMonitor::mousePressEvent( QMouseEvent * ) { 88void CardMonitor::mousePressEvent( QMouseEvent * ) {
@@ -97,11 +95,13 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) {
97 } 95 }
98 96
99 if ( cardInPcmcia0 ) { 97 if ( cardInPcmcia0 ) {
100 menu->insertItem( tr("Eject card 0: %1").arg(cardInPcmcia0Name), 1 ); 98 menu->insertItem( QIconSet ( Resource::loadPixmap ( getIconName(cardInPcmcia0Type) )),
99 tr("Eject card 0: %1").arg(cardInPcmcia0Name), 1 );
101 } 100 }
102 101
103 if ( cardInPcmcia1 ) { 102 if ( cardInPcmcia1 ) {
104 menu->insertItem( tr("Eject card 1: %1").arg(cardInPcmcia1Name), 2 ); 103 menu->insertItem( QIconSet ( Resource::loadPixmap ( getIconName(cardInPcmcia1Type) )),
104 tr("Eject card 1: %1").arg(cardInPcmcia1Name), 2 );
105 } 105 }
106 106
107 QPoint p = mapToGlobal ( QPoint ( 0, 0 )); 107 QPoint p = mapToGlobal ( QPoint ( 0, 0 ));
@@ -116,21 +116,21 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) {
116 err = system( (const char *) cmd ); 116 err = system( (const char *) cmd );
117 if ( ( err == 127 ) || ( err < 0 ) ) { 117 if ( ( err == 127 ) || ( err < 0 ) ) {
118 qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", err); 118 qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", err);
119 popUp( tr("CF/PCMCIA card eject failed!")); 119 popup( tr("CF/PCMCIA card eject failed!"));
120 } 120 }
121 } else if ( opt == 0 ) { 121 } else if ( opt == 0 ) {
122 cmd = "/etc/sdcontrol compeject"; 122 cmd = "/etc/sdcontrol compeject";
123 err = system( (const char *) cmd ); 123 err = system( (const char *) cmd );
124 if ( ( err != 0 ) ) { 124 if ( ( err != 0 ) ) {
125 qDebug("Could not execute `/etc/sdcontrol comeject'! err=%d", err); 125 qDebug("Could not execute `/etc/sdcontrol comeject'! err=%d", err);
126 popUp( tr("SD/MMC card eject failed!")); 126 popup( tr("SD/MMC card eject failed!"));
127 } 127 }
128 } else if ( opt == 2 ) { 128 } else if ( opt == 2 ) {
129 cmd = "/sbin/cardctl eject 1"; 129 cmd = "/sbin/cardctl eject 1";
130 err = system( (const char *) cmd ); 130 err = system( (const char *) cmd );
131 if ( ( err == 127 ) || ( err < 0 ) ) { 131 if ( ( err == 127 ) || ( err < 0 ) ) {
132 qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", err); 132 qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", err);
133 popUp( tr("CF/PCMCIA card eject failed!")); 133 popup( tr("CF/PCMCIA card eject failed!"));
134 } 134 }
135 } 135 }
136 136
@@ -185,9 +185,12 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) {
185 cardInPcmcia0Name.stripWhiteSpace(); 185 cardInPcmcia0Name.stripWhiteSpace();
186 cardInPcmcia0 = TRUE; 186 cardInPcmcia0 = TRUE;
187 show(); 187 show();
188 line++;
189 int pos=(*line).find('\t')+1;
190 cardInPcmcia0Type = (*line).mid( pos, (*line).find("\t", pos) - pos);
188 } 191 }
189 } 192 }
190 if( (*line).startsWith("Socket 1:") ){ 193 else if( (*line).startsWith("Socket 1:") ){
191 if( (*line).startsWith("Socket 1: empty") && cardInPcmcia1 ){ 194 if( (*line).startsWith("Socket 1: empty") && cardInPcmcia1 ){
192 cardInPcmcia1 = FALSE; 195 cardInPcmcia1 = FALSE;
193 } else if ( !(*line).startsWith("Socket 1: empty") && !cardInPcmcia1 ){ 196 } else if ( !(*line).startsWith("Socket 1: empty") && !cardInPcmcia1 ){
@@ -195,9 +198,13 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) {
195 cardInPcmcia1Name.stripWhiteSpace(); 198 cardInPcmcia1Name.stripWhiteSpace();
196 cardInPcmcia1 = TRUE; 199 cardInPcmcia1 = TRUE;
197 show(); 200 show();
201 line++;
202 int pos=(*line).find('\t')+1;
203 cardInPcmcia1Type = (*line).mid( pos, (*line).find("\t", pos) - pos);
198 } 204 }
199 } 205 }
200 } 206 }
207 f.close();
201 } else { 208 } else {
202 // no file found 209 // no file found
203 qDebug("no file found"); 210 qDebug("no file found");
@@ -207,29 +214,22 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) {
207 214
208 } 215 }
209 216
210 if(!cardInPcmcia0 && !cardInPcmcia1) {
211 qDebug("Pcmcia: no cards");
212 }
213
214 if( !showPopUp && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1)) { 217 if( !showPopUp && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1)) {
215 QString text = ""; 218 QString text = "";
216 if(cardWas0 != cardInPcmcia0) { 219 if(cardWas0 != cardInPcmcia0) {
217 if(cardInPcmcia0) { text += tr("New card: "); } 220 if(cardInPcmcia0) { text += tr("New card: "); }
218 else { text += tr("Ejected: "); } 221 else { text += tr("Ejected: "); }
219 text += cardInPcmcia0Name; 222 text += cardInPcmcia0Name;
220 } 223 popup( text, getIconName( cardInPcmcia0Type ) );
221 if(cardWas0 != cardInPcmcia0 && cardWas1 != cardInPcmcia1) {
222 text += "\n";
223 } 224 }
224 if(cardWas1 != cardInPcmcia1) { 225 if(cardWas1 != cardInPcmcia1) {
225 if(cardInPcmcia1) { text += tr("New card: "); } 226 if(cardInPcmcia1) { text += tr("New card: "); }
226 else { text += tr("Ejected: "); } 227 else { text += tr("Ejected: "); }
227 text += cardInPcmcia1Name; 228 text += cardInPcmcia1Name;
229 popup( text, getIconName( cardInPcmcia1Type ) );
228 } 230 }
229 popUp( text );
230 } 231 }
231 232
232 f.close();
233 233
234 return ((cardWas0 == cardInPcmcia0 || cardWas1 == cardInPcmcia1) ? FALSE : TRUE); 234 return ((cardWas0 == cardInPcmcia0 || cardWas1 == cardInPcmcia1) ? FALSE : TRUE);
235} 235}
@@ -257,7 +257,7 @@ bool CardMonitor::getStatusSd( int showPopUp ) {
257 QString text = ""; 257 QString text = "";
258 if(cardInSd) { text += "SD Inserted"; } 258 if(cardInSd) { text += "SD Inserted"; }
259 else { text += "SD Removed"; } 259 else { text += "SD Removed"; }
260 popUp( text ); 260 popup( text); // XX add SD pic
261 } 261 }
262 262
263#else 263#else
@@ -278,4 +278,12 @@ void CardMonitor::paintEvent( QPaintEvent * ) {
278 } 278 }
279} 279}
280 280
281QString CardMonitor::getIconName( QString type ) {
282 if( type != "network" &&
283 type != "ide" ) {
284 type="cardmon";
285 }
286 return "cardmon/"+type;
287}
288
281 289
diff --git a/core/applets/cardmon/cardmon.h b/core/applets/cardmon/cardmon.h
index 34b8d95..e424192 100644
--- a/core/applets/cardmon/cardmon.h
+++ b/core/applets/cardmon/cardmon.h
@@ -22,7 +22,6 @@
22#include <qwidget.h> 22#include <qwidget.h>
23#include <qpixmap.h> 23#include <qpixmap.h>
24#include <qpopupmenu.h> 24#include <qpopupmenu.h>
25#include <qtimer.h>
26 25
27class CardMonitor : public QWidget { 26class CardMonitor : public QWidget {
28 Q_OBJECT 27 Q_OBJECT
@@ -34,24 +33,26 @@ public:
34 33
35private slots: 34private slots:
36 void cardMessage( const QCString &msg, const QByteArray & ); 35 void cardMessage( const QCString &msg, const QByteArray & );
37 void popUpTimeout(); 36 void popupTimeout();
38 37
39protected: 38protected:
40 void paintEvent( QPaintEvent* ); 39 void paintEvent( QPaintEvent* );
41 void mousePressEvent( QMouseEvent * ); 40 void mousePressEvent( QMouseEvent * );
42private: 41private:
43 QPixmap pm; 42 QPixmap pm;
44 QPopupMenu *popUpMenu;
45 QTimer *popUpMenuTimer;
46 // pcmcia socket 0 43 // pcmcia socket 0
47 bool cardInPcmcia0; 44 bool cardInPcmcia0;
48 QString cardInPcmcia0Name; 45 QString cardInPcmcia0Name;
46 QString cardInPcmcia0Type;
49 // pcmcia socket 1 47 // pcmcia socket 1
50 bool cardInPcmcia1; 48 bool cardInPcmcia1;
51 QString cardInPcmcia1Name; 49 QString cardInPcmcia1Name;
50 QString cardInPcmcia1Type;
52 bool cardInSd; 51 bool cardInSd;
53 void iconShow(); 52 void iconShow();
54 void popUp(QString message); 53 QPopupMenu *popupMenu;
54 void popup(QString message, QString icon="");
55 QString getIconName(QString type);
55}; 56};
56 57
57#endif 58#endif
diff --git a/core/applets/cardmon/opie-cardmon.control b/core/applets/cardmon/opie-cardmon.control
index 9f941f8..bcd0326 100644
--- a/core/applets/cardmon/opie-cardmon.control
+++ b/core/applets/cardmon/opie-cardmon.control
@@ -1,4 +1,4 @@
1Files: plugins/applets/libcardmonapplet.so* pics/cardmon/pcmcia.png 1Files: plugins/applets/libcardmonapplet.so* pics/cardmon/*.png
2Priority: optional 2Priority: optional
3Section: opie/taskbar 3Section: opie/taskbar
4Maintainer: Maximilian Reiß <max.reiss@gmx.de> 4Maintainer: Maximilian Reiß <max.reiss@gmx.de>