00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifdef QWS
00031 #include <qpe/config.h>
00032 #include <qpe/qpeapplication.h>
00033 #else
00034 #include <qapplication.h>
00035 #endif
00036
00037 #include <qfile.h>
00038 #include <qtextstream.h>
00039
00040 #include "datamgr.h"
00041 #include "global.h"
00042
00043 QString LOCAL_SERVER;
00044 QString LOCAL_IPKGS;
00045
00046
00047 QString DataManager::availableCategories = "";
00048 DataManager::DataManager()
00049 : QObject( 0x0, 0x0 )
00050 {
00051 activeServer = "";
00052 availableCategories = "#";
00053
00054 serverList.setAutoDelete( TRUE );
00055 destList.setAutoDelete( TRUE );
00056 }
00057
00058 DataManager::~DataManager()
00059 {
00060 }
00061
00062 Server *DataManager :: getServer( const char *name )
00063 {
00064 QListIterator<Server> it( serverList );
00065 while ( it.current() && it.current()->getServerName() != name )
00066 {
00067 ++it;
00068 }
00069
00070 return it.current();
00071 }
00072
00073 Destination *DataManager :: getDestination( const char *name )
00074 {
00075 QListIterator<Destination> it( destList );
00076 while ( it.current() && it.current()->getDestinationName() != name )
00077 {
00078 ++it;
00079 }
00080
00081 return it.current();
00082 }
00083
00084 void DataManager :: loadServers()
00085 {
00086
00087
00088 serverList.append( new Server( LOCAL_SERVER, "" ) );
00089 serverList.append( new Server( LOCAL_IPKGS, "" ) );
00090
00091 #ifdef QWS
00092 Config cfg( "aqpkg" );
00093 cfg.setGroup( "destinations" );
00094 #endif
00095
00096
00097 QString ipkg_conf = IPKG_CONF;
00098 FILE *fp;
00099 fp = fopen( ipkg_conf, "r" );
00100 char line[130];
00101 QString lineStr;
00102 if ( fp == NULL )
00103 {
00104 return;
00105 }
00106 else
00107 {
00108 while ( fgets( line, sizeof line, fp) != NULL )
00109 {
00110 lineStr = line;
00111 if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) )
00112 {
00113 char alias[20];
00114 char url[100];
00115
00116
00117
00118
00119
00120 sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url );
00121 Server *s = new Server( alias, url );
00122 if ( lineStr.startsWith( "src" ) )
00123 s->setActive( true );
00124 else
00125 s->setActive( false );
00126
00127 serverList.append( s );
00128
00129 }
00130 else if ( lineStr.startsWith( "dest" ) )
00131 {
00132 char alias[20];
00133 char path[50];
00134 sscanf( lineStr, "%*[^ ] %s %s", alias, path );
00135 Destination *d = new Destination( alias, path );
00136 bool linkToRoot = true;
00137 #ifdef QWS
00138 QString key = alias;
00139 key += "_linkToRoot";
00140 linkToRoot = cfg.readBoolEntry( key, true );
00141 #endif
00142 d->linkToRoot( linkToRoot );
00143
00144 destList.append( d );
00145 }
00146 else if ( lineStr.startsWith( "option" ) || lineStr.startsWith( "#option" ) )
00147 {
00148 char type[20];
00149 char val[100];
00150 sscanf( lineStr, "%*[^ ] %s %s", type, val );
00151 if ( qstricmp( type, "http_proxy" ) == 0 )
00152 {
00153 httpProxy = val;
00154 if ( lineStr.startsWith( "#" ) )
00155 httpProxyEnabled = false;
00156 else
00157 httpProxyEnabled = true;
00158 }
00159 if ( qstricmp( type, "ftp_proxy" ) == 0 )
00160 {
00161 ftpProxy = val;
00162 if ( lineStr.startsWith( "#" ) )
00163 ftpProxyEnabled = false;
00164 else
00165 ftpProxyEnabled = true;
00166 }
00167 if ( qstricmp( type, "proxy_username" ) == 0 )
00168 proxyUsername = val;
00169 if ( qstricmp( type, "proxy_password" ) == 0 )
00170 proxyPassword = val;
00171 }
00172 }
00173 }
00174 fclose( fp );
00175
00176 reloadServerData( );
00177 }
00178
00179 void DataManager :: reloadServerData( )
00180 {
00181 emit progressSetSteps( serverList.count() );
00182 emit progressSetMessage( tr( "Reading configuration..." ) );
00183
00184 QString serverName;
00185 int i = 0;
00186
00187 Server *server;
00188 QListIterator<Server> it( serverList );
00189 for ( ; it.current(); ++it )
00190 {
00191 server = it.current();
00192 serverName = server->getServerName();
00193 i++;
00194 emit progressUpdate( i );
00195 qApp->processEvents();
00196
00197
00198
00199
00200
00201
00202 if ( serverName == LOCAL_SERVER )
00203 server->readStatusFile( destList );
00204 else if ( serverName == LOCAL_IPKGS )
00205 server->readLocalIpks( getServer( LOCAL_SERVER ) );
00206 else
00207 server->readPackageFile( getServer( LOCAL_SERVER ) );
00208 }
00209 }
00210
00211 void DataManager :: writeOutIpkgConf()
00212 {
00213 QFile f( IPKG_CONF );
00214 if ( !f.open( IO_WriteOnly ) )
00215 {
00216 return;
00217 }
00218
00219 QTextStream t( &f );
00220
00221
00222
00223
00224 t << "# Written by AQPkg\n";
00225 t << "# Must have one or more source entries of the form:\n";
00226 t << "#\n";
00227 t << "# src <src-name> <source-url>\n";
00228 t << "#\n";
00229 t << "# and one or more destination entries of the form:\n";
00230 t << "#\n";
00231 t << "# dest <dest-name> <target-path>\n";
00232 t << "#\n";
00233 t << "# where <src-name> and <dest-names> are identifiers that\n";
00234 t << "# should match [a-zA-Z0-9._-]+, <source-url> should be a\n";
00235 t << "# URL that points to a directory containing a Familiar\n";
00236 t << "# Packages file, and <target-path> should be a directory\n";
00237 t << "# that exists on the target system.\n\n";
00238
00239
00240 Server *server;
00241 QListIterator<Server> it( serverList );
00242 while ( it.current() )
00243 {
00244 server = it.current();
00245 QString alias = server->getServerName();
00246
00247 if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS )
00248 {
00249 QString url = server->getServerUrl();;
00250
00251 if ( !server->isServerActive() )
00252 t << "#";
00253 t << "src " << alias << " " << url << endl;
00254 }
00255
00256 ++it;
00257 }
00258
00259 t << endl;
00260
00261
00262 QListIterator<Destination> it2( destList );
00263 while ( it2.current() )
00264 {
00265 t << "dest " << it2.current()->getDestinationName() << " " << it2.current()->getDestinationPath() << endl;
00266 ++it2;
00267 }
00268
00269 t << endl;
00270 t << "# Proxy Support\n";
00271
00272 if ( !httpProxyEnabled && httpProxy == "" )
00273 t << "#option http_proxy http://proxy.tld:3128\n";
00274 else
00275 {
00276 if ( !httpProxyEnabled )
00277 t << "#";
00278 t << "option http_proxy " << httpProxy << endl;
00279 }
00280
00281 if ( !ftpProxyEnabled && ftpProxy == "" )
00282 t << "#option ftp_proxy http://proxy.tld:3128\n";
00283 else
00284 {
00285 if ( !ftpProxyEnabled )
00286 t << "#";
00287 t << "option ftp_proxy " << ftpProxy << endl;
00288 }
00289 if ( proxyUsername == "" || (!httpProxyEnabled && !ftpProxyEnabled) )
00290 t << "#option proxy_username <username>\n";
00291 else
00292 t << "option proxy_username " << proxyUsername << endl;
00293 if ( proxyPassword == "" || (!httpProxyEnabled && !ftpProxyEnabled) )
00294 t << "#option proxy_password <password>\n\n";
00295 else
00296 t << "option proxy_password " << proxyPassword << endl<< endl;
00297
00298 t << "# Offline mode (for use in constructing flash images offline)\n";
00299 t << "#option offline_root target\n";
00300
00301 f.close();
00302 }
00303
00304
00305 void DataManager :: setAvailableCategories( QString section )
00306 {
00307 QString sectstr = "#";
00308 sectstr.append( section.lower() );
00309 sectstr.append( "#" );
00310 if ( availableCategories.find( sectstr ) == -1 )
00311 {
00312 availableCategories.append( section );
00313 availableCategories.append( "#" );
00314 }
00315 }