author | drw <drw> | 2004-04-21 15:57:19 (UTC) |
---|---|---|
committer | drw <drw> | 2004-04-21 15:57:19 (UTC) |
commit | 5ac20617216e4592685940ede23f135d86e8d2cd (patch) (unidiff) | |
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 | |||
@@ -1,506 +1,576 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (c) 2003 Dan Williams <drw@handhelds.org> | 4 | Copyright (c) 2003 Dan Williams <drw@handhelds.org> |
5 | =. | 5 | =. |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | 29 | ||
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include "oipkg.h" | 32 | #include "oipkg.h" |
33 | 33 | ||
34 | #include <stdlib.h> | 34 | #include <stdlib.h> |
35 | #include <string.h> | 35 | #include <string.h> |
36 | 36 | ||
37 | #include <qdir.h> | 37 | #include <qdir.h> |
38 | #include <qfile.h> | 38 | #include <qfile.h> |
39 | #include <qtextstream.h> | 39 | #include <qtextstream.h> |
40 | 40 | ||
41 | const QString IPKG_CONF = "/etc/ipkg.conf"; // Fully-qualified name of Ipkg primary configuration file | 41 | const QString IPKG_CONF = "/etc/ipkg.conf"; // Fully-qualified name of Ipkg primary configuration file |
42 | const QString IPKG_CONF_DIR = "/etc/ipkg"; // Directory of secondary Ipkg configuration files | 42 | const QString IPKG_CONF_DIR = "/etc/ipkg"; // Directory of secondary Ipkg configuration files |
43 | const QString IPKG_PKG_PATH = "/usr/lib/ipkg/lists"; // Directory containing server package lists | 43 | const QString IPKG_PKG_PATH = "/usr/lib/ipkg/lists"; // Directory containing server package lists |
44 | const QString IPKG_STATUS_PATH = "usr/lib/ipkg/status"; // Destination status file location | 44 | const QString IPKG_STATUS_PATH = "usr/lib/ipkg/status"; // Destination status file location |
45 | 45 | ||
46 | OIpkg *oipkg; | 46 | OIpkg *oipkg; |
47 | 47 | ||
48 | // Ipkg callback functions | 48 | // Ipkg callback functions |
49 | 49 | ||
50 | int fsignalIpkgMessage( ipkg_conf_t */*conf*/, message_level_t /*level*/, char *msg ) | 50 | int fsignalIpkgMessage( ipkg_conf_t */*conf*/, message_level_t /*level*/, char *msg ) |
51 | { | 51 | { |
52 | oipkg->ipkgMessage( msg ); | 52 | oipkg->ipkgMessage( msg ); |
53 | return 0; | 53 | return 0; |
54 | } | 54 | } |
55 | 55 | ||
56 | char *fIpkgResponse( char */*question*/ ) | 56 | char *fIpkgResponse( char */*question*/ ) |
57 | { | 57 | { |
58 | return 0x0; | 58 | return 0x0; |
59 | } | 59 | } |
60 | 60 | ||
61 | int fIpkgStatus( char */*name*/, int /*status*/, char *desc, void */*userdata*/ ) | 61 | int fIpkgStatus( char */*name*/, int /*status*/, char *desc, void */*userdata*/ ) |
62 | { | 62 | { |
63 | oipkg->ipkgStatus( desc ); | 63 | oipkg->ipkgStatus( desc ); |
64 | return 0; | 64 | return 0; |
65 | } | 65 | } |
66 | 66 | ||
67 | int fIpkgFiles( char */*name*/, char *desc, char */*version*/, pkg_state_status_t /*status*/, | 67 | int fIpkgFiles( char */*name*/, char *desc, char */*version*/, pkg_state_status_t /*status*/, |
68 | void */*userdata*/ ) | 68 | void */*userdata*/ ) |
69 | { | 69 | { |
70 | oipkg->ipkgList( desc ); | 70 | oipkg->ipkgList( desc ); |
71 | return 0; | 71 | return 0; |
72 | } | 72 | } |
73 | 73 | ||
74 | OIpkg::OIpkg( Config *config, QObject *parent, const char *name ) | 74 | OIpkg::OIpkg( Config *config, QObject *parent, const char *name ) |
75 | : QObject( parent, name ) | 75 | : QObject( parent, name ) |
76 | , m_config( config ) | 76 | , m_config( config ) |
77 | , m_confInfo( NULL ) | 77 | , m_confInfo( NULL ) |
78 | , m_ipkgExecOptions( 0 ) | 78 | , m_ipkgExecOptions( 0 ) |
79 | , m_ipkgExecVerbosity( 1 ) | 79 | , m_ipkgExecVerbosity( 1 ) |
80 | { | 80 | { |
81 | oipkg = this; | 81 | oipkg = this; |
82 | 82 | ||
83 | // Initialize libipkg | 83 | // Initialize libipkg |
84 | ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs ); | 84 | ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs ); |
85 | 85 | ||
86 | // Default ipkg run-time arguments | 86 | // Default ipkg run-time arguments |
87 | m_ipkgArgs.noaction = false; | 87 | m_ipkgArgs.noaction = false; |
88 | m_ipkgArgs.force_defaults = true; | 88 | m_ipkgArgs.force_defaults = true; |
89 | } | 89 | } |
90 | 90 | ||
91 | OIpkg::~OIpkg() | 91 | OIpkg::~OIpkg() |
92 | { | 92 | { |
93 | // Upon destruction, ensure that items in config list are deleted with list | 93 | // Upon destruction, ensure that items in config list are deleted with list |
94 | if ( m_confInfo ) | 94 | if ( m_confInfo ) |
95 | m_confInfo->setAutoDelete( true ); | 95 | m_confInfo->setAutoDelete( true ); |
96 | 96 | ||
97 | // Free up libipkg resources | 97 | // Free up libipkg resources |
98 | ipkg_deinit( &m_ipkgArgs ); | 98 | ipkg_deinit( &m_ipkgArgs ); |
99 | } | 99 | } |
100 | 100 | ||
101 | OConfItemList *OIpkg::configItems() | 101 | OConfItemList *OIpkg::configItems() |
102 | { | 102 | { |
103 | // Retrieve all configuration items | 103 | // Retrieve all configuration items |
104 | return filterConfItems(); | 104 | return filterConfItems(); |
105 | } | 105 | } |
106 | 106 | ||
107 | OConfItemList *OIpkg::servers() | 107 | OConfItemList *OIpkg::servers() |
108 | { | 108 | { |
109 | // Retrieve only servers | 109 | // Retrieve only servers |
110 | return filterConfItems( OConfItem::Source ); | 110 | return filterConfItems( OConfItem::Source ); |
111 | } | 111 | } |
112 | 112 | ||
113 | OConfItemList *OIpkg::destinations() | 113 | OConfItemList *OIpkg::destinations() |
114 | { | 114 | { |
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 |
147 | if ( !m_confInfo ) | 216 | if ( !m_confInfo ) |
148 | loadConfiguration(); | 217 | loadConfiguration(); |
149 | 218 | ||
150 | // Build new server list (caller is responsible for deleting) | 219 | // Build new server list (caller is responsible for deleting) |
151 | OPackageList *pl = new OPackageList; | 220 | OPackageList *pl = new OPackageList; |
152 | 221 | ||
153 | // Open package list file | 222 | // Open package list file |
154 | QFile f( IPKG_PKG_PATH + "/" + server ); | 223 | QFile f( IPKG_PKG_PATH + "/" + server ); |
155 | if ( !f.open( IO_ReadOnly ) ) | 224 | if ( !f.open( IO_ReadOnly ) ) |
156 | return NULL; | 225 | return NULL; |
157 | QTextStream t( &f ); | 226 | QTextStream t( &f ); |
158 | 227 | ||
159 | // Process all information in package list file | 228 | // Process all information in package list file |
160 | OPackage *package = NULL; | 229 | OPackage *package = NULL; |
161 | QString line = t.readLine(); | 230 | QString line = t.readLine(); |
162 | while ( !t.eof() ) | 231 | while ( !t.eof() ) |
163 | { | 232 | { |
164 | // Determine key/value pair | 233 | // Determine key/value pair |
165 | int pos = line.find( ':', 0 ); | 234 | int pos = line.find( ':', 0 ); |
166 | QString key; | 235 | QString key; |
167 | if ( pos > -1 ) | 236 | if ( pos > -1 ) |
168 | key = line.mid( 0, pos ); | 237 | key = line.mid( 0, pos ); |
169 | else | 238 | else |
170 | key = QString::null; | 239 | key = QString::null; |
171 | QString value = line.mid( pos+2, line.length()-pos ); | 240 | QString value = line.mid( pos+2, line.length()-pos ); |
172 | 241 | ||
173 | // Allocate new package and insert into list | 242 | // Allocate new package and insert into list |
174 | if ( package == NULL && !key.isEmpty() ) | 243 | if ( package == NULL && !key.isEmpty() ) |
175 | { | 244 | { |
176 | package = new OPackage( value ); | 245 | package = new OPackage( value ); |
177 | package->setSource( server ); | 246 | package->setSource( server ); |
178 | pl->append( package ); | 247 | pl->append( package ); |
179 | } | 248 | } |
180 | 249 | ||
181 | // Update package data | 250 | // Update package data |
182 | if ( key == "Package" ) | 251 | if ( key == "Package" ) |
183 | package->setName( value ); | 252 | package->setName( value ); |
184 | else if ( key == "Version" ) | 253 | else if ( key == "Version" ) |
185 | package->setVersion( value ); | 254 | package->setVersion( value ); |
186 | else if ( key == "Section" ) | 255 | else if ( key == "Section" ) |
187 | package->setCategory( value ); | 256 | package->setCategory( value ); |
188 | //DataManager::setAvailableCategories( value ); | 257 | //DataManager::setAvailableCategories( value ); |
189 | else if ( key.isEmpty() && value.isEmpty() ) | 258 | else if ( key.isEmpty() && value.isEmpty() ) |
190 | package = NULL; | 259 | package = NULL; |
191 | 260 | ||
192 | // Skip past all description lines | 261 | // Skip past all description lines |
193 | if ( key == "Description" ) | 262 | if ( key == "Description" ) |
194 | { | 263 | { |
195 | line = t.readLine(); | 264 | line = t.readLine(); |
196 | while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() ) | 265 | while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() ) |
197 | line = t.readLine(); | 266 | line = t.readLine(); |
198 | } | 267 | } |
199 | else | 268 | else |
200 | line = t.readLine(); | 269 | line = t.readLine(); |
201 | } | 270 | } |
202 | 271 | ||
203 | f.close(); | 272 | f.close(); |
204 | 273 | ||
205 | return pl; | 274 | return pl; |
206 | } | 275 | } |
207 | 276 | ||
208 | OPackageList *OIpkg::installedPackages( const QString &destName, const QString &destPath ) | 277 | OPackageList *OIpkg::installedPackages( const QString &destName, const QString &destPath ) |
209 | { | 278 | { |
210 | // Load Ipkg configuration info if not already cached | 279 | // Load Ipkg configuration info if not already cached |
211 | if ( !m_confInfo ) | 280 | if ( !m_confInfo ) |
212 | loadConfiguration(); | 281 | loadConfiguration(); |
213 | 282 | ||
214 | // Build new server list (caller is responsible for deleting) | 283 | // Build new server list (caller is responsible for deleting) |
215 | OPackageList *pl = new OPackageList; | 284 | OPackageList *pl = new OPackageList; |
216 | 285 | ||
217 | // Open status file | 286 | // Open status file |
218 | QString path = destPath; | 287 | QString path = destPath; |
219 | if ( path.right( 1 ) != "/" ) | 288 | if ( path.right( 1 ) != "/" ) |
220 | path.append( "/" ); | 289 | path.append( "/" ); |
221 | path.append( IPKG_STATUS_PATH ); | 290 | path.append( IPKG_STATUS_PATH ); |
222 | 291 | ||
223 | QFile f( path ); | 292 | QFile f( path ); |
224 | if ( !f.open( IO_ReadOnly ) ) | 293 | if ( !f.open( IO_ReadOnly ) ) |
225 | return NULL; | 294 | return NULL; |
226 | QTextStream t( &f ); | 295 | QTextStream t( &f ); |
227 | 296 | ||
228 | // Process all information in status file | 297 | // Process all information in status file |
229 | bool newPackage = false; | 298 | bool newPackage = false; |
230 | QString line = t.readLine(); | 299 | QString line = t.readLine(); |
231 | QString name; | 300 | QString name; |
232 | QString version; | 301 | QString version; |
233 | QString status; | 302 | QString status; |
234 | 303 | ||
235 | while ( !t.eof() ) | 304 | while ( !t.eof() ) |
236 | { | 305 | { |
237 | // Determine key/value pair | 306 | // Determine key/value pair |
238 | int pos = line.find( ':', 0 ); | 307 | int pos = line.find( ':', 0 ); |
239 | QString key; | 308 | QString key; |
240 | if ( pos > -1 ) | 309 | if ( pos > -1 ) |
241 | key = line.mid( 0, pos ); | 310 | key = line.mid( 0, pos ); |
242 | else | 311 | else |
243 | key = QString::null; | 312 | key = QString::null; |
244 | QString value = line.mid( pos+2, line.length()-pos ); | 313 | QString value = line.mid( pos+2, line.length()-pos ); |
245 | 314 | ||
246 | // Allocate new package and insert into list | 315 | // Allocate new package and insert into list |
247 | if ( newPackage && !key.isEmpty() ) | 316 | if ( newPackage && !key.isEmpty() ) |
248 | { | 317 | { |
249 | // Add to list only if it has a valid name and is installed | 318 | // Add to list only if it has a valid name and is installed |
250 | if ( !name.isNull() && status.contains( " installed" ) ) | 319 | if ( !name.isNull() && status.contains( " installed" ) ) |
251 | { | 320 | { |
252 | pl->append( new OPackage( name, QString::null, version, QString::null, destName ) ); | 321 | pl->append( new OPackage( name, QString::null, version, QString::null, destName ) ); |
253 | name = QString::null; | 322 | name = QString::null; |
254 | version = QString::null; | 323 | version = QString::null; |
255 | status = QString::null; | 324 | status = QString::null; |
256 | 325 | ||
257 | newPackage = false; | 326 | newPackage = false; |
258 | } | 327 | } |
259 | } | 328 | } |
260 | 329 | ||
261 | // Update package data | 330 | // Update package data |
262 | if ( key == "Package" ) | 331 | if ( key == "Package" ) |
263 | name = value; | 332 | name = value; |
264 | else if ( key == "Version" ) | 333 | else if ( key == "Version" ) |
265 | version = value; | 334 | version = value; |
266 | else if ( key == "Status" ) | 335 | else if ( key == "Status" ) |
267 | status = value; | 336 | status = value; |
268 | else if ( key.isEmpty() && value.isEmpty() ) | 337 | else if ( key.isEmpty() && value.isEmpty() ) |
269 | newPackage = true; | 338 | newPackage = true; |
270 | 339 | ||
271 | // Skip past all description lines | 340 | // Skip past all description lines |
272 | if ( key == "Description" ) | 341 | if ( key == "Description" ) |
273 | { | 342 | { |
274 | line = t.readLine(); | 343 | line = t.readLine(); |
275 | while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() ) | 344 | while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() ) |
276 | line = t.readLine(); | 345 | line = t.readLine(); |
277 | } | 346 | } |
278 | else | 347 | else |
279 | line = t.readLine(); | 348 | line = t.readLine(); |
280 | } | 349 | } |
281 | 350 | ||
282 | f.close(); | 351 | f.close(); |
283 | 352 | ||
284 | return pl; | 353 | return pl; |
285 | } | 354 | } |
286 | 355 | ||
287 | bool OIpkg::executeCommand( OPackage::Command command, QStringList *parameters, const QString &destination, | 356 | bool OIpkg::executeCommand( OPackage::Command command, QStringList *parameters, const QString &destination, |
288 | const QObject *receiver, const char *slotOutput, bool rawOutput ) | 357 | const QObject *receiver, const char *slotOutput, bool rawOutput ) |
289 | { | 358 | { |
290 | if ( command == OPackage::NotDefined ) | 359 | if ( command == OPackage::NotDefined ) |
291 | return false; | 360 | return false; |
292 | 361 | ||
293 | // Set ipkg run-time options/arguments | 362 | // Set ipkg run-time options/arguments |
294 | m_ipkgArgs.force_depends = ( m_ipkgExecOptions & FORCE_DEPENDS ); | 363 | m_ipkgArgs.force_depends = ( m_ipkgExecOptions & FORCE_DEPENDS ); |
295 | m_ipkgArgs.force_reinstall = ( m_ipkgExecOptions & FORCE_REINSTALL ); | 364 | m_ipkgArgs.force_reinstall = ( m_ipkgExecOptions & FORCE_REINSTALL ); |
296 | // TODO m_ipkgArgs.force_remove = ( m_ipkgExecOptions & FORCE_REMOVE ); | 365 | // TODO m_ipkgArgs.force_remove = ( m_ipkgExecOptions & FORCE_REMOVE ); |
297 | m_ipkgArgs.force_overwrite = ( m_ipkgExecOptions & FORCE_OVERWRITE ); | 366 | m_ipkgArgs.force_overwrite = ( m_ipkgExecOptions & FORCE_OVERWRITE ); |
298 | m_ipkgArgs.verbosity = m_ipkgExecVerbosity; | 367 | m_ipkgArgs.verbosity = m_ipkgExecVerbosity; |
299 | if ( m_ipkgArgs.dest ) | 368 | if ( m_ipkgArgs.dest ) |
300 | free( m_ipkgArgs.dest ); | 369 | free( m_ipkgArgs.dest ); |
301 | if ( !destination.isNull() ) | 370 | if ( !destination.isNull() ) |
302 | { | 371 | { |
303 | int len = destination.length() + 1; | 372 | int len = destination.length() + 1; |
304 | m_ipkgArgs.dest = (char *)malloc( len ); | 373 | m_ipkgArgs.dest = (char *)malloc( len ); |
305 | strncpy( m_ipkgArgs.dest, destination, destination.length() ); | 374 | strncpy( m_ipkgArgs.dest, destination, destination.length() ); |
306 | m_ipkgArgs.dest[ len - 1 ] = '\0'; | 375 | m_ipkgArgs.dest[ len - 1 ] = '\0'; |
307 | } | 376 | } |
308 | else | 377 | else |
309 | m_ipkgArgs.dest = 0x0; | 378 | m_ipkgArgs.dest = 0x0; |
310 | 379 | ||
311 | // Connect output signal to widget | 380 | // Connect output signal to widget |
312 | 381 | ||
313 | if ( rawOutput ) | 382 | if ( rawOutput ) |
314 | { | 383 | { |
315 | // if ( slotOutput ) | 384 | // if ( slotOutput ) |
316 | // connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); | 385 | // connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); |
317 | } | 386 | } |
318 | else | 387 | else |
319 | { | 388 | { |
320 | // TODO - connect to local slot and parse output before emitting signalIpkgMessage | 389 | // TODO - connect to local slot and parse output before emitting signalIpkgMessage |
321 | } | 390 | } |
322 | 391 | ||
323 | switch( command ) | 392 | switch( command ) |
324 | { | 393 | { |
325 | case OPackage::Update : { | 394 | case OPackage::Update : { |
326 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); | 395 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); |
327 | ipkg_lists_update( &m_ipkgArgs ); | 396 | ipkg_lists_update( &m_ipkgArgs ); |
328 | }; | 397 | }; |
329 | break; | 398 | break; |
330 | case OPackage::Upgrade : { | 399 | case OPackage::Upgrade : { |
331 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); | 400 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); |
332 | ipkg_packages_upgrade( &m_ipkgArgs ); | 401 | ipkg_packages_upgrade( &m_ipkgArgs ); |
333 | }; | 402 | }; |
334 | break; | 403 | break; |
335 | case OPackage::Install : { | 404 | case OPackage::Install : { |
336 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); | 405 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); |
337 | for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) | 406 | for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) |
338 | { | 407 | { |
339 | ipkg_packages_install( &m_ipkgArgs, (*it) ); | 408 | ipkg_packages_install( &m_ipkgArgs, (*it) ); |
340 | } | 409 | } |
341 | }; | 410 | }; |
342 | break; | 411 | break; |
343 | case OPackage::Remove : { | 412 | case OPackage::Remove : { |
344 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); | 413 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); |
345 | for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) | 414 | for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) |
346 | { | 415 | { |
347 | ipkg_packages_remove( &m_ipkgArgs, (*it), true ); | 416 | ipkg_packages_remove( &m_ipkgArgs, (*it), true ); |
348 | } | 417 | } |
349 | }; | 418 | }; |
350 | break; | 419 | break; |
351 | case OPackage::Download : { | 420 | case OPackage::Download : { |
352 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); | 421 | connect( this, SIGNAL(signalIpkgMessage(char*)), receiver, slotOutput ); |
353 | for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) | 422 | for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) |
354 | { | 423 | { |
355 | ipkg_packages_download( &m_ipkgArgs, (*it) ); | 424 | ipkg_packages_download( &m_ipkgArgs, (*it) ); |
356 | } | 425 | } |
357 | }; | 426 | }; |
358 | break; | 427 | break; |
359 | case OPackage::Info : { | 428 | case OPackage::Info : { |
360 | connect( this, SIGNAL(signalIpkgStatus(char*)), receiver, slotOutput ); | 429 | connect( this, SIGNAL(signalIpkgStatus(char*)), receiver, slotOutput ); |
361 | ipkg_packages_info( &m_ipkgArgs, (*parameters->begin()), &fIpkgStatus, 0x0 ); | 430 | ipkg_packages_info( &m_ipkgArgs, (*parameters->begin()), &fIpkgStatus, 0x0 ); |
362 | }; | 431 | }; |
363 | break; | 432 | break; |
364 | case OPackage::Files : { | 433 | case OPackage::Files : { |
365 | connect( this, SIGNAL(signalIpkgList(char*)), receiver, slotOutput ); | 434 | connect( this, SIGNAL(signalIpkgList(char*)), receiver, slotOutput ); |
366 | ipkg_package_files( &m_ipkgArgs, (*parameters->begin()), &fIpkgFiles, 0x0 ); | 435 | ipkg_package_files( &m_ipkgArgs, (*parameters->begin()), &fIpkgFiles, 0x0 ); |
367 | }; | 436 | }; |
368 | break; | 437 | break; |
369 | default : break; | 438 | default : break; |
370 | }; | 439 | }; |
371 | 440 | ||
372 | return true; | 441 | return true; |
373 | } | 442 | } |
374 | 443 | ||
375 | void OIpkg::ipkgMessage( char *msg ) | 444 | void OIpkg::ipkgMessage( char *msg ) |
376 | { | 445 | { |
377 | emit signalIpkgMessage( msg ); | 446 | emit signalIpkgMessage( msg ); |
378 | } | 447 | } |
379 | 448 | ||
380 | void OIpkg::ipkgStatus( char *status ) | 449 | void OIpkg::ipkgStatus( char *status ) |
381 | { | 450 | { |
382 | emit signalIpkgStatus( status ); | 451 | emit signalIpkgStatus( status ); |
383 | } | 452 | } |
384 | 453 | ||
385 | void OIpkg::ipkgList( char *filelist ) | 454 | void OIpkg::ipkgList( char *filelist ) |
386 | { | 455 | { |
387 | emit signalIpkgList( filelist ); | 456 | emit signalIpkgList( filelist ); |
388 | } | 457 | } |
389 | 458 | ||
390 | void OIpkg::loadConfiguration() | 459 | 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 | ||
424 | // Parse line and save info to the conf options list | 494 | // Parse line and save info to the conf options list |
425 | if ( !line.isEmpty() ) | 495 | if ( !line.isEmpty() ) |
426 | { | 496 | { |
427 | if ( !line.startsWith( "#" ) || | 497 | if ( !line.startsWith( "#" ) || |
428 | line.startsWith( "#src" ) || | 498 | line.startsWith( "#src" ) || |
429 | line.startsWith( "#dest" ) || | 499 | line.startsWith( "#dest" ) || |
430 | line.startsWith( "#arch" ) || | 500 | line.startsWith( "#arch" ) || |
431 | line.startsWith( "#option" ) ) | 501 | line.startsWith( "#option" ) ) |
432 | { | 502 | { |
433 | int pos = line.find( ' ', 1 ); | 503 | int pos = line.find( ' ', 1 ); |
434 | 504 | ||
435 | // Type | 505 | // Type |
436 | QString typeStr = line.left( pos ); | 506 | QString typeStr = line.left( pos ); |
437 | OConfItem::Type type; | 507 | OConfItem::Type type; |
438 | if ( typeStr == "src" || typeStr == "#src" ) | 508 | if ( typeStr == "src" || typeStr == "#src" ) |
439 | type = OConfItem::Source; | 509 | type = OConfItem::Source; |
440 | else if ( typeStr == "dest" || typeStr == "#dest" ) | 510 | else if ( typeStr == "dest" || typeStr == "#dest" ) |
441 | type = OConfItem::Destination; | 511 | type = OConfItem::Destination; |
442 | else if ( typeStr == "option" || typeStr == "#option" ) | 512 | else if ( typeStr == "option" || typeStr == "#option" ) |
443 | type = OConfItem::Option; | 513 | type = OConfItem::Option; |
444 | else if ( typeStr == "arch" || typeStr == "#arch" ) | 514 | else if ( typeStr == "arch" || typeStr == "#arch" ) |
445 | type = OConfItem::Arch; | 515 | type = OConfItem::Arch; |
446 | else | 516 | else |
447 | type = OConfItem::NotDefined; | 517 | type = OConfItem::NotDefined; |
448 | ++pos; | 518 | ++pos; |
449 | int endpos = line.find( ' ', pos ); | 519 | int endpos = line.find( ' ', pos ); |
450 | 520 | ||
451 | // Name | 521 | // Name |
452 | QString name = line.mid( pos, endpos - pos ); | 522 | QString name = line.mid( pos, endpos - pos ); |
453 | 523 | ||
454 | // Value | 524 | // Value |
455 | QString value = ""; | 525 | QString value = ""; |
456 | if ( endpos > -1 ) | 526 | if ( endpos > -1 ) |
457 | value = line.right( line.length() - endpos - 1 ); | 527 | value = line.right( line.length() - endpos - 1 ); |
458 | 528 | ||
459 | // Active | 529 | // Active |
460 | bool active = !line.startsWith( "#" ); | 530 | bool active = !line.startsWith( "#" ); |
461 | 531 | ||
462 | // Add to list | 532 | // Add to list |
463 | m_confInfo->append( new OConfItem( absFile, type, name, value, active ) ); | 533 | m_confInfo->append( new OConfItem( absFile, type, name, value, active ) ); |
464 | } | 534 | } |
465 | } | 535 | } |
466 | } | 536 | } |
467 | 537 | ||
468 | f.close(); | 538 | f.close(); |
469 | } | 539 | } |
470 | } | 540 | } |
471 | } | 541 | } |
472 | 542 | ||
473 | // Load Ipkg execution options from application configuration file | 543 | // Load Ipkg execution options from application configuration file |
474 | if ( m_config ) | 544 | if ( m_config ) |
475 | { | 545 | { |
476 | m_config->setGroup( "Ipkg" ); | 546 | m_config->setGroup( "Ipkg" ); |
477 | m_ipkgExecOptions = m_config->readNumEntry( "ExecOptions", m_ipkgExecOptions ); | 547 | m_ipkgExecOptions = m_config->readNumEntry( "ExecOptions", m_ipkgExecOptions ); |
478 | m_ipkgExecVerbosity = m_config->readNumEntry( "Verbosity", m_ipkgExecVerbosity ); | 548 | m_ipkgExecVerbosity = m_config->readNumEntry( "Verbosity", m_ipkgExecVerbosity ); |
479 | } | 549 | } |
480 | } | 550 | } |
481 | 551 | ||
482 | OConfItemList *OIpkg::filterConfItems( OConfItem::Type typefilter ) | 552 | OConfItemList *OIpkg::filterConfItems( OConfItem::Type typefilter ) |
483 | { | 553 | { |
484 | // Load Ipkg configuration info if not already cached | 554 | // Load Ipkg configuration info if not already cached |
485 | if ( !m_confInfo ) | 555 | if ( !m_confInfo ) |
486 | loadConfiguration(); | 556 | loadConfiguration(); |
487 | 557 | ||
488 | // Build new server list (caller is responsible for deleting) | 558 | // Build new server list (caller is responsible for deleting) |
489 | OConfItemList *sl = new OConfItemList; | 559 | OConfItemList *sl = new OConfItemList; |
490 | 560 | ||
491 | // If typefilter is empty, retrieve all items | 561 | // If typefilter is empty, retrieve all items |
492 | bool retrieveAll = ( typefilter == OConfItem::NotDefined ); | 562 | bool retrieveAll = ( typefilter == OConfItem::NotDefined ); |
493 | 563 | ||
494 | // Parse configuration info for servers | 564 | // Parse configuration info for servers |
495 | OConfItemListIterator it( *m_confInfo ); | 565 | OConfItemListIterator it( *m_confInfo ); |
496 | for ( ; it.current(); ++it ) | 566 | for ( ; it.current(); ++it ) |
497 | { | 567 | { |
498 | OConfItem *item = it.current(); | 568 | OConfItem *item = it.current(); |
499 | if ( retrieveAll || item->type() == typefilter ) | 569 | if ( retrieveAll || item->type() == typefilter ) |
500 | { | 570 | { |
501 | sl->append( item ); | 571 | sl->append( item ); |
502 | } | 572 | } |
503 | } | 573 | } |
504 | 574 | ||
505 | return sl; | 575 | return sl; |
506 | } | 576 | } |