summaryrefslogtreecommitdiff
path: root/noncore/settings/aqpkg/datamgr.cpp
Unidiff
Diffstat (limited to 'noncore/settings/aqpkg/datamgr.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/datamgr.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/noncore/settings/aqpkg/datamgr.cpp b/noncore/settings/aqpkg/datamgr.cpp
index cd0c78f..67f90a3 100644
--- a/noncore/settings/aqpkg/datamgr.cpp
+++ b/noncore/settings/aqpkg/datamgr.cpp
@@ -1,74 +1,77 @@
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
43QString LOCAL_SERVER;
44QString LOCAL_IPKGS;
45
43 46
44QString DataManager::availableCategories = ""; 47QString DataManager::availableCategories = "";
45DataManager::DataManager() 48DataManager::DataManager()
46 : QObject( 0x0, 0x0 ) 49 : QObject( 0x0, 0x0 )
47{ 50{
48 activeServer = ""; 51 activeServer = "";
49 availableCategories = "#"; 52 availableCategories = "#";
50 53
51 serverList.setAutoDelete( TRUE ); 54 serverList.setAutoDelete( TRUE );
52 destList.setAutoDelete( TRUE ); 55 destList.setAutoDelete( TRUE );
53} 56}
54 57
55DataManager::~DataManager() 58DataManager::~DataManager()
56{ 59{
57} 60}
58 61
59Server *DataManager :: getServer( const char *name ) 62Server *DataManager :: getServer( const char *name )
60{ 63{
61 QListIterator<Server> it( serverList ); 64 QListIterator<Server> it( serverList );
62 while ( it.current() && it.current()->getServerName() != name ) 65 while ( it.current() && it.current()->getServerName() != name )
63 { 66 {
64 ++it; 67 ++it;
65 } 68 }
66 69
67 return it.current(); 70 return it.current();
68} 71}
69 72
70Destination *DataManager :: getDestination( const char *name ) 73Destination *DataManager :: getDestination( const char *name )
71{ 74{
72 QListIterator<Destination> it( destList ); 75 QListIterator<Destination> it( destList );
73 while ( it.current() && it.current()->getDestinationName() != name ) 76 while ( it.current() && it.current()->getDestinationName() != name )
74 { 77 {
@@ -116,124 +119,124 @@ void DataManager :: loadServers()
116 // Should Handle #src, # src, src, and combinations of 119 // Should Handle #src, # src, src, and combinations of
117 sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url ); 120 sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url );
118 Server *s = new Server( alias, url ); 121 Server *s = new Server( alias, url );
119 if ( lineStr.startsWith( "src" ) ) 122 if ( lineStr.startsWith( "src" ) )
120 s->setActive( true ); 123 s->setActive( true );
121 else 124 else
122 s->setActive( false ); 125 s->setActive( false );
123 126
124 serverList.append( s ); 127 serverList.append( s );
125 128
126 } 129 }
127 else if ( lineStr.startsWith( "dest" ) ) 130 else if ( lineStr.startsWith( "dest" ) )
128 { 131 {
129 char alias[20]; 132 char alias[20];
130 char path[50]; 133 char path[50];
131 sscanf( lineStr, "%*[^ ] %s %s", alias, path ); 134 sscanf( lineStr, "%*[^ ] %s %s", alias, path );
132 Destination *d = new Destination( alias, path ); 135 Destination *d = new Destination( alias, path );
133 bool linkToRoot = true; 136 bool linkToRoot = true;
134#ifdef QWS 137#ifdef QWS
135 QString key = alias; 138 QString key = alias;
136 key += "_linkToRoot"; 139 key += "_linkToRoot";
137 linkToRoot = cfg.readBoolEntry( key, true ); 140 linkToRoot = cfg.readBoolEntry( key, true );
138#endif 141#endif
139 d->linkToRoot( linkToRoot ); 142 d->linkToRoot( linkToRoot );
140 143
141 destList.append( d ); 144 destList.append( d );
142 } 145 }
143 else if ( lineStr.startsWith( "option" ) || lineStr.startsWith( "#option" ) ) 146 else if ( lineStr.startsWith( "option" ) || lineStr.startsWith( "#option" ) )
144 { 147 {
145 char type[20]; 148 char type[20];
146 char val[100]; 149 char val[100];
147 sscanf( lineStr, "%*[^ ] %s %s", type, val ); 150 sscanf( lineStr, "%*[^ ] %s %s", type, val );
148 if ( stricmp( type, "http_proxy" ) == 0 ) 151 if ( stricmp( type, "http_proxy" ) == 0 )
149 { 152 {
150 httpProxy = val; 153 httpProxy = val;
151 if ( lineStr.startsWith( "#" ) ) 154 if ( lineStr.startsWith( "#" ) )
152 httpProxyEnabled = false; 155 httpProxyEnabled = false;
153 else 156 else
154 httpProxyEnabled = true; 157 httpProxyEnabled = true;
155 } 158 }
156 if ( stricmp( type, "ftp_proxy" ) == 0 ) 159 if ( stricmp( type, "ftp_proxy" ) == 0 )
157 { 160 {
158 ftpProxy = val; 161 ftpProxy = val;
159 if ( lineStr.startsWith( "#" ) ) 162 if ( lineStr.startsWith( "#" ) )
160 ftpProxyEnabled = false; 163 ftpProxyEnabled = false;
161 else 164 else
162 ftpProxyEnabled = true; 165 ftpProxyEnabled = true;
163 } 166 }
164 if ( stricmp( type, "proxy_username" ) == 0 ) 167 if ( stricmp( type, "proxy_username" ) == 0 )
165 proxyUsername = val; 168 proxyUsername = val;
166 if ( stricmp( type, "proxy_password" ) == 0 ) 169 if ( stricmp( type, "proxy_password" ) == 0 )
167 proxyPassword = val; 170 proxyPassword = val;
168 } 171 }
169 } 172 }
170 } 173 }
171 fclose( fp ); 174 fclose( fp );
172 175
173 reloadServerData( ); 176 reloadServerData( );
174} 177}
175 178
176void DataManager :: reloadServerData( ) 179void DataManager :: reloadServerData( )
177{ 180{
178 emit progressSetSteps( serverList.count() ); 181 emit progressSetSteps( serverList.count() );
179 emit progressSetMessage( tr( "Reading configuration..." ) ); 182 emit progressSetMessage( tr( "Reading configuration..." ) );
180 183
181 QString serverName; 184 QString serverName;
182 int i = 0; 185 int i = 0;
183 186
184 Server *server; 187 Server *server;
185 QListIterator<Server> it( serverList ); 188 QListIterator<Server> it( serverList );
186 for ( ; it.current(); ++it ) 189 for ( ; it.current(); ++it )
187 { 190 {
188 server = it.current(); 191 server = it.current();
189 serverName = server->getServerName(); 192 serverName = server->getServerName();
190 i++; 193 i++;
191 emit progressUpdate( i ); 194 emit progressUpdate( i );
192 qApp->processEvents(); 195 qApp->processEvents();
193 196
194 // 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
195 // 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
196 // status files the number of which depends on how many destinations 199 // status files the number of which depends on how many destinations
197 // we've set up 200 // we've set up
198 // 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
199 if ( serverName == LOCAL_SERVER ) 202 if ( serverName == LOCAL_SERVER )
200 server->readStatusFile( destList ); 203 server->readStatusFile( destList );
201 else if ( serverName == LOCAL_IPKGS ) 204 else if ( serverName == LOCAL_IPKGS )
202 server->readLocalIpks( getServer( LOCAL_SERVER ) ); 205 server->readLocalIpks( getServer( LOCAL_SERVER ) );
203 else 206 else
204 server->readPackageFile( getServer( LOCAL_SERVER ) ); 207 server->readPackageFile( getServer( LOCAL_SERVER ) );
205 } 208 }
206} 209}
207 210
208void DataManager :: writeOutIpkgConf() 211void DataManager :: writeOutIpkgConf()
209{ 212{
210 QFile f( IPKG_CONF ); 213 QFile f( IPKG_CONF );
211 if ( !f.open( IO_WriteOnly ) ) 214 if ( !f.open( IO_WriteOnly ) )
212 { 215 {
213 return; 216 return;
214 } 217 }
215 218
216 QTextStream t( &f ); 219 QTextStream t( &f );
217/* 220/*
218 QString ipkg_conf = IPKG_CONF; 221 QString ipkg_conf = IPKG_CONF;
219 ofstream out( ipkg_conf ); 222 ofstream out( ipkg_conf );
220*/ 223*/
221 t << "# Written by AQPkg\n"; 224 t << "# Written by AQPkg\n";
222 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";
223 t << "#\n"; 226 t << "#\n";
224 t << "# src <src-name> <source-url>\n"; 227 t << "# src <src-name> <source-url>\n";
225 t << "#\n"; 228 t << "#\n";
226 t << "# and one or more destination entries of the form:\n"; 229 t << "# and one or more destination entries of the form:\n";
227 t << "#\n"; 230 t << "#\n";
228 t << "# dest <dest-name> <target-path>\n"; 231 t << "# dest <dest-name> <target-path>\n";
229 t << "#\n"; 232 t << "#\n";
230 t << "# where <src-name> and <dest-names> are identifiers that\n"; 233 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"; 234 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"; 235 t << "# URL that points to a directory containing a Familiar\n";
233 t << "# Packages file, and <target-path> should be a directory\n"; 236 t << "# Packages file, and <target-path> should be a directory\n";
234 t << "# that exists on the target system.\n\n"; 237 t << "# that exists on the target system.\n\n";
235 238
236 // Write out servers 239 // Write out servers
237 Server *server; 240 Server *server;
238 QListIterator<Server> it( serverList ); 241 QListIterator<Server> it( serverList );
239 while ( it.current() ) 242 while ( it.current() )
@@ -273,40 +276,40 @@ void DataManager :: writeOutIpkgConf()
273 if ( !httpProxyEnabled ) 276 if ( !httpProxyEnabled )
274 t << "#"; 277 t << "#";
275 t << "option http_proxy " << httpProxy << endl; 278 t << "option http_proxy " << httpProxy << endl;
276 } 279 }
277 280
278 if ( !ftpProxyEnabled && ftpProxy == "" ) 281 if ( !ftpProxyEnabled && ftpProxy == "" )
279 t << "#option ftp_proxy http://proxy.tld:3128\n"; 282 t << "#option ftp_proxy http://proxy.tld:3128\n";
280 else 283 else
281 { 284 {
282 if ( !ftpProxyEnabled ) 285 if ( !ftpProxyEnabled )
283 t << "#"; 286 t << "#";
284 t << "option ftp_proxy " << ftpProxy << endl; 287 t << "option ftp_proxy " << ftpProxy << endl;
285 } 288 }
286 if ( proxyUsername == "" || (!httpProxyEnabled && !ftpProxyEnabled) ) 289 if ( proxyUsername == "" || (!httpProxyEnabled && !ftpProxyEnabled) )
287 t << "#option proxy_username <username>\n"; 290 t << "#option proxy_username <username>\n";
288 else 291 else
289 t << "option proxy_username " << proxyUsername << endl; 292 t << "option proxy_username " << proxyUsername << endl;
290 if ( proxyPassword == "" || (!httpProxyEnabled && !ftpProxyEnabled) ) 293 if ( proxyPassword == "" || (!httpProxyEnabled && !ftpProxyEnabled) )
291 t << "#option proxy_password <password>\n\n"; 294 t << "#option proxy_password <password>\n\n";
292 else 295 else
293 t << "option proxy_password " << proxyPassword << endl<< endl; 296 t << "option proxy_password " << proxyPassword << endl<< endl;
294 297
295 t << "# Offline mode (for use in constructing flash images offline)\n"; 298 t << "# Offline mode (for use in constructing flash images offline)\n";
296 t << "#option offline_root target\n"; 299 t << "#option offline_root target\n";
297 300
298 f.close(); 301 f.close();
299} 302}
300 303
301 304
302void DataManager :: setAvailableCategories( QString section ) 305void DataManager :: setAvailableCategories( QString section )
303{ 306{
304 QString sectstr = "#"; 307 QString sectstr = "#";
305 sectstr.append( section.lower() ); 308 sectstr.append( section.lower() );
306 sectstr.append( "#" ); 309 sectstr.append( "#" );
307 if ( availableCategories.find( sectstr ) == -1 ) 310 if ( availableCategories.find( sectstr ) == -1 )
308 { 311 {
309 availableCategories.append( section ); 312 availableCategories.append( section );
310 availableCategories.append( "#" ); 313 availableCategories.append( "#" );
311 } 314 }
312} 315}