author | andyq <andyq> | 2002-10-17 22:52:44 (UTC) |
---|---|---|
committer | andyq <andyq> | 2002-10-17 22:52:44 (UTC) |
commit | e38ea35a5bbfae58a9d4cb66cfdf557d606921cd (patch) (unidiff) | |
tree | 4526e3e7a8540bbc81baa25c629bfda2f76e56bd | |
parent | b61a21e46590228b6c5800d168fc57789ce733f6 (diff) | |
download | opie-e38ea35a5bbfae58a9d4cb66cfdf557d606921cd.zip opie-e38ea35a5bbfae58a9d4cb66cfdf557d606921cd.tar.gz opie-e38ea35a5bbfae58a9d4cb66cfdf557d606921cd.tar.bz2 |
Now sets the destination a package was installed to
-rw-r--r-- | noncore/settings/aqpkg/server.cpp | 13 | ||||
-rw-r--r-- | noncore/settings/aqpkg/server.h | 3 |
2 files changed, 11 insertions, 5 deletions
diff --git a/noncore/settings/aqpkg/server.cpp b/noncore/settings/aqpkg/server.cpp index 0069a60..7d103a2 100644 --- a/noncore/settings/aqpkg/server.cpp +++ b/noncore/settings/aqpkg/server.cpp | |||
@@ -1,266 +1,273 @@ | |||
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 | 31 | ||
32 | #ifdef QWS | 32 | #ifdef QWS |
33 | #include <qpe/global.h> | 33 | #include <qpe/global.h> |
34 | #include <qpe/applnk.h> | 34 | #include <qpe/applnk.h> |
35 | #include <qlist.h> | 35 | #include <qlist.h> |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #include "utils.h" | 38 | #include "utils.h" |
39 | 39 | ||
40 | #include "global.h" | 40 | #include "global.h" |
41 | 41 | ||
42 | Server :: Server( const char *name, const char *url ) | 42 | Server :: Server( const char *name, const char *url ) |
43 | { | 43 | { |
44 | serverName = name; | 44 | serverName = name; |
45 | serverUrl = url; | 45 | serverUrl = url; |
46 | packageFile = IPKG_DIR; | 46 | packageFile = IPKG_DIR; |
47 | packageFile += "lists/" + serverName; | 47 | packageFile += "lists/" + serverName; |
48 | } | 48 | } |
49 | 49 | ||
50 | Server :: ~Server() | 50 | Server :: ~Server() |
51 | { | 51 | { |
52 | cleanUp(); | 52 | cleanUp(); |
53 | } | 53 | } |
54 | 54 | ||
55 | void Server :: cleanUp() | 55 | void Server :: cleanUp() |
56 | { | 56 | { |
57 | packageList.clear(); | 57 | packageList.clear(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void Server :: readStatusFile( vector<Destination> &destList ) | 60 | void Server :: readStatusFile( vector<Destination> &destList ) |
61 | { | 61 | { |
62 | cleanUp(); | 62 | cleanUp(); |
63 | 63 | ||
64 | vector<Destination>::iterator dit; | 64 | vector<Destination>::iterator dit; |
65 | bool rootRead = false; | 65 | bool rootRead = false; |
66 | for ( dit = destList.begin() ; dit != destList.end() ; ++dit ) | 66 | for ( dit = destList.begin() ; dit != destList.end() ; ++dit ) |
67 | { | 67 | { |
68 | bool installingToRoot = false; | 68 | bool installingToRoot = false; |
69 | 69 | ||
70 | QString path = dit->getDestinationPath(); | 70 | QString path = dit->getDestinationPath(); |
71 | if ( path.right( 1 ) != "/" ) | 71 | if ( path.right( 1 ) != "/" ) |
72 | path += "/"; | 72 | path += "/"; |
73 | 73 | ||
74 | if ( path == "/" ) | 74 | if ( path == "/" ) |
75 | { | 75 | { |
76 | rootRead = true; | 76 | rootRead = true; |
77 | installingToRoot = true; | 77 | installingToRoot = true; |
78 | } | 78 | } |
79 | 79 | ||
80 | packageFile = path + "usr/lib/ipkg/status"; | 80 | packageFile = path + "usr/lib/ipkg/status"; |
81 | readPackageFile( 0, false, installingToRoot ); | 81 | readPackageFile( 0, false, installingToRoot, dit ); |
82 | } | 82 | } |
83 | 83 | ||
84 | // Ensure that the root status file is read | 84 | // Ensure that the root status file is read |
85 | if ( !rootRead ) | 85 | if ( !rootRead ) |
86 | { | 86 | { |
87 | cout << "Reading status file " << "/usr/lib/ipkg/status" << endl; | 87 | cout << "Reading status file " << "/usr/lib/ipkg/status" << endl; |
88 | packageFile = "/usr/lib/ipkg/status"; | 88 | packageFile = "/usr/lib/ipkg/status"; |
89 | readPackageFile( 0, false, true ); | 89 | readPackageFile( 0, false, true ); |
90 | } | 90 | } |
91 | } | 91 | } |
92 | 92 | ||
93 | void Server :: readLocalIpks( Server *local ) | 93 | void Server :: readLocalIpks( Server *local ) |
94 | { | 94 | { |
95 | cleanUp(); | 95 | cleanUp(); |
96 | 96 | ||
97 | #ifdef QWS | 97 | #ifdef QWS |
98 | // First, get any local IPKGs in the documents area | 98 | // First, get any local IPKGs in the documents area |
99 | // Only applicable to Qtopie/Opie | 99 | // Only applicable to Qtopie/Opie |
100 | 100 | ||
101 | DocLnkSet files; | 101 | DocLnkSet files; |
102 | Global::findDocuments( &files, "application/ipkg" ); | 102 | Global::findDocuments( &files, "application/ipkg" ); |
103 | 103 | ||
104 | // Now add the items to the list | 104 | // Now add the items to the list |
105 | QListIterator<DocLnk> it( files.children() ); | 105 | QListIterator<DocLnk> it( files.children() ); |
106 | 106 | ||
107 | for ( ; it.current() ; ++it ) | 107 | for ( ; it.current() ; ++it ) |
108 | { | 108 | { |
109 | // 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 |
110 | // for these are packagename_version_arm.ipk | 110 | // for these are packagename_version_arm.ipk |
111 | QString file = (*it)->file(); | 111 | QString file = (*it)->file(); |
112 | 112 | ||
113 | QString packageName = Utils::getPackageNameFromIpkFilename( file ); | 113 | QString packageName = Utils::getPackageNameFromIpkFilename( file ); |
114 | QString ver = Utils::getPackageVersionFromIpkFilename( file ); | 114 | QString ver = Utils::getPackageVersionFromIpkFilename( file ); |
115 | packageList.push_back( Package( packageName ) ); | 115 | packageList.push_back( Package( packageName ) ); |
116 | packageList.back().setVersion( ver ); | 116 | packageList.back().setVersion( ver ); |
117 | packageList.back().setFilename( file ); | 117 | packageList.back().setFilename( file ); |
118 | packageList.back().setPackageStoredLocally( true ); | 118 | packageList.back().setPackageStoredLocally( true ); |
119 | 119 | ||
120 | } | 120 | } |
121 | #else | 121 | #else |
122 | 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" }; | 122 | 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 | for ( int i = 0 ; i < 4 ; ++i ) | 123 | for ( int i = 0 ; i < 4 ; ++i ) |
124 | { | 124 | { |
125 | // OK, we have a local IPK file, I think the standard naming conventions | 125 | // OK, we have a local IPK file, I think the standard naming conventions |
126 | // for these are packagename_version_arm.ipk | 126 | // for these are packagename_version_arm.ipk |
127 | QString file = names[i]; | 127 | QString file = names[i]; |
128 | int p = file.find( "_" ); | 128 | int p = file.find( "_" ); |
129 | QString tmp = file.mid( 0, p ); | 129 | QString tmp = file.mid( 0, p ); |
130 | packageList.push_back( Package( tmp ) ); | 130 | packageList.push_back( Package( tmp ) ); |
131 | int p2 = file.find( "_", p+1 ); | 131 | int p2 = file.find( "_", p+1 ); |
132 | tmp = file.mid( p+1, p2-(p+1) ); | 132 | tmp = file.mid( p+1, p2-(p+1) ); |
133 | packageList.back().setVersion( tmp ); | 133 | packageList.back().setVersion( tmp ); |
134 | packageList.back().setPackageStoredLocally( true ); | 134 | packageList.back().setPackageStoredLocally( true ); |
135 | } | 135 | } |
136 | #endif | 136 | #endif |
137 | 137 | ||
138 | // build local packages | 138 | // build local packages |
139 | buildLocalPackages( local ); | 139 | buildLocalPackages( local ); |
140 | } | 140 | } |
141 | 141 | ||
142 | void Server :: readPackageFile( Server *local, bool clearAll, bool installingToRoot ) | 142 | void Server :: readPackageFile( Server *local, bool clearAll, bool installingToRoot, Destination *dest ) |
143 | { | 143 | { |
144 | ifstream in( packageFile ); | 144 | ifstream in( packageFile ); |
145 | if ( !in.is_open() ) | 145 | if ( !in.is_open() ) |
146 | return; | 146 | return; |
147 | 147 | ||
148 | char line[1001]; | 148 | char line[1001]; |
149 | char k[21]; | 149 | char k[21]; |
150 | char v[1001]; | 150 | char v[1001]; |
151 | QString key; | 151 | QString key; |
152 | QString value; | 152 | QString value; |
153 | 153 | ||
154 | if ( clearAll ) | 154 | if ( clearAll ) |
155 | cleanUp(); | 155 | cleanUp(); |
156 | Package *currPackage = 0; | 156 | Package *currPackage = 0; |
157 | 157 | ||
158 | bool newPackage = true; | 158 | bool newPackage = true; |
159 | do | 159 | do |
160 | { | 160 | { |
161 | in.getline( line, 1000 ); | 161 | in.getline( line, 1000 ); |
162 | if ( in.eof() ) | 162 | if ( in.eof() ) |
163 | continue; | 163 | continue; |
164 | 164 | ||
165 | k[0] = '\0'; | 165 | k[0] = '\0'; |
166 | v[0] = '\0'; | 166 | v[0] = '\0'; |
167 | 167 | ||
168 | sscanf( line, "%[^:]: %[^\n]", k, v ); | 168 | sscanf( line, "%[^:]: %[^\n]", k, v ); |
169 | key = k; | 169 | key = k; |
170 | value = v; | 170 | value = v; |
171 | key.stripWhiteSpace(); | 171 | key = key.stripWhiteSpace(); |
172 | value = value.stripWhiteSpace(); | ||
172 | if ( key == "Package" && newPackage ) | 173 | if ( key == "Package" && newPackage ) |
173 | { | 174 | { |
174 | newPackage = false; | 175 | newPackage = false; |
175 | 176 | ||
176 | currPackage = getPackage( value ); | 177 | currPackage = getPackage( value ); |
177 | if ( !currPackage ) | 178 | if ( !currPackage ) |
178 | { | 179 | { |
179 | packageList.push_back( Package( value ) ); | 180 | packageList.push_back( Package( value ) ); |
180 | currPackage = &(packageList.back()); | 181 | currPackage = &(packageList.back()); |
182 | currPackage->setInstalledTo( dest ); | ||
181 | 183 | ||
182 | if ( installingToRoot ) | 184 | if ( installingToRoot ) |
183 | currPackage->setInstalledToRoot( true ); | 185 | currPackage->setInstalledToRoot( true ); |
184 | } | 186 | } |
187 | else | ||
188 | { | ||
189 | if (currPackage->getStatus().find( "deinstall" ) != -1 ) | ||
190 | currPackage->setInstalledTo( dest ); | ||
191 | } | ||
185 | } | 192 | } |
186 | else if ( key == "Version" ) | 193 | else if ( key == "Version" ) |
187 | { | 194 | { |
188 | if ( currPackage ) | 195 | if ( currPackage ) |
189 | currPackage->setVersion( value ); | 196 | currPackage->setVersion( value ); |
190 | } | 197 | } |
191 | else if ( key == "Status" ) | 198 | else if ( key == "Status" ) |
192 | { | 199 | { |
193 | if ( currPackage ) | 200 | if ( currPackage ) |
194 | currPackage->setStatus( value ); | 201 | currPackage->setStatus( value ); |
195 | } | 202 | } |
196 | else if ( key == "Description" ) | 203 | else if ( key == "Description" ) |
197 | { | 204 | { |
198 | if ( currPackage ) | 205 | if ( currPackage ) |
199 | currPackage->setDescription( value ); | 206 | currPackage->setDescription( value ); |
200 | } | 207 | } |
201 | else if ( key == "Filename" ) | 208 | else if ( key == "Filename" ) |
202 | { | 209 | { |
203 | if ( currPackage ) | 210 | if ( currPackage ) |
204 | currPackage->setFilename( value ); | 211 | currPackage->setFilename( value ); |
205 | } | 212 | } |
206 | else if ( key == "" ) | 213 | else if ( key == "" ) |
207 | { | 214 | { |
208 | newPackage = true; | 215 | newPackage = true; |
209 | } | 216 | } |
210 | } while ( !in.eof() ); | 217 | } while ( !in.eof() ); |
211 | 218 | ||
212 | in.close(); | 219 | in.close(); |
213 | 220 | ||
214 | // build local packages | 221 | // build local packages |
215 | buildLocalPackages( local ); | 222 | buildLocalPackages( local ); |
216 | } | 223 | } |
217 | 224 | ||
218 | void Server :: buildLocalPackages( Server *local ) | 225 | void Server :: buildLocalPackages( Server *local ) |
219 | { | 226 | { |
220 | for ( unsigned int i = 0 ; i < packageList.size() ; ++i ) | 227 | for ( unsigned int i = 0 ; i < packageList.size() ; ++i ) |
221 | { | 228 | { |
222 | QString name = packageList[i].getPackageName(); | 229 | QString name = packageList[i].getPackageName(); |
223 | if ( local ) | 230 | if ( local ) |
224 | packageList[i].setLocalPackage( local->getPackage( name ) ); | 231 | packageList[i].setLocalPackage( local->getPackage( name ) ); |
225 | else | 232 | else |
226 | packageList[i].setLocalPackage( 0 ); | 233 | packageList[i].setLocalPackage( 0 ); |
227 | } | 234 | } |
228 | 235 | ||
229 | } | 236 | } |
230 | 237 | ||
231 | Package *Server :: getPackage( QString &name ) | 238 | Package *Server :: getPackage( QString &name ) |
232 | { | 239 | { |
233 | return getPackage( (const char *)name ); | 240 | return getPackage( (const char *)name ); |
234 | } | 241 | } |
235 | 242 | ||
236 | Package *Server :: getPackage( const char *name ) | 243 | Package *Server :: getPackage( const char *name ) |
237 | { | 244 | { |
238 | Package *ret = 0; | 245 | Package *ret = 0; |
239 | 246 | ||
240 | for ( unsigned int i = 0 ; i < packageList.size() && ret == 0; ++i ) | 247 | for ( unsigned int i = 0 ; i < packageList.size() && ret == 0; ++i ) |
241 | { | 248 | { |
242 | if ( packageList[i].getPackageName() == name ) | 249 | if ( packageList[i].getPackageName() == name ) |
243 | ret = &packageList[i]; | 250 | ret = &packageList[i]; |
244 | } | 251 | } |
245 | 252 | ||
246 | return ret; | 253 | return ret; |
247 | } | 254 | } |
248 | 255 | ||
249 | QString Server :: toString() | 256 | QString Server :: toString() |
250 | { | 257 | { |
251 | QString ret = "Server\n name - " + serverName + | 258 | QString ret = "Server\n name - " + serverName + |
252 | "\n url - " + serverUrl + | 259 | "\n url - " + serverUrl + |
253 | "\n"; | 260 | "\n"; |
254 | 261 | ||
255 | for ( unsigned int i = 0 ; i < packageList.size() ; ++i ) | 262 | for ( unsigned int i = 0 ; i < packageList.size() ; ++i ) |
256 | ret += "\n " + packageList[i].toString(); | 263 | ret += "\n " + packageList[i].toString(); |
257 | 264 | ||
258 | 265 | ||
259 | return ret; | 266 | return ret; |
260 | } | 267 | } |
261 | 268 | ||
262 | vector<Package> &Server::getPackageList() | 269 | vector<Package> &Server::getPackageList() |
263 | { | 270 | { |
264 | return packageList; | 271 | return packageList; |
265 | } | 272 | } |
266 | 273 | ||
diff --git a/noncore/settings/aqpkg/server.h b/noncore/settings/aqpkg/server.h index 5f83f75..e9f434c 100644 --- a/noncore/settings/aqpkg/server.h +++ b/noncore/settings/aqpkg/server.h | |||
@@ -1,66 +1,65 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | server.h - description | 2 | server.h - 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 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | #ifndef SERVER_H | 17 | #ifndef SERVER_H |
18 | #define SERVER_H | 18 | #define SERVER_H |
19 | 19 | ||
20 | #include <qstring.h> | 20 | #include <qstring.h> |
21 | 21 | ||
22 | #include <vector> | 22 | #include <vector> |
23 | using namespace std; | 23 | using namespace std; |
24 | 24 | ||
25 | #include "package.h" | 25 | #include "package.h" |
26 | #include "destination.h" | 26 | #include "destination.h" |
27 | 27 | ||
28 | class Server | 28 | class Server |
29 | { | 29 | { |
30 | public: | 30 | public: |
31 | Server() {} | 31 | Server() {} |
32 | Server( const char *name, const char *url ); | 32 | Server( const char *name, const char *url ); |
33 | Server( const char *name, const char *url, const char *file ); | 33 | Server( const char *name, const char *url, const char *file ); |
34 | ~Server(); | 34 | ~Server(); |
35 | 35 | ||
36 | void cleanUp(); | 36 | void cleanUp(); |
37 | 37 | ||
38 | void readStatusFile( vector<Destination> &v ); | 38 | void readStatusFile( vector<Destination> &v ); |
39 | void readLocalIpks( Server *local ); | 39 | void readLocalIpks( Server *local ); |
40 | void readPackageFile( Server *local = 0, bool clearAll = true, bool installedToRoot= false ); | 40 | void readPackageFile( Server *local = 0, bool clearAll = true, bool installedToRoot= false, Destination *dest = 0 ); |
41 | void buildLocalPackages( Server *local ); | 41 | void buildLocalPackages( Server *local ); |
42 | Package *getPackage( const char *name ); | 42 | Package *getPackage( const char *name ); |
43 | Package *getPackage( QString &name ); | 43 | Package *getPackage( QString &name ); |
44 | QString toString(); | 44 | QString toString(); |
45 | vector<Package> &getPackageList(); | 45 | vector<Package> &getPackageList(); |
46 | bool isServerActive() { return active; } | 46 | bool isServerActive() { return active; } |
47 | 47 | ||
48 | void setServerName( const QString &name ) { serverName = name; } | 48 | void setServerName( const QString &name ) { serverName = name; } |
49 | void setServerUrl( const QString &url ) { serverUrl = url; } | 49 | void setServerUrl( const QString &url ) { serverUrl = url; } |
50 | void setActive( bool val ) { active = val; } | 50 | void setActive( bool val ) { active = val; } |
51 | QString &getServerName() { return serverName; } | 51 | QString &getServerName() { return serverName; } |
52 | QString &getServerUrl() { return serverUrl; } | 52 | QString &getServerUrl() { return serverUrl; } |
53 | 53 | ||
54 | protected: | 54 | protected: |
55 | 55 | ||
56 | private: | 56 | private: |
57 | QString serverName; | 57 | QString serverName; |
58 | QString serverUrl; | 58 | QString serverUrl; |
59 | QString packageFile; | 59 | QString packageFile; |
60 | bool active; | 60 | bool active; |
61 | 61 | ||
62 | |||
63 | vector<Package> packageList; | 62 | vector<Package> packageList; |
64 | }; | 63 | }; |
65 | 64 | ||
66 | #endif | 65 | #endif |