summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/cardmon/cardmon.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp
index 25bb137..f3f9044 100644
--- a/core/applets/cardmon/cardmon.cpp
+++ b/core/applets/cardmon/cardmon.cpp
@@ -22,320 +22,323 @@
22#include <qpe/resource.h> 22#include <qpe/resource.h>
23 23
24#include <opie/odevice.h> 24#include <opie/odevice.h>
25 25
26#include <qcopchannel_qws.h> 26#include <qcopchannel_qws.h>
27#include <qpainter.h> 27#include <qpainter.h>
28#include <qmessagebox.h> 28#include <qmessagebox.h>
29#include <qfile.h> 29#include <qfile.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qtimer.h> 31#include <qtimer.h>
32#include <qapplication.h> 32#include <qapplication.h>
33 33
34#include <stdio.h> 34#include <stdio.h>
35#include <unistd.h> 35#include <unistd.h>
36#include <stdlib.h> 36#include <stdlib.h>
37#include <string.h> 37#include <string.h>
38#include <fcntl.h> 38#include <fcntl.h>
39#include <qsound.h> 39#include <qsound.h>
40 40
41#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 41#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
42#include <sys/vfs.h> 42#include <sys/vfs.h>
43#include <mntent.h> 43#include <mntent.h>
44#endif 44#endif
45 45
46using namespace Opie; 46using namespace Opie;
47 47
48CardMonitor::CardMonitor(QWidget * parent):QWidget(parent), 48CardMonitor::CardMonitor(QWidget * parent):QWidget(parent),
49pm(Resource:: 49pm(Resource::
50 loadPixmap("cardmon/pcmcia")) 50 loadPixmap("cardmon/pcmcia"))
51{ 51{
52 52
53 QCopChannel *pcmciaChannel = new QCopChannel("QPE/Card", this); 53 QCopChannel *pcmciaChannel = new QCopChannel("QPE/Card", this);
54 connect(pcmciaChannel, 54 connect(pcmciaChannel,
55 SIGNAL(received(const QCString &, const QByteArray &)), this, 55 SIGNAL(received(const QCString &, const QByteArray &)), this,
56 SLOT(cardMessage(const QCString &, const QByteArray &))); 56 SLOT(cardMessage(const QCString &, const QByteArray &)));
57 57
58 QCopChannel *sdChannel = new QCopChannel("QPE/Card", this); 58 QCopChannel *sdChannel = new QCopChannel("QPE/Card", this);
59 connect(sdChannel, 59 connect(sdChannel,
60 SIGNAL(received(const QCString &, const QByteArray &)), this, 60 SIGNAL(received(const QCString &, const QByteArray &)), this,
61 SLOT(cardMessage(const QCString &, const QByteArray &))); 61 SLOT(cardMessage(const QCString &, const QByteArray &)));
62 62
63 cardInPcmcia0 = FALSE; 63 cardInPcmcia0 = FALSE;
64 cardInPcmcia1 = FALSE; 64 cardInPcmcia1 = FALSE;
65 cardInSd = FALSE; 65 cardInSd = FALSE;
66 66
67 setFixedSize(pm.size()); 67 setFixedSize(pm.size());
68 getStatusPcmcia(TRUE); 68 getStatusPcmcia(TRUE);
69 getStatusSd(TRUE); 69 getStatusSd(TRUE);
70 repaint(FALSE); 70 repaint(FALSE);
71 popupMenu = 0; 71 popupMenu = 0;
72} 72}
73 73
74CardMonitor::~CardMonitor() 74CardMonitor::~CardMonitor()
75{ 75{
76 if (popupMenu) { 76 if (popupMenu) {
77 delete popupMenu; 77 delete popupMenu;
78 } 78 }
79} 79}
80 80
81void CardMonitor::popUp(QString message, QString icon) 81void CardMonitor::popUp(QString message, QString icon)
82{ 82{
83 if (!popupMenu) { 83 if (!popupMenu) {
84 popupMenu = new QPopupMenu(this); 84 popupMenu = new QPopupMenu(this);
85 } 85 }
86 86
87 popupMenu->clear(); 87 popupMenu->clear();
88 if (icon.isEmpty()) { 88 if (icon.isEmpty()) {
89 popupMenu->insertItem(message, 0); 89 popupMenu->insertItem(message, 0);
90 } else { 90 } else {
91 popupMenu->insertItem(QIconSet(Resource::loadPixmap(icon)), 91 popupMenu->insertItem(QIconSet(Resource::loadPixmap(icon)),
92 message, 0); 92 message, 0);
93 } 93 }
94 94
95 QPoint p = mapToGlobal(QPoint(0, 0)); 95 QPoint p = mapToGlobal(QPoint(0, 0));
96 QSize s = popupMenu->sizeHint(); 96 QSize s = popupMenu->sizeHint();
97 popupMenu->popup(QPoint(p.x() + (width() / 2) - (s.width() / 2), 97 popupMenu->popup(QPoint(p.x() + (width() / 2) - (s.width() / 2),
98 p.y() - s.height()), 0); 98 p.y() - s.height()), 0);
99 99
100 QTimer::singleShot(2000, this, SLOT(popupTimeout())); 100 QTimer::singleShot(2000, this, SLOT(popupTimeout()));
101} 101}
102 102
103void CardMonitor::popupTimeout() 103void CardMonitor::popupTimeout()
104{ 104{
105 popupMenu->hide(); 105 popupMenu->hide();
106} 106}
107 107
108void CardMonitor::mousePressEvent(QMouseEvent *) 108void CardMonitor::mousePressEvent(QMouseEvent *)
109{ 109{
110 QPopupMenu *menu = new QPopupMenu(this); 110 QPopupMenu *menu = new QPopupMenu(this);
111 QString cmd; 111 QString cmd;
112 int err = 0; 112 int err = 0;
113 113
114 if (cardInSd) { 114 if (cardInSd) {
115 menu->insertItem(QIconSet(Resource::loadPixmap("cardmon/ide")), 115 menu->insertItem(QIconSet(Resource::loadPixmap("cardmon/ide")),
116 tr("Eject SD/MMC card"), 0); 116 tr("Eject SD/MMC card"), 0);
117 } 117 }
118 118
119 if (cardInPcmcia0) { 119 if (cardInPcmcia0) {
120 menu-> 120 menu->
121 insertItem(QIconSet 121 insertItem(QIconSet
122 (Resource::loadPixmap("cardmon/" + cardInPcmcia0Type)), 122 (Resource::loadPixmap("cardmon/" + cardInPcmcia0Type)),
123 tr("Eject card 0: %1").arg(cardInPcmcia0Name), 1); 123 tr("Eject card 0: %1").arg(cardInPcmcia0Name), 1);
124 } 124 }
125 125
126 if (cardInPcmcia1) { 126 if (cardInPcmcia1) {
127 menu-> 127 menu->
128 insertItem(QIconSet 128 insertItem(QIconSet
129 (Resource::loadPixmap("cardmon/" + cardInPcmcia1Type)), 129 (Resource::loadPixmap("cardmon/" + cardInPcmcia1Type)),
130 tr("Eject card 1: %1").arg(cardInPcmcia1Name), 2); 130 tr("Eject card 1: %1").arg(cardInPcmcia1Name), 2);
131 } 131 }
132 132
133 QPoint p = mapToGlobal(QPoint(0, 0)); 133 QPoint p = mapToGlobal(QPoint(0, 0));
134 QSize s = menu->sizeHint(); 134 QSize s = menu->sizeHint();
135 int opt = menu->exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), 135 int opt = menu->exec(QPoint(p.x() + (width() / 2) - (s.width() / 2),
136 p.y() - s.height()), 0); 136 p.y() - s.height()), 0);
137 137
138 if (opt == 1) { 138 if (opt == 1) {
139 cmd = "/sbin/cardctl eject 0"; 139 cmd = "/sbin/cardctl eject 0";
140 err = system((const char *) cmd); 140 err = system((const char *) cmd);
141 if (err != 0) { 141 if (err != 0) {
142 qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", 142 qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d",
143 err); 143 err);
144 popUp(tr("CF/PCMCIA card eject failed!")); 144 popUp(tr("CF/PCMCIA card eject failed!"));
145 } 145 }
146 } else if (opt == 0) { 146 } else if (opt == 0) {
147 if (ODevice::inst()->system() == System_Familiar) { 147 if (ODevice::inst()->system() == System_Familiar) {
148 cmd = "umount /dev/mmc/part1"; 148 cmd = "umount /dev/mmc/part1";
149 } else { 149 } else {
150 cmd = "umount /dev/mmcda1"; 150 cmd = "umount /dev/mmcda1";
151 } 151 }
152 err = system((const char *) cmd); 152 err = system((const char *) cmd);
153 if (err != 0) { 153 if (err != 0) {
154 popUp(tr("SD/MMC card eject failed!")); 154 popUp(tr("SD/MMC card eject failed!"));
155 } 155 }
156 } else if (opt == 2) { 156 } else if (opt == 2) {
157 cmd = "/sbin/cardctl eject 1"; 157 cmd = "/sbin/cardctl eject 1";
158 err = system((const char *) cmd); 158 err = system((const char *) cmd);
159 if (err != 0) { 159 if (err != 0) {
160 qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", 160 qDebug("Could not execute `/sbin/cardctl eject 1'! 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 delete menu; 165 delete menu;
166} 166}
167 167
168 168
169void CardMonitor::cardMessage(const QCString & msg, const QByteArray &) 169void CardMonitor::cardMessage(const QCString & msg, const QByteArray &)
170{ 170{
171 if (msg == "stabChanged()") { 171 if (msg == "stabChanged()") {
172 // qDebug("Pcmcia: stabchanged"); 172 // qDebug("Pcmcia: stabchanged");
173 getStatusPcmcia(); 173 getStatusPcmcia();
174 } else if (msg == "mtabChanged()") { 174 } else if (msg == "mtabChanged()") {
175 // qDebug("CARDMONAPPLET: mtabchanged"); 175 // qDebug("CARDMONAPPLET: mtabchanged");
176 getStatusSd(); 176 getStatusSd();
177 } 177 }
178} 178}
179 179
180bool CardMonitor::getStatusPcmcia(int showPopUp) 180bool CardMonitor::getStatusPcmcia(int showPopUp)
181{ 181{
182 182
183 bool cardWas0 = cardInPcmcia0;// remember last state 183 bool cardWas0 = cardInPcmcia0;// remember last state
184 bool cardWas1 = cardInPcmcia1; 184 bool cardWas1 = cardInPcmcia1;
185 185
186 QString fileName; 186 QString fileName;
187 187
188 // one of these 3 files should exist 188 // one of these 3 files should exist
189 if (QFile::exists("/var/run/stab")) { 189 if (QFile::exists("/var/run/stab")) {
190 fileName = "/var/run/stab"; 190 fileName = "/var/run/stab";
191 } else if (QFile::exists("/var/state/pcmcia/stab")) { 191 } else if (QFile::exists("/var/state/pcmcia/stab")) {
192 fileName = "/var/state/pcmcia/stab"; 192 fileName = "/var/state/pcmcia/stab";
193 } else { 193 } else {
194 fileName = "/var/lib/pcmcia/stab"; 194 fileName = "/var/lib/pcmcia/stab";
195 } 195 }
196 196
197 QFile f(fileName); 197 QFile f(fileName);
198 198
199 if (f.open(IO_ReadOnly)) { 199 if (f.open(IO_ReadOnly)) {
200 QStringList list; 200 QStringList list;
201 QTextStream stream(&f); 201 QTextStream stream(&f);
202 QString streamIn; 202 QString streamIn;
203 streamIn = stream.read(); 203 streamIn = stream.read();
204 list = QStringList::split("\n", streamIn); 204 list = QStringList::split("\n", streamIn);
205 for (QStringList::Iterator line = list.begin(); line != list.end(); 205 for (QStringList::Iterator line = list.begin(); line != list.end();
206 line++) { 206 line++) {
207 if ((*line).startsWith("Socket 0:")) { 207 if ((*line).startsWith("Socket 0:")) {
208 if ((*line).startsWith("Socket 0: empty") && cardInPcmcia0) { 208 if ((*line).startsWith("Socket 0: empty") && cardInPcmcia0) {
209 cardInPcmcia0 = FALSE; 209 cardInPcmcia0 = FALSE;
210 } else if (!(*line).startsWith("Socket 0: empty") 210 } else if (!(*line).startsWith("Socket 0: empty")
211 && !cardInPcmcia0) { 211 && !cardInPcmcia0) {
212 cardInPcmcia0Name = 212 cardInPcmcia0Name =
213 (*line).mid(((*line).find(':') + 1), 213 (*line).mid(((*line).find(':') + 1),
214 (*line).length() - 9); 214 (*line).length() - 9);
215 cardInPcmcia0Name.stripWhiteSpace(); 215 cardInPcmcia0Name.stripWhiteSpace();
216 cardInPcmcia0 = TRUE; 216 cardInPcmcia0 = TRUE;
217 show(); 217 show();
218 line++; 218 line++;
219 int pos = (*line).find('\t') + 1; 219 int pos = (*line).find('\t') + 1;
220 cardInPcmcia0Type = 220 cardInPcmcia0Type =
221 (*line).mid(pos, (*line).find("\t", pos) - pos); 221 (*line).mid(pos, (*line).find("\t", pos) - pos);
222 } 222 }
223 } else if ((*line).startsWith("Socket 1:")) { 223 } else if ((*line).startsWith("Socket 1:")) {
224 if ((*line).startsWith("Socket 1: empty") && cardInPcmcia1) { 224 if ((*line).startsWith("Socket 1: empty") && cardInPcmcia1) {
225 cardInPcmcia1 = FALSE; 225 cardInPcmcia1 = FALSE;
226 } else if (!(*line).startsWith("Socket 1: empty") 226 } else if (!(*line).startsWith("Socket 1: empty")
227 && !cardInPcmcia1) { 227 && !cardInPcmcia1) {
228 cardInPcmcia1Name = 228 cardInPcmcia1Name =
229 (*line).mid(((*line).find(':') + 1), 229 (*line).mid(((*line).find(':') + 1),
230 (*line).length() - 9); 230 (*line).length() - 9);
231 cardInPcmcia1Name.stripWhiteSpace(); 231 cardInPcmcia1Name.stripWhiteSpace();
232 cardInPcmcia1 = TRUE; 232 cardInPcmcia1 = TRUE;
233 show(); 233 show();
234 line++; 234 line++;
235 int pos = (*line).find('\t') + 1; 235 int pos = (*line).find('\t') + 1;
236 cardInPcmcia1Type = 236 cardInPcmcia1Type =
237 (*line).mid(pos, (*line).find("\t", pos) - pos); 237 (*line).mid(pos, (*line).find("\t", pos) - pos);
238 } 238 }
239 } 239 }
240 } 240 }
241 f.close(); 241 f.close();
242 242
243 if (!showPopUp 243 if (!showPopUp
244 && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1)) { 244 && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1)) {
245 QString text = QString::null; 245 QString text = QString::null;
246 QString what = QString::null; 246 QString what = QString::null;
247 if (cardWas0 != cardInPcmcia0) { 247 if (cardWas0 != cardInPcmcia0) {
248 if (cardInPcmcia0) { 248 if (cardInPcmcia0) {
249 text += tr("New card: "); 249 text += tr("New card: ");
250 what = "on"; 250 what = "on";
251 } else { 251 } else {
252 text += tr("Ejected: "); 252 text += tr("Ejected: ");
253 what = "off"; 253 what = "off";
254 } 254 }
255 text += cardInPcmcia0Name; 255 text += cardInPcmcia0Name;
256 popUp(text, "cardmon/" + cardInPcmcia0Type); 256 popUp(text, "cardmon/" + cardInPcmcia0Type);
257 } 257 }
258 258
259 if (cardWas1 != cardInPcmcia1) { 259 if (cardWas1 != cardInPcmcia1) {
260 if (cardInPcmcia1) { 260 if (cardInPcmcia1) {
261 text += tr("New card: "); 261 text += tr("New card: ");
262 what = "on"; 262 what = "on";
263 } else { 263 } else {
264 text += tr("Ejected: "); 264 text += tr("Ejected: ");
265 what = "off"; 265 what = "off";
266 } 266 }
267 text += cardInPcmcia1Name; 267 text += cardInPcmcia1Name;
268 popUp(text, "cardmon/" + cardInPcmcia1Type); 268 popUp(text, "cardmon/" + cardInPcmcia1Type);
269 } 269 }
270 QSound::play(Resource::findSound("cardmon/card" + what)); 270 QSound::play(Resource::findSound("cardmon/card" + what));
271 } 271 }
272 } else { 272 } else {
273 // no file found 273 // no file found
274 qDebug("no file found"); 274 qDebug("no file found");
275 cardInPcmcia0 = FALSE; 275 cardInPcmcia0 = FALSE;
276 cardInPcmcia1 = FALSE; 276 cardInPcmcia1 = FALSE;
277 } 277 }
278 repaint( FALSE );
278 return ((cardWas0 == cardInPcmcia0 279 return ((cardWas0 == cardInPcmcia0
279 && cardWas1 == cardInPcmcia1) ? FALSE : TRUE); 280 && cardWas1 == cardInPcmcia1) ? FALSE : TRUE);
281
280} 282}
281 283
282 284
283bool CardMonitor::getStatusSd(int showPopUp) 285bool CardMonitor::getStatusSd(int showPopUp)
284{ 286{
285 287
286 bool cardWas = cardInSd;// remember last state 288 bool cardWas = cardInSd;// remember last state
287 cardInSd = FALSE; 289 cardInSd = FALSE;
288 290
289#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 291#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
290 struct mntent *me; 292 struct mntent *me;
291 FILE *mntfp = setmntent("/etc/mtab", "r"); 293 FILE *mntfp = setmntent("/etc/mtab", "r");
292 294
293 if (mntfp) { 295 if (mntfp) {
294 while ((me = getmntent(mntfp)) != 0) { 296 while ((me = getmntent(mntfp)) != 0) {
295 QString fs = me->mnt_fsname; 297 QString fs = me->mnt_fsname;
296 //qDebug( fs ); 298 //qDebug( fs );
297 if (fs.left(14) == "/dev/mmc/part1" || fs.left(7) == "/dev/sd" 299 if (fs.left(14) == "/dev/mmc/part1" || fs.left(7) == "/dev/sd"
298 || fs.left(9) == "/dev/mmcd") { 300 || fs.left(9) == "/dev/mmcd") {
299 cardInSd = TRUE; 301 cardInSd = TRUE;
300 show(); 302 show();
301 } 303 }
302// else { 304// else {
303// cardInSd = FALSE; 305// cardInSd = FALSE;
304// } 306// }
305 } 307 }
306 endmntent(mntfp); 308 endmntent(mntfp);
307 } 309 }
308 310
309 if (!showPopUp && cardWas != cardInSd) { 311 if (!showPopUp && cardWas != cardInSd) {
310 QString text = QString::null; 312 QString text = QString::null;
311 QString what = QString::null; 313 QString what = QString::null;
312 if (cardInSd) { 314 if (cardInSd) {
313 text += "New card: SD/MMC"; 315 text += "New card: SD/MMC";
314 what = "on"; 316 what = "on";
315 } else { 317 } else {
316 text += "Ejected: SD/MMC"; 318 text += "Ejected: SD/MMC";
317 what = "off"; 319 what = "off";
318 } 320 }
319 //qDebug("TEXT: " + text ); 321 //qDebug("TEXT: " + text );
320 QSound::play(Resource::findSound("cardmon/card" + what)); 322 QSound::play(Resource::findSound("cardmon/card" + what));
321 popUp(text, "cardmon/ide");// XX add SD pic 323 popUp(text, "cardmon/ide");// XX add SD pic
322 } 324 }
323#else 325#else
324#error "Not on Linux" 326#error "Not on Linux"
325#endif 327#endif
328 repaint( FALSE );
326 return ((cardWas == cardInSd) ? FALSE : TRUE); 329 return ((cardWas == cardInSd) ? FALSE : TRUE);
327} 330}
328 331
329void CardMonitor::paintEvent(QPaintEvent *) 332void CardMonitor::paintEvent(QPaintEvent *)
330{ 333{
331 334
332 QPainter p(this); 335 QPainter p(this);
333 336
334 if (cardInPcmcia0 || cardInPcmcia1 || cardInSd) { 337 if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) {
335 p.drawPixmap(0, 0, pm); 338 p.drawPixmap(0, 0, pm);
336 show(); 339 show();
337 } else { 340 } else {
338 p.eraseRect(rect()); 341 //p.eraseRect(rect());
339 hide(); 342 hide();
340 } 343 }
341} 344}