summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-05-19 12:01:49 (UTC)
committer mickeyl <mickeyl>2005-05-19 12:01:49 (UTC)
commit50cc0698e54f1f69591cc89be34ffcb7e309380a (patch) (unidiff)
treea6573038a424b1566e68e6ed83f7709e0a6356a1
parentcdecf5d75233150cba06094262158fb218e9bf03 (diff)
downloadopie-50cc0698e54f1f69591cc89be34ffcb7e309380a.zip
opie-50cc0698e54f1f69591cc89be34ffcb7e309380a.tar.gz
opie-50cc0698e54f1f69591cc89be34ffcb7e309380a.tar.bz2
add skeleton for new pcmcia/cf configuration and monitoring applet
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--Rules.make1
-rw-r--r--core/applets/cardmon/.cvsignore6
-rw-r--r--core/applets/cardmon/config.in4
-rw-r--r--core/applets/cardmon/pcmcia.cpp371
-rw-r--r--core/applets/cardmon/pcmcia.h80
-rw-r--r--core/applets/cardmon/pcmcia.pro12
-rw-r--r--packages1
7 files changed, 472 insertions, 3 deletions
diff --git a/Rules.make b/Rules.make
index f75e6da..3ce2853 100644
--- a/Rules.make
+++ b/Rules.make
@@ -180,6 +180,7 @@ $(OPIEDIR)/stamp-headers :
180 # libopie2 180 # libopie2
181 ( cd include/opie2 && ln -sf ../../libopie2/opiecore/*.h .; ) 181 ( cd include/opie2 && ln -sf ../../libopie2/opiecore/*.h .; )
182 ( cd include/opie2 && ln -sf ../../libopie2/opiecore/device/*.h .; ) 182 ( cd include/opie2 && ln -sf ../../libopie2/opiecore/device/*.h .; )
183 ( cd include/opie2 && ln -sf ../../libopie2/opiecore/linux/*.h .; )
183 ( cd include/opie2 && ln -sf ../../libopie2/opiemm/*.h .; ) 184 ( cd include/opie2 && ln -sf ../../libopie2/opiemm/*.h .; )
184 ( cd include/opie2 && ln -sf ../../libopie2/opiedb/*.h .; ) 185 ( cd include/opie2 && ln -sf ../../libopie2/opiedb/*.h .; )
185 ( cd include/opie2 && ln -sf ../../libopie2/opienet/*.h .; ) 186 ( cd include/opie2 && ln -sf ../../libopie2/opienet/*.h .; )
diff --git a/core/applets/cardmon/.cvsignore b/core/applets/cardmon/.cvsignore
index 37c45ac..d704947 100644
--- a/core/applets/cardmon/.cvsignore
+++ b/core/applets/cardmon/.cvsignore
@@ -1,5 +1,9 @@
1*.moc 1*moc
2*.~
2Makefile* 3Makefile*
3moc_* 4moc_*
5opieobj
6obj
7moc_
4.moc 8.moc
5.obj 9.obj
diff --git a/core/applets/cardmon/config.in b/core/applets/cardmon/config.in
index 50a52b4..5f5af73 100644
--- a/core/applets/cardmon/config.in
+++ b/core/applets/cardmon/config.in
@@ -1,4 +1,4 @@
1 config CARDMON 1 config PCMCIA-APPLET
2 boolean "opie-cardmon (monitor cf/sd/mmc card status, and eject function)" 2 boolean "opie-pcmciaapplet (monitor and configure pcmcia/cf cards)"
3 default "y" 3 default "y"
4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE 4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE
diff --git a/core/applets/cardmon/pcmcia.cpp b/core/applets/cardmon/pcmcia.cpp
new file mode 100644
index 0000000..2486f17
--- a/dev/null
+++ b/core/applets/cardmon/pcmcia.cpp
@@ -0,0 +1,371 @@
1/*
2                 This file is part of the Opie Project
3 =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l.
5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details.
20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA.
27
28*/
29
30#include "pcmcia.h"
31
32/* OPIE */
33#include <opie2/odebug.h>
34#include <opie2/odevice.h>
35#include <opie2/oprocess.h>
36#include <opie2/oresource.h>
37#include <opie2/otaskbarapplet.h>
38#include <qpe/applnk.h>
39#include <qpe/resource.h>
40using namespace Opie::Core;
41using namespace Opie::Ui;
42
43/* QT */
44#include <qcopchannel_qws.h>
45#include <qpainter.h>
46#include <qfile.h>
47#include <qtextstream.h>
48#include <qsound.h>
49#include <qtimer.h>
50
51/* STD */
52#include <stdio.h>
53#include <unistd.h>
54#include <stdlib.h>
55#include <string.h>
56#include <fcntl.h>
57#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
58#include <sys/vfs.h>
59#include <mntent.h>
60#endif
61
62PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent )
63{
64 pm = Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon );
65#if 0
66 QCopChannel *channel = new QCopChannel("QPE/System", this);
67 connect(channel, SIGNAL(received(const QCString&,const QByteArray&)),
68 this, SLOT(systemMsg(const QCString&,const QByteArray&)) );
69#endif
70 QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this );
71 connect( pcmciaChannel,
72 SIGNAL( received(const QCString&,const QByteArray&) ), this,
73 SLOT( cardMessage(const QCString&,const QByteArray&) ) );
74
75 QCopChannel *sdChannel = new QCopChannel( "QPE/Card", this );
76 connect( sdChannel,
77 SIGNAL( received(const QCString&,const QByteArray&) ), this,
78 SLOT( cardMessage(const QCString&,const QByteArray&) ) );
79
80 cardInPcmcia0 = FALSE;
81 cardInPcmcia1 = FALSE;
82 cardInSd = FALSE;
83
84 setFocusPolicy( NoFocus );
85
86 setFixedWidth ( AppLnk::smallIconSize() );
87 setFixedHeight ( AppLnk::smallIconSize() );
88
89 getStatusPcmcia( TRUE );
90 getStatusSd( TRUE );
91 repaint( FALSE );
92 popupMenu = 0;
93}
94
95
96PcmciaManager::~PcmciaManager()
97{
98 delete popupMenu;
99}
100
101
102void PcmciaManager::popUp( QString message, QString icon )
103{
104 if ( !popupMenu ) {
105 popupMenu = new QPopupMenu( this );
106 }
107
108 popupMenu->clear();
109 if ( icon.isEmpty() ) {
110 popupMenu->insertItem( message, 0 );
111 } else {
112 popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ),
113 message, 0 );
114 }
115
116 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
117 QSize s = popupMenu->sizeHint();
118 popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ),
119 p.y() - s.height() ), 0 );
120
121 QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) );
122}
123
124
125void PcmciaManager::popupTimeout()
126{
127 popupMenu->hide();
128}
129
130
131void PcmciaManager::mousePressEvent( QMouseEvent * )
132{
133 QPopupMenu * menu = new QPopupMenu( this );
134 QStringList cmd;
135 bool execute = true;
136
137 if ( cardInSd ) {
138 menu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( "cardmon/ide", Opie::Core::OResource::SmallIcon ) ),
139 tr( "Eject SD/MMC card" ), 0 );
140 }
141
142 if ( cardInPcmcia0 ) {
143 menu->
144 insertItem( QIconSet
145 ( Opie::Core::OResource::loadPixmap( "cardmon/" + cardInPcmcia0Type, Opie::Core::OResource::SmallIcon ) ),
146 tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 );
147 }
148
149 if ( cardInPcmcia1 ) {
150 menu->
151 insertItem( QIconSet
152 ( Opie::Core::OResource::loadPixmap( "cardmon/" + cardInPcmcia1Type, Opie::Core::OResource::SmallIcon ) ),
153 tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 );
154 }
155
156 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
157 QSize s = menu->sizeHint();
158 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ),
159 p.y() - s.height() ), 0 );
160
161 if ( opt == 1 ) {
162 m_commandOrig = PCMCIA_Socket1;
163 cmd << "/sbin/cardctl" << "eject" << "0";
164 } else if ( opt == 0 ) {
165 m_commandOrig = MMC_Socket;
166 cmd << "umount" << cardSdName;
167 } else if ( opt == 2 ) {
168 m_commandOrig = PCMCIA_Socket2;
169 cmd << "/sbin/cardctl" << "eject" << "1";
170 }else
171 execute = false;
172
173 if ( execute )
174 execCommand( cmd );
175
176 delete menu;
177}
178
179
180void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
181{
182 if ( msg == "stabChanged()" ) {
183 // odebug << "Pcmcia: stabchanged" << oendl;
184 getStatusPcmcia();
185 } else if ( msg == "mtabChanged()" ) {
186 // odebug << "CARDMONAPPLET: mtabchanged" << oendl;
187 getStatusSd();
188 }
189}
190
191
192bool PcmciaManager::getStatusPcmcia( int showPopUp ) {
193
194 bool cardWas0 = cardInPcmcia0; // remember last state
195 bool cardWas1 = cardInPcmcia1;
196
197 QString fileName;
198
199 if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; }
200 else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; }
201 else { fileName = "/var/lib/pcmcia/stab"; }
202
203 QFile f( fileName );
204
205 if ( f.open( IO_ReadOnly ) ) {
206 QStringList list;
207 QTextStream stream( &f );
208 QString streamIn;
209 streamIn = stream.read();
210 list = QStringList::split( "\n", streamIn );
211 for ( QStringList::Iterator line = list.begin(); line != list.end();
212 line++ ) {
213 if ( ( *line ).startsWith( "Socket 0:" ) ) {
214 if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ) {
215 cardInPcmcia0 = FALSE;
216 } else if ( !( *line ).startsWith( "Socket 0: empty" )
217 && !cardInPcmcia0 ) {
218 cardInPcmcia0Name =
219 ( *line ).mid( ( ( *line ).find( ':' ) + 1 ),
220 ( *line ).length() - 9 );
221 cardInPcmcia0Name.stripWhiteSpace();
222 cardInPcmcia0 = TRUE;
223 show();
224 line++;
225 int pos = ( *line ).find( '\t' ) + 1;
226 cardInPcmcia0Type =
227 ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos );
228 }
229 } else if ( ( *line ).startsWith( "Socket 1:" ) ) {
230 if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) {
231 cardInPcmcia1 = FALSE;
232 } else if ( !( *line ).startsWith( "Socket 1: empty" )
233 && !cardInPcmcia1 ) {
234 cardInPcmcia1Name =
235 ( *line ).mid( ( ( *line ).find( ':' ) + 1 ),
236 ( *line ).length() - 9 );
237 cardInPcmcia1Name.stripWhiteSpace();
238 cardInPcmcia1 = TRUE;
239 show();
240 line++;
241 int pos = ( *line ).find( '\t' ) + 1;
242 cardInPcmcia1Type =
243 ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos );
244 }
245 }
246 }
247 f.close();
248
249 if ( !showPopUp
250 && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) ) {
251 QString text = QString::null;
252 QString what = QString::null;
253 if ( cardWas0 != cardInPcmcia0 ) {
254 if ( cardInPcmcia0 ) {
255 text += tr( "New card: " );
256 what = "on";
257 } else {
258 text += tr( "Ejected: " );
259 what = "off";
260 }
261 text += cardInPcmcia0Name;
262 popUp( text, "cardmon/" + cardInPcmcia0Type );
263 }
264
265 if ( cardWas1 != cardInPcmcia1 ) {
266 if ( cardInPcmcia1 ) {
267 text += tr( "New card: " );
268 what = "on";
269 } else {
270 text += tr( "Ejected: " );
271 what = "off";
272 }
273 text += cardInPcmcia1Name;
274 popUp( text, "cardmon/" + cardInPcmcia1Type );
275 }
276 #ifndef QT_NO_SOUND
277 QSound::play( Resource::findSound( "cardmon/card" + what ) );
278 #endif
279
280 }
281 } else {
282 // no file found
283 odebug << "no file found" << oendl;
284 cardInPcmcia0 = FALSE;
285 cardInPcmcia1 = FALSE;
286 }
287
288 repaint( FALSE );
289 return ( ( cardWas0 == cardInPcmcia0
290 && cardWas1 == cardInPcmcia1 ) ? FALSE : TRUE );
291
292}
293
294
295bool PcmciaManager::getStatusSd( int showPopUp )
296{
297
298 bool cardWas = cardInSd; // remember last state
299 cardInSd = FALSE;
300
301 #if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
302
303 struct mntent *me;
304 FILE *mntfp = setmntent( "/etc/mtab", "r" );
305
306 if ( mntfp ) {
307 while ( ( me = getmntent( mntfp ) ) != 0 ) {
308 QString fs = QFile::decodeName( me->mnt_fsname );
309 //odebug << fs << oendl;
310 if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd"
311 || fs.left( 9 ) == "/dev/mmcd" || fs.left(11) == "/dev/mmcblk" ) {
312 cardInSd = TRUE;
313 cardSdName = fs;
314 show();
315 }
316 // else {
317 // cardInSd = FALSE;
318 // }
319 }
320 endmntent( mntfp );
321 }
322
323 if ( !showPopUp && cardWas != cardInSd ) {
324 QString text = QString::null;
325 QString what = QString::null;
326 if ( cardInSd ) {
327 text += tr("New card: SD/MMC");
328 what = "on";
329 } else {
330 text += tr("Ejected: SD/MMC");
331 what = "off";
332 }
333 //odebug << "TEXT: " + text << oendl;
334 #ifndef QT_NO_SOUND
335 QSound::play( Resource::findSound( "cardmon/card" + what ) );
336 #endif
337
338 popUp( text, "cardmon/ide" ); // XX add SD pic
339 }
340 #else
341 #error "Not on Linux"
342 #endif
343 repaint( FALSE );
344 return ( ( cardWas == cardInSd ) ? FALSE : TRUE );
345}
346
347void PcmciaManager::paintEvent( QPaintEvent * )
348{
349
350 QPainter p( this );
351
352 if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) {
353 p.drawPixmap( 0, 0, pm );
354 show();
355 } else {
356 //p.eraseRect(rect());
357 hide();
358 }
359}
360
361int PcmciaManager::position()
362{
363 return 7;
364}
365
366void PcmciaManager::execCommand( const QStringList &strList )
367{
368}
369
370EXPORT_OPIE_APPLET_v1( PcmciaManager )
371
diff --git a/core/applets/cardmon/pcmcia.h b/core/applets/cardmon/pcmcia.h
new file mode 100644
index 0000000..58a2d42
--- a/dev/null
+++ b/core/applets/cardmon/pcmcia.h
@@ -0,0 +1,80 @@
1/*
2                 This file is part of the Opie Project
3 =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l.
5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details.
20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA.
27
28*/
29
30#ifndef PCMCIA_H
31#define PCMCIA_H
32
33#include <qwidget.h>
34#include <qpixmap.h>
35#include <qpopupmenu.h>
36
37class PcmciaManager : public QWidget
38{
39 Q_OBJECT
40public:
41 enum {
42 PCMCIA_Socket1,
43 PCMCIA_Socket2,
44 MMC_Socket
45 };
46
47 PcmciaManager( QWidget *parent = 0 );
48 ~PcmciaManager();
49 bool getStatusPcmcia( int showPopUp = FALSE );
50 bool getStatusSd( int showPopUp = FALSE );
51 static int position();
52private slots:
53 void cardMessage( const QCString &msg, const QByteArray & );
54 void popupTimeout();
55
56protected:
57 void paintEvent( QPaintEvent* );
58 void mousePressEvent( QMouseEvent * );
59
60private:
61 void execCommand( const QStringList &command );
62 int m_commandOrig;
63 QPixmap pm;
64 // pcmcia socket 0
65 bool cardInPcmcia0;
66 QString cardInPcmcia0Name;
67 QString cardInPcmcia0Type;
68 // pcmcia socket 1
69 bool cardInPcmcia1;
70 QString cardInPcmcia1Name;
71 QString cardInPcmcia1Type;
72 bool cardInSd;
73 QString cardSdName; // the device which is mounted
74 void iconShow();
75 QPopupMenu *popupMenu;
76 void popUp(QString message, QString icon = QString::null );
77};
78
79#endif
80
diff --git a/core/applets/cardmon/pcmcia.pro b/core/applets/cardmon/pcmcia.pro
new file mode 100644
index 0000000..c4f7b62
--- a/dev/null
+++ b/core/applets/cardmon/pcmcia.pro
@@ -0,0 +1,12 @@
1TEMPLATE = lib
2CONFIG += qt plugin warn_on
3HEADERS = pcmcia.h
4SOURCES = pcmcia.cpp
5TARGET = pcmciaapplet
6DESTDIR = $(OPIEDIR)/plugins/applets
7INCLUDEPATH += $(OPIEDIR)/include
8DEPENDPATH += $(OPIEDIR)/include
9LIBS += -lqpe -lopiecore2
10VERSION = 0.1.0
11
12include( $(OPIEDIR)/include.pro )
diff --git a/packages b/packages
index be8c0f9..ac5f890 100644
--- a/packages
+++ b/packages
@@ -177,6 +177,7 @@ CONFIG_OSEARCH core/pim/osearch osearch.pro
177 CONFIG_OXYGEN noncore/apps/oxygenoxygen.pro 177 CONFIG_OXYGEN noncore/apps/oxygenoxygen.pro
178 CONFIG_PACKAGEMANAGER noncore/settings/packagemanagerpackagemanager.pro 178 CONFIG_PACKAGEMANAGER noncore/settings/packagemanagerpackagemanager.pro
179 CONFIG_PARASHOOT noncore/games/parashootparashoot.pro 179 CONFIG_PARASHOOT noncore/games/parashootparashoot.pro
180 CONFIG_PCMCIA-APPLET noncore/applets/pcmciapcmcia.pro
180 CONFIG_PHASE noncore/styles/phasephase.pro 181 CONFIG_PHASE noncore/styles/phasephase.pro
181 CONFIG_PICKBOARD inputmethods/pickboardpickboard.pro 182 CONFIG_PICKBOARD inputmethods/pickboardpickboard.pro
182CONFIG_PIMCONVERTER noncore/tools/pimconverter converter.pro 183CONFIG_PIMCONVERTER noncore/tools/pimconverter converter.pro