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