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