summaryrefslogtreecommitdiff
authorandyq <andyq>2002-11-23 15:27:45 (UTC)
committer andyq <andyq>2002-11-23 15:27:45 (UTC)
commitbf0cc4c950f0a96bf7091e730744a2b3eb6cc751 (patch) (unidiff)
tree97fb1d7337da8659bbcdaf0343de7d76cc4d7d1c
parent7763c095d81f44cd3012d894da6b17eb0b0cc194 (diff)
downloadopie-bf0cc4c950f0a96bf7091e730744a2b3eb6cc751.zip
opie-bf0cc4c950f0a96bf7091e730744a2b3eb6cc751.tar.gz
opie-bf0cc4c950f0a96bf7091e730744a2b3eb6cc751.tar.bz2
*** empty log message ***
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/server.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/noncore/settings/aqpkg/server.cpp b/noncore/settings/aqpkg/server.cpp
index 2cb0533..fc5ed12 100644
--- a/noncore/settings/aqpkg/server.cpp
+++ b/noncore/settings/aqpkg/server.cpp
@@ -1,302 +1,302 @@
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>
28using namespace std; 28using 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
43Server :: Server( const char *name, const char *url ) 43Server :: 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
52Server :: ~Server() 52Server :: ~Server()
53{ 53{
54 cleanUp(); 54 cleanUp();
55} 55}
56 56
57void Server :: cleanUp() 57void Server :: cleanUp()
58{ 58{
59 packageList.clear(); 59 packageList.clear();
60} 60}
61 61
62void Server :: readStatusFile( vector<Destination> &destList ) 62void Server :: readStatusFile( vector<Destination> &destList )
63{ 63{
64 cleanUp(); 64 cleanUp();
65 65
66 vector<Destination>::iterator dit; 66 vector<Destination>::iterator dit;
67 bool rootRead = false; 67 bool rootRead = false;
68 for ( dit = destList.begin() ; dit != destList.end() ; ++dit ) 68 for ( dit = destList.begin() ; dit != destList.end() ; ++dit )
69 { 69 {
70 bool installingToRoot = false; 70 bool installingToRoot = false;
71 71
72 QString path = dit->getDestinationPath(); 72 QString path = dit->getDestinationPath();
73 if ( path.right( 1 ) != "/" ) 73 if ( path.right( 1 ) != "/" )
74 path += "/"; 74 path += "/";
75 75
76 if ( path == "/" ) 76 if ( path == "/" )
77 { 77 {
78 rootRead = true; 78 rootRead = true;
79 installingToRoot = true; 79 installingToRoot = true;
80 } 80 }
81 81
82 packageFile = path + "usr/lib/ipkg/status"; 82 packageFile = path + "usr/lib/ipkg/status";
83 readPackageFile( 0, false, installingToRoot, &( *dit ) ); 83 readPackageFile( 0, false, installingToRoot, &( *dit ) );
84 } 84 }
85 85
86 // Ensure that the root status file is read 86 // Ensure that the root status file is read
87 if ( !rootRead ) 87 if ( !rootRead )
88 { 88 {
89 cout << "Reading status file " << "/usr/lib/ipkg/status" << endl; 89 cout << "Reading status file " << "/usr/lib/ipkg/status" << endl;
90 packageFile = "/usr/lib/ipkg/status"; 90 packageFile = "/usr/lib/ipkg/status";
91 readPackageFile( 0, false, true ); 91 readPackageFile( 0, false, true );
92 } 92 }
93} 93}
94 94
95void Server :: readLocalIpks( Server *local ) 95void Server :: readLocalIpks( Server *local )
96{ 96{
97 cleanUp(); 97 cleanUp();
98 98
99#ifdef QWS 99#ifdef QWS
100 // First, get any local IPKGs in the documents area 100 // First, get any local IPKGs in the documents area
101 // Only applicable to Qtopie/Opie 101 // Only applicable to Qtopie/Opie
102 102
103 DocLnkSet files; 103 DocLnkSet files;
104 Global::findDocuments( &files, "application/ipkg" ); 104 Global::findDocuments( &files, "application/ipkg" );
105 105
106 // Now add the items to the list 106 // Now add the items to the list
107 QListIterator<DocLnk> it( files.children() ); 107 QListIterator<DocLnk> it( files.children() );
108 108
109 for ( ; it.current() ; ++it ) 109 for ( ; it.current() ; ++it )
110 { 110 {
111 // OK, we have a local IPK file, I think the standard naming conventions 111 // OK, we have a local IPK file, I think the standard naming conventions
112 // for these are packagename_version_arm.ipk 112 // for these are packagename_version_arm.ipk
113 QString file = (*it)->file(); 113 QString file = (*it)->file();
114 114
115 // Changed to display the filename (excluding the path) 115 // Changed to display the filename (excluding the path)
116 QString packageName = Utils::getFilenameFromIpkFilename( file ); 116 QString packageName = Utils::getFilenameFromIpkFilename( file );
117 QString ver = Utils::getPackageVersionFromIpkFilename( file ); 117 QString ver = Utils::getPackageVersionFromIpkFilename( file );
118 packageList.push_back( Package( packageName ) ); 118 packageList.push_back( Package( packageName ) );
119 packageList.back().setVersion( ver ); 119 packageList.back().setVersion( ver );
120 packageList.back().setFilename( file ); 120 packageList.back().setFilename( file );
121 packageList.back().setPackageStoredLocally( true ); 121 packageList.back().setPackageStoredLocally( true );
122 122
123 } 123 }
124#else 124#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" }; 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" };
126 for ( int i = 0 ; i < 4 ; ++i ) 126 for ( int i = 0 ; i < 4 ; ++i )
127 { 127 {
128 // OK, we have a local IPK file, I think the standard naming conventions 128 // OK, we have a local IPK file, I think the standard naming conventions
129 // for these are packagename_version_arm.ipk 129 // for these are packagename_version_arm.ipk
130 QString file = names[i]; 130 QString file = names[i];
131 int p = file.find( "_" ); 131 int p = file.find( "_" );
132 QString tmp = file.mid( 0, p ); 132 QString tmp = file.mid( 0, p );
133 packageList.push_back( Package( tmp ) ); 133 packageList.push_back( Package( tmp ) );
134 int p2 = file.find( "_", p+1 ); 134 int p2 = file.find( "_", p+1 );
135 tmp = file.mid( p+1, p2-(p+1) ); 135 tmp = file.mid( p+1, p2-(p+1) );
136 packageList.back().setVersion( tmp ); 136 packageList.back().setVersion( tmp );
137 packageList.back().setPackageStoredLocally( true ); 137 packageList.back().setPackageStoredLocally( true );
138 } 138 }
139#endif 139#endif
140 140
141 // build local packages 141 // build local packages
142 buildLocalPackages( local ); 142 buildLocalPackages( local );
143} 143}
144 144
145void Server :: readPackageFile( Server *local, bool clearAll, bool installingToRoot, Destination *dest ) 145void Server :: readPackageFile( Server *local, bool clearAll, bool installingToRoot, Destination *dest )
146{ 146{
147 ifstream in( packageFile ); 147 ifstream in( packageFile );
148 if ( !in.is_open() ) 148 if ( !in.is_open() )
149 return; 149 return;
150 150
151 char line[1001]; 151 char line[1001];
152 char k[21]; 152 char k[21];
153 char v[1001]; 153 char v[1001];
154 QString key; 154 QString key;
155 QString value; 155 QString value;
156 156
157 if ( clearAll ) 157 if ( clearAll )
158 cleanUp(); 158 cleanUp();
159 Package *currPackage = 0; 159 Package *currPackage = 0;
160 160
161 bool newPackage = true; 161 bool newPackage = true;
162 do 162 do
163 { 163 {
164 in.getline( line, 1000 ); 164 in.getline( line, 1000 );
165 if ( in.eof() ) 165 if ( in.eof() )
166 continue; 166 continue;
167 167
168 k[0] = '\0'; 168 k[0] = '\0';
169 v[0] = '\0'; 169 v[0] = '\0';
170 170
171 sscanf( line, "%[^:]: %[^\n]", k, v ); 171 sscanf( line, "%[^:]: %[^\n]", k, v );
172 key = k; 172 key = k;
173 value = v; 173 value = v;
174 key = key.stripWhiteSpace(); 174 key = key.stripWhiteSpace();
175 value = value.stripWhiteSpace(); 175 value = value.stripWhiteSpace();
176 if ( key == "Package" && newPackage ) 176 if ( key == "Package" && newPackage )
177 { 177 {
178 newPackage = false; 178 newPackage = false;
179 179
180 currPackage = getPackage( value ); 180 currPackage = getPackage( value );
181 if ( !currPackage ) 181 if ( !currPackage )
182 { 182 {
183 packageList.push_back( Package( value ) ); 183 packageList.push_back( Package( value ) );
184 currPackage = &(packageList.back()); 184 currPackage = &(packageList.back());
185 currPackage->setInstalledTo( dest ); 185 currPackage->setInstalledTo( dest );
186 186
187 if ( installingToRoot ) 187 if ( installingToRoot )
188 currPackage->setInstalledToRoot( true ); 188 currPackage->setInstalledToRoot( true );
189 } 189 }
190 else 190 else
191 { 191 {
192 if (currPackage->getStatus().find( "deinstall" ) != -1 ) 192 if (currPackage->getStatus().find( "deinstall" ) != -1 )
193 currPackage->setInstalledTo( dest ); 193 currPackage->setInstalledTo( dest );
194 } 194 }
195 } 195 }
196 else if ( key == "Version" ) 196 else if ( key == "Version" )
197 { 197 {
198 if ( currPackage ) 198 if ( currPackage )
199 currPackage->setVersion( value ); 199 currPackage->setVersion( value );
200 } 200 }
201 else if ( key == "Status" ) 201 else if ( key == "Status" )
202 { 202 {
203 if ( currPackage ) 203 if ( currPackage )
204 currPackage->setStatus( value ); 204 currPackage->setStatus( value );
205 } 205 }
206 else if ( key == "Description" ) 206 else if ( key == "Description" )
207 { 207 {
208 if ( currPackage ) 208 if ( currPackage )
209 currPackage->setDescription( value ); 209 currPackage->setDescription( value );
210 } 210 }
211 else if ( key == "Filename" ) 211 else if ( key == "Filename" )
212 { 212 {
213 if ( currPackage ) 213 if ( currPackage )
214 currPackage->setFilename( value ); 214 currPackage->setFilename( value );
215 } 215 }
216 else if ( key == "Size" ) 216 else if ( key == "Size" )
217 { 217 {
218 if ( currPackage ) 218 if ( currPackage )
219 currPackage->setPackageSize( value ); 219 currPackage->setPackageSize( value );
220 } 220 }
221 else if ( key == "Section" ) 221 else if ( key == "Section" )
222 { 222 {
223 if ( currPackage ) 223 if ( currPackage )
224 currPackage->setSection( value ); 224 currPackage->setSection( value );
225 225
226 DataManager::setAvailableCategories( value ); 226 DataManager::setAvailableCategories( value );
227 } 227 }
228 else if ( key == "" ) 228 else if ( key == "" )
229 { 229 {
230 newPackage = true; 230 newPackage = true;
231 } 231 }
232 } while ( !in.eof() ); 232 } while ( !in.eof() );
233 233
234 in.close(); 234 in.close();
235 235
236 // build local packages 236 // build local packages
237 buildLocalPackages( local ); 237 buildLocalPackages( local );
238} 238}
239 239
240void Server :: buildLocalPackages( Server *local ) 240void Server :: buildLocalPackages( Server *local )
241{ 241{
242 for ( unsigned int i = 0 ; i < packageList.size() ; ++i ) 242 for ( unsigned int i = 0 ; i < packageList.size() ; ++i )
243 { 243 {
244 QString name = packageList[i].getPackageName(); 244 QString name = packageList[i].getPackageName();
245 245
246 // If the package name is an ipk name, then convert the filename to a package name 246 // If the package name is an ipk name, then convert the filename to a package name
247 if ( name.find( ".ipk" ) != -1 ) 247 if ( name.find( ".ipk" ) != -1 )
248 name = Utils::getPackageNameFromIpkFilename( packageList[i].getFilename() ); 248 name = Utils::getPackageNameFromIpkFilename( packageList[i].getFilename() );
249 249
250 if ( local ) 250 if ( local )
251 { 251 {
252 Package *p = local->getPackage( name ); 252 Package *p = local->getPackage( name );
253 packageList[i].setLocalPackage( p ); 253 packageList[i].setLocalPackage( p );
254 if ( p ) 254 if ( p )
255 { 255 {
256 // Set some default stuff like size and things 256 // Set some default stuff like size and things
257 if ( p->getInstalledVersion() == packageList[i].getVersion() ) 257 if ( p->getInstalledVersion() == packageList[i].getVersion() )
258 { 258 {
259 p->setPackageSize( packageList[i].getPackageSize() ); 259 p->setPackageSize( packageList[i].getPackageSize() );
260 p->setSection( packageList[i].getSection() ); 260 p->setSection( packageList[i].getSection() );
261 p->setDescription( packageList[i].getDescription() ); 261 p->setDescription( packageList[i].getDescription() );
262 } 262 }
263 } 263 }
264 264
265 } 265 }
266 else 266 else
267 packageList[i].setLocalPackage( 0 ); 267 packageList[i].setLocalPackage( 0 );
268 } 268 }
269 269
270} 270}
271 271
272Package *Server :: getPackage( QString &name ) 272Package *Server :: getPackage( QString &name )
273{ 273{
274 return getPackage( (const char *)name ); 274 return getPackage( (const char *)name );
275} 275}
276 276
277Package *Server :: getPackage( const char *name ) 277Package *Server :: getPackage( const char *name )
278{ 278{
279 Package *ret = 0; 279 Package *ret = 0;
280 280
281 for ( unsigned int i = 0 ; i < packageList.size() && ret == 0; ++i ) 281 for ( unsigned int i = 0 ; i < packageList.size() && ret == 0; ++i )
282 { 282 {
283 if ( packageList[i].getPackageName() == name ) 283 if ( packageList[i].getPackageName() == name )
284 ret = &packageList[i]; 284 ret = &packageList[i];
285 } 285 }
286 286
287 return ret; 287 return ret;
288} 288}
289 289
290QString Server :: toString() 290QString Server :: toString()
291{ 291{
292 QString ret = "Server\n name - " + serverName + 292 QString ret = "Server\n name - " + serverName +
293 "\n url - " + serverUrl + 293 "\n url - " + serverUrl +
294 "\n"; 294 "\n";
295 295
296 for ( unsigned int i = 0 ; i < packageList.size() ; ++i ) 296 for ( unsigned int i = 0 ; i < packageList.size() ; ++i )
297 ret += "\n " + packageList[i].toString(); 297 ret += "\n " + packageList[i].toString();
298 298
299 299
300 return ret; 300 return ret;
301} 301}
302 302