summaryrefslogtreecommitdiff
authordrw <drw>2004-04-21 15:57:19 (UTC)
committer drw <drw>2004-04-21 15:57:19 (UTC)
commit5ac20617216e4592685940ede23f135d86e8d2cd (patch) (unidiff)
tree17a2ba8adc06eed219b3b77e42d46e5e0c714630
parent4e6c1ec2758d337d772af3af49a1b74f737cd57f (diff)
downloadopie-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
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
@@ -119,24 +119,93 @@ OConfItemList *OIpkg::destinations()
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}
@@ -395,25 +464,26 @@ void OIpkg::loadConfiguration()
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() )