author | drw <drw> | 2004-04-21 15:57:19 (UTC) |
---|---|---|
committer | drw <drw> | 2004-04-21 15:57:19 (UTC) |
commit | 5ac20617216e4592685940ede23f135d86e8d2cd (patch) (side-by-side diff) | |
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 @@ -67,128 +67,197 @@ int fIpkgStatus( char */*name*/, int /*status*/, char *desc, void */*userdata*/ int fIpkgFiles( char */*name*/, char *desc, char */*version*/, pkg_state_status_t /*status*/, void */*userdata*/ ) { oipkg->ipkgList( desc ); return 0; } OIpkg::OIpkg( Config *config, QObject *parent, const char *name ) : QObject( parent, name ) , m_config( config ) , m_confInfo( NULL ) , m_ipkgExecOptions( 0 ) , m_ipkgExecVerbosity( 1 ) { oipkg = this; // Initialize libipkg ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs ); // Default ipkg run-time arguments m_ipkgArgs.noaction = false; m_ipkgArgs.force_defaults = true; } OIpkg::~OIpkg() { // Upon destruction, ensure that items in config list are deleted with list if ( m_confInfo ) m_confInfo->setAutoDelete( true ); // Free up libipkg resources ipkg_deinit( &m_ipkgArgs ); } OConfItemList *OIpkg::configItems() { // Retrieve all configuration items return filterConfItems(); } OConfItemList *OIpkg::servers() { // Retrieve only servers return filterConfItems( OConfItem::Source ); } OConfItemList *OIpkg::destinations() { // Retrieve only destinations return filterConfItems( OConfItem::Destination ); } OConfItemList *OIpkg::options() { // Retrieve only destinations return filterConfItems( OConfItem::Option ); } void OIpkg::setConfigItems( OConfItemList *configList ) { if ( m_confInfo ) delete m_confInfo; m_confInfo = configList; + + // Write out new /etc/ipkg.conf + QFile confFile( IPKG_CONF ); + if ( confFile.open( IO_WriteOnly ) ) + { + QTextStream confStream( &confFile ); + confStream << "# Generated by Opie Package Manager\n\n"; + + OConfItemListIterator it( *m_confInfo ); + for ( ; it.current(); ++it ) + { + OConfItem *item = it.current(); + + // Only write out valid conf items + if ( item->type() != OConfItem::NotDefined ) + { + QString confLine; + if ( !item->active() ) + confLine = "#"; + + switch ( item->type() ) + { + case OConfItem::Source : confLine.append( "src " ); break; + case OConfItem::Destination : confLine.append( "dest " ); break; + case OConfItem::Option : confLine.append( "option " ); break; + case OConfItem::Arch : confLine.append( "arch " ); break; + default : break; + }; + + confStream << confLine << " " << item->name() << " " << item->value() << "\n"; + } + } + + confFile.close(); + } + else + { + // Problem writing to /etc/ipkg.conf, exit before removing other conf files + return; + } + + // Delete /etc/ipkg/*.conf files (/etc/ipkg.conf should now have all settings + QStringList confFiles; + QDir confDir( IPKG_CONF_DIR ); + if ( confDir.exists() ) + { + confDir.setNameFilter( "*.conf" ); + confDir.setFilter( QDir::Files ); + confFiles = confDir.entryList( "*.conf", QDir::Files ); + + QStringList::Iterator lastFile = confFiles.end(); + for ( QStringList::Iterator it = confFiles.begin(); it != lastFile; ++it ) + { + // Create absolute file path if necessary + QString absFile = (*it); + if ( !absFile.startsWith( "/" ) ) + absFile.prepend( QString( IPKG_CONF_DIR ) + "/" ); + + // Delete file +printf( "Deleting: \'%s\'\n", absFile.latin1() ); + QFile::remove( absFile ); + } + } + + // Reinitialize libipkg to pick up new configuration + ipkg_deinit( &m_ipkgArgs ); + ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs ); + m_ipkgArgs.noaction = false; + m_ipkgArgs.force_defaults = true; } void OIpkg::saveSettings() { // Save Ipkg execution options to application configuration file if ( m_config ) { m_config->setGroup( "Ipkg" ); m_config->writeEntry( "ExecOptions", m_ipkgExecOptions ); m_config->writeEntry( "Verbosity", m_ipkgExecVerbosity ); } } OPackageList *OIpkg::availablePackages( const QString &server ) { // Load Ipkg configuration info if not already cached if ( !m_confInfo ) loadConfiguration(); // Build new server list (caller is responsible for deleting) OPackageList *pl = new OPackageList; // Open package list file QFile f( IPKG_PKG_PATH + "/" + server ); if ( !f.open( IO_ReadOnly ) ) return NULL; QTextStream t( &f ); // Process all information in package list file OPackage *package = NULL; QString line = t.readLine(); while ( !t.eof() ) { // Determine key/value pair int pos = line.find( ':', 0 ); QString key; if ( pos > -1 ) key = line.mid( 0, pos ); else key = QString::null; QString value = line.mid( pos+2, line.length()-pos ); // Allocate new package and insert into list if ( package == NULL && !key.isEmpty() ) { package = new OPackage( value ); package->setSource( server ); pl->append( package ); } // Update package data if ( key == "Package" ) package->setName( value ); else if ( key == "Version" ) package->setVersion( value ); else if ( key == "Section" ) package->setCategory( value ); //DataManager::setAvailableCategories( value ); else if ( key.isEmpty() && value.isEmpty() ) package = NULL; // Skip past all description lines if ( key == "Description" ) { @@ -343,129 +412,130 @@ bool OIpkg::executeCommand( OPackage::Command command, QStringList *parameters, case OPackage::Remove : { connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) { ipkg_packages_remove( &m_ipkgArgs, (*it), true ); } }; break; case OPackage::Download : { connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) { ipkg_packages_download( &m_ipkgArgs, (*it) ); } }; break; case OPackage::Info : { connect( this, SIGNAL(signalIpkgStatus(char*)), receiver, slotOutput ); ipkg_packages_info( &m_ipkgArgs, (*parameters->begin()), &fIpkgStatus, 0x0 ); }; break; case OPackage::Files : { connect( this, SIGNAL(signalIpkgList(char*)), receiver, slotOutput ); ipkg_package_files( &m_ipkgArgs, (*parameters->begin()), &fIpkgFiles, 0x0 ); }; break; default : break; }; return true; } void OIpkg::ipkgMessage( char *msg ) { emit signalIpkgMessage( msg ); } void OIpkg::ipkgStatus( char *status ) { emit signalIpkgStatus( status ); } void OIpkg::ipkgList( char *filelist ) { emit signalIpkgList( filelist ); } void OIpkg::loadConfiguration() { if ( m_confInfo ) delete m_confInfo; // Load configuration item list m_confInfo = new OConfItemList(); QStringList confFiles; QDir confDir( IPKG_CONF_DIR ); if ( confDir.exists() ) { confDir.setNameFilter( "*.conf" ); confDir.setFilter( QDir::Files ); confFiles = confDir.entryList( "*.conf", QDir::Files ); confFiles << IPKG_CONF; - for ( QStringList::Iterator it = confFiles.begin(); it != confFiles.end(); ++it ) + QStringList::Iterator lastFile = confFiles.end(); + for ( QStringList::Iterator it = confFiles.begin(); it != lastFile; ++it ) { // Create absolute file path if necessary QString absFile = (*it); if ( !absFile.startsWith( "/" ) ) absFile.prepend( QString( IPKG_CONF_DIR ) + "/" ); // Read in file QFile f( absFile ); if ( f.open( IO_ReadOnly ) ) { QTextStream s( &f ); while ( !s.eof() ) { QString line = s.readLine().simplifyWhiteSpace(); // Parse line and save info to the conf options list if ( !line.isEmpty() ) { if ( !line.startsWith( "#" ) || line.startsWith( "#src" ) || line.startsWith( "#dest" ) || line.startsWith( "#arch" ) || line.startsWith( "#option" ) ) { int pos = line.find( ' ', 1 ); // Type QString typeStr = line.left( pos ); OConfItem::Type type; if ( typeStr == "src" || typeStr == "#src" ) type = OConfItem::Source; else if ( typeStr == "dest" || typeStr == "#dest" ) type = OConfItem::Destination; else if ( typeStr == "option" || typeStr == "#option" ) type = OConfItem::Option; else if ( typeStr == "arch" || typeStr == "#arch" ) type = OConfItem::Arch; else type = OConfItem::NotDefined; ++pos; int endpos = line.find( ' ', pos ); // Name QString name = line.mid( pos, endpos - pos ); // Value QString value = ""; if ( endpos > -1 ) value = line.right( line.length() - endpos - 1 ); // Active bool active = !line.startsWith( "#" ); // Add to list m_confInfo->append( new OConfItem( absFile, type, name, value, active ) ); } } } f.close(); } } } |