author | tille <tille> | 2002-11-24 16:28:25 (UTC) |
---|---|---|
committer | tille <tille> | 2002-11-24 16:28:25 (UTC) |
commit | 5b029ef4b109d50ae41a3fd8bfae0b30864745f8 (patch) (unidiff) | |
tree | f5a3d81a404a57dd21c5205e70dca985bb948416 | |
parent | 9387bc3f63b1e48c559d0758c50d9af857e7feeb (diff) | |
download | opie-5b029ef4b109d50ae41a3fd8bfae0b30864745f8.zip opie-5b029ef4b109d50ae41a3fd8bfae0b30864745f8.tar.gz opie-5b029ef4b109d50ae41a3fd8bfae0b30864745f8.tar.bz2 |
valgrind found bugs
thanks to simon
-rw-r--r-- | noncore/unsupported/oipkg/package.cpp | 30 | ||||
-rw-r--r-- | noncore/unsupported/oipkg/package.h | 5 | ||||
-rw-r--r-- | noncore/unsupported/oipkg/packagelist.cpp | 1 | ||||
-rw-r--r-- | noncore/unsupported/oipkg/packagelistitem.cpp | 5 |
4 files changed, 27 insertions, 14 deletions
diff --git a/noncore/unsupported/oipkg/package.cpp b/noncore/unsupported/oipkg/package.cpp index e020601..190b3fb 100644 --- a/noncore/unsupported/oipkg/package.cpp +++ b/noncore/unsupported/oipkg/package.cpp | |||
@@ -1,337 +1,347 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> | 9 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> |
10 | #include "package.h" | 10 | #include "package.h" |
11 | 11 | ||
12 | #include <qpe/process.h> | 12 | #include <qpe/process.h> |
13 | #include <qpe/stringutil.h> | 13 | #include <qpe/stringutil.h> |
14 | #include <qfile.h> | 14 | #include <qfile.h> |
15 | #include <qtextstream.h> | 15 | #include <qtextstream.h> |
16 | #include <stdlib.h> | 16 | #include <stdlib.h> |
17 | #include <unistd.h> | 17 | #include <unistd.h> |
18 | 18 | ||
19 | #include "debug.h" | 19 | #include "debug.h" |
20 | 20 | ||
21 | OipkgPackage::OipkgPackage( QObject *parent, const char *name ) | 21 | OipkgPackage::OipkgPackage( QObject *parent, const char *name ) |
22 | : QObject(parent,name) | 22 | : QObject(parent,name) |
23 | { | 23 | { |
24 | 24 | init(); | |
25 | } | 25 | } |
26 | 26 | ||
27 | OipkgPackage::~OipkgPackage() | 27 | OipkgPackage::~OipkgPackage() |
28 | { | 28 | { |
29 | |||
29 | } | 30 | } |
30 | 31 | ||
31 | OipkgPackage::OipkgPackage( PackageManagerSettings *s, QObject *parent, const char *name ) | 32 | OipkgPackage::OipkgPackage( PackageManagerSettings *s, QObject *parent, const char *name ) |
32 | : QObject(parent,name) | 33 | : QObject(parent,name) |
33 | { | 34 | { |
34 | init(s); | 35 | settings = s; |
36 | init(); | ||
35 | } | 37 | } |
36 | 38 | ||
37 | void OipkgPackage::init( PackageManagerSettings *s ) | 39 | // void OipkgPackage::init( PackageManagerSettings *s ) |
40 | // { | ||
41 | // settings = s; | ||
42 | // init(); | ||
43 | // } | ||
44 | |||
45 | void OipkgPackage::init( ) | ||
38 | { | 46 | { |
39 | settings = s; | ||
40 | _size = ""; | 47 | _size = ""; |
41 | _section = ""; | 48 | _section = ""; |
42 | _subsection = ""; | 49 | _subsection = ""; |
43 | _shortDesc = ""; | 50 | _shortDesc = ""; |
44 | _desc = ""; | 51 | _desc = ""; |
45 | _name = ""; | 52 | _name = ""; |
46 | _toProcess = false; | 53 | _toProcess = false; |
47 | _useFileName = false; | 54 | _useFileName = false; |
48 | _old = false; | 55 | _old = false; |
49 | _status = ""; | 56 | _status = ""; |
50 | _dest = settings->getDestinationName(); | 57 | _dest = settings->getDestinationName(); |
51 | _link = settings->createLinks(); | 58 | _link = settings->createLinks(); |
52 | _versions=0; | 59 | _versions=0; |
53 | _version=""; | 60 | _version=""; |
54 | } | 61 | } |
55 | 62 | ||
56 | OipkgPackage::OipkgPackage( QStringList pack, PackageManagerSettings *s , QObject *parent, const char *name ) | 63 | OipkgPackage::OipkgPackage( QStringList pack, PackageManagerSettings *s , QObject *parent, const char *name ) |
57 | : QObject(parent,name) | 64 | : QObject(parent,name) |
58 | { | 65 | { |
59 | init(s); | 66 | settings = s; |
67 | init(); | ||
60 | parsePackage( pack ); | 68 | parsePackage( pack ); |
61 | } | 69 | } |
62 | 70 | ||
63 | OipkgPackage::OipkgPackage( QString n, PackageManagerSettings *s, QObject *parent, const char *name ) | 71 | OipkgPackage::OipkgPackage( QString n, PackageManagerSettings *s, QObject *parent, const char *name ) |
64 | : QObject(parent,name) | 72 | : QObject(parent,name) |
65 | { | 73 | { |
66 | init(s); | 74 | settings = s; |
75 | init(); | ||
67 | if ( !QFile::exists( n ) ) | 76 | if ( !QFile::exists( n ) ) |
68 | { | 77 | { |
69 | _name = QString( n ); | 78 | _name = QString( n ); |
70 | }else{ | 79 | }else{ |
71 | pvDebug(4,"remote file: "+n); | 80 | pvDebug(4,"remote file: "+n); |
72 | parseIpkgFile( n ); | 81 | parseIpkgFile( n ); |
73 | _useFileName = true; | 82 | _useFileName = true; |
74 | _fileName = QString( n ); | 83 | _fileName = QString( n ); |
75 | } | 84 | } |
76 | } | 85 | } |
77 | 86 | ||
78 | OipkgPackage::OipkgPackage( OipkgPackage *pi, QObject *parent, const char *name ) | 87 | OipkgPackage::OipkgPackage( OipkgPackage *pi, QObject *parent, const char *name ) |
79 | : QObject(parent,name) | 88 | : QObject(parent,name) |
80 | { | 89 | { |
81 | init(pi->settings); | 90 | settings = pi->settings; |
91 | init(); | ||
82 | copyValues( pi ); | 92 | copyValues( pi ); |
83 | } | 93 | } |
84 | 94 | ||
85 | 95 | ||
86 | void OipkgPackage::setValue( QString n, QString t ) | 96 | void OipkgPackage::setValue( QString n, QString t ) |
87 | { | 97 | { |
88 | if ( n == "Package" ) | 98 | if ( n == "Package" ) |
89 | { | 99 | { |
90 | _name = QString( t ); | 100 | _name = QString( t ); |
91 | }else if ( n == "Installed-Size" ) | 101 | }else if ( n == "Installed-Size" ) |
92 | { | 102 | { |
93 | _size = t; | 103 | _size = t; |
94 | // }else if ( n == "Priority") | 104 | // }else if ( n == "Priority") |
95 | // { | 105 | // { |
96 | 106 | ||
97 | }else if ( n == "Section") | 107 | }else if ( n == "Section") |
98 | { | 108 | { |
99 | setSection( t ); | 109 | setSection( t ); |
100 | // }else if ( n == "Maintainer") | 110 | // }else if ( n == "Maintainer") |
101 | // { | 111 | // { |
102 | // | 112 | // |
103 | // }else if ( n == "Architecture") | 113 | // }else if ( n == "Architecture") |
104 | // { | 114 | // { |
105 | 115 | ||
106 | }else if ( n == "Version") | 116 | }else if ( n == "Version") |
107 | { | 117 | { |
108 | _version = t; | 118 | _version = t; |
109 | // }else if ( n == "Pre-Depends") | 119 | // }else if ( n == "Pre-Depends") |
110 | // { | 120 | // { |
111 | // | 121 | // |
112 | // }else if ( n == "Depends") | 122 | // }else if ( n == "Depends") |
113 | // { | 123 | // { |
114 | 124 | ||
115 | }else if ( n == "Filename") | 125 | }else if ( n == "Filename") |
116 | { | 126 | { |
117 | _fileName = t; | 127 | _fileName = t; |
118 | // }else if ( n == "Size") | 128 | // }else if ( n == "Size") |
119 | // { | 129 | // { |
120 | // | 130 | // |
121 | //}else if ( n == "MD5Sum") | 131 | //}else if ( n == "MD5Sum") |
122 | //{ | 132 | //{ |
123 | 133 | ||
124 | }else if ( n == "Description") | 134 | }else if ( n == "Description") |
125 | { | 135 | { |
126 | setDesc( t ); | 136 | setDesc( t ); |
127 | }else if ( n == "Status") | 137 | }else if ( n == "Status") |
128 | { | 138 | { |
129 | if ( installed() ) return; | 139 | if ( installed() ) return; |
130 | _status = t; | 140 | _status = t; |
131 | // }else if ( n == "Essential") | 141 | // }else if ( n == "Essential") |
132 | // { | 142 | // { |
133 | 143 | ||
134 | }else{ | 144 | }else{ |
135 | _values.insert(n,new QString(t)); | 145 | _values.insert(n,new QString(t)); |
136 | } | 146 | } |
137 | } | 147 | } |
138 | 148 | ||
139 | QString OipkgPackage::name() | 149 | QString OipkgPackage::name() |
140 | { | 150 | { |
141 | if (_displayName.isEmpty() ) return _name; | 151 | if (_displayName.isEmpty() ) return _name; |
142 | else return _displayName; | 152 | else return _displayName; |
143 | } | 153 | } |
144 | 154 | ||
145 | 155 | ||
146 | QString OipkgPackage::installName() | 156 | QString OipkgPackage::installName() |
147 | { | 157 | { |
148 | if (_useFileName) return _fileName; | 158 | if (_useFileName) return _fileName; |
149 | else return _name; | 159 | else return _name; |
150 | } | 160 | } |
151 | 161 | ||
152 | QString OipkgPackage::packageName() | 162 | QString OipkgPackage::packageName() |
153 | { | 163 | { |
154 | QString pn = installName(); | 164 | QString pn = installName(); |
155 | pn = pn.right(pn.length()-pn.findRev("/")); | 165 | pn = pn.right(pn.length()-pn.findRev("/")); |
156 | pn = pn.left(pn.find("_")); | 166 | pn = pn.left(pn.find("_")); |
157 | return pn; | 167 | return pn; |
158 | } | 168 | } |
159 | 169 | ||
160 | bool OipkgPackage::installed() | 170 | bool OipkgPackage::installed() |
161 | { | 171 | { |
162 | if (_status.contains("installed")) | 172 | if (_status.contains("installed")) |
163 | { | 173 | { |
164 | if (_status.contains("not-installed")) | 174 | if (_status.contains("not-installed")) |
165 | { | 175 | { |
166 | _toProcess = true; | 176 | _toProcess = true; |
167 | return false; | 177 | return false; |
168 | } | 178 | } |
169 | else return true; | 179 | else return true; |
170 | } | 180 | } |
171 | else | 181 | else |
172 | if (_versions) | 182 | if (_versions) |
173 | { | 183 | { |
174 | QDictIterator<OipkgPackage> other( *_versions ); | 184 | QDictIterator<OipkgPackage> other( *_versions ); |
175 | while ( other.current() ) | 185 | while ( other.current() ) |
176 | { | 186 | { |
177 | if (other.current()->status().contains("installed") | 187 | if (other.current()->status().contains("installed") |
178 | && other.current()->version() == version()) | 188 | && other.current()->version() == version()) |
179 | return true; | 189 | return true; |
180 | ++other; | 190 | ++other; |
181 | } | 191 | } |
182 | } | 192 | } |
183 | return false; | 193 | return false; |
184 | } | 194 | } |
185 | 195 | ||
186 | bool OipkgPackage::otherInstalled() | 196 | bool OipkgPackage::otherInstalled() |
187 | { | 197 | { |
188 | if (_versions) | 198 | if (_versions) |
189 | { | 199 | { |
190 | QDictIterator<OipkgPackage> other( *_versions ); | 200 | QDictIterator<OipkgPackage> other( *_versions ); |
191 | while ( other.current() ) | 201 | while ( other.current() ) |
192 | { | 202 | { |
193 | if (other.current()->installed()) return true; | 203 | if (other.current()->installed()) return true; |
194 | ++other; | 204 | ++other; |
195 | } | 205 | } |
196 | } | 206 | } |
197 | return false; | 207 | return false; |
198 | } | 208 | } |
199 | 209 | ||
200 | void OipkgPackage::setDesc( QString s ) | 210 | void OipkgPackage::setDesc( QString s ) |
201 | { | 211 | { |
202 | _desc = s; | 212 | _desc = s; |
203 | _shortDesc = s.left( s.find("\n") ); | 213 | _shortDesc = s.left( s.find("\n") ); |
204 | } | 214 | } |
205 | 215 | ||
206 | QString OipkgPackage::desc() | 216 | QString OipkgPackage::desc() |
207 | { | 217 | { |
208 | return _desc; | 218 | return _desc; |
209 | } | 219 | } |
210 | 220 | ||
211 | QString OipkgPackage::shortDesc() | 221 | QString OipkgPackage::shortDesc() |
212 | { | 222 | { |
213 | return _shortDesc; | 223 | return _shortDesc; |
214 | } | 224 | } |
215 | 225 | ||
216 | QString OipkgPackage::size() | 226 | QString OipkgPackage::size() |
217 | { | 227 | { |
218 | return _size; | 228 | return _size; |
219 | } | 229 | } |
220 | 230 | ||
221 | 231 | ||
222 | QString OipkgPackage::version() | 232 | QString OipkgPackage::version() |
223 | { | 233 | { |
224 | return _version; | 234 | return _version; |
225 | } | 235 | } |
226 | 236 | ||
227 | QString OipkgPackage::sizeUnits() | 237 | QString OipkgPackage::sizeUnits() |
228 | { | 238 | { |
229 | int i = _size.toInt(); | 239 | int i = _size.toInt(); |
230 | int c = 0; | 240 | int c = 0; |
231 | QString ret; | 241 | QString ret; |
232 | QStringList unit; | 242 | QStringList unit; |
233 | unit << "B" << "KB" << "MB" << "GB" << "TB"; //prepair for the future ;) | 243 | unit << "B" << "KB" << "MB" << "GB" << "TB"; //prepair for the future ;) |
234 | while (i > 1) | 244 | while (i > 1) |
235 | { | 245 | { |
236 | ret=QString::number(i)+" "+unit[c]; | 246 | ret=QString::number(i)+" "+unit[c]; |
237 | c++; | 247 | c++; |
238 | i /= 1024; | 248 | i /= 1024; |
239 | } | 249 | } |
240 | return ret; | 250 | return ret; |
241 | } | 251 | } |
242 | 252 | ||
243 | bool OipkgPackage::toProcess() | 253 | bool OipkgPackage::toProcess() |
244 | { | 254 | { |
245 | return _toProcess; | 255 | return _toProcess; |
246 | } | 256 | } |
247 | 257 | ||
248 | bool OipkgPackage::toRemove() | 258 | bool OipkgPackage::toRemove() |
249 | { | 259 | { |
250 | if ( _toProcess && installed() ) return true; | 260 | if ( _toProcess && installed() ) return true; |
251 | else return false; | 261 | else return false; |
252 | } | 262 | } |
253 | 263 | ||
254 | bool OipkgPackage::toInstall() | 264 | bool OipkgPackage::toInstall() |
255 | { | 265 | { |
256 | if ( _toProcess && !installed() ) return true; | 266 | if ( _toProcess && !installed() ) return true; |
257 | else return false; | 267 | else return false; |
258 | } | 268 | } |
259 | 269 | ||
260 | void OipkgPackage::toggleProcess() | 270 | void OipkgPackage::toggleProcess() |
261 | { | 271 | { |
262 | _toProcess = ! _toProcess; | 272 | _toProcess = ! _toProcess; |
263 | } | 273 | } |
264 | 274 | ||
265 | 275 | ||
266 | void OipkgPackage::copyValues( OipkgPackage* pack ) | 276 | void OipkgPackage::copyValues( OipkgPackage* pack ) |
267 | { | 277 | { |
268 | if (_size.isEmpty() && !pack->_size.isEmpty()) _size = QString( pack->_size ); | 278 | if (_size.isEmpty() && !pack->_size.isEmpty()) _size = QString( pack->_size ); |
269 | if (_section.isEmpty() && !pack->_section.isEmpty()) _section = QString( pack->_section ); | 279 | if (_section.isEmpty() && !pack->_section.isEmpty()) _section = QString( pack->_section ); |
270 | if (_subsection.isEmpty()&& !pack->_subsection.isEmpty()) _subsection = QString( pack->_subsection ); | 280 | if (_subsection.isEmpty()&& !pack->_subsection.isEmpty()) _subsection = QString( pack->_subsection ); |
271 | if (_shortDesc.isEmpty() && !pack->_shortDesc.isEmpty()) _shortDesc = QString( pack->_shortDesc ); | 281 | if (_shortDesc.isEmpty() && !pack->_shortDesc.isEmpty()) _shortDesc = QString( pack->_shortDesc ); |
272 | if (_desc.isEmpty() && !pack->_desc.isEmpty()) _desc = QString( pack->_desc ); | 282 | if (_desc.isEmpty() && !pack->_desc.isEmpty()) _desc = QString( pack->_desc ); |
273 | if (_name.isEmpty() && !pack->_name.isEmpty()) _name = QString( pack->_name ); | 283 | if (_name.isEmpty() && !pack->_name.isEmpty()) _name = QString( pack->_name ); |
274 | if (_dest.isEmpty() && !pack->_dest.isEmpty()) _dest= QString( pack->_dest ); | 284 | if (_dest.isEmpty() && !pack->_dest.isEmpty()) _dest= QString( pack->_dest ); |
275 | if (_displayName.isEmpty()&& !pack->_displayName.isEmpty()) _displayName = QString( pack->_displayName ); | 285 | if (_displayName.isEmpty()&& !pack->_displayName.isEmpty()) _displayName = QString( pack->_displayName ); |
276 | if (_fileName.isEmpty() && !pack->_fileName.isEmpty()) _fileName = QString( pack->_fileName ); | 286 | if (_fileName.isEmpty() && !pack->_fileName.isEmpty()) _fileName = QString( pack->_fileName ); |
277 | if (_version.isEmpty() && !pack->_version.isEmpty()) _version = QString( pack->_version ); | 287 | if (_version.isEmpty() && !pack->_version.isEmpty()) _version = QString( pack->_version ); |
278 | if (_values.isEmpty() && !pack->_values.isEmpty())_values = QDict<QString>( pack->_values ); | 288 | if (_values.isEmpty() && !pack->_values.isEmpty())_values = QDict<QString>( pack->_values ); |
279 | if (!installed() && _status.isEmpty() && !pack->_status.isEmpty()) _status = QString( pack->_status ); | 289 | if (!installed() && _status.isEmpty() && !pack->_status.isEmpty()) _status = QString( pack->_status ); |
280 | } | 290 | } |
281 | 291 | ||
282 | QString OipkgPackage::section() | 292 | QString OipkgPackage::section() |
283 | { | 293 | { |
284 | return _section; | 294 | return _section; |
285 | } | 295 | } |
286 | 296 | ||
287 | void OipkgPackage::setSection( QString s) | 297 | void OipkgPackage::setSection( QString s) |
288 | { | 298 | { |
289 | int i = s.find("/"); | 299 | int i = s.find("/"); |
290 | if ( i > 0 ) | 300 | if ( i > 0 ) |
291 | { | 301 | { |
292 | _section = s.left(i); | 302 | _section = s.left(i); |
293 | _subsection = s.mid(i+1); | 303 | _subsection = s.mid(i+1); |
294 | }else{ | 304 | }else{ |
295 | _section = s; | 305 | _section = s; |
296 | _subsection = ""; | 306 | _subsection = ""; |
297 | } | 307 | } |
298 | } | 308 | } |
299 | 309 | ||
300 | QString OipkgPackage::subSection() | 310 | QString OipkgPackage::subSection() |
301 | { | 311 | { |
302 | return _subsection; | 312 | return _subsection; |
303 | } | 313 | } |
304 | 314 | ||
305 | void OipkgPackage::parsePackage( QStringList pack ) | 315 | void OipkgPackage::parsePackage( QStringList pack ) |
306 | { | 316 | { |
307 | if ( pack.isEmpty() ) return; | 317 | if ( pack.isEmpty() ) return; |
308 | int count = pack.count(); | 318 | int count = pack.count(); |
309 | for( int i = 0; i < count; i++ ) | 319 | for( int i = 0; i < count; i++ ) |
310 | { | 320 | { |
311 | QString line = pack[i]; | 321 | QString line = pack[i]; |
312 | int sep = line.find( QRegExp(":[\t ]+") ); | 322 | int sep = line.find( QRegExp(":[\t ]+") ); |
313 | if ( sep >= 0 ) | 323 | if ( sep >= 0 ) |
314 | { | 324 | { |
315 | QString tag = line.left(sep); | 325 | QString tag = line.left(sep); |
316 | QString value = line.mid(sep+2).simplifyWhiteSpace(); | 326 | QString value = line.mid(sep+2).simplifyWhiteSpace(); |
317 | setValue( tag, value ); | 327 | setValue( tag, value ); |
318 | }else{ | 328 | }else{ |
319 | } | 329 | } |
320 | } | 330 | } |
321 | return; | 331 | return; |
322 | } | 332 | } |
323 | 333 | ||
324 | QString OipkgPackage::details() | 334 | QString OipkgPackage::details() |
325 | { | 335 | { |
326 | QString status; | 336 | QString status; |
327 | Process ipkg_status(QStringList() << "ipkg" << "info" << name() ); | 337 | Process ipkg_status(QStringList() << "ipkg" << "info" << name() ); |
328 | QString description; | 338 | QString description; |
329 | if ( ipkg_status.exec("",status) ) | 339 | if ( ipkg_status.exec("",status) ) |
330 | { | 340 | { |
331 | QStringList lines = QStringList::split('\n',status,TRUE); | 341 | QStringList lines = QStringList::split('\n',status,TRUE); |
332 | for (QStringList::Iterator it = lines.begin(); it!=lines.end(); ++it) { | 342 | for (QStringList::Iterator it = lines.begin(); it!=lines.end(); ++it) { |
333 | QString line = *it; | 343 | QString line = *it; |
334 | if ( line == " ." ) | 344 | if ( line == " ." ) |
335 | { | 345 | { |
336 | description.append("<p>"); | 346 | description.append("<p>"); |
337 | } else | 347 | } else |
diff --git a/noncore/unsupported/oipkg/package.h b/noncore/unsupported/oipkg/package.h index 2334c31..02d8eff 100644 --- a/noncore/unsupported/oipkg/package.h +++ b/noncore/unsupported/oipkg/package.h | |||
@@ -1,100 +1,101 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> | 9 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> |
10 | #ifndef PK_ITEM_H | 10 | #ifndef PK_ITEM_H |
11 | #define PK_ITEM_H | 11 | #define PK_ITEM_H |
12 | 12 | ||
13 | #include <qstring.h> | 13 | #include <qstring.h> |
14 | #include <qlistview.h> | 14 | #include <qlistview.h> |
15 | #include <qpainter.h> | 15 | #include <qpainter.h> |
16 | #include <qpixmap.h> | 16 | #include <qpixmap.h> |
17 | #include <qdict.h> | 17 | #include <qdict.h> |
18 | #include <qobject.h> | 18 | #include <qobject.h> |
19 | 19 | ||
20 | #include "pksettings.h" | 20 | #include "pksettings.h" |
21 | 21 | ||
22 | class OipkgPackage : public QObject | 22 | class OipkgPackage : public QObject |
23 | { | 23 | { |
24 | Q_OBJECT | 24 | Q_OBJECT |
25 | public: | 25 | public: |
26 | OipkgPackage(QObject *parent=0, const char *name=0); | 26 | OipkgPackage(QObject *parent=0, const char *name=0); |
27 | OipkgPackage(PackageManagerSettings *s, QObject *parent=0, const char *name=0); | 27 | OipkgPackage(PackageManagerSettings *s, QObject *parent=0, const char *name=0); |
28 | ~OipkgPackage(); | 28 | ~OipkgPackage(); |
29 | OipkgPackage( QStringList, PackageManagerSettings *s, QObject *parent=0, const char *name=0 ); | 29 | OipkgPackage( QStringList, PackageManagerSettings *s, QObject *parent=0, const char *name=0 ); |
30 | OipkgPackage( QString, PackageManagerSettings *s, QObject *parent=0, const char *name=0 ); | 30 | OipkgPackage( QString, PackageManagerSettings *s, QObject *parent=0, const char *name=0 ); |
31 | OipkgPackage( OipkgPackage*s, QObject *parent=0, const char *name=0 ); | 31 | OipkgPackage( OipkgPackage*s, QObject *parent=0, const char *name=0 ); |
32 | 32 | ||
33 | void setValue( QString, QString ); | 33 | void setValue( QString, QString ); |
34 | void copyValues( OipkgPackage* ); | 34 | void copyValues( OipkgPackage* ); |
35 | 35 | ||
36 | QString name(); | 36 | QString name(); |
37 | QString installName(); | 37 | QString installName(); |
38 | QString packageName(); | 38 | QString packageName(); |
39 | bool installed(); | 39 | bool installed(); |
40 | bool otherInstalled(); | 40 | bool otherInstalled(); |
41 | 41 | ||
42 | void setDesc( QString ); | 42 | void setDesc( QString ); |
43 | QString shortDesc(); | 43 | QString shortDesc(); |
44 | QString desc(); | 44 | QString desc(); |
45 | QString size(); | 45 | QString size(); |
46 | QString sizeUnits(); | 46 | QString sizeUnits(); |
47 | QString version(); | 47 | QString version(); |
48 | void setSection( QString ); | 48 | void setSection( QString ); |
49 | QString section(); | 49 | QString section(); |
50 | QString subSection(); | 50 | QString subSection(); |
51 | QString details(); | 51 | QString details(); |
52 | bool toProcess(); | 52 | bool toProcess(); |
53 | bool toInstall(); | 53 | bool toInstall(); |
54 | bool toRemove(); | 54 | bool toRemove(); |
55 | void processed(); | 55 | void processed(); |
56 | QString dest(); | 56 | QString dest(); |
57 | void setDest( QString d ); | 57 | void setDest( QString d ); |
58 | void setOn(); | 58 | void setOn(); |
59 | bool link(); | 59 | bool link(); |
60 | void setLink(bool); | 60 | void setLink(bool); |
61 | bool isOld(); | 61 | bool isOld(); |
62 | bool hasVersions(); | 62 | bool hasVersions(); |
63 | void parseIpkgFile( QString ); | 63 | void parseIpkgFile( QString ); |
64 | void instalFromFile(bool iff=true); | 64 | void instalFromFile(bool iff=true); |
65 | void setName(QString); | 65 | void setName(QString); |
66 | QDict<QString>* getFields(); | 66 | QDict<QString>* getFields(); |
67 | QString status(); | 67 | QString status(); |
68 | 68 | ||
69 | QDict<OipkgPackage>* getOtherVersions(); | 69 | QDict<OipkgPackage>* getOtherVersions(); |
70 | void setOtherVersions(QDict<OipkgPackage>*); | 70 | void setOtherVersions(QDict<OipkgPackage>*); |
71 | 71 | ||
72 | public slots: | 72 | public slots: |
73 | void toggleProcess(); | 73 | void toggleProcess(); |
74 | 74 | ||
75 | private: | 75 | private: |
76 | PackageManagerSettings *settings; | 76 | PackageManagerSettings *settings; |
77 | QString _displayName; | 77 | QString _displayName; |
78 | QString _name; | 78 | QString _name; |
79 | QString _fileName; | 79 | QString _fileName; |
80 | bool _old; | 80 | bool _old; |
81 | bool _hasVersions; | 81 | bool _hasVersions; |
82 | bool _toProcess; | 82 | bool _toProcess; |
83 | bool _link; | 83 | bool _link; |
84 | QString _status; | 84 | QString _status; |
85 | QString _size; | 85 | QString _size; |
86 | QString _section; | 86 | QString _section; |
87 | QString _subsection; | 87 | QString _subsection; |
88 | QString _shortDesc; | 88 | QString _shortDesc; |
89 | QString _desc; | 89 | QString _desc; |
90 | QString _version; | 90 | QString _version; |
91 | QString _dest; | 91 | QString _dest; |
92 | QDict<QString> _values; | 92 | QDict<QString> _values; |
93 | QDict<OipkgPackage> *_versions; | 93 | QDict<OipkgPackage> *_versions; |
94 | bool _useFileName; | 94 | bool _useFileName; |
95 | void parsePackage( QStringList ); | 95 | void parsePackage( QStringList ); |
96 | void init(PackageManagerSettings *); | 96 | void init(); |
97 | // void init(PackageManagerSettings*); | ||
97 | }; | 98 | }; |
98 | 99 | ||
99 | 100 | ||
100 | #endif | 101 | #endif |
diff --git a/noncore/unsupported/oipkg/packagelist.cpp b/noncore/unsupported/oipkg/packagelist.cpp index 5f79ec1..6f0b56f 100644 --- a/noncore/unsupported/oipkg/packagelist.cpp +++ b/noncore/unsupported/oipkg/packagelist.cpp | |||
@@ -1,240 +1,241 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> | 9 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> |
10 | #include "packagelist.h" | 10 | #include "packagelist.h" |
11 | 11 | ||
12 | #include <assert.h> | 12 | #include <assert.h> |
13 | #include <qfile.h> | 13 | #include <qfile.h> |
14 | #include <qfileinfo.h> | 14 | #include <qfileinfo.h> |
15 | #include <qtextstream.h> | 15 | #include <qtextstream.h> |
16 | 16 | ||
17 | #include "debug.h" | 17 | #include "debug.h" |
18 | 18 | ||
19 | static QDict<OipkgPackage> *packageListAll; | 19 | static QDict<OipkgPackage> *packageListAll; |
20 | static int packageListAllRefCount = 0; | 20 | static int packageListAllRefCount = 0; |
21 | 21 | ||
22 | PackageList::PackageList(QObject *parent, const char *name) | 22 | PackageList::PackageList(QObject *parent, const char *name) |
23 | : QObject(parent,name), packageIter( packageList ) | 23 | : QObject(parent,name), packageIter( packageList ) |
24 | { | 24 | { |
25 | empty=true; | 25 | empty=true; |
26 | if (!packageListAll) packageListAll = new QDict<OipkgPackage>(); | 26 | if (!packageListAll) packageListAll = new QDict<OipkgPackage>(); |
27 | packageListAllRefCount++; | 27 | packageListAllRefCount++; |
28 | sections << "All"; | 28 | sections << "All"; |
29 | subSections.insert("All", new QStringList() ); | 29 | subSections.insert("All", new QStringList() ); |
30 | QStringList *ss = subSections["All"]; | 30 | QStringList *ss = subSections["All"]; |
31 | *ss << "All"; | 31 | *ss << "All"; |
32 | aktSection = "All"; | 32 | aktSection = "All"; |
33 | aktSubSection = "All"; | 33 | aktSubSection = "All"; |
34 | } | 34 | } |
35 | 35 | ||
36 | PackageList::PackageList( PackageManagerSettings* s, QObject *parent, const char *name) | 36 | PackageList::PackageList( PackageManagerSettings* s, QObject *parent, const char *name) |
37 | : QObject(parent,name), packageIter( packageList ) | 37 | : QObject(parent,name), packageIter( packageList ) |
38 | { | 38 | { |
39 | settings = s; | 39 | settings = s; |
40 | PackageList(parent, name); | 40 | PackageList(parent, name); |
41 | } | 41 | } |
42 | 42 | ||
43 | PackageList::~PackageList() | 43 | PackageList::~PackageList() |
44 | { | 44 | { |
45 | if (--packageListAllRefCount < 1 ) delete packageListAll; | 45 | if (--packageListAllRefCount < 1 ) delete packageListAll; |
46 | } | 46 | } |
47 | 47 | ||
48 | /** Inserts a package into the list */ | 48 | /** Inserts a package into the list */ |
49 | void PackageList::insertPackage( OipkgPackage* pack ) | 49 | void PackageList::insertPackage( OipkgPackage* pack ) |
50 | { | 50 | { |
51 | if (!pack) return; | 51 | if (!pack) return; |
52 | OipkgPackage* p = packageListAll->find( pack->name() ); | 52 | OipkgPackage* p = packageListAll->find( pack->name() ); |
53 | if ( p ) | 53 | if ( p ) |
54 | { | 54 | { |
55 | if ( (p->version() == pack->version()) | 55 | if ( (p->version() == pack->version()) |
56 | // && (p->dest() == pack->dest()) | 56 | // && (p->dest() == pack->dest()) |
57 | ) | 57 | ) |
58 | { | 58 | { |
59 | p->copyValues( pack ); | 59 | p->copyValues( pack ); |
60 | delete pack; | 60 | delete pack; |
61 | pack = p; | 61 | pack = p; |
62 | } else { | 62 | } else { |
63 | QDict<OipkgPackage> *packver = p->getOtherVersions(); | 63 | QDict<OipkgPackage> *packver = p->getOtherVersions(); |
64 | // p->setName( pack->name()+"["+p->version()+"]" ); | 64 | // p->setName( pack->name()+"["+p->version()+"]" ); |
65 | if (!packver) | 65 | if (!packver) |
66 | { | 66 | { |
67 | packver = new QDict<OipkgPackage>(); | 67 | packver = new QDict<OipkgPackage>(); |
68 | packver->insert( pack->name(), p ); | 68 | packver->insert( pack->name(), p ); |
69 | p->setOtherVersions( packver ); | 69 | p->setOtherVersions( packver ); |
70 | } | 70 | } |
71 | pack->setName( pack->name() );//+"["+pack->version()+"]" ); | 71 | pack->setName( pack->name() );//+"["+pack->version()+"]" ); |
72 | pack->setOtherVersions( packver ); | 72 | pack->setOtherVersions( packver ); |
73 | packver->insert( pack->name(), pack ); | 73 | packver->insert( pack->name(), pack ); |
74 | packageListAll->insert( pack->name(), pack ); | 74 | packageListAll->insert( pack->name(), pack ); |
75 | packageList.insert( pack->name(), pack ); | 75 | packageList.insert( pack->name(), pack ); |
76 | origPackageList.insert( pack->name(), pack ); | 76 | origPackageList.insert( pack->name(), pack ); |
77 | } | 77 | } |
78 | }else{ | 78 | }else{ |
79 | packageListAll->insert( pack->name(), pack ); | 79 | packageListAll->insert( pack->name(), pack ); |
80 | packageList.insert( pack->name(), pack ); | 80 | packageList.insert( pack->name(), pack ); |
81 | origPackageList.insert( pack->name(), pack ); | 81 | origPackageList.insert( pack->name(), pack ); |
82 | }; | 82 | }; |
83 | empty=false; | 83 | empty=false; |
84 | updateSections( pack ); | 84 | updateSections( pack ); |
85 | } | 85 | } |
86 | 86 | ||
87 | void PackageList::filterPackages( QString f ) | 87 | void PackageList::filterPackages( QString f ) |
88 | { | 88 | { |
89 | packageList.clear(); | 89 | packageList.clear(); |
90 | QDictIterator<OipkgPackage> filterIter( origPackageList ); | 90 | QDictIterator<OipkgPackage> filterIter( origPackageList ); |
91 | filterIter.toFirst(); | 91 | filterIter.toFirst(); |
92 | OipkgPackage *pack= filterIter.current() ; | 92 | OipkgPackage *pack= filterIter.current() ; |
93 | while ( pack ) | 93 | while ( pack ) |
94 | { | 94 | { |
95 | if ( | 95 | if ( |
96 | ((aktSection=="All")||(pack->section()==aktSection)) && | 96 | ((aktSection=="All")||(pack->section()==aktSection)) && |
97 | ((aktSubSection=="All")||(pack->subSection()==aktSubSection)) && | 97 | ((aktSubSection=="All")||(pack->subSection()==aktSubSection)) && |
98 | pack->name().contains( f ) | 98 | pack->name().contains( f ) |
99 | ) | 99 | ) |
100 | { | 100 | { |
101 | packageList.insert( pack->name(), pack ); | 101 | packageList.insert( pack->name(), pack ); |
102 | } | 102 | } |
103 | ++filterIter; | 103 | ++filterIter; |
104 | pack = filterIter.current(); | 104 | pack = filterIter.current(); |
105 | } | 105 | } |
106 | } | 106 | } |
107 | 107 | ||
108 | OipkgPackage* PackageList::find( QString n ) | 108 | OipkgPackage* PackageList::find( QString n ) |
109 | { | 109 | { |
110 | return packageList.find( n ); | 110 | return packageList.find( n ); |
111 | } | 111 | } |
112 | 112 | ||
113 | OipkgPackage* PackageList::first() | 113 | OipkgPackage* PackageList::first() |
114 | { | 114 | { |
115 | packageIter.toFirst(); | 115 | packageIter.toFirst(); |
116 | return packageIter.current(); | 116 | return packageIter.current(); |
117 | } | 117 | } |
118 | 118 | ||
119 | OipkgPackage* PackageList::next() | 119 | OipkgPackage* PackageList::next() |
120 | { | 120 | { |
121 | ++packageIter; | 121 | ++packageIter; |
122 | return packageIter.current(); | 122 | return packageIter.current(); |
123 | } | 123 | } |
124 | 124 | ||
125 | QStringList PackageList::getSections() | 125 | QStringList PackageList::getSections() |
126 | { | 126 | { |
127 | sections.sort(); | 127 | sections.sort(); |
128 | return sections; | 128 | return sections; |
129 | } | 129 | } |
130 | 130 | ||
131 | QStringList PackageList::getSubSections() | 131 | QStringList PackageList::getSubSections() |
132 | { | 132 | { |
133 | QStringList ss; | 133 | QStringList ss; |
134 | if ( !subSections[aktSection] ) return ss; | 134 | if ( !subSections[aktSection] ) return ss; |
135 | ss = *subSections[aktSection]; | 135 | ss = *subSections[aktSection]; |
136 | ss.sort(); | 136 | ss.sort(); |
137 | return ss; | 137 | return ss; |
138 | } | 138 | } |
139 | 139 | ||
140 | void PackageList::setSection( QString sec ) | 140 | void PackageList::setSection( QString sec ) |
141 | { | 141 | { |
142 | aktSection = sec; | 142 | aktSection = sec; |
143 | } | 143 | } |
144 | 144 | ||
145 | void PackageList::setSubSection( QString ssec ) | 145 | void PackageList::setSubSection( QString ssec ) |
146 | { | 146 | { |
147 | aktSubSection = ssec; | 147 | aktSubSection = ssec; |
148 | } | 148 | } |
149 | 149 | ||
150 | void PackageList::updateSections( OipkgPackage* pack ) | 150 | void PackageList::updateSections( OipkgPackage* pack ) |
151 | { | 151 | { |
152 | QString s = pack->section(); | 152 | QString s = pack->section(); |
153 | if ( s.isEmpty() || s == "") return; | 153 | if ( s.isEmpty() || s == "") return; |
154 | if ( !sections.contains(s) ) sections += s; | 154 | if ( !sections.contains(s) ) sections += s; |
155 | QString ss = pack->subSection(); | 155 | QString ss = pack->subSection(); |
156 | if ( ss.isEmpty() || ss == "" ) return; | 156 | if ( ss.isEmpty() || ss == "" ) return; |
157 | if ( !subSections[s] ) { | 157 | if ( !subSections[s] ) { |
158 | subSections.insert( s, new QStringList() ); | 158 | subSections.insert( s, new QStringList() ); |
159 | QStringList *subsecs = subSections[s]; | 159 | QStringList *subsecs = subSections[s]; |
160 | *subsecs += "All"; | 160 | *subsecs += "All"; |
161 | } | 161 | } |
162 | QStringList *subsecs = subSections[s]; | 162 | QStringList *subsecs = subSections[s]; |
163 | if ( !subsecs->contains(ss) ) *subsecs += ss; | 163 | if ( !subsecs->contains(ss) ) *subsecs += ss; |
164 | // if ( !subSections["All"] ) subSections.insert( "All", new QStringList() ); | 164 | // if ( !subSections["All"] ) subSections.insert( "All", new QStringList() ); |
165 | // subsecs = subSections["All"]; | 165 | // subsecs = subSections["All"]; |
166 | // *subsecs += ss; | 166 | // *subsecs += ss; |
167 | } | 167 | } |
168 | 168 | ||
169 | 169 | ||
170 | void PackageList::readFileEntries( QString filename, QString dest ) | 170 | void PackageList::readFileEntries( QString filename, QString dest ) |
171 | { | 171 | { |
172 | pvDebug(5,"PackageList::readFileEntries "+filename+" dest "+dest); | 172 | pvDebug(5,"PackageList::readFileEntries "+filename+" dest "+dest); |
173 | QStringList packEntry; | 173 | QStringList packEntry; |
174 | QFile f( filename ); | 174 | QFile f( filename ); |
175 | if ( !f.open(IO_ReadOnly) ) return; | 175 | if ( !f.open(IO_ReadOnly) ) return; |
176 | QTextStream *statusStream = new QTextStream( &f ); | 176 | QTextStream *statusStream = new QTextStream( &f ); |
177 | while ( !statusStream ->eof() ) | 177 | while ( !statusStream ->eof() ) |
178 | { | 178 | { |
179 | QString line = statusStream->readLine(); | 179 | QString line = statusStream->readLine(); |
180 | if ( line.find(QRegExp("[\n\t ]*")) || line == "" ) | 180 | if ( line.find(QRegExp("[\n\t ]*")) || line == "" ) |
181 | { | 181 | { |
182 | //end of package | 182 | //end of package |
183 | if ( ! packEntry.isEmpty() ) | 183 | if ( ! packEntry.isEmpty() ) |
184 | { | 184 | { |
185 | OipkgPackage *p = new OipkgPackage( packEntry, settings ); | 185 | OipkgPackage *p = new OipkgPackage( packEntry, settings ); |
186 | if ( p ) | 186 | if ( p ) |
187 | { | 187 | { |
188 | p->setDest( dest ); | 188 | p->setDest( dest ); |
189 | insertPackage( p ); | 189 | insertPackage( p ); |
190 | packEntry.clear(); | 190 | packEntry.clear(); |
191 | } | 191 | } |
192 | } | 192 | } |
193 | }else{ | 193 | }else{ |
194 | packEntry << line; | 194 | packEntry << line; |
195 | }; | 195 | }; |
196 | } | 196 | } |
197 | //there might be no nl at the end of the package file | 197 | //there might be no nl at the end of the package file |
198 | if ( ! packEntry.isEmpty() ) | 198 | if ( ! packEntry.isEmpty() ) |
199 | { | 199 | { |
200 | OipkgPackage *p = new OipkgPackage( packEntry, settings ); | 200 | OipkgPackage *p = new OipkgPackage( packEntry, settings ); |
201 | if ( p ) | 201 | if ( p ) |
202 | { | 202 | { |
203 | p->setDest( dest ); | 203 | p->setDest( dest ); |
204 | insertPackage( p ); | 204 | insertPackage( p ); |
205 | packEntry.clear(); | 205 | packEntry.clear(); |
206 | } | 206 | } |
207 | } | 207 | } |
208 | delete statusStream; | 208 | delete statusStream; |
209 | f.close(); | ||
209 | return; | 210 | return; |
210 | } | 211 | } |
211 | 212 | ||
212 | void PackageList::setSettings( PackageManagerSettings *s ) | 213 | void PackageList::setSettings( PackageManagerSettings *s ) |
213 | { | 214 | { |
214 | settings = s; | 215 | settings = s; |
215 | } | 216 | } |
216 | 217 | ||
217 | OipkgPackage* PackageList::getByName( QString n ) | 218 | OipkgPackage* PackageList::getByName( QString n ) |
218 | { | 219 | { |
219 | return origPackageList[n]; | 220 | return origPackageList[n]; |
220 | } | 221 | } |
221 | 222 | ||
222 | void PackageList::clear() | 223 | void PackageList::clear() |
223 | { | 224 | { |
224 | origPackageList.clear(); | 225 | origPackageList.clear(); |
225 | packageList.clear(); | 226 | packageList.clear(); |
226 | } | 227 | } |
227 | 228 | ||
228 | void PackageList::allPackages() | 229 | void PackageList::allPackages() |
229 | { | 230 | { |
230 | packageList.clear(); | 231 | packageList.clear(); |
231 | QDictIterator<OipkgPackage> filterIter( origPackageList ); | 232 | QDictIterator<OipkgPackage> filterIter( origPackageList ); |
232 | filterIter.toFirst(); | 233 | filterIter.toFirst(); |
233 | OipkgPackage *pack= filterIter.current() ; | 234 | OipkgPackage *pack= filterIter.current() ; |
234 | while ( pack ) | 235 | while ( pack ) |
235 | { | 236 | { |
236 | packageList.insert( pack->name(), pack ); | 237 | packageList.insert( pack->name(), pack ); |
237 | ++filterIter; | 238 | ++filterIter; |
238 | pack = filterIter.current(); | 239 | pack = filterIter.current(); |
239 | } | 240 | } |
240 | } | 241 | } |
diff --git a/noncore/unsupported/oipkg/packagelistitem.cpp b/noncore/unsupported/oipkg/packagelistitem.cpp index 51d024b..1610a37 100644 --- a/noncore/unsupported/oipkg/packagelistitem.cpp +++ b/noncore/unsupported/oipkg/packagelistitem.cpp | |||
@@ -1,239 +1,240 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> | 9 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> |
10 | #include "packagelistitem.h" | 10 | #include "packagelistitem.h" |
11 | 11 | ||
12 | #include <qpe/resource.h> | 12 | #include <qpe/resource.h> |
13 | #include <qobject.h> | 13 | #include <qobject.h> |
14 | #include <qpopupmenu.h> | 14 | #include <qpopupmenu.h> |
15 | #include <qaction.h> | 15 | #include <qaction.h> |
16 | 16 | ||
17 | #include "debug.h" | 17 | #include "debug.h" |
18 | 18 | ||
19 | static QPixmap *pm_uninstalled=0; | 19 | static QPixmap *pm_uninstalled=0; |
20 | static QPixmap *pm_uninstalled_old=0; | 20 | static QPixmap *pm_uninstalled_old=0; |
21 | static QPixmap *pm_installed=0; | 21 | static QPixmap *pm_installed=0; |
22 | static QPixmap *pm_installed_old=0; | 22 | static QPixmap *pm_installed_old=0; |
23 | static QPixmap *pm_uninstall=0; | 23 | static QPixmap *pm_uninstall=0; |
24 | static QPixmap *pm_install=0; | 24 | static QPixmap *pm_install=0; |
25 | static QPixmap *pm_uninstalled_old_installed_new=0; | 25 | static QPixmap *pm_uninstalled_old_installed_new=0; |
26 | static QPixmap *pm_uninstalled_installed_old=0; | 26 | static QPixmap *pm_uninstalled_installed_old=0; |
27 | 27 | ||
28 | PackageListItem::PackageListItem(ListViewItemOipkg *parent, QString name, Type ittype) | 28 | PackageListItem::PackageListItem(ListViewItemOipkg *parent, QString name, Type ittype) |
29 | : ListViewItemOipkg(parent,name,ittype) | 29 | : ListViewItemOipkg(parent,name,ittype) |
30 | { | 30 | { |
31 | 31 | ||
32 | } | 32 | } |
33 | 33 | ||
34 | PackageListItem::PackageListItem(QListView* lv, OipkgPackage *pi, PackageManagerSettings *s) | 34 | PackageListItem::PackageListItem(QListView* lv, OipkgPackage *pi, PackageManagerSettings *s) |
35 | :ListViewItemOipkg(lv,pi->name(),ListViewItemOipkg::Package) | 35 | :ListViewItemOipkg(lv,pi->name(),ListViewItemOipkg::Package) |
36 | { | 36 | { |
37 | init(pi,s); | 37 | init(pi,s); |
38 | } | 38 | } |
39 | 39 | ||
40 | PackageListItem::PackageListItem(ListViewItemOipkg *lvi, OipkgPackage *pi, PackageManagerSettings *s) | 40 | PackageListItem::PackageListItem(ListViewItemOipkg *lvi, OipkgPackage *pi, PackageManagerSettings *s) |
41 | :ListViewItemOipkg(lvi,pi->name(),ListViewItemOipkg::Package) | 41 | :ListViewItemOipkg(lvi,pi->name(),ListViewItemOipkg::Package) |
42 | { | 42 | { |
43 | init(pi,s); | 43 | init(pi,s); |
44 | } | 44 | } |
45 | PackageListItem::~PackageListItem() | 45 | PackageListItem::~PackageListItem() |
46 | { | 46 | { |
47 | delete popupMenu; | 47 | delete popupMenu; |
48 | delete destsMenu; | 48 | delete destsMenu; |
49 | } | 49 | } |
50 | 50 | ||
51 | void PackageListItem::init( OipkgPackage *pi, PackageManagerSettings *s) | 51 | void PackageListItem::init( OipkgPackage *pi, PackageManagerSettings *s) |
52 | { | 52 | { |
53 | //waring pass something different than 0 | ||
53 | popupMenu = new QPopupMenu( 0 ); | 54 | popupMenu = new QPopupMenu( 0 ); |
54 | destsMenu = new QPopupMenu( 0 ); | 55 | destsMenu = new QPopupMenu( 0 ); |
55 | package = pi; | 56 | package = pi; |
56 | settings = s; | 57 | settings = s; |
57 | setExpandable( true ); | 58 | setExpandable( true ); |
58 | ListViewItemOipkg *item; | 59 | ListViewItemOipkg *item; |
59 | nameItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute,"name" ); | 60 | nameItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute,"name" ); |
60 | item = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("Description: ")+pi->desc() ); | 61 | item = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("Description: ")+pi->desc() ); |
61 | item = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("Size: ")+pi->size() ); | 62 | item = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("Size: ")+pi->size() ); |
62 | destItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "dest" ); | 63 | destItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "dest" ); |
63 | linkItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "link" ); | 64 | linkItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "link" ); |
64 | statusItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "status" ); | 65 | statusItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, "status" ); |
65 | ListViewItemOipkg *otherItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("other") ); | 66 | ListViewItemOipkg *otherItem = new ListViewItemOipkg( this, ListViewItemOipkg::Attribute, QObject::tr("other") ); |
66 | item = new ListViewItemOipkg( otherItem, ListViewItemOipkg::Attribute, QObject::tr("Install Name: ")+pi->installName() ); | 67 | item = new ListViewItemOipkg( otherItem, ListViewItemOipkg::Attribute, QObject::tr("Install Name: ")+pi->installName() ); |
67 | QDict<QString> *fields = pi->getFields(); | 68 | QDict<QString> *fields = pi->getFields(); |
68 | QDictIterator<QString> it( *fields ); | 69 | QDictIterator<QString> it( *fields ); |
69 | while ( it.current() ) { | 70 | while ( it.current() ) { |
70 | item = new ListViewItemOipkg( otherItem, ListViewItemOipkg::Attribute, QString(it.currentKey()+": "+*it.current()) ); | 71 | item = new ListViewItemOipkg( otherItem, ListViewItemOipkg::Attribute, QString(it.currentKey()+": "+*it.current()) ); |
71 | ++it; | 72 | ++it; |
72 | } | 73 | } |
73 | displayDetails(); | 74 | displayDetails(); |
74 | 75 | ||
75 | if (!pm_uninstalled) | 76 | if (!pm_uninstalled) |
76 | { | 77 | { |
77 | pm_uninstalled = new QPixmap(Resource::loadPixmap("oipkg/uninstalled")); | 78 | pm_uninstalled = new QPixmap(Resource::loadPixmap("oipkg/uninstalled")); |
78 | pm_uninstalled_old = new QPixmap(Resource::loadPixmap("oipkg/uninstalledOld")); | 79 | pm_uninstalled_old = new QPixmap(Resource::loadPixmap("oipkg/uninstalledOld")); |
79 | pm_uninstalled_old_installed_new = new QPixmap(Resource::loadPixmap("oipkg/uninstalledOldinstalledNew")); | 80 | pm_uninstalled_old_installed_new = new QPixmap(Resource::loadPixmap("oipkg/uninstalledOldinstalledNew")); |
80 | pm_uninstalled_installed_old = new QPixmap(Resource::loadPixmap("oipkg/uninstalledInstalledOld")); | 81 | pm_uninstalled_installed_old = new QPixmap(Resource::loadPixmap("oipkg/uninstalledInstalledOld")); |
81 | pm_installed = new QPixmap(Resource::loadPixmap("oipkg/installed")); | 82 | pm_installed = new QPixmap(Resource::loadPixmap("oipkg/installed")); |
82 | pm_installed_old = new QPixmap(Resource::loadPixmap("oipkg/installedOld")); | 83 | pm_installed_old = new QPixmap(Resource::loadPixmap("oipkg/installedOld")); |
83 | pm_install = new QPixmap(Resource::loadPixmap("oipkg/install")); | 84 | pm_install = new QPixmap(Resource::loadPixmap("oipkg/install")); |
84 | pm_uninstall = new QPixmap(Resource::loadPixmap("oipkg/uninstall")); | 85 | pm_uninstall = new QPixmap(Resource::loadPixmap("oipkg/uninstall")); |
85 | } | 86 | } |
86 | } | 87 | } |
87 | 88 | ||
88 | void PackageListItem::paintCell( QPainter *p, const QColorGroup & cg, | 89 | void PackageListItem::paintCell( QPainter *p, const QColorGroup & cg, |
89 | int column, int width, int alignment ) | 90 | int column, int width, int alignment ) |
90 | { | 91 | { |
91 | if ( !p ) | 92 | if ( !p ) |
92 | return; | 93 | return; |
93 | 94 | ||
94 | p->fillRect( 0, 0, width, height(), | 95 | p->fillRect( 0, 0, width, height(), |
95 | isSelected()? cg.highlight() : cg.base() ); | 96 | isSelected()? cg.highlight() : cg.base() ); |
96 | 97 | ||
97 | if ( column != 0 ) { | 98 | if ( column != 0 ) { |
98 | // The rest is text | 99 | // The rest is text |
99 | QListViewItem::paintCell( p, cg, column, width, alignment ); | 100 | QListViewItem::paintCell( p, cg, column, width, alignment ); |
100 | return; | 101 | return; |
101 | } | 102 | } |
102 | 103 | ||
103 | QListView *lv = listView(); | 104 | QListView *lv = listView(); |
104 | if ( !lv ) | 105 | if ( !lv ) |
105 | return; | 106 | return; |
106 | int marg = lv->itemMargin(); | 107 | int marg = lv->itemMargin(); |
107 | int r = marg; | 108 | int r = marg; |
108 | 109 | ||
109 | QPixmap pm = statePixmap(); | 110 | QPixmap pm = statePixmap(); |
110 | p->drawPixmap(marg,(height()-pm.height())/2,pm); | 111 | p->drawPixmap(marg,(height()-pm.height())/2,pm); |
111 | r += pm.width()+1; | 112 | r += pm.width()+1; |
112 | 113 | ||
113 | p->translate( r, 0 ); | 114 | p->translate( r, 0 ); |
114 | QListViewItem::paintCell( p, cg, column, width - r, alignment ); | 115 | QListViewItem::paintCell( p, cg, column, width - r, alignment ); |
115 | } | 116 | } |
116 | 117 | ||
117 | 118 | ||
118 | void PackageListItem::paintFocus( QPainter *p, const QColorGroup & cg, | 119 | void PackageListItem::paintFocus( QPainter *p, const QColorGroup & cg, |
119 | const QRect & r ) | 120 | const QRect & r ) |
120 | { | 121 | { |
121 | // Skip QCheckListItem | 122 | // Skip QCheckListItem |
122 | // (makes you wonder what we're getting from QCheckListItem) | 123 | // (makes you wonder what we're getting from QCheckListItem) |
123 | QListViewItem::paintFocus(p,cg,r); | 124 | QListViewItem::paintFocus(p,cg,r); |
124 | } | 125 | } |
125 | 126 | ||
126 | QPixmap PackageListItem::statePixmap() const | 127 | QPixmap PackageListItem::statePixmap() const |
127 | { | 128 | { |
128 | bool installed = package->installed(); | 129 | bool installed = package->installed(); |
129 | bool old = package->isOld(); | 130 | bool old = package->isOld(); |
130 | bool verinstalled = package->otherInstalled(); | 131 | bool verinstalled = package->otherInstalled(); |
131 | if ( !package->toProcess() ) { | 132 | if ( !package->toProcess() ) { |
132 | if ( !installed ) | 133 | if ( !installed ) |
133 | if (old) | 134 | if (old) |
134 | { | 135 | { |
135 | if (verinstalled) return *pm_uninstalled_old_installed_new; | 136 | if (verinstalled) return *pm_uninstalled_old_installed_new; |
136 | else return *pm_uninstalled_old; | 137 | else return *pm_uninstalled_old; |
137 | } | 138 | } |
138 | else | 139 | else |
139 | { | 140 | { |
140 | if (verinstalled) return *pm_uninstalled_installed_old; | 141 | if (verinstalled) return *pm_uninstalled_installed_old; |
141 | else return *pm_uninstalled; | 142 | else return *pm_uninstalled; |
142 | } | 143 | } |
143 | else | 144 | else |
144 | if (old) return *pm_installed_old; | 145 | if (old) return *pm_installed_old; |
145 | else return *pm_installed; | 146 | else return *pm_installed; |
146 | } else { //toProcess() == true | 147 | } else { //toProcess() == true |
147 | if ( !installed ) | 148 | if ( !installed ) |
148 | return *pm_install; | 149 | return *pm_install; |
149 | else | 150 | else |
150 | return *pm_uninstall; | 151 | return *pm_uninstall; |
151 | } | 152 | } |
152 | } | 153 | } |
153 | 154 | ||
154 | QString PackageListItem::key( int column, bool ascending ) const | 155 | QString PackageListItem::key( int column, bool ascending ) const |
155 | { | 156 | { |
156 | if ( column == 2 ) { | 157 | if ( column == 2 ) { |
157 | QString t = text(2); | 158 | QString t = text(2); |
158 | double bytes=t.toDouble(); | 159 | double bytes=t.toDouble(); |
159 | if ( t.contains('M') ) bytes*=1024*1024; | 160 | if ( t.contains('M') ) bytes*=1024*1024; |
160 | else if ( t.contains('K') || t.contains('k') ) bytes*=1024; | 161 | else if ( t.contains('K') || t.contains('k') ) bytes*=1024; |
161 | if ( !ascending ) bytes=999999999-bytes; | 162 | if ( !ascending ) bytes=999999999-bytes; |
162 | return QString().sprintf("%09d",(int)bytes); | 163 | return QString().sprintf("%09d",(int)bytes); |
163 | } else { | 164 | } else { |
164 | return QListViewItem::key(column,ascending); | 165 | return QListViewItem::key(column,ascending); |
165 | } | 166 | } |
166 | } | 167 | } |
167 | 168 | ||
168 | void PackageListItem::setOn( bool b ) | 169 | void PackageListItem::setOn( bool b ) |
169 | { | 170 | { |
170 | QCheckListItem::setOn( b ); | 171 | QCheckListItem::setOn( b ); |
171 | package->toggleProcess(); | 172 | package->toggleProcess(); |
172 | package->setLink( settings->createLinks() ); | 173 | package->setLink( settings->createLinks() ); |
173 | displayDetails(); | 174 | displayDetails(); |
174 | } | 175 | } |
175 | 176 | ||
176 | void PackageListItem::displayDetails() | 177 | void PackageListItem::displayDetails() |
177 | { | 178 | { |
178 | QString sod; | 179 | QString sod; |
179 | sod += package->sizeUnits().isEmpty()?QString(""):QString(package->sizeUnits()); | 180 | sod += package->sizeUnits().isEmpty()?QString(""):QString(package->sizeUnits()); |
180 | //sod += QString(package->dest().isEmpty()?"":QObject::tr(" on ")+package->dest()); | 181 | //sod += QString(package->dest().isEmpty()?"":QObject::tr(" on ")+package->dest()); |
181 | sod += package->dest().isEmpty()?QString(""):QString(QObject::tr(" on ")+package->dest()); | 182 | sod += package->dest().isEmpty()?QString(""):QString(QObject::tr(" on ")+package->dest()); |
182 | sod = sod.isEmpty()?QString(""):QString(" ("+sod+")"); | 183 | sod = sod.isEmpty()?QString(""):QString(" ("+sod+")"); |
183 | setText(0, package->name()+sod ); | 184 | setText(0, package->name()+sod ); |
184 | nameItem->setText( 0, QObject::tr("Name: ")+package->name()); | 185 | nameItem->setText( 0, QObject::tr("Name: ")+package->name()); |
185 | linkItem->setText( 0, QObject::tr("Link: ")+(package->link()?QObject::tr("Yes"):QObject::tr("No"))); | 186 | linkItem->setText( 0, QObject::tr("Link: ")+(package->link()?QObject::tr("Yes"):QObject::tr("No"))); |
186 | destItem->setText( 0, QObject::tr("Destination: ")+package->dest() ); | 187 | destItem->setText( 0, QObject::tr("Destination: ")+package->dest() ); |
187 | statusItem->setText( 0, QObject::tr("Status: ")+package->status() ); | 188 | statusItem->setText( 0, QObject::tr("Status: ")+package->status() ); |
188 | repaint(); | 189 | repaint(); |
189 | } | 190 | } |
190 | 191 | ||
191 | QPopupMenu* PackageListItem::getPopupMenu() | 192 | QPopupMenu* PackageListItem::getPopupMenu() |
192 | { | 193 | { |
193 | popupMenu->clear(); | 194 | popupMenu->clear(); |
194 | destsMenu->clear(); | 195 | destsMenu->clear(); |
195 | 196 | ||
196 | QAction *popupAction; | 197 | QAction *popupAction; |
197 | qDebug("PackageListItem::showPopup "); | 198 | qDebug("PackageListItem::showPopup "); |
198 | 199 | ||
199 | if (!package->installed()){ | 200 | if (!package->installed()){ |
200 | popupMenu->insertItem( QObject::tr("Install to"), destsMenu ); | 201 | popupMenu->insertItem( QObject::tr("Install to"), destsMenu ); |
201 | QStringList dests = settings->getDestinationNames(); | 202 | QStringList dests = settings->getDestinationNames(); |
202 | QString ad = settings->getDestinationName(); | 203 | QString ad = settings->getDestinationName(); |
203 | for (uint i = 0; i < dests.count(); i++ ) | 204 | for (uint i = 0; i < dests.count(); i++ ) |
204 | { | 205 | { |
205 | popupAction = new QAction( dests[i], QString::null, 0, popupMenu, 0 ); | 206 | popupAction = new QAction( dests[i], QString::null, 0, popupMenu, 0 ); |
206 | popupAction->addTo( destsMenu ); | 207 | popupAction->addTo( destsMenu ); |
207 | if ( dests[i] == ad && getPackage()->toInstall() ) | 208 | if ( dests[i] == ad && getPackage()->toInstall() ) |
208 | { | 209 | { |
209 | popupAction->setToggleAction( true ); | 210 | popupAction->setToggleAction( true ); |
210 | popupAction->setOn(true); | 211 | popupAction->setOn(true); |
211 | } | 212 | } |
212 | } | 213 | } |
213 | connect( destsMenu, SIGNAL( activated( int ) ), | 214 | connect( destsMenu, SIGNAL( activated( int ) ), |
214 | this, SLOT( menuAction( int ) ) ); | 215 | this, SLOT( menuAction( int ) ) ); |
215 | popupMenu->popup( QCursor::pos() ); | 216 | popupMenu->popup( QCursor::pos() ); |
216 | }else{ | 217 | }else{ |
217 | popupMenu->insertItem( QObject::tr("Remove")); | 218 | popupMenu->insertItem( QObject::tr("Remove")); |
218 | connect( popupMenu, SIGNAL( activated( int ) ), | 219 | connect( popupMenu, SIGNAL( activated( int ) ), |
219 | this, SLOT( menuAction( int ) ) ); | 220 | this, SLOT( menuAction( int ) ) ); |
220 | popupMenu->popup( QCursor::pos() ); | 221 | popupMenu->popup( QCursor::pos() ); |
221 | } | 222 | } |
222 | return popupMenu; | 223 | return popupMenu; |
223 | } | 224 | } |
224 | 225 | ||
225 | void PackageListItem::menuAction( int i ) | 226 | void PackageListItem::menuAction( int i ) |
226 | { | 227 | { |
227 | if (!package->installed()){ | 228 | if (!package->installed()){ |
228 | package->setDest( destsMenu->text(i) ); | 229 | package->setDest( destsMenu->text(i) ); |
229 | package->setLink( settings->createLinks() ); | 230 | package->setLink( settings->createLinks() ); |
230 | } | 231 | } |
231 | package->setOn(); | 232 | package->setOn(); |
232 | displayDetails(); | 233 | displayDetails(); |
233 | } | 234 | } |
234 | 235 | ||
235 | //void PackageListItem::toggleProcess() | 236 | //void PackageListItem::toggleProcess() |
236 | //{ | 237 | //{ |
237 | // package->toggleProcess() ; | 238 | // package->toggleProcess() ; |
238 | // displayDetails(); | 239 | // displayDetails(); |
239 | //} | 240 | //} |