author | drw <drw> | 2003-04-29 02:28:16 (UTC) |
---|---|---|
committer | drw <drw> | 2003-04-29 02:28:16 (UTC) |
commit | e096c9d1f2be1ec74ede583fc4221871a56ef508 (patch) (unidiff) | |
tree | 1c6f49430179e2f262179951477bbe4bd7d32e71 /noncore/settings/aqpkg/datamgr.cpp | |
parent | 2f26f696ca6acd05aa615e15d891eede9907a1c0 (diff) | |
download | opie-e096c9d1f2be1ec74ede583fc4221871a56ef508.zip opie-e096c9d1f2be1ec74ede583fc4221871a56ef508.tar.gz opie-e096c9d1f2be1ec74ede583fc4221871a56ef508.tar.bz2 |
Give aqpkg standard source headers and some minor code clean-up.
Diffstat (limited to 'noncore/settings/aqpkg/datamgr.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/aqpkg/datamgr.cpp | 139 |
1 files changed, 80 insertions, 59 deletions
diff --git a/noncore/settings/aqpkg/datamgr.cpp b/noncore/settings/aqpkg/datamgr.cpp index 79f36e1..cd0c78f 100644 --- a/noncore/settings/aqpkg/datamgr.cpp +++ b/noncore/settings/aqpkg/datamgr.cpp | |||
@@ -1,40 +1,50 @@ | |||
1 | /*************************************************************************** | 1 | /* |
2 | datamgr.cpp - description | 2 | This file is part of the OPIE Project |
3 | ------------------- | 3 | |
4 | begin : Thu Aug 29 2002 | 4 | =. Copyright (c) 2002 Andy Qua <andy.qua@blueyonder.co.uk> |
5 | copyright : (C) 2002 by Andy Qua | 5 | .=l. Dan Williams <drw@handhelds.org> |
6 | email : andy.qua@blueyonder.co.uk | 6 | .>+-= |
7 | ***************************************************************************/ | 7 | _;:, .> :=|. This file is free software; you can |
8 | 8 | .> <`_, > . <= redistribute it and/or modify it under | |
9 | /*************************************************************************** | 9 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
10 | * * | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | * it under the terms of the GNU General Public License as published by * | 12 | ._= =} : or (at your option) any later version. |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | .%`+i> _;_. |
14 | * (at your option) any later version. * | 14 | .i_,=:_. -<s. This file is distributed in the hope that |
15 | * * | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | ***************************************************************************/ | 16 | : .. .:, . . . without even the implied warranty of |
17 | #include <fstream> | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | #include <iostream> | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
19 | using namespace std; | 19 | ..}^=.= = ; Public License for more details. |
20 | ++= -. .` .: | ||
21 | : = ...= . :.=- You should have received a copy of the GNU | ||
22 | -. .:....=;==+<; General Public License along with this file; | ||
23 | -_. . . )=. = see the file COPYING. If not, write to the | ||
24 | -- :-=` Free Software Foundation, Inc., | ||
25 | 59 Temple Place - Suite 330, | ||
26 | Boston, MA 02111-1307, USA. | ||
27 | |||
28 | */ | ||
20 | 29 | ||
21 | #ifdef QWS | 30 | #ifdef QWS |
22 | #include <qpe/config.h> | 31 | #include <qpe/config.h> |
23 | #include <qpe/qpeapplication.h> | 32 | #include <qpe/qpeapplication.h> |
24 | #else | 33 | #else |
25 | #include <qapplication.h> | 34 | #include <qapplication.h> |
26 | #endif | 35 | #endif |
27 | 36 | ||
28 | #include <stdio.h> | 37 | #include <qfile.h> |
38 | #include <qtextstream.h> | ||
29 | 39 | ||
30 | #include "datamgr.h" | 40 | #include "datamgr.h" |
31 | #include "global.h" | 41 | #include "global.h" |
32 | 42 | ||
33 | 43 | ||
34 | QString DataManager::availableCategories = ""; | 44 | QString DataManager::availableCategories = ""; |
35 | DataManager::DataManager() | 45 | DataManager::DataManager() |
36 | : QObject( 0x0, 0x0 ) | 46 | : QObject( 0x0, 0x0 ) |
37 | { | 47 | { |
38 | activeServer = ""; | 48 | activeServer = ""; |
39 | availableCategories = "#"; | 49 | availableCategories = "#"; |
40 | 50 | ||
@@ -79,25 +89,24 @@ void DataManager :: loadServers() | |||
79 | Config cfg( "aqpkg" ); | 89 | Config cfg( "aqpkg" ); |
80 | cfg.setGroup( "destinations" ); | 90 | cfg.setGroup( "destinations" ); |
81 | #endif | 91 | #endif |
82 | 92 | ||
83 | // Read file from /etc/ipkg.conf | 93 | // Read file from /etc/ipkg.conf |
84 | QString ipkg_conf = IPKG_CONF; | 94 | QString ipkg_conf = IPKG_CONF; |
85 | FILE *fp; | 95 | FILE *fp; |
86 | fp = fopen( ipkg_conf, "r" ); | 96 | fp = fopen( ipkg_conf, "r" ); |
87 | char line[130]; | 97 | char line[130]; |
88 | QString lineStr; | 98 | QString lineStr; |
89 | if ( fp == NULL ) | 99 | if ( fp == NULL ) |
90 | { | 100 | { |
91 | cout << "Couldn't open " << ipkg_conf << "! err = " << fp << endl; | ||
92 | return; | 101 | return; |
93 | } | 102 | } |
94 | else | 103 | else |
95 | { | 104 | { |
96 | while ( fgets( line, sizeof line, fp) != NULL ) | 105 | while ( fgets( line, sizeof line, fp) != NULL ) |
97 | { | 106 | { |
98 | lineStr = line; | 107 | lineStr = line; |
99 | if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) ) | 108 | if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) ) |
100 | { | 109 | { |
101 | char alias[20]; | 110 | char alias[20]; |
102 | char url[100]; | 111 | char url[100]; |
103 | 112 | ||
@@ -189,103 +198,115 @@ void DataManager :: reloadServerData( ) | |||
189 | // The other servers files hold the contents of the server package list | 198 | // The other servers files hold the contents of the server package list |
190 | if ( serverName == LOCAL_SERVER ) | 199 | if ( serverName == LOCAL_SERVER ) |
191 | server->readStatusFile( destList ); | 200 | server->readStatusFile( destList ); |
192 | else if ( serverName == LOCAL_IPKGS ) | 201 | else if ( serverName == LOCAL_IPKGS ) |
193 | server->readLocalIpks( getServer( LOCAL_SERVER ) ); | 202 | server->readLocalIpks( getServer( LOCAL_SERVER ) ); |
194 | else | 203 | else |
195 | server->readPackageFile( getServer( LOCAL_SERVER ) ); | 204 | server->readPackageFile( getServer( LOCAL_SERVER ) ); |
196 | } | 205 | } |
197 | } | 206 | } |
198 | 207 | ||
199 | void DataManager :: writeOutIpkgConf() | 208 | void DataManager :: writeOutIpkgConf() |
200 | { | 209 | { |
210 | QFile f( IPKG_CONF ); | ||
211 | if ( !f.open( IO_WriteOnly ) ) | ||
212 | { | ||
213 | return; | ||
214 | } | ||
215 | |||
216 | QTextStream t( &f ); | ||
217 | /* | ||
201 | QString ipkg_conf = IPKG_CONF; | 218 | QString ipkg_conf = IPKG_CONF; |
202 | ofstream out( ipkg_conf ); | 219 | ofstream out( ipkg_conf ); |
220 | */ | ||
221 | t << "# Written by AQPkg\n"; | ||
222 | t << "# Must have one or more source entries of the form:\n"; | ||
223 | t << "#\n"; | ||
224 | t << "# src <src-name> <source-url>\n"; | ||
225 | t << "#\n"; | ||
226 | t << "# and one or more destination entries of the form:\n"; | ||
227 | t << "#\n"; | ||
228 | t << "# dest <dest-name> <target-path>\n"; | ||
229 | t << "#\n"; | ||
230 | t << "# where <src-name> and <dest-names> are identifiers that\n"; | ||
231 | t << "# should match [a-zA-Z0-9._-]+, <source-url> should be a\n"; | ||
232 | t << "# URL that points to a directory containing a Familiar\n"; | ||
233 | t << "# Packages file, and <target-path> should be a directory\n"; | ||
234 | t << "# that exists on the target system.\n\n"; | ||
203 | 235 | ||
204 | out << "# Written by AQPkg" << endl; | ||
205 | out << "# Must have one or more source entries of the form:" << endl; | ||
206 | out << "#" << endl; | ||
207 | out << "# src <src-name> <source-url>" << endl; | ||
208 | out << "#" << endl; | ||
209 | out << "# and one or more destination entries of the form:" << endl; | ||
210 | out << "#" << endl; | ||
211 | out << "# dest <dest-name> <target-path>" << endl; | ||
212 | out << "#" << 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; | ||
215 | out << "# URL that points to a directory containing a Familiar" << endl; | ||
216 | out << "# Packages file, and <target-path> should be a directory" << endl; | ||
217 | out << "# that exists on the target system." << endl << endl; | ||
218 | |||
219 | // Write out servers | 236 | // Write out servers |
220 | Server *server; | 237 | Server *server; |
221 | QListIterator<Server> it( serverList ); | 238 | QListIterator<Server> it( serverList ); |
222 | while ( it.current() ) | 239 | while ( it.current() ) |
223 | { | 240 | { |
224 | server = it.current(); | 241 | server = it.current(); |
225 | QString alias = server->getServerName(); | 242 | QString alias = server->getServerName(); |
226 | // Don't write out local as its a dummy | 243 | // Don't write out local as its a dummy |
227 | if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS ) | 244 | if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS ) |
228 | { | 245 | { |
229 | QString url = server->getServerUrl();; | 246 | QString url = server->getServerUrl();; |
230 | 247 | ||
231 | if ( !server->isServerActive() ) | 248 | if ( !server->isServerActive() ) |
232 | out << "#"; | 249 | t << "#"; |
233 | out << "src " << alias << " " << url << endl; | 250 | t << "src " << alias << " " << url << endl; |
234 | } | 251 | } |
235 | 252 | ||
236 | ++it; | 253 | ++it; |
237 | } | 254 | } |
238 | 255 | ||
239 | out << endl; | 256 | t << endl; |
240 | 257 | ||
241 | // Write out destinations | 258 | // Write out destinations |
242 | QListIterator<Destination> it2( destList ); | 259 | QListIterator<Destination> it2( destList ); |
243 | while ( it2.current() ) | 260 | while ( it2.current() ) |
244 | { | 261 | { |
245 | out << "dest " << it2.current()->getDestinationName() << " " << it2.current()->getDestinationPath() << endl; | 262 | t << "dest " << it2.current()->getDestinationName() << " " << it2.current()->getDestinationPath() << endl; |
246 | ++it2; | 263 | ++it2; |
247 | } | 264 | } |
248 | 265 | ||
249 | out << endl; | 266 | t << endl; |
250 | out << "# Proxy Support" << endl; | 267 | t << "# Proxy Support\n"; |
251 | 268 | ||
252 | if ( !httpProxyEnabled && httpProxy == "" ) | 269 | if ( !httpProxyEnabled && httpProxy == "" ) |
253 | out << "#option http_proxy http://proxy.tld:3128" << endl; | 270 | t << "#option http_proxy http://proxy.tld:3128\n"; |
254 | else | 271 | else |
255 | { | 272 | { |
256 | if ( !httpProxyEnabled ) | 273 | if ( !httpProxyEnabled ) |
257 | out << "#"; | 274 | t << "#"; |
258 | out << "option http_proxy " << httpProxy << endl; | 275 | t << "option http_proxy " << httpProxy << endl; |
259 | } | 276 | } |
260 | 277 | ||
261 | if ( !ftpProxyEnabled && ftpProxy == "" ) | 278 | if ( !ftpProxyEnabled && ftpProxy == "" ) |
262 | out << "#option ftp_proxy http://proxy.tld:3128" << endl; | 279 | t << "#option ftp_proxy http://proxy.tld:3128\n"; |
263 | else | 280 | else |
264 | { | 281 | { |
265 | if ( !ftpProxyEnabled ) | 282 | if ( !ftpProxyEnabled ) |
266 | out << "#"; | 283 | t << "#"; |
267 | out << "option ftp_proxy " << ftpProxy << endl; | 284 | t << "option ftp_proxy " << ftpProxy << endl; |
268 | } | 285 | } |
269 | if ( proxyUsername == "" || (!httpProxyEnabled && !ftpProxyEnabled) ) | 286 | if ( proxyUsername == "" || (!httpProxyEnabled && !ftpProxyEnabled) ) |
270 | out << "#option proxy_username <username>" << endl; | 287 | t << "#option proxy_username <username>\n"; |
271 | else | 288 | else |
272 | out << "option proxy_username " << proxyUsername << endl; | 289 | t << "option proxy_username " << proxyUsername << endl; |
273 | if ( proxyPassword == "" || (!httpProxyEnabled && !ftpProxyEnabled) ) | 290 | if ( proxyPassword == "" || (!httpProxyEnabled && !ftpProxyEnabled) ) |
274 | out << "#option proxy_password <password>" << endl << endl; | 291 | t << "#option proxy_password <password>\n\n"; |
275 | else | 292 | else |
276 | out << "option proxy_password " << proxyPassword << endl<< endl; | 293 | t << "option proxy_password " << proxyPassword << endl<< endl; |
277 | |||
278 | out << "# Offline mode (for use in constructing flash images offline)" << endl; | ||
279 | out << "#option offline_root target" << endl; | ||
280 | 294 | ||
295 | t << "# Offline mode (for use in constructing flash images offline)\n"; | ||
296 | t << "#option offline_root target\n"; | ||
281 | 297 | ||
282 | out.close(); | 298 | f.close(); |
283 | } | 299 | } |
284 | 300 | ||
285 | 301 | ||
286 | void DataManager :: setAvailableCategories( QString section ) | 302 | void DataManager :: setAvailableCategories( QString section ) |
287 | { | 303 | { |
288 | section = section.lower(); | 304 | QString sectstr = "#"; |
289 | if ( availableCategories.find( "#" + section + "#" ) == -1 ) | 305 | sectstr.append( section.lower() ); |
290 | availableCategories += section + "#"; | 306 | sectstr.append( "#" ); |
307 | if ( availableCategories.find( sectstr ) == -1 ) | ||
308 | { | ||
309 | availableCategories.append( section ); | ||
310 | availableCategories.append( "#" ); | ||
311 | } | ||
291 | } | 312 | } |