summaryrefslogtreecommitdiff
path: root/noncore/settings/aqpkg/datamgr.cpp
Unidiff
Diffstat (limited to 'noncore/settings/aqpkg/datamgr.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/aqpkg/datamgr.cpp82
1 files changed, 42 insertions, 40 deletions
diff --git a/noncore/settings/aqpkg/datamgr.cpp b/noncore/settings/aqpkg/datamgr.cpp
index 2c83e28..79f36e1 100644
--- a/noncore/settings/aqpkg/datamgr.cpp
+++ b/noncore/settings/aqpkg/datamgr.cpp
@@ -28,64 +28,61 @@ using namespace std;
28#include <stdio.h> 28#include <stdio.h>
29 29
30#include "datamgr.h" 30#include "datamgr.h"
31#include "global.h" 31#include "global.h"
32 32
33 33
34QString DataManager::availableCategories = ""; 34QString DataManager::availableCategories = "";
35DataManager::DataManager() 35DataManager::DataManager()
36 : QObject( 0x0, 0x0 ) 36 : QObject( 0x0, 0x0 )
37{ 37{
38 activeServer = ""; 38 activeServer = "";
39 availableCategories = "#"; 39 availableCategories = "#";
40
41 serverList.setAutoDelete( TRUE );
42 destList.setAutoDelete( TRUE );
40} 43}
41 44
42DataManager::~DataManager() 45DataManager::~DataManager()
43{ 46{
44} 47}
45 48
46vector<Server>::iterator DataManager :: getServer( const char *name ) 49Server *DataManager :: getServer( const char *name )
47{ 50{
48 vector<Server>::iterator it = serverList.begin(); 51 QListIterator<Server> it( serverList );
49 while ( it != serverList.end() ) 52 while ( it.current() && it.current()->getServerName() != name )
50 { 53 {
51 if ( it->getServerName() == name )
52 return it;
53
54 ++it; 54 ++it;
55 } 55 }
56 56
57 return serverList.end(); 57 return it.current();
58} 58}
59 59
60vector<Destination>::iterator DataManager :: getDestination( const char *name ) 60Destination *DataManager :: getDestination( const char *name )
61{ 61{
62 vector<Destination>::iterator it = destList.begin(); 62 QListIterator<Destination> it( destList );
63 while ( it != destList.end() ) 63 while ( it.current() && it.current()->getDestinationName() != name )
64 { 64 {
65 if ( it->getDestinationName() == name )
66 return it;
67
68 ++it; 65 ++it;
69 } 66 }
70 67
71 return destList.end(); 68 return it.current();
72} 69}
73 70
74void DataManager :: loadServers() 71void DataManager :: loadServers()
75{ 72{
76 // First add our local server - not really a server but 73 // First add our local server - not really a server but
77 // the local config (which packages are installed) 74 // the local config (which packages are installed)
78 serverList.push_back( Server( LOCAL_SERVER, "" ) ); 75 serverList.append( new Server( LOCAL_SERVER, "" ) );
79 serverList.push_back( Server( LOCAL_IPKGS, "" ) ); 76 serverList.append( new Server( LOCAL_IPKGS, "" ) );
80 77
81#ifdef QWS 78#ifdef QWS
82 Config cfg( "aqpkg" ); 79 Config cfg( "aqpkg" );
83 cfg.setGroup( "destinations" ); 80 cfg.setGroup( "destinations" );
84#endif 81#endif
85 82
86 // Read file from /etc/ipkg.conf 83 // Read file from /etc/ipkg.conf
87 QString ipkg_conf = IPKG_CONF; 84 QString ipkg_conf = IPKG_CONF;
88 FILE *fp; 85 FILE *fp;
89 fp = fopen( ipkg_conf, "r" ); 86 fp = fopen( ipkg_conf, "r" );
90 char line[130]; 87 char line[130];
91 QString lineStr; 88 QString lineStr;
@@ -100,48 +97,48 @@ void DataManager :: loadServers()
100 { 97 {
101 lineStr = line; 98 lineStr = line;
102 if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) ) 99 if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) )
103 { 100 {
104 char alias[20]; 101 char alias[20];
105 char url[100]; 102 char url[100];
106 103
107 // Looks a little wierd but read up to the r of src (throwing it away), 104 // Looks a little wierd but read up to the r of src (throwing it away),
108 // then read up to the next space and throw that away, the alias 105 // then read up to the next space and throw that away, the alias
109 // is next. 106 // is next.
110 // Should Handle #src, # src, src, and combinations of 107 // Should Handle #src, # src, src, and combinations of
111 sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url ); 108 sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url );
112 Server s( alias, url ); 109 Server *s = new Server( alias, url );
113 if ( lineStr.startsWith( "src" ) ) 110 if ( lineStr.startsWith( "src" ) )
114 s.setActive( true ); 111 s->setActive( true );
115 else 112 else
116 s.setActive( false ); 113 s->setActive( false );
117 114
118 serverList.push_back( s ); 115 serverList.append( s );
119 116
120 } 117 }
121 else if ( lineStr.startsWith( "dest" ) ) 118 else if ( lineStr.startsWith( "dest" ) )
122 { 119 {
123 char alias[20]; 120 char alias[20];
124 char path[50]; 121 char path[50];
125 sscanf( lineStr, "%*[^ ] %s %s", alias, path ); 122 sscanf( lineStr, "%*[^ ] %s %s", alias, path );
126 Destination d( alias, path ); 123 Destination *d = new Destination( alias, path );
127 bool linkToRoot = true; 124 bool linkToRoot = true;
128#ifdef QWS 125#ifdef QWS
129 QString key = alias; 126 QString key = alias;
130 key += "_linkToRoot"; 127 key += "_linkToRoot";
131 linkToRoot = cfg.readBoolEntry( key, true ); 128 linkToRoot = cfg.readBoolEntry( key, true );
132#endif 129#endif
133 d.linkToRoot( linkToRoot ); 130 d->linkToRoot( linkToRoot );
134 131
135 destList.push_back( d ); 132 destList.append( d );
136 } 133 }
137 else if ( lineStr.startsWith( "option" ) || lineStr.startsWith( "#option" ) ) 134 else if ( lineStr.startsWith( "option" ) || lineStr.startsWith( "#option" ) )
138 { 135 {
139 char type[20]; 136 char type[20];
140 char val[100]; 137 char val[100];
141 sscanf( lineStr, "%*[^ ] %s %s", type, val ); 138 sscanf( lineStr, "%*[^ ] %s %s", type, val );
142 if ( stricmp( type, "http_proxy" ) == 0 ) 139 if ( stricmp( type, "http_proxy" ) == 0 )
143 { 140 {
144 httpProxy = val; 141 httpProxy = val;
145 if ( lineStr.startsWith( "#" ) ) 142 if ( lineStr.startsWith( "#" ) )
146 httpProxyEnabled = false; 143 httpProxyEnabled = false;
147 else 144 else
@@ -160,97 +157,102 @@ void DataManager :: loadServers()
160 if ( stricmp( type, "proxy_password" ) == 0 ) 157 if ( stricmp( type, "proxy_password" ) == 0 )
161 proxyPassword = val; 158 proxyPassword = val;
162 } 159 }
163 } 160 }
164 } 161 }
165 fclose( fp ); 162 fclose( fp );
166 163
167 reloadServerData( ); 164 reloadServerData( );
168} 165}
169 166
170void DataManager :: reloadServerData( ) 167void DataManager :: reloadServerData( )
171{ 168{
172 emit progressSetSteps( serverList.size() ); 169 emit progressSetSteps( serverList.count() );
173 emit progressSetMessage( tr( "Reading configuration..." ) ); 170 emit progressSetMessage( tr( "Reading configuration..." ) );
174 171
175 vector<Server>::iterator it = serverList.begin();
176 QString serverName; 172 QString serverName;
177 int i = 0; 173 int i = 0;
178 for ( it = serverList.begin() ; it != serverList.end() ; ++it ) 174
175 Server *server;
176 QListIterator<Server> it( serverList );
177 for ( ; it.current(); ++it )
179 { 178 {
180 serverName = it->getServerName(); 179 server = it.current();
180 serverName = server->getServerName();
181 i++; 181 i++;
182 emit progressUpdate( i ); 182 emit progressUpdate( i );
183 qApp->processEvents(); 183 qApp->processEvents();
184 184
185 // Now we've read the config file in we need to read the servers 185 // Now we've read the config file in we need to read the servers
186 // The local server is a special case. This holds the contents of the 186 // The local server is a special case. This holds the contents of the
187 // status files the number of which depends on how many destinations 187 // status files the number of which depends on how many destinations
188 // we've set up 188 // we've set up
189 // The other servers files hold the contents of the server package list 189 // The other servers files hold the contents of the server package list
190 if ( serverName == LOCAL_SERVER ) 190 if ( serverName == LOCAL_SERVER )
191 it->readStatusFile( destList ); 191 server->readStatusFile( destList );
192 else if ( serverName == LOCAL_IPKGS ) 192 else if ( serverName == LOCAL_IPKGS )
193 it->readLocalIpks( &( *getServer( LOCAL_SERVER ) ) ); 193 server->readLocalIpks( getServer( LOCAL_SERVER ) );
194 else 194 else
195 it->readPackageFile( &( *getServer( LOCAL_SERVER ) ) ); 195 server->readPackageFile( getServer( LOCAL_SERVER ) );
196 } 196 }
197} 197}
198 198
199void DataManager :: writeOutIpkgConf() 199void DataManager :: writeOutIpkgConf()
200{ 200{
201 QString ipkg_conf = IPKG_CONF; 201 QString ipkg_conf = IPKG_CONF;
202 ofstream out( ipkg_conf ); 202 ofstream out( ipkg_conf );
203 203
204 out << "# Written by AQPkg" << endl; 204 out << "# Written by AQPkg" << endl;
205 out << "# Must have one or more source entries of the form:" << endl; 205 out << "# Must have one or more source entries of the form:" << endl;
206 out << "#" << endl; 206 out << "#" << endl;
207 out << "# src <src-name> <source-url>" << endl; 207 out << "# src <src-name> <source-url>" << endl;
208 out << "#" << endl; 208 out << "#" << endl;
209 out << "# and one or more destination entries of the form:" << endl; 209 out << "# and one or more destination entries of the form:" << endl;
210 out << "#" << endl; 210 out << "#" << endl;
211 out << "# dest <dest-name> <target-path>" << endl; 211 out << "# dest <dest-name> <target-path>" << endl;
212 out << "#" << endl; 212 out << "#" << endl;
213 out << "# where <src-name> and <dest-names> are identifiers that" << 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; 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; 215 out << "# URL that points to a directory containing a Familiar" << endl;
216 out << "# Packages file, and <target-path> should be a directory" << endl; 216 out << "# Packages file, and <target-path> should be a directory" << endl;
217 out << "# that exists on the target system." << endl << endl; 217 out << "# that exists on the target system." << endl << endl;
218 218
219 // Write out servers 219 // Write out servers
220 vector<Server>::iterator it = serverList.begin(); 220 Server *server;
221 while ( it != serverList.end() ) 221 QListIterator<Server> it( serverList );
222 while ( it.current() )
222 { 223 {
223 QString alias = it->getServerName(); 224 server = it.current();
225 QString alias = server->getServerName();
224 // Don't write out local as its a dummy 226 // Don't write out local as its a dummy
225 if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS ) 227 if ( alias != LOCAL_SERVER && alias != LOCAL_IPKGS )
226 { 228 {
227 QString url = it->getServerUrl();; 229 QString url = server->getServerUrl();;
228 230
229 if ( !it->isServerActive() ) 231 if ( !server->isServerActive() )
230 out << "#"; 232 out << "#";
231 out << "src " << alias << " " << url << endl; 233 out << "src " << alias << " " << url << endl;
232 } 234 }
233 235
234 it++; 236 ++it;
235 } 237 }
236 238
237 out << endl; 239 out << endl;
238 240
239 // Write out destinations 241 // Write out destinations
240 vector<Destination>::iterator it2 = destList.begin(); 242 QListIterator<Destination> it2( destList );
241 while ( it2 != destList.end() ) 243 while ( it2.current() )
242 { 244 {
243 out << "dest " << it2->getDestinationName() << " " << it2->getDestinationPath() << endl; 245 out << "dest " << it2.current()->getDestinationName() << " " << it2.current()->getDestinationPath() << endl;
244 it2++; 246 ++it2;
245 } 247 }
246 248
247 out << endl; 249 out << endl;
248 out << "# Proxy Support" << endl; 250 out << "# Proxy Support" << endl;
249 251
250 if ( !httpProxyEnabled && httpProxy == "" ) 252 if ( !httpProxyEnabled && httpProxy == "" )
251 out << "#option http_proxy http://proxy.tld:3128" << endl; 253 out << "#option http_proxy http://proxy.tld:3128" << endl;
252 else 254 else
253 { 255 {
254 if ( !httpProxyEnabled ) 256 if ( !httpProxyEnabled )
255 out << "#"; 257 out << "#";
256 out << "option http_proxy " << httpProxy << endl; 258 out << "option http_proxy " << httpProxy << endl;