summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/pcmcia/configdialog.cpp10
-rw-r--r--noncore/applets/pcmcia/pcmcia.cpp22
2 files changed, 18 insertions, 14 deletions
diff --git a/noncore/applets/pcmcia/configdialog.cpp b/noncore/applets/pcmcia/configdialog.cpp
index f94edde..3b1b40c 100644
--- a/noncore/applets/pcmcia/configdialog.cpp
+++ b/noncore/applets/pcmcia/configdialog.cpp
@@ -1,179 +1,179 @@
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 "configdialog.h" 30#include "configdialog.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/oconfig.h> 33#include <opie2/oconfig.h>
34#include <opie2/odebug.h> 34#include <opie2/odebug.h>
35#include <opie2/opcmciasystem.h> 35#include <opie2/opcmciasystem.h>
36using namespace Opie::Core; 36using namespace Opie::Core;
37 37
38/* QT */ 38/* QT */
39#include <qcombobox.h> 39#include <qcombobox.h>
40#include <qdir.h> 40#include <qdir.h>
41#include <qfile.h> 41#include <qfile.h>
42#include <qgroupbox.h> 42#include <qgroupbox.h>
43#include <qlabel.h> 43#include <qlabel.h>
44#include <qtextstream.h> 44#include <qtextstream.h>
45 45
46ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent ) 46ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent )
47 :ConfigDialogBase( parent, "pcmcia config dialog", true ) 47 :ConfigDialogBase( parent, "pcmcia config dialog", true )
48{ 48{
49 gbDetails->setTitle( QString( "Details for card in socket #%1" ).arg( card->number() ) ); 49 gbDetails->setTitle( QString( "Details for card in socket #%1" ).arg( card->number() ) );
50 txtCardName->setText( card->productIdentity().join( " " ) ); 50 txtCardName->setText( card->productIdentity() );
51 txtManfid->setText( card->manufacturerIdentity() ); 51 txtManfid->setText( card->manufacturerIdentity() );
52 txtFunction->setText( card->function() ); 52 txtFunction->setText( card->function() );
53 53
54 QString insertAction = preferredAction( card, "insert" ); 54 QString insertAction = preferredAction( card, "insert" );
55 QString resumeAction = preferredAction( card, "resume" ); 55 QString resumeAction = preferredAction( card, "resume" );
56 56
57 odebug << "pcmcia: preferred insertion action for card '" << card->name() << "' seems to be '" << insertAction << "'" << oendl; 57 odebug << "pcmcia: preferred insertion action for card '" << card->productIdentity() << "' seems to be '" << insertAction << "'" << oendl;
58 odebug << "pcmcia: preferred resume action for card '" << card->name() << "' seems to be '" << resumeAction << "'" << oendl; 58 odebug << "pcmcia: preferred resume action for card '" << card->productIdentity() << "' seems to be '" << resumeAction << "'" << oendl;
59 59
60 if ( !insertAction.isEmpty() ) 60 if ( !insertAction.isEmpty() )
61 { 61 {
62 for ( int i; i < cbInsertAction->count(); ++i ) 62 for ( int i; i < cbInsertAction->count(); ++i )
63 if ( cbInsertAction->text( i ) == insertAction ) cbInsertAction->setCurrentItem( i ); 63 if ( cbInsertAction->text( i ) == insertAction ) cbInsertAction->setCurrentItem( i );
64 } 64 }
65 65
66 if ( !resumeAction.isEmpty() ) 66 if ( !resumeAction.isEmpty() )
67 { 67 {
68 for ( int i; i < cbResumeAction->count(); ++i ) 68 for ( int i; i < cbResumeAction->count(); ++i )
69 if ( cbResumeAction->text( i ) == resumeAction ) cbResumeAction->setCurrentItem( i ); 69 if ( cbResumeAction->text( i ) == resumeAction ) cbResumeAction->setCurrentItem( i );
70 } 70 }
71 71
72 if ( !card->isUnsupported() ) 72 if ( !card->isUnsupported() )
73 { 73 {
74 odebug << "pcmcia: card is recognized - hiding bindings" << oendl; 74 odebug << "pcmcia: card is recognized - hiding bindings" << oendl;
75 textInfo->hide(); 75 textInfo->hide();
76 textBindTo->hide(); 76 textBindTo->hide();
77 cbBindTo->hide(); 77 cbBindTo->hide();
78 return; 78 return;
79 } 79 }
80 else 80 else
81 { 81 {
82 odebug << "card is unsupported yet - showing possible bindings" << oendl; 82 odebug << "card is unsupported yet - showing possible bindings" << oendl;
83 textInfo->show(); 83 textInfo->show();
84 textBindTo->show(); 84 textBindTo->show();
85 cbBindTo->show(); 85 cbBindTo->show();
86 } 86 }
87 87
88 // parse possible bind entries out of /etc/pcmcia/*.conf 88 // parse possible bind entries out of /etc/pcmcia/*.conf
89 QDir pcmciaconfdir( "/etc/pcmcia", "*.conf" ); 89 QDir pcmciaconfdir( "/etc/pcmcia", "*.conf" );
90 90
91 for ( unsigned int i = 0; i < pcmciaconfdir.count(); ++i ) 91 for ( unsigned int i = 0; i < pcmciaconfdir.count(); ++i )
92 { 92 {
93 odebug << "processing conf file '" << pcmciaconfdir[i] << "'" << oendl; 93 odebug << "processing conf file '" << pcmciaconfdir[i] << "'" << oendl;
94 QString conffilename = QString( "%1/%2" ).arg( pcmciaconfdir.absPath() ).arg( pcmciaconfdir[i] ); 94 QString conffilename = QString( "%1/%2" ).arg( pcmciaconfdir.absPath() ).arg( pcmciaconfdir[i] );
95 QFile conffile( conffilename ); 95 QFile conffile( conffilename );
96 if ( conffile.open( IO_ReadOnly ) ) 96 if ( conffile.open( IO_ReadOnly ) )
97 { 97 {
98 QTextStream ts( &conffile ); 98 QTextStream ts( &conffile );
99 while ( !ts.atEnd() ) 99 while ( !ts.atEnd() )
100 { 100 {
101 QString word; 101 QString word;
102 ts >> word; 102 ts >> word;
103 if ( word == "bind" ) 103 if ( word == "bind" )
104 { 104 {
105 word = ts.readLine(); 105 word = ts.readLine();
106 bindEntries[ word.stripWhiteSpace() ] = conffilename; 106 bindEntries[ word.stripWhiteSpace() ] = conffilename;
107 continue; 107 continue;
108 } 108 }
109 ts.readLine(); 109 ts.readLine();
110 } 110 }
111 } 111 }
112 else 112 else
113 { 113 {
114 owarn << "couldn't open '" << conffile.name() << "' for reading" << oendl; 114 owarn << "couldn't open '" << conffile.name() << "' for reading" << oendl;
115 continue; 115 continue;
116 } 116 }
117 } 117 }
118 118
119 for ( StringMap::Iterator it = bindEntries.begin(); it != bindEntries.end(); ++it ) 119 for ( StringMap::Iterator it = bindEntries.begin(); it != bindEntries.end(); ++it )
120 { 120 {
121 odebug << "found binding '" << it.key() << "' defined in '" << it.data().latin1() << "'" << oendl; 121 odebug << "found binding '" << it.key() << "' defined in '" << it.data().latin1() << "'" << oendl;
122 cbBindTo->insertItem( it.key() ); 122 cbBindTo->insertItem( it.key() );
123 } 123 }
124} 124}
125 125
126ConfigDialog::~ConfigDialog() 126ConfigDialog::~ConfigDialog()
127{ 127{
128} 128}
129 129
130void ConfigDialog::writeConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& value ) 130void ConfigDialog::writeConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& value )
131{ 131{
132 OConfig cfg( "PCMCIA" ); 132 OConfig cfg( "PCMCIA" );
133 cfg.setGroup( "Global" ); 133 cfg.setGroup( "Global" );
134 int nCards = cfg.readNumEntry( "nCards", 0 ); 134 int nCards = cfg.readNumEntry( "nCards", 0 );
135 QString cardName = card->productIdentity().join( " " ).stripWhiteSpace(); 135 QString cardName = card->productIdentity();
136 QString action; 136 QString action;
137 137
138 for ( int i = 0; i < nCards; ++i ) 138 for ( int i = 0; i < nCards; ++i )
139 { 139 {
140 QString cardSection = QString( "Card_%1" ).arg( i ); 140 QString cardSection = QString( "Card_%1" ).arg( i );
141 cfg.setGroup( cardSection ); 141 cfg.setGroup( cardSection );
142 QString name = cfg.readEntry( "name" ); 142 QString name = cfg.readEntry( "name" );
143 odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl; 143 odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
144 if ( cardName == name ) 144 if ( cardName == name )
145 { 145 {
146 cfg.writeEntry( key, value ); 146 cfg.writeEntry( key, value );
147 break; 147 break;
148 } 148 }
149 } 149 }
150} 150}
151 151
152QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& defaultValue ) 152QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& defaultValue )
153{ 153{
154 OConfig cfg( "PCMCIA" ); 154 OConfig cfg( "PCMCIA" );
155 cfg.setGroup( "Global" ); 155 cfg.setGroup( "Global" );
156 int nCards = cfg.readNumEntry( "nCards", 0 ); 156 int nCards = cfg.readNumEntry( "nCards", 0 );
157 QString cardName = card->productIdentity().join( " " ).stripWhiteSpace(); 157 QString cardName = card->productIdentity();
158 QString value; 158 QString value;
159 159
160 for ( int i = 0; i < nCards; ++i ) 160 for ( int i = 0; i < nCards; ++i )
161 { 161 {
162 QString cardSection = QString( "Card_%1" ).arg( i ); 162 QString cardSection = QString( "Card_%1" ).arg( i );
163 cfg.setGroup( cardSection ); 163 cfg.setGroup( cardSection );
164 QString name = cfg.readEntry( "name" ); 164 QString name = cfg.readEntry( "name" );
165 odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl; 165 odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
166 if ( cardName == name ) 166 if ( cardName == name )
167 { 167 {
168 value = cfg.readEntry( key, defaultValue ); 168 value = cfg.readEntry( key, defaultValue );
169 break; 169 break;
170 } 170 }
171 } 171 }
172 return value; 172 return value;
173} 173}
174 174
175 175
176QString ConfigDialog::preferredAction( const OPcmciaSocket* card, const QString& type ) 176QString ConfigDialog::preferredAction( const OPcmciaSocket* card, const QString& type )
177{ 177{
178 return ConfigDialog::readConfigEntry( card, QString( "%1Action" ).arg( type ), "suspend" ); 178 return ConfigDialog::readConfigEntry( card, QString( "%1Action" ).arg( type ), "suspend" );
179} 179}
diff --git a/noncore/applets/pcmcia/pcmcia.cpp b/noncore/applets/pcmcia/pcmcia.cpp
index af23f58..c6386cb 100644
--- a/noncore/applets/pcmcia/pcmcia.cpp
+++ b/noncore/applets/pcmcia/pcmcia.cpp
@@ -1,360 +1,364 @@
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 ), popupMenu( 0 ) 69PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ), popupMenu( 0 )
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( "pcmcia/pcmcia", Opie::Core::OResource::SmallIcon ); 79 pm = Opie::Core::OResource::loadPixmap( "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 99
100 while ( it.current() ) 100 while ( it.current() )
101 { 101 {
102 if ( !it.current()->isEmpty() ) 102 if ( !it.current()->isEmpty() )
103 { 103 {
104 executeAction( it.current(), "resume" ); 104 executeAction( it.current(), "resume" );
105 } 105 }
106 ++it; 106 ++it;
107 } 107 }
108 } 108 }
109} 109}
110 110
111void PcmciaManager::popUp( QString message, QString icon ) 111void PcmciaManager::popUp( QString message, QString icon )
112{ 112{
113 if ( !popupMenu) 113 if ( !popupMenu)
114 { 114 {
115 popupMenu = new QPopupMenu( this ); 115 popupMenu = new QPopupMenu( this );
116 popupMenu->setFocusPolicy( QWidget::NoFocus ); 116 popupMenu->setFocusPolicy( QWidget::NoFocus );
117 } 117 }
118 popupMenu->clear(); 118 popupMenu->clear();
119 119
120 if ( icon.isEmpty() ) { 120 if ( icon.isEmpty() ) {
121 popupMenu->insertItem( message, 0 ); 121 popupMenu->insertItem( message, 0 );
122 } else { 122 } else {
123 popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ), 123 popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ),
124 message, 0 ); 124 message, 0 );
125 } 125 }
126 126
127 QPoint p = mapToGlobal( QPoint( 0, 0 ) ); 127 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
128 QSize s = popupMenu->sizeHint(); 128 QSize s = popupMenu->sizeHint();
129 popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), 129 popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ),
130 p.y() - s.height() ), 0 ); 130 p.y() - s.height() ), 0 );
131 131
132 QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); 132 QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) );
133} 133}
134 134
135 135
136void PcmciaManager::popupTimeout() 136void PcmciaManager::popupTimeout()
137{ 137{
138 popupMenu->hide(); 138 popupMenu->hide();
139} 139}
140 140
141enum { EJECT, INSERT, SUSPEND, RESUME, RESET, CONFIGURE }; 141enum { EJECT, INSERT, SUSPEND, RESUME, RESET, CONFIGURE };
142static const char* actionText[] = { "eject", "insert", "suspend", "resum", "resett", "configur" }; 142static const char* actionText[] = { "eject", "insert", "suspend", "resum", "resett", "configur" };
143 143
144void PcmciaManager::mousePressEvent( QMouseEvent* ) 144void PcmciaManager::mousePressEvent( QMouseEvent* )
145{ 145{
146 QPopupMenu* menu = new QPopupMenu( this ); 146 QPopupMenu* menu = new QPopupMenu( this );
147 QStringList cmd; 147 QStringList cmd;
148 bool execute = true; 148 bool execute = true;
149 149
150 OPcmciaSystem* sys = OPcmciaSystem::instance(); 150 OPcmciaSystem* sys = OPcmciaSystem::instance();
151 sys->synchronize(); 151 sys->synchronize();
152 OPcmciaSystem::CardIterator it = sys->iterator(); 152 OPcmciaSystem::CardIterator it = sys->iterator();
153 if ( !sys->count() ) return; 153 if ( !sys->count() ) return;
154 154
155 int i = 0; 155 int i = 0;
156 while ( it.current() ) 156 while ( it.current() )
157 { 157 {
158 QPopupMenu* submenu = new QPopupMenu( menu ); 158 QPopupMenu* submenu = new QPopupMenu( menu );
159 submenu->insertItem( "&Eject", EJECT+i*100 ); 159 submenu->insertItem( "&Eject", EJECT+i*100 );
160 submenu->insertItem( "&Insert", INSERT+i*100 ); 160 submenu->insertItem( "&Insert", INSERT+i*100 );
161 submenu->insertItem( "&Suspend", SUSPEND+i*100 ); 161 submenu->insertItem( "&Suspend", SUSPEND+i*100 );
162 submenu->insertItem( "&Resume", RESUME+i*100 ); 162 submenu->insertItem( "&Resume", RESUME+i*100 );
163 submenu->insertItem( "Rese&t", RESET+i*100 ); 163 submenu->insertItem( "Rese&t", RESET+i*100 );
164 submenu->insertItem( "&Configure", CONFIGURE+i*100 ); 164 submenu->insertItem( "&Configure", CONFIGURE+i*100 );
165 165
166 submenu->setItemEnabled( EJECT+i*100, !it.current()->isEmpty() ); 166 bool isSuspended = it.current()->isSuspended();
167 submenu->setItemEnabled( INSERT+i*100, it.current()->isEmpty() ); 167 bool isEmpty = it.current()->isEmpty();
168 submenu->setItemEnabled( SUSPEND+i*100, !it.current()->isEmpty() && it.current()->isSuspended() ); 168
169 submenu->setItemEnabled( RESUME+i*100, !it.current()->isEmpty() && !it.current()->isSuspended() ); 169 submenu->setItemEnabled( EJECT+i*100, !isEmpty );
170 submenu->setItemEnabled( CONFIGURE+i*100, !it.current()->isEmpty() && !configuring ); 170 submenu->setItemEnabled( INSERT+i*100, isEmpty );
171 submenu->setItemEnabled( SUSPEND+i*100, !isEmpty && !isSuspended );
172 submenu->setItemEnabled( RESUME+i*100, !isEmpty && isSuspended );
173 submenu->setItemEnabled( RESET+i*100, !isEmpty && !isSuspended );
174 submenu->setItemEnabled( CONFIGURE+i*100, !isEmpty && !configuring );
171 175
172 connect( submenu, SIGNAL(activated(int)), this, SLOT(userCardAction(int)) ); 176 connect( submenu, SIGNAL(activated(int)), this, SLOT(userCardAction(int)) );
173 menu->insertItem( tr( "%1: %2" ).arg( i++ ).arg( it.current()->identity() ), submenu, 1 ); 177 menu->insertItem( tr( "%1: %2" ).arg( i++ ).arg( it.current()->identity() ), submenu, 1 );
174 ++it; 178 ++it;
175 } 179 }
176 180
177 QPoint p = mapToGlobal( QPoint( 0, 0 ) ); 181 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
178 QSize s = menu->sizeHint(); 182 QSize s = menu->sizeHint();
179 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 ); 183 int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 );
180 qDebug( "pcmcia: menu result = %d", opt ); 184 qDebug( "pcmcia: menu result = %d", opt );
181 delete menu; 185 delete menu;
182} 186}
183 187
184 188
185void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) 189void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
186{ 190{
187 odebug << "PcmciaManager::cardMessage( '" << msg << "' )" << oendl; 191 odebug << "PcmciaManager::cardMessage( '" << msg << "' )" << oendl;
188 if ( msg != "stabChanged()" ) return; 192 if ( msg != "stabChanged()" ) return;
189 193
190 /* check if a previously unknown card has been inserted */ 194 /* check if a previously unknown card has been inserted */
191 OPcmciaSystem::instance()->synchronize(); 195 OPcmciaSystem::instance()->synchronize();
192 196
193 if ( !OPcmciaSystem::instance()->cardCount() ) return; 197 if ( !OPcmciaSystem::instance()->cardCount() ) return;
194 198
195 OConfig cfg( "PCMCIA" ); 199 OConfig cfg( "PCMCIA" );
196 cfg.setGroup( "Global" ); 200 cfg.setGroup( "Global" );
197 int nCards = cfg.readNumEntry( "nCards", 0 ); 201 int nCards = cfg.readNumEntry( "nCards", 0 );
198 202
199 OPcmciaSystem* sys = OPcmciaSystem::instance(); 203 OPcmciaSystem* sys = OPcmciaSystem::instance();
200 OPcmciaSystem::CardIterator it = sys->iterator(); 204 OPcmciaSystem::CardIterator it = sys->iterator();
201 205
202 bool newCard = true; 206 bool newCard = true;
203 OPcmciaSocket* theCard = 0; 207 OPcmciaSocket* theCard = 0;
204 208
205 while ( it.current() && newCard ) 209 while ( it.current() && newCard )
206 { 210 {
207 if ( it.current()->isEmpty() ) 211 if ( it.current()->isEmpty() )
208 { 212 {
209 odebug << "pcmcia: skipping empty card in socket " << it.current()->number() << oendl; 213 odebug << "pcmcia: skipping empty card in socket " << it.current()->number() << oendl;
210 ++it; 214 ++it;
211 continue; 215 continue;
212 } 216 }
213 else 217 else
214 { 218 {
215 theCard = it.current(); 219 theCard = it.current();
216 QString cardName = theCard->productIdentity().join( " " ).stripWhiteSpace(); 220 QString cardName = theCard->productIdentity();
217 for ( int i = 0; i < nCards; ++i ) 221 for ( int i = 0; i < nCards; ++i )
218 { 222 {
219 QString cardSection = QString( "Card_%1" ).arg( i ); 223 QString cardSection = QString( "Card_%1" ).arg( i );
220 cfg.setGroup( cardSection ); 224 cfg.setGroup( cardSection );
221 QString name = cfg.readEntry( "name" ); 225 QString name = cfg.readEntry( "name" );
222 odebug << "pcmcia: comparing card '" << cardName << "' with known card '" << name << "'" << oendl; 226 odebug << "pcmcia: comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
223 if ( cardName == name ) 227 if ( cardName == name )
224 { 228 {
225 newCard = false; 229 newCard = false;
226 odebug << "pcmcia: we have seen this card before" << oendl; 230 odebug << "pcmcia: we have seen this card before" << oendl;
227 executeAction( theCard, "insert" ); 231 executeAction( theCard, "insert" );
228 break; 232 break;
229 } 233 }
230 } 234 }
231 if ( !newCard ) ++it; else break; 235 if ( !newCard ) ++it; else break;
232 } 236 }
233 } 237 }
234 if ( newCard ) 238 if ( newCard )
235 { 239 {
236 odebug << "pcmcia: unconfigured card detected" << oendl; 240 odebug << "pcmcia: unconfigured card detected" << oendl;
237 QString newCardName = theCard->productIdentity().join( " " ).stripWhiteSpace(); 241 QString newCardName = theCard->productIdentity();
238 int result = QMessageBox::information( qApp->desktop(), 242 int result = QMessageBox::information( qApp->desktop(),
239 tr( "PCMCIA/CF Subsystem" ), 243 tr( "PCMCIA/CF Subsystem" ),
240 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 ), 244 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 ),
241 tr( "Yes" ), tr( "No" ), 0, 0, 1 ); 245 tr( "Yes" ), tr( "No" ), 0, 0, 1 );
242 odebug << "pcmcia: result = " << result << oendl; 246 odebug << "pcmcia: result = " << result << oendl;
243 if ( result == 0 ) 247 if ( result == 0 )
244 { 248 {
245 QString insertAction; QString resumeAction; QString driver; QString conf; 249 QString insertAction; QString resumeAction; QString driver; QString conf;
246 bool configured = configure( theCard, insertAction, resumeAction, driver, conf ); 250 bool configured = configure( theCard, insertAction, resumeAction, driver, conf );
247 251
248 if ( configured ) 252 if ( configured )
249 { 253 {
250 odebug << "pcmcia: card has been configured. writing out to database" << oendl; 254 odebug << "pcmcia: card has been configured. writing out to database" << oendl;
251 cfg.setGroup( QString( "Card_%1" ).arg( nCards ) ); 255 cfg.setGroup( QString( "Card_%1" ).arg( nCards ) );
252 cfg.writeEntry( "name", newCardName ); 256 cfg.writeEntry( "name", newCardName );
253 cfg.writeEntry( "insertAction", insertAction ); 257 cfg.writeEntry( "insertAction", insertAction );
254 cfg.writeEntry( "resumeAction", resumeAction ); 258 cfg.writeEntry( "resumeAction", resumeAction );
255 cfg.setGroup( "Global" ); 259 cfg.setGroup( "Global" );
256 cfg.writeEntry( "nCards", nCards+1 ); 260 cfg.writeEntry( "nCards", nCards+1 );
257 cfg.write(); 261 cfg.write();
258 262
259 QFile confFile( conf ); 263 QFile confFile( conf );
260 if ( confFile.open( IO_ReadWrite | IO_Append ) ) 264 if ( confFile.open( IO_ReadWrite | IO_Append ) )
261 { 265 {
262 QString entryCard = QString( "card \"%1\"" ).arg( newCardName ); 266 QString entryCard = QString( "card \"%1\"" ).arg( newCardName );
263 QString entryVersion( " version " ); 267 QString entryVersion( " version " );
264 for ( QStringList::Iterator it = theCard->productIdentity().begin(); it != theCard->productIdentity().end(); ++it ) 268 for ( QStringList::Iterator it = theCard->productIdentityVector().begin(); it != theCard->productIdentityVector().end(); ++it )
265 { 269 {
266 entryVersion += QString( "\"%1\", " ).arg( *it ); 270 entryVersion += QString( "\"%1\", " ).arg( *it );
267 } 271 }
268 QString entryBind = QString( " bind %1" ).arg( driver ); 272 QString entryBind = QString( " bind %1" ).arg( driver );
269 QString entry = QString( "\n%1\n%2\n%3\n" ).arg( entryCard ).arg( entryVersion ).arg( entryBind ); 273 QString entry = QString( "\n%1\n%2\n%3\n" ).arg( entryCard ).arg( entryVersion ).arg( entryBind );
270 odebug << "pcmcia: writing entry...:" << entry << oendl; 274 odebug << "pcmcia: writing entry...:" << entry << oendl;
271 275
272 confFile.writeBlock( (const char*) entry, entry.length() ); 276 confFile.writeBlock( (const char*) entry, entry.length() );
273 Global::statusMessage( "restarting pcmcia services..." ); 277 Global::statusMessage( "restarting pcmcia services..." );
274 ::system( "/etc/init.d/pcmcia restart" ); 278 ::system( "/etc/init.d/pcmcia restart" );
275 } 279 }
276 else 280 else
277 { 281 {
278 owarn << "pcmcia: couldn't write binding to '" << conf << "' ( " << strerror( errno ) << " )." << oendl; 282 owarn << "pcmcia: couldn't write binding to '" << conf << "' ( " << strerror( errno ) << " )." << oendl;
279 } 283 }
280 } 284 }
281 else 285 else
282 { 286 {
283 odebug << "pcmcia: card has not been configured this time. leaving as unknown card" << oendl; 287 odebug << "pcmcia: card has not been configured this time. leaving as unknown card" << oendl;
284 } 288 }
285 } 289 }
286 else 290 else
287 { 291 {
288 odebug << "pcmcia: user doesn't want to configure " << newCardName << " now." << oendl; 292 odebug << "pcmcia: user doesn't want to configure " << newCardName << " now." << oendl;
289 } 293 }
290 } 294 }
291 else // it's an already configured card 295 else // it's an already configured card
292 { 296 {
293 odebug << "pcmcia: doing nothing... why do we come here?" << oendl; 297 odebug << "pcmcia: doing nothing... why do we come here?" << oendl;
294 } 298 }
295} 299}
296 300
297void PcmciaManager::paintEvent( QPaintEvent * ) 301void PcmciaManager::paintEvent( QPaintEvent * )
298{ 302{
299 QPainter p( this ); 303 QPainter p( this );
300 p.drawPixmap( 0, 0, pm ); 304 p.drawPixmap( 0, 0, pm );
301} 305}
302 306
303int PcmciaManager::position() 307int PcmciaManager::position()
304{ 308{
305 return 7; 309 return 7;
306} 310}
307 311
308void PcmciaManager::execCommand( const QStringList &strList ) 312void PcmciaManager::execCommand( const QStringList &strList )
309{ 313{
310} 314}
311 315
312void PcmciaManager::userCardAction( int action ) 316void PcmciaManager::userCardAction( int action )
313{ 317{
314 odebug << "pcmcia: user action on socket " << action / 100 << " requested. action = " << action << oendl; 318 odebug << "pcmcia: user action on socket " << action / 100 << " requested. action = " << action << oendl;
315 319
316 int socket = action / 100; 320 int socket = action / 100;
317 int what = action % 100; 321 int what = action % 100;
318 bool success = false; 322 bool success = false;
319 323
320 switch ( what ) 324 switch ( what )
321 { 325 {
322 case CONFIGURE: 326 case CONFIGURE:
323 { 327 {
324 QString insertAction; QString resumeAction; QString driver; QString conf; 328 QString insertAction; QString resumeAction; QString driver; QString conf;
325 configure( OPcmciaSystem::instance()->socket( socket ), insertAction, resumeAction, driver, conf ); 329 configure( OPcmciaSystem::instance()->socket( socket ), insertAction, resumeAction, driver, conf );
326 return; 330 return;
327 } 331 }
328 case EJECT: success = OPcmciaSystem::instance()->socket( socket )->eject(); 332 case EJECT: success = OPcmciaSystem::instance()->socket( socket )->eject();
329 break; 333 break;
330 case INSERT: success = OPcmciaSystem::instance()->socket( socket )->insert(); 334 case INSERT: success = OPcmciaSystem::instance()->socket( socket )->insert();
331 break; 335 break;
332 case SUSPEND: success = OPcmciaSystem::instance()->socket( socket )->suspend(); 336 case SUSPEND: success = OPcmciaSystem::instance()->socket( socket )->suspend();
333 break; 337 break;
334 case RESUME: success = OPcmciaSystem::instance()->socket( socket )->resume(); 338 case RESUME: success = OPcmciaSystem::instance()->socket( socket )->resume();
335 break; 339 break;
336 case RESET: success = OPcmciaSystem::instance()->socket( socket )->reset(); 340 case RESET: success = OPcmciaSystem::instance()->socket( socket )->reset();
337 break; 341 break;
338 default: odebug << "pcmcia: not yet implemented" << oendl; 342 default: odebug << "pcmcia: not yet implemented" << oendl;
339 } 343 }
340 344
341 if ( success ) 345 if ( success )
342 { 346 {
343 popUp( tr( "Successfully %1ed card in socket #%2" ).arg( actionText[action] ).arg( socket ) ); 347 popUp( tr( "Successfully %1ed card in socket #%2" ).arg( actionText[action] ).arg( socket ) );
344 } 348 }
345 else 349 else
346 { 350 {
347 popUp( tr( "Error while %1ing card in socket #%2" ).arg( actionText[action] ).arg( socket ) ); 351 popUp( tr( "Error while %1ing card in socket #%2" ).arg( actionText[action] ).arg( socket ) );
348 } 352 }
349} 353}
350 354
351bool PcmciaManager::configure( OPcmciaSocket* card, QString& insertAction, QString& resumeAction, QString& driver, QString& conf ) 355bool PcmciaManager::configure( OPcmciaSocket* card, QString& insertAction, QString& resumeAction, QString& driver, QString& conf )
352{ 356{
353 configuring = true; 357 configuring = true;
354 ConfigDialog dialog( card, qApp->desktop() ); 358 ConfigDialog dialog( card, qApp->desktop() );
355 int configresult = QPEApplication::execDialog( &dialog, false ); 359 int configresult = QPEApplication::execDialog( &dialog, false );
356 configuring = false; 360 configuring = false;
357 odebug << "pcmcia: configresult = " << configresult << oendl; 361 odebug << "pcmcia: configresult = " << configresult << oendl;
358 if ( configresult ) 362 if ( configresult )
359 { 363 {
360 insertAction = dialog.cbInsertAction->currentText(); 364 insertAction = dialog.cbInsertAction->currentText();