-rw-r--r-- | core/applets/cardmon/cardmon.cpp | 4 |
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 | |||
@@ -13,64 +13,66 @@ | |||
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 | ||
45 | using namespace Opie; | ||
46 | |||
45 | CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ), | 47 | CardMonitor::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 | ||
67 | CardMonitor::~CardMonitor() { | 69 | CardMonitor::~CardMonitor() { |
68 | if( popupMenu ) { | 70 | if( popupMenu ) { |
69 | delete popupMenu; | 71 | delete popupMenu; |
70 | } | 72 | } |
71 | } | 73 | } |
72 | 74 | ||
73 | void CardMonitor::popUp( QString message, QString icon ) { | 75 | void CardMonitor::popUp( QString message, QString icon ) { |
74 | if ( ! popupMenu ) { | 76 | if ( ! popupMenu ) { |
75 | popupMenu = new QPopupMenu(); | 77 | popupMenu = new QPopupMenu(); |
76 | } | 78 | } |
@@ -99,65 +101,65 @@ void 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 | ||
157 | void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) { | 159 | void 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()" ) { |