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.cpp29
1 files changed, 11 insertions, 18 deletions
diff --git a/noncore/settings/aqpkg/datamgr.cpp b/noncore/settings/aqpkg/datamgr.cpp
index e7fb75a..96c28c0 100644
--- a/noncore/settings/aqpkg/datamgr.cpp
+++ b/noncore/settings/aqpkg/datamgr.cpp
@@ -18,76 +18,74 @@
18#include <iostream> 18#include <iostream>
19using namespace std; 19using namespace std;
20 20
21#ifdef QWS 21#ifdef QWS
22#include <qpe/config.h> 22#include <qpe/config.h>
23#endif 23#endif
24 24
25#include <stdio.h> 25#include <stdio.h>
26 26
27#include "datamgr.h" 27#include "datamgr.h"
28#include "global.h" 28#include "global.h"
29 29
30 30
31QString DataManager::availableCategories = ""; 31QString DataManager::availableCategories = "";
32DataManager::DataManager() 32DataManager::DataManager()
33{ 33{
34 activeServer = ""; 34 activeServer = "";
35 availableCategories = "#"; 35 availableCategories = "#";
36} 36}
37 37
38DataManager::~DataManager() 38DataManager::~DataManager()
39{ 39{
40} 40}
41 41
42Server *DataManager :: getServer( const char *name ) 42vector<Server>::iterator DataManager :: getServer( const char *name )
43{ 43{
44 Server *s = 0; 44 vector<Server>::iterator it = serverList.begin();
45 vector<Server>::iterator it = serverList.begin(); 45 while ( it != serverList.end() )
46 while ( it != serverList.end() && s == 0 )
47 { 46 {
48 if ( it->getServerName() == name ) 47 if ( it->getServerName() == name )
49 s = &(*it); 48 return it;
50 49
51 ++it; 50 ++it;
52 } 51 }
53 52
54 return s; 53 return serverList.end();
55} 54}
56 55
57Destination *DataManager :: getDestination( const char *name ) 56vector<Destination>::iterator DataManager :: getDestination( const char *name )
58{ 57{
59 Destination *d = 0;
60 vector<Destination>::iterator it = destList.begin(); 58 vector<Destination>::iterator it = destList.begin();
61 while ( it != destList.end() && d == 0 ) 59 while ( it != destList.end() )
62 { 60 {
63 if ( it->getDestinationName() == name ) 61 if ( it->getDestinationName() == name )
64 d = &(*it); 62 return it;
65 63
66 ++it; 64 ++it;
67 } 65 }
68 66
69 return d; 67 return destList.end();
70} 68}
71 69
72void DataManager :: loadServers() 70void DataManager :: loadServers()
73{ 71{
74 // First add our local server - not really a server but 72 // First add our local server - not really a server but
75 // the local config (which packages are installed) 73 // the local config (which packages are installed)
76 serverList.push_back( Server( LOCAL_SERVER, "" ) ); 74 serverList.push_back( Server( LOCAL_SERVER, "" ) );
77 serverList.push_back( Server( LOCAL_IPKGS, "" ) ); 75 serverList.push_back( Server( LOCAL_IPKGS, "" ) );
78 76
79#ifdef QWS 77#ifdef QWS
80 Config cfg( "aqpkg" ); 78 Config cfg( "aqpkg" );
81 cfg.setGroup( "destinations" ); 79 cfg.setGroup( "destinations" );
82#endif 80#endif
83 81
84 // Read file from /etc/ipkg.conf 82 // Read file from /etc/ipkg.conf
85 QString ipkg_conf = IPKG_CONF; 83 QString ipkg_conf = IPKG_CONF;
86 FILE *fp; 84 FILE *fp;
87 fp = fopen( ipkg_conf, "r" ); 85 fp = fopen( ipkg_conf, "r" );
88 char line[130]; 86 char line[130];
89 QString lineStr; 87 QString lineStr;
90 if ( fp == NULL ) 88 if ( fp == NULL )
91 { 89 {
92 cout << "Couldn't open " << ipkg_conf << "! err = " << fp << endl; 90 cout << "Couldn't open " << ipkg_conf << "! err = " << fp << endl;
93 return; 91 return;
@@ -129,72 +127,67 @@ void DataManager :: loadServers()
129 linkToRoot = cfg.readBoolEntry( key, true ); 127 linkToRoot = cfg.readBoolEntry( key, true );
130#endif 128#endif
131 d.linkToRoot( linkToRoot ); 129 d.linkToRoot( linkToRoot );
132 130
133 destList.push_back( d ); 131 destList.push_back( d );
134 } 132 }
135 else if ( lineStr.startsWith( "option" ) ) 133 else if ( lineStr.startsWith( "option" ) )
136 { 134 {
137 char type[20]; 135 char type[20];
138 char val[100]; 136 char val[100];
139 sscanf( lineStr, "%*[^ ] %s %s", type, val ); 137 sscanf( lineStr, "%*[^ ] %s %s", type, val );
140 if ( stricmp( type, "http_proxy" ) == 0 ) 138 if ( stricmp( type, "http_proxy" ) == 0 )
141 httpProxy = val; 139 httpProxy = val;
142 if ( stricmp( type, "ftp_proxy" ) == 0 ) 140 if ( stricmp( type, "ftp_proxy" ) == 0 )
143 ftpProxy = val; 141 ftpProxy = val;
144 if ( stricmp( type, "proxy_username" ) == 0 ) 142 if ( stricmp( type, "proxy_username" ) == 0 )
145 proxyUsername = val; 143 proxyUsername = val;
146 if ( stricmp( type, "proxy_password" ) == 0 ) 144 if ( stricmp( type, "proxy_password" ) == 0 )
147 proxyPassword = val; 145 proxyPassword = val;
148 } 146 }
149 } 147 }
150 } 148 }
151 fclose( fp ); 149 fclose( fp );
152 150
153 cout << "httpProxy = " << httpProxy << endl;
154 cout << "ftpProxy = " << ftpProxy << endl;
155 cout << "proxyUsername = " << proxyUsername << endl;
156 cout << "proxyPassword = " << proxyPassword << endl;
157
158 reloadServerData( ); 151 reloadServerData( );
159} 152}
160 153
161void DataManager :: reloadServerData( ) 154void DataManager :: reloadServerData( )
162{ 155{
163 vector<Server>::iterator it = serverList.begin(); 156 vector<Server>::iterator it = serverList.begin();
164 for ( it = serverList.begin() ; it != serverList.end() ; ++it ) 157 for ( it = serverList.begin() ; it != serverList.end() ; ++it )
165 { 158 {
166 // Now we've read the config file in we need to read the servers 159 // Now we've read the config file in we need to read the servers
167 // The local server is a special case. This holds the contents of the 160 // The local server is a special case. This holds the contents of the
168 // status files the number of which depends on how many destinations 161 // status files the number of which depends on how many destinations
169 // we've set up 162 // we've set up
170 // The other servers files hold the contents of the server package list 163 // The other servers files hold the contents of the server package list
171 if ( it->getServerName() == LOCAL_SERVER ) 164 if ( it->getServerName() == LOCAL_SERVER )
172 it->readStatusFile( destList ); 165 it->readStatusFile( destList );
173 else if ( it->getServerName() == LOCAL_IPKGS ) 166 else if ( it->getServerName() == LOCAL_IPKGS )
174 it->readLocalIpks( getServer( LOCAL_SERVER ) ); 167 it->readLocalIpks( &( *getServer( LOCAL_SERVER ) ) );
175 else 168 else
176 it->readPackageFile( getServer( LOCAL_SERVER ) ); 169 it->readPackageFile( &( *getServer( LOCAL_SERVER ) ) );
177 } 170 }
178} 171}
179 172
180void DataManager :: writeOutIpkgConf() 173void DataManager :: writeOutIpkgConf()
181{ 174{
182 QString ipkg_conf = IPKG_CONF; 175 QString ipkg_conf = IPKG_CONF;
183 ofstream out( ipkg_conf ); 176 ofstream out( ipkg_conf );
184 177
185 out << "# Written by AQPkg" << endl; 178 out << "# Written by AQPkg" << endl;
186 out << "# Must have one or more source entries of the form:" << endl; 179 out << "# Must have one or more source entries of the form:" << endl;
187 out << "#" << endl; 180 out << "#" << endl;
188 out << "# src <src-name> <source-url>" << endl; 181 out << "# src <src-name> <source-url>" << endl;
189 out << "#" << endl; 182 out << "#" << endl;
190 out << "# and one or more destination entries of the form:" << endl; 183 out << "# and one or more destination entries of the form:" << endl;
191 out << "#" << endl; 184 out << "#" << endl;
192 out << "# dest <dest-name> <target-path>" << endl; 185 out << "# dest <dest-name> <target-path>" << endl;
193 out << "#" << endl; 186 out << "#" << endl;
194 out << "# where <src-name> and <dest-names> are identifiers that" << endl; 187 out << "# where <src-name> and <dest-names> are identifiers that" << endl;
195 out << "# should match [a-zA-Z0-9._-]+, <source-url> should be a" << endl; 188 out << "# should match [a-zA-Z0-9._-]+, <source-url> should be a" << endl;
196 out << "# URL that points to a directory containing a Familiar" << endl; 189 out << "# URL that points to a directory containing a Familiar" << endl;
197 out << "# Packages file, and <target-path> should be a directory" << endl; 190 out << "# Packages file, and <target-path> should be a directory" << endl;
198 out << "# that exists on the target system." << endl << endl; 191 out << "# that exists on the target system." << endl << endl;
199 192
200 // Write out servers 193 // Write out servers