author | drw <drw> | 2004-07-31 16:57:09 (UTC) |
---|---|---|
committer | drw <drw> | 2004-07-31 16:57:09 (UTC) |
commit | bc85059dbd265feb3424215a2c1a4818af7d069e (patch) (side-by-side diff) | |
tree | 6200d0188ac374741fdcd0019e68227a5a966892 | |
parent | b099a3dd18571fcbd5b1211f18ac111ec39f9ce8 (diff) | |
download | opie-bc85059dbd265feb3424215a2c1a4818af7d069e.zip opie-bc85059dbd265feb3424215a2c1a4818af7d069e.tar.gz opie-bc85059dbd265feb3424215a2c1a4818af7d069e.tar.bz2 |
Read ipkg.conf even when /etc/ipkg does not exist, found by Bernardo...thanks\!
-rw-r--r-- | noncore/settings/packagemanager/oipkg.cpp | 114 |
1 files changed, 57 insertions, 57 deletions
diff --git a/noncore/settings/packagemanager/oipkg.cpp b/noncore/settings/packagemanager/oipkg.cpp index 87a30bb..eca5861 100644 --- a/noncore/settings/packagemanager/oipkg.cpp +++ b/noncore/settings/packagemanager/oipkg.cpp @@ -280,295 +280,295 @@ OPackageList *OIpkg::installedPackages( const QString &destName, const QString & // Build new server list (caller is responsible for deleting) OPackageList *pl = new OPackageList; // Open status file QString path = destPath; if ( path.right( 1 ) != "/" ) path.append( "/" ); path.append( IPKG_STATUS_PATH ); QFile f( path ); if ( !f.open( IO_ReadOnly ) ) return NULL; QTextStream t( &f ); // Process all information in status file bool newPackage = false; QString line = t.readLine(); QString name; QString version; QString status; 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 ( newPackage && !key.isEmpty() ) { // Add to list only if it has a valid name and is installed if ( !name.isNull() && status.contains( " installed" ) ) { pl->append( new OPackage( name, QString::null, version, QString::null, destName ) ); name = QString::null; version = QString::null; status = QString::null; newPackage = false; } } // Update package data if ( key == "Package" ) name = value; else if ( key == "Version" ) version = value; else if ( key == "Status" ) status = value; else if ( key.isEmpty() && value.isEmpty() ) newPackage = true; // Skip past all description lines if ( key == "Description" ) { line = t.readLine(); while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() ) line = t.readLine(); } else line = t.readLine(); } f.close(); return pl; } bool OIpkg::executeCommand( OPackage::Command command, QStringList *parameters, const QString &destination, const QObject *receiver, const char *slotOutput, bool rawOutput ) { if ( command == OPackage::NotDefined ) return false; // Set ipkg run-time options/arguments m_ipkgArgs.force_depends = ( m_ipkgExecOptions & FORCE_DEPENDS ); m_ipkgArgs.force_reinstall = ( m_ipkgExecOptions & FORCE_REINSTALL ); // TODO m_ipkgArgs.force_remove = ( m_ipkgExecOptions & FORCE_REMOVE ); m_ipkgArgs.force_overwrite = ( m_ipkgExecOptions & FORCE_OVERWRITE ); m_ipkgArgs.verbosity = m_ipkgExecVerbosity; if ( m_ipkgArgs.dest ) free( m_ipkgArgs.dest ); if ( !destination.isNull() ) { int len = destination.length() + 1; m_ipkgArgs.dest = (char *)malloc( len ); strncpy( m_ipkgArgs.dest, destination, destination.length() ); m_ipkgArgs.dest[ len - 1 ] = '\0'; } else m_ipkgArgs.dest = 0x0; // Connect output signal to widget if ( rawOutput ) { // if ( slotOutput ) // connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); } else { // TODO - connect to local slot and parse output before emitting signalIpkgMessage } switch( command ) { case OPackage::Update : { connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); ipkg_lists_update( &m_ipkgArgs ); }; break; case OPackage::Upgrade : { connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); ipkg_packages_upgrade( &m_ipkgArgs ); }; break; case OPackage::Install : { connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) { ipkg_packages_install( &m_ipkgArgs, (*it) ); } }; break; 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; + } + confFiles << IPKG_CONF; - QStringList::Iterator lastFile = confFiles.end(); - for ( QStringList::Iterator it = confFiles.begin(); it != lastFile; ++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 ) ) { - // 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() ) { - QTextStream s( &f ); - while ( !s.eof() ) - { - QString line = s.readLine().simplifyWhiteSpace(); + QString line = s.readLine().simplifyWhiteSpace(); - // Parse line and save info to the conf options list - if ( !line.isEmpty() ) + // 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" ) ) { - 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( type, name, value, active ) ); - } + 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( type, name, value, active ) ); } } - - f.close(); } + + f.close(); } } // Load Ipkg execution options from application configuration file if ( m_config ) { m_config->setGroup( "Ipkg" ); m_ipkgExecOptions = m_config->readNumEntry( "ExecOptions", m_ipkgExecOptions ); m_ipkgExecVerbosity = m_config->readNumEntry( "Verbosity", m_ipkgExecVerbosity ); } } OConfItemList *OIpkg::filterConfItems( OConfItem::Type typefilter ) { // Load Ipkg configuration info if not already cached if ( !m_confInfo ) loadConfiguration(); // Build new server list (caller is responsible for deleting) OConfItemList *sl = new OConfItemList; // If typefilter is empty, retrieve all items bool retrieveAll = ( typefilter == OConfItem::NotDefined ); // Parse configuration info for servers OConfItemListIterator it( *m_confInfo ); for ( ; it.current(); ++it ) { OConfItem *item = it.current(); if ( retrieveAll || item->type() == typefilter ) { sl->append( item ); } } return sl; } |