-rw-r--r-- | core/applets/cardmon/cardmon.cpp | 230 | ||||
-rw-r--r-- | core/applets/cardmon/cardmon.h | 52 | ||||
-rw-r--r-- | core/applets/cardmon/cardmon.pro | 23 | ||||
-rw-r--r-- | core/applets/cardmon/cardmonimpl.cpp | 40 | ||||
-rw-r--r-- | core/applets/cardmon/cardmonimpl.h | 19 | ||||
-rw-r--r-- | core/applets/cardmon/opie-cardmon.control | 9 | ||||
-rwxr-xr-x | core/applets/cardmon/qpe-cardmon.postinst | 2 | ||||
-rwxr-xr-x | core/applets/cardmon/qpe-cardmon.postrm | 2 |
8 files changed, 377 insertions, 0 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp new file mode 100644 index 0000000..9522b88 --- a/dev/null +++ b/core/applets/cardmon/cardmon.cpp | |||
@@ -0,0 +1,230 @@ | |||
1 | /* | ||
2 | * cardmon.cpp | ||
3 | * | ||
4 | * --------------------- | ||
5 | * | ||
6 | * copyright : (c) 2002 by Maximilian Reiss | ||
7 | * email : max.reiss@gmx.de | ||
8 | * based on two apps by Devin Butterfield | ||
9 | */ | ||
10 | /*************************************************************************** | ||
11 | * * | ||
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 * | ||
14 | * the Free Software Foundation; either version 2 of the License, or * | ||
15 | * (at your option) any later version. * | ||
16 | * * | ||
17 | ***************************************************************************/ | ||
18 | |||
19 | |||
20 | #include "cardmon.h" | ||
21 | |||
22 | #include <qpe/resource.h> | ||
23 | |||
24 | #include <qcopchannel_qws.h> | ||
25 | #include <qpainter.h> | ||
26 | #include <qmessagebox.h> | ||
27 | #include <qpopupmenu.h> | ||
28 | #include <qfile.h> | ||
29 | #include <qtextstream.h> | ||
30 | |||
31 | #include <stdio.h> | ||
32 | #include <unistd.h> | ||
33 | #include <stdlib.h> | ||
34 | #include <string.h> | ||
35 | #include <fcntl.h> | ||
36 | |||
37 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | ||
38 | #include <sys/vfs.h> | ||
39 | #include <mntent.h> | ||
40 | #endif | ||
41 | |||
42 | CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ), | ||
43 | pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) { | ||
44 | |||
45 | QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this ); | ||
46 | connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), | ||
47 | this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); | ||
48 | |||
49 | QCopChannel* sdChannel = new QCopChannel( "QPE/Card", this ); | ||
50 | connect( sdChannel, SIGNAL(received(const QCString &, const QByteArray &)), | ||
51 | this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); | ||
52 | |||
53 | |||
54 | setFixedSize( pm.size() ); | ||
55 | hide(); | ||
56 | getStatusPcmcia(); | ||
57 | } | ||
58 | |||
59 | CardMonitor::~CardMonitor() { | ||
60 | } | ||
61 | |||
62 | void CardMonitor::mousePressEvent( QMouseEvent * ) { | ||
63 | QPopupMenu *menu = new QPopupMenu(); | ||
64 | QString cmd; | ||
65 | int err=0; | ||
66 | |||
67 | if ( cardInSd ) { | ||
68 | menu->insertItem( tr("Eject SD/ MMC card"), 0 ); | ||
69 | } | ||
70 | |||
71 | if ( cardInPcmcia0 ) { | ||
72 | menu->insertItem( tr("Eject card (0) %1").arg(cardInPcmcia0Name), 1 ); | ||
73 | } | ||
74 | |||
75 | if ( cardInPcmcia1 ) { | ||
76 | menu->insertItem( tr("Eject card (1) %1").arg(cardInPcmcia1Name), 2 ); | ||
77 | } | ||
78 | |||
79 | QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); | ||
80 | |||
81 | if ( menu->exec( p, 1 ) == 1 ) { | ||
82 | |||
83 | cmd = "/sbin/cardctl eject 0"; | ||
84 | err = system( (const char *) cmd ); | ||
85 | if ( ( err == 127 ) || ( err < 0 ) ) { | ||
86 | qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", err); | ||
87 | QMessageBox::warning( this, tr("CardMonitor"), tr("CF/PCMCIA card eject failed!"), | ||
88 | tr("&OK") ); | ||
89 | } | ||
90 | } else if ( menu->exec( p, 1 ) == 0 ) { | ||
91 | cmd = "/etc/sdcontrol compeject"; | ||
92 | err = system( (const char *) cmd ); | ||
93 | if ( ( err != 0 ) ) { | ||
94 | qDebug("Could not execute `/etc/sdcontrol comeject'! err=%d", err); | ||
95 | QMessageBox::warning( this, tr("CardMonitor"), tr("SD/MMC card eject failed!"), | ||
96 | tr("&OK") ); | ||
97 | } | ||
98 | } else if ( menu->exec( p, 1 ) == 2 ) { | ||
99 | cmd = "/sbin/cardctl eject 1"; | ||
100 | err = system( (const char *) cmd ); | ||
101 | if ( ( err == 127 ) || ( err < 0 ) ) { | ||
102 | qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", err); | ||
103 | QMessageBox::warning( this, tr("CardMonitor"), tr("CF/PCMCIA card eject failed!"), | ||
104 | tr("&OK") ); | ||
105 | } | ||
106 | } | ||
107 | |||
108 | delete menu; | ||
109 | } | ||
110 | |||
111 | |||
112 | void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) { | ||
113 | if ( msg == "stabChanged()" ) { | ||
114 | if ( getStatusPcmcia() ) { | ||
115 | repaint(FALSE); | ||
116 | } | ||
117 | } else if ( msg == "mtabChanged()" ) { | ||
118 | if ( getStatusSd() ) { | ||
119 | repaint(FALSE); | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | |||
124 | bool CardMonitor::getStatusPcmcia( void ) { | ||
125 | |||
126 | bool cardWas0 = cardInPcmcia0; // remember last state | ||
127 | bool cardWas1 = cardInPcmcia1; | ||
128 | |||
129 | QString fileName; | ||
130 | |||
131 | // one of these 3 files should exist | ||
132 | if (QFile::exists("/var/run/stab")) { | ||
133 | fileName = "/var/run/stab"; | ||
134 | } else if (QFile::exists("/var/state/pcmcia/stab")) { | ||
135 | fileName="/var/state/pcmcia/stab"; | ||
136 | } else { | ||
137 | fileName="/var/lib/pcmcia/stab"; | ||
138 | } | ||
139 | |||
140 | QFile f(fileName); | ||
141 | |||
142 | if ( f.open(IO_ReadOnly) ) { | ||
143 | QStringList list; | ||
144 | QTextStream stream ( &f); | ||
145 | QString streamIn; | ||
146 | streamIn = stream.read(); | ||
147 | list = QStringList::split("\n", streamIn); | ||
148 | for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { | ||
149 | if( (*line).startsWith("Socket 0:") ){ | ||
150 | // extendable, maybe read out card name | ||
151 | if( (*line).startsWith("Socket 0: empty") && cardInPcmcia0 ){ | ||
152 | cardInPcmcia0 = FALSE; | ||
153 | hide(); | ||
154 | } else if ( !(*line).startsWith("Socket 0: empty") && !cardInPcmcia0 ){ | ||
155 | cardInPcmcia0Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 ); | ||
156 | cardInPcmcia0 = TRUE; | ||
157 | show(); | ||
158 | } | ||
159 | } | ||
160 | if( (*line).startsWith("Socket 1:") ){ | ||
161 | if( (*line).startsWith("Socket 1: empty") && cardInPcmcia1 ){ | ||
162 | cardInPcmcia1 = FALSE; | ||
163 | hide(); | ||
164 | } else if ( !(*line).startsWith("Socket 1: empty") && !cardInPcmcia1 ){ | ||
165 | cardInPcmcia1Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 ); | ||
166 | cardInPcmcia1 = TRUE; | ||
167 | show(); | ||
168 | } | ||
169 | } | ||
170 | } | ||
171 | } else { | ||
172 | // no file found | ||
173 | qDebug("no file found"); | ||
174 | cardInPcmcia0 = FALSE; | ||
175 | cardInPcmcia1 = FALSE; | ||
176 | hide(); | ||
177 | return FALSE; | ||
178 | |||
179 | } | ||
180 | |||
181 | f.close(); | ||
182 | |||
183 | return ((cardWas0 == cardInPcmcia0 || cardWas1 == cardInPcmcia1) ? FALSE : TRUE); | ||
184 | } | ||
185 | |||
186 | |||
187 | bool CardMonitor::getStatusSd( void ) { | ||
188 | |||
189 | bool cardWas=cardInSd; // remember last state | ||
190 | cardInSd=false; | ||
191 | |||
192 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | ||
193 | struct mntent *me; | ||
194 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); | ||
195 | |||
196 | if ( mntfp ) { | ||
197 | while ( (me = getmntent( mntfp )) != 0 ) { | ||
198 | QString fs = me->mnt_fsname; | ||
199 | if ( fs.left(7)=="/dev/sd" || fs.left(9) == "/dev/mmcd" ) { | ||
200 | cardInSd=true; | ||
201 | } | ||
202 | } | ||
203 | endmntent( mntfp ); | ||
204 | if (cardInSd!=cardWas) { | ||
205 | if (cardInSd) { | ||
206 | show(); | ||
207 | } else { | ||
208 | hide(); | ||
209 | } | ||
210 | } | ||
211 | } else { | ||
212 | hide(); | ||
213 | } | ||
214 | #else | ||
215 | #error "Not on Linux" | ||
216 | #endif | ||
217 | return ((cardWas == cardInSd) ? FALSE : TRUE); | ||
218 | } | ||
219 | |||
220 | void CardMonitor::paintEvent( QPaintEvent * ) { | ||
221 | QPainter p( this ); | ||
222 | |||
223 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { | ||
224 | p.drawPixmap( 0, 0, pm ); | ||
225 | } else { | ||
226 | p.eraseRect( rect() ); | ||
227 | } | ||
228 | } | ||
229 | |||
230 | |||
diff --git a/core/applets/cardmon/cardmon.h b/core/applets/cardmon/cardmon.h new file mode 100644 index 0000000..2a90c90 --- a/dev/null +++ b/core/applets/cardmon/cardmon.h | |||
@@ -0,0 +1,52 @@ | |||
1 | /* | ||
2 | * cardmon.h | ||
3 | * | ||
4 | * --------------------- | ||
5 | * | ||
6 | * copyright : (c) 2002 by Maximilian Reiss | ||
7 | * email : max.reiss@gmx.de | ||
8 | * based on two apps by Devin Butterfield | ||
9 | */ | ||
10 | /*************************************************************************** | ||
11 | * * | ||
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 * | ||
14 | * the Free Software Foundation; either version 2 of the License, or * | ||
15 | * (at your option) any later version. * | ||
16 | * * | ||
17 | ***************************************************************************/ | ||
18 | |||
19 | #ifndef CARDMON_H | ||
20 | #define CARDMON_H | ||
21 | |||
22 | #include <qwidget.h> | ||
23 | #include <qpixmap.h> | ||
24 | |||
25 | class CardMonitor : public QWidget { | ||
26 | Q_OBJECT | ||
27 | public: | ||
28 | CardMonitor( QWidget *parent = 0 ); | ||
29 | ~CardMonitor(); | ||
30 | bool getStatusPcmcia( void ); | ||
31 | bool getStatusSd( void ); | ||
32 | |||
33 | private slots: | ||
34 | void cardMessage( const QCString &msg, const QByteArray & ); | ||
35 | |||
36 | protected: | ||
37 | void paintEvent( QPaintEvent* ); | ||
38 | void mousePressEvent( QMouseEvent * ); | ||
39 | private: | ||
40 | QPixmap pm; | ||
41 | // pcmcia socket 0 | ||
42 | bool cardInPcmcia0; | ||
43 | QString cardInPcmcia0Name; | ||
44 | // pcmcia socket 1 | ||
45 | bool cardInPcmcia1; | ||
46 | QString cardInPcmcia1Name; | ||
47 | bool cardInSd; | ||
48 | |||
49 | }; | ||
50 | |||
51 | #endif | ||
52 | |||
diff --git a/core/applets/cardmon/cardmon.pro b/core/applets/cardmon/cardmon.pro new file mode 100644 index 0000000..bda051b --- a/dev/null +++ b/core/applets/cardmon/cardmon.pro | |||
@@ -0,0 +1,23 @@ | |||
1 | TEMPLATE= lib | ||
2 | CONFIG += qt warn_on release | ||
3 | HEADERS =cardmon.h cardmonimpl.h | ||
4 | SOURCES =cardmon.cpp cardmonimpl.cpp | ||
5 | TARGET = cardmonapplet | ||
6 | DESTDIR = $(OPIEDIR)/plugins/applets | ||
7 | INCLUDEPATH += $(OPIEDIR)/include | ||
8 | DEPENDPATH += $(OPIEDIR)/include ../launcher | ||
9 | LIBS += -lqpe | ||
10 | VERSION = 1.0.0 | ||
11 | |||
12 | TRANSLATIONS = ../i18n/de/libcardmonapplet.ts | ||
13 | TRANSLATIONS += ../i18n/pt_BR/libcardmonapplet.ts | ||
14 | TRANSLATIONS += ../i18n/en/libcardmonapplet.ts | ||
15 | TRANSLATIONS += ../i18n/hu/libcardmonapplet.ts | ||
16 | TRANSLATIONS += ../i18n/sl/libcardmonapplet.ts | ||
17 | TRANSLATIONS += ../i18n/pl/libcardmonapplet.ts | ||
18 | TRANSLATIONS += ../i18n/ja/libcardmonapplet.ts | ||
19 | TRANSLATIONS += ../i18n/fr/libcardmonapplet.ts | ||
20 | TRANSLATIONS += ../i18n/ko/libcardmonapplet.ts | ||
21 | TRANSLATIONS += ../i18n/no/libcardmonapplet.ts | ||
22 | TRANSLATIONS += ../i18n/zh_CN/libcardmonapplet.ts | ||
23 | TRANSLATIONS += ../i18n/zh_TW/libcardmonapplet.ts | ||
diff --git a/core/applets/cardmon/cardmonimpl.cpp b/core/applets/cardmon/cardmonimpl.cpp new file mode 100644 index 0000000..0aa55de --- a/dev/null +++ b/core/applets/cardmon/cardmonimpl.cpp | |||
@@ -0,0 +1,40 @@ | |||
1 | #include "cardmon.h" | ||
2 | #include "cardmonimpl.h" | ||
3 | |||
4 | |||
5 | CardMonitorImpl::CardMonitorImpl() | ||
6 | : cardMonitor(0), ref(0) { | ||
7 | } | ||
8 | |||
9 | CardMonitorImpl::~CardMonitorImpl() { | ||
10 | delete cardMonitor; | ||
11 | } | ||
12 | |||
13 | QWidget *CardMonitorImpl::applet( QWidget *parent ) { | ||
14 | if ( !cardMonitor ) { | ||
15 | cardMonitor = new CardMonitor( parent ); | ||
16 | } | ||
17 | return cardMonitor; | ||
18 | } | ||
19 | |||
20 | int CardMonitorImpl::position() const { | ||
21 | return 7; | ||
22 | } | ||
23 | |||
24 | QRESULT CardMonitorImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { | ||
25 | *iface = 0; | ||
26 | if ( uuid == IID_QUnknown ) { | ||
27 | *iface = this; | ||
28 | } else if ( uuid == IID_TaskbarApplet ) { | ||
29 | *iface = this; | ||
30 | } | ||
31 | |||
32 | if ( *iface ) { | ||
33 | (*iface)->addRef(); | ||
34 | } | ||
35 | return QS_OK; | ||
36 | } | ||
37 | |||
38 | Q_EXPORT_INTERFACE() { | ||
39 | Q_CREATE_INSTANCE( CardMonitorImpl ) | ||
40 | } | ||
diff --git a/core/applets/cardmon/cardmonimpl.h b/core/applets/cardmon/cardmonimpl.h new file mode 100644 index 0000000..ec2d871 --- a/dev/null +++ b/core/applets/cardmon/cardmonimpl.h | |||
@@ -0,0 +1,19 @@ | |||
1 | #include <qpe/taskbarappletinterface.h> | ||
2 | |||
3 | class CardMonitor; | ||
4 | |||
5 | class CardMonitorImpl : public TaskbarAppletInterface { | ||
6 | public: | ||
7 | CardMonitorImpl(); | ||
8 | virtual ~CardMonitorImpl(); | ||
9 | |||
10 | QRESULT queryInterface( const QUuid&, QUnknownInterface** ); | ||
11 | Q_REFCOUNT | ||
12 | |||
13 | virtual QWidget *applet( QWidget *parent ); | ||
14 | virtual int position() const; | ||
15 | |||
16 | private: | ||
17 | CardMonitor *cardMonitor; | ||
18 | ulong ref; | ||
19 | }; | ||
diff --git a/core/applets/cardmon/opie-cardmon.control b/core/applets/cardmon/opie-cardmon.control new file mode 100644 index 0000000..9f941f8 --- a/dev/null +++ b/core/applets/cardmon/opie-cardmon.control | |||
@@ -0,0 +1,9 @@ | |||
1 | Files: plugins/applets/libcardmonapplet.so* pics/cardmon/pcmcia.png | ||
2 | Priority: optional | ||
3 | Section: opie/taskbar | ||
4 | Maintainer: Maximilian Reiß <max.reiss@gmx.de> | ||
5 | Architecture: arm | ||
6 | Version: $QPE_VERSION-$SUB_VERSION | ||
7 | Depends: opie-base ($QPE_VERSION) | ||
8 | Description: CF/PCMCIA Card Monitor applet | ||
9 | SD/MMC/CF/PCMCIA Card Monitor applet for the Opie environment taskbar. | ||
diff --git a/core/applets/cardmon/qpe-cardmon.postinst b/core/applets/cardmon/qpe-cardmon.postinst new file mode 100755 index 0000000..ba76ffa --- a/dev/null +++ b/core/applets/cardmon/qpe-cardmon.postinst | |||
@@ -0,0 +1,2 @@ | |||
1 | #!/bin/sh | ||
2 | /opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadApplets()" | ||
diff --git a/core/applets/cardmon/qpe-cardmon.postrm b/core/applets/cardmon/qpe-cardmon.postrm new file mode 100755 index 0000000..ba76ffa --- a/dev/null +++ b/core/applets/cardmon/qpe-cardmon.postrm | |||
@@ -0,0 +1,2 @@ | |||
1 | #!/bin/sh | ||
2 | /opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadApplets()" | ||