summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-06-21 14:58:24 (UTC)
committer mickeyl <mickeyl>2005-06-21 14:58:24 (UTC)
commit6d4379546a9ae0ca397463820fe81126703f53c5 (patch) (unidiff)
tree4d729dfa5cfaa460a97ff2041fb189535956d3a1
parentae85d18a1f8a63323ad47631724516f3aa355a75 (diff)
downloadopie-6d4379546a9ae0ca397463820fe81126703f53c5.zip
opie-6d4379546a9ae0ca397463820fe81126703f53c5.tar.gz
opie-6d4379546a9ae0ca397463820fe81126703f53c5.tar.bz2
use own pixmap (s/cardmon/pcmcia/)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/pcmcia/pcmcia.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/applets/pcmcia/pcmcia.cpp b/noncore/applets/pcmcia/pcmcia.cpp
index 0787c3c..e435f61 100644
--- a/noncore/applets/pcmcia/pcmcia.cpp
+++ b/noncore/applets/pcmcia/pcmcia.cpp
@@ -1,271 +1,271 @@
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/global.h> 42#include <qpe/global.h>
43#include <qpe/resource.h> 43#include <qpe/resource.h>
44using namespace Opie::Core; 44using namespace Opie::Core;
45using namespace Opie::Ui; 45using namespace Opie::Ui;
46 46
47/* QT */ 47/* QT */
48#include <qcombobox.h> 48#include <qcombobox.h>
49#include <qcopchannel_qws.h> 49#include <qcopchannel_qws.h>
50#include <qpainter.h> 50#include <qpainter.h>
51#include <qfile.h> 51#include <qfile.h>
52#include <qtextstream.h> 52#include <qtextstream.h>
53#include <qmessagebox.h> 53#include <qmessagebox.h>
54#include <qsound.h> 54#include <qsound.h>
55#include <qtimer.h> 55#include <qtimer.h>
56 56
57/* STD */ 57/* STD */
58#include <stdio.h> 58#include <stdio.h>
59#include <unistd.h> 59#include <unistd.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include <string.h> 61#include <string.h>
62#include <errno.h> 62#include <errno.h>
63#include <fcntl.h> 63#include <fcntl.h>
64#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 64#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
65#include <sys/vfs.h> 65#include <sys/vfs.h>
66#include <mntent.h> 66#include <mntent.h>
67#endif 67#endif
68 68
69PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ) 69PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent )
70{ 70{
71 QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); 71 QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this );
72 connect( pcmciaChannel, 72 connect( pcmciaChannel,
73 SIGNAL( received(const QCString&,const QByteArray&) ), this, 73 SIGNAL( received(const QCString&,const QByteArray&) ), this,
74 SLOT( cardMessage(const QCString&,const QByteArray&) ) ); 74 SLOT( cardMessage(const QCString&,const QByteArray&) ) );
75 75
76 setFocusPolicy( NoFocus ); 76 setFocusPolicy( NoFocus );
77 setFixedWidth ( AppLnk::smallIconSize() ); 77 setFixedWidth ( AppLnk::smallIconSize() );
78 setFixedHeight ( AppLnk::smallIconSize() ); 78 setFixedHeight ( AppLnk::smallIconSize() );
79 pm = Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon ); 79 pm = Opie::Core::OResource::loadPixmap( "pcmcia/pcmcia", Opie::Core::OResource::SmallIcon );
80 configuring = false; 80 configuring = false;
81 81
82 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 82 QCopChannel *channel = new QCopChannel( "QPE/System", this );
83 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), 83 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
84 this, SLOT(handleSystemChannel(const QCString&,const QByteArray&)) ); 84 this, SLOT(handleSystemChannel(const QCString&,const QByteArray&)) );
85} 85}
86 86
87 87
88PcmciaManager::~PcmciaManager() 88PcmciaManager::~PcmciaManager()
89{ 89{
90} 90}
91 91
92void PcmciaManager::handleSystemChannel( const QCString&msg, const QByteArray& ) 92void PcmciaManager::handleSystemChannel( const QCString&msg, const QByteArray& )
93{ 93{
94 if ( msg == "returnFromSuspend()" ) 94 if ( msg == "returnFromSuspend()" )
95 { 95 {
96 if ( !OPcmciaSystem::instance()->cardCount() ) return; 96 if ( !OPcmciaSystem::instance()->cardCount() ) return;
97 OPcmciaSystem* sys = OPcmciaSystem::instance(); 97 OPcmciaSystem* sys = OPcmciaSystem::instance();
98 OPcmciaSystem::CardIterator it = sys->iterator(); 98 OPcmciaSystem::CardIterator it = sys->iterator();
99 OPcmciaSocket* theCard = 0; 99 OPcmciaSocket* theCard = 0;
100 100
101 while ( it.current() ) 101 while ( it.current() )
102 { 102 {
103 if ( it.current()->isEmpty() ) 103 if ( it.current()->isEmpty() )
104 { 104 {
105 executeResumeAction( theCard ); 105 executeResumeAction( theCard );
106 } 106 }
107 ++it; 107 ++it;
108 } 108 }
109 } 109 }
110} 110}
111 111
112void PcmciaManager::popUp( QString message, QString icon ) 112void PcmciaManager::popUp( QString message, QString icon )
113{ 113{
114 if ( !popupMenu ) { 114 if ( !popupMenu ) {
115 popupMenu = new QPopupMenu( this ); 115 popupMenu = new QPopupMenu( this );
116 } 116 }
117 117
118 popupMenu->clear(); 118 popupMenu->clear();
119 if ( icon.isEmpty() ) { 119 if ( icon.isEmpty() ) {
120 popupMenu->insertItem( message, 0 ); 120 popupMenu->insertItem( message, 0 );
121 } else { 121 } else {
122 popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ), 122 popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ),
123 message, 0 ); 123 message, 0 );
124 } 124 }
125 125
126 QPoint p = mapToGlobal( QPoint( 0, 0 ) ); 126 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
127 QSize s = popupMenu->sizeHint(); 127 QSize s = popupMenu->sizeHint();
128 popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), 128 popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ),
129 p.y() - s.height() ), 0 ); 129 p.y() - s.height() ), 0 );
130 130
131 QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); 131 QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) );
132} 132}
133 133
134 134
135void PcmciaManager::popupTimeout() 135void PcmciaManager::popupTimeout()
136{ 136{
137 popupMenu->hide(); 137 popupMenu->hide();
138} 138}
139 139
140enum { EJECT, INSERT, SUSPEND, RESUME, RESET, CONFIGURE }; 140enum { EJECT, INSERT, SUSPEND, RESUME, RESET, CONFIGURE };
141 141
142void PcmciaManager::mousePressEvent( QMouseEvent* ) 142void PcmciaManager::mousePressEvent( QMouseEvent* )
143{ 143{
144 QPopupMenu* menu = new QPopupMenu( this ); 144 QPopupMenu* menu = new QPopupMenu( this );
145 QStringList cmd; 145 QStringList cmd;
146 bool execute = true; 146 bool execute = true;
147 147
148 OPcmciaSystem* sys = OPcmciaSystem::instance(); 148 OPcmciaSystem* sys = OPcmciaSystem::instance();
149 OPcmciaSystem::CardIterator it = sys->iterator(); 149 OPcmciaSystem::CardIterator it = sys->iterator();
150 if ( !sys->count() ) return; 150 if ( !sys->count() ) return;
151 151
152 int i = 0; 152 int i = 0;
153 while ( it.current() ) 153 while ( it.current() )
154 { 154 {
155 QPopupMenu* submenu = new QPopupMenu( menu ); 155 QPopupMenu* submenu = new QPopupMenu( menu );
156 submenu->insertItem( "&Eject", EJECT+i*100 ); 156 submenu->insertItem( "&Eject", EJECT+i*100 );
157 submenu->insertItem( "&Insert", INSERT+i*100 ); 157 submenu->insertItem( "&Insert", INSERT+i*100 );
158 submenu->insertItem( "&Suspend", SUSPEND+i*100 ); 158 submenu->insertItem( "&Suspend", SUSPEND+i*100 );
159 submenu->insertItem( "&Resume", RESUME+i*100 ); 159 submenu->insertItem( "&Resume", RESUME+i*100 );
160 submenu->insertItem( "Rese&t", RESET+i*100 ); 160 submenu->insertItem( "Rese&t", RESET+i*100 );
161 submenu->insertItem( "&Configure", CONFIGURE+i*100 ); 161 submenu->insertItem( "&Configure", CONFIGURE+i*100 );
162 162
163 submenu->setItemEnabled( EJECT+i*100, !it.current()->isEmpty() ); 163 submenu->setItemEnabled( EJECT+i*100, !it.current()->isEmpty() );
164 submenu->setItemEnabled( INSERT+i*100, it.current()->isEmpty() ); 164 submenu->setItemEnabled( INSERT+i*100, it.current()->isEmpty() );
165 submenu->setItemEnabled( SUSPEND+i*100, !it.current()->isEmpty() && it.current()->isSuspended() ); 165 submenu->setItemEnabled( SUSPEND+i*100, !it.current()->isEmpty() && it.current()->isSuspended() );
166 submenu->setItemEnabled( RESUME+i*100, !it.current()->isEmpty() && !it.current()->isSuspended() ); 166 submenu->setItemEnabled( RESUME+i*100, !it.current()->isEmpty() && !it.current()->isSuspended() );
167 submenu->setItemEnabled( CONFIGURE+i*100, !it.current()->isEmpty() && !configuring ); 167 submenu->setItemEnabled( CONFIGURE+i*100, !it.current()->isEmpty() && !configuring );
168 168
169 connect( submenu, SIGNAL(activated(int)), this, SLOT(userCardAction(int)) ); 169 connect( submenu, SIGNAL(activated(int)), this, SLOT(userCardAction(int)) );
170 menu->insertItem( tr( "%1: %2" ).arg( i++ ).arg( it.current()->identity() ), submenu, 1 ); 170 menu->insertItem( tr( "%1: %2" ).arg( i++ ).arg( it.current()->identity() ), submenu, 1 );
171 ++it; 171 ++it;
172 } 172 }
173 173
174 QPoint p = mapToGlobal( QPoint( 0, 0 ) ); 174 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
175 QSize s = menu->sizeHint(); 175 QSize s = menu->sizeHint();
176 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 ); 176 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 );
177 qDebug( "pcmcia: menu result = %d", opt ); 177 qDebug( "pcmcia: menu result = %d", opt );
178 delete menu; 178 delete menu;
179} 179}
180 180
181 181
182void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) 182void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
183{ 183{
184 odebug << "PcmciaManager::cardMessage( '" << msg << "' )" << oendl; 184 odebug << "PcmciaManager::cardMessage( '" << msg << "' )" << oendl;
185 if ( msg != "stabChanged()" ) return; 185 if ( msg != "stabChanged()" ) return;
186 186
187 /* check if a previously unknown card has been inserted */ 187 /* check if a previously unknown card has been inserted */
188 OPcmciaSystem::instance()->synchronize(); 188 OPcmciaSystem::instance()->synchronize();
189 189
190 if ( !OPcmciaSystem::instance()->cardCount() ) return; 190 if ( !OPcmciaSystem::instance()->cardCount() ) return;
191 191
192 OConfig cfg( "PCMCIA" ); 192 OConfig cfg( "PCMCIA" );
193 cfg.setGroup( "Global" ); 193 cfg.setGroup( "Global" );
194 int nCards = cfg.readNumEntry( "nCards", 0 ); 194 int nCards = cfg.readNumEntry( "nCards", 0 );
195 195
196 OPcmciaSystem* sys = OPcmciaSystem::instance(); 196 OPcmciaSystem* sys = OPcmciaSystem::instance();
197 OPcmciaSystem::CardIterator it = sys->iterator(); 197 OPcmciaSystem::CardIterator it = sys->iterator();
198 198
199 bool newCard = true; 199 bool newCard = true;
200 OPcmciaSocket* theCard = 0; 200 OPcmciaSocket* theCard = 0;
201 201
202 while ( it.current() && newCard ) 202 while ( it.current() && newCard )
203 { 203 {
204 if ( it.current()->isEmpty() ) 204 if ( it.current()->isEmpty() )
205 { 205 {
206 odebug << "pcmcia: skipping empty card in socket " << it.current()->number() << oendl; 206 odebug << "pcmcia: skipping empty card in socket " << it.current()->number() << oendl;
207 ++it; 207 ++it;
208 continue; 208 continue;
209 } 209 }
210 else 210 else
211 { 211 {
212 theCard = it.current(); 212 theCard = it.current();
213 QString cardName = theCard->productIdentity().join( " " ); 213 QString cardName = theCard->productIdentity().join( " " );
214 for ( int i = 0; i < nCards; ++i ) 214 for ( int i = 0; i < nCards; ++i )
215 { 215 {
216 QString cardSection = QString( "Card_%1" ).arg( i ); 216 QString cardSection = QString( "Card_%1" ).arg( i );
217 cfg.setGroup( cardSection ); 217 cfg.setGroup( cardSection );
218 QString name = cfg.readEntry( "name" ); 218 QString name = cfg.readEntry( "name" );
219 odebug << "pcmcia: comparing card '" << cardName << "' with known card '" << name << "'" << oendl; 219 odebug << "pcmcia: comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
220 if ( cardName == name ) 220 if ( cardName == name )
221 { 221 {
222 newCard = false; 222 newCard = false;
223 odebug << "pcmcia: we have seen this card before" << oendl; 223 odebug << "pcmcia: we have seen this card before" << oendl;
224 executeInsertAction( theCard ); 224 executeInsertAction( theCard );
225 break; 225 break;
226 } 226 }
227 } 227 }
228 if ( !newCard ) ++it; else break; 228 if ( !newCard ) ++it; else break;
229 } 229 }
230 } 230 }
231 if ( newCard ) 231 if ( newCard )
232 { 232 {
233 odebug << "pcmcia: unconfigured card detected" << oendl; 233 odebug << "pcmcia: unconfigured card detected" << oendl;
234 QString newCardName = theCard->productIdentity().join( " " ).stripWhiteSpace(); 234 QString newCardName = theCard->productIdentity().join( " " ).stripWhiteSpace();
235 int result = QMessageBox::information( qApp->desktop(), 235 int result = QMessageBox::information( qApp->desktop(),
236 tr( "PCMCIA/CF Subsystem" ), 236 tr( "PCMCIA/CF Subsystem" ),
237 tr( "<qt>You have inserted the card<br/><b>%1</b><br/>This card is not yet configured. Do you want to configure it now?</qt>" ).arg( newCardName ), 237 tr( "<qt>You have inserted the card<br/><b>%1</b><br/>This card is not yet configured. Do you want to configure it now?</qt>" ).arg( newCardName ),
238 tr( "Yes" ), tr( "No" ), 0, 0, 1 ); 238 tr( "Yes" ), tr( "No" ), 0, 0, 1 );
239 odebug << "pcmcia: result = " << result << oendl; 239 odebug << "pcmcia: result = " << result << oendl;
240 if ( result == 0 ) 240 if ( result == 0 )
241 { 241 {
242 QString insertAction; QString resumeAction; QString driver; QString conf; 242 QString insertAction; QString resumeAction; QString driver; QString conf;
243 bool configured = configure( theCard, insertAction, resumeAction, driver, conf ); 243 bool configured = configure( theCard, insertAction, resumeAction, driver, conf );
244 244
245 if ( configured ) 245 if ( configured )
246 { 246 {
247 odebug << "pcmcia: card has been configured. writing out to database" << oendl; 247 odebug << "pcmcia: card has been configured. writing out to database" << oendl;
248 cfg.setGroup( QString( "Card_%1" ).arg( nCards ) ); 248 cfg.setGroup( QString( "Card_%1" ).arg( nCards ) );
249 cfg.writeEntry( "name", newCardName ); 249 cfg.writeEntry( "name", newCardName );
250 cfg.writeEntry( "insertAction", insertAction ); 250 cfg.writeEntry( "insertAction", insertAction );
251 cfg.writeEntry( "resumeAction", resumeAction ); 251 cfg.writeEntry( "resumeAction", resumeAction );
252 cfg.setGroup( "Global" ); 252 cfg.setGroup( "Global" );
253 cfg.writeEntry( "nCards", nCards+1 ); 253 cfg.writeEntry( "nCards", nCards+1 );
254 cfg.write(); 254 cfg.write();
255 255
256 QFile confFile( QString( "/etc/pcmcia/%1" ).arg( conf ) ); 256 QFile confFile( QString( "/etc/pcmcia/%1" ).arg( conf ) );
257 if ( confFile.open( IO_ReadWrite | IO_Append ) ) 257 if ( confFile.open( IO_ReadWrite | IO_Append ) )
258 { 258 {
259 QString entryCard = QString( "card \"%1\"" ).arg( newCardName ); 259 QString entryCard = QString( "card \"%1\"" ).arg( newCardName );
260 QString entryVersion( " version " ); 260 QString entryVersion( " version " );
261 for ( QStringList::Iterator it = theCard->productIdentity().begin(); it != theCard->productIdentity().end(); ++it ) 261 for ( QStringList::Iterator it = theCard->productIdentity().begin(); it != theCard->productIdentity().end(); ++it )
262 { 262 {
263 entryVersion += QString( "\"%1\", " ).arg( *it ); 263 entryVersion += QString( "\"%1\", " ).arg( *it );
264 } 264 }
265 QString entryBind = QString( " bind %1" ).arg( driver ); 265 QString entryBind = QString( " bind %1" ).arg( driver );
266 QString entry = QString( "\n%1\n%2\n%3\n" ).arg( entryCard ).arg( entryVersion ).arg( entryBind ); 266 QString entry = QString( "\n%1\n%2\n%3\n" ).arg( entryCard ).arg( entryVersion ).arg( entryBind );
267 odebug << "pcmcia: writing entry...:" << entry << oendl; 267 odebug << "pcmcia: writing entry...:" << entry << oendl;
268 268
269 confFile.writeBlock( (const char*) entry, entry.length() ); 269 confFile.writeBlock( (const char*) entry, entry.length() );
270 Global::statusMessage( "restarting pcmcia services..." ); 270 Global::statusMessage( "restarting pcmcia services..." );
271 ::system( "/etc/init.d/pcmcia restart" ); 271 ::system( "/etc/init.d/pcmcia restart" );