-rw-r--r-- | noncore/settings/aqpkg/datamgr.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/noncore/settings/aqpkg/datamgr.cpp b/noncore/settings/aqpkg/datamgr.cpp index 67f90a3..93daaba 100644 --- a/noncore/settings/aqpkg/datamgr.cpp +++ b/noncore/settings/aqpkg/datamgr.cpp | |||
@@ -1,315 +1,315 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | 3 | ||
4 | =. Copyright (c) 2002 Andy Qua <andy.qua@blueyonder.co.uk> | 4 | =. Copyright (c) 2002 Andy Qua <andy.qua@blueyonder.co.uk> |
5 | .=l. Dan Williams <drw@handhelds.org> | 5 | .=l. Dan Williams <drw@handhelds.org> |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This file is free software; you can | 7 | _;:, .> :=|. This file is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This file is distributed in the hope that | 14 | .i_,=:_. -<s. This file is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
19 | ..}^=.= = ; Public License for more details. | 19 | ..}^=.= = ; Public License for more details. |
20 | ++= -. .` .: | 20 | ++= -. .` .: |
21 | : = ...= . :.=- You should have received a copy of the GNU | 21 | : = ...= . :.=- You should have received a copy of the GNU |
22 | -. .:....=;==+<; General Public License along with this file; | 22 | -. .:....=;==+<; General Public License along with this file; |
23 | -_. . . )=. = see the file COPYING. If not, write to the | 23 | -_. . . )=. = see the file COPYING. If not, write to the |
24 | -- :-=` Free Software Foundation, Inc., | 24 | -- :-=` Free Software Foundation, Inc., |
25 | 59 Temple Place - Suite 330, | 25 | 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | 27 | ||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #ifdef QWS | 30 | #ifdef QWS |
31 | #include <qpe/config.h> | 31 | #include <qpe/config.h> |
32 | #include <qpe/qpeapplication.h> | 32 | #include <qpe/qpeapplication.h> |
33 | #else | 33 | #else |
34 | #include <qapplication.h> | 34 | #include <qapplication.h> |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | #include <qfile.h> | 37 | #include <qfile.h> |
38 | #include <qtextstream.h> | 38 | #include <qtextstream.h> |
39 | 39 | ||
40 | #include "datamgr.h" | 40 | #include "datamgr.h" |
41 | #include "global.h" | 41 | #include "global.h" |
42 | 42 | ||
43 | QString LOCAL_SERVER; | 43 | QString LOCAL_SERVER; |
44 | QString LOCAL_IPKGS; | 44 | QString LOCAL_IPKGS; |
45 | 45 | ||
46 | 46 | ||
47 | QString DataManager::availableCategories = ""; | 47 | QString DataManager::availableCategories = ""; |
48 | DataManager::DataManager() | 48 | DataManager::DataManager() |
49 | : QObject( 0x0, 0x0 ) | 49 | : QObject( 0x0, 0x0 ) |
50 | { | 50 | { |
51 | activeServer = ""; | 51 | activeServer = ""; |
52 | availableCategories = "#"; | 52 | availableCategories = "#"; |
53 | 53 | ||
54 | serverList.setAutoDelete( TRUE ); | 54 | serverList.setAutoDelete( TRUE ); |
55 | destList.setAutoDelete( TRUE ); | 55 | destList.setAutoDelete( TRUE ); |
56 | } | 56 | } |
57 | 57 | ||
58 | DataManager::~DataManager() | 58 | DataManager::~DataManager() |
59 | { | 59 | { |
60 | } | 60 | } |
61 | 61 | ||
62 | Server *DataManager :: getServer( const char *name ) | 62 | Server *DataManager :: getServer( const char *name ) |
63 | { | 63 | { |
64 | QListIterator<Server> it( serverList ); | 64 | QListIterator<Server> it( serverList ); |
65 | while ( it.current() && it.current()->getServerName() != name ) | 65 | while ( it.current() && it.current()->getServerName() != name ) |
66 | { | 66 | { |
67 | ++it; | 67 | ++it; |
68 | } | 68 | } |
69 | 69 | ||
70 | return it.current(); | 70 | return it.current(); |
71 | } | 71 | } |
72 | 72 | ||
73 | Destination *DataManager :: getDestination( const char *name ) | 73 | Destination *DataManager :: getDestination( const char *name ) |
74 | { | 74 | { |
75 | QListIterator<Destination> it( destList ); | 75 | QListIterator<Destination> it( destList ); |
76 | while ( it.current() && it.current()->getDestinationName() != name ) | 76 | while ( it.current() && it.current()->getDestinationName() != name ) |
77 | { | 77 | { |
78 | ++it; | 78 | ++it; |
79 | } | 79 | } |
80 | 80 | ||
81 | return it.current(); | 81 | return it.current(); |
82 | } | 82 | } |
83 | 83 | ||
84 | void DataManager :: loadServers() | 84 | void DataManager :: loadServers() |
85 | { | 85 | { |
86 | // First add our local server - not really a server but | 86 | // First add our local server - not really a server but |
87 | // the local config (which packages are installed) | 87 | // the local config (which packages are installed) |
88 | serverList.append( new Server( LOCAL_SERVER, "" ) ); | 88 | serverList.append( new Server( LOCAL_SERVER, "" ) ); |
89 | serverList.append( new Server( LOCAL_IPKGS, "" ) ); | 89 | serverList.append( new Server( LOCAL_IPKGS, "" ) ); |
90 | 90 | ||
91 | #ifdef QWS | 91 | #ifdef QWS |
92 | Config cfg( "aqpkg" ); | 92 | Config cfg( "aqpkg" ); |
93 | cfg.setGroup( "destinations" ); | 93 | cfg.setGroup( "destinations" ); |
94 | #endif | 94 | #endif |
95 | 95 | ||
96 | // Read file from /etc/ipkg.conf | 96 | // Read file from /etc/ipkg.conf |
97 | QString ipkg_conf = IPKG_CONF; | 97 | QString ipkg_conf = IPKG_CONF; |
98 | FILE *fp; | 98 | FILE *fp; |
99 | fp = fopen( ipkg_conf, "r" ); | 99 | fp = fopen( ipkg_conf, "r" ); |
100 | char line[130]; | 100 | char line[130]; |
101 | QString lineStr; | 101 | QString lineStr; |
102 | if ( fp == NULL ) | 102 | if ( fp == NULL ) |
103 | { | 103 | { |
104 | return; | 104 | return; |
105 | } | 105 | } |
106 | else | 106 | else |
107 | { | 107 | { |
108 | while ( fgets( line, sizeof line, fp) != NULL ) | 108 | while ( fgets( line, sizeof line, fp) != NULL ) |
109 | { | 109 | { |
110 | lineStr = line; | 110 | lineStr = line; |
111 | if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) ) | 111 | if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) ) |
112 | { | 112 | { |
113 | char alias[20]; | 113 | char alias[20]; |
114 | char url[100]; | 114 | char url[100]; |
115 | 115 | ||
116 | // Looks a little wierd but read up to the r of src (throwing it away), | 116 | // Looks a little wierd but read up to the r of src (throwing it away), |
117 | // then read up to the next space and throw that away, the alias | 117 | // then read up to the next space and throw that away, the alias |
118 | // is next. | 118 | // is next. |
119 | // Should Handle #src, # src, src, and combinations of | 119 | // Should Handle #src, # src, src, and combinations of |
120 | sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url ); | 120 | sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url ); |
121 | Server *s = new Server( alias, url ); | 121 | Server *s = new Server( alias, url ); |
122 | if ( lineStr.startsWith( "src" ) ) | 122 | if ( lineStr.startsWith( "src" ) ) |
123 | s->setActive( true ); | 123 | s->setActive( true ); |
124 | else | 124 | else |
125 | s->setActive( false ); | 125 | s->setActive( false ); |
126 | 126 | ||
127 | serverList.append( s ); | 127 | serverList.append( s ); |
128 | 128 | ||
129 | } | 129 | } |
130 | else if ( lineStr.startsWith( "dest" ) ) | 130 | else if ( lineStr.startsWith( "dest" ) ) |
131 | { | 131 | { |
132 | char alias[20]; | 132 | char alias[20]; |
133 | char path[50]; | 133 | char path[50]; |
134 | sscanf( lineStr, "%*[^ ] %s %s", alias, path ); | 134 | sscanf( lineStr, "%*[^ ] %s %s", alias, path ); |
135 | Destination *d = new Destination( alias, path ); | 135 | Destination *d = new Destination( alias, path ); |
136 | bool linkToRoot = true; | 136 | bool linkToRoot = true; |
137 | #ifdef QWS | 137 | #ifdef QWS |
138 | QString key = alias; | 138 | QString key = alias; |
139 | key += "_linkToRoot"; | 139 | key += "_linkToRoot"; |
140 | linkToRoot = cfg.readBoolEntry( key, true ); | 140 | linkToRoot = cfg.readBoolEntry( key, true ); |
141 | #endif | 141 | #endif |
142 | d->linkToRoot( linkToRoot ); | 142 | d->linkToRoot( linkToRoot ); |
143 | 143 | ||
144 | destList.append( d ); | 144 | destList.append( d ); |
145 | } | 145 | } |
146 | else if ( lineStr.startsWith( "option" ) || lineStr.startsWith( "#option" ) ) | 146 | else if ( lineStr.startsWith( "option" ) || lineStr.startsWith( "#option" ) ) |
147 | { | 147 | { |
148 | char type[20]; | 148 | char type[20]; |
149 | char val[100]; | 149 | char val[100]; |
150 | sscanf( lineStr, "%*[^ ] %s %s", type, val ); | 150 | sscanf( lineStr, "%*[^ ] %s %s", type, val ); |
151 | if ( stricmp( type, "http_proxy" ) == 0 ) | 151 | if ( qstricmp( type, "http_proxy" ) == 0 ) |
152 | { | 152 | { |
153 | httpProxy = val; | 153 | httpProxy = val; |
154 | if ( lineStr.startsWith( "#" ) ) | 154 | if ( lineStr.startsWith( "#" ) ) |
155 | httpProxyEnabled = false; | 155 | httpProxyEnabled = false; |
156 | else | 156 | else |
157 | httpProxyEnabled = true; | 157 | httpProxyEnabled = true; |
158 | } | 158 | } |
159 | if ( stricmp( type, "ftp_proxy" ) == 0 ) | 159 | if ( qstricmp( type, "ftp_proxy" ) == 0 ) |
160 | { | 160 | { |
161 | ftpProxy = val; | 161 | ftpProxy = val; |
162 | if ( lineStr.startsWith( "#" ) ) | 162 | if ( lineStr.startsWith( "#" ) ) |
163 | ftpProxyEnabled = false; | 163 | ftpProxyEnabled = false; |
164 | else | 164 | else |
165 | ftpProxyEnabled = true; | 165 | ftpProxyEnabled = true; |
166 | } | 166 | } |
167 | if ( stricmp( type, "proxy_username" ) == 0 ) | 167 | if ( qstricmp( type, "proxy_username" ) == 0 ) |
168 | proxyUsername = val; | 168 | proxyUsername = val; |
169 | if ( stricmp( type, "proxy_password" ) == 0 ) | 169 | if ( qstricmp( type, "proxy_password" ) == 0 ) |
170 | proxyPassword = val; | 170 | proxyPassword = val; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | } | 173 | } |
174 | fclose( fp ); | 174 | fclose( fp ); |
175 | 175 | ||
176 | reloadServerData( ); | 176 | reloadServerData( ); |
177 | } | 177 | } |
178 | 178 | ||
179 | void DataManager :: reloadServerData( ) | 179 | void DataManager :: reloadServerData( ) |
180 | { | 180 | { |
181 | emit progressSetSteps( serverList.count() ); | 181 | emit progressSetSteps( serverList.count() ); |
182 | emit progressSetMessage( tr( "Reading configuration..." ) ); | 182 | emit progressSetMessage( tr( "Reading configuration..." ) ); |
183 | 183 | ||
184 | QString serverName; | 184 | QString serverName; |
185 | int i = 0; | 185 | int i = 0; |
186 | 186 | ||
187 | Server *server; | 187 | Server *server; |
188 | QListIterator<Server> it( serverList ); | 188 | QListIterator<Server> it( serverList ); |
189 | for ( ; it.current(); ++it ) | 189 | for ( ; it.current(); ++it ) |
190 | { | 190 | { |
191 | server = it.current(); | 191 | server = it.current(); |
192 | serverName = server->getServerName(); | 192 | serverName = server->getServerName(); |
193 | i++; | 193 | i++; |
194 | emit progressUpdate( i ); | 194 | emit progressUpdate( i ); |
195 | qApp->processEvents(); | 195 | qApp->processEvents(); |
196 | 196 | ||
197 | // Now we've read the config file in we need to read the servers | 197 | // Now we've read the config file in we need to read the servers |
198 | // The local server is a special case. This holds the contents of the | 198 | // The local server is a special case. This holds the contents of the |
199 | // status files the number of which depends on how many destinations | 199 | // status files the number of which depends on how many destinations |
200 | // we've set up | 200 | // we've set up |
201 | // The other servers files hold the contents of the server package list | 201 | // The other servers files hold the contents of the server package list |
202 | if ( serverName == LOCAL_SERVER ) | 202 | if ( serverName == LOCAL_SERVER ) |
203 | server->readStatusFile( destList ); | 203 | server->readStatusFile( destList ); |
204 | else if ( serverName == LOCAL_IPKGS ) | 204 | else if ( serverName == LOCAL_IPKGS ) |
205 | server->readLocalIpks( getServer( LOCAL_SERVER ) ); | 205 | server->readLocalIpks( getServer( LOCAL_SERVER ) ); |
206 | else | 206 | else |
207 | server->readPackageFile( getServer( LOCAL_SERVER ) ); | 207 | server->readPackageFile( getServer( LOCAL_SERVER ) ); |
208 | } | 208 | } |
209 | } | 209 | } |
210 | 210 | ||
211 | void DataManager :: writeOutIpkgConf() | 211 | void DataManager :: writeOutIpkgConf() |
212 | { | 212 | { |
213 | QFile f( IPKG_CONF ); | 213 | QFile f( IPKG_CONF ); |
214 | if ( !f.open( IO_WriteOnly ) ) | 214 | if ( !f.open( IO_WriteOnly ) ) |
215 | { | 215 | { |
216 | return; | 216 | return; |
217 | } | 217 | } |
218 | 218 | ||
219 | QTextStream t( &f ); | 219 | QTextStream t( &f ); |
220 | /* | 220 | /* |
221 | QString ipkg_conf = IPKG_CONF; | 221 | QString ipkg_conf = IPKG_CONF; |
222 | ofstream out( ipkg_conf ); | 222 | ofstream out( ipkg_conf ); |
223 | */ | 223 | */ |
224 | t << "# Written by AQPkg\n"; | 224 | t << "# Written by AQPkg\n"; |
225 | t << "# Must have one or more source entries of the form:\n"; | 225 | t << "# Must have one or more source entries of the form:\n"; |
226 | t << "#\n"; | 226 | t << "#\n"; |
227 | t << "# src <src-name> <source-url>\n"; | 227 | t << "# src <src-name> <source-url>\n"; |
228 | t << "#\n"; | 228 | t << "#\n"; |
229 | t << "# and one or more destination entries of the form:\n"; | 229 | t << "# and one or more destination entries of the form:\n"; |
230 | t << "#\n"; | 230 | t << "#\n"; |
231 | t << "# dest <dest-name> <target-path>\n"; | 231 | t << "# dest <dest-name> <target-path>\n"; |
232 | t << "#\n"; | 232 | t << "#\n"; |
233 | t << "# where <src-name> and <dest-names> are identifiers that\n"; | 233 | t << "# where <src-name> and <dest-names> are identifiers that\n"; |
234 | t << "# should match [a-zA-Z0-9._-]+, <source-url> should be a\n"; | 234 | t << "# should match [a-zA-Z0-9._-]+, <source-url> should be a\n"; |
235 | t << "# URL that points to a directory containing a Familiar\n"; | 235 | t << "# URL that points to a directory containing a Familiar\n"; |
236 | t << "# Packages file, and <target-path> should be a directory\n"; | 236 | t << "# Packages file, and <target-path> should be a directory\n"; |
237 | t << "# that exists on the target system.\n\n"; | 237 | t << "# that exists on the target system.\n\n"; |
238 | 238 | ||
239 | // Write out servers | 239 | // Write out servers |
240 | Server *server; | 240 | Server *server; |
241 | QListIterator<Server> it( serverList ); | 241 | QListIterator<Server> it( serverList ); |
242 | while ( it.current() ) | 242 | while ( it.current() ) |
243 | { | 243 | { |
244 | server = it.current(); | 244 | server = it.current(); |
245 | QString alias = server->getServerName(); | 245 | QString alias = server->getServerName(); |
246 | // Don't write out local as its a dummy | 246 | // Don't write out local as its a dummy |
247 | if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS ) | 247 | if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS ) |
248 | { | 248 | { |
249 | QString url = server->getServerUrl();; | 249 | QString url = server->getServerUrl();; |
250 | 250 | ||
251 | if ( !server->isServerActive() ) | 251 | if ( !server->isServerActive() ) |
252 | t << "#"; | 252 | t << "#"; |
253 | t << "src " << alias << " " << url << endl; | 253 | t << "src " << alias << " " << url << endl; |
254 | } | 254 | } |
255 | 255 | ||
256 | ++it; | 256 | ++it; |
257 | } | 257 | } |
258 | 258 | ||
259 | t << endl; | 259 | t << endl; |
260 | 260 | ||
261 | // Write out destinations | 261 | // Write out destinations |
262 | QListIterator<Destination> it2( destList ); | 262 | QListIterator<Destination> it2( destList ); |
263 | while ( it2.current() ) | 263 | while ( it2.current() ) |
264 | { | 264 | { |
265 | t << "dest " << it2.current()->getDestinationName() << " " << it2.current()->getDestinationPath() << endl; | 265 | t << "dest " << it2.current()->getDestinationName() << " " << it2.current()->getDestinationPath() << endl; |
266 | ++it2; | 266 | ++it2; |
267 | } | 267 | } |
268 | 268 | ||
269 | t << endl; | 269 | t << endl; |
270 | t << "# Proxy Support\n"; | 270 | t << "# Proxy Support\n"; |
271 | 271 | ||
272 | if ( !httpProxyEnabled && httpProxy == "" ) | 272 | if ( !httpProxyEnabled && httpProxy == "" ) |
273 | t << "#option http_proxy http://proxy.tld:3128\n"; | 273 | t << "#option http_proxy http://proxy.tld:3128\n"; |
274 | else | 274 | else |
275 | { | 275 | { |
276 | if ( !httpProxyEnabled ) | 276 | if ( !httpProxyEnabled ) |
277 | t << "#"; | 277 | t << "#"; |
278 | t << "option http_proxy " << httpProxy << endl; | 278 | t << "option http_proxy " << httpProxy << endl; |
279 | } | 279 | } |
280 | 280 | ||
281 | if ( !ftpProxyEnabled && ftpProxy == "" ) | 281 | if ( !ftpProxyEnabled && ftpProxy == "" ) |
282 | t << "#option ftp_proxy http://proxy.tld:3128\n"; | 282 | t << "#option ftp_proxy http://proxy.tld:3128\n"; |
283 | else | 283 | else |
284 | { | 284 | { |
285 | if ( !ftpProxyEnabled ) | 285 | if ( !ftpProxyEnabled ) |
286 | t << "#"; | 286 | t << "#"; |
287 | t << "option ftp_proxy " << ftpProxy << endl; | 287 | t << "option ftp_proxy " << ftpProxy << endl; |
288 | } | 288 | } |
289 | if ( proxyUsername == "" || (!httpProxyEnabled && !ftpProxyEnabled) ) | 289 | if ( proxyUsername == "" || (!httpProxyEnabled && !ftpProxyEnabled) ) |
290 | t << "#option proxy_username <username>\n"; | 290 | t << "#option proxy_username <username>\n"; |
291 | else | 291 | else |
292 | t << "option proxy_username " << proxyUsername << endl; | 292 | t << "option proxy_username " << proxyUsername << endl; |
293 | if ( proxyPassword == "" || (!httpProxyEnabled && !ftpProxyEnabled) ) | 293 | if ( proxyPassword == "" || (!httpProxyEnabled && !ftpProxyEnabled) ) |
294 | t << "#option proxy_password <password>\n\n"; | 294 | t << "#option proxy_password <password>\n\n"; |
295 | else | 295 | else |
296 | t << "option proxy_password " << proxyPassword << endl<< endl; | 296 | t << "option proxy_password " << proxyPassword << endl<< endl; |
297 | 297 | ||
298 | t << "# Offline mode (for use in constructing flash images offline)\n"; | 298 | t << "# Offline mode (for use in constructing flash images offline)\n"; |
299 | t << "#option offline_root target\n"; | 299 | t << "#option offline_root target\n"; |
300 | 300 | ||
301 | f.close(); | 301 | f.close(); |
302 | } | 302 | } |
303 | 303 | ||
304 | 304 | ||
305 | void DataManager :: setAvailableCategories( QString section ) | 305 | void DataManager :: setAvailableCategories( QString section ) |
306 | { | 306 | { |
307 | QString sectstr = "#"; | 307 | QString sectstr = "#"; |
308 | sectstr.append( section.lower() ); | 308 | sectstr.append( section.lower() ); |
309 | sectstr.append( "#" ); | 309 | sectstr.append( "#" ); |
310 | if ( availableCategories.find( sectstr ) == -1 ) | 310 | if ( availableCategories.find( sectstr ) == -1 ) |
311 | { | 311 | { |
312 | availableCategories.append( section ); | 312 | availableCategories.append( section ); |
313 | availableCategories.append( "#" ); | 313 | availableCategories.append( "#" ); |
314 | } | 314 | } |
315 | } | 315 | } |