author | zecke <zecke> | 2004-04-04 23:31:29 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-04-04 23:31:29 (UTC) |
commit | fb8ce053c0f08769d359fe4153785e3de72f83ea (patch) (unidiff) | |
tree | 2f0081cf8739c6daba81c791ec77bde37cbbba1a | |
parent | f2da7b706fd5e0512222e11ce0d94d2750074fd1 (diff) | |
download | opie-fb8ce053c0f08769d359fe4153785e3de72f83ea.zip opie-fb8ce053c0f08769d359fe4153785e3de72f83ea.tar.gz opie-fb8ce053c0f08769d359fe4153785e3de72f83ea.tar.bz2 |
Comitting a fix is probably a good idea
use EXPORT_OPIE_APPLET_v1 instead of OTaskBarAppletWrapper directly
-rw-r--r-- | core/applets/cardmon/cardmon.cpp | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp index ed4bfc7..1ad8b55 100644 --- a/core/applets/cardmon/cardmon.cpp +++ b/core/applets/cardmon/cardmon.cpp | |||
@@ -1,427 +1,424 @@ | |||
1 | /* | 1 | /* |
2 | * cardmon.cpp | 2 | * cardmon.cpp |
3 | * | 3 | * |
4 | * --------------------- | 4 | * --------------------- |
5 | * | 5 | * |
6 | * copyright : (c) 2002 by Maximilian Reiss | 6 | * copyright : (c) 2002 by Maximilian Reiss |
7 | * email : max.reiss@gmx.de | 7 | * email : max.reiss@gmx.de |
8 | * based on two apps by Devin Butterfield | 8 | * based on two apps by Devin Butterfield |
9 | */ | 9 | */ |
10 | /*************************************************************************** | 10 | /*************************************************************************** |
11 | * * | 11 | * * |
12 | * This program is free software; you can redistribute it and/or modify * | 12 | * This program is free software; you can redistribute it and/or modify * |
13 | * it under the terms of the GNU General Public License as published by * | 13 | * it under the terms of the GNU General Public License as published by * |
14 | * the Free Software Foundation; either version 2 of the License, or * | 14 | * the Free Software Foundation; either version 2 of the License, or * |
15 | * (at your option) any later version. * | 15 | * (at your option) any later version. * |
16 | * * | 16 | * * |
17 | ***************************************************************************/ | 17 | ***************************************************************************/ |
18 | 18 | ||
19 | #include "cardmon.h" | 19 | #include "cardmon.h" |
20 | 20 | ||
21 | /* OPIE */ | 21 | /* OPIE */ |
22 | #include <opie2/odevice.h> | 22 | #include <opie2/odevice.h> |
23 | #include <opie2/otaskbarapplet.h> | 23 | #include <opie2/otaskbarapplet.h> |
24 | #include <qpe/applnk.h> | 24 | #include <qpe/applnk.h> |
25 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
26 | 26 | ||
27 | /* QT */ | 27 | /* QT */ |
28 | #include <qcopchannel_qws.h> | 28 | #include <qcopchannel_qws.h> |
29 | #include <qpainter.h> | 29 | #include <qpainter.h> |
30 | #include <qfile.h> | 30 | #include <qfile.h> |
31 | #include <qtextstream.h> | 31 | #include <qtextstream.h> |
32 | #include <qsound.h> | 32 | #include <qsound.h> |
33 | #include <qtimer.h> | 33 | #include <qtimer.h> |
34 | 34 | ||
35 | /* STD */ | 35 | /* STD */ |
36 | #include <stdio.h> | 36 | #include <stdio.h> |
37 | #include <unistd.h> | 37 | #include <unistd.h> |
38 | #include <stdlib.h> | 38 | #include <stdlib.h> |
39 | #include <string.h> | 39 | #include <string.h> |
40 | #include <fcntl.h> | 40 | #include <fcntl.h> |
41 | 41 | ||
42 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 42 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
43 | #include <sys/vfs.h> | 43 | #include <sys/vfs.h> |
44 | #include <mntent.h> | 44 | #include <mntent.h> |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | using namespace Opie; | 47 | using namespace Opie; |
48 | 48 | ||
49 | using namespace Opie::Ui; | 49 | using namespace Opie::Ui; |
50 | using namespace Opie::Ui; | 50 | using namespace Opie::Ui; |
51 | using namespace Opie::Core; | 51 | using namespace Opie::Core; |
52 | 52 | ||
53 | CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ), | 53 | CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ), |
54 | pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) | 54 | pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) |
55 | { | 55 | { |
56 | 56 | ||
57 | QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); | 57 | QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); |
58 | connect( pcmciaChannel, | 58 | connect( pcmciaChannel, |
59 | SIGNAL( received(const QCString&,const QByteArray&) ), this, | 59 | SIGNAL( received(const QCString&,const QByteArray&) ), this, |
60 | SLOT( cardMessage(const QCString&,const QByteArray&) ) ); | 60 | SLOT( cardMessage(const QCString&,const QByteArray&) ) ); |
61 | 61 | ||
62 | QCopChannel *sdChannel = new QCopChannel( "QPE/Card", this ); | 62 | QCopChannel *sdChannel = new QCopChannel( "QPE/Card", this ); |
63 | connect( sdChannel, | 63 | connect( sdChannel, |
64 | SIGNAL( received(const QCString&,const QByteArray&) ), this, | 64 | SIGNAL( received(const QCString&,const QByteArray&) ), this, |
65 | SLOT( cardMessage(const QCString&,const QByteArray&) ) ); | 65 | SLOT( cardMessage(const QCString&,const QByteArray&) ) ); |
66 | 66 | ||
67 | cardInPcmcia0 = FALSE; | 67 | cardInPcmcia0 = FALSE; |
68 | cardInPcmcia1 = FALSE; | 68 | cardInPcmcia1 = FALSE; |
69 | cardInSd = FALSE; | 69 | cardInSd = FALSE; |
70 | 70 | ||
71 | setFocusPolicy( NoFocus ); | 71 | setFocusPolicy( NoFocus ); |
72 | 72 | ||
73 | setFixedWidth ( AppLnk::smallIconSize() ); | 73 | setFixedWidth ( AppLnk::smallIconSize() ); |
74 | setFixedHeight ( AppLnk::smallIconSize() ); | 74 | setFixedHeight ( AppLnk::smallIconSize() ); |
75 | 75 | ||
76 | getStatusPcmcia( TRUE ); | 76 | getStatusPcmcia( TRUE ); |
77 | getStatusSd( TRUE ); | 77 | getStatusSd( TRUE ); |
78 | repaint( FALSE ); | 78 | repaint( FALSE ); |
79 | popupMenu = 0; | 79 | popupMenu = 0; |
80 | } | 80 | } |
81 | 81 | ||
82 | CardMonitor::~CardMonitor() | 82 | CardMonitor::~CardMonitor() |
83 | { | 83 | { |
84 | if ( popupMenu ) | 84 | if ( popupMenu ) |
85 | { | 85 | { |
86 | delete popupMenu; | 86 | delete popupMenu; |
87 | } | 87 | } |
88 | } | 88 | } |
89 | 89 | ||
90 | void CardMonitor::popUp( QString message, QString icon ) | 90 | void CardMonitor::popUp( QString message, QString icon ) |
91 | { | 91 | { |
92 | if ( !popupMenu ) | 92 | if ( !popupMenu ) |
93 | { | 93 | { |
94 | popupMenu = new QPopupMenu( this ); | 94 | popupMenu = new QPopupMenu( this ); |
95 | } | 95 | } |
96 | 96 | ||
97 | popupMenu->clear(); | 97 | popupMenu->clear(); |
98 | if ( icon.isEmpty() ) | 98 | if ( icon.isEmpty() ) |
99 | { | 99 | { |
100 | popupMenu->insertItem( message, 0 ); | 100 | popupMenu->insertItem( message, 0 ); |
101 | } | 101 | } |
102 | else | 102 | else |
103 | { | 103 | { |
104 | popupMenu->insertItem( QIconSet( Resource::loadPixmap( icon ) ), | 104 | popupMenu->insertItem( QIconSet( Resource::loadPixmap( icon ) ), |
105 | message, 0 ); | 105 | message, 0 ); |
106 | } | 106 | } |
107 | 107 | ||
108 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); | 108 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); |
109 | QSize s = popupMenu->sizeHint(); | 109 | QSize s = popupMenu->sizeHint(); |
110 | popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), | 110 | popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), |
111 | p.y() - s.height() ), 0 ); | 111 | p.y() - s.height() ), 0 ); |
112 | 112 | ||
113 | QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); | 113 | QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); |
114 | } | 114 | } |
115 | 115 | ||
116 | void CardMonitor::popupTimeout() | 116 | void CardMonitor::popupTimeout() |
117 | { | 117 | { |
118 | popupMenu->hide(); | 118 | popupMenu->hide(); |
119 | } | 119 | } |
120 | 120 | ||
121 | void CardMonitor::mousePressEvent( QMouseEvent * ) | 121 | void CardMonitor::mousePressEvent( QMouseEvent * ) |
122 | { | 122 | { |
123 | QPopupMenu * menu = new QPopupMenu( this ); | 123 | QPopupMenu * menu = new QPopupMenu( this ); |
124 | QString cmd; | 124 | QString cmd; |
125 | int err = 0; | 125 | int err = 0; |
126 | 126 | ||
127 | if ( cardInSd ) | 127 | if ( cardInSd ) |
128 | { | 128 | { |
129 | menu->insertItem( QIconSet( Resource::loadPixmap( "cardmon/ide" ) ), | 129 | menu->insertItem( QIconSet( Resource::loadPixmap( "cardmon/ide" ) ), |
130 | tr( "Eject SD/MMC card" ), 0 ); | 130 | tr( "Eject SD/MMC card" ), 0 ); |
131 | } | 131 | } |
132 | 132 | ||
133 | if ( cardInPcmcia0 ) | 133 | if ( cardInPcmcia0 ) |
134 | { | 134 | { |
135 | menu-> | 135 | menu-> |
136 | insertItem( QIconSet | 136 | insertItem( QIconSet |
137 | ( Resource::loadPixmap( "cardmon/" + cardInPcmcia0Type ) ), | 137 | ( Resource::loadPixmap( "cardmon/" + cardInPcmcia0Type ) ), |
138 | tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 ); | 138 | tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 ); |
139 | } | 139 | } |
140 | 140 | ||
141 | if ( cardInPcmcia1 ) | 141 | if ( cardInPcmcia1 ) |
142 | { | 142 | { |
143 | menu-> | 143 | menu-> |
144 | insertItem( QIconSet | 144 | insertItem( QIconSet |
145 | ( Resource::loadPixmap( "cardmon/" + cardInPcmcia1Type ) ), | 145 | ( Resource::loadPixmap( "cardmon/" + cardInPcmcia1Type ) ), |
146 | tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); | 146 | tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); |
147 | } | 147 | } |
148 | 148 | ||
149 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); | 149 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); |
150 | QSize s = menu->sizeHint(); | 150 | QSize s = menu->sizeHint(); |
151 | int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), | 151 | int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), |
152 | p.y() - s.height() ), 0 ); | 152 | p.y() - s.height() ), 0 ); |
153 | 153 | ||
154 | if ( opt == 1 ) | 154 | if ( opt == 1 ) |
155 | { | 155 | { |
156 | cmd = "/sbin/cardctl eject 0"; | 156 | cmd = "/sbin/cardctl eject 0"; |
157 | err = system( ( const char * ) cmd ); | 157 | err = system( ( const char * ) cmd ); |
158 | if ( err != 0 ) | 158 | if ( err != 0 ) |
159 | { | 159 | { |
160 | qDebug( "Could not execute `/sbin/cardctl eject 0'! err=%d", | 160 | qDebug( "Could not execute `/sbin/cardctl eject 0'! err=%d", |
161 | err ); | 161 | err ); |
162 | popUp( tr( "CF/PCMCIA card eject failed!" ) ); | 162 | popUp( tr( "CF/PCMCIA card eject failed!" ) ); |
163 | } | 163 | } |
164 | } | 164 | } |
165 | else if ( opt == 0 ) | 165 | else if ( opt == 0 ) |
166 | { | 166 | { |
167 | if ( ODevice::inst() ->system() == System_Familiar ) | 167 | if ( ODevice::inst() ->system() == System_Familiar ) |
168 | { | 168 | { |
169 | cmd = "umount /dev/mmc/part1"; | 169 | cmd = "umount /dev/mmc/part1"; |
170 | } | 170 | } |
171 | else | 171 | else |
172 | { | 172 | { |
173 | cmd = "umount /dev/mmcda1"; | 173 | cmd = "umount /dev/mmcda1"; |
174 | } | 174 | } |
175 | err = system( ( const char * ) cmd ); | 175 | err = system( ( const char * ) cmd ); |
176 | if ( err != 0 ) | 176 | if ( err != 0 ) |
177 | { | 177 | { |
178 | popUp( tr( "SD/MMC card eject failed!" ) ); | 178 | popUp( tr( "SD/MMC card eject failed!" ) ); |
179 | } | 179 | } |
180 | } | 180 | } |
181 | else if ( opt == 2 ) | 181 | else if ( opt == 2 ) |
182 | { | 182 | { |
183 | cmd = "/sbin/cardctl eject 1"; | 183 | cmd = "/sbin/cardctl eject 1"; |
184 | err = system( ( const char * ) cmd ); | 184 | err = system( ( const char * ) cmd ); |
185 | if ( err != 0 ) | 185 | if ( err != 0 ) |
186 | { | 186 | { |
187 | qDebug( "Could not execute `/sbin/cardctl eject 1'! err=%d", | 187 | qDebug( "Could not execute `/sbin/cardctl eject 1'! err=%d", |
188 | err ); | 188 | err ); |
189 | popUp( tr( "CF/PCMCIA card eject failed!" ) ); | 189 | popUp( tr( "CF/PCMCIA card eject failed!" ) ); |
190 | } | 190 | } |
191 | } | 191 | } |
192 | delete menu; | 192 | delete menu; |
193 | } | 193 | } |
194 | 194 | ||
195 | 195 | ||
196 | void CardMonitor::cardMessage( const QCString & msg, const QByteArray & ) | 196 | void CardMonitor::cardMessage( const QCString & msg, const QByteArray & ) |
197 | { | 197 | { |
198 | if ( msg == "stabChanged()" ) | 198 | if ( msg == "stabChanged()" ) |
199 | { | 199 | { |
200 | // qDebug("Pcmcia: stabchanged"); | 200 | // qDebug("Pcmcia: stabchanged"); |
201 | getStatusPcmcia(); | 201 | getStatusPcmcia(); |
202 | } | 202 | } |
203 | else if ( msg == "mtabChanged()" ) | 203 | else if ( msg == "mtabChanged()" ) |
204 | { | 204 | { |
205 | // qDebug("CARDMONAPPLET: mtabchanged"); | 205 | // qDebug("CARDMONAPPLET: mtabchanged"); |
206 | getStatusSd(); | 206 | getStatusSd(); |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
210 | bool CardMonitor::getStatusPcmcia( int showPopUp ) | 210 | bool CardMonitor::getStatusPcmcia( int showPopUp ) |
211 | { | 211 | { |
212 | 212 | ||
213 | bool cardWas0 = cardInPcmcia0;// remember last state | 213 | bool cardWas0 = cardInPcmcia0;// remember last state |
214 | bool cardWas1 = cardInPcmcia1; | 214 | bool cardWas1 = cardInPcmcia1; |
215 | 215 | ||
216 | QString fileName; | 216 | QString fileName; |
217 | 217 | ||
218 | // one of these 3 files should exist | 218 | // one of these 3 files should exist |
219 | if ( QFile::exists( "/var/run/stab" ) ) | 219 | if ( QFile::exists( "/var/run/stab" ) ) |
220 | { | 220 | { |
221 | fileName = "/var/run/stab"; | 221 | fileName = "/var/run/stab"; |
222 | } | 222 | } |
223 | else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) | 223 | else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) |
224 | { | 224 | { |
225 | fileName = "/var/state/pcmcia/stab"; | 225 | fileName = "/var/state/pcmcia/stab"; |
226 | } | 226 | } |
227 | else | 227 | else |
228 | { | 228 | { |
229 | fileName = "/var/lib/pcmcia/stab"; | 229 | fileName = "/var/lib/pcmcia/stab"; |
230 | } | 230 | } |
231 | 231 | ||
232 | QFile f( fileName ); | 232 | QFile f( fileName ); |
233 | 233 | ||
234 | if ( f.open( IO_ReadOnly ) ) | 234 | if ( f.open( IO_ReadOnly ) ) |
235 | { | 235 | { |
236 | QStringList list; | 236 | QStringList list; |
237 | QTextStream stream( &f ); | 237 | QTextStream stream( &f ); |
238 | QString streamIn; | 238 | QString streamIn; |
239 | streamIn = stream.read(); | 239 | streamIn = stream.read(); |
240 | list = QStringList::split( "\n", streamIn ); | 240 | list = QStringList::split( "\n", streamIn ); |
241 | for ( QStringList::Iterator line = list.begin(); line != list.end(); | 241 | for ( QStringList::Iterator line = list.begin(); line != list.end(); |
242 | line++ ) | 242 | line++ ) |
243 | { | 243 | { |
244 | if ( ( *line ).startsWith( "Socket 0:" ) ) | 244 | if ( ( *line ).startsWith( "Socket 0:" ) ) |
245 | { | 245 | { |
246 | if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ) | 246 | if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ) |
247 | { | 247 | { |
248 | cardInPcmcia0 = FALSE; | 248 | cardInPcmcia0 = FALSE; |
249 | } | 249 | } |
250 | else if ( !( *line ).startsWith( "Socket 0: empty" ) | 250 | else if ( !( *line ).startsWith( "Socket 0: empty" ) |
251 | && !cardInPcmcia0 ) | 251 | && !cardInPcmcia0 ) |
252 | { | 252 | { |
253 | cardInPcmcia0Name = | 253 | cardInPcmcia0Name = |
254 | ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), | 254 | ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), |
255 | ( *line ).length() - 9 ); | 255 | ( *line ).length() - 9 ); |
256 | cardInPcmcia0Name.stripWhiteSpace(); | 256 | cardInPcmcia0Name.stripWhiteSpace(); |
257 | cardInPcmcia0 = TRUE; | 257 | cardInPcmcia0 = TRUE; |
258 | show(); | 258 | show(); |
259 | line++; | 259 | line++; |
260 | int pos = ( *line ).find( '\t' ) + 1; | 260 | int pos = ( *line ).find( '\t' ) + 1; |
261 | cardInPcmcia0Type = | 261 | cardInPcmcia0Type = |
262 | ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); | 262 | ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); |
263 | } | 263 | } |
264 | } | 264 | } |
265 | else if ( ( *line ).startsWith( "Socket 1:" ) ) | 265 | else if ( ( *line ).startsWith( "Socket 1:" ) ) |
266 | { | 266 | { |
267 | if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) | 267 | if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) |
268 | { | 268 | { |
269 | cardInPcmcia1 = FALSE; | 269 | cardInPcmcia1 = FALSE; |
270 | } | 270 | } |
271 | else if ( !( *line ).startsWith( "Socket 1: empty" ) | 271 | else if ( !( *line ).startsWith( "Socket 1: empty" ) |
272 | && !cardInPcmcia1 ) | 272 | && !cardInPcmcia1 ) |
273 | { | 273 | { |
274 | cardInPcmcia1Name = | 274 | cardInPcmcia1Name = |
275 | ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), | 275 | ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), |
276 | ( *line ).length() - 9 ); | 276 | ( *line ).length() - 9 ); |
277 | cardInPcmcia1Name.stripWhiteSpace(); | 277 | cardInPcmcia1Name.stripWhiteSpace(); |
278 | cardInPcmcia1 = TRUE; | 278 | cardInPcmcia1 = TRUE; |
279 | show(); | 279 | show(); |
280 | line++; | 280 | line++; |
281 | int pos = ( *line ).find( '\t' ) + 1; | 281 | int pos = ( *line ).find( '\t' ) + 1; |
282 | cardInPcmcia1Type = | 282 | cardInPcmcia1Type = |
283 | ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); | 283 | ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); |
284 | } | 284 | } |
285 | } | 285 | } |
286 | } | 286 | } |
287 | f.close(); | 287 | f.close(); |
288 | 288 | ||
289 | if ( !showPopUp | 289 | if ( !showPopUp |
290 | && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) ) | 290 | && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) ) |
291 | { | 291 | { |
292 | QString text = QString::null; | 292 | QString text = QString::null; |
293 | QString what = QString::null; | 293 | QString what = QString::null; |
294 | if ( cardWas0 != cardInPcmcia0 ) | 294 | if ( cardWas0 != cardInPcmcia0 ) |
295 | { | 295 | { |
296 | if ( cardInPcmcia0 ) | 296 | if ( cardInPcmcia0 ) |
297 | { | 297 | { |
298 | text += tr( "New card: " ); | 298 | text += tr( "New card: " ); |
299 | what = "on"; | 299 | what = "on"; |
300 | } | 300 | } |
301 | else | 301 | else |
302 | { | 302 | { |
303 | text += tr( "Ejected: " ); | 303 | text += tr( "Ejected: " ); |
304 | what = "off"; | 304 | what = "off"; |
305 | } | 305 | } |
306 | text += cardInPcmcia0Name; | 306 | text += cardInPcmcia0Name; |
307 | popUp( text, "cardmon/" + cardInPcmcia0Type ); | 307 | popUp( text, "cardmon/" + cardInPcmcia0Type ); |
308 | } | 308 | } |
309 | 309 | ||
310 | if ( cardWas1 != cardInPcmcia1 ) | 310 | if ( cardWas1 != cardInPcmcia1 ) |
311 | { | 311 | { |
312 | if ( cardInPcmcia1 ) | 312 | if ( cardInPcmcia1 ) |
313 | { | 313 | { |
314 | text += tr( "New card: " ); | 314 | text += tr( "New card: " ); |
315 | what = "on"; | 315 | what = "on"; |
316 | } | 316 | } |
317 | else | 317 | else |
318 | { | 318 | { |
319 | text += tr( "Ejected: " ); | 319 | text += tr( "Ejected: " ); |
320 | what = "off"; | 320 | what = "off"; |
321 | } | 321 | } |
322 | text += cardInPcmcia1Name; | 322 | text += cardInPcmcia1Name; |
323 | popUp( text, "cardmon/" + cardInPcmcia1Type ); | 323 | popUp( text, "cardmon/" + cardInPcmcia1Type ); |
324 | } | 324 | } |
325 | #ifndef QT_NO_SOUND | 325 | #ifndef QT_NO_SOUND |
326 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); | 326 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); |
327 | #endif | 327 | #endif |
328 | 328 | ||
329 | } | 329 | } |
330 | } | 330 | } |
331 | else | 331 | else |
332 | { | 332 | { |
333 | // no file found | 333 | // no file found |
334 | qDebug( "no file found" ); | 334 | qDebug( "no file found" ); |
335 | cardInPcmcia0 = FALSE; | 335 | cardInPcmcia0 = FALSE; |
336 | cardInPcmcia1 = FALSE; | 336 | cardInPcmcia1 = FALSE; |
337 | } | 337 | } |
338 | repaint( FALSE ); | 338 | repaint( FALSE ); |
339 | return ( ( cardWas0 == cardInPcmcia0 | 339 | return ( ( cardWas0 == cardInPcmcia0 |
340 | && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE ); | 340 | && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE ); |
341 | 341 | ||
342 | } | 342 | } |
343 | 343 | ||
344 | 344 | ||
345 | bool CardMonitor::getStatusSd( int showPopUp ) | 345 | bool CardMonitor::getStatusSd( int showPopUp ) |
346 | { | 346 | { |
347 | 347 | ||
348 | bool cardWas = cardInSd;// remember last state | 348 | bool cardWas = cardInSd;// remember last state |
349 | cardInSd = FALSE; | 349 | cardInSd = FALSE; |
350 | 350 | ||
351 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 351 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
352 | struct mntent *me; | 352 | struct mntent *me; |
353 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); | 353 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); |
354 | 354 | ||
355 | if ( mntfp ) | 355 | if ( mntfp ) |
356 | { | 356 | { |
357 | while ( ( me = getmntent( mntfp ) ) != 0 ) | 357 | while ( ( me = getmntent( mntfp ) ) != 0 ) |
358 | { | 358 | { |
359 | QString fs = me->mnt_fsname; | 359 | QString fs = me->mnt_fsname; |
360 | //qDebug( fs ); | 360 | //qDebug( fs ); |
361 | if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd" | 361 | if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd" |
362 | || fs.left( 9 ) == "/dev/mmcd" ) | 362 | || fs.left( 9 ) == "/dev/mmcd" ) |
363 | { | 363 | { |
364 | cardInSd = TRUE; | 364 | cardInSd = TRUE; |
365 | show(); | 365 | show(); |
366 | } | 366 | } |
367 | // else { | 367 | // else { |
368 | // cardInSd = FALSE; | 368 | // cardInSd = FALSE; |
369 | // } | 369 | // } |
370 | } | 370 | } |
371 | endmntent( mntfp ); | 371 | endmntent( mntfp ); |
372 | } | 372 | } |
373 | 373 | ||
374 | if ( !showPopUp && cardWas != cardInSd ) | 374 | if ( !showPopUp && cardWas != cardInSd ) |
375 | { | 375 | { |
376 | QString text = QString::null; | 376 | QString text = QString::null; |
377 | QString what = QString::null; | 377 | QString what = QString::null; |
378 | if ( cardInSd ) | 378 | if ( cardInSd ) |
379 | { | 379 | { |
380 | text += "New card: SD/MMC"; | 380 | text += "New card: SD/MMC"; |
381 | what = "on"; | 381 | what = "on"; |
382 | } | 382 | } |
383 | else | 383 | else |
384 | { | 384 | { |
385 | text += "Ejected: SD/MMC"; | 385 | text += "Ejected: SD/MMC"; |
386 | what = "off"; | 386 | what = "off"; |
387 | } | 387 | } |
388 | //qDebug("TEXT: " + text ); | 388 | //qDebug("TEXT: " + text ); |
389 | #ifndef QT_NO_SOUND | 389 | #ifndef QT_NO_SOUND |
390 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); | 390 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); |
391 | #endif | 391 | #endif |
392 | popUp( text, "cardmon/ide" );// XX add SD pic | 392 | popUp( text, "cardmon/ide" );// XX add SD pic |
393 | } | 393 | } |
394 | #else | 394 | #else |
395 | #error "Not on Linux" | 395 | #error "Not on Linux" |
396 | #endif | 396 | #endif |
397 | repaint( FALSE ); | 397 | repaint( FALSE ); |
398 | return ( ( cardWas == cardInSd ) ? FALSE : TRUE ); | 398 | return ( ( cardWas == cardInSd ) ? FALSE : TRUE ); |
399 | } | 399 | } |
400 | 400 | ||
401 | void CardMonitor::paintEvent( QPaintEvent * ) | 401 | void CardMonitor::paintEvent( QPaintEvent * ) |
402 | { | 402 | { |
403 | 403 | ||
404 | QPainter p( this ); | 404 | QPainter p( this ); |
405 | 405 | ||
406 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) | 406 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) |
407 | { | 407 | { |
408 | p.drawPixmap( 0, 0, pm ); | 408 | p.drawPixmap( 0, 0, pm ); |
409 | show(); | 409 | show(); |
410 | } | 410 | } |
411 | else | 411 | else |
412 | { | 412 | { |
413 | //p.eraseRect(rect()); | 413 | //p.eraseRect(rect()); |
414 | hide(); | 414 | hide(); |
415 | } | 415 | } |
416 | } | 416 | } |
417 | 417 | ||
418 | int CardMonitor::position() | 418 | int CardMonitor::position() |
419 | { | 419 | { |
420 | return 7; | 420 | return 7; |
421 | } | 421 | } |
422 | 422 | ||
423 | Q_EXPORT_INTERFACE() | 423 | EXPORT_OPIE_APPLET_v1( CardMonitor ) |
424 | { | ||
425 | Q_CREATE_INSTANCE( Opie::Ui::Private::OTaskbarAppletWrapper<CardMonitor> ); | ||
426 | } | ||
427 | 424 | ||