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