-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 | |||
@@ -115,32 +115,101 @@ OConfItemList *OIpkg::destinations() | |||
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 |
@@ -391,33 +460,34 @@ 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 | ||