Diffstat (limited to 'noncore/settings/aqpkg/datamgr.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/aqpkg/datamgr.cpp | 82 |
1 files changed, 42 insertions, 40 deletions
diff --git a/noncore/settings/aqpkg/datamgr.cpp b/noncore/settings/aqpkg/datamgr.cpp index 2c83e28..79f36e1 100644 --- a/noncore/settings/aqpkg/datamgr.cpp +++ b/noncore/settings/aqpkg/datamgr.cpp | |||
@@ -1,289 +1,291 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | datamgr.cpp - description | 2 | datamgr.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Thu Aug 29 2002 | 4 | begin : Thu Aug 29 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 | #include <fstream> | 17 | #include <fstream> |
18 | #include <iostream> | 18 | #include <iostream> |
19 | using namespace std; | 19 | using namespace std; |
20 | 20 | ||
21 | #ifdef QWS | 21 | #ifdef QWS |
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | #include <qpe/qpeapplication.h> | 23 | #include <qpe/qpeapplication.h> |
24 | #else | 24 | #else |
25 | #include <qapplication.h> | 25 | #include <qapplication.h> |
26 | #endif | 26 | #endif |
27 | 27 | ||
28 | #include <stdio.h> | 28 | #include <stdio.h> |
29 | 29 | ||
30 | #include "datamgr.h" | 30 | #include "datamgr.h" |
31 | #include "global.h" | 31 | #include "global.h" |
32 | 32 | ||
33 | 33 | ||
34 | QString DataManager::availableCategories = ""; | 34 | QString DataManager::availableCategories = ""; |
35 | DataManager::DataManager() | 35 | DataManager::DataManager() |
36 | : QObject( 0x0, 0x0 ) | 36 | : QObject( 0x0, 0x0 ) |
37 | { | 37 | { |
38 | activeServer = ""; | 38 | activeServer = ""; |
39 | availableCategories = "#"; | 39 | availableCategories = "#"; |
40 | |||
41 | serverList.setAutoDelete( TRUE ); | ||
42 | destList.setAutoDelete( TRUE ); | ||
40 | } | 43 | } |
41 | 44 | ||
42 | DataManager::~DataManager() | 45 | DataManager::~DataManager() |
43 | { | 46 | { |
44 | } | 47 | } |
45 | 48 | ||
46 | vector<Server>::iterator DataManager :: getServer( const char *name ) | 49 | Server *DataManager :: getServer( const char *name ) |
47 | { | 50 | { |
48 | vector<Server>::iterator it = serverList.begin(); | 51 | QListIterator<Server> it( serverList ); |
49 | while ( it != serverList.end() ) | 52 | while ( it.current() && it.current()->getServerName() != name ) |
50 | { | 53 | { |
51 | if ( it->getServerName() == name ) | ||
52 | return it; | ||
53 | |||
54 | ++it; | 54 | ++it; |
55 | } | 55 | } |
56 | 56 | ||
57 | return serverList.end(); | 57 | return it.current(); |
58 | } | 58 | } |
59 | 59 | ||
60 | vector<Destination>::iterator DataManager :: getDestination( const char *name ) | 60 | Destination *DataManager :: getDestination( const char *name ) |
61 | { | 61 | { |
62 | vector<Destination>::iterator it = destList.begin(); | 62 | QListIterator<Destination> it( destList ); |
63 | while ( it != destList.end() ) | 63 | while ( it.current() && it.current()->getDestinationName() != name ) |
64 | { | 64 | { |
65 | if ( it->getDestinationName() == name ) | ||
66 | return it; | ||
67 | |||
68 | ++it; | 65 | ++it; |
69 | } | 66 | } |
70 | 67 | ||
71 | return destList.end(); | 68 | return it.current(); |
72 | } | 69 | } |
73 | 70 | ||
74 | void DataManager :: loadServers() | 71 | void DataManager :: loadServers() |
75 | { | 72 | { |
76 | // First add our local server - not really a server but | 73 | // First add our local server - not really a server but |
77 | // the local config (which packages are installed) | 74 | // the local config (which packages are installed) |
78 | serverList.push_back( Server( LOCAL_SERVER, "" ) ); | 75 | serverList.append( new Server( LOCAL_SERVER, "" ) ); |
79 | serverList.push_back( Server( LOCAL_IPKGS, "" ) ); | 76 | serverList.append( new Server( LOCAL_IPKGS, "" ) ); |
80 | 77 | ||
81 | #ifdef QWS | 78 | #ifdef QWS |
82 | Config cfg( "aqpkg" ); | 79 | Config cfg( "aqpkg" ); |
83 | cfg.setGroup( "destinations" ); | 80 | cfg.setGroup( "destinations" ); |
84 | #endif | 81 | #endif |
85 | 82 | ||
86 | // Read file from /etc/ipkg.conf | 83 | // Read file from /etc/ipkg.conf |
87 | QString ipkg_conf = IPKG_CONF; | 84 | QString ipkg_conf = IPKG_CONF; |
88 | FILE *fp; | 85 | FILE *fp; |
89 | fp = fopen( ipkg_conf, "r" ); | 86 | fp = fopen( ipkg_conf, "r" ); |
90 | char line[130]; | 87 | char line[130]; |
91 | QString lineStr; | 88 | QString lineStr; |
92 | if ( fp == NULL ) | 89 | if ( fp == NULL ) |
93 | { | 90 | { |
94 | cout << "Couldn't open " << ipkg_conf << "! err = " << fp << endl; | 91 | cout << "Couldn't open " << ipkg_conf << "! err = " << fp << endl; |
95 | return; | 92 | return; |
96 | } | 93 | } |
97 | else | 94 | else |
98 | { | 95 | { |
99 | while ( fgets( line, sizeof line, fp) != NULL ) | 96 | while ( fgets( line, sizeof line, fp) != NULL ) |
100 | { | 97 | { |
101 | lineStr = line; | 98 | lineStr = line; |
102 | if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) ) | 99 | if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) ) |
103 | { | 100 | { |
104 | char alias[20]; | 101 | char alias[20]; |
105 | char url[100]; | 102 | char url[100]; |
106 | 103 | ||
107 | // Looks a little wierd but read up to the r of src (throwing it away), | 104 | // Looks a little wierd but read up to the r of src (throwing it away), |
108 | // then read up to the next space and throw that away, the alias | 105 | // then read up to the next space and throw that away, the alias |
109 | // is next. | 106 | // is next. |
110 | // Should Handle #src, # src, src, and combinations of | 107 | // Should Handle #src, # src, src, and combinations of |
111 | sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url ); | 108 | sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url ); |
112 | Server s( alias, url ); | 109 | Server *s = new Server( alias, url ); |
113 | if ( lineStr.startsWith( "src" ) ) | 110 | if ( lineStr.startsWith( "src" ) ) |
114 | s.setActive( true ); | 111 | s->setActive( true ); |
115 | else | 112 | else |
116 | s.setActive( false ); | 113 | s->setActive( false ); |
117 | 114 | ||
118 | serverList.push_back( s ); | 115 | serverList.append( s ); |
119 | 116 | ||
120 | } | 117 | } |
121 | else if ( lineStr.startsWith( "dest" ) ) | 118 | else if ( lineStr.startsWith( "dest" ) ) |
122 | { | 119 | { |
123 | char alias[20]; | 120 | char alias[20]; |
124 | char path[50]; | 121 | char path[50]; |
125 | sscanf( lineStr, "%*[^ ] %s %s", alias, path ); | 122 | sscanf( lineStr, "%*[^ ] %s %s", alias, path ); |
126 | Destination d( alias, path ); | 123 | Destination *d = new Destination( alias, path ); |
127 | bool linkToRoot = true; | 124 | bool linkToRoot = true; |
128 | #ifdef QWS | 125 | #ifdef QWS |
129 | QString key = alias; | 126 | QString key = alias; |
130 | key += "_linkToRoot"; | 127 | key += "_linkToRoot"; |
131 | linkToRoot = cfg.readBoolEntry( key, true ); | 128 | linkToRoot = cfg.readBoolEntry( key, true ); |
132 | #endif | 129 | #endif |
133 | d.linkToRoot( linkToRoot ); | 130 | d->linkToRoot( linkToRoot ); |
134 | 131 | ||
135 | destList.push_back( d ); | 132 | destList.append( d ); |
136 | } | 133 | } |
137 | else if ( lineStr.startsWith( "option" ) || lineStr.startsWith( "#option" ) ) | 134 | else if ( lineStr.startsWith( "option" ) || lineStr.startsWith( "#option" ) ) |
138 | { | 135 | { |
139 | char type[20]; | 136 | char type[20]; |
140 | char val[100]; | 137 | char val[100]; |
141 | sscanf( lineStr, "%*[^ ] %s %s", type, val ); | 138 | sscanf( lineStr, "%*[^ ] %s %s", type, val ); |
142 | if ( stricmp( type, "http_proxy" ) == 0 ) | 139 | if ( stricmp( type, "http_proxy" ) == 0 ) |
143 | { | 140 | { |
144 | httpProxy = val; | 141 | httpProxy = val; |
145 | if ( lineStr.startsWith( "#" ) ) | 142 | if ( lineStr.startsWith( "#" ) ) |
146 | httpProxyEnabled = false; | 143 | httpProxyEnabled = false; |
147 | else | 144 | else |
148 | httpProxyEnabled = true; | 145 | httpProxyEnabled = true; |
149 | } | 146 | } |
150 | if ( stricmp( type, "ftp_proxy" ) == 0 ) | 147 | if ( stricmp( type, "ftp_proxy" ) == 0 ) |
151 | { | 148 | { |
152 | ftpProxy = val; | 149 | ftpProxy = val; |
153 | if ( lineStr.startsWith( "#" ) ) | 150 | if ( lineStr.startsWith( "#" ) ) |
154 | ftpProxyEnabled = false; | 151 | ftpProxyEnabled = false; |
155 | else | 152 | else |
156 | ftpProxyEnabled = true; | 153 | ftpProxyEnabled = true; |
157 | } | 154 | } |
158 | if ( stricmp( type, "proxy_username" ) == 0 ) | 155 | if ( stricmp( type, "proxy_username" ) == 0 ) |
159 | proxyUsername = val; | 156 | proxyUsername = val; |
160 | if ( stricmp( type, "proxy_password" ) == 0 ) | 157 | if ( stricmp( type, "proxy_password" ) == 0 ) |
161 | proxyPassword = val; | 158 | proxyPassword = val; |
162 | } | 159 | } |
163 | } | 160 | } |
164 | } | 161 | } |
165 | fclose( fp ); | 162 | fclose( fp ); |
166 | 163 | ||
167 | reloadServerData( ); | 164 | reloadServerData( ); |
168 | } | 165 | } |
169 | 166 | ||
170 | void DataManager :: reloadServerData( ) | 167 | void DataManager :: reloadServerData( ) |
171 | { | 168 | { |
172 | emit progressSetSteps( serverList.size() ); | 169 | emit progressSetSteps( serverList.count() ); |
173 | emit progressSetMessage( tr( "Reading configuration..." ) ); | 170 | emit progressSetMessage( tr( "Reading configuration..." ) ); |
174 | 171 | ||
175 | vector<Server>::iterator it = serverList.begin(); | ||
176 | QString serverName; | 172 | QString serverName; |
177 | int i = 0; | 173 | int i = 0; |
178 | for ( it = serverList.begin() ; it != serverList.end() ; ++it ) | 174 | |
175 | Server *server; | ||
176 | QListIterator<Server> it( serverList ); | ||
177 | for ( ; it.current(); ++it ) | ||
179 | { | 178 | { |
180 | serverName = it->getServerName(); | 179 | server = it.current(); |
180 | serverName = server->getServerName(); | ||
181 | i++; | 181 | i++; |
182 | emit progressUpdate( i ); | 182 | emit progressUpdate( i ); |
183 | qApp->processEvents(); | 183 | qApp->processEvents(); |
184 | 184 | ||
185 | // Now we've read the config file in we need to read the servers | 185 | // Now we've read the config file in we need to read the servers |
186 | // The local server is a special case. This holds the contents of the | 186 | // The local server is a special case. This holds the contents of the |
187 | // status files the number of which depends on how many destinations | 187 | // status files the number of which depends on how many destinations |
188 | // we've set up | 188 | // we've set up |
189 | // The other servers files hold the contents of the server package list | 189 | // The other servers files hold the contents of the server package list |
190 | if ( serverName == LOCAL_SERVER ) | 190 | if ( serverName == LOCAL_SERVER ) |
191 | it->readStatusFile( destList ); | 191 | server->readStatusFile( destList ); |
192 | else if ( serverName == LOCAL_IPKGS ) | 192 | else if ( serverName == LOCAL_IPKGS ) |
193 | it->readLocalIpks( &( *getServer( LOCAL_SERVER ) ) ); | 193 | server->readLocalIpks( getServer( LOCAL_SERVER ) ); |
194 | else | 194 | else |
195 | it->readPackageFile( &( *getServer( LOCAL_SERVER ) ) ); | 195 | server->readPackageFile( getServer( LOCAL_SERVER ) ); |
196 | } | 196 | } |
197 | } | 197 | } |
198 | 198 | ||
199 | void DataManager :: writeOutIpkgConf() | 199 | void DataManager :: writeOutIpkgConf() |
200 | { | 200 | { |
201 | QString ipkg_conf = IPKG_CONF; | 201 | QString ipkg_conf = IPKG_CONF; |
202 | ofstream out( ipkg_conf ); | 202 | ofstream out( ipkg_conf ); |
203 | 203 | ||
204 | out << "# Written by AQPkg" << endl; | 204 | out << "# Written by AQPkg" << endl; |
205 | out << "# Must have one or more source entries of the form:" << endl; | 205 | out << "# Must have one or more source entries of the form:" << endl; |
206 | out << "#" << endl; | 206 | out << "#" << endl; |
207 | out << "# src <src-name> <source-url>" << endl; | 207 | out << "# src <src-name> <source-url>" << endl; |
208 | out << "#" << endl; | 208 | out << "#" << endl; |
209 | out << "# and one or more destination entries of the form:" << endl; | 209 | out << "# and one or more destination entries of the form:" << endl; |
210 | out << "#" << endl; | 210 | out << "#" << endl; |
211 | out << "# dest <dest-name> <target-path>" << endl; | 211 | out << "# dest <dest-name> <target-path>" << endl; |
212 | out << "#" << endl; | 212 | out << "#" << endl; |
213 | out << "# where <src-name> and <dest-names> are identifiers that" << endl; | 213 | out << "# where <src-name> and <dest-names> are identifiers that" << endl; |
214 | out << "# should match [a-zA-Z0-9._-]+, <source-url> should be a" << endl; | 214 | out << "# should match [a-zA-Z0-9._-]+, <source-url> should be a" << endl; |
215 | out << "# URL that points to a directory containing a Familiar" << endl; | 215 | out << "# URL that points to a directory containing a Familiar" << endl; |
216 | out << "# Packages file, and <target-path> should be a directory" << endl; | 216 | out << "# Packages file, and <target-path> should be a directory" << endl; |
217 | out << "# that exists on the target system." << endl << endl; | 217 | out << "# that exists on the target system." << endl << endl; |
218 | 218 | ||
219 | // Write out servers | 219 | // Write out servers |
220 | vector<Server>::iterator it = serverList.begin(); | 220 | Server *server; |
221 | while ( it != serverList.end() ) | 221 | QListIterator<Server> it( serverList ); |
222 | while ( it.current() ) | ||
222 | { | 223 | { |
223 | QString alias = it->getServerName(); | 224 | server = it.current(); |
225 | QString alias = server->getServerName(); | ||
224 | // Don't write out local as its a dummy | 226 | // Don't write out local as its a dummy |
225 | if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS ) | 227 | if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS ) |
226 | { | 228 | { |
227 | QString url = it->getServerUrl();; | 229 | QString url = server->getServerUrl();; |
228 | 230 | ||
229 | if ( !it->isServerActive() ) | 231 | if ( !server->isServerActive() ) |
230 | out << "#"; | 232 | out << "#"; |
231 | out << "src " << alias << " " << url << endl; | 233 | out << "src " << alias << " " << url << endl; |
232 | } | 234 | } |
233 | 235 | ||
234 | it++; | 236 | ++it; |
235 | } | 237 | } |
236 | 238 | ||
237 | out << endl; | 239 | out << endl; |
238 | 240 | ||
239 | // Write out destinations | 241 | // Write out destinations |
240 | vector<Destination>::iterator it2 = destList.begin(); | 242 | QListIterator<Destination> it2( destList ); |
241 | while ( it2 != destList.end() ) | 243 | while ( it2.current() ) |
242 | { | 244 | { |
243 | out << "dest " << it2->getDestinationName() << " " << it2->getDestinationPath() << endl; | 245 | out << "dest " << it2.current()->getDestinationName() << " " << it2.current()->getDestinationPath() << endl; |
244 | it2++; | 246 | ++it2; |
245 | } | 247 | } |
246 | 248 | ||
247 | out << endl; | 249 | out << endl; |
248 | out << "# Proxy Support" << endl; | 250 | out << "# Proxy Support" << endl; |
249 | 251 | ||
250 | if ( !httpProxyEnabled && httpProxy == "" ) | 252 | if ( !httpProxyEnabled && httpProxy == "" ) |
251 | out << "#option http_proxy http://proxy.tld:3128" << endl; | 253 | out << "#option http_proxy http://proxy.tld:3128" << endl; |
252 | else | 254 | else |
253 | { | 255 | { |
254 | if ( !httpProxyEnabled ) | 256 | if ( !httpProxyEnabled ) |
255 | out << "#"; | 257 | out << "#"; |
256 | out << "option http_proxy " << httpProxy << endl; | 258 | out << "option http_proxy " << httpProxy << endl; |
257 | } | 259 | } |
258 | 260 | ||
259 | if ( !ftpProxyEnabled && ftpProxy == "" ) | 261 | if ( !ftpProxyEnabled && ftpProxy == "" ) |
260 | out << "#option ftp_proxy http://proxy.tld:3128" << endl; | 262 | out << "#option ftp_proxy http://proxy.tld:3128" << endl; |
261 | else | 263 | else |
262 | { | 264 | { |
263 | if ( !ftpProxyEnabled ) | 265 | if ( !ftpProxyEnabled ) |
264 | out << "#"; | 266 | out << "#"; |
265 | out << "option ftp_proxy " << ftpProxy << endl; | 267 | out << "option ftp_proxy " << ftpProxy << endl; |
266 | } | 268 | } |
267 | if ( proxyUsername == "" || (!httpProxyEnabled && !ftpProxyEnabled) ) | 269 | if ( proxyUsername == "" || (!httpProxyEnabled && !ftpProxyEnabled) ) |
268 | out << "#option proxy_username <username>" << endl; | 270 | out << "#option proxy_username <username>" << endl; |
269 | else | 271 | else |
270 | out << "option proxy_username " << proxyUsername << endl; | 272 | out << "option proxy_username " << proxyUsername << endl; |
271 | if ( proxyPassword == "" || (!httpProxyEnabled && !ftpProxyEnabled) ) | 273 | if ( proxyPassword == "" || (!httpProxyEnabled && !ftpProxyEnabled) ) |
272 | out << "#option proxy_password <password>" << endl << endl; | 274 | out << "#option proxy_password <password>" << endl << endl; |
273 | else | 275 | else |
274 | out << "option proxy_password " << proxyPassword << endl<< endl; | 276 | out << "option proxy_password " << proxyPassword << endl<< endl; |
275 | 277 | ||
276 | out << "# Offline mode (for use in constructing flash images offline)" << endl; | 278 | out << "# Offline mode (for use in constructing flash images offline)" << endl; |
277 | out << "#option offline_root target" << endl; | 279 | out << "#option offline_root target" << endl; |
278 | 280 | ||
279 | 281 | ||
280 | out.close(); | 282 | out.close(); |
281 | } | 283 | } |
282 | 284 | ||
283 | 285 | ||
284 | void DataManager :: setAvailableCategories( QString section ) | 286 | void DataManager :: setAvailableCategories( QString section ) |
285 | { | 287 | { |
286 | section = section.lower(); | 288 | section = section.lower(); |
287 | if ( availableCategories.find( "#" + section + "#" ) == -1 ) | 289 | if ( availableCategories.find( "#" + section + "#" ) == -1 ) |
288 | availableCategories += section + "#"; | 290 | availableCategories += section + "#"; |
289 | } | 291 | } |