summaryrefslogtreecommitdiff
path: root/noncore/unsupported/oipkg/pmipkg.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/oipkg/pmipkg.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/unsupported/oipkg/pmipkg.cpp149
1 files changed, 64 insertions, 85 deletions
diff --git a/noncore/unsupported/oipkg/pmipkg.cpp b/noncore/unsupported/oipkg/pmipkg.cpp
index 5996e63..75f93cf 100644
--- a/noncore/unsupported/oipkg/pmipkg.cpp
+++ b/noncore/unsupported/oipkg/pmipkg.cpp
@@ -7,6 +7,7 @@
7#include <qpe/resource.h> 7#include <qpe/resource.h>
8#include <qpe/config.h> 8#include <qpe/config.h>
9#include <qpe/stringutil.h> 9#include <qpe/stringutil.h>
10#include <qpe/qpeapplication.h>
10#include <qdir.h> 11#include <qdir.h>
11#include <qfile.h> 12#include <qfile.h>
12#include <qgroupbox.h> 13#include <qgroupbox.h>
@@ -37,19 +38,11 @@ PmIpkg::~PmIpkg()
37{ 38{
38} 39}
39 40
40//#define PROC 41bool PmIpkg::runIpkg(const QString& args, const QString& dest )
41#define SYSTEM
42#define QT_QPROCESS_DEBUG
43int PmIpkg::runIpkg(const QString& args, const QString& dest )
44{ 42{
45 pvDebug(2,"PmIpkg::runIpkg "+args); 43 bool ret=false;
46 QDir::setCurrent("/tmp"); 44 QDir::setCurrent("/tmp");
47#ifdef PROC
48 QString cmd;
49#endif
50#ifdef SYSTEM
51 QString cmd = "/usr/bin/ipkg "; 45 QString cmd = "/usr/bin/ipkg ";
52#endif
53 pvDebug( 3,"PmIpkg::runIpkg got dest="+dest); 46 pvDebug( 3,"PmIpkg::runIpkg got dest="+dest);
54 if ( dest == "" ) 47 if ( dest == "" )
55 cmd += " -dest "+settings->getDestinationName(); 48 cmd += " -dest "+settings->getDestinationName();
@@ -68,42 +61,38 @@ int PmIpkg::runIpkg(const QString& args, const QString& dest )
68 cmd += " -force-removal-of-essential-packages "; 61 cmd += " -force-removal-of-essential-packages ";
69 } 62 }
70 63
71 out( "<hr><br>Starting to "+ args+"<br>\n"); 64 out( "Starting to "+ args+"\n");
72 cmd += args; 65 cmd += args;
73 int r = 0; 66 out( "running:\n"+cmd+"\n" );
74#ifdef PROC 67 pvDebug(2,"running:"+cmd);
75 QString o = "start"; 68 qApp->processEvents();
76 Process *ipkg = new Process(QStringList() << "ipkg" << cmd ); 69 FILE *fp;
77 out( "running:<br>\n"+ipkg->arguments().join(" ")+"<br>\n" ); 70 char line[130];
78 QString description; 71 QString lineStr, lineStrOld;
79 r = ipkg->exec("",o); 72 sleep(1);
80 out( o ); 73 cmd +=" 2>&1";
81#endif 74 fp = popen( (const char *) cmd, "r");
82#ifdef SYSTEM 75 if ( !fp ) {
83 out( "running:<br>\n"+cmd+"<br>\n" ); 76 qDebug("Could not execute '" + cmd + "'! err=%d", fp);
84 QString redirect = "/tmp/oipkg.pipe"; 77 pclose(fp);
85 cmd += " 2>&1 | tee "+redirect+" 2>&1"; 78 out("\nError while executing "+ cmd+"\n\n");
86 pvDebug(2, "running >"+cmd+"<"); 79 return false;
87 r = system(cmd.latin1()); 80 } else {
88 QFile f( redirect ); 81 while ( fgets( line, sizeof line, fp)) {
89 QString line; 82 lineStr = line;
90 QString oldLine; 83 lineStr=lineStr.left(lineStr.length()-1);
91 while ( ! f.open(IO_ReadOnly) ) {}; 84 //Configuring opie-oipkg...Done
92 QTextStream t( &f ); 85 if (lineStr.contains("Done"))
93 while ( !t.eof() ) 86 ret = true;
94 { 87 if (lineStr!=lineStrOld)
95 line = t.readLine(); 88 out(lineStr);
96 if ( line != oldLine ) 89 lineStrOld = lineStr;
97 {
98 out( line +"<br>" );
99 oldLine = line;
100 } 90 }
91 pclose(fp);
101 } 92 }
102 f.close(); 93 //out( "Finished!");
103 out( "Finished!<br>"); 94 pvDebug(2,QString(ret?"success\n":"failure\n"));
104#endif 95 return ret;
105
106 return r;
107} 96}
108 97
109void PmIpkg::makeLinks(Package *pack) 98void PmIpkg::makeLinks(Package *pack)
@@ -127,7 +116,7 @@ QStringList* PmIpkg::getList( QString packFileName, QString d )
127 if ( ! f.open(IO_ReadOnly) ) 116 if ( ! f.open(IO_ReadOnly) )
128 { 117 {
129 pvDebug(1," Panik! Could not open"); 118 pvDebug(1," Panik! Could not open");
130 out( "<b>Panik!</b> Could not open:<br>"+packFileName ); 119 out( "Panik!\n Could not open:\n"+packFileName );
131 return (QStringList*)0; 120 return (QStringList*)0;
132 } 121 }
133 QStringList *fileList = new QStringList(); 122 QStringList *fileList = new QStringList();
@@ -243,15 +232,18 @@ void PmIpkg::commit()
243 runwindow->progress->setTotalSteps(sizecount); 232 runwindow->progress->setTotalSteps(sizecount);
244 qDebug("Install size %i",sizecount); 233 qDebug("Install size %i",sizecount);
245 installDialog->showMaximized(); 234 installDialog->showMaximized();
235 installDialog->show();
246 if ( installDialog->exec() ) doIt(); 236 if ( installDialog->exec() ) doIt();
247 installDialog->close(); 237 installDialog->close();
248 runwindow->showMaximized(); 238 runwindow->showMaximized();
249 out(tr("<b>All done.</b>")); 239 runwindow->show();
240 out(tr("\nAll done."));
250} 241}
251 242
252void PmIpkg::doIt() 243void PmIpkg::doIt()
253{ 244{
254 show( true ); 245 runwindow->progress->setProgress(0);
246 show();
255 remove(); 247 remove();
256 install(); 248 install();
257} 249}
@@ -261,59 +253,59 @@ void PmIpkg::remove()
261{ 253{
262 if ( to_remove.count() == 0 ) return; 254 if ( to_remove.count() == 0 ) return;
263 255
264 out("<b>"+tr("Removing")+"<br>"+tr("please wait")+"</b><br><hr>"); 256 out(tr("Removing")+"\n"+tr("please wait")+"\n\n");
265 257
266 QStringList *fileList; 258 QStringList *fileList;
267 for (uint i=0; i < to_remove.count(); i++) 259 for (uint i=0; i < to_remove.count(); i++)
268 { 260 {
269 if ( to_remove.at(i)->link() )fileList = getList( to_remove.at(i)->name(), to_remove.at(i)->dest() ); 261 if ( to_remove.at(i)->link() )fileList = getList( to_remove.at(i)->name(), to_remove.at(i)->dest() );
270 if ( runIpkg("remove " + to_remove.at(i)->name(), to_remove.at(i)->dest() ) == 0) 262 if ( runIpkg("remove " + to_remove.at(i)->name(), to_remove.at(i)->dest() ))
271 { 263 {
272 runwindow->progress->setProgress( 1 ); 264 runwindow->progress->setProgress( 1 );
273 linkOpp = removeLink; 265 linkOpp = removeLink;
274 if ( to_remove.at(i)->link() ) 266 if ( to_remove.at(i)->link() )
275 { 267 {
276 out( "<br>removing links<br>" ); 268 out( "\nremoving links\n" );
277 out( "for package "+to_remove.at(i)->name()+" in "+to_remove.at(i)->dest()+"<br>" ); 269 out( "for package "+to_remove.at(i)->name()+" in "+to_remove.at(i)->dest()+"\n" );
278 processFileList( fileList, to_remove.at(i)->dest() ); 270 processFileList( fileList, to_remove.at(i)->dest() );
279 } 271 }
280 to_remove.at(i)->processed(); 272 to_remove.at(i)->processed();
281 to_remove.take( i ); 273 to_remove.take( i );
282 out("<br><hr>"); 274 out("\n\n");
283 }else{ 275 }else{
284 out("<b>"+tr("Error while removing")+"</b><hr>"+to_remove.at(i)->name()); 276 out(tr("Error while removing")+to_remove.at(i)->name()+"\n");
285 } 277 }
286 if ( to_remove.at(i)->link() )delete fileList; 278 if ( to_remove.at(i)->link() )delete fileList;
287 } 279 }
288 to_remove.clear(); 280 to_remove.clear();
289 out("<br>"); 281 out("\n");
290} 282}
291 283
292 284
293void PmIpkg::install() 285void PmIpkg::install()
294{ 286{
295 if ( to_install.count() == 0 ) return; 287 if ( to_install.count() == 0 ) return;
296 out("<b>"+tr("Installing")+"<br>"+tr("please wait")+"</b><br>"); 288 out(tr("Installing")+"\n"+tr("please wait")+"\n");
297 for (uint i=0; i < to_install.count(); i++) 289 for (uint i=0; i < to_install.count(); i++)
298 { 290 {
299 if ( runIpkg("install " + to_install.at(i)->installName(), to_install.at(i)->dest() ) == 0 ) 291 if ( runIpkg("install " + to_install.at(i)->installName(), to_install.at(i)->dest() ))
300 { 292 {
301 runwindow->progress->setProgress( to_install.at(i)->size().toInt() + runwindow->progress->progress()); 293 runwindow->progress->setProgress( to_install.at(i)->size().toInt() + runwindow->progress->progress());
302 linkOpp = createLink; 294 linkOpp = createLink;
303 if ( to_install.at(i)->link() ) 295 if ( to_install.at(i)->link() )
304 { 296 {
305 out( "<br>creating links<br>" ); 297 out( "\ncreating links\n" );
306 out( "for package "+to_install.at(i)->name()+" in "+to_install.at(i)->dest()+"<br>" ); 298 out( "for package "+to_install.at(i)->name()+" in "+to_install.at(i)->dest()+"\n" );
307 makeLinks( to_install.at(i) ); 299 makeLinks( to_install.at(i) );
308 } 300 }
309 to_install.at(i)->processed(); 301 to_install.at(i)->processed();
310 to_install.take( i ); 302 to_install.take( i );
311 out("<br><hr>"); 303 out("\n\n");
312 }else{ 304 }else{
313 out("<b>"+tr("Error while installing")+"</b><hr>"+to_install.at(i)->name()); 305 out(tr("Error while installing")+to_install.at(i)->name()+"\n");
314 } 306 }
315 } 307 }
316 out("<br>"); 308 out("\n");
317 to_install.clear(); 309 to_install.clear();
318} 310}
319 311
@@ -339,7 +331,7 @@ void PmIpkg::removeLinks( const QString &dest )
339 331
340void PmIpkg::update() 332void PmIpkg::update()
341{ 333{
342 show( false ); 334 show();
343 runIpkg( "update" ); 335 runIpkg( "update" );
344 runwindow->close(); 336 runwindow->close();
345} 337}
@@ -347,38 +339,25 @@ void PmIpkg::update()
347void PmIpkg::out( QString o ) 339void PmIpkg::out( QString o )
348{ 340{
349 runwindow->outPut->append(o); 341 runwindow->outPut->append(o);
350 //runwindow->outPut->setCursorPosition(0, runwindow->outPut->contentsHeight()); 342 runwindow->outPut->setCursorPosition(runwindow->outPut->numLines() + 1,0,FALSE);
351 //runwindow->outPut->setText( runwindow->outPut->text()+o );
352 runwindow->outPut->setContentsPos(0, runwindow->outPut->contentsHeight());
353} 343}
354 344
355 345
356void PmIpkg::showButtons(bool b)
357{
358 if ( b )
359 {
360 runwindow->cancelButton->hide();
361 runwindow->doItButton->hide();
362 runwindow->removeButton->hide();
363 runwindow->installButton->hide();
364 }else{
365 runwindow->cancelButton->show();
366 runwindow->doItButton->show();
367 runwindow->removeButton->show();
368 runwindow->installButton->show();
369 346
370 }
371}
372 347
373void PmIpkg::show(bool b) 348void PmIpkg::show()
374{ 349{
375 if (!runwindow->isVisible()) 350 if (!runwindow->isVisible())
351 {
376 runwindow->showMaximized(); 352 runwindow->showMaximized();
377 showButtons(b); 353 runwindow->show();
378 if ( !b ) 354 }
379 runwindow->progress->hide(); 355 runwindow->outPut->setText("");
380 else 356 //showButtons(b);
381 runwindow->progress->show(); 357 //if ( !b )
358 // runwindow->progress->hide();
359// else
360 // runwindow->progress->show();
382} 361}
383 362
384void PmIpkg::installFile(const QString &fileName, const QString &dest) 363void PmIpkg::installFile(const QString &fileName, const QString &dest)