author | mickeyl <mickeyl> | 2005-05-21 18:09:20 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-05-21 18:09:20 (UTC) |
commit | d56ca82c22c3ac6b7dfb0bb7b4d5a0e5ad1ff4f1 (patch) (unidiff) | |
tree | a2024d12d6986c9d6397e9570faa96000a221cb0 | |
parent | 7f8a80783ba36f32892bedf6a3bfebc20e822199 (diff) | |
download | opie-d56ca82c22c3ac6b7dfb0bb7b4d5a0e5ad1ff4f1.zip opie-d56ca82c22c3ac6b7dfb0bb7b4d5a0e5ad1ff4f1.tar.gz opie-d56ca82c22c3ac6b7dfb0bb7b4d5a0e5ad1ff4f1.tar.bz2 |
make detection algorithm work with any number of sockets
-rw-r--r-- | noncore/applets/pcmcia/pcmcia.cpp | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/noncore/applets/pcmcia/pcmcia.cpp b/noncore/applets/pcmcia/pcmcia.cpp index 7f24371..a1deb6b 100644 --- a/noncore/applets/pcmcia/pcmcia.cpp +++ b/noncore/applets/pcmcia/pcmcia.cpp | |||
@@ -1,259 +1,277 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | .=l. | 4 | .=l. |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | 27 | ||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "pcmcia.h" | 30 | #include "pcmcia.h" |
31 | 31 | ||
32 | /* OPIE */ | 32 | /* OPIE */ |
33 | #include <opie2/odebug.h> | 33 | #include <opie2/odebug.h> |
34 | #include <opie2/odevice.h> | 34 | #include <opie2/odevice.h> |
35 | #include <opie2/oconfig.h> | 35 | #include <opie2/oconfig.h> |
36 | #include <opie2/oprocess.h> | 36 | #include <opie2/oprocess.h> |
37 | #include <opie2/opcmciasystem.h> | 37 | #include <opie2/opcmciasystem.h> |
38 | #include <opie2/oresource.h> | 38 | #include <opie2/oresource.h> |
39 | #include <opie2/otaskbarapplet.h> | 39 | #include <opie2/otaskbarapplet.h> |
40 | #include <qpe/applnk.h> | 40 | #include <qpe/applnk.h> |
41 | #include <qpe/resource.h> | 41 | #include <qpe/resource.h> |
42 | using namespace Opie::Core; | 42 | using namespace Opie::Core; |
43 | using namespace Opie::Ui; | 43 | using namespace Opie::Ui; |
44 | 44 | ||
45 | /* QT */ | 45 | /* QT */ |
46 | #include <qcopchannel_qws.h> | 46 | #include <qcopchannel_qws.h> |
47 | #include <qpainter.h> | 47 | #include <qpainter.h> |
48 | #include <qfile.h> | 48 | #include <qfile.h> |
49 | #include <qtextstream.h> | 49 | #include <qtextstream.h> |
50 | #include <qmessagebox.h> | 50 | #include <qmessagebox.h> |
51 | #include <qsound.h> | 51 | #include <qsound.h> |
52 | #include <qtimer.h> | 52 | #include <qtimer.h> |
53 | 53 | ||
54 | /* STD */ | 54 | /* STD */ |
55 | #include <stdio.h> | 55 | #include <stdio.h> |
56 | #include <unistd.h> | 56 | #include <unistd.h> |
57 | #include <stdlib.h> | 57 | #include <stdlib.h> |
58 | #include <string.h> | 58 | #include <string.h> |
59 | #include <fcntl.h> | 59 | #include <fcntl.h> |
60 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 60 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
61 | #include <sys/vfs.h> | 61 | #include <sys/vfs.h> |
62 | #include <mntent.h> | 62 | #include <mntent.h> |
63 | #endif | 63 | #endif |
64 | 64 | ||
65 | PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ) | 65 | PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ) |
66 | { | 66 | { |
67 | QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); | 67 | QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); |
68 | connect( pcmciaChannel, | 68 | connect( pcmciaChannel, |
69 | SIGNAL( received(const QCString&,const QByteArray&) ), this, | 69 | SIGNAL( received(const QCString&,const QByteArray&) ), this, |
70 | SLOT( cardMessage(const QCString&,const QByteArray&) ) ); | 70 | SLOT( cardMessage(const QCString&,const QByteArray&) ) ); |
71 | 71 | ||
72 | setFocusPolicy( NoFocus ); | 72 | setFocusPolicy( NoFocus ); |
73 | setFixedWidth ( AppLnk::smallIconSize() ); | 73 | setFixedWidth ( AppLnk::smallIconSize() ); |
74 | setFixedHeight ( AppLnk::smallIconSize() ); | 74 | setFixedHeight ( AppLnk::smallIconSize() ); |
75 | pm = Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon ); | 75 | pm = Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon ); |
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | PcmciaManager::~PcmciaManager() | 79 | PcmciaManager::~PcmciaManager() |
80 | { | 80 | { |
81 | } | 81 | } |
82 | 82 | ||
83 | 83 | ||
84 | void PcmciaManager::popUp( QString message, QString icon ) | 84 | void PcmciaManager::popUp( QString message, QString icon ) |
85 | { | 85 | { |
86 | if ( !popupMenu ) { | 86 | if ( !popupMenu ) { |
87 | popupMenu = new QPopupMenu( this ); | 87 | popupMenu = new QPopupMenu( this ); |
88 | } | 88 | } |
89 | 89 | ||
90 | popupMenu->clear(); | 90 | popupMenu->clear(); |
91 | if ( icon.isEmpty() ) { | 91 | if ( icon.isEmpty() ) { |
92 | popupMenu->insertItem( message, 0 ); | 92 | popupMenu->insertItem( message, 0 ); |
93 | } else { | 93 | } else { |
94 | popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ), | 94 | popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ), |
95 | message, 0 ); | 95 | message, 0 ); |
96 | } | 96 | } |
97 | 97 | ||
98 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); | 98 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); |
99 | QSize s = popupMenu->sizeHint(); | 99 | QSize s = popupMenu->sizeHint(); |
100 | popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), | 100 | popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), |
101 | p.y() - s.height() ), 0 ); | 101 | p.y() - s.height() ), 0 ); |
102 | 102 | ||
103 | QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); | 103 | QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); |
104 | } | 104 | } |
105 | 105 | ||
106 | 106 | ||
107 | void PcmciaManager::popupTimeout() | 107 | void PcmciaManager::popupTimeout() |
108 | { | 108 | { |
109 | popupMenu->hide(); | 109 | popupMenu->hide(); |
110 | } | 110 | } |
111 | 111 | ||
112 | 112 | ||
113 | void PcmciaManager::mousePressEvent( QMouseEvent* ) | 113 | void PcmciaManager::mousePressEvent( QMouseEvent* ) |
114 | { | 114 | { |
115 | QPopupMenu* menu = new QPopupMenu( this ); | 115 | QPopupMenu* menu = new QPopupMenu( this ); |
116 | QStringList cmd; | 116 | QStringList cmd; |
117 | bool execute = true; | 117 | bool execute = true; |
118 | 118 | ||
119 | OPcmciaSystem* sys = OPcmciaSystem::instance(); | 119 | OPcmciaSystem* sys = OPcmciaSystem::instance(); |
120 | OPcmciaSystem::CardIterator it = sys->iterator(); | 120 | OPcmciaSystem::CardIterator it = sys->iterator(); |
121 | if ( !sys->count() ) return; | 121 | if ( !sys->count() ) return; |
122 | 122 | ||
123 | int i = 0; | 123 | int i = 0; |
124 | while ( it.current() ) | 124 | while ( it.current() ) |
125 | { | 125 | { |
126 | 126 | ||
127 | QPopupMenu* submenu = new QPopupMenu( menu ); | 127 | QPopupMenu* submenu = new QPopupMenu( menu ); |
128 | submenu->insertItem( "Eject" ); | 128 | submenu->insertItem( "Eject" ); |
129 | submenu->insertItem( "Insert" ); | 129 | submenu->insertItem( "Insert" ); |
130 | submenu->insertItem( "Suspend" ); | 130 | submenu->insertItem( "Suspend" ); |
131 | submenu->insertItem( "Resume" ); | 131 | submenu->insertItem( "Resume" ); |
132 | submenu->insertItem( "Configure" ); | 132 | submenu->insertItem( "Configure" ); |
133 | 133 | ||
134 | menu->insertItem( tr( "%1: %2" ).arg( i++ ).arg( it.current()->identity() ), submenu, 1 ); | 134 | menu->insertItem( tr( "%1: %2" ).arg( i++ ).arg( it.current()->identity() ), submenu, 1 ); |
135 | ++it; | 135 | ++it; |
136 | } | 136 | } |
137 | 137 | ||
138 | 138 | ||
139 | 139 | ||
140 | /* insert items depending on number of cards etc. | 140 | /* insert items depending on number of cards etc. |
141 | 141 | ||
142 | if ( cardInSd ) { | 142 | if ( cardInSd ) { |
143 | menu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( "cardmon/ide", Opie::Core::OResource::SmallIcon ) ), | 143 | menu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( "cardmon/ide", Opie::Core::OResource::SmallIcon ) ), |
144 | tr( "Eject SD/MMC card" ), 0 ); | 144 | tr( "Eject SD/MMC card" ), 0 ); |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | 148 | ||
149 | if ( cardInPcmcia0 ) { | 149 | if ( cardInPcmcia0 ) { |
150 | menu-> | 150 | menu-> |
151 | insertItem( QIconSet | 151 | insertItem( QIconSet |
152 | ( Opie::Core::OResource::loadPixmap( "cardmon/" + cardInPcmcia0Type, Opie::Core::OResource::SmallIcon ) ), | 152 | ( Opie::Core::OResource::loadPixmap( "cardmon/" + cardInPcmcia0Type, Opie::Core::OResource::SmallIcon ) ), |
153 | tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 ); | 153 | tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 ); |
154 | } | 154 | } |
155 | 155 | ||
156 | if ( cardInPcmcia1 ) { | 156 | if ( cardInPcmcia1 ) { |
157 | menu-> | 157 | menu-> |
158 | insertItem( QIconSet | 158 | insertItem( QIconSet |
159 | ( Opie::Core::OResource::loadPixmap( "cardmon/" + cardInPcmcia1Type, Opie::Core::OResource::SmallIcon ) ), | 159 | ( Opie::Core::OResource::loadPixmap( "cardmon/" + cardInPcmcia1Type, Opie::Core::OResource::SmallIcon ) ), |
160 | tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); | 160 | tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 ); |
161 | } | 161 | } |
162 | */ | 162 | */ |
163 | 163 | ||
164 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); | 164 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); |
165 | QSize s = menu->sizeHint(); | 165 | QSize s = menu->sizeHint(); |
166 | int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 ); | 166 | int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 ); |
167 | qDebug( "pcmcia: menu result = %d", opt ); | 167 | qDebug( "pcmcia: menu result = %d", opt ); |
168 | delete menu; | 168 | delete menu; |
169 | } | 169 | } |
170 | 170 | ||
171 | 171 | ||
172 | void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) | 172 | void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) |
173 | { | 173 | { |
174 | odebug << "PcmciaManager::cardMessage( '" << msg << "' )" << oendl; | 174 | odebug << "PcmciaManager::cardMessage( '" << msg << "' )" << oendl; |
175 | if ( msg != "stabChanged()" ) return; | 175 | if ( msg != "stabChanged()" ) return; |
176 | 176 | ||
177 | /* check if a previously unknown card has been inserted */ | 177 | /* check if a previously unknown card has been inserted */ |
178 | OPcmciaSystem::instance()->synchronize(); | 178 | OPcmciaSystem::instance()->synchronize(); |
179 | 179 | ||
180 | if ( !OPcmciaSystem::instance()->cardCount() ) return; | 180 | if ( !OPcmciaSystem::instance()->cardCount() ) return; |
181 | 181 | ||
182 | OConfig cfg( "PCMCIA" ); | 182 | OConfig cfg( "PCMCIA" ); |
183 | cfg.setGroup( "Global" ); | 183 | cfg.setGroup( "Global" ); |
184 | int nCards = cfg.readNumEntry( "nCards", 0 ); | 184 | int nCards = cfg.readNumEntry( "nCards", 0 ); |
185 | 185 | ||
186 | OPcmciaSystem* sys = OPcmciaSystem::instance(); | 186 | OPcmciaSystem* sys = OPcmciaSystem::instance(); |
187 | OPcmciaSystem::CardIterator it = sys->iterator(); | 187 | OPcmciaSystem::CardIterator it = sys->iterator(); |
188 | 188 | ||
189 | bool newCard = true; | 189 | bool newCard = true; |
190 | 190 | QString cardName; | |
191 | while ( it.current() && !it.current()->isEmpty() && newCard ) | 191 | |
192 | while ( it.current() && newCard ) | ||
192 | { | 193 | { |
193 | QString name = it.current()->identity(); | 194 | if ( it.current()->isEmpty() ) |
194 | for ( int i = 0; i < nCards; ++i ) | 195 | { |
196 | odebug << "skipping empty card in socket " << it.current()->number() << oendl; | ||
197 | ++it; | ||
198 | continue; | ||
199 | } | ||
200 | else | ||
195 | { | 201 | { |
196 | QString cardSection = QString( "Card_%1" ).arg( i ); | 202 | cardName = it.current()->identity(); |
197 | cfg.setGroup( cardSection ); | 203 | for ( int i = 0; i < nCards; ++i ) |
198 | QString cardName = cfg.readEntry( "name" ); | ||
199 | odebug << "comparing card '" << name << "' with known card '" << cardName << "'" << oendl; | ||
200 | if ( cardName == name ) | ||
201 | { | 204 | { |
202 | newCard = false; | 205 | QString cardSection = QString( "Card_%1" ).arg( i ); |
203 | break; | 206 | cfg.setGroup( cardSection ); |
207 | QString name = cfg.readEntry( "name" ); | ||
208 | odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl; | ||
209 | if ( cardName == name ) | ||
210 | { | ||
211 | newCard = false; | ||
212 | break; | ||
213 | } | ||
204 | } | 214 | } |
215 | if ( !newCard ) ++it; else break; | ||
205 | } | 216 | } |
206 | if ( !newCard ) ++it; else break; | ||
207 | } | 217 | } |
208 | |||
209 | if ( newCard ) | 218 | if ( newCard ) |
210 | { | 219 | { |
211 | QString newCardName = it.current()->identity(); | ||
212 | odebug << "pcmcia: new card detected" << oendl; | 220 | odebug << "pcmcia: new card detected" << oendl; |
213 | cfg.setGroup( QString( "Card_%1" ).arg( nCards ) ); | 221 | cfg.setGroup( QString( "Card_%1" ).arg( nCards ) ); |
214 | cfg.writeEntry( "name", newCardName ); | 222 | cfg.writeEntry( "name", cardName ); |
215 | cfg.setGroup( "Global" ); | 223 | cfg.setGroup( "Global" ); |
216 | cfg.writeEntry( "nCards", nCards+1 ); | 224 | cfg.writeEntry( "nCards", nCards+1 ); |
217 | cfg.write(); | 225 | cfg.write(); |
218 | 226 | ||
219 | int result = QMessageBox::information( qApp->desktop(), | 227 | int result = QMessageBox::information( qApp->desktop(), |
220 | tr( "PCMCIA/CF Subsystem" ), | 228 | tr( "PCMCIA/CF Subsystem" ), |
221 | tr( "You have inserted a new card\n%1\nDo you want to configure this card?" ).arg( newCardName ), | 229 | tr( "You have inserted a new card:\n%1\nDo you want to configure?" ).arg( cardName ), |
222 | tr( "Yes" ), tr( "No" ), 0, 0, 1 ); | 230 | tr( "Yes" ), tr( "No" ), 0, 0, 1 ); |
223 | odebug << "result = " << result << oendl; | 231 | odebug << "result = " << result << oendl; |
224 | 232 | if ( result == 0 ) | |
233 | { | ||
234 | QMessageBox::information( qApp->desktop(), | ||
235 | tr( "PCMCIA/CF Subsystem" ), | ||
236 | tr( "Sorry, not yet implemented...\n~lart mickeyl :D" ), | ||
237 | tr( "No Problem" ), 0, 0, 0 ); | ||
238 | } | ||
239 | else | ||
240 | { | ||
241 | odebug << "pcmcia: user doesn't want to configure " << cardName << " now." << oendl; | ||
242 | } | ||
225 | } | 243 | } |
226 | else | 244 | else |
227 | { | 245 | { |
228 | odebug << "pcmcia: card has been previously inserted" << oendl; | 246 | odebug << "pcmcia: card has been previously inserted" << oendl; |
229 | } | 247 | } |
230 | repaint( TRUE ); | 248 | repaint( true ); |
231 | } | 249 | } |
232 | 250 | ||
233 | 251 | ||
234 | void PcmciaManager::paintEvent( QPaintEvent * ) | 252 | void PcmciaManager::paintEvent( QPaintEvent * ) |
235 | { | 253 | { |
236 | QPainter p( this ); | 254 | QPainter p( this ); |
237 | qDebug( "count = %d", (OPcmciaSystem::instance()->count() ) ); | 255 | qDebug( "count = %d", (OPcmciaSystem::instance()->count() ) ); |
238 | if ( OPcmciaSystem::instance()->count() ) | 256 | if ( OPcmciaSystem::instance()->count() ) |
239 | { | 257 | { |
240 | p.drawPixmap( 0, 0, pm ); | 258 | p.drawPixmap( 0, 0, pm ); |
241 | show(); | 259 | show(); |
242 | } | 260 | } |
243 | else | 261 | else |
244 | { | 262 | { |
245 | hide(); | 263 | hide(); |
246 | } | 264 | } |
247 | } | 265 | } |
248 | 266 | ||
249 | int PcmciaManager::position() | 267 | int PcmciaManager::position() |
250 | { | 268 | { |
251 | return 7; | 269 | return 7; |
252 | } | 270 | } |
253 | 271 | ||
254 | void PcmciaManager::execCommand( const QStringList &strList ) | 272 | void PcmciaManager::execCommand( const QStringList &strList ) |
255 | { | 273 | { |
256 | } | 274 | } |
257 | 275 | ||
258 | EXPORT_OPIE_APPLET_v1( PcmciaManager ) | 276 | EXPORT_OPIE_APPLET_v1( PcmciaManager ) |
259 | 277 | ||