author | alwin <alwin> | 2005-03-03 22:40:52 (UTC) |
---|---|---|
committer | alwin <alwin> | 2005-03-03 22:40:52 (UTC) |
commit | 6458e3f1f86ab0aadceb3675c38abfbf33f070eb (patch) (unidiff) | |
tree | 9da8d7692485690a827d5095e43c1219e42467e3 | |
parent | e007cb2e4e3627ece4a093bc976debd6366ed1fa (diff) | |
download | opie-6458e3f1f86ab0aadceb3675c38abfbf33f070eb.zip opie-6458e3f1f86ab0aadceb3675c38abfbf33f070eb.tar.gz opie-6458e3f1f86ab0aadceb3675c38abfbf33f070eb.tar.bz2 |
added 2.6 kernel devicenames
ToDo: let it check using OStorage
-rw-r--r-- | core/applets/cardmon/cardmon.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp index 53497df..452339c 100644 --- a/core/applets/cardmon/cardmon.cpp +++ b/core/applets/cardmon/cardmon.cpp | |||
@@ -1,381 +1,381 @@ | |||
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/odebug.h> | 22 | #include <opie2/odebug.h> |
23 | #include <opie2/odevice.h> | 23 | #include <opie2/odevice.h> |
24 | #include <opie2/otaskbarapplet.h> | 24 | #include <opie2/otaskbarapplet.h> |
25 | #include <opie2/oprocess.h> | 25 | #include <opie2/oprocess.h> |
26 | 26 | ||
27 | #include <qpe/applnk.h> | 27 | #include <qpe/applnk.h> |
28 | #include <qpe/resource.h> | 28 | #include <qpe/resource.h> |
29 | using namespace Opie::Core; | 29 | using namespace Opie::Core; |
30 | using namespace Opie::Ui; | 30 | using namespace Opie::Ui; |
31 | 31 | ||
32 | /* QT */ | 32 | /* QT */ |
33 | #include <qcopchannel_qws.h> | 33 | #include <qcopchannel_qws.h> |
34 | #include <qpainter.h> | 34 | #include <qpainter.h> |
35 | #include <qfile.h> | 35 | #include <qfile.h> |
36 | #include <qtextstream.h> | 36 | #include <qtextstream.h> |
37 | #include <qsound.h> | 37 | #include <qsound.h> |
38 | #include <qtimer.h> | 38 | #include <qtimer.h> |
39 | 39 | ||
40 | /* STD */ | 40 | /* STD */ |
41 | #include <stdio.h> | 41 | #include <stdio.h> |
42 | #include <unistd.h> | 42 | #include <unistd.h> |
43 | #include <stdlib.h> | 43 | #include <stdlib.h> |
44 | #include <string.h> | 44 | #include <string.h> |
45 | #include <fcntl.h> | 45 | #include <fcntl.h> |
46 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 46 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
47 | #include <sys/vfs.h> | 47 | #include <sys/vfs.h> |
48 | #include <mntent.h> | 48 | #include <mntent.h> |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ) | 51 | CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ) |
52 | { | 52 | { |
53 | pm = Resource::loadImage( "cardmon/pcmcia").smoothScale(AppLnk::smallIconSize(), AppLnk::smallIconSize()); | 53 | pm = Resource::loadImage( "cardmon/pcmcia").smoothScale(AppLnk::smallIconSize(), AppLnk::smallIconSize()); |
54 | 54 | ||
55 | QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); | 55 | QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); |
56 | connect( pcmciaChannel, | 56 | connect( pcmciaChannel, |
57 | SIGNAL( received(const QCString&,const QByteArray&) ), this, | 57 | SIGNAL( received(const QCString&,const QByteArray&) ), this, |
58 | SLOT( cardMessage(const QCString&,const QByteArray&) ) ); | 58 | SLOT( cardMessage(const QCString&,const QByteArray&) ) ); |
59 | 59 | ||
60 | QCopChannel *sdChannel = new QCopChannel( "QPE/Card", this ); | 60 | QCopChannel *sdChannel = new QCopChannel( "QPE/Card", this ); |
61 | connect( sdChannel, | 61 | connect( sdChannel, |
62 | SIGNAL( received(const QCString&,const QByteArray&) ), this, | 62 | SIGNAL( received(const QCString&,const QByteArray&) ), this, |
63 | SLOT( cardMessage(const QCString&,const QByteArray&) ) ); | 63 | SLOT( cardMessage(const QCString&,const QByteArray&) ) ); |
64 | 64 | ||
65 | cardInPcmcia0 = FALSE; | 65 | cardInPcmcia0 = FALSE; |
66 | cardInPcmcia1 = FALSE; | 66 | cardInPcmcia1 = FALSE; |
67 | cardInSd = FALSE; | 67 | cardInSd = FALSE; |
68 | m_process = 0; | 68 | m_process = 0; |
69 | 69 | ||
70 | setFocusPolicy( NoFocus ); | 70 | setFocusPolicy( NoFocus ); |
71 | 71 | ||
72 | setFixedWidth ( AppLnk::smallIconSize() ); | 72 | setFixedWidth ( AppLnk::smallIconSize() ); |
73 | setFixedHeight ( AppLnk::smallIconSize() ); | 73 | setFixedHeight ( AppLnk::smallIconSize() ); |
74 | 74 | ||
75 | getStatusPcmcia( TRUE ); | 75 | getStatusPcmcia( TRUE ); |
76 | getStatusSd( TRUE ); | 76 | getStatusSd( TRUE ); |
77 | repaint( FALSE ); | 77 | repaint( FALSE ); |
78 | popupMenu = 0; | 78 | popupMenu = 0; |
79 | } | 79 | } |
80 | 80 | ||
81 | CardMonitor::~CardMonitor() { | 81 | CardMonitor::~CardMonitor() { |
82 | delete popupMenu; | 82 | delete popupMenu; |
83 | } | 83 | } |
84 | 84 | ||
85 | void CardMonitor::popUp( QString message, QString icon ) { | 85 | void CardMonitor::popUp( QString message, QString icon ) { |
86 | if ( !popupMenu ) { | 86 | if ( !popupMenu ) { |
87 | popupMenu = new QPopupMenu( this ); | 87 | popupMenu = new QPopupMenu( this ); |
88 | } | 88 | } |
89 | 89 | ||
90 | popupMenu->clear(); | 90 | popupMenu->clear(); |
91 | if ( icon.isEmpty() ) { | 91 | if ( icon.isEmpty() ) { |
92 | popupMenu->insertItem( message, 0 ); | 92 | popupMenu->insertItem( message, 0 ); |
93 | } else { | 93 | } else { |
94 | popupMenu->insertItem( QIconSet( Resource::loadPixmap( icon ) ), | 94 | popupMenu->insertItem( QIconSet( Resource::loadPixmap( icon ) ), |
95 | message, 0 ); | 95 | message, 0 ); |
96 | } | 96 | } |
97 | 97 | ||
98 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); | 98 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); |
99 | QSize s = popupMenu->sizeHint(); | 99 | QSize s = popupMenu->sizeHint(); |
100 | popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), | 100 | popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), |
101 | p.y() - s.height() ), 0 ); | 101 | p.y() - s.height() ), 0 ); |
102 | 102 | ||
103 | QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); | 103 | QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); |
104 | } | 104 | } |
105 | 105 | ||
106 | void CardMonitor::popupTimeout() { | 106 | void CardMonitor::popupTimeout() { |
107 | popupMenu->hide(); | 107 | popupMenu->hide(); |
108 | } | 108 | } |
109 | 109 | ||
110 | void CardMonitor::mousePressEvent( QMouseEvent * ) { | 110 | void CardMonitor::mousePressEvent( QMouseEvent * ) { |
111 | QPopupMenu * menu = new QPopupMenu( this ); | 111 | QPopupMenu * menu = new QPopupMenu( this ); |
112 | QStringList cmd; | 112 | QStringList cmd; |
113 | bool execute = true; | 113 | bool execute = true; |
114 | 114 | ||
115 | if ( cardInSd ) { | 115 | if ( cardInSd ) { |
116 | menu->insertItem( QIconSet( Resource::loadPixmap( "cardmon/ide" ) ), | 116 | menu->insertItem( QIconSet( Resource::loadPixmap( "cardmon/ide" ) ), |
117 | tr( "Eject SD/MMC card" ), 0 ); | 117 | tr( "Eject SD/MMC card" ), 0 ); |
118 | } | 118 | } |
119 | 119 | ||
120 | if ( cardInPcmcia0 ) { | 120 | if ( cardInPcmcia0 ) { |
121 | menu-> | 121 | menu-> |
122 | insertItem( QIconSet | 122 | insertItem( QIconSet |
123 | ( Resource::loadPixmap( "cardmon/" + cardInPcmcia0Type ) ), | 123 | ( Resource::loadPixmap( "cardmon/" + cardInPcmcia0Type ) ), |
124 | tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 ); | 124 | tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 ); |
125 | } | 125 | } |
126 | 126 | ||
127 | if ( cardInPcmcia1 ) { | 127 | if ( cardInPcmcia1 ) { |
128 | menu-> | 128 | menu-> |
129 | insertItem( QIconSet | 129 | insertItem( QIconSet |
130 | ( Resource::loadPixmap( "cardmon/" + cardInPcmcia1Type ) ), | 130 | ( Resource::loadPixmap( "cardmon/" + cardInPcmcia1Type ) ), |
131 | tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); | 131 | tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); |
132 | } | 132 | } |
133 | 133 | ||
134 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); | 134 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); |
135 | QSize s = menu->sizeHint(); | 135 | QSize s = menu->sizeHint(); |
136 | int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), | 136 | int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), |
137 | p.y() - s.height() ), 0 ); | 137 | p.y() - s.height() ), 0 ); |
138 | 138 | ||
139 | if ( opt == 1 ) { | 139 | if ( opt == 1 ) { |
140 | m_commandOrig = PCMCIA_Socket1; | 140 | m_commandOrig = PCMCIA_Socket1; |
141 | cmd << "/sbin/cardctl" << "eject" << "0"; | 141 | cmd << "/sbin/cardctl" << "eject" << "0"; |
142 | } else if ( opt == 0 ) { | 142 | } else if ( opt == 0 ) { |
143 | m_commandOrig = MMC_Socket; | 143 | m_commandOrig = MMC_Socket; |
144 | cmd << "umount" << cardSdName; | 144 | cmd << "umount" << cardSdName; |
145 | } else if ( opt == 2 ) { | 145 | } else if ( opt == 2 ) { |
146 | m_commandOrig = PCMCIA_Socket2; | 146 | m_commandOrig = PCMCIA_Socket2; |
147 | cmd << "/sbin/cardctl" << "eject" << "1"; | 147 | cmd << "/sbin/cardctl" << "eject" << "1"; |
148 | }else | 148 | }else |
149 | execute = false; | 149 | execute = false; |
150 | 150 | ||
151 | if ( execute ) | 151 | if ( execute ) |
152 | execCommand( cmd ); | 152 | execCommand( cmd ); |
153 | 153 | ||
154 | delete menu; | 154 | delete menu; |
155 | } | 155 | } |
156 | 156 | ||
157 | 157 | ||
158 | void CardMonitor::cardMessage( const QCString & msg, const QByteArray & ) { | 158 | void CardMonitor::cardMessage( const QCString & msg, const QByteArray & ) { |
159 | if ( msg == "stabChanged()" ) { | 159 | if ( msg == "stabChanged()" ) { |
160 | // odebug << "Pcmcia: stabchanged" << oendl; | 160 | // odebug << "Pcmcia: stabchanged" << oendl; |
161 | getStatusPcmcia(); | 161 | getStatusPcmcia(); |
162 | } else if ( msg == "mtabChanged()" ) { | 162 | } else if ( msg == "mtabChanged()" ) { |
163 | // odebug << "CARDMONAPPLET: mtabchanged" << oendl; | 163 | // odebug << "CARDMONAPPLET: mtabchanged" << oendl; |
164 | getStatusSd(); | 164 | getStatusSd(); |
165 | } | 165 | } |
166 | } | 166 | } |
167 | 167 | ||
168 | bool CardMonitor::getStatusPcmcia( int showPopUp ) { | 168 | bool CardMonitor::getStatusPcmcia( int showPopUp ) { |
169 | 169 | ||
170 | bool cardWas0 = cardInPcmcia0; // remember last state | 170 | bool cardWas0 = cardInPcmcia0; // remember last state |
171 | bool cardWas1 = cardInPcmcia1; | 171 | bool cardWas1 = cardInPcmcia1; |
172 | 172 | ||
173 | QString fileName; | 173 | QString fileName; |
174 | 174 | ||
175 | // one of these 3 files should exist | 175 | // one of these 3 files should exist |
176 | if ( QFile::exists( "/var/run/stab" ) ) { | 176 | if ( QFile::exists( "/var/run/stab" ) ) { |
177 | fileName = "/var/run/stab"; | 177 | fileName = "/var/run/stab"; |
178 | } else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { | 178 | } else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { |
179 | fileName = "/var/state/pcmcia/stab"; | 179 | fileName = "/var/state/pcmcia/stab"; |
180 | } else { | 180 | } else { |
181 | fileName = "/var/lib/pcmcia/stab"; | 181 | fileName = "/var/lib/pcmcia/stab"; |
182 | } | 182 | } |
183 | 183 | ||
184 | QFile f( fileName ); | 184 | QFile f( fileName ); |
185 | 185 | ||
186 | if ( f.open( IO_ReadOnly ) ) { | 186 | if ( f.open( IO_ReadOnly ) ) { |
187 | QStringList list; | 187 | QStringList list; |
188 | QTextStream stream( &f ); | 188 | QTextStream stream( &f ); |
189 | QString streamIn; | 189 | QString streamIn; |
190 | streamIn = stream.read(); | 190 | streamIn = stream.read(); |
191 | list = QStringList::split( "\n", streamIn ); | 191 | list = QStringList::split( "\n", streamIn ); |
192 | for ( QStringList::Iterator line = list.begin(); line != list.end(); | 192 | for ( QStringList::Iterator line = list.begin(); line != list.end(); |
193 | line++ ) { | 193 | line++ ) { |
194 | if ( ( *line ).startsWith( "Socket 0:" ) ) { | 194 | if ( ( *line ).startsWith( "Socket 0:" ) ) { |
195 | if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ) { | 195 | if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ) { |
196 | cardInPcmcia0 = FALSE; | 196 | cardInPcmcia0 = FALSE; |
197 | } else if ( !( *line ).startsWith( "Socket 0: empty" ) | 197 | } else if ( !( *line ).startsWith( "Socket 0: empty" ) |
198 | && !cardInPcmcia0 ) { | 198 | && !cardInPcmcia0 ) { |
199 | cardInPcmcia0Name = | 199 | cardInPcmcia0Name = |
200 | ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), | 200 | ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), |
201 | ( *line ).length() - 9 ); | 201 | ( *line ).length() - 9 ); |
202 | cardInPcmcia0Name.stripWhiteSpace(); | 202 | cardInPcmcia0Name.stripWhiteSpace(); |
203 | cardInPcmcia0 = TRUE; | 203 | cardInPcmcia0 = TRUE; |
204 | show(); | 204 | show(); |
205 | line++; | 205 | line++; |
206 | int pos = ( *line ).find( '\t' ) + 1; | 206 | int pos = ( *line ).find( '\t' ) + 1; |
207 | cardInPcmcia0Type = | 207 | cardInPcmcia0Type = |
208 | ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); | 208 | ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); |
209 | } | 209 | } |
210 | } else if ( ( *line ).startsWith( "Socket 1:" ) ) { | 210 | } else if ( ( *line ).startsWith( "Socket 1:" ) ) { |
211 | if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) { | 211 | if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) { |
212 | cardInPcmcia1 = FALSE; | 212 | cardInPcmcia1 = FALSE; |
213 | } else if ( !( *line ).startsWith( "Socket 1: empty" ) | 213 | } else if ( !( *line ).startsWith( "Socket 1: empty" ) |
214 | && !cardInPcmcia1 ) { | 214 | && !cardInPcmcia1 ) { |
215 | cardInPcmcia1Name = | 215 | cardInPcmcia1Name = |
216 | ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), | 216 | ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), |
217 | ( *line ).length() - 9 ); | 217 | ( *line ).length() - 9 ); |
218 | cardInPcmcia1Name.stripWhiteSpace(); | 218 | cardInPcmcia1Name.stripWhiteSpace(); |
219 | cardInPcmcia1 = TRUE; | 219 | cardInPcmcia1 = TRUE; |
220 | show(); | 220 | show(); |
221 | line++; | 221 | line++; |
222 | int pos = ( *line ).find( '\t' ) + 1; | 222 | int pos = ( *line ).find( '\t' ) + 1; |
223 | cardInPcmcia1Type = | 223 | cardInPcmcia1Type = |
224 | ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); | 224 | ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); |
225 | } | 225 | } |
226 | } | 226 | } |
227 | } | 227 | } |
228 | f.close(); | 228 | f.close(); |
229 | 229 | ||
230 | if ( !showPopUp | 230 | if ( !showPopUp |
231 | && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) ) { | 231 | && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) ) { |
232 | QString text = QString::null; | 232 | QString text = QString::null; |
233 | QString what = QString::null; | 233 | QString what = QString::null; |
234 | if ( cardWas0 != cardInPcmcia0 ) { | 234 | if ( cardWas0 != cardInPcmcia0 ) { |
235 | if ( cardInPcmcia0 ) { | 235 | if ( cardInPcmcia0 ) { |
236 | text += tr( "New card: " ); | 236 | text += tr( "New card: " ); |
237 | what = "on"; | 237 | what = "on"; |
238 | } else { | 238 | } else { |
239 | text += tr( "Ejected: " ); | 239 | text += tr( "Ejected: " ); |
240 | what = "off"; | 240 | what = "off"; |
241 | } | 241 | } |
242 | text += cardInPcmcia0Name; | 242 | text += cardInPcmcia0Name; |
243 | popUp( text, "cardmon/" + cardInPcmcia0Type ); | 243 | popUp( text, "cardmon/" + cardInPcmcia0Type ); |
244 | } | 244 | } |
245 | 245 | ||
246 | if ( cardWas1 != cardInPcmcia1 ) { | 246 | if ( cardWas1 != cardInPcmcia1 ) { |
247 | if ( cardInPcmcia1 ) { | 247 | if ( cardInPcmcia1 ) { |
248 | text += tr( "New card: " ); | 248 | text += tr( "New card: " ); |
249 | what = "on"; | 249 | what = "on"; |
250 | } else { | 250 | } else { |
251 | text += tr( "Ejected: " ); | 251 | text += tr( "Ejected: " ); |
252 | what = "off"; | 252 | what = "off"; |
253 | } | 253 | } |
254 | text += cardInPcmcia1Name; | 254 | text += cardInPcmcia1Name; |
255 | popUp( text, "cardmon/" + cardInPcmcia1Type ); | 255 | popUp( text, "cardmon/" + cardInPcmcia1Type ); |
256 | } | 256 | } |
257 | #ifndef QT_NO_SOUND | 257 | #ifndef QT_NO_SOUND |
258 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); | 258 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); |
259 | #endif | 259 | #endif |
260 | 260 | ||
261 | } | 261 | } |
262 | } else { | 262 | } else { |
263 | // no file found | 263 | // no file found |
264 | odebug << "no file found" << oendl; | 264 | odebug << "no file found" << oendl; |
265 | cardInPcmcia0 = FALSE; | 265 | cardInPcmcia0 = FALSE; |
266 | cardInPcmcia1 = FALSE; | 266 | cardInPcmcia1 = FALSE; |
267 | } | 267 | } |
268 | repaint( FALSE ); | 268 | repaint( FALSE ); |
269 | return ( ( cardWas0 == cardInPcmcia0 | 269 | return ( ( cardWas0 == cardInPcmcia0 |
270 | && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE ); | 270 | && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE ); |
271 | 271 | ||
272 | } | 272 | } |
273 | 273 | ||
274 | 274 | ||
275 | bool CardMonitor::getStatusSd( int showPopUp ) { | 275 | bool CardMonitor::getStatusSd( int showPopUp ) { |
276 | 276 | ||
277 | bool cardWas = cardInSd; // remember last state | 277 | bool cardWas = cardInSd; // remember last state |
278 | cardInSd = FALSE; | 278 | cardInSd = FALSE; |
279 | 279 | ||
280 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 280 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
281 | 281 | ||
282 | struct mntent *me; | 282 | struct mntent *me; |
283 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); | 283 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); |
284 | 284 | ||
285 | if ( mntfp ) { | 285 | if ( mntfp ) { |
286 | while ( ( me = getmntent( mntfp ) ) != 0 ) { | 286 | while ( ( me = getmntent( mntfp ) ) != 0 ) { |
287 | QString fs = QFile::decodeName( me->mnt_fsname ); | 287 | QString fs = QFile::decodeName( me->mnt_fsname ); |
288 | //odebug << fs << oendl; | 288 | //odebug << fs << oendl; |
289 | if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd" | 289 | if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd" |
290 | || fs.left( 9 ) == "/dev/mmcd" ) { | 290 | || fs.left( 9 ) == "/dev/mmcd" || fs.left(11) == "/dev/mmcblk" ) { |
291 | cardInSd = TRUE; | 291 | cardInSd = TRUE; |
292 | cardSdName = fs; | 292 | cardSdName = fs; |
293 | show(); | 293 | show(); |
294 | } | 294 | } |
295 | // else { | 295 | // else { |
296 | // cardInSd = FALSE; | 296 | // cardInSd = FALSE; |
297 | // } | 297 | // } |
298 | } | 298 | } |
299 | endmntent( mntfp ); | 299 | endmntent( mntfp ); |
300 | } | 300 | } |
301 | 301 | ||
302 | if ( !showPopUp && cardWas != cardInSd ) { | 302 | if ( !showPopUp && cardWas != cardInSd ) { |
303 | QString text = QString::null; | 303 | QString text = QString::null; |
304 | QString what = QString::null; | 304 | QString what = QString::null; |
305 | if ( cardInSd ) { | 305 | if ( cardInSd ) { |
306 | text += tr("New card: SD/MMC"); | 306 | text += tr("New card: SD/MMC"); |
307 | what = "on"; | 307 | what = "on"; |
308 | } else { | 308 | } else { |
309 | text += tr("Ejected: SD/MMC"); | 309 | text += tr("Ejected: SD/MMC"); |
310 | what = "off"; | 310 | what = "off"; |
311 | } | 311 | } |
312 | //odebug << "TEXT: " + text << oendl; | 312 | //odebug << "TEXT: " + text << oendl; |
313 | #ifndef QT_NO_SOUND | 313 | #ifndef QT_NO_SOUND |
314 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); | 314 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); |
315 | #endif | 315 | #endif |
316 | 316 | ||
317 | popUp( text, "cardmon/ide" ); // XX add SD pic | 317 | popUp( text, "cardmon/ide" ); // XX add SD pic |
318 | } | 318 | } |
319 | #else | 319 | #else |
320 | #error "Not on Linux" | 320 | #error "Not on Linux" |
321 | #endif | 321 | #endif |
322 | repaint( FALSE ); | 322 | repaint( FALSE ); |
323 | return ( ( cardWas == cardInSd ) ? FALSE : TRUE ); | 323 | return ( ( cardWas == cardInSd ) ? FALSE : TRUE ); |
324 | } | 324 | } |
325 | 325 | ||
326 | void CardMonitor::paintEvent( QPaintEvent * ) { | 326 | void CardMonitor::paintEvent( QPaintEvent * ) { |
327 | 327 | ||
328 | QPainter p( this ); | 328 | QPainter p( this ); |
329 | 329 | ||
330 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { | 330 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { |
331 | p.drawPixmap( 0, 0, pm ); | 331 | p.drawPixmap( 0, 0, pm ); |
332 | show(); | 332 | show(); |
333 | } else { | 333 | } else { |
334 | //p.eraseRect(rect()); | 334 | //p.eraseRect(rect()); |
335 | hide(); | 335 | hide(); |
336 | } | 336 | } |
337 | } | 337 | } |
338 | 338 | ||
339 | int CardMonitor::position() { | 339 | int CardMonitor::position() { |
340 | return 7; | 340 | return 7; |
341 | } | 341 | } |
342 | 342 | ||
343 | void CardMonitor::execCommand( const QStringList &strList ) { | 343 | void CardMonitor::execCommand( const QStringList &strList ) { |
344 | delete m_process; | 344 | delete m_process; |
345 | m_process = 0; | 345 | m_process = 0; |
346 | 346 | ||
347 | if ( m_process == 0 ) { | 347 | if ( m_process == 0 ) { |
348 | m_process = new OProcess(); | 348 | m_process = new OProcess(); |
349 | 349 | ||
350 | 350 | ||
351 | for ( QStringList::ConstIterator it = strList.begin(); it != strList.end(); ++it ) { | 351 | for ( QStringList::ConstIterator it = strList.begin(); it != strList.end(); ++it ) { |
352 | *m_process << *it; | 352 | *m_process << *it; |
353 | } | 353 | } |
354 | 354 | ||
355 | connect(m_process, SIGNAL(processExited(Opie::Core::OProcess*)), | 355 | connect(m_process, SIGNAL(processExited(Opie::Core::OProcess*)), |
356 | this, SLOT( slotExited(Opie::Core::OProcess*))); | 356 | this, SLOT( slotExited(Opie::Core::OProcess*))); |
357 | 357 | ||
358 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ) { | 358 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ) { |
359 | delete m_process; | 359 | delete m_process; |
360 | m_process = 0; | 360 | m_process = 0; |
361 | } | 361 | } |
362 | } | 362 | } |
363 | } | 363 | } |
364 | 364 | ||
365 | void CardMonitor::slotExited( OProcess* ) { | 365 | void CardMonitor::slotExited( OProcess* ) { |
366 | 366 | ||
367 | if( m_process->normalExit() ) { | 367 | if( m_process->normalExit() ) { |
368 | int ret = m_process->exitStatus(); | 368 | int ret = m_process->exitStatus(); |
369 | if( ret != 0 ) { | 369 | if( ret != 0 ) { |
370 | if ( m_commandOrig == PCMCIA_Socket1 || | 370 | if ( m_commandOrig == PCMCIA_Socket1 || |
371 | m_commandOrig == PCMCIA_Socket2 ) { | 371 | m_commandOrig == PCMCIA_Socket2 ) { |
372 | popUp( tr( "CF/PCMCIA card eject failed!" ) ); | 372 | popUp( tr( "CF/PCMCIA card eject failed!" ) ); |
373 | } else if ( m_commandOrig == MMC_Socket ) { | 373 | } else if ( m_commandOrig == MMC_Socket ) { |
374 | popUp( tr( "SD/MMC card eject failed!" ) ); | 374 | popUp( tr( "SD/MMC card eject failed!" ) ); |
375 | } | 375 | } |
376 | } | 376 | } |
377 | } | 377 | } |
378 | } | 378 | } |
379 | 379 | ||
380 | EXPORT_OPIE_APPLET_v1( CardMonitor ) | 380 | EXPORT_OPIE_APPLET_v1( CardMonitor ) |
381 | 381 | ||