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