author | andyq <andyq> | 2002-10-17 22:49:03 (UTC) |
---|---|---|
committer | andyq <andyq> | 2002-10-17 22:49:03 (UTC) |
commit | 943c09096f11827470b9cd3e311329ac422aaf20 (patch) (unidiff) | |
tree | cec58c8ee61f85a2ebf3944594962a42489255fb | |
parent | 63a3ca758c82a397f448cce88789bf12c492b294 (diff) | |
download | opie-943c09096f11827470b9cd3e311329ac422aaf20.zip opie-943c09096f11827470b9cd3e311329ac422aaf20.tar.gz opie-943c09096f11827470b9cd3e311329ac422aaf20.tar.bz2 |
Read/Write out to config file whether a destination is set to linkToRoot
-rw-r--r-- | noncore/settings/aqpkg/datamgr.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/noncore/settings/aqpkg/datamgr.cpp b/noncore/settings/aqpkg/datamgr.cpp index d929c39..089c3e3 100644 --- a/noncore/settings/aqpkg/datamgr.cpp +++ b/noncore/settings/aqpkg/datamgr.cpp | |||
@@ -1,162 +1,179 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | datamgr.cpp - description | 2 | datamgr.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Thu Aug 29 2002 | 4 | begin : Thu Aug 29 2002 |
5 | copyright : (C) 2002 by Andy Qua | 5 | copyright : (C) 2002 by Andy Qua |
6 | email : andy.qua@blueyonder.co.uk | 6 | email : andy.qua@blueyonder.co.uk |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * | 13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * | 14 | * (at your option) any later version. * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | #include <fstream> | 17 | #include <fstream> |
18 | #include <iostream> | 18 | #include <iostream> |
19 | using namespace std; | 19 | using namespace std; |
20 | 20 | ||
21 | #ifdef QWS | ||
22 | #include <qpe/config.h> | ||
23 | #endif | ||
24 | |||
21 | #include <stdio.h> | 25 | #include <stdio.h> |
22 | 26 | ||
23 | #include "datamgr.h" | 27 | #include "datamgr.h" |
24 | #include "global.h" | 28 | #include "global.h" |
25 | 29 | ||
26 | 30 | ||
27 | DataManager::DataManager() | 31 | DataManager::DataManager() |
28 | { | 32 | { |
29 | activeServer = ""; | 33 | activeServer = ""; |
30 | } | 34 | } |
31 | 35 | ||
32 | DataManager::~DataManager() | 36 | DataManager::~DataManager() |
33 | { | 37 | { |
34 | } | 38 | } |
35 | 39 | ||
36 | Server *DataManager :: getServer( const char *name ) | 40 | Server *DataManager :: getServer( const char *name ) |
37 | { | 41 | { |
38 | Server *s = 0; | 42 | Server *s = 0; |
39 | vector<Server>::iterator it = serverList.begin(); | 43 | vector<Server>::iterator it = serverList.begin(); |
40 | while ( it != serverList.end() && s == 0 ) | 44 | while ( it != serverList.end() && s == 0 ) |
41 | { | 45 | { |
42 | if ( it->getServerName() == name ) | 46 | if ( it->getServerName() == name ) |
43 | s = &(*it); | 47 | s = &(*it); |
44 | 48 | ||
45 | ++it; | 49 | ++it; |
46 | } | 50 | } |
47 | 51 | ||
48 | return s; | 52 | return s; |
49 | } | 53 | } |
50 | 54 | ||
51 | Destination *DataManager :: getDestination( const char *name ) | 55 | Destination *DataManager :: getDestination( const char *name ) |
52 | { | 56 | { |
53 | Destination *d = 0; | 57 | Destination *d = 0; |
54 | vector<Destination>::iterator it = destList.begin(); | 58 | vector<Destination>::iterator it = destList.begin(); |
55 | while ( it != destList.end() && d == 0 ) | 59 | while ( it != destList.end() && d == 0 ) |
56 | { | 60 | { |
57 | if ( it->getDestinationName() == name ) | 61 | if ( it->getDestinationName() == name ) |
58 | d = &(*it); | 62 | d = &(*it); |
59 | 63 | ||
60 | ++it; | 64 | ++it; |
61 | } | 65 | } |
62 | 66 | ||
63 | return d; | 67 | return d; |
64 | } | 68 | } |
65 | 69 | ||
66 | void DataManager :: loadServers() | 70 | void DataManager :: loadServers() |
67 | { | 71 | { |
68 | // First add our local server - not really a server but | 72 | // First add our local server - not really a server but |
69 | // the local config (which packages are installed) | 73 | // the local config (which packages are installed) |
70 | serverList.push_back( Server( LOCAL_SERVER, "" ) ); | 74 | serverList.push_back( Server( LOCAL_SERVER, "" ) ); |
71 | serverList.push_back( Server( LOCAL_IPKGS, "" ) ); | 75 | serverList.push_back( Server( LOCAL_IPKGS, "" ) ); |
72 | 76 | ||
77 | #ifdef QWS | ||
78 | Config cfg( "aqpkg" ); | ||
79 | cfg.setGroup( "destinations" ); | ||
80 | #endif | ||
81 | |||
73 | // Read file from /etc/ipkg.conf | 82 | // Read file from /etc/ipkg.conf |
74 | QString ipkg_conf = IPKG_CONF; | 83 | QString ipkg_conf = IPKG_CONF; |
75 | FILE *fp; | 84 | FILE *fp; |
76 | fp = fopen( ipkg_conf, "r" ); | 85 | fp = fopen( ipkg_conf, "r" ); |
77 | char line[130]; | 86 | char line[130]; |
78 | QString lineStr; | 87 | QString lineStr; |
79 | if ( fp == NULL ) | 88 | if ( fp == NULL ) |
80 | { | 89 | { |
81 | cout << "Couldn't open " << ipkg_conf << "! err = " << fp << endl; | 90 | cout << "Couldn't open " << ipkg_conf << "! err = " << fp << endl; |
82 | return; | 91 | return; |
83 | } | 92 | } |
84 | else | 93 | else |
85 | { | 94 | { |
86 | while ( fgets( line, sizeof line, fp) != NULL ) | 95 | while ( fgets( line, sizeof line, fp) != NULL ) |
87 | { | 96 | { |
88 | lineStr = line; | 97 | lineStr = line; |
89 | if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) ) | 98 | if ( lineStr.startsWith( "src" ) || lineStr.startsWith( "#src" ) || lineStr.startsWith( "# src" ) ) |
90 | { | 99 | { |
91 | char alias[20]; | 100 | char alias[20]; |
92 | char url[100]; | 101 | char url[100]; |
93 | 102 | ||
94 | 103 | ||
95 | // 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), |
96 | // 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 |
97 | // is next. | 106 | // is next. |
98 | // Should Handle #src, # src, src, and combinations of | 107 | // Should Handle #src, # src, src, and combinations of |
99 | sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url ); | 108 | sscanf( lineStr, "%*[^r]%*[^ ] %s %s", alias, url ); |
100 | Server s( alias, url ); | 109 | Server s( alias, url ); |
101 | if ( lineStr.startsWith( "src" ) ) | 110 | if ( lineStr.startsWith( "src" ) ) |
102 | s.setActive( true ); | 111 | s.setActive( true ); |
103 | else | 112 | else |
104 | s.setActive( false ); | 113 | s.setActive( false ); |
105 | 114 | ||
106 | serverList.push_back( s ); | 115 | serverList.push_back( s ); |
107 | 116 | ||
108 | } | 117 | } |
109 | else if ( lineStr.startsWith( "dest" ) ) | 118 | else if ( lineStr.startsWith( "dest" ) ) |
110 | { | 119 | { |
111 | char alias[20]; | 120 | char alias[20]; |
112 | char path[50]; | 121 | char path[50]; |
113 | sscanf( lineStr, "%*[^ ] %s %s", alias, path ); | 122 | sscanf( lineStr, "%*[^ ] %s %s", alias, path ); |
114 | Destination d( alias, path ); | 123 | Destination d( alias, path ); |
124 | bool linkToRoot = true; | ||
125 | #ifdef QWS | ||
126 | QString key = alias; | ||
127 | key += "_linkToRoot"; | ||
128 | linkToRoot = cfg.readBoolEntry( key, true ); | ||
129 | #endif | ||
130 | d.linkToRoot( linkToRoot ); | ||
131 | |||
115 | destList.push_back( d ); | 132 | destList.push_back( d ); |
116 | } | 133 | } |
117 | } | 134 | } |
118 | } | 135 | } |
119 | fclose( fp ); | 136 | fclose( fp ); |
120 | 137 | ||
121 | vector<Server>::iterator it; | 138 | vector<Server>::iterator it; |
122 | for ( it = serverList.begin() ; it != serverList.end() ; ++it ) | 139 | for ( it = serverList.begin() ; it != serverList.end() ; ++it ) |
123 | reloadServerData( it->getServerName() ); | 140 | reloadServerData( it->getServerName() ); |
124 | } | 141 | } |
125 | 142 | ||
126 | void DataManager :: reloadServerData( const char *serverName ) | 143 | void DataManager :: reloadServerData( const char *serverName ) |
127 | { | 144 | { |
128 | Server *s = getServer( serverName ); | 145 | Server *s = getServer( serverName ); |
129 | // Now we've read the config file in we need to read the servers | 146 | // Now we've read the config file in we need to read the servers |
130 | // The local server is a special case. This holds the contents of the | 147 | // The local server is a special case. This holds the contents of the |
131 | // status files the number of which depends on how many destinations | 148 | // status files the number of which depends on how many destinations |
132 | // we've set up | 149 | // we've set up |
133 | // The other servers files hold the contents of the server package list | 150 | // The other servers files hold the contents of the server package list |
134 | if ( s->getServerName() == LOCAL_SERVER ) | 151 | if ( s->getServerName() == LOCAL_SERVER ) |
135 | s->readStatusFile( destList ); | 152 | s->readStatusFile( destList ); |
136 | else if ( s->getServerName() == LOCAL_IPKGS ) | 153 | else if ( s->getServerName() == LOCAL_IPKGS ) |
137 | s->readLocalIpks( getServer( LOCAL_SERVER ) ); | 154 | s->readLocalIpks( getServer( LOCAL_SERVER ) ); |
138 | else | 155 | else |
139 | s->readPackageFile( getServer( LOCAL_SERVER ) ); | 156 | s->readPackageFile( getServer( LOCAL_SERVER ) ); |
140 | 157 | ||
141 | } | 158 | } |
142 | 159 | ||
143 | void DataManager :: writeOutIpkgConf() | 160 | void DataManager :: writeOutIpkgConf() |
144 | { | 161 | { |
145 | QString ipkg_conf = IPKG_CONF; | 162 | QString ipkg_conf = IPKG_CONF; |
146 | ofstream out( ipkg_conf ); | 163 | ofstream out( ipkg_conf ); |
147 | 164 | ||
148 | out << "# Written by AQPkg" << endl; | 165 | out << "# Written by AQPkg" << endl; |
149 | out << "# Must have one or more source entries of the form:" << endl; | 166 | out << "# Must have one or more source entries of the form:" << endl; |
150 | out << "#" << endl; | 167 | out << "#" << endl; |
151 | out << "# src <src-name> <source-url>" << endl; | 168 | out << "# src <src-name> <source-url>" << endl; |
152 | out << "#" << endl; | 169 | out << "#" << endl; |
153 | out << "# and one or more destination entries of the form:" << endl; | 170 | out << "# and one or more destination entries of the form:" << endl; |
154 | out << "#" << endl; | 171 | out << "#" << endl; |
155 | out << "# dest <dest-name> <target-path>" << endl; | 172 | out << "# dest <dest-name> <target-path>" << endl; |
156 | out << "#" << endl; | 173 | out << "#" << endl; |
157 | out << "# where <src-name> and <dest-names> are identifiers that" << endl; | 174 | out << "# where <src-name> and <dest-names> are identifiers that" << endl; |
158 | out << "# should match [a-zA-Z0-9._-]+, <source-url> should be a" << endl; | 175 | out << "# should match [a-zA-Z0-9._-]+, <source-url> should be a" << endl; |
159 | out << "# URL that points to a directory containing a Familiar" << endl; | 176 | out << "# URL that points to a directory containing a Familiar" << endl; |
160 | out << "# Packages file, and <target-path> should be a directory" << endl; | 177 | out << "# Packages file, and <target-path> should be a directory" << endl; |
161 | out << "# that exists on the target system." << endl << endl; | 178 | out << "# that exists on the target system." << endl << endl; |
162 | 179 | ||