-rw-r--r-- | noncore/settings/aqpkg/server.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/noncore/settings/aqpkg/server.cpp b/noncore/settings/aqpkg/server.cpp index 06b0863..d4fa439 100644 --- a/noncore/settings/aqpkg/server.cpp +++ b/noncore/settings/aqpkg/server.cpp | |||
@@ -1,316 +1,315 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | server.cpp - description | 2 | server.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Aug 26 2002 | 4 | begin : Mon Aug 26 2002 |
5 | copyright : (C) 2002 by Andy Qua | 5 | copyright : (C) 2002 by Andy Qua |
6 | email : andy.qua@blueyonder.co.uk | 6 | email : andy.qua@blueyonder.co.uk |
7 | description : This class holds details about a server | 7 | description : This class holds details about a server |
8 | : e.g. all the packages that contained on the server | 8 | : e.g. all the packages that contained on the server |
9 | : the installation status | 9 | : the installation status |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * * | 13 | * * |
14 | * This program is free software; you can redistribute it and/or modify * | 14 | * This program is free software; you can redistribute it and/or modify * |
15 | * it under the terms of the GNU General Public License as published by * | 15 | * it under the terms of the GNU General Public License as published by * |
16 | * the Free Software Foundation; either version 2 of the License, or * | 16 | * the Free Software Foundation; either version 2 of the License, or * |
17 | * (at your option) any later version. * | 17 | * (at your option) any later version. * |
18 | * * | 18 | * * |
19 | ***************************************************************************/ | 19 | ***************************************************************************/ |
20 | 20 | ||
21 | 21 | ||
22 | #include <stdio.h> | 22 | #include <stdio.h> |
23 | #include <string.h> | 23 | #include <string.h> |
24 | #include <stdlib.h> | 24 | #include <stdlib.h> |
25 | 25 | ||
26 | #include <iostream> | 26 | #include <iostream> |
27 | #include <fstream> | 27 | #include <fstream> |
28 | using namespace std; | 28 | using namespace std; |
29 | 29 | ||
30 | #include "server.h" | 30 | #include "server.h" |
31 | #include "datamgr.h" | 31 | #include "datamgr.h" |
32 | 32 | ||
33 | #ifdef QWS | 33 | #ifdef QWS |
34 | #include <qpe/global.h> | 34 | #include <qpe/global.h> |
35 | #include <qpe/applnk.h> | 35 | #include <qpe/applnk.h> |
36 | #include <qlist.h> | 36 | #include <qlist.h> |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | #include "utils.h" | 39 | #include "utils.h" |
40 | 40 | ||
41 | #include "global.h" | 41 | #include "global.h" |
42 | 42 | ||
43 | Server :: Server( const char *name, const char *url ) | 43 | Server :: Server( const char *name, const char *url ) |
44 | { | 44 | { |
45 | serverName = name; | 45 | serverName = name; |
46 | serverUrl = url; | 46 | serverUrl = url; |
47 | packageFile = IPKG_DIR; | 47 | packageFile = IPKG_DIR; |
48 | active = true; | 48 | active = true; |
49 | packageFile += "lists/" + serverName; | 49 | packageFile += "lists/" + serverName; |
50 | } | 50 | } |
51 | 51 | ||
52 | Server :: ~Server() | 52 | Server :: ~Server() |
53 | { | 53 | { |
54 | cleanUp(); | 54 | cleanUp(); |
55 | } | 55 | } |
56 | 56 | ||
57 | void Server :: cleanUp() | 57 | void Server :: cleanUp() |
58 | { | 58 | { |
59 | packageList.clear(); | 59 | packageList.clear(); |
60 | } | 60 | } |
61 | 61 | ||
62 | void Server :: readStatusFile( QList<Destination> &destList ) | 62 | void Server :: readStatusFile( QList<Destination> &destList ) |
63 | { | 63 | { |
64 | cleanUp(); | 64 | cleanUp(); |
65 | 65 | ||
66 | Destination *dest; | 66 | Destination *dest; |
67 | QListIterator<Destination> dit( destList ); | 67 | QListIterator<Destination> dit( destList ); |
68 | bool rootRead = false; | 68 | bool rootRead = false; |
69 | for ( ; dit.current(); ++dit ) | 69 | for ( ; dit.current(); ++dit ) |
70 | { | 70 | { |
71 | dest = dit.current(); | 71 | dest = dit.current(); |
72 | bool installingToRoot = false; | 72 | bool installingToRoot = false; |
73 | 73 | ||
74 | QString path = dest->getDestinationPath(); | 74 | QString path = dest->getDestinationPath(); |
75 | if ( path.right( 1 ) != "/" ) | 75 | if ( path.right( 1 ) != "/" ) |
76 | path += "/"; | 76 | path += "/"; |
77 | 77 | ||
78 | if ( path == "/" ) | 78 | if ( path == "/" ) |
79 | { | 79 | { |
80 | rootRead = true; | 80 | rootRead = true; |
81 | installingToRoot = true; | 81 | installingToRoot = true; |
82 | } | 82 | } |
83 | 83 | ||
84 | packageFile = path + "usr/lib/ipkg/status"; | 84 | packageFile = path + "usr/lib/ipkg/status"; |
85 | readPackageFile( 0, false, installingToRoot, &( *dest ) ); | 85 | readPackageFile( 0, false, installingToRoot, &( *dest ) ); |
86 | } | 86 | } |
87 | 87 | ||
88 | // Ensure that the root status file is read | 88 | // Ensure that the root status file is read |
89 | if ( !rootRead ) | 89 | if ( !rootRead ) |
90 | { | 90 | { |
91 | cout << "Reading status file " << "/usr/lib/ipkg/status" << endl; | 91 | cout << "Reading status file " << "/usr/lib/ipkg/status" << endl; |
92 | packageFile = "/usr/lib/ipkg/status"; | 92 | packageFile = "/usr/lib/ipkg/status"; |
93 | readPackageFile( 0, false, true ); | 93 | readPackageFile( 0, false, true ); |
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | void Server :: readLocalIpks( Server *local ) | 97 | void Server :: readLocalIpks( Server *local ) |
98 | { | 98 | { |
99 | cleanUp(); | 99 | cleanUp(); |
100 | 100 | ||
101 | #ifdef QWS | 101 | #ifdef QWS |
102 | // First, get any local IPKGs in the documents area | 102 | // First, get any local IPKGs in the documents area |
103 | // Only applicable to Qtopie/Opie | 103 | // Only applicable to Qtopie/Opie |
104 | 104 | ||
105 | DocLnkSet files; | 105 | DocLnkSet files; |
106 | Global::findDocuments( &files, "application/ipkg" ); | 106 | Global::findDocuments( &files, "application/ipkg" ); |
107 | 107 | ||
108 | // Now add the items to the list | 108 | // Now add the items to the list |
109 | QListIterator<DocLnk> it( files.children() ); | 109 | QListIterator<DocLnk> it( files.children() ); |
110 | 110 | ||
111 | for ( ; it.current() ; ++it ) | 111 | for ( ; it.current() ; ++it ) |
112 | { | 112 | { |
113 | // OK, we have a local IPK file, I think the standard naming conventions | 113 | // OK, we have a local IPK file, I think the standard naming conventions |
114 | // for these are packagename_version_arm.ipk | 114 | // for these are packagename_version_arm.ipk |
115 | QString file = (*it)->file(); | 115 | QString file = (*it)->file(); |
116 | 116 | ||
117 | // Changed to display the filename (excluding the path) | 117 | // Changed to display the filename (excluding the path) |
118 | QString packageName = Utils::getFilenameFromIpkFilename( file ); | 118 | QString packageName = Utils::getFilenameFromIpkFilename( file ); |
119 | QString ver = Utils::getPackageVersionFromIpkFilename( file ); | 119 | QString ver = Utils::getPackageVersionFromIpkFilename( file ); |
120 | Package *package = new Package( packageName ); | 120 | Package *package = new Package( packageName ); |
121 | package->setVersion( ver ); | 121 | package->setVersion( ver ); |
122 | package->setFilename( file ); | 122 | package->setFilename( file ); |
123 | package->setPackageStoredLocally( true ); | 123 | package->setPackageStoredLocally( true ); |
124 | packageList.append( package ); | 124 | packageList.append( package ); |
125 | } | 125 | } |
126 | #else | 126 | #else |
127 | QString names[] = { "advancedfm_0.9.1-20020811_arm.ipk", "libopie_0.9.1-20020811_arm.ipk", "libopieobex_0.9.1-20020811.1_arm.ipk", "opie-addressbook_0.9.1-20020811_arm.ipk" }; | 127 | QString names[] = { "advancedfm_0.9.1-20020811_arm.ipk", "libopie_0.9.1-20020811_arm.ipk", "libopieobex_0.9.1-20020811.1_arm.ipk", "opie-addressbook_0.9.1-20020811_arm.ipk" }; |
128 | for ( int i = 0 ; i < 4 ; ++i ) | 128 | for ( int i = 0 ; i < 4 ; ++i ) |
129 | { | 129 | { |
130 | // OK, we have a local IPK file, I think the standard naming conventions | 130 | // OK, we have a local IPK file, I think the standard naming conventions |
131 | // for these are packagename_version_arm.ipk | 131 | // for these are packagename_version_arm.ipk |
132 | QString file = names[i]; | 132 | QString file = names[i]; |
133 | int p = file.find( "_" ); | 133 | int p = file.find( "_" ); |
134 | QString tmp = file.mid( 0, p ); | 134 | QString tmp = file.mid( 0, p ); |
135 | packageList.push_back( Package( tmp ) ); | 135 | packageList.push_back( Package( tmp ) ); |
136 | int p2 = file.find( "_", p+1 ); | 136 | int p2 = file.find( "_", p+1 ); |
137 | tmp = file.mid( p+1, p2-(p+1) ); | 137 | tmp = file.mid( p+1, p2-(p+1) ); |
138 | packageList.back().setVersion( tmp ); | 138 | packageList.back().setVersion( tmp ); |
139 | packageList.back().setPackageStoredLocally( true ); | 139 | packageList.back().setPackageStoredLocally( true ); |
140 | } | 140 | } |
141 | #endif | 141 | #endif |
142 | 142 | ||
143 | // build local packages | 143 | // build local packages |
144 | buildLocalPackages( local ); | 144 | buildLocalPackages( local ); |
145 | } | 145 | } |
146 | 146 | ||
147 | void Server :: readPackageFile( Server *local, bool clearAll, bool installingToRoot, Destination *dest ) | 147 | void Server :: readPackageFile( Server *local, bool clearAll, bool installingToRoot, Destination *dest ) |
148 | { | 148 | { |
149 | ifstream in( packageFile ); | 149 | ifstream in( packageFile ); |
150 | if ( !in.is_open() ) | 150 | if ( !in.is_open() ) |
151 | return; | 151 | return; |
152 | 152 | ||
153 | char line[1001]; | 153 | char line[1001]; |
154 | char k[21]; | 154 | char k[21]; |
155 | char v[1001]; | 155 | char v[1001]; |
156 | QString key; | 156 | QString key; |
157 | QString value; | 157 | QString value; |
158 | 158 | ||
159 | if ( clearAll ) | 159 | if ( clearAll ) |
160 | cleanUp(); | 160 | cleanUp(); |
161 | Package *currPackage = 0; | 161 | Package *currPackage = 0; |
162 | 162 | ||
163 | bool newPackage = true; | 163 | bool newPackage = true; |
164 | do | 164 | do |
165 | { | 165 | { |
166 | in.getline( line, 1000 ); | 166 | in.getline( line, 1000 ); |
167 | if ( in.eof() ) | 167 | if ( in.eof() ) |
168 | break; | 168 | continue; |
169 | 169 | ||
170 | k[0] = '\0'; | 170 | k[0] = '\0'; |
171 | v[0] = '\0'; | 171 | v[0] = '\0'; |
172 | 172 | ||
173 | if ( sscanf( line, "%[^:]: %[^\n]", k, v ) < 2 ) | 173 | sscanf( line, "%[^:]: %[^\n]", k, v ); |
174 | break; | ||
175 | 174 | ||
176 | key = k; | 175 | key = k; |
177 | value = v; | 176 | value = v; |
178 | key = key.stripWhiteSpace(); | 177 | key = key.stripWhiteSpace(); |
179 | value = value.stripWhiteSpace(); | 178 | value = value.stripWhiteSpace(); |
180 | if ( key == "Package" && newPackage ) | 179 | if ( key == "Package" && newPackage ) |
181 | { | 180 | { |
182 | newPackage = false; | 181 | newPackage = false; |
183 | 182 | ||
184 | currPackage = getPackage( value ); | 183 | currPackage = getPackage( value ); |
185 | if ( !currPackage ) | 184 | if ( !currPackage ) |
186 | { | 185 | { |
187 | Package *package = new Package( value ); | 186 | Package *package = new Package( value ); |
188 | packageList.append( package ); | 187 | packageList.append( package ); |
189 | currPackage = package; | 188 | currPackage = package; |
190 | currPackage->setInstalledTo( dest ); | 189 | currPackage->setInstalledTo( dest ); |
191 | if ( installingToRoot ) | 190 | if ( installingToRoot ) |
192 | currPackage->setInstalledToRoot( true ); | 191 | currPackage->setInstalledToRoot( true ); |
193 | } | 192 | } |
194 | else | 193 | else |
195 | { | 194 | { |
196 | if (currPackage->getStatus().find( "deinstall" ) != -1 ) | 195 | if (currPackage->getStatus().find( "deinstall" ) != -1 ) |
197 | currPackage->setInstalledTo( dest ); | 196 | currPackage->setInstalledTo( dest ); |
198 | } | 197 | } |
199 | } | 198 | } |
200 | else if ( key == "Version" ) | 199 | else if ( key == "Version" ) |
201 | { | 200 | { |
202 | if ( currPackage ) | 201 | if ( currPackage ) |
203 | currPackage->setVersion( value ); | 202 | currPackage->setVersion( value ); |
204 | } | 203 | } |
205 | else if ( key == "Status" ) | 204 | else if ( key == "Status" ) |
206 | { | 205 | { |
207 | if ( currPackage ) | 206 | if ( currPackage ) |
208 | currPackage->setStatus( value ); | 207 | currPackage->setStatus( value ); |
209 | } | 208 | } |
210 | else if ( key == "Description" ) | 209 | else if ( key == "Description" ) |
211 | { | 210 | { |
212 | if ( currPackage ) | 211 | if ( currPackage ) |
213 | currPackage->setDescription( value ); | 212 | currPackage->setDescription( value ); |
214 | } | 213 | } |
215 | else if ( key == "Filename" ) | 214 | else if ( key == "Filename" ) |
216 | { | 215 | { |
217 | if ( currPackage ) | 216 | if ( currPackage ) |
218 | currPackage->setFilename( value ); | 217 | currPackage->setFilename( value ); |
219 | } | 218 | } |
220 | else if ( key == "Size" ) | 219 | else if ( key == "Size" ) |
221 | { | 220 | { |
222 | if ( currPackage ) | 221 | if ( currPackage ) |
223 | currPackage->setPackageSize( value ); | 222 | currPackage->setPackageSize( value ); |
224 | } | 223 | } |
225 | else if ( key == "Section" ) | 224 | else if ( key == "Section" ) |
226 | { | 225 | { |
227 | if ( currPackage ) | 226 | if ( currPackage ) |
228 | currPackage->setSection( value ); | 227 | currPackage->setSection( value ); |
229 | 228 | ||
230 | DataManager::setAvailableCategories( value ); | 229 | DataManager::setAvailableCategories( value ); |
231 | } | 230 | } |
232 | else if ( key == "" ) | 231 | else if ( key == "" ) |
233 | { | 232 | { |
234 | newPackage = true; | 233 | newPackage = true; |
235 | } | 234 | } |
236 | } while ( !in.eof() ); | 235 | } while ( !in.eof() ); |
237 | 236 | ||
238 | in.close(); | 237 | in.close(); |
239 | 238 | ||
240 | // build local packages | 239 | // build local packages |
241 | buildLocalPackages( local ); | 240 | buildLocalPackages( local ); |
242 | } | 241 | } |
243 | 242 | ||
244 | void Server :: buildLocalPackages( Server *local ) | 243 | void Server :: buildLocalPackages( Server *local ) |
245 | { | 244 | { |
246 | Package *curr; | 245 | Package *curr; |
247 | QListIterator<Package> it( packageList ); | 246 | QListIterator<Package> it( packageList ); |
248 | for ( ; it.current(); ++it ) | 247 | for ( ; it.current(); ++it ) |
249 | { | 248 | { |
250 | curr = it.current(); | 249 | curr = it.current(); |
251 | QString name = curr->getPackageName(); | 250 | QString name = curr->getPackageName(); |
252 | 251 | ||
253 | // If the package name is an ipk name, then convert the filename to a package name | 252 | // If the package name is an ipk name, then convert the filename to a package name |
254 | if ( name.find( ".ipk" ) != -1 ) | 253 | if ( name.find( ".ipk" ) != -1 ) |
255 | name = Utils::getPackageNameFromIpkFilename( curr->getFilename() ); | 254 | name = Utils::getPackageNameFromIpkFilename( curr->getFilename() ); |
256 | 255 | ||
257 | if ( local ) | 256 | if ( local ) |
258 | { | 257 | { |
259 | Package *p = local->getPackage( name ); | 258 | Package *p = local->getPackage( name ); |
260 | curr->setLocalPackage( p ); | 259 | curr->setLocalPackage( p ); |
261 | if ( p ) | 260 | if ( p ) |
262 | { | 261 | { |
263 | // Set some default stuff like size and things | 262 | // Set some default stuff like size and things |
264 | if ( p->getInstalledVersion() == curr->getVersion() ) | 263 | if ( p->getInstalledVersion() == curr->getVersion() ) |
265 | { | 264 | { |
266 | p->setPackageSize( curr->getPackageSize() ); | 265 | p->setPackageSize( curr->getPackageSize() ); |
267 | p->setSection( curr->getSection() ); | 266 | p->setSection( curr->getSection() ); |
268 | p->setDescription( curr->getDescription() ); | 267 | p->setDescription( curr->getDescription() ); |
269 | } | 268 | } |
270 | } | 269 | } |
271 | 270 | ||
272 | } | 271 | } |
273 | else | 272 | else |
274 | curr->setLocalPackage( 0 ); | 273 | curr->setLocalPackage( 0 ); |
275 | } | 274 | } |
276 | 275 | ||
277 | } | 276 | } |
278 | 277 | ||
279 | Package *Server :: getPackage( QString &name ) | 278 | Package *Server :: getPackage( QString &name ) |
280 | { | 279 | { |
281 | return getPackage( (const char *)name ); | 280 | return getPackage( (const char *)name ); |
282 | } | 281 | } |
283 | 282 | ||
284 | Package *Server :: getPackage( const char *name ) | 283 | Package *Server :: getPackage( const char *name ) |
285 | { | 284 | { |
286 | Package *ret = 0; | 285 | Package *ret = 0; |
287 | 286 | ||
288 | QListIterator<Package> it( packageList ); | 287 | QListIterator<Package> it( packageList ); |
289 | for ( ; it.current(); ++it ) | 288 | for ( ; it.current(); ++it ) |
290 | { | 289 | { |
291 | if ( it.current()->getPackageName() == name ) | 290 | if ( it.current()->getPackageName() == name ) |
292 | ret = it.current(); | 291 | ret = it.current(); |
293 | } | 292 | } |
294 | 293 | ||
295 | return ret; | 294 | return ret; |
296 | } | 295 | } |
297 | 296 | ||
298 | QString Server :: toString() | 297 | QString Server :: toString() |
299 | { | 298 | { |
300 | QString ret = QString( "Server\n name - %1\n url - %2\n" ).arg( serverName ).arg( serverUrl ); | 299 | QString ret = QString( "Server\n name - %1\n url - %2\n" ).arg( serverName ).arg( serverUrl ); |
301 | 300 | ||
302 | QListIterator<Package> it( packageList ); | 301 | QListIterator<Package> it( packageList ); |
303 | for ( ; it.current(); ++it ) | 302 | for ( ; it.current(); ++it ) |
304 | { | 303 | { |
305 | ret.append( QString( "\n %1" ).arg( it.current()->toString() ) ); | 304 | ret.append( QString( "\n %1" ).arg( it.current()->toString() ) ); |
306 | } | 305 | } |
307 | 306 | ||
308 | 307 | ||
309 | return ret; | 308 | return ret; |
310 | } | 309 | } |
311 | 310 | ||
312 | QList<Package> &Server::getPackageList() | 311 | QList<Package> &Server::getPackageList() |
313 | { | 312 | { |
314 | return packageList; | 313 | return packageList; |
315 | } | 314 | } |
316 | 315 | ||