summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/cardmon/cardmon.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp
index ffead4d..e94f1dc 100644
--- a/core/applets/cardmon/cardmon.cpp
+++ b/core/applets/cardmon/cardmon.cpp
@@ -1,196 +1,196 @@
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 19
20#include "cardmon.h" 20#include "cardmon.h"
21 21
22#include <qpe/resource.h> 22#include <qpe/resource.h>
23 23
24#include <qcopchannel_qws.h> 24#include <qcopchannel_qws.h>
25#include <qpainter.h> 25#include <qpainter.h>
26#include <qmessagebox.h> 26#include <qmessagebox.h>
27#include <qfile.h> 27#include <qfile.h>
28#include <qtextstream.h> 28#include <qtextstream.h>
29#include <qtimer.h> 29#include <qtimer.h>
30 30
31#include <stdio.h> 31#include <stdio.h>
32#include <unistd.h> 32#include <unistd.h>
33#include <stdlib.h> 33#include <stdlib.h>
34#include <string.h> 34#include <string.h>
35#include <fcntl.h> 35#include <fcntl.h>
36#include <qsound.h> 36#include <qsound.h>
37 37
38#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 38#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
39#include <sys/vfs.h> 39#include <sys/vfs.h>
40#include <mntent.h> 40#include <mntent.h>
41#endif 41#endif
42 42
43CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ), 43CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ),
44 pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) { 44 pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) {
45 45
46 QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this ); 46 QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this );
47 connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), 47 connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)),
48 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 48 this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
49 49
50 QCopChannel* sdChannel = new QCopChannel( "QPE/Card", this ); 50 QCopChannel* sdChannel = new QCopChannel( "QPE/Card", this );
51 connect( sdChannel, SIGNAL(received(const QCString &, const QByteArray &)), 51 connect( sdChannel, SIGNAL(received(const QCString &, const QByteArray &)),
52 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 52 this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
53 53
54 cardInPcmcia0 = FALSE; 54 cardInPcmcia0 = FALSE;
55 cardInPcmcia1 = FALSE; 55 cardInPcmcia1 = FALSE;
56 56
57 setFixedSize( pm.size() ); 57 setFixedSize( pm.size() );
58 getStatusPcmcia(TRUE); 58 getStatusPcmcia(TRUE);
59 getStatusSd(TRUE); 59 getStatusSd(TRUE);
60 repaint(FALSE); 60 repaint(FALSE);
61 popupMenu = 0; 61 popupMenu = 0;
62} 62}
63 63
64CardMonitor::~CardMonitor() { 64CardMonitor::~CardMonitor() {
65 if( popupMenu ) { delete popupMenu; } 65 if( popupMenu ) { delete popupMenu; }
66} 66}
67 67
68void CardMonitor::popUp( QString message, QString icon = QString::null ) { 68void CardMonitor::popUp( QString message, QString icon ) {
69 if ( ! popupMenu ) { 69 if ( ! popupMenu ) {
70 popupMenu = new QPopupMenu(); 70 popupMenu = new QPopupMenu();
71 } 71 }
72 popupMenu->clear(); 72 popupMenu->clear();
73 if( icon.isEmpty() ) { 73 if( icon.isEmpty() ) {
74 popupMenu->insertItem( message, 0 ); 74 popupMenu->insertItem( message, 0 );
75 } else { 75 } else {
76 popupMenu->insertItem( QIconSet ( Resource::loadPixmap ( icon )), 76 popupMenu->insertItem( QIconSet ( Resource::loadPixmap ( icon )),
77 message, 0 ); 77 message, 0 );
78 } 78 }
79 79
80 QPoint p = mapToGlobal ( QPoint ( 0, 0 )); 80 QPoint p = mapToGlobal ( QPoint ( 0, 0 ));
81 QSize s = popupMenu->sizeHint ( ); 81 QSize s = popupMenu->sizeHint ( );
82 popupMenu->popup( QPoint ( 82 popupMenu->popup( QPoint (
83 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), 83 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ),
84 p. y ( ) - s. height ( ) ), 0); 84 p. y ( ) - s. height ( ) ), 0);
85 85
86 QTimer::singleShot( 2000, this, SLOT(popupTimeout()) ); 86 QTimer::singleShot( 2000, this, SLOT(popupTimeout()) );
87} 87}
88 88
89void CardMonitor::popupTimeout() { 89void CardMonitor::popupTimeout() {
90 popupMenu->hide(); 90 popupMenu->hide();
91} 91}
92 92
93void CardMonitor::mousePressEvent( QMouseEvent * ) { 93void CardMonitor::mousePressEvent( QMouseEvent * ) {
94 QPopupMenu *menu = new QPopupMenu(); 94 QPopupMenu *menu = new QPopupMenu();
95 QString cmd; 95 QString cmd;
96 int err=0; 96 int err=0;
97 97
98 if ( cardInSd ) { 98 if ( cardInSd ) {
99 menu->insertItem( tr("Eject SD/MMC card"), 0 ); 99 menu->insertItem( tr("Eject SD/MMC card"), 0 );
100 } 100 }
101 101
102 if ( cardInPcmcia0 ) { 102 if ( cardInPcmcia0 ) {
103 menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia0Type )), 103 menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia0Type )),
104 tr("Eject card 0: %1").arg(cardInPcmcia0Name), 1 ); 104 tr("Eject card 0: %1").arg(cardInPcmcia0Name), 1 );
105 } 105 }
106 106
107 if ( cardInPcmcia1 ) { 107 if ( cardInPcmcia1 ) {
108 menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia1Type )), 108 menu->insertItem( QIconSet ( Resource::loadPixmap ( "cardmon/" + cardInPcmcia1Type )),
109 tr("Eject card 1: %1").arg(cardInPcmcia1Name), 2 ); 109 tr("Eject card 1: %1").arg(cardInPcmcia1Name), 2 );
110 } 110 }
111 111
112 QPoint p = mapToGlobal ( QPoint ( 0, 0 )); 112 QPoint p = mapToGlobal ( QPoint ( 0, 0 ));
113 QSize s = menu->sizeHint ( ); 113 QSize s = menu->sizeHint ( );
114 int opt = menu->exec( QPoint ( 114 int opt = menu->exec( QPoint (
115 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), 115 p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ),
116 p. y ( ) - s. height ( ) ), 0); 116 p. y ( ) - s. height ( ) ), 0);
117 117
118 if ( opt == 1 ) { 118 if ( opt == 1 ) {
119 119
120 cmd = "/sbin/cardctl eject 0"; 120 cmd = "/sbin/cardctl eject 0";
121 err = system( (const char *) cmd ); 121 err = system( (const char *) cmd );
122 if ( ( err == 127 ) || ( err < 0 ) ) { 122 if ( ( err == 127 ) || ( err < 0 ) ) {
123 qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", err); 123 qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", err);
124 popUp( tr("CF/PCMCIA card eject failed!")); 124 popUp( tr("CF/PCMCIA card eject failed!"));
125 } 125 }
126 } else if ( opt == 0 ) { 126 } else if ( opt == 0 ) {
127 cmd = "/etc/sdcontrol compeject"; 127 cmd = "/etc/sdcontrol compeject";
128 err = system( (const char *) cmd ); 128 err = system( (const char *) cmd );
129 if ( ( err != 0 ) ) { 129 if ( ( err != 0 ) ) {
130 qDebug("Could not execute `/etc/sdcontrol comeject'! err=%d", err); 130 qDebug("Could not execute `/etc/sdcontrol comeject'! err=%d", err);
131 popUp( tr("SD/MMC card eject failed!")); 131 popUp( tr("SD/MMC card eject failed!"));
132 } 132 }
133 } else if ( opt == 2 ) { 133 } else if ( opt == 2 ) {
134 cmd = "/sbin/cardctl eject 1"; 134 cmd = "/sbin/cardctl eject 1";
135 err = system( (const char *) cmd ); 135 err = system( (const char *) cmd );
136 if ( ( err == 127 ) || ( err < 0 ) ) { 136 if ( ( err == 127 ) || ( err < 0 ) ) {
137 qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", err); 137 qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", err);
138 popUp( tr("CF/PCMCIA card eject failed!")); 138 popUp( tr("CF/PCMCIA card eject failed!"));
139 } 139 }
140 } 140 }
141 141
142 delete menu; 142 delete menu;
143} 143}
144 144
145 145
146void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) { 146void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) {
147 if ( msg == "stabChanged()" ) { 147 if ( msg == "stabChanged()" ) {
148 // qDebug("Pcmcia: stabchanged"); 148 // qDebug("Pcmcia: stabchanged");
149 if ( getStatusPcmcia() ) { 149 if ( getStatusPcmcia() ) {
150 repaint(FALSE); 150 repaint(FALSE);
151 } 151 }
152 } else if ( msg == "mtabChanged()" ) { 152 } else if ( msg == "mtabChanged()" ) {
153 // qDebug("Pcmcia: mtabchanged"); 153 // qDebug("Pcmcia: mtabchanged");
154 if ( getStatusSd() ) { 154 if ( getStatusSd() ) {
155 repaint(FALSE); 155 repaint(FALSE);
156 } 156 }
157 } 157 }
158} 158}
159 159
160bool CardMonitor::getStatusPcmcia( int showPopUp ) { 160bool CardMonitor::getStatusPcmcia( int showPopUp ) {
161 161
162 bool cardWas0 = cardInPcmcia0; // remember last state 162 bool cardWas0 = cardInPcmcia0; // remember last state
163 bool cardWas1 = cardInPcmcia1; 163 bool cardWas1 = cardInPcmcia1;
164 164
165 QString fileName; 165 QString fileName;
166 166
167 // one of these 3 files should exist 167 // one of these 3 files should exist
168 if (QFile::exists("/var/run/stab")) { 168 if (QFile::exists("/var/run/stab")) {
169 fileName = "/var/run/stab"; 169 fileName = "/var/run/stab";
170 } else if (QFile::exists("/var/state/pcmcia/stab")) { 170 } else if (QFile::exists("/var/state/pcmcia/stab")) {
171 fileName="/var/state/pcmcia/stab"; 171 fileName="/var/state/pcmcia/stab";
172 } else { 172 } else {
173 fileName="/var/lib/pcmcia/stab"; 173 fileName="/var/lib/pcmcia/stab";
174 } 174 }
175 175
176 QFile f(fileName); 176 QFile f(fileName);
177 177
178 if ( f.open(IO_ReadOnly) ) { 178 if ( f.open(IO_ReadOnly) ) {
179 QStringList list; 179 QStringList list;
180 QTextStream stream ( &f); 180 QTextStream stream ( &f);
181 QString streamIn; 181 QString streamIn;
182 streamIn = stream.read(); 182 streamIn = stream.read();
183 list = QStringList::split("\n", streamIn); 183 list = QStringList::split("\n", streamIn);
184 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { 184 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) {
185 if( (*line).startsWith("Socket 0:") ){ 185 if( (*line).startsWith("Socket 0:") ){
186 if( (*line).startsWith("Socket 0: empty") && cardInPcmcia0 ){ 186 if( (*line).startsWith("Socket 0: empty") && cardInPcmcia0 ){
187 cardInPcmcia0 = FALSE; 187 cardInPcmcia0 = FALSE;
188 } else if ( !(*line).startsWith("Socket 0: empty") && !cardInPcmcia0 ){ 188 } else if ( !(*line).startsWith("Socket 0: empty") && !cardInPcmcia0 ){
189 cardInPcmcia0Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 ); 189 cardInPcmcia0Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 );
190 cardInPcmcia0Name.stripWhiteSpace(); 190 cardInPcmcia0Name.stripWhiteSpace();
191 cardInPcmcia0 = TRUE; 191 cardInPcmcia0 = TRUE;
192 show(); 192 show();
193 line++; 193 line++;
194 int pos=(*line).find('\t')+1; 194 int pos=(*line).find('\t')+1;
195 cardInPcmcia0Type = (*line).mid( pos, (*line).find("\t", pos) - pos); 195 cardInPcmcia0Type = (*line).mid( pos, (*line).find("\t", pos) - pos);
196 } 196 }