author | harlekin <harlekin> | 2002-06-23 21:59:16 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-06-23 21:59:16 (UTC) |
commit | 64f2b33735d6df230820af5aa0f47d8db29e6e35 (patch) (unidiff) | |
tree | f6b6e62a3a2153c96c18df7055367049600192aa /core/applets/cardmon/cardmon.cpp | |
parent | 8e6c9f9b93d5c95fe1a40689817e86d478a8c944 (diff) | |
download | opie-64f2b33735d6df230820af5aa0f47d8db29e6e35.zip opie-64f2b33735d6df230820af5aa0f47d8db29e6e35.tar.gz opie-64f2b33735d6df230820af5aa0f47d8db29e6e35.tar.bz2 |
fixed first start and cleanups
Diffstat (limited to 'core/applets/cardmon/cardmon.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/applets/cardmon/cardmon.cpp | 80 |
1 files changed, 44 insertions, 36 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 | ||
61 | CardMonitor::~CardMonitor() { | 63 | CardMonitor::~CardMonitor() { |
64 | if( popupMenu ) { delete popupMenu; } | ||
62 | } | 65 | } |
63 | 66 | ||
64 | void CardMonitor::popUp(QString message) { | 67 | void 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 | |||
85 | void CardMonitor::popUpTimeout() { | ||
86 | popUpMenu->hide(); | ||
87 | popUpMenuTimer->stop(); | ||
88 | } | 86 | } |
89 | 87 | ||
90 | void CardMonitor::mousePressEvent( QMouseEvent * ) { | 88 | void 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 | ||
281 | QString CardMonitor::getIconName( QString type ) { | ||
282 | if( type != "network" && | ||
283 | type != "ide" ) { | ||
284 | type="cardmon"; | ||
285 | } | ||
286 | return "cardmon/"+type; | ||
287 | } | ||
288 | |||
281 | 289 | ||