summaryrefslogtreecommitdiff
path: root/noncore/unsupported/oipkg/package.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/oipkg/package.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/oipkg/package.cpp100
1 files changed, 49 insertions, 51 deletions
diff --git a/noncore/unsupported/oipkg/package.cpp b/noncore/unsupported/oipkg/package.cpp
index 3effb73..e020601 100644
--- a/noncore/unsupported/oipkg/package.cpp
+++ b/noncore/unsupported/oipkg/package.cpp
@@ -9,91 +9,90 @@
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
21Package::Package( QObject *parent, const char *name ) 21OipkgPackage::OipkgPackage( QObject *parent, const char *name )
22 : QObject(parent,name) 22 : QObject(parent,name)
23{ 23{
24 24
25} 25}
26 26
27Package::~Package() 27OipkgPackage::~OipkgPackage()
28{ 28{
29} 29}
30 30
31Package::Package( PackageManagerSettings *s, QObject *parent, const char *name ) 31OipkgPackage::OipkgPackage( PackageManagerSettings *s, QObject *parent, const char *name )
32 : QObject(parent,name) 32 : QObject(parent,name)
33{ 33 {
34 Package(parent,name);
35 init(s); 34 init(s);
36} 35}
37 36
38void Package::init( PackageManagerSettings *s ) 37void OipkgPackage::init( PackageManagerSettings *s )
39{ 38{
40 settings = s; 39 settings = s;
41 _size = ""; 40 _size = "";
42 _section = ""; 41 _section = "";
43 _subsection = ""; 42 _subsection = "";
44 _shortDesc = ""; 43 _shortDesc = "";
45 _desc = ""; 44 _desc = "";
46 _name = ""; 45 _name = "";
47 _toProcess = false; 46 _toProcess = false;
48 _useFileName = false; 47 _useFileName = false;
49 _old = false; 48 _old = false;
50 _status = ""; 49 _status = "";
51 _dest = settings->getDestinationName(); 50 _dest = settings->getDestinationName();
52 _link = settings->createLinks(); 51 _link = settings->createLinks();
53 _versions=0; 52 _versions=0;
54 _version=""; 53 _version="";
55} 54}
56 55
57Package::Package( QStringList pack, PackageManagerSettings *s , QObject *parent, const char *name ) 56OipkgPackage::OipkgPackage( QStringList pack, PackageManagerSettings *s , QObject *parent, const char *name )
58 : QObject(parent,name) 57 : QObject(parent,name)
59{ 58{
60 init(s); 59 init(s);
61 parsePackage( pack ); 60 parsePackage( pack );
62} 61}
63 62
64Package::Package( QString n, PackageManagerSettings *s, QObject *parent, const char *name ) 63OipkgPackage::OipkgPackage( QString n, PackageManagerSettings *s, QObject *parent, const char *name )
65 : QObject(parent,name) 64 : QObject(parent,name)
66{ 65{
67 init(s); 66 init(s);
68 if ( !QFile::exists( n ) ) 67 if ( !QFile::exists( n ) )
69 { 68 {
70 _name = QString( n ); 69 _name = QString( n );
71 }else{ 70 }else{
72 pvDebug(4,"remote file: "+n); 71 pvDebug(4,"remote file: "+n);
73 parseIpkgFile( n ); 72 parseIpkgFile( n );
74 _useFileName = true; 73 _useFileName = true;
75 _fileName = QString( n ); 74 _fileName = QString( n );
76 } 75 }
77} 76}
78 77
79Package::Package( Package *pi, QObject *parent, const char *name ) 78OipkgPackage::OipkgPackage( OipkgPackage *pi, QObject *parent, const char *name )
80 : QObject(parent,name) 79 : QObject(parent,name)
81{ 80{
82 init(pi->settings); 81 init(pi->settings);
83 copyValues( pi ); 82 copyValues( pi );
84} 83}
85 84
86 85
87void Package::setValue( QString n, QString t ) 86void OipkgPackage::setValue( QString n, QString t )
88{ 87{
89 if ( n == "Package" ) 88 if ( n == "Package" )
90 { 89 {
91 _name = QString( t ); 90 _name = QString( t );
92 }else if ( n == "Installed-Size" ) 91 }else if ( n == "Installed-Size" )
93 { 92 {
94 _size = t; 93 _size = t;
95// }else if ( n == "Priority") 94// }else if ( n == "Priority")
96// { 95// {
97 96
98 }else if ( n == "Section") 97 }else if ( n == "Section")
99 { 98 {
@@ -128,211 +127,210 @@ void Package::setValue( QString n, QString t )
128 }else if ( n == "Status") 127 }else if ( n == "Status")
129 { 128 {
130 if ( installed() ) return; 129 if ( installed() ) return;
131 _status = t; 130 _status = t;
132// }else if ( n == "Essential") 131// }else if ( n == "Essential")
133// { 132// {
134 133
135 }else{ 134 }else{
136 _values.insert(n,new QString(t)); 135 _values.insert(n,new QString(t));
137 } 136 }
138} 137}
139 138
140QString Package::name() 139QString OipkgPackage::name()
141{ 140{
142 if (_displayName.isEmpty() ) return _name; 141 if (_displayName.isEmpty() ) return _name;
143 else return _displayName; 142 else return _displayName;
144} 143}
145 144
146 145
147QString Package::installName() 146QString OipkgPackage::installName()
148{ 147{
149 if (_useFileName) return _fileName; 148 if (_useFileName) return _fileName;
150 else return _name; 149 else return _name;
151} 150}
152 151
153QString Package::packageName() 152QString OipkgPackage::packageName()
154{ 153{
155 QString pn = installName(); 154 QString pn = installName();
156 pn = pn.right(pn.length()-pn.findRev("/")); 155 pn = pn.right(pn.length()-pn.findRev("/"));
157 pn = pn.left(pn.find("_")); 156 pn = pn.left(pn.find("_"));
158 return pn; 157 return pn;
159} 158}
160 159
161bool Package::installed() 160bool OipkgPackage::installed()
162{ 161{
163 if (_status.contains("installed")) 162 if (_status.contains("installed"))
164 { 163 {
165 if (_status.contains("not-installed")) 164 if (_status.contains("not-installed"))
166 { 165 {
167 _toProcess = true; 166 _toProcess = true;
168 return false; 167 return false;
169 } 168 }
170 else return true; 169 else return true;
171 } 170 }
172 else 171 else
173 if (_versions) 172 if (_versions)
174 { 173 {
175 QDictIterator<Package> other( *_versions ); 174 QDictIterator<OipkgPackage> other( *_versions );
176 while ( other.current() ) 175 while ( other.current() )
177 { 176 {
178 if (other.current()->status().contains("installed") 177 if (other.current()->status().contains("installed")
179 && other.current()->version() == version()) 178 && other.current()->version() == version())
180 return true; 179 return true;
181 ++other; 180 ++other;
182 } 181 }
183 } 182 }
184 return false; 183 return false;
185} 184}
186 185
187bool Package::otherInstalled() 186bool OipkgPackage::otherInstalled()
188{ 187{
189 if (_versions) 188 if (_versions)
190 { 189 {
191 QDictIterator<Package> other( *_versions ); 190 QDictIterator<OipkgPackage> other( *_versions );
192 while ( other.current() ) 191 while ( other.current() )
193 { 192 {
194 if (other.current()->installed()) return true; 193 if (other.current()->installed()) return true;
195 ++other; 194 ++other;
196 } 195 }
197 } 196 }
198 return false; 197 return false;
199} 198}
200 199
201void Package::setDesc( QString s ) 200void OipkgPackage::setDesc( QString s )
202{ 201{
203 _desc = s; 202 _desc = s;
204 _shortDesc = s.left( s.find("\n") ); 203 _shortDesc = s.left( s.find("\n") );
205} 204}
206 205
207QString Package::desc() 206QString OipkgPackage::desc()
208{ 207{
209 return _desc; 208 return _desc;
210} 209}
211 210
212QString Package::shortDesc() 211QString OipkgPackage::shortDesc()
213{ 212{
214 return _shortDesc; 213 return _shortDesc;
215} 214}
216 215
217QString Package::size() 216QString OipkgPackage::size()
218{ 217{
219 return _size; 218 return _size;
220} 219}
221 220
222 221
223QString Package::version() 222QString OipkgPackage::version()
224{ 223{
225 return _version; 224 return _version;
226} 225}
227 226
228QString Package::sizeUnits() 227QString OipkgPackage::sizeUnits()
229{ 228{
230 int i = _size.toInt(); 229 int i = _size.toInt();
231 int c = 0; 230 int c = 0;
232 QString ret; 231 QString ret;
233 QStringList unit; 232 QStringList unit;
234 unit << "B" << "KB" << "MB" << "GB" << "TB"; //prepair for the future ;) 233 unit << "B" << "KB" << "MB" << "GB" << "TB"; //prepair for the future ;)
235 while (i > 1) 234 while (i > 1)
236 { 235 {
237 ret=QString::number(i)+" "+unit[c]; 236 ret=QString::number(i)+" "+unit[c];
238 c++; 237 c++;
239 i /= 1024; 238 i /= 1024;
240 } 239 }
241 return ret; 240 return ret;
242} 241}
243 242
244bool Package::toProcess() 243bool OipkgPackage::toProcess()
245{ 244{
246 return _toProcess; 245 return _toProcess;
247} 246}
248 247
249bool Package::toRemove() 248bool OipkgPackage::toRemove()
250{ 249{
251 if ( _toProcess && installed() ) return true; 250 if ( _toProcess && installed() ) return true;
252 else return false; 251 else return false;
253} 252}
254 253
255bool Package::toInstall() 254bool OipkgPackage::toInstall()
256{ 255{
257 if ( _toProcess && !installed() ) return true; 256 if ( _toProcess && !installed() ) return true;
258 else return false; 257 else return false;
259} 258}
260 259
261void Package::toggleProcess() 260void OipkgPackage::toggleProcess()
262{ 261{
263 _toProcess = ! _toProcess; 262 _toProcess = ! _toProcess;
264} 263}
265 264
266 265
267 266void OipkgPackage::copyValues( OipkgPackage* pack )
268void Package::copyValues( Package* pack )
269{ 267{
270 if (_size.isEmpty() && !pack->_size.isEmpty()) _size = QString( pack->_size ); 268 if (_size.isEmpty() && !pack->_size.isEmpty()) _size = QString( pack->_size );
271 if (_section.isEmpty() && !pack->_section.isEmpty()) _section = QString( pack->_section ); 269 if (_section.isEmpty() && !pack->_section.isEmpty()) _section = QString( pack->_section );
272 if (_subsection.isEmpty()&& !pack->_subsection.isEmpty()) _subsection = QString( pack->_subsection ); 270 if (_subsection.isEmpty()&& !pack->_subsection.isEmpty()) _subsection = QString( pack->_subsection );
273 if (_shortDesc.isEmpty() && !pack->_shortDesc.isEmpty()) _shortDesc = QString( pack->_shortDesc ); 271 if (_shortDesc.isEmpty() && !pack->_shortDesc.isEmpty()) _shortDesc = QString( pack->_shortDesc );
274 if (_desc.isEmpty() && !pack->_desc.isEmpty()) _desc = QString( pack->_desc ); 272 if (_desc.isEmpty() && !pack->_desc.isEmpty()) _desc = QString( pack->_desc );
275 if (_name.isEmpty() && !pack->_name.isEmpty()) _name = QString( pack->_name ); 273 if (_name.isEmpty() && !pack->_name.isEmpty()) _name = QString( pack->_name );
276 if (_dest.isEmpty() && !pack->_dest.isEmpty()) _dest= QString( pack->_dest ); 274 if (_dest.isEmpty() && !pack->_dest.isEmpty()) _dest= QString( pack->_dest );
277 if (_displayName.isEmpty()&& !pack->_displayName.isEmpty()) _displayName = QString( pack->_displayName ); 275 if (_displayName.isEmpty()&& !pack->_displayName.isEmpty()) _displayName = QString( pack->_displayName );
278 if (_fileName.isEmpty() && !pack->_fileName.isEmpty()) _fileName = QString( pack->_fileName ); 276 if (_fileName.isEmpty() && !pack->_fileName.isEmpty()) _fileName = QString( pack->_fileName );
279 if (_version.isEmpty() && !pack->_version.isEmpty()) _version = QString( pack->_version ); 277 if (_version.isEmpty() && !pack->_version.isEmpty()) _version = QString( pack->_version );
280 if (_values.isEmpty() && !pack->_values.isEmpty())_values = QDict<QString>( pack->_values ); 278 if (_values.isEmpty() && !pack->_values.isEmpty())_values = QDict<QString>( pack->_values );
281 if (!installed() && _status.isEmpty() && !pack->_status.isEmpty()) _status = QString( pack->_status ); 279 if (!installed() && _status.isEmpty() && !pack->_status.isEmpty()) _status = QString( pack->_status );
282} 280}
283 281
284QString Package::section() 282QString OipkgPackage::section()
285{ 283{
286 return _section; 284 return _section;
287} 285}
288 286
289void Package::setSection( QString s) 287void OipkgPackage::setSection( QString s)
290{ 288{
291 int i = s.find("/"); 289 int i = s.find("/");
292 if ( i > 0 ) 290 if ( i > 0 )
293 { 291 {
294 _section = s.left(i); 292 _section = s.left(i);
295 _subsection = s.mid(i+1); 293 _subsection = s.mid(i+1);
296 }else{ 294 }else{
297 _section = s; 295 _section = s;
298 _subsection = ""; 296 _subsection = "";
299 } 297 }
300} 298}
301 299
302QString Package::subSection() 300QString OipkgPackage::subSection()
303{ 301{
304 return _subsection; 302 return _subsection;
305} 303}
306 304
307void Package::parsePackage( QStringList pack ) 305void OipkgPackage::parsePackage( QStringList pack )
308{ 306{
309 if ( pack.isEmpty() ) return; 307 if ( pack.isEmpty() ) return;
310 int count = pack.count(); 308 int count = pack.count();
311 for( int i = 0; i < count; i++ ) 309 for( int i = 0; i < count; i++ )
312 { 310 {
313 QString line = pack[i]; 311 QString line = pack[i];
314 int sep = line.find( QRegExp(":[\t ]+") ); 312 int sep = line.find( QRegExp(":[\t ]+") );
315 if ( sep >= 0 ) 313 if ( sep >= 0 )
316 { 314 {
317 QString tag = line.left(sep); 315 QString tag = line.left(sep);
318 QString value = line.mid(sep+2).simplifyWhiteSpace(); 316 QString value = line.mid(sep+2).simplifyWhiteSpace();
319 setValue( tag, value ); 317 setValue( tag, value );
320 }else{ 318 }else{
321 } 319 }
322 } 320 }
323 return; 321 return;
324} 322}
325 323
326QString Package::details() 324QString OipkgPackage::details()
327{ 325{
328 QString status; 326 QString status;
329 Process ipkg_status(QStringList() << "ipkg" << "info" << name() ); 327 Process ipkg_status(QStringList() << "ipkg" << "info" << name() );
330 QString description; 328 QString description;
331 if ( ipkg_status.exec("",status) ) 329 if ( ipkg_status.exec("",status) )
332 { 330 {
333 QStringList lines = QStringList::split('\n',status,TRUE); 331 QStringList lines = QStringList::split('\n',status,TRUE);
334 for (QStringList::Iterator it = lines.begin(); it!=lines.end(); ++it) { 332 for (QStringList::Iterator it = lines.begin(); it!=lines.end(); ++it) {
335 QString line = *it; 333 QString line = *it;
336 if ( line == " ." ) 334 if ( line == " ." )
337 { 335 {
338 description.append("<p>"); 336 description.append("<p>");
@@ -353,62 +351,62 @@ QString Package::details()
353 description.append(":</b> "); 351 description.append(":</b> ");
354 description.append(Qtopia::escapeString(line.mid(sep+2))); 352 description.append(Qtopia::escapeString(line.mid(sep+2)));
355 } else { 353 } else {
356 description.append(" "); 354 description.append(" ");
357 description.append(Qtopia::escapeString(line)); 355 description.append(Qtopia::escapeString(line));
358 } 356 }
359 } 357 }
360 } 358 }
361 } 359 }
362 return description; 360 return description;
363} 361}
364 362
365void Package::processed() 363void OipkgPackage::processed()
366{ 364{
367 _toProcess = false; 365 _toProcess = false;
368 //hack, but we're not writing status anyway... 366 //hack, but we're not writing status anyway...
369 if ( installed() ) _status = "install"; 367 if ( installed() ) _status = "install";
370 else _status = "installed"; 368 else _status = "installed";
371} 369}
372 370
373QString Package::dest() 371QString OipkgPackage::dest()
374{ 372{
375 if ( installed()||(!installed() && _toProcess) ) 373 if ( installed()||(!installed() && _toProcess) )
376 return _dest!=""?_dest:settings->getDestinationName(); 374 return _dest!=""?_dest:settings->getDestinationName();
377 else return ""; 375 else return "";
378} 376}
379 377
380void Package::setDest( QString d ) 378void OipkgPackage::setDest( QString d )
381{ 379{
382 if ( d == "remote") _useFileName = true; 380 if ( d == "remote") _useFileName = true;
383 else _dest = d; 381 else _dest = d;
384} 382}
385 383
386void Package::setOn() 384void OipkgPackage::setOn()
387{ 385{
388 _toProcess = true; 386 _toProcess = true;
389} 387}
390 388
391bool Package::link() 389bool OipkgPackage::link()
392{ 390{
393 if ( _dest == "root" || (!installed() && !_toProcess) ) return false; 391 if ( _dest == "root" || (!installed() && !_toProcess) ) return false;
394 return _link; 392 return _link;
395} 393}
396 394
397void Package::setLink(bool b) 395void OipkgPackage::setLink(bool b)
398{ 396{
399 _link = b; 397 _link = b;
400} 398}
401 399
402void Package::parseIpkgFile( QString file) 400void OipkgPackage::parseIpkgFile( QString file)
403{ 401{
404// 20020830 402// 20020830
405// a quick hack to make oipkg understand the new ipk format 403// a quick hack to make oipkg understand the new ipk format
406// neu: ar pf PACKAGE control.tar.gz | tar xfOz - ./control > /tmp/control 404// neu: ar pf PACKAGE control.tar.gz | tar xfOz - ./control > /tmp/control
407 if (system("ar pf "+file+" control.tar.gz | tar xfOz - ./control > /tmp/control") != 0) 405 if (system("ar pf "+file+" control.tar.gz | tar xfOz - ./control > /tmp/control") != 0)
408 { 406 {
409//#old tar ipk format 407//#old tar ipk format
410 system("tar xzf "+file+" -C /tmp"); 408 system("tar xzf "+file+" -C /tmp");
411 system("tar xzf /tmp/control.tar.gz -C /tmp"); 409 system("tar xzf /tmp/control.tar.gz -C /tmp");
412 } 410 }
413 QFile f("/tmp/control"); 411 QFile f("/tmp/control");
414 if ( f.open(IO_ReadOnly) ) 412 if ( f.open(IO_ReadOnly) )
@@ -416,64 +414,64 @@ void Package::parseIpkgFile( QString file)
416 QTextStream t( &f ); 414 QTextStream t( &f );
417 QStringList pack; 415 QStringList pack;
418 while ( !t.eof() ) 416 while ( !t.eof() )
419 { 417 {
420 pack << t.readLine(); 418 pack << t.readLine();
421 } 419 }
422 f.close(); 420 f.close();
423 parsePackage( pack ); 421 parsePackage( pack );
424 } 422 }
425 423
426} 424}
427 425
428//QString Package::getPackageName() 426//QString OipkgPackage::getPackageName()
429//{ 427//{
430 //if ( _packageName.isEmpty() ) return _name; 428 //if ( _packageName.isEmpty() ) return _name;
431 //else return _packageName; 429 //else return _packageName;
432//} 430//}
433 431
434void Package::instalFromFile(bool iff) 432void OipkgPackage::instalFromFile(bool iff)
435{ 433{
436 _useFileName = iff; 434 _useFileName = iff;
437} 435}
438 436
439void Package::setName(QString n) 437void OipkgPackage::setName(QString n)
440{ 438{
441 _displayName = n; 439 _displayName = n;
442} 440}
443 441
444QDict<QString>* Package::getFields() 442QDict<QString>* OipkgPackage::getFields()
445{ 443{
446 return &_values; 444 return &_values;
447} 445}
448 446
449QString Package::status() 447QString OipkgPackage::status()
450{ 448{
451 return _status; 449 return _status;
452} 450}
453 451
454bool Package::isOld() 452bool OipkgPackage::isOld()
455{ 453{
456 if (!_versions) return false; 454 if (!_versions) return false;
457 QDictIterator<Package> other( *_versions ); 455 QDictIterator<OipkgPackage> other( *_versions );
458 while ( other.current() ) { 456 while ( other.current() ) {
459 if (other.current()->version() > version() ) return true; 457 if (other.current()->version() > version() ) return true;
460 ++other; 458 ++other;
461 } 459 }
462 return false; 460 return false;
463} 461}
464 462
465bool Package::hasVersions() 463bool OipkgPackage::hasVersions()
466{ 464{
467 if (!_versions) return false; 465 if (!_versions) return false;
468 else return true; 466 else return true;
469} 467}
470 468
471QDict<Package>* Package::getOtherVersions() 469QDict<OipkgPackage>* OipkgPackage::getOtherVersions()
472{ 470{
473 return _versions; 471 return _versions;
474} 472}
475 473
476void Package::setOtherVersions(QDict<Package> *v) 474void OipkgPackage::setOtherVersions(QDict<OipkgPackage> *v)
477{ 475{
478 _versions=v; 476 _versions=v;
479} 477}