author | drw <drw> | 2004-04-21 15:57:19 (UTC) |
---|---|---|
committer | drw <drw> | 2004-04-21 15:57:19 (UTC) |
commit | 5ac20617216e4592685940ede23f135d86e8d2cd (patch) (unidiff) | |
tree | 17a2ba8adc06eed219b3b77e42d46e5e0c714630 | |
parent | 4e6c1ec2758d337d772af3af49a1b74f737cd57f (diff) | |
download | opie-5ac20617216e4592685940ede23f135d86e8d2cd.zip opie-5ac20617216e4592685940ede23f135d86e8d2cd.tar.gz opie-5ac20617216e4592685940ede23f135d86e8d2cd.tar.bz2 |
Implement saving of ipkg config information and re-initialization of libipkg after config info changed
-rw-r--r-- | noncore/settings/packagemanager/oipkg.cpp | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/noncore/settings/packagemanager/oipkg.cpp b/noncore/settings/packagemanager/oipkg.cpp index 5c79ba9..b9c82df 100644 --- a/noncore/settings/packagemanager/oipkg.cpp +++ b/noncore/settings/packagemanager/oipkg.cpp | |||
@@ -35,192 +35,261 @@ | |||
35 | #include <string.h> | 35 | #include <string.h> |
36 | 36 | ||
37 | #include <qdir.h> | 37 | #include <qdir.h> |
38 | #include <qfile.h> | 38 | #include <qfile.h> |
39 | #include <qtextstream.h> | 39 | #include <qtextstream.h> |
40 | 40 | ||
41 | const QString IPKG_CONF = "/etc/ipkg.conf"; // Fully-qualified name of Ipkg primary configuration file | 41 | const QString IPKG_CONF = "/etc/ipkg.conf"; // Fully-qualified name of Ipkg primary configuration file |
42 | const QString IPKG_CONF_DIR = "/etc/ipkg"; // Directory of secondary Ipkg configuration files | 42 | const QString IPKG_CONF_DIR = "/etc/ipkg"; // Directory of secondary Ipkg configuration files |
43 | const QString IPKG_PKG_PATH = "/usr/lib/ipkg/lists"; // Directory containing server package lists | 43 | const QString IPKG_PKG_PATH = "/usr/lib/ipkg/lists"; // Directory containing server package lists |
44 | const QString IPKG_STATUS_PATH = "usr/lib/ipkg/status"; // Destination status file location | 44 | const QString IPKG_STATUS_PATH = "usr/lib/ipkg/status"; // Destination status file location |
45 | 45 | ||
46 | OIpkg *oipkg; | 46 | OIpkg *oipkg; |
47 | 47 | ||
48 | // Ipkg callback functions | 48 | // Ipkg callback functions |
49 | 49 | ||
50 | int fsignalIpkgMessage( ipkg_conf_t */*conf*/, message_level_t /*level*/, char *msg ) | 50 | int fsignalIpkgMessage( ipkg_conf_t */*conf*/, message_level_t /*level*/, char *msg ) |
51 | { | 51 | { |
52 | oipkg->ipkgMessage( msg ); | 52 | oipkg->ipkgMessage( msg ); |
53 | return 0; | 53 | return 0; |
54 | } | 54 | } |
55 | 55 | ||
56 | char *fIpkgResponse( char */*question*/ ) | 56 | char *fIpkgResponse( char */*question*/ ) |
57 | { | 57 | { |
58 | return 0x0; | 58 | return 0x0; |
59 | } | 59 | } |
60 | 60 | ||
61 | int fIpkgStatus( char */*name*/, int /*status*/, char *desc, void */*userdata*/ ) | 61 | int fIpkgStatus( char */*name*/, int /*status*/, char *desc, void */*userdata*/ ) |
62 | { | 62 | { |
63 | oipkg->ipkgStatus( desc ); | 63 | oipkg->ipkgStatus( desc ); |
64 | return 0; | 64 | return 0; |
65 | } | 65 | } |
66 | 66 | ||
67 | int fIpkgFiles( char */*name*/, char *desc, char */*version*/, pkg_state_status_t /*status*/, | 67 | int fIpkgFiles( char */*name*/, char *desc, char */*version*/, pkg_state_status_t /*status*/, |
68 | void */*userdata*/ ) | 68 | void */*userdata*/ ) |
69 | { | 69 | { |
70 | oipkg->ipkgList( desc ); | 70 | oipkg->ipkgList( desc ); |
71 | return 0; | 71 | return 0; |
72 | } | 72 | } |
73 | 73 | ||
74 | OIpkg::OIpkg( Config *config, QObject *parent, const char *name ) | 74 | OIpkg::OIpkg( Config *config, QObject *parent, const char *name ) |
75 | : QObject( parent, name ) | 75 | : QObject( parent, name ) |
76 | , m_config( config ) | 76 | , m_config( config ) |
77 | , m_confInfo( NULL ) | 77 | , m_confInfo( NULL ) |
78 | , m_ipkgExecOptions( 0 ) | 78 | , m_ipkgExecOptions( 0 ) |
79 | , m_ipkgExecVerbosity( 1 ) | 79 | , m_ipkgExecVerbosity( 1 ) |
80 | { | 80 | { |
81 | oipkg = this; | 81 | oipkg = this; |
82 | 82 | ||
83 | // Initialize libipkg | 83 | // Initialize libipkg |
84 | ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs ); | 84 | ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs ); |
85 | 85 | ||
86 | // Default ipkg run-time arguments | 86 | // Default ipkg run-time arguments |
87 | m_ipkgArgs.noaction = false; | 87 | m_ipkgArgs.noaction = false; |
88 | m_ipkgArgs.force_defaults = true; | 88 | m_ipkgArgs.force_defaults = true; |
89 | } | 89 | } |
90 | 90 | ||
91 | OIpkg::~OIpkg() | 91 | OIpkg::~OIpkg() |
92 | { | 92 | { |
93 | // Upon destruction, ensure that items in config list are deleted with list | 93 | // Upon destruction, ensure that items in config list are deleted with list |
94 | if ( m_confInfo ) | 94 | if ( m_confInfo ) |
95 | m_confInfo->setAutoDelete( true ); | 95 | m_confInfo->setAutoDelete( true ); |
96 | 96 | ||
97 | // Free up libipkg resources | 97 | // Free up libipkg resources |
98 | ipkg_deinit( &m_ipkgArgs ); | 98 | ipkg_deinit( &m_ipkgArgs ); |
99 | } | 99 | } |
100 | 100 | ||
101 | OConfItemList *OIpkg::configItems() | 101 | OConfItemList *OIpkg::configItems() |
102 | { | 102 | { |
103 | // Retrieve all configuration items | 103 | // Retrieve all configuration items |
104 | return filterConfItems(); | 104 | return filterConfItems(); |
105 | } | 105 | } |
106 | 106 | ||
107 | OConfItemList *OIpkg::servers() | 107 | OConfItemList *OIpkg::servers() |
108 | { | 108 | { |
109 | // Retrieve only servers | 109 | // Retrieve only servers |
110 | return filterConfItems( OConfItem::Source ); | 110 | return filterConfItems( OConfItem::Source ); |
111 | } | 111 | } |
112 | 112 | ||
113 | OConfItemList *OIpkg::destinations() | 113 | OConfItemList *OIpkg::destinations() |
114 | { | 114 | { |
115 | // Retrieve only destinations | 115 | // Retrieve only destinations |
116 | return filterConfItems( OConfItem::Destination ); | 116 | return filterConfItems( OConfItem::Destination ); |
117 | } | 117 | } |
118 | 118 | ||
119 | OConfItemList *OIpkg::options() | 119 | OConfItemList *OIpkg::options() |
120 | { | 120 | { |
121 | // Retrieve only destinations | 121 | // Retrieve only destinations |
122 | return filterConfItems( OConfItem::Option ); | 122 | return filterConfItems( OConfItem::Option ); |
123 | } | 123 | } |
124 | 124 | ||
125 | void OIpkg::setConfigItems( OConfItemList *configList ) | 125 | void OIpkg::setConfigItems( OConfItemList *configList ) |
126 | { | 126 | { |
127 | if ( m_confInfo ) | 127 | if ( m_confInfo ) |
128 | delete m_confInfo; | 128 | delete m_confInfo; |
129 | 129 | ||
130 | m_confInfo = configList; | 130 | m_confInfo = configList; |
131 | |||
132 | // Write out new /etc/ipkg.conf | ||
133 | QFile confFile( IPKG_CONF ); | ||
134 | if ( confFile.open( IO_WriteOnly ) ) | ||
135 | { | ||
136 | QTextStream confStream( &confFile ); | ||
137 | confStream << "# Generated by Opie Package Manager\n\n"; | ||
138 | |||
139 | OConfItemListIterator it( *m_confInfo ); | ||
140 | for ( ; it.current(); ++it ) | ||
141 | { | ||
142 | OConfItem *item = it.current(); | ||
143 | |||
144 | // Only write out valid conf items | ||
145 | if ( item->type() != OConfItem::NotDefined ) | ||
146 | { | ||
147 | QString confLine; | ||
148 | if ( !item->active() ) | ||
149 | confLine = "#"; | ||
150 | |||
151 | switch ( item->type() ) | ||
152 | { | ||
153 | case OConfItem::Source : confLine.append( "src " ); break; | ||
154 | case OConfItem::Destination : confLine.append( "dest " ); break; | ||
155 | case OConfItem::Option : confLine.append( "option " ); break; | ||
156 | case OConfItem::Arch : confLine.append( "arch " ); break; | ||
157 | default : break; | ||
158 | }; | ||
159 | |||
160 | confStream << confLine << " " << item->name() << " " << item->value() << "\n"; | ||
161 | } | ||
162 | } | ||
163 | |||
164 | confFile.close(); | ||
165 | } | ||
166 | else | ||
167 | { | ||
168 | // Problem writing to /etc/ipkg.conf, exit before removing other conf files | ||
169 | return; | ||
170 | } | ||
171 | |||
172 | // Delete /etc/ipkg/*.conf files (/etc/ipkg.conf should now have all settings | ||
173 | QStringList confFiles; | ||
174 | QDir confDir( IPKG_CONF_DIR ); | ||
175 | if ( confDir.exists() ) | ||
176 | { | ||
177 | confDir.setNameFilter( "*.conf" ); | ||
178 | confDir.setFilter( QDir::Files ); | ||
179 | confFiles = confDir.entryList( "*.conf", QDir::Files ); | ||
180 | |||
181 | QStringList::Iterator lastFile = confFiles.end(); | ||
182 | for ( QStringList::Iterator it = confFiles.begin(); it != lastFile; ++it ) | ||
183 | { | ||
184 | // Create absolute file path if necessary | ||
185 | QString absFile = (*it); | ||
186 | if ( !absFile.startsWith( "/" ) ) | ||
187 | absFile.prepend( QString( IPKG_CONF_DIR ) + "/" ); | ||
188 | |||
189 | // Delete file | ||
190 | printf( "Deleting: \'%s\'\n", absFile.latin1() ); | ||
191 | QFile::remove( absFile ); | ||
192 | } | ||
193 | } | ||
194 | |||
195 | // Reinitialize libipkg to pick up new configuration | ||
196 | ipkg_deinit( &m_ipkgArgs ); | ||
197 | ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs ); | ||
198 | m_ipkgArgs.noaction = false; | ||
199 | m_ipkgArgs.force_defaults = true; | ||
131 | } | 200 | } |
132 | 201 | ||
133 | void OIpkg::saveSettings() | 202 | void OIpkg::saveSettings() |
134 | { | 203 | { |
135 | // Save Ipkg execution options to application configuration file | 204 | // Save Ipkg execution options to application configuration file |
136 | if ( m_config ) | 205 | if ( m_config ) |
137 | { | 206 | { |
138 | m_config->setGroup( "Ipkg" ); | 207 | m_config->setGroup( "Ipkg" ); |
139 | m_config->writeEntry( "ExecOptions", m_ipkgExecOptions ); | 208 | m_config->writeEntry( "ExecOptions", m_ipkgExecOptions ); |
140 | m_config->writeEntry( "Verbosity", m_ipkgExecVerbosity ); | 209 | m_config->writeEntry( "Verbosity", m_ipkgExecVerbosity ); |
141 | } | 210 | } |
142 | } | 211 | } |
143 | 212 | ||
144 | OPackageList *OIpkg::availablePackages( const QString &server ) | 213 | OPackageList *OIpkg::availablePackages( const QString &server ) |
145 | { | 214 | { |
146 | // Load Ipkg configuration info if not already cached | 215 | // Load Ipkg configuration info if not already cached |
147 | if ( !m_confInfo ) | 216 | if ( !m_confInfo ) |
148 | loadConfiguration(); | 217 | loadConfiguration(); |
149 | 218 | ||
150 | // Build new server list (caller is responsible for deleting) | 219 | // Build new server list (caller is responsible for deleting) |
151 | OPackageList *pl = new OPackageList; | 220 | OPackageList *pl = new OPackageList; |
152 | 221 | ||
153 | // Open package list file | 222 | // Open package list file |
154 | QFile f( IPKG_PKG_PATH + "/" + server ); | 223 | QFile f( IPKG_PKG_PATH + "/" + server ); |
155 | if ( !f.open( IO_ReadOnly ) ) | 224 | if ( !f.open( IO_ReadOnly ) ) |
156 | return NULL; | 225 | return NULL; |
157 | QTextStream t( &f ); | 226 | QTextStream t( &f ); |
158 | 227 | ||
159 | // Process all information in package list file | 228 | // Process all information in package list file |
160 | OPackage *package = NULL; | 229 | OPackage *package = NULL; |
161 | QString line = t.readLine(); | 230 | QString line = t.readLine(); |
162 | while ( !t.eof() ) | 231 | while ( !t.eof() ) |
163 | { | 232 | { |
164 | // Determine key/value pair | 233 | // Determine key/value pair |
165 | int pos = line.find( ':', 0 ); | 234 | int pos = line.find( ':', 0 ); |
166 | QString key; | 235 | QString key; |
167 | if ( pos > -1 ) | 236 | if ( pos > -1 ) |
168 | key = line.mid( 0, pos ); | 237 | key = line.mid( 0, pos ); |
169 | else | 238 | else |
170 | key = QString::null; | 239 | key = QString::null; |
171 | QString value = line.mid( pos+2, line.length()-pos ); | 240 | QString value = line.mid( pos+2, line.length()-pos ); |
172 | 241 | ||
173 | // Allocate new package and insert into list | 242 | // Allocate new package and insert into list |
174 | if ( package == NULL && !key.isEmpty() ) | 243 | if ( package == NULL && !key.isEmpty() ) |
175 | { | 244 | { |
176 | package = new OPackage( value ); | 245 | package = new OPackage( value ); |
177 | package->setSource( server ); | 246 | package->setSource( server ); |
178 | pl->append( package ); | 247 | pl->append( package ); |
179 | } | 248 | } |
180 | 249 | ||
181 | // Update package data | 250 | // Update package data |
182 | if ( key == "Package" ) | 251 | if ( key == "Package" ) |
183 | package->setName( value ); | 252 | package->setName( value ); |
184 | else if ( key == "Version" ) | 253 | else if ( key == "Version" ) |
185 | package->setVersion( value ); | 254 | package->setVersion( value ); |
186 | else if ( key == "Section" ) | 255 | else if ( key == "Section" ) |
187 | package->setCategory( value ); | 256 | package->setCategory( value ); |
188 | //DataManager::setAvailableCategories( value ); | 257 | //DataManager::setAvailableCategories( value ); |
189 | else if ( key.isEmpty() && value.isEmpty() ) | 258 | else if ( key.isEmpty() && value.isEmpty() ) |
190 | package = NULL; | 259 | package = NULL; |
191 | 260 | ||
192 | // Skip past all description lines | 261 | // Skip past all description lines |
193 | if ( key == "Description" ) | 262 | if ( key == "Description" ) |
194 | { | 263 | { |
195 | line = t.readLine(); | 264 | line = t.readLine(); |
196 | while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() ) | 265 | while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() ) |
197 | line = t.readLine(); | 266 | line = t.readLine(); |
198 | } | 267 | } |
199 | else | 268 | else |
200 | line = t.readLine(); | 269 | line = t.readLine(); |
201 | } | 270 | } |
202 | 271 | ||
203 | f.close(); | 272 | f.close(); |
204 | 273 | ||
205 | return pl; | 274 | return pl; |
206 | } | 275 | } |
207 | 276 | ||
208 | OPackageList *OIpkg::installedPackages( const QString &destName, const QString &destPath ) | 277 | OPackageList *OIpkg::installedPackages( const QString &destName, const QString &destPath ) |
209 | { | 278 | { |
210 | // Load Ipkg configuration info if not already cached | 279 | // Load Ipkg configuration info if not already cached |
211 | if ( !m_confInfo ) | 280 | if ( !m_confInfo ) |
212 | loadConfiguration(); | 281 | loadConfiguration(); |
213 | 282 | ||
214 | // Build new server list (caller is responsible for deleting) | 283 | // Build new server list (caller is responsible for deleting) |
215 | OPackageList *pl = new OPackageList; | 284 | OPackageList *pl = new OPackageList; |
216 | 285 | ||
217 | // Open status file | 286 | // Open status file |
218 | QString path = destPath; | 287 | QString path = destPath; |
219 | if ( path.right( 1 ) != "/" ) | 288 | if ( path.right( 1 ) != "/" ) |
220 | path.append( "/" ); | 289 | path.append( "/" ); |
221 | path.append( IPKG_STATUS_PATH ); | 290 | path.append( IPKG_STATUS_PATH ); |
222 | 291 | ||
223 | QFile f( path ); | 292 | QFile f( path ); |
224 | if ( !f.open( IO_ReadOnly ) ) | 293 | if ( !f.open( IO_ReadOnly ) ) |
225 | return NULL; | 294 | return NULL; |
226 | QTextStream t( &f ); | 295 | QTextStream t( &f ); |
@@ -311,193 +380,194 @@ bool OIpkg::executeCommand( OPackage::Command command, QStringList *parameters, | |||
311 | // Connect output signal to widget | 380 | // Connect output signal to widget |
312 | 381 | ||
313 | if ( rawOutput ) | 382 | if ( rawOutput ) |
314 | { | 383 | { |
315 | // if ( slotOutput ) | 384 | // if ( slotOutput ) |
316 | // connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); | 385 | // connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); |
317 | } | 386 | } |
318 | else | 387 | else |
319 | { | 388 | { |
320 | // TODO - connect to local slot and parse output before emitting signalIpkgMessage | 389 | // TODO - connect to local slot and parse output before emitting signalIpkgMessage |
321 | } | 390 | } |
322 | 391 | ||
323 | switch( command ) | 392 | switch( command ) |
324 | { | 393 | { |
325 | case OPackage::Update : { | 394 | case OPackage::Update : { |
326 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); | 395 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); |
327 | ipkg_lists_update( &m_ipkgArgs ); | 396 | ipkg_lists_update( &m_ipkgArgs ); |
328 | }; | 397 | }; |
329 | break; | 398 | break; |
330 | case OPackage::Upgrade : { | 399 | case OPackage::Upgrade : { |
331 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); | 400 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); |
332 | ipkg_packages_upgrade( &m_ipkgArgs ); | 401 | ipkg_packages_upgrade( &m_ipkgArgs ); |
333 | }; | 402 | }; |
334 | break; | 403 | break; |
335 | case OPackage::Install : { | 404 | case OPackage::Install : { |
336 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); | 405 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); |
337 | for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) | 406 | for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) |
338 | { | 407 | { |
339 | ipkg_packages_install( &m_ipkgArgs, (*it) ); | 408 | ipkg_packages_install( &m_ipkgArgs, (*it) ); |
340 | } | 409 | } |
341 | }; | 410 | }; |
342 | break; | 411 | break; |
343 | case OPackage::Remove : { | 412 | case OPackage::Remove : { |
344 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); | 413 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); |
345 | for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) | 414 | for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) |
346 | { | 415 | { |
347 | ipkg_packages_remove( &m_ipkgArgs, (*it), true ); | 416 | ipkg_packages_remove( &m_ipkgArgs, (*it), true ); |
348 | } | 417 | } |
349 | }; | 418 | }; |
350 | break; | 419 | break; |
351 | case OPackage::Download : { | 420 | case OPackage::Download : { |
352 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); | 421 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); |
353 | for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) | 422 | for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) |
354 | { | 423 | { |
355 | ipkg_packages_download( &m_ipkgArgs, (*it) ); | 424 | ipkg_packages_download( &m_ipkgArgs, (*it) ); |
356 | } | 425 | } |
357 | }; | 426 | }; |
358 | break; | 427 | break; |
359 | case OPackage::Info : { | 428 | case OPackage::Info : { |
360 | connect( this, SIGNAL(signalIpkgStatus(char*)), receiver, slotOutput ); | 429 | connect( this, SIGNAL(signalIpkgStatus(char*)), receiver, slotOutput ); |
361 | ipkg_packages_info( &m_ipkgArgs, (*parameters->begin()), &fIpkgStatus, 0x0 ); | 430 | ipkg_packages_info( &m_ipkgArgs, (*parameters->begin()), &fIpkgStatus, 0x0 ); |
362 | }; | 431 | }; |
363 | break; | 432 | break; |
364 | case OPackage::Files : { | 433 | case OPackage::Files : { |
365 | connect( this, SIGNAL(signalIpkgList(char*)), receiver, slotOutput ); | 434 | connect( this, SIGNAL(signalIpkgList(char*)), receiver, slotOutput ); |
366 | ipkg_package_files( &m_ipkgArgs, (*parameters->begin()), &fIpkgFiles, 0x0 ); | 435 | ipkg_package_files( &m_ipkgArgs, (*parameters->begin()), &fIpkgFiles, 0x0 ); |
367 | }; | 436 | }; |
368 | break; | 437 | break; |
369 | default : break; | 438 | default : break; |
370 | }; | 439 | }; |
371 | 440 | ||
372 | return true; | 441 | return true; |
373 | } | 442 | } |
374 | 443 | ||
375 | void OIpkg::ipkgMessage( char *msg ) | 444 | void OIpkg::ipkgMessage( char *msg ) |
376 | { | 445 | { |
377 | emit signalIpkgMessage( msg ); | 446 | emit signalIpkgMessage( msg ); |
378 | } | 447 | } |
379 | 448 | ||
380 | void OIpkg::ipkgStatus( char *status ) | 449 | void OIpkg::ipkgStatus( char *status ) |
381 | { | 450 | { |
382 | emit signalIpkgStatus( status ); | 451 | emit signalIpkgStatus( status ); |
383 | } | 452 | } |
384 | 453 | ||
385 | void OIpkg::ipkgList( char *filelist ) | 454 | void OIpkg::ipkgList( char *filelist ) |
386 | { | 455 | { |
387 | emit signalIpkgList( filelist ); | 456 | emit signalIpkgList( filelist ); |
388 | } | 457 | } |
389 | 458 | ||
390 | void OIpkg::loadConfiguration() | 459 | void OIpkg::loadConfiguration() |
391 | { | 460 | { |
392 | if ( m_confInfo ) | 461 | if ( m_confInfo ) |
393 | delete m_confInfo; | 462 | delete m_confInfo; |
394 | 463 | ||
395 | // Load configuration item list | 464 | // Load configuration item list |
396 | m_confInfo = new OConfItemList(); | 465 | m_confInfo = new OConfItemList(); |
397 | 466 | ||
398 | QStringList confFiles; | 467 | QStringList confFiles; |
399 | QDir confDir( IPKG_CONF_DIR ); | 468 | QDir confDir( IPKG_CONF_DIR ); |
400 | if ( confDir.exists() ) | 469 | if ( confDir.exists() ) |
401 | { | 470 | { |
402 | confDir.setNameFilter( "*.conf" ); | 471 | confDir.setNameFilter( "*.conf" ); |
403 | confDir.setFilter( QDir::Files ); | 472 | confDir.setFilter( QDir::Files ); |
404 | confFiles = confDir.entryList( "*.conf", QDir::Files ); | 473 | confFiles = confDir.entryList( "*.conf", QDir::Files ); |
405 | confFiles << IPKG_CONF; | 474 | confFiles << IPKG_CONF; |
406 | 475 | ||
407 | for ( QStringList::Iterator it = confFiles.begin(); it != confFiles.end(); ++it ) | 476 | QStringList::Iterator lastFile = confFiles.end(); |
477 | for ( QStringList::Iterator it = confFiles.begin(); it != lastFile; ++it ) | ||
408 | { | 478 | { |
409 | // Create absolute file path if necessary | 479 | // Create absolute file path if necessary |
410 | QString absFile = (*it); | 480 | QString absFile = (*it); |
411 | if ( !absFile.startsWith( "/" ) ) | 481 | if ( !absFile.startsWith( "/" ) ) |
412 | absFile.prepend( QString( IPKG_CONF_DIR ) + "/" ); | 482 | absFile.prepend( QString( IPKG_CONF_DIR ) + "/" ); |
413 | 483 | ||
414 | // Read in file | 484 | // Read in file |
415 | QFile f( absFile ); | 485 | QFile f( absFile ); |
416 | if ( f.open( IO_ReadOnly ) ) | 486 | if ( f.open( IO_ReadOnly ) ) |
417 | { | 487 | { |
418 | QTextStream s( &f ); | 488 | QTextStream s( &f ); |
419 | while ( !s.eof() ) | 489 | while ( !s.eof() ) |
420 | { | 490 | { |
421 | 491 | ||
422 | QString line = s.readLine().simplifyWhiteSpace(); | 492 | QString line = s.readLine().simplifyWhiteSpace(); |
423 | 493 | ||
424 | // Parse line and save info to the conf options list | 494 | // Parse line and save info to the conf options list |
425 | if ( !line.isEmpty() ) | 495 | if ( !line.isEmpty() ) |
426 | { | 496 | { |
427 | if ( !line.startsWith( "#" ) || | 497 | if ( !line.startsWith( "#" ) || |
428 | line.startsWith( "#src" ) || | 498 | line.startsWith( "#src" ) || |
429 | line.startsWith( "#dest" ) || | 499 | line.startsWith( "#dest" ) || |
430 | line.startsWith( "#arch" ) || | 500 | line.startsWith( "#arch" ) || |
431 | line.startsWith( "#option" ) ) | 501 | line.startsWith( "#option" ) ) |
432 | { | 502 | { |
433 | int pos = line.find( ' ', 1 ); | 503 | int pos = line.find( ' ', 1 ); |
434 | 504 | ||
435 | // Type | 505 | // Type |
436 | QString typeStr = line.left( pos ); | 506 | QString typeStr = line.left( pos ); |
437 | OConfItem::Type type; | 507 | OConfItem::Type type; |
438 | if ( typeStr == "src" || typeStr == "#src" ) | 508 | if ( typeStr == "src" || typeStr == "#src" ) |
439 | type = OConfItem::Source; | 509 | type = OConfItem::Source; |
440 | else if ( typeStr == "dest" || typeStr == "#dest" ) | 510 | else if ( typeStr == "dest" || typeStr == "#dest" ) |
441 | type = OConfItem::Destination; | 511 | type = OConfItem::Destination; |
442 | else if ( typeStr == "option" || typeStr == "#option" ) | 512 | else if ( typeStr == "option" || typeStr == "#option" ) |
443 | type = OConfItem::Option; | 513 | type = OConfItem::Option; |
444 | else if ( typeStr == "arch" || typeStr == "#arch" ) | 514 | else if ( typeStr == "arch" || typeStr == "#arch" ) |
445 | type = OConfItem::Arch; | 515 | type = OConfItem::Arch; |
446 | else | 516 | else |
447 | type = OConfItem::NotDefined; | 517 | type = OConfItem::NotDefined; |
448 | ++pos; | 518 | ++pos; |
449 | int endpos = line.find( ' ', pos ); | 519 | int endpos = line.find( ' ', pos ); |
450 | 520 | ||
451 | // Name | 521 | // Name |
452 | QString name = line.mid( pos, endpos - pos ); | 522 | QString name = line.mid( pos, endpos - pos ); |
453 | 523 | ||
454 | // Value | 524 | // Value |
455 | QString value = ""; | 525 | QString value = ""; |
456 | if ( endpos > -1 ) | 526 | if ( endpos > -1 ) |
457 | value = line.right( line.length() - endpos - 1 ); | 527 | value = line.right( line.length() - endpos - 1 ); |
458 | 528 | ||
459 | // Active | 529 | // Active |
460 | bool active = !line.startsWith( "#" ); | 530 | bool active = !line.startsWith( "#" ); |
461 | 531 | ||
462 | // Add to list | 532 | // Add to list |
463 | m_confInfo->append( new OConfItem( absFile, type, name, value, active ) ); | 533 | m_confInfo->append( new OConfItem( absFile, type, name, value, active ) ); |
464 | } | 534 | } |
465 | } | 535 | } |
466 | } | 536 | } |
467 | 537 | ||
468 | f.close(); | 538 | f.close(); |
469 | } | 539 | } |
470 | } | 540 | } |
471 | } | 541 | } |
472 | 542 | ||
473 | // Load Ipkg execution options from application configuration file | 543 | // Load Ipkg execution options from application configuration file |
474 | if ( m_config ) | 544 | if ( m_config ) |
475 | { | 545 | { |
476 | m_config->setGroup( "Ipkg" ); | 546 | m_config->setGroup( "Ipkg" ); |
477 | m_ipkgExecOptions = m_config->readNumEntry( "ExecOptions", m_ipkgExecOptions ); | 547 | m_ipkgExecOptions = m_config->readNumEntry( "ExecOptions", m_ipkgExecOptions ); |
478 | m_ipkgExecVerbosity = m_config->readNumEntry( "Verbosity", m_ipkgExecVerbosity ); | 548 | m_ipkgExecVerbosity = m_config->readNumEntry( "Verbosity", m_ipkgExecVerbosity ); |
479 | } | 549 | } |
480 | } | 550 | } |
481 | 551 | ||
482 | OConfItemList *OIpkg::filterConfItems( OConfItem::Type typefilter ) | 552 | OConfItemList *OIpkg::filterConfItems( OConfItem::Type typefilter ) |
483 | { | 553 | { |
484 | // Load Ipkg configuration info if not already cached | 554 | // Load Ipkg configuration info if not already cached |
485 | if ( !m_confInfo ) | 555 | if ( !m_confInfo ) |
486 | loadConfiguration(); | 556 | loadConfiguration(); |
487 | 557 | ||
488 | // Build new server list (caller is responsible for deleting) | 558 | // Build new server list (caller is responsible for deleting) |
489 | OConfItemList *sl = new OConfItemList; | 559 | OConfItemList *sl = new OConfItemList; |
490 | 560 | ||
491 | // If typefilter is empty, retrieve all items | 561 | // If typefilter is empty, retrieve all items |
492 | bool retrieveAll = ( typefilter == OConfItem::NotDefined ); | 562 | bool retrieveAll = ( typefilter == OConfItem::NotDefined ); |
493 | 563 | ||
494 | // Parse configuration info for servers | 564 | // Parse configuration info for servers |
495 | OConfItemListIterator it( *m_confInfo ); | 565 | OConfItemListIterator it( *m_confInfo ); |
496 | for ( ; it.current(); ++it ) | 566 | for ( ; it.current(); ++it ) |
497 | { | 567 | { |
498 | OConfItem *item = it.current(); | 568 | OConfItem *item = it.current(); |
499 | if ( retrieveAll || item->type() == typefilter ) | 569 | if ( retrieveAll || item->type() == typefilter ) |
500 | { | 570 | { |
501 | sl->append( item ); | 571 | sl->append( item ); |
502 | } | 572 | } |
503 | } | 573 | } |