author | mickeyl <mickeyl> | 2005-05-21 14:33:55 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-05-21 14:33:55 (UTC) |
commit | 81a650dc44d3be986cbf8f60e7c7b21ef76d1b94 (patch) (unidiff) | |
tree | 146576c950237445a6f3639ef5de8e9cf6214294 | |
parent | dfdc651b989550e30f2b72f535ce0cd3431fc9f4 (diff) | |
download | opie-81a650dc44d3be986cbf8f60e7c7b21ef76d1b94.zip opie-81a650dc44d3be986cbf8f60e7c7b21ef76d1b94.tar.gz opie-81a650dc44d3be986cbf8f60e7c7b21ef76d1b94.tar.bz2 |
add pcmciaapplet. this applet will be a 'next-generation' cardmon applet allowing
not only to monitor PCMCIA/CF cards but also to configure cards, e.g. what Opie
should do, when a certain card has been inserted.
-rw-r--r-- | noncore/applets/pcmcia/.cvsignore | 9 | ||||
-rw-r--r-- | noncore/applets/pcmcia/config.in | 4 | ||||
-rw-r--r-- | noncore/applets/pcmcia/pcmcia.cpp | 249 | ||||
-rw-r--r-- | noncore/applets/pcmcia/pcmcia.h | 65 | ||||
-rw-r--r-- | noncore/applets/pcmcia/pcmcia.pro | 12 |
5 files changed, 339 insertions, 0 deletions
diff --git a/noncore/applets/pcmcia/.cvsignore b/noncore/applets/pcmcia/.cvsignore new file mode 100644 index 0000000..d704947 --- a/dev/null +++ b/noncore/applets/pcmcia/.cvsignore | |||
@@ -0,0 +1,9 @@ | |||
1 | *moc | ||
2 | *.~ | ||
3 | Makefile* | ||
4 | moc_* | ||
5 | opieobj | ||
6 | obj | ||
7 | moc_ | ||
8 | .moc | ||
9 | .obj | ||
diff --git a/noncore/applets/pcmcia/config.in b/noncore/applets/pcmcia/config.in new file mode 100644 index 0000000..5f5af73 --- a/dev/null +++ b/noncore/applets/pcmcia/config.in | |||
@@ -0,0 +1,4 @@ | |||
1 | config PCMCIA-APPLET | ||
2 | boolean "opie-pcmciaapplet (monitor and configure pcmcia/cf cards)" | ||
3 | default "y" | ||
4 | depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE | ||
diff --git a/noncore/applets/pcmcia/pcmcia.cpp b/noncore/applets/pcmcia/pcmcia.cpp new file mode 100644 index 0000000..5183572 --- a/dev/null +++ b/noncore/applets/pcmcia/pcmcia.cpp | |||
@@ -0,0 +1,249 @@ | |||
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/oconfig.h> | ||
36 | #include <opie2/oprocess.h> | ||
37 | #include <opie2/opcmciasystem.h> | ||
38 | #include <opie2/oresource.h> | ||
39 | #include <opie2/otaskbarapplet.h> | ||
40 | #include <qpe/applnk.h> | ||
41 | #include <qpe/resource.h> | ||
42 | using namespace Opie::Core; | ||
43 | using namespace Opie::Ui; | ||
44 | |||
45 | /* QT */ | ||
46 | #include <qcopchannel_qws.h> | ||
47 | #include <qpainter.h> | ||
48 | #include <qfile.h> | ||
49 | #include <qtextstream.h> | ||
50 | #include <qmessagebox.h> | ||
51 | #include <qsound.h> | ||
52 | #include <qtimer.h> | ||
53 | |||
54 | /* STD */ | ||
55 | #include <stdio.h> | ||
56 | #include <unistd.h> | ||
57 | #include <stdlib.h> | ||
58 | #include <string.h> | ||
59 | #include <fcntl.h> | ||
60 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | ||
61 | #include <sys/vfs.h> | ||
62 | #include <mntent.h> | ||
63 | #endif | ||
64 | |||
65 | PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ) | ||
66 | { | ||
67 | QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); | ||
68 | connect( pcmciaChannel, | ||
69 | SIGNAL( received(const QCString&,const QByteArray&) ), this, | ||
70 | SLOT( cardMessage(const QCString&,const QByteArray&) ) ); | ||
71 | |||
72 | setFocusPolicy( NoFocus ); | ||
73 | setFixedWidth ( AppLnk::smallIconSize() ); | ||
74 | setFixedHeight ( AppLnk::smallIconSize() ); | ||
75 | pm = Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon ); | ||
76 | } | ||
77 | |||
78 | |||
79 | PcmciaManager::~PcmciaManager() | ||
80 | { | ||
81 | } | ||
82 | |||
83 | |||
84 | void PcmciaManager::popUp( QString message, QString icon ) | ||
85 | { | ||
86 | if ( !popupMenu ) { | ||
87 | popupMenu = new QPopupMenu( this ); | ||
88 | } | ||
89 | |||
90 | popupMenu->clear(); | ||
91 | if ( icon.isEmpty() ) { | ||
92 | popupMenu->insertItem( message, 0 ); | ||
93 | } else { | ||
94 | popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ), | ||
95 | message, 0 ); | ||
96 | } | ||
97 | |||
98 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); | ||
99 | QSize s = popupMenu->sizeHint(); | ||
100 | popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), | ||
101 | p.y() - s.height() ), 0 ); | ||
102 | |||
103 | QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); | ||
104 | } | ||
105 | |||
106 | |||
107 | void PcmciaManager::popupTimeout() | ||
108 | { | ||
109 | popupMenu->hide(); | ||
110 | } | ||
111 | |||
112 | |||
113 | void PcmciaManager::mousePressEvent( QMouseEvent* ) | ||
114 | { | ||
115 | QPopupMenu * menu = new QPopupMenu( this ); | ||
116 | QStringList cmd; | ||
117 | bool execute = true; | ||
118 | |||
119 | OPcmciaSystem* sys = OPcmciaSystem::instance(); | ||
120 | OPcmciaSystem::CardIterator it = sys->iterator(); | ||
121 | if ( !sys->count() ) return; | ||
122 | |||
123 | int i = 0; | ||
124 | while ( it.current() ) | ||
125 | { | ||
126 | menu->insertItem( tr( "Eject card %1: %2" ).arg( i++ ).arg( it.currentKey() ), 1 ); | ||
127 | ++it; | ||
128 | } | ||
129 | |||
130 | |||
131 | /* insert items depending on number of cards etc. | ||
132 | |||
133 | if ( cardInSd ) { | ||
134 | menu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( "cardmon/ide", Opie::Core::OResource::SmallIcon ) ), | ||
135 | tr( "Eject SD/MMC card" ), 0 ); | ||
136 | } | ||
137 | |||
138 | |||
139 | |||
140 | if ( cardInPcmcia0 ) { | ||
141 | menu-> | ||
142 | insertItem( QIconSet | ||
143 | ( Opie::Core::OResource::loadPixmap( "cardmon/" + cardInPcmcia0Type, Opie::Core::OResource::SmallIcon ) ), | ||
144 | tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 ); | ||
145 | } | ||
146 | |||
147 | if ( cardInPcmcia1 ) { | ||
148 | menu-> | ||
149 | insertItem( QIconSet | ||
150 | ( Opie::Core::OResource::loadPixmap( "cardmon/" + cardInPcmcia1Type, Opie::Core::OResource::SmallIcon ) ), | ||
151 | tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); | ||
152 | } | ||
153 | */ | ||
154 | |||
155 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); | ||
156 | QSize s = menu->sizeHint(); | ||
157 | int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 ); | ||
158 | qDebug( "pcmcia: menu result = %d", opt ); | ||
159 | delete menu; | ||
160 | } | ||
161 | |||
162 | |||
163 | void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) | ||
164 | { | ||
165 | odebug << "PcmciaManager::cardMessage( '" << msg << "' )" << oendl; | ||
166 | if ( msg != "stabChanged()" ) return; | ||
167 | |||
168 | /* check if a previously unknown card has been inserted */ | ||
169 | OPcmciaSystem::instance()->synchronize(); | ||
170 | |||
171 | if ( !OPcmciaSystem::instance()->count() ) return; | ||
172 | |||
173 | OConfig cfg( "PCMCIA" ); | ||
174 | cfg.setGroup( "Global" ); | ||
175 | int nCards = cfg.readNumEntry( "nCards", 0 ); | ||
176 | |||
177 | OPcmciaSystem* sys = OPcmciaSystem::instance(); | ||
178 | OPcmciaSystem::CardIterator it = sys->iterator(); | ||
179 | |||
180 | bool newCard = true; | ||
181 | while ( it.current() && newCard ) | ||
182 | { | ||
183 | QString name = it.currentKey(); | ||
184 | for ( int i = 0; i < nCards; ++i ) | ||
185 | { | ||
186 | QString cardSection = QString( "Card_%1" ).arg( i ); | ||
187 | cfg.setGroup( cardSection ); | ||
188 | QString cardName = cfg.readEntry( "name" ); | ||
189 | odebug << "comparing card '" << name << "' with known card '" << cardName << "'" << oendl; | ||
190 | if ( cardName == name ) | ||
191 | { | ||
192 | newCard = false; | ||
193 | break; | ||
194 | } | ||
195 | } | ||
196 | if ( !newCard ) ++it; else break; | ||
197 | } | ||
198 | QString newCardName = it.currentKey(); | ||
199 | |||
200 | if ( newCard ) | ||
201 | { | ||
202 | odebug << "pcmcia: new card detected" << oendl; | ||
203 | cfg.setGroup( QString( "Card_%1" ).arg( nCards ) ); | ||
204 | cfg.writeEntry( "name", newCardName ); | ||
205 | cfg.setGroup( "Global" ); | ||
206 | cfg.writeEntry( "nCards", nCards+1 ); | ||
207 | cfg.write(); | ||
208 | |||
209 | int result = QMessageBox::information( qApp->desktop(), | ||
210 | tr( "PCMCIA/CF Subsystem" ), | ||
211 | tr( "You have inserted a new card\n%1\nDo you want to configure this card?" ).arg( newCardName ), | ||
212 | tr( "Yes" ), tr( "No" ), 0, 0, 1 ); | ||
213 | odebug << "result = " << result << oendl; | ||
214 | |||
215 | } | ||
216 | else | ||
217 | { | ||
218 | odebug << "pcmcia: card has been previously inserted" << oendl; | ||
219 | } | ||
220 | repaint( TRUE ); | ||
221 | } | ||
222 | |||
223 | |||
224 | void PcmciaManager::paintEvent( QPaintEvent * ) | ||
225 | { | ||
226 | QPainter p( this ); | ||
227 | qDebug( "count = %d", (OPcmciaSystem::instance()->count() ) ); | ||
228 | if ( OPcmciaSystem::instance()->count() ) | ||
229 | { | ||
230 | p.drawPixmap( 0, 0, pm ); | ||
231 | show(); | ||
232 | } | ||
233 | else | ||
234 | { | ||
235 | hide(); | ||
236 | } | ||
237 | } | ||
238 | |||
239 | int PcmciaManager::position() | ||
240 | { | ||
241 | return 7; | ||
242 | } | ||
243 | |||
244 | void PcmciaManager::execCommand( const QStringList &strList ) | ||
245 | { | ||
246 | } | ||
247 | |||
248 | EXPORT_OPIE_APPLET_v1( PcmciaManager ) | ||
249 | |||
diff --git a/noncore/applets/pcmcia/pcmcia.h b/noncore/applets/pcmcia/pcmcia.h new file mode 100644 index 0000000..5c20433 --- a/dev/null +++ b/noncore/applets/pcmcia/pcmcia.h | |||
@@ -0,0 +1,65 @@ | |||
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 | |||
37 | class PcmciaManager : public QWidget | ||
38 | { | ||
39 | Q_OBJECT | ||
40 | public: | ||
41 | PcmciaManager( QWidget *parent = 0 ); | ||
42 | ~PcmciaManager(); | ||
43 | static int position(); | ||
44 | |||
45 | private slots: | ||
46 | void cardMessage( const QCString& msg, const QByteArray& ); | ||
47 | void popupTimeout(); | ||
48 | |||
49 | protected: | ||
50 | void paintEvent( QPaintEvent* ); | ||
51 | void mousePressEvent( QMouseEvent * ); | ||
52 | |||
53 | private: | ||
54 | void execCommand( const QStringList &command ); | ||
55 | void popUp(QString message, QString icon = QString::null ); | ||
56 | |||
57 | private: | ||
58 | int m_commandOrig; | ||
59 | QPixmap pm; | ||
60 | QPopupMenu *popupMenu; | ||
61 | |||
62 | }; | ||
63 | |||
64 | #endif | ||
65 | |||
diff --git a/noncore/applets/pcmcia/pcmcia.pro b/noncore/applets/pcmcia/pcmcia.pro new file mode 100644 index 0000000..c4f7b62 --- a/dev/null +++ b/noncore/applets/pcmcia/pcmcia.pro | |||
@@ -0,0 +1,12 @@ | |||
1 | TEMPLATE = lib | ||
2 | CONFIG += qt plugin warn_on | ||
3 | HEADERS = pcmcia.h | ||
4 | SOURCES = pcmcia.cpp | ||
5 | TARGET = pcmciaapplet | ||
6 | DESTDIR = $(OPIEDIR)/plugins/applets | ||
7 | INCLUDEPATH += $(OPIEDIR)/include | ||
8 | DEPENDPATH += $(OPIEDIR)/include | ||
9 | LIBS += -lqpe -lopiecore2 | ||
10 | VERSION = 0.1.0 | ||
11 | |||
12 | include( $(OPIEDIR)/include.pro ) | ||