summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-06-17 13:29:56 (UTC)
committer mickeyl <mickeyl>2005-06-17 13:29:56 (UTC)
commit0e11eb29a20ff6bff533a07ff604ed858237f82b (patch) (unidiff)
treebd1ef20d6771064973297bfea7b0bffc2271ab87
parent8af66795130275b1337f8ae06d249649ac273d0d (diff)
downloadopie-0e11eb29a20ff6bff533a07ff604ed858237f82b.zip
opie-0e11eb29a20ff6bff533a07ff604ed858237f82b.tar.gz
opie-0e11eb29a20ff6bff533a07ff604ed858237f82b.tar.bz2
make reset, eject, suspend, resume, insert work
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/pcmcia/pcmcia.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/noncore/applets/pcmcia/pcmcia.cpp b/noncore/applets/pcmcia/pcmcia.cpp
index fac7065..aea699f 100644
--- a/noncore/applets/pcmcia/pcmcia.cpp
+++ b/noncore/applets/pcmcia/pcmcia.cpp
@@ -1,285 +1,297 @@
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#include "configdialog.h" 31#include "configdialog.h"
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/odebug.h> 34#include <opie2/odebug.h>
35#include <opie2/odevice.h> 35#include <opie2/odevice.h>
36#include <opie2/oconfig.h> 36#include <opie2/oconfig.h>
37#include <opie2/oprocess.h> 37#include <opie2/oprocess.h>
38#include <opie2/opcmciasystem.h> 38#include <opie2/opcmciasystem.h>
39#include <opie2/oresource.h> 39#include <opie2/oresource.h>
40#include <opie2/otaskbarapplet.h> 40#include <opie2/otaskbarapplet.h>
41#include <qpe/applnk.h> 41#include <qpe/applnk.h>
42#include <qpe/resource.h> 42#include <qpe/resource.h>
43using namespace Opie::Core; 43using namespace Opie::Core;
44using namespace Opie::Ui; 44using namespace Opie::Ui;
45 45
46/* QT */ 46/* QT */
47#include <qcopchannel_qws.h> 47#include <qcopchannel_qws.h>
48#include <qpainter.h> 48#include <qpainter.h>
49#include <qfile.h> 49#include <qfile.h>
50#include <qtextstream.h> 50#include <qtextstream.h>
51#include <qmessagebox.h> 51#include <qmessagebox.h>
52#include <qsound.h> 52#include <qsound.h>
53#include <qtimer.h> 53#include <qtimer.h>
54 54
55/* STD */ 55/* STD */
56#include <stdio.h> 56#include <stdio.h>
57#include <unistd.h> 57#include <unistd.h>
58#include <stdlib.h> 58#include <stdlib.h>
59#include <string.h> 59#include <string.h>
60#include <fcntl.h> 60#include <fcntl.h>
61#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 61#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
62#include <sys/vfs.h> 62#include <sys/vfs.h>
63#include <mntent.h> 63#include <mntent.h>
64#endif 64#endif
65 65
66PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ) 66PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent )
67{ 67{
68 QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); 68 QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this );
69 connect( pcmciaChannel, 69 connect( pcmciaChannel,
70 SIGNAL( received(const QCString&,const QByteArray&) ), this, 70 SIGNAL( received(const QCString&,const QByteArray&) ), this,
71 SLOT( cardMessage(const QCString&,const QByteArray&) ) ); 71 SLOT( cardMessage(const QCString&,const QByteArray&) ) );
72 72
73 setFocusPolicy( NoFocus ); 73 setFocusPolicy( NoFocus );
74 setFixedWidth ( AppLnk::smallIconSize() ); 74 setFixedWidth ( AppLnk::smallIconSize() );
75 setFixedHeight ( AppLnk::smallIconSize() ); 75 setFixedHeight ( AppLnk::smallIconSize() );
76 pm = Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon ); 76 pm = Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon );
77 configuring = false; 77 configuring = false;
78} 78}
79 79
80 80
81PcmciaManager::~PcmciaManager() 81PcmciaManager::~PcmciaManager()
82{ 82{
83} 83}
84 84
85 85
86void PcmciaManager::popUp( QString message, QString icon ) 86void PcmciaManager::popUp( QString message, QString icon )
87{ 87{
88 if ( !popupMenu ) { 88 if ( !popupMenu ) {
89 popupMenu = new QPopupMenu( this ); 89 popupMenu = new QPopupMenu( this );
90 } 90 }
91 91
92 popupMenu->clear(); 92 popupMenu->clear();
93 if ( icon.isEmpty() ) { 93 if ( icon.isEmpty() ) {
94 popupMenu->insertItem( message, 0 ); 94 popupMenu->insertItem( message, 0 );
95 } else { 95 } else {
96 popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ), 96 popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ),
97 message, 0 ); 97 message, 0 );
98 } 98 }
99 99
100 QPoint p = mapToGlobal( QPoint( 0, 0 ) ); 100 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
101 QSize s = popupMenu->sizeHint(); 101 QSize s = popupMenu->sizeHint();
102 popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), 102 popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ),
103 p.y() - s.height() ), 0 ); 103 p.y() - s.height() ), 0 );
104 104
105 QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); 105 QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) );
106} 106}
107 107
108 108
109void PcmciaManager::popupTimeout() 109void PcmciaManager::popupTimeout()
110{ 110{
111 popupMenu->hide(); 111 popupMenu->hide();
112} 112}
113 113
114enum { EJECT, INSERT, SUSPEND, RESUME, RESET, CONFIGURE }; 114enum { EJECT, INSERT, SUSPEND, RESUME, RESET, CONFIGURE };
115 115
116void PcmciaManager::mousePressEvent( QMouseEvent* ) 116void PcmciaManager::mousePressEvent( QMouseEvent* )
117{ 117{
118 QPopupMenu* menu = new QPopupMenu( this ); 118 QPopupMenu* menu = new QPopupMenu( this );
119 QStringList cmd; 119 QStringList cmd;
120 bool execute = true; 120 bool execute = true;
121 121
122 OPcmciaSystem* sys = OPcmciaSystem::instance(); 122 OPcmciaSystem* sys = OPcmciaSystem::instance();
123 OPcmciaSystem::CardIterator it = sys->iterator(); 123 OPcmciaSystem::CardIterator it = sys->iterator();
124 if ( !sys->count() ) return; 124 if ( !sys->count() ) return;
125 125
126 int i = 0; 126 int i = 0;
127 while ( it.current() ) 127 while ( it.current() )
128 { 128 {
129 QPopupMenu* submenu = new QPopupMenu( menu ); 129 QPopupMenu* submenu = new QPopupMenu( menu );
130 submenu->insertItem( "&Eject", EJECT+i*100 ); 130 submenu->insertItem( "&Eject", EJECT+i*100 );
131 submenu->insertItem( "&Insert", INSERT+i*100 ); 131 submenu->insertItem( "&Insert", INSERT+i*100 );
132 submenu->insertItem( "&Suspend", SUSPEND+i*100 ); 132 submenu->insertItem( "&Suspend", SUSPEND+i*100 );
133 submenu->insertItem( "&Resume", RESUME+i*100 ); 133 submenu->insertItem( "&Resume", RESUME+i*100 );
134 submenu->insertItem( "Rese&t", RESET+i*100 ); 134 submenu->insertItem( "Rese&t", RESET+i*100 );
135 submenu->insertItem( "&Configure", CONFIGURE+i*100 ); 135 submenu->insertItem( "&Configure", CONFIGURE+i*100 );
136 136
137 submenu->setItemEnabled( EJECT+i*100, !it.current()->isEmpty() ); 137 submenu->setItemEnabled( EJECT+i*100, !it.current()->isEmpty() );
138 submenu->setItemEnabled( INSERT+i*100, it.current()->isEmpty() ); 138 submenu->setItemEnabled( INSERT+i*100, it.current()->isEmpty() );
139 submenu->setItemEnabled( SUSPEND+i*100, !it.current()->isEmpty() && !it.current()->isSuspended() ); 139 submenu->setItemEnabled( SUSPEND+i*100, !it.current()->isEmpty() && !it.current()->isSuspended() );
140 submenu->setItemEnabled( RESUME+i*100, !it.current()->isEmpty() && it.current()->isSuspended() ); 140 submenu->setItemEnabled( RESUME+i*100, !it.current()->isEmpty() && it.current()->isSuspended() );
141 submenu->setItemEnabled( CONFIGURE+i*100, !it.current()->isEmpty() && !configuring ); 141 submenu->setItemEnabled( CONFIGURE+i*100, !it.current()->isEmpty() && !configuring );
142 142
143 connect( submenu, SIGNAL(activated(int)), this, SLOT(userCardAction(int)) ); 143 connect( submenu, SIGNAL(activated(int)), this, SLOT(userCardAction(int)) );
144 menu->insertItem( tr( "%1: %2" ).arg( i++ ).arg( it.current()->identity() ), submenu, 1 ); 144 menu->insertItem( tr( "%1: %2" ).arg( i++ ).arg( it.current()->identity() ), submenu, 1 );
145 ++it; 145 ++it;
146 } 146 }
147 147
148 QPoint p = mapToGlobal( QPoint( 0, 0 ) ); 148 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
149 QSize s = menu->sizeHint(); 149 QSize s = menu->sizeHint();
150 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 ); 150 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 );
151 qDebug( "pcmcia: menu result = %d", opt ); 151 qDebug( "pcmcia: menu result = %d", opt );
152 delete menu; 152 delete menu;
153} 153}
154 154
155 155
156void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) 156void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
157{ 157{
158 odebug << "PcmciaManager::cardMessage( '" << msg << "' )" << oendl; 158 odebug << "PcmciaManager::cardMessage( '" << msg << "' )" << oendl;
159 if ( msg != "stabChanged()" ) return; 159 if ( msg != "stabChanged()" ) return;
160 160
161 /* check if a previously unknown card has been inserted */ 161 /* check if a previously unknown card has been inserted */
162 OPcmciaSystem::instance()->synchronize(); 162 OPcmciaSystem::instance()->synchronize();
163 163
164 if ( !OPcmciaSystem::instance()->cardCount() ) return; 164 if ( !OPcmciaSystem::instance()->cardCount() ) return;
165 165
166 OConfig cfg( "PCMCIA" ); 166 OConfig cfg( "PCMCIA" );
167 cfg.setGroup( "Global" ); 167 cfg.setGroup( "Global" );
168 int nCards = cfg.readNumEntry( "nCards", 0 ); 168 int nCards = cfg.readNumEntry( "nCards", 0 );
169 169
170 OPcmciaSystem* sys = OPcmciaSystem::instance(); 170 OPcmciaSystem* sys = OPcmciaSystem::instance();
171 OPcmciaSystem::CardIterator it = sys->iterator(); 171 OPcmciaSystem::CardIterator it = sys->iterator();
172 172
173 bool newCard = true; 173 bool newCard = true;
174 OPcmciaSocket* theCard = 0; 174 OPcmciaSocket* theCard = 0;
175 175
176 while ( it.current() && newCard ) 176 while ( it.current() && newCard )
177 { 177 {
178 if ( it.current()->isEmpty() ) 178 if ( it.current()->isEmpty() )
179 { 179 {
180 odebug << "skipping empty card in socket " << it.current()->number() << oendl; 180 odebug << "skipping empty card in socket " << it.current()->number() << oendl;
181 ++it; 181 ++it;
182 continue; 182 continue;
183 } 183 }
184 else 184 else
185 { 185 {
186 OPcmciaSocket* theCard = it.current(); 186 theCard = it.current();
187 QString cardName = theCard->identity(); 187 QString cardName = theCard->productIdentity().join( " " );
188 for ( int i = 0; i < nCards; ++i ) 188 for ( int i = 0; i < nCards; ++i )
189 { 189 {
190 QString cardSection = QString( "Card_%1" ).arg( i ); 190 QString cardSection = QString( "Card_%1" ).arg( i );
191 cfg.setGroup( cardSection ); 191 cfg.setGroup( cardSection );
192 QString name = cfg.readEntry( "name" ); 192 QString name = cfg.readEntry( "name" );
193 odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl; 193 odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
194 if ( cardName == name ) 194 if ( cardName == name )
195 { 195 {
196 newCard = false; 196 newCard = false;
197 break; 197 break;
198 } 198 }
199 } 199 }
200 if ( !newCard ) ++it; else break; 200 if ( !newCard ) ++it; else break;
201 } 201 }
202 } 202 }
203 if ( newCard ) 203 if ( newCard )
204 { 204 {
205 odebug << "pcmcia: new card detected" << oendl; 205 odebug << "pcmcia: new card detected" << oendl;
206 cfg.setGroup( QString( "Card_%1" ).arg( nCards ) ); 206 cfg.setGroup( QString( "Card_%1" ).arg( nCards ) );
207 cfg.writeEntry( "name", theCard->identity() ); 207 cfg.writeEntry( "name", theCard->productIdentity().join( " " ) );
208 cfg.writeEntry( "insert", "suspend" ); 208 cfg.writeEntry( "insert", "suspend" );
209 cfg.setGroup( "Global" ); 209 cfg.setGroup( "Global" );
210 cfg.writeEntry( "nCards", nCards+1 ); 210 cfg.writeEntry( "nCards", nCards+1 );
211 cfg.write(); 211 cfg.write();
212 212
213 int result = QMessageBox::information( qApp->desktop(), 213 int result = QMessageBox::information( qApp->desktop(),
214 tr( "PCMCIA/CF Subsystem" ), 214 tr( "PCMCIA/CF Subsystem" ),
215 tr( "You have inserted a new card:\n%1\nDo you want to configure?" ).arg( theCard->identity() ), 215 tr( "You have inserted a new card:\n%1\nDo you want to configure?" ).arg( theCard->productIdentity().join( " " ) ),
216 tr( "Yes" ), tr( "No" ), 0, 0, 1 ); 216 tr( "Yes" ), tr( "No" ), 0, 0, 1 );
217 odebug << "result = " << result << oendl; 217 odebug << "result = " << result << oendl;
218 if ( result == 0 ) 218 if ( result == 0 )
219 { 219 {
220 configure( theCard ); 220 configure( theCard );
221 } 221 }
222 else 222 else
223 { 223 {
224 odebug << "pcmcia: user doesn't want to configure " << theCard->identity() << " now." << oendl; 224 odebug << "pcmcia: user doesn't want to configure " << theCard->productIdentity().join( " " ) << " now." << oendl;
225 } 225 }
226 } 226 }
227 else 227 else
228 { 228 {
229 odebug << "pcmcia: card has been previously inserted" << oendl; 229 odebug << "pcmcia: card has been previously inserted" << oendl;
230 } 230 }
231 repaint( true ); 231 repaint( true );
232} 232}
233 233
234 234
235void PcmciaManager::paintEvent( QPaintEvent * ) 235void PcmciaManager::paintEvent( QPaintEvent * )
236{ 236{
237 QPainter p( this ); 237 QPainter p( this );
238 odebug << "sockets = " << OPcmciaSystem::instance()->count() << ", cards = " << OPcmciaSystem::instance()->cardCount() << oendl; 238 odebug << "sockets = " << OPcmciaSystem::instance()->count() << ", cards = " << OPcmciaSystem::instance()->cardCount() << oendl;
239 239
240 if ( OPcmciaSystem::instance()->cardCount() ) 240 if ( OPcmciaSystem::instance()->cardCount() )
241 { 241 {
242 p.drawPixmap( 0, 0, pm ); 242 p.drawPixmap( 0, 0, pm );
243 show(); 243 show();
244 } 244 }
245 else 245 else
246 { 246 {
247 hide(); 247 hide();
248 } 248 }
249} 249}
250 250
251int PcmciaManager::position() 251int PcmciaManager::position()
252{ 252{
253 return 7; 253 return 7;
254} 254}
255 255
256void PcmciaManager::execCommand( const QStringList &strList ) 256void PcmciaManager::execCommand( const QStringList &strList )
257{ 257{
258} 258}
259 259
260void PcmciaManager::userCardAction( int action ) 260void PcmciaManager::userCardAction( int action )
261{ 261{
262 odebug << "user action requested. action = " << action << oendl; 262 odebug << "user action requested. action = " << action << oendl;
263 263
264 int socket = action / 100; 264 int socket = action / 100;
265 int what = action % 100; 265 int what = action % 100;
266 bool success = false;
266 267
267 switch ( what ) 268 switch ( what )
268 { 269 {
269 case CONFIGURE: configure( OPcmciaSystem::instance()->socket( socket ) ); break; 270 case CONFIGURE: configure( OPcmciaSystem::instance()->socket( socket ) ); success = true; break;
270 default: odebug << "not yet implemented"; 271 case EJECT: success = OPcmciaSystem::instance()->socket( socket )->eject(); break;
272 case INSERT: success = OPcmciaSystem::instance()->socket( socket )->insert(); break;
273 case SUSPEND: success = OPcmciaSystem::instance()->socket( socket )->suspend(); break;
274 case RESUME: success = OPcmciaSystem::instance()->socket( socket )->resume(); break;
275 case RESET: success = OPcmciaSystem::instance()->socket( socket )->reset(); break;
276 default: odebug << "not yet implemented" << oendl;
271 } 277 }
278
279 if ( !success )
280 {
281 owarn << "couldn't perform user action" << oendl;
282 }
283
272} 284}
273 285
274void PcmciaManager::configure( OPcmciaSocket* card ) 286void PcmciaManager::configure( OPcmciaSocket* card )
275{ 287{
276 configuring = true; 288 configuring = true;
277 ConfigDialog dialog( card, qApp->desktop() ); 289 ConfigDialog dialog( card, qApp->desktop() );
278 int configresult = QPEApplication::execDialog( &dialog, false ); 290 int configresult = QPEApplication::execDialog( &dialog, false );
279 configuring = false; 291 configuring = false;
280 odebug << "pcmcia: configresult = " << configresult << oendl; 292 odebug << "pcmcia: configresult = " << configresult << oendl;
281} 293}
282 294
283 295
284EXPORT_OPIE_APPLET_v1( PcmciaManager ) 296EXPORT_OPIE_APPLET_v1( PcmciaManager )
285 297