Diffstat (limited to 'core/applets/cardmon/cardmon.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/applets/cardmon/cardmon.cpp | 84 |
1 files changed, 56 insertions, 28 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp index 9522b88..ac2aea2 100644 --- a/core/applets/cardmon/cardmon.cpp +++ b/core/applets/cardmon/cardmon.cpp | |||
@@ -49,12 +49,12 @@ CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ), | |||
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 | |||
54 | setFixedSize( pm.size() ); | 53 | setFixedSize( pm.size() ); |
55 | hide(); | 54 | getStatusPcmcia(TRUE); |
56 | getStatusPcmcia(); | 55 | getStatusSd(TRUE); |
56 | repaint(FALSE); | ||
57 | } | 57 | } |
58 | 58 | ||
59 | CardMonitor::~CardMonitor() { | 59 | CardMonitor::~CardMonitor() { |
60 | } | 60 | } |
@@ -64,65 +64,71 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) { | |||
64 | QString cmd; | 64 | QString cmd; |
65 | int err=0; | 65 | int err=0; |
66 | 66 | ||
67 | if ( cardInSd ) { | 67 | if ( cardInSd ) { |
68 | menu->insertItem( tr("Eject SD/ MMC card"), 0 ); | 68 | menu->insertItem( tr("Eject SD/MMC card"), 0 ); |
69 | } | 69 | } |
70 | 70 | ||
71 | if ( cardInPcmcia0 ) { | 71 | if ( cardInPcmcia0 ) { |
72 | menu->insertItem( tr("Eject card (0) %1").arg(cardInPcmcia0Name), 1 ); | 72 | menu->insertItem( tr("Eject card 0: %1").arg(cardInPcmcia0Name), 1 ); |
73 | } | 73 | } |
74 | 74 | ||
75 | if ( cardInPcmcia1 ) { | 75 | if ( cardInPcmcia1 ) { |
76 | menu->insertItem( tr("Eject card (1) %1").arg(cardInPcmcia1Name), 2 ); | 76 | menu->insertItem( tr("Eject card 1: %1").arg(cardInPcmcia1Name), 2 ); |
77 | } | 77 | } |
78 | 78 | ||
79 | QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); | 79 | QPoint p = mapToGlobal ( QPoint ( 0, 0 )); |
80 | QSize s = menu->sizeHint ( ); | ||
81 | int opt = menu->exec( QPoint ( | ||
82 | p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), | ||
83 | p. y ( ) - s. height ( ) ), 0); | ||
80 | 84 | ||
81 | if ( menu->exec( p, 1 ) == 1 ) { | 85 | if ( opt == 1 ) { |
82 | 86 | ||
83 | cmd = "/sbin/cardctl eject 0"; | 87 | cmd = "/sbin/cardctl eject 0"; |
84 | err = system( (const char *) cmd ); | 88 | err = system( (const char *) cmd ); |
85 | if ( ( err == 127 ) || ( err < 0 ) ) { | 89 | if ( ( err == 127 ) || ( err < 0 ) ) { |
86 | qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", err); | 90 | qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", err); |
87 | QMessageBox::warning( this, tr("CardMonitor"), tr("CF/PCMCIA card eject failed!"), | 91 | QMessageBox::warning( this, tr("CardMonitor"), tr("CF/PCMCIA card eject failed!"), |
88 | tr("&OK") ); | 92 | tr("&OK") ); |
89 | } | 93 | } |
90 | } else if ( menu->exec( p, 1 ) == 0 ) { | 94 | } else if ( opt == 0 ) { |
91 | cmd = "/etc/sdcontrol compeject"; | 95 | cmd = "/etc/sdcontrol compeject"; |
92 | err = system( (const char *) cmd ); | 96 | err = system( (const char *) cmd ); |
93 | if ( ( err != 0 ) ) { | 97 | if ( ( err != 0 ) ) { |
94 | qDebug("Could not execute `/etc/sdcontrol comeject'! err=%d", err); | 98 | qDebug("Could not execute `/etc/sdcontrol comeject'! err=%d", err); |
95 | QMessageBox::warning( this, tr("CardMonitor"), tr("SD/MMC card eject failed!"), | 99 | QMessageBox::warning( this, tr("CardMonitor"), tr("SD/MMC card eject failed!"), |
96 | tr("&OK") ); | 100 | tr("&OK") ); |
97 | } | 101 | } |
98 | } else if ( menu->exec( p, 1 ) == 2 ) { | 102 | } else if ( opt == 2 ) { |
99 | cmd = "/sbin/cardctl eject 1"; | 103 | cmd = "/sbin/cardctl eject 1"; |
100 | err = system( (const char *) cmd ); | 104 | err = system( (const char *) cmd ); |
101 | if ( ( err == 127 ) || ( err < 0 ) ) { | 105 | if ( ( err == 127 ) || ( err < 0 ) ) { |
102 | qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", err); | 106 | qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", err); |
103 | QMessageBox::warning( this, tr("CardMonitor"), tr("CF/PCMCIA card eject failed!"), | 107 | QMessageBox::warning( this, tr("CardMonitor"), tr("CF/PCMCIA card eject failed!"), |
104 | tr("&OK") ); | 108 | tr("&OK") ); |
105 | } | 109 | } |
106 | } | 110 | } |
107 | 111 | ||
108 | delete menu; | 112 | delete menu; |
109 | } | 113 | } |
110 | 114 | ||
111 | 115 | ||
112 | void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) { | 116 | void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) { |
113 | if ( msg == "stabChanged()" ) { | 117 | if ( msg == "stabChanged()" ) { |
118 | // qDebug("Pcmcia: stabchanged"); | ||
114 | if ( getStatusPcmcia() ) { | 119 | if ( getStatusPcmcia() ) { |
115 | repaint(FALSE); | 120 | repaint(FALSE); |
116 | } | 121 | } |
117 | } else if ( msg == "mtabChanged()" ) { | 122 | } else if ( msg == "mtabChanged()" ) { |
123 | // qDebug("Pcmcia: mtabchanged"); | ||
118 | if ( getStatusSd() ) { | 124 | if ( getStatusSd() ) { |
119 | repaint(FALSE); | 125 | repaint(FALSE); |
120 | } | 126 | } |
121 | } | 127 | } |
122 | } | 128 | } |
123 | 129 | ||
124 | bool CardMonitor::getStatusPcmcia( void ) { | 130 | bool CardMonitor::getStatusPcmcia( int showPopUp = FALSE ) { |
125 | 131 | ||
126 | bool cardWas0 = cardInPcmcia0; // remember last state | 132 | bool cardWas0 = cardInPcmcia0; // remember last state |
127 | bool cardWas1 = cardInPcmcia1; | 133 | bool cardWas1 = cardInPcmcia1; |
128 | 134 | ||
@@ -146,24 +152,23 @@ bool CardMonitor::getStatusPcmcia( void ) { | |||
146 | streamIn = stream.read(); | 152 | streamIn = stream.read(); |
147 | list = QStringList::split("\n", streamIn); | 153 | list = QStringList::split("\n", streamIn); |
148 | for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { | 154 | for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { |
149 | if( (*line).startsWith("Socket 0:") ){ | 155 | if( (*line).startsWith("Socket 0:") ){ |
150 | // extendable, maybe read out card name | ||
151 | if( (*line).startsWith("Socket 0: empty") && cardInPcmcia0 ){ | 156 | if( (*line).startsWith("Socket 0: empty") && cardInPcmcia0 ){ |
152 | cardInPcmcia0 = FALSE; | 157 | cardInPcmcia0 = FALSE; |
153 | hide(); | ||
154 | } else if ( !(*line).startsWith("Socket 0: empty") && !cardInPcmcia0 ){ | 158 | } else if ( !(*line).startsWith("Socket 0: empty") && !cardInPcmcia0 ){ |
155 | cardInPcmcia0Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 ); | 159 | cardInPcmcia0Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 ); |
160 | cardInPcmcia0Name.stripWhiteSpace(); | ||
156 | cardInPcmcia0 = TRUE; | 161 | cardInPcmcia0 = TRUE; |
157 | show(); | 162 | show(); |
158 | } | 163 | } |
159 | } | 164 | } |
160 | if( (*line).startsWith("Socket 1:") ){ | 165 | if( (*line).startsWith("Socket 1:") ){ |
161 | if( (*line).startsWith("Socket 1: empty") && cardInPcmcia1 ){ | 166 | if( (*line).startsWith("Socket 1: empty") && cardInPcmcia1 ){ |
162 | cardInPcmcia1 = FALSE; | 167 | cardInPcmcia1 = FALSE; |
163 | hide(); | ||
164 | } else if ( !(*line).startsWith("Socket 1: empty") && !cardInPcmcia1 ){ | 168 | } else if ( !(*line).startsWith("Socket 1: empty") && !cardInPcmcia1 ){ |
165 | cardInPcmcia1Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 ); | 169 | cardInPcmcia1Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 ); |
170 | cardInPcmcia1Name.stripWhiteSpace(); | ||
166 | cardInPcmcia1 = TRUE; | 171 | cardInPcmcia1 = TRUE; |
167 | show(); | 172 | show(); |
168 | } | 173 | } |
169 | } | 174 | } |
@@ -172,20 +177,42 @@ bool CardMonitor::getStatusPcmcia( void ) { | |||
172 | // no file found | 177 | // no file found |
173 | qDebug("no file found"); | 178 | qDebug("no file found"); |
174 | cardInPcmcia0 = FALSE; | 179 | cardInPcmcia0 = FALSE; |
175 | cardInPcmcia1 = FALSE; | 180 | cardInPcmcia1 = FALSE; |
176 | hide(); | ||
177 | return FALSE; | 181 | return FALSE; |
178 | 182 | ||
179 | } | 183 | } |
180 | 184 | ||
185 | if(!cardInPcmcia0 && !cardInPcmcia1) { | ||
186 | qDebug("Pcmcia: no cards"); | ||
187 | } | ||
188 | |||
189 | if( !showPopUp && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1)) { | ||
190 | QString text = ""; | ||
191 | if(cardWas0 != cardInPcmcia0) { | ||
192 | if(cardInPcmcia0) { text += tr("New card: "); } | ||
193 | else { text += tr("Ejected: "); } | ||
194 | text += cardInPcmcia0Name; | ||
195 | } | ||
196 | if(cardWas0 != cardInPcmcia0 && cardWas1 != cardInPcmcia1) { | ||
197 | text += "\n"; | ||
198 | } | ||
199 | if(cardWas1 != cardInPcmcia1) { | ||
200 | if(cardInPcmcia1) { text += tr("New card: "); } | ||
201 | else { text += tr("Ejected: "); } | ||
202 | text += cardInPcmcia1Name; | ||
203 | } | ||
204 | QMessageBox::warning( this, tr("CardMonitor"), text, | ||
205 | tr("&OK") ); | ||
206 | } | ||
207 | |||
181 | f.close(); | 208 | f.close(); |
182 | 209 | ||
183 | return ((cardWas0 == cardInPcmcia0 || cardWas1 == cardInPcmcia1) ? FALSE : TRUE); | 210 | return ((cardWas0 == cardInPcmcia0 || cardWas1 == cardInPcmcia1) ? FALSE : TRUE); |
184 | } | 211 | } |
185 | 212 | ||
186 | 213 | ||
187 | bool CardMonitor::getStatusSd( void ) { | 214 | bool CardMonitor::getStatusSd( int showPopUp = FALSE ) { |
188 | 215 | ||
189 | bool cardWas=cardInSd; // remember last state | 216 | bool cardWas=cardInSd; // remember last state |
190 | cardInSd=false; | 217 | cardInSd=false; |
191 | 218 | ||
@@ -200,18 +227,17 @@ bool CardMonitor::getStatusSd( void ) { | |||
200 | cardInSd=true; | 227 | cardInSd=true; |
201 | } | 228 | } |
202 | } | 229 | } |
203 | endmntent( mntfp ); | 230 | endmntent( mntfp ); |
204 | if (cardInSd!=cardWas) { | ||
205 | if (cardInSd) { | ||
206 | show(); | ||
207 | } else { | ||
208 | hide(); | ||
209 | } | ||
210 | } | ||
211 | } else { | ||
212 | hide(); | ||
213 | } | 231 | } |
232 | if(!showPopUp && cardWas != cardInSd) { | ||
233 | QString text = ""; | ||
234 | if(cardInSd) { text += "SD Inserted"; } | ||
235 | else { text += "SD Removed"; } | ||
236 | QMessageBox::warning( this, tr("CardMonitor"), text, | ||
237 | tr("&OK") ); | ||
238 | } | ||
239 | |||
214 | #else | 240 | #else |
215 | #error "Not on Linux" | 241 | #error "Not on Linux" |
216 | #endif | 242 | #endif |
217 | return ((cardWas == cardInSd) ? FALSE : TRUE); | 243 | return ((cardWas == cardInSd) ? FALSE : TRUE); |
@@ -221,10 +247,12 @@ void CardMonitor::paintEvent( QPaintEvent * ) { | |||
221 | QPainter p( this ); | 247 | QPainter p( this ); |
222 | 248 | ||
223 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { | 249 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { |
224 | p.drawPixmap( 0, 0, pm ); | 250 | p.drawPixmap( 0, 0, pm ); |
251 | show(); | ||
225 | } else { | 252 | } else { |
226 | p.eraseRect( rect() ); | 253 | p.eraseRect( rect() ); |
254 | hide(); | ||
227 | } | 255 | } |
228 | } | 256 | } |
229 | 257 | ||
230 | 258 | ||