summaryrefslogtreecommitdiff
path: root/noncore/applets/pcmcia/pcmcia.cpp
Unidiff
Diffstat (limited to 'noncore/applets/pcmcia/pcmcia.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/pcmcia/pcmcia.cpp92
1 files changed, 48 insertions, 44 deletions
diff --git a/noncore/applets/pcmcia/pcmcia.cpp b/noncore/applets/pcmcia/pcmcia.cpp
index a1deb6b..4fcc189 100644
--- a/noncore/applets/pcmcia/pcmcia.cpp
+++ b/noncore/applets/pcmcia/pcmcia.cpp
@@ -25,12 +25,13 @@
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 32
32/* OPIE */ 33/* OPIE */
33#include <opie2/odebug.h> 34#include <opie2/odebug.h>
34#include <opie2/odevice.h> 35#include <opie2/odevice.h>
35#include <opie2/oconfig.h> 36#include <opie2/oconfig.h>
36#include <opie2/oprocess.h> 37#include <opie2/oprocess.h>
@@ -106,12 +107,13 @@ void PcmciaManager::popUp( QString message, QString icon )
106 107
107void PcmciaManager::popupTimeout() 108void PcmciaManager::popupTimeout()
108{ 109{
109 popupMenu->hide(); 110 popupMenu->hide();
110} 111}
111 112
113enum { EJECT, INSERT, SUSPEND, RESUME, CONFIGURE };
112 114
113void PcmciaManager::mousePressEvent( QMouseEvent* ) 115void PcmciaManager::mousePressEvent( QMouseEvent* )
114{ 116{
115 QPopupMenu* menu = new QPopupMenu( this ); 117 QPopupMenu* menu = new QPopupMenu( this );
116 QStringList cmd; 118 QStringList cmd;
117 bool execute = true; 119 bool execute = true;
@@ -120,50 +122,30 @@ void PcmciaManager::mousePressEvent( QMouseEvent* )
120 OPcmciaSystem::CardIterator it = sys->iterator(); 122 OPcmciaSystem::CardIterator it = sys->iterator();
121 if ( !sys->count() ) return; 123 if ( !sys->count() ) return;
122 124
123 int i = 0; 125 int i = 0;
124 while ( it.current() ) 126 while ( it.current() )
125 { 127 {
126
127 QPopupMenu* submenu = new QPopupMenu( menu ); 128 QPopupMenu* submenu = new QPopupMenu( menu );
128 submenu->insertItem( "Eject" ); 129 submenu->insertItem( "&Eject", EJECT+i*100 );
129 submenu->insertItem( "Insert" ); 130 submenu->insertItem( "&Insert", INSERT+i*100 );
130 submenu->insertItem( "Suspend" ); 131 submenu->insertItem( "&Suspend", SUSPEND+i*100 );
131 submenu->insertItem( "Resume" ); 132 submenu->insertItem( "&Resume", RESUME+i*100 );
132 submenu->insertItem( "Configure" ); 133 submenu->insertItem( "&Configure", CONFIGURE+i*100 );
133 134
135 submenu->setItemEnabled( EJECT+i*100, !it.current()->isEmpty() );
136 submenu->setItemEnabled( INSERT+i*100, it.current()->isEmpty() );
137 submenu->setItemEnabled( SUSPEND+i*100, !it.current()->isEmpty() && !it.current()->isSuspended() );
138 submenu->setItemEnabled( RESUME+i*100, !it.current()->isEmpty() && it.current()->isSuspended() );
139 submenu->setItemEnabled( CONFIGURE+i*100, !it.current()->isEmpty() );
140
141 connect( submenu, SIGNAL(activated(int)), this, SLOT(userCardAction(int)) );
134 menu->insertItem( tr( "%1: %2" ).arg( i++ ).arg( it.current()->identity() ), submenu, 1 ); 142 menu->insertItem( tr( "%1: %2" ).arg( i++ ).arg( it.current()->identity() ), submenu, 1 );
135 ++it; 143 ++it;
136 } 144 }
137 145
138
139
140 /* insert items depending on number of cards etc.
141
142 if ( cardInSd ) {
143 menu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( "cardmon/ide", Opie::Core::OResource::SmallIcon ) ),
144 tr( "Eject SD/MMC card" ), 0 );
145 }
146
147
148
149 if ( cardInPcmcia0 ) {
150 menu->
151 insertItem( QIconSet
152 ( Opie::Core::OResource::loadPixmap( "cardmon/" + cardInPcmcia0Type, Opie::Core::OResource::SmallIcon ) ),
153 tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 );
154 }
155
156 if ( cardInPcmcia1 ) {
157 menu->
158 insertItem( QIconSet
159 ( Opie::Core::OResource::loadPixmap( "cardmon/" + cardInPcmcia1Type, Opie::Core::OResource::SmallIcon ) ),
160 tr( "Eject card 1: %1" ).arg( cardInPcmcia1Name ), 2 );
161 }
162 */
163
164 QPoint p = mapToGlobal( QPoint( 0, 0 ) ); 146 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
165 QSize s = menu->sizeHint(); 147 QSize s = menu->sizeHint();
166 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 ); 148 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 );
167 qDebug( "pcmcia: menu result = %d", opt ); 149 qDebug( "pcmcia: menu result = %d", opt );
168 delete menu; 150 delete menu;
169} 151}
@@ -184,25 +166,26 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
184 int nCards = cfg.readNumEntry( "nCards", 0 ); 166 int nCards = cfg.readNumEntry( "nCards", 0 );
185 167
186 OPcmciaSystem* sys = OPcmciaSystem::instance(); 168 OPcmciaSystem* sys = OPcmciaSystem::instance();
187 OPcmciaSystem::CardIterator it = sys->iterator(); 169 OPcmciaSystem::CardIterator it = sys->iterator();
188 170
189 bool newCard = true; 171 bool newCard = true;
190 QString cardName; 172 OPcmciaSocket* theCard = 0;
191 173
192 while ( it.current() && newCard ) 174 while ( it.current() && newCard )
193 { 175 {
194 if ( it.current()->isEmpty() ) 176 if ( it.current()->isEmpty() )
195 { 177 {
196 odebug << "skipping empty card in socket " << it.current()->number() << oendl; 178 odebug << "skipping empty card in socket " << it.current()->number() << oendl;
197 ++it; 179 ++it;
198 continue; 180 continue;
199 } 181 }
200 else 182 else
201 { 183 {
202 cardName = it.current()->identity(); 184 OPcmciaSocket* theCard = it.current();
185 QString cardName = theCard->identity();
203 for ( int i = 0; i < nCards; ++i ) 186 for ( int i = 0; i < nCards; ++i )
204 { 187 {
205 QString cardSection = QString( "Card_%1" ).arg( i ); 188 QString cardSection = QString( "Card_%1" ).arg( i );
206 cfg.setGroup( cardSection ); 189 cfg.setGroup( cardSection );
207 QString name = cfg.readEntry( "name" ); 190 QString name = cfg.readEntry( "name" );
208 odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl; 191 odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
@@ -216,32 +199,30 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
216 } 199 }
217 } 200 }
218 if ( newCard ) 201 if ( newCard )
219 { 202 {
220 odebug << "pcmcia: new card detected" << oendl; 203 odebug << "pcmcia: new card detected" << oendl;
221 cfg.setGroup( QString( "Card_%1" ).arg( nCards ) ); 204 cfg.setGroup( QString( "Card_%1" ).arg( nCards ) );
222 cfg.writeEntry( "name", cardName ); 205 cfg.writeEntry( "name", theCard->identity() );
206 cfg.writeEntry( "insert", "suspend" );
223 cfg.setGroup( "Global" ); 207 cfg.setGroup( "Global" );
224 cfg.writeEntry( "nCards", nCards+1 ); 208 cfg.writeEntry( "nCards", nCards+1 );
225 cfg.write(); 209 cfg.write();
226 210
227 int result = QMessageBox::information( qApp->desktop(), 211 int result = QMessageBox::information( qApp->desktop(),
228 tr( "PCMCIA/CF Subsystem" ), 212 tr( "PCMCIA/CF Subsystem" ),
229 tr( "You have inserted a new card:\n%1\nDo you want to configure?" ).arg( cardName ), 213 tr( "You have inserted a new card:\n%1\nDo you want to configure?" ).arg( theCard->identity() ),
230 tr( "Yes" ), tr( "No" ), 0, 0, 1 ); 214 tr( "Yes" ), tr( "No" ), 0, 0, 1 );
231 odebug << "result = " << result << oendl; 215 odebug << "result = " << result << oendl;
232 if ( result == 0 ) 216 if ( result == 0 )
233 { 217 {
234 QMessageBox::information( qApp->desktop(), 218 configure( theCard );
235 tr( "PCMCIA/CF Subsystem" ),
236 tr( "Sorry, not yet implemented...\n~lart mickeyl :D" ),
237 tr( "No Problem" ), 0, 0, 0 );
238 } 219 }
239 else 220 else
240 { 221 {
241 odebug << "pcmcia: user doesn't want to configure " << cardName << " now." << oendl; 222 odebug << "pcmcia: user doesn't want to configure " << theCard->identity() << " now." << oendl;
242 } 223 }
243 } 224 }
244 else 225 else
245 { 226 {
246 odebug << "pcmcia: card has been previously inserted" << oendl; 227 odebug << "pcmcia: card has been previously inserted" << oendl;
247 } 228 }
@@ -249,14 +230,15 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
249} 230}
250 231
251 232
252void PcmciaManager::paintEvent( QPaintEvent * ) 233void PcmciaManager::paintEvent( QPaintEvent * )
253{ 234{
254 QPainter p( this ); 235 QPainter p( this );
255 qDebug( "count = %d", (OPcmciaSystem::instance()->count() ) ); 236 odebug << "sockets = " << OPcmciaSystem::instance()->count() << ", cards = " << OPcmciaSystem::instance()->cardCount() << oendl;
256 if ( OPcmciaSystem::instance()->count() ) 237
238 if ( OPcmciaSystem::instance()->cardCount() )
257 { 239 {
258 p.drawPixmap( 0, 0, pm ); 240 p.drawPixmap( 0, 0, pm );
259 show(); 241 show();
260 } 242 }
261 else 243 else
262 { 244 {
@@ -270,8 +252,30 @@ int PcmciaManager::position()
270} 252}
271 253
272void PcmciaManager::execCommand( const QStringList &strList ) 254void PcmciaManager::execCommand( const QStringList &strList )
273{ 255{
274} 256}
275 257
258void PcmciaManager::userCardAction( int action )
259{
260 odebug << "user action requested. action = " << action << oendl;
261
262 int socket = action / 100;
263 int what = action % 100;
264
265 switch ( what )
266 {
267 case CONFIGURE: configure( OPcmciaSystem::instance()->socket( socket ) ); break;
268 default: odebug << "not yet implemented";
269 }
270}
271
272void PcmciaManager::configure( OPcmciaSocket* card )
273{
274 ConfigDialog dialog( card->identity(), qApp->desktop() );
275 int configresult = dialog.exec();
276 odebug << "pcmcia: configresult = " << configresult << oendl;
277}
278
279
276EXPORT_OPIE_APPLET_v1( PcmciaManager ) 280EXPORT_OPIE_APPLET_v1( PcmciaManager )
277 281