summaryrefslogtreecommitdiff
path: root/noncore/applets/pcmcia/configdialog.cpp
Unidiff
Diffstat (limited to 'noncore/applets/pcmcia/configdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/pcmcia/configdialog.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/noncore/applets/pcmcia/configdialog.cpp b/noncore/applets/pcmcia/configdialog.cpp
index f5812ba..f94edde 100644
--- a/noncore/applets/pcmcia/configdialog.cpp
+++ b/noncore/applets/pcmcia/configdialog.cpp
@@ -39,139 +39,141 @@ using namespace Opie::Core;
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().join( " " ) );
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->name() << "' 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->name() << "' 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 action; 136 QString action;
136 137
137 for ( int i = 0; i < nCards; ++i ) 138 for ( int i = 0; i < nCards; ++i )
138 { 139 {
139 QString cardSection = QString( "Card_%1" ).arg( i ); 140 QString cardSection = QString( "Card_%1" ).arg( i );
140 cfg.setGroup( cardSection ); 141 cfg.setGroup( cardSection );
141 QString name = cfg.readEntry( "name" ); 142 QString name = cfg.readEntry( "name" );
142 odebug << "comparing card '" << card->name() << "' with known card '" << name << "'" << oendl; 143 odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
143 if ( card->name() == name ) 144 if ( cardName == name )
144 { 145 {
145 cfg.writeEntry( key, value ); 146 cfg.writeEntry( key, value );
146 break; 147 break;
147 } 148 }
148 } 149 }
149} 150}
150 151
151QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& defaultValue ) 152QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& defaultValue )
152{ 153{
153 OConfig cfg( "PCMCIA" ); 154 OConfig cfg( "PCMCIA" );
154 cfg.setGroup( "Global" ); 155 cfg.setGroup( "Global" );
155 int nCards = cfg.readNumEntry( "nCards", 0 ); 156 int nCards = cfg.readNumEntry( "nCards", 0 );
157 QString cardName = card->productIdentity().join( " " ).stripWhiteSpace();
156 QString value; 158 QString value;
157 159
158 for ( int i = 0; i < nCards; ++i ) 160 for ( int i = 0; i < nCards; ++i )
159 { 161 {
160 QString cardSection = QString( "Card_%1" ).arg( i ); 162 QString cardSection = QString( "Card_%1" ).arg( i );
161 cfg.setGroup( cardSection ); 163 cfg.setGroup( cardSection );
162 QString name = cfg.readEntry( "name" ); 164 QString name = cfg.readEntry( "name" );
163 odebug << "comparing card '" << card->name() << "' with known card '" << name << "'" << oendl; 165 odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
164 if ( card->name() == name ) 166 if ( cardName == name )
165 { 167 {
166 value = cfg.readEntry( key, defaultValue ); 168 value = cfg.readEntry( key, defaultValue );
167 break; 169 break;
168 } 170 }
169 } 171 }
170 return value; 172 return value;
171} 173}
172 174
173 175
174QString ConfigDialog::preferredAction( const OPcmciaSocket* card, const QString& type ) 176QString ConfigDialog::preferredAction( const OPcmciaSocket* card, const QString& type )
175{ 177{
176 return ConfigDialog::readConfigEntry( card, QString( "%1Action" ).arg( type ), "suspend" ); 178 return ConfigDialog::readConfigEntry( card, QString( "%1Action" ).arg( type ), "suspend" );
177} 179}