Diffstat (limited to 'noncore/settings/packagemanager/oipkg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/packagemanager/oipkg.cpp | 117 |
1 files changed, 71 insertions, 46 deletions
diff --git a/noncore/settings/packagemanager/oipkg.cpp b/noncore/settings/packagemanager/oipkg.cpp index e7e292e..3d2c621 100644 --- a/noncore/settings/packagemanager/oipkg.cpp +++ b/noncore/settings/packagemanager/oipkg.cpp @@ -139,52 +139,63 @@ void OIpkg::setConfigItems( OConfItemList *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; + QString name = item->name(); if ( !item->active() ) confLine = "#"; switch ( item->type() ) { case OConfItem::Source : { if ( item->features().contains( "Compressed" ) ) - confLine.append( "src/gz " ); + confLine.append( "src/gz" ); else - confLine.append( "src " ); + 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; + case OConfItem::Other : + { + // For options w/type = Other, the mapping is as follows: + // name = typeStr (e.g. "lists_dir") + // value = value + // features = name (from configuration file) + confLine.append( item->name() ); + name = item->features(); } 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"; + confStream << confLine << " " << 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() ) { @@ -532,76 +543,90 @@ void OIpkg::loadConfiguration() 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" ) ) + // Strip leading comment marker if exists + bool comment = false; + if ( line.startsWith( "#" ) ) { - int pos = line.find( ' ', 1 ); - - // Type - QString typeStr = line.left( pos ); - OConfItem::Type type; - QString features; - if ( typeStr == "src" || typeStr == "#src" ) - type = OConfItem::Source; - else if ( typeStr == "src/gz" || typeStr == "#src/gz" ) - { - type = OConfItem::Source; - features = "Compressed"; - } - 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 ); + line.remove( 0, 1 ); + line = line.simplifyWhiteSpace(); + comment = true; + } - // Active - bool active = !line.startsWith( "#" ); + bool recognizedOption = true; + int pos = line.find( ' ', 1 ) + 1; + 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 = !comment; + + // Type + // For options w/type = Other, the mapping is as follows: + // name = typeStr (e.g. "lists_dir") + // value = value + // features = name (from configuration file) + + QString typeStr = line.left( pos - 1 ); + OConfItem::Type type; + QString features; + if ( typeStr == "src" ) + type = OConfItem::Source; + else if ( typeStr == "src/gz" ) + { + type = OConfItem::Source; + features = "Compressed"; + } + else if ( typeStr == "dest" ) + type = OConfItem::Destination; + else if ( typeStr == "option" ) + type = OConfItem::Option; + else if ( typeStr == "arch" ) + type = OConfItem::Arch; + else if ( typeStr == "lists_dir" ) + { + type = OConfItem::Other; + features = name; + name = typeStr; + } + else + recognizedOption = false; - // Add to list + // Add to list + if ( recognizedOption ) m_confInfo->append( new OConfItem( type, name, value, features, active ) ); - } } } 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 ); } } |