Diffstat (limited to 'core/applets/cardmon/cardmon.cpp') (more/less context) (ignore 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 | |||
@@ -41,105 +41,105 @@ | |||
41 | 41 | ||
42 | CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ), | 42 | 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; | ||
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 * ) { |
91 | QPopupMenu *menu = new QPopupMenu(); | 89 | QPopupMenu *menu = new QPopupMenu(); |
92 | QString cmd; | 90 | QString cmd; |
93 | int err=0; | 91 | int err=0; |
94 | 92 | ||
95 | if ( cardInSd ) { | 93 | if ( cardInSd ) { |
96 | menu->insertItem( tr("Eject SD/MMC card"), 0 ); | 94 | menu->insertItem( tr("Eject SD/MMC card"), 0 ); |
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 )); |
108 | QSize s = menu->sizeHint ( ); | 108 | QSize s = menu->sizeHint ( ); |
109 | int opt = menu->exec( QPoint ( | 109 | int opt = menu->exec( QPoint ( |
110 | p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), | 110 | p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), |
111 | p. y ( ) - s. height ( ) ), 0); | 111 | p. y ( ) - s. height ( ) ), 0); |
112 | 112 | ||
113 | if ( opt == 1 ) { | 113 | if ( opt == 1 ) { |
114 | 114 | ||
115 | cmd = "/sbin/cardctl eject 0"; | 115 | cmd = "/sbin/cardctl eject 0"; |
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 | ||
137 | delete menu; | 137 | delete menu; |
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) { | 141 | void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) { |
142 | if ( msg == "stabChanged()" ) { | 142 | if ( msg == "stabChanged()" ) { |
143 | // qDebug("Pcmcia: stabchanged"); | 143 | // qDebug("Pcmcia: stabchanged"); |
144 | if ( getStatusPcmcia() ) { | 144 | if ( getStatusPcmcia() ) { |
145 | repaint(FALSE); | 145 | repaint(FALSE); |
@@ -176,69 +176,69 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) { | |||
176 | QString streamIn; | 176 | QString streamIn; |
177 | streamIn = stream.read(); | 177 | streamIn = stream.read(); |
178 | list = QStringList::split("\n", streamIn); | 178 | list = QStringList::split("\n", streamIn); |
179 | for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { | 179 | for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { |
180 | if( (*line).startsWith("Socket 0:") ){ | 180 | if( (*line).startsWith("Socket 0:") ){ |
181 | if( (*line).startsWith("Socket 0: empty") && cardInPcmcia0 ){ | 181 | if( (*line).startsWith("Socket 0: empty") && cardInPcmcia0 ){ |
182 | cardInPcmcia0 = FALSE; | 182 | cardInPcmcia0 = FALSE; |
183 | } else if ( !(*line).startsWith("Socket 0: empty") && !cardInPcmcia0 ){ | 183 | } else if ( !(*line).startsWith("Socket 0: empty") && !cardInPcmcia0 ){ |
184 | cardInPcmcia0Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 ); | 184 | cardInPcmcia0Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 ); |
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 ){ |
194 | cardInPcmcia1Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 ); | 197 | cardInPcmcia1Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 ); |
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"); |
204 | cardInPcmcia0 = FALSE; | 211 | cardInPcmcia0 = FALSE; |
205 | cardInPcmcia1 = FALSE; | 212 | cardInPcmcia1 = FALSE; |
206 | return FALSE; | 213 | return FALSE; |
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 | } |
236 | 236 | ||
237 | 237 | ||
238 | bool CardMonitor::getStatusSd( int showPopUp ) { | 238 | bool CardMonitor::getStatusSd( int showPopUp ) { |
239 | 239 | ||
240 | bool cardWas=cardInSd; // remember last state | 240 | bool cardWas=cardInSd; // remember last state |
241 | cardInSd=false; | 241 | cardInSd=false; |
242 | 242 | ||
243 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 243 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
244 | struct mntent *me; | 244 | struct mntent *me; |
@@ -248,34 +248,42 @@ bool CardMonitor::getStatusSd( int showPopUp ) { | |||
248 | while ( (me = getmntent( mntfp )) != 0 ) { | 248 | while ( (me = getmntent( mntfp )) != 0 ) { |
249 | QString fs = me->mnt_fsname; | 249 | QString fs = me->mnt_fsname; |
250 | if ( fs.left(7)=="/dev/sd" || fs.left(9) == "/dev/mmcd" ) { | 250 | if ( fs.left(7)=="/dev/sd" || fs.left(9) == "/dev/mmcd" ) { |
251 | cardInSd=true; | 251 | cardInSd=true; |
252 | } | 252 | } |
253 | } | 253 | } |
254 | endmntent( mntfp ); | 254 | endmntent( mntfp ); |
255 | } | 255 | } |
256 | if(!showPopUp && cardWas != cardInSd) { | 256 | if(!showPopUp && cardWas != cardInSd) { |
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 |
264 | #error "Not on Linux" | 264 | #error "Not on Linux" |
265 | #endif | 265 | #endif |
266 | return ((cardWas == cardInSd) ? FALSE : TRUE); | 266 | return ((cardWas == cardInSd) ? FALSE : TRUE); |
267 | } | 267 | } |
268 | 268 | ||
269 | void CardMonitor::paintEvent( QPaintEvent * ) { | 269 | void CardMonitor::paintEvent( QPaintEvent * ) { |
270 | QPainter p( this ); | 270 | QPainter p( this ); |
271 | 271 | ||
272 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { | 272 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { |
273 | p.drawPixmap( 0, 0, pm ); | 273 | p.drawPixmap( 0, 0, pm ); |
274 | show(); | 274 | show(); |
275 | } else { | 275 | } else { |
276 | p.eraseRect( rect() ); | 276 | p.eraseRect( rect() ); |
277 | hide(); | 277 | hide(); |
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 | ||