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
@@ -10,35 +10,30 @@
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{
@@ -64,40 +59,41 @@ void Server :: readStatusFile( QList<Destination> &destList )
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
@@ -137,54 +133,50 @@ void Server :: readLocalIpks( Server *local )
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 )
@@ -219,31 +211,31 @@ void Server :: readPackageFile( Server *local, bool clearAll, bool installingToR
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();