summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/packagemanager/oipkg.cpp72
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
@@ -107,48 +107,117 @@ OConfItemList *OIpkg::configItems()
107OConfItemList *OIpkg::servers() 107OConfItemList *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
113OConfItemList *OIpkg::destinations() 113OConfItemList *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
119OConfItemList *OIpkg::options() 119OConfItemList *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
125void OIpkg::setConfigItems( OConfItemList *configList ) 125void 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
190printf( "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
133void OIpkg::saveSettings() 202void 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
144OPackageList *OIpkg::availablePackages( const QString &server ) 213OPackageList *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 );
@@ -383,49 +452,50 @@ void OIpkg::ipkgStatus( char *status )
383} 452}
384 453
385void OIpkg::ipkgList( char *filelist ) 454void OIpkg::ipkgList( char *filelist )
386{ 455{
387 emit signalIpkgList( filelist ); 456 emit signalIpkgList( filelist );
388} 457}
389 458
390void OIpkg::loadConfiguration() 459void 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" ) )