author | drw <drw> | 2003-02-06 01:19:25 (UTC) |
---|---|---|
committer | drw <drw> | 2003-02-06 01:19:25 (UTC) |
commit | 79588befde53765db0a92977c6890a4d226096e7 (patch) (unidiff) | |
tree | 83b6dd14c49733b9759fad04147bf0bee50793fe /noncore/settings/aqpkg/server.cpp | |
parent | bbb3690f12191763a407e6a0edd521113b3c25ac (diff) | |
download | opie-79588befde53765db0a92977c6890a4d226096e7.zip opie-79588befde53765db0a92977c6890a4d226096e7.tar.gz opie-79588befde53765db0a92977c6890a4d226096e7.tar.bz2 |
Change all vector<> to QList<>. First step in removing dependency on libstdc++.
Diffstat (limited to 'noncore/settings/aqpkg/server.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/aqpkg/server.cpp | 75 |
1 files changed, 41 insertions, 34 deletions
diff --git a/noncore/settings/aqpkg/server.cpp b/noncore/settings/aqpkg/server.cpp index fc5ed12..04f5ab7 100644 --- a/noncore/settings/aqpkg/server.cpp +++ b/noncore/settings/aqpkg/server.cpp | |||
@@ -46,54 +46,56 @@ Server :: Server( const char *name, const char *url ) | |||
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( vector<Destination> &destList ) | 62 | void Server :: readStatusFile( QList<Destination> &destList ) |
63 | { | 63 | { |
64 | cleanUp(); | 64 | cleanUp(); |
65 | 65 | ||
66 | vector<Destination>::iterator dit; | 66 | Destination *dest; |
67 | QListIterator<Destination> dit( destList ); | ||
67 | bool rootRead = false; | 68 | bool rootRead = false; |
68 | for ( dit = destList.begin() ; dit != destList.end() ; ++dit ) | 69 | for ( ; dit.current(); ++dit ) |
69 | { | 70 | { |
71 | dest = dit.current(); | ||
70 | bool installingToRoot = false; | 72 | bool installingToRoot = false; |
71 | 73 | ||
72 | QString path = dit->getDestinationPath(); | 74 | QString path = dest->getDestinationPath(); |
73 | if ( path.right( 1 ) != "/" ) | 75 | if ( path.right( 1 ) != "/" ) |
74 | path += "/"; | 76 | path += "/"; |
75 | 77 | ||
76 | if ( path == "/" ) | 78 | if ( path == "/" ) |
77 | { | 79 | { |
78 | rootRead = true; | 80 | rootRead = true; |
79 | installingToRoot = true; | 81 | installingToRoot = true; |
80 | } | 82 | } |
81 | 83 | ||
82 | packageFile = path + "usr/lib/ipkg/status"; | 84 | packageFile = path + "usr/lib/ipkg/status"; |
83 | readPackageFile( 0, false, installingToRoot, &( *dit ) ); | 85 | readPackageFile( 0, false, installingToRoot, &( *dest ) ); |
84 | } | 86 | } |
85 | 87 | ||
86 | // Ensure that the root status file is read | 88 | // Ensure that the root status file is read |
87 | if ( !rootRead ) | 89 | if ( !rootRead ) |
88 | { | 90 | { |
89 | cout << "Reading status file " << "/usr/lib/ipkg/status" << endl; | 91 | cout << "Reading status file " << "/usr/lib/ipkg/status" << endl; |
90 | packageFile = "/usr/lib/ipkg/status"; | 92 | packageFile = "/usr/lib/ipkg/status"; |
91 | readPackageFile( 0, false, true ); | 93 | readPackageFile( 0, false, true ); |
92 | } | 94 | } |
93 | } | 95 | } |
94 | 96 | ||
95 | void Server :: readLocalIpks( Server *local ) | 97 | void Server :: readLocalIpks( Server *local ) |
96 | { | 98 | { |
97 | cleanUp(); | 99 | cleanUp(); |
98 | 100 | ||
99 | #ifdef QWS | 101 | #ifdef QWS |
@@ -102,38 +104,38 @@ void Server :: readLocalIpks( Server *local ) | |||
102 | 104 | ||
103 | DocLnkSet files; | 105 | DocLnkSet files; |
104 | Global::findDocuments( &files, "application/ipkg" ); | 106 | Global::findDocuments( &files, "application/ipkg" ); |
105 | 107 | ||
106 | // Now add the items to the list | 108 | // Now add the items to the list |
107 | QListIterator<DocLnk> it( files.children() ); | 109 | QListIterator<DocLnk> it( files.children() ); |
108 | 110 | ||
109 | for ( ; it.current() ; ++it ) | 111 | for ( ; it.current() ; ++it ) |
110 | { | 112 | { |
111 | // 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 |
112 | // for these are packagename_version_arm.ipk | 114 | // for these are packagename_version_arm.ipk |
113 | QString file = (*it)->file(); | 115 | QString file = (*it)->file(); |
114 | 116 | ||
115 | // Changed to display the filename (excluding the path) | 117 | // Changed to display the filename (excluding the path) |
116 | QString packageName = Utils::getFilenameFromIpkFilename( file ); | 118 | QString packageName = Utils::getFilenameFromIpkFilename( file ); |
117 | QString ver = Utils::getPackageVersionFromIpkFilename( file ); | 119 | QString ver = Utils::getPackageVersionFromIpkFilename( file ); |
118 | packageList.push_back( Package( packageName ) ); | 120 | Package *package = new Package( packageName ); |
119 | packageList.back().setVersion( ver ); | 121 | package->setVersion( ver ); |
120 | packageList.back().setFilename( file ); | 122 | package->setFilename( file ); |
121 | packageList.back().setPackageStoredLocally( true ); | 123 | package->setPackageStoredLocally( true ); |
122 | 124 | packageList.append( package ); | |
123 | } | 125 | } |
124 | #else | 126 | #else |
125 | 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" }; |
126 | for ( int i = 0 ; i < 4 ; ++i ) | 128 | for ( int i = 0 ; i < 4 ; ++i ) |
127 | { | 129 | { |
128 | // 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 |
129 | // for these are packagename_version_arm.ipk | 131 | // for these are packagename_version_arm.ipk |
130 | QString file = names[i]; | 132 | QString file = names[i]; |
131 | int p = file.find( "_" ); | 133 | int p = file.find( "_" ); |
132 | QString tmp = file.mid( 0, p ); | 134 | QString tmp = file.mid( 0, p ); |
133 | packageList.push_back( Package( tmp ) ); | 135 | packageList.push_back( Package( tmp ) ); |
134 | int p2 = file.find( "_", p+1 ); | 136 | int p2 = file.find( "_", p+1 ); |
135 | tmp = file.mid( p+1, p2-(p+1) ); | 137 | tmp = file.mid( p+1, p2-(p+1) ); |
136 | packageList.back().setVersion( tmp ); | 138 | packageList.back().setVersion( tmp ); |
137 | packageList.back().setPackageStoredLocally( true ); | 139 | packageList.back().setPackageStoredLocally( true ); |
138 | } | 140 | } |
139 | #endif | 141 | #endif |
@@ -167,36 +169,36 @@ void Server :: readPackageFile( Server *local, bool clearAll, bool installingToR | |||
167 | 169 | ||
168 | k[0] = '\0'; | 170 | k[0] = '\0'; |
169 | v[0] = '\0'; | 171 | v[0] = '\0'; |
170 | 172 | ||
171 | sscanf( line, "%[^:]: %[^\n]", k, v ); | 173 | sscanf( line, "%[^:]: %[^\n]", k, v ); |
172 | key = k; | 174 | key = k; |
173 | value = v; | 175 | value = v; |
174 | key = key.stripWhiteSpace(); | 176 | key = key.stripWhiteSpace(); |
175 | value = value.stripWhiteSpace(); | 177 | value = value.stripWhiteSpace(); |
176 | if ( key == "Package" && newPackage ) | 178 | if ( key == "Package" && newPackage ) |
177 | { | 179 | { |
178 | newPackage = false; | 180 | newPackage = false; |
179 | 181 | ||
180 | currPackage = getPackage( value ); | 182 | currPackage = getPackage( value ); |
181 | if ( !currPackage ) | 183 | if ( !currPackage ) |
182 | { | 184 | { |
183 | packageList.push_back( Package( value ) ); | 185 | Package *package = new Package( value ); |
184 | currPackage = &(packageList.back()); | 186 | packageList.append( package ); |
187 | currPackage = package; | ||
185 | currPackage->setInstalledTo( dest ); | 188 | currPackage->setInstalledTo( dest ); |
186 | |||
187 | if ( installingToRoot ) | 189 | if ( installingToRoot ) |
188 | currPackage->setInstalledToRoot( true ); | 190 | currPackage->setInstalledToRoot( true ); |
189 | } | 191 | } |
190 | else | 192 | else |
191 | { | 193 | { |
192 | if (currPackage->getStatus().find( "deinstall" ) != -1 ) | 194 | if (currPackage->getStatus().find( "deinstall" ) != -1 ) |
193 | currPackage->setInstalledTo( dest ); | 195 | currPackage->setInstalledTo( dest ); |
194 | } | 196 | } |
195 | } | 197 | } |
196 | else if ( key == "Version" ) | 198 | else if ( key == "Version" ) |
197 | { | 199 | { |
198 | if ( currPackage ) | 200 | if ( currPackage ) |
199 | currPackage->setVersion( value ); | 201 | currPackage->setVersion( value ); |
200 | } | 202 | } |
201 | else if ( key == "Status" ) | 203 | else if ( key == "Status" ) |
202 | { | 204 | { |
@@ -226,82 +228,87 @@ void Server :: readPackageFile( Server *local, bool clearAll, bool installingToR | |||
226 | DataManager::setAvailableCategories( value ); | 228 | DataManager::setAvailableCategories( value ); |
227 | } | 229 | } |
228 | else if ( key == "" ) | 230 | else if ( key == "" ) |
229 | { | 231 | { |
230 | newPackage = true; | 232 | newPackage = true; |
231 | } | 233 | } |
232 | } while ( !in.eof() ); | 234 | } while ( !in.eof() ); |
233 | 235 | ||
234 | in.close(); | 236 | in.close(); |
235 | 237 | ||
236 | // build local packages | 238 | // build local packages |
237 | buildLocalPackages( local ); | 239 | buildLocalPackages( local ); |
238 | } | 240 | } |
239 | 241 | ||
240 | void Server :: buildLocalPackages( Server *local ) | 242 | void Server :: buildLocalPackages( Server *local ) |
241 | { | 243 | { |
242 | for ( unsigned int i = 0 ; i < packageList.size() ; ++i ) | 244 | Package *curr; |
245 | QListIterator<Package> it( packageList ); | ||
246 | for ( ; it.current(); ++it ) | ||
243 | { | 247 | { |
244 | QString name = packageList[i].getPackageName(); | 248 | curr = it.current(); |
249 | QString name = curr->getPackageName(); | ||
245 | 250 | ||
246 | // If the package name is an ipk name, then convert the filename to a package name | 251 | // If the package name is an ipk name, then convert the filename to a package name |
247 | if ( name.find( ".ipk" ) != -1 ) | 252 | if ( name.find( ".ipk" ) != -1 ) |
248 | name = Utils::getPackageNameFromIpkFilename( packageList[i].getFilename() ); | 253 | name = Utils::getPackageNameFromIpkFilename( curr->getFilename() ); |
249 | 254 | ||
250 | if ( local ) | 255 | if ( local ) |
251 | { | 256 | { |
252 | Package *p = local->getPackage( name ); | 257 | Package *p = local->getPackage( name ); |
253 | packageList[i].setLocalPackage( p ); | 258 | curr->setLocalPackage( p ); |
254 | if ( p ) | 259 | if ( p ) |
255 | { | 260 | { |
256 | // Set some default stuff like size and things | 261 | // Set some default stuff like size and things |
257 | if ( p->getInstalledVersion() == packageList[i].getVersion() ) | 262 | if ( p->getInstalledVersion() == curr->getVersion() ) |
258 | { | 263 | { |
259 | p->setPackageSize( packageList[i].getPackageSize() ); | 264 | p->setPackageSize( curr->getPackageSize() ); |
260 | p->setSection( packageList[i].getSection() ); | 265 | p->setSection( curr->getSection() ); |
261 | p->setDescription( packageList[i].getDescription() ); | 266 | p->setDescription( curr->getDescription() ); |
262 | } | 267 | } |
263 | } | 268 | } |
264 | 269 | ||
265 | } | 270 | } |
266 | else | 271 | else |
267 | packageList[i].setLocalPackage( 0 ); | 272 | curr->setLocalPackage( 0 ); |
268 | } | 273 | } |
269 | 274 | ||
270 | } | 275 | } |
271 | 276 | ||
272 | Package *Server :: getPackage( QString &name ) | 277 | Package *Server :: getPackage( QString &name ) |
273 | { | 278 | { |
274 | return getPackage( (const char *)name ); | 279 | return getPackage( (const char *)name ); |
275 | } | 280 | } |
276 | 281 | ||
277 | Package *Server :: getPackage( const char *name ) | 282 | Package *Server :: getPackage( const char *name ) |
278 | { | 283 | { |
279 | Package *ret = 0; | 284 | Package *ret = 0; |
280 | 285 | ||
281 | for ( unsigned int i = 0 ; i < packageList.size() && ret == 0; ++i ) | 286 | QListIterator<Package> it( packageList ); |
287 | for ( ; it.current(); ++it ) | ||
282 | { | 288 | { |
283 | if ( packageList[i].getPackageName() == name ) | 289 | if ( it.current()->getPackageName() == name ) |
284 | ret = &packageList[i]; | 290 | ret = it.current(); |
285 | } | 291 | } |
286 | 292 | ||
287 | return ret; | 293 | return ret; |
288 | } | 294 | } |
289 | 295 | ||
290 | QString Server :: toString() | 296 | QString Server :: toString() |
291 | { | 297 | { |
292 | QString ret = "Server\n name - " + serverName + | 298 | QString ret = QString( "Server\n name - %1\n url - %2\n" ).arg( serverName ).arg( serverUrl ); |
293 | "\n url - " + serverUrl + | 299 | |
294 | "\n"; | 300 | QListIterator<Package> it( packageList ); |
295 | 301 | for ( ; it.current(); ++it ) | |
296 | for ( unsigned int i = 0 ; i < packageList.size() ; ++i ) | 302 | { |
297 | ret += "\n " + packageList[i].toString(); | 303 | ret.append( QString( "\n %1" ).arg( it.current()->toString() ) ); |
304 | } | ||
298 | 305 | ||
299 | 306 | ||
300 | return ret; | 307 | return ret; |
301 | } | 308 | } |
302 | 309 | ||
303 | vector<Package> &Server::getPackageList() | 310 | QList<Package> &Server::getPackageList() |
304 | { | 311 | { |
305 | return packageList; | 312 | return packageList; |
306 | } | 313 | } |
307 | 314 | ||