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