From d510e5a69762c8452b9d7b3d8122bc9fa85ed8b3 Mon Sep 17 00:00:00 2001 From: tille Date: Sat, 04 May 2002 17:12:04 +0000 Subject: popen thanks to ljp but still does not work from the launcher but only from the command line --- diff --git a/noncore/unsupported/oipkg/main.cpp b/noncore/unsupported/oipkg/main.cpp index d98bcaa..bb3d1db 100644 --- a/noncore/unsupported/oipkg/main.cpp +++ b/noncore/unsupported/oipkg/main.cpp @@ -3,7 +3,7 @@ #include #include -#include +//#include int debugLevel; int main( int argc, char ** argv ) @@ -17,8 +17,8 @@ int main( int argc, char ** argv ) } QPEApplication a( argc, argv ); MainWindow mw; - if (argc > 2) - QMessageBox::information( &mw, "oipkg","While ipkg is working\noipkg is hanging.\nPlease be patient!"); +// if (argc > 2) +// QMessageBox::information( &mw, "oipkg","While ipkg is working\noipkg is hanging.\nPlease be patient!"); a.showMainDocumentWidget( &mw ); return a.exec(); } diff --git a/noncore/unsupported/oipkg/mainwindow.cpp b/noncore/unsupported/oipkg/mainwindow.cpp index 55f915d..2fa91e3 100644 --- a/noncore/unsupported/oipkg/mainwindow.cpp +++ b/noncore/unsupported/oipkg/mainwindow.cpp @@ -93,8 +93,8 @@ void MainWindow::makeMenu() // menuBar->insertItem( tr( "Sections" ), sectMenu ); QLabel *spacer = new QLabel( "", toolBar ); - spacer->setBackgroundColor( toolBar->backgroundColor() ); - toolBar->setStretchableWidget( spacer ); +// spacer->setBackgroundColor( toolBar->backgroundColor() ); +// toolBar->setStretchableWidget( spacer ); runAction = new QAction( tr( "Apply" ), 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 @@ #include #include #include +#include #include #include #include @@ -37,19 +38,11 @@ PmIpkg::~PmIpkg() { } -//#define PROC -#define SYSTEM -#define QT_QPROCESS_DEBUG -int PmIpkg::runIpkg(const QString& args, const QString& dest ) +bool PmIpkg::runIpkg(const QString& args, const QString& dest ) { - pvDebug(2,"PmIpkg::runIpkg "+args); + bool ret=false; QDir::setCurrent("/tmp"); -#ifdef PROC - QString cmd; -#endif -#ifdef SYSTEM QString cmd = "/usr/bin/ipkg "; -#endif pvDebug( 3,"PmIpkg::runIpkg got dest="+dest); if ( dest == "" ) cmd += " -dest "+settings->getDestinationName(); @@ -68,42 +61,38 @@ int PmIpkg::runIpkg(const QString& args, const QString& dest ) cmd += " -force-removal-of-essential-packages "; } - out( "

Starting to "+ args+"
\n"); + out( "Starting to "+ args+"\n"); cmd += args; - int r = 0; -#ifdef PROC - QString o = "start"; - Process *ipkg = new Process(QStringList() << "ipkg" << cmd ); - out( "running:
\n"+ipkg->arguments().join(" ")+"
\n" ); - QString description; - r = ipkg->exec("",o); - out( o ); -#endif -#ifdef SYSTEM - out( "running:
\n"+cmd+"
\n" ); - QString redirect = "/tmp/oipkg.pipe"; - cmd += " 2>&1 | tee "+redirect+" 2>&1"; - pvDebug(2, "running >"+cmd+"<"); - r = system(cmd.latin1()); - QFile f( redirect ); - QString line; - QString oldLine; - while ( ! f.open(IO_ReadOnly) ) {}; - QTextStream t( &f ); - while ( !t.eof() ) - { - line = t.readLine(); - if ( line != oldLine ) - { - out( line +"
" ); - oldLine = line; - } - } - f.close(); - out( "Finished!
"); -#endif - - return r; + out( "running:\n"+cmd+"\n" ); + pvDebug(2,"running:"+cmd); + qApp->processEvents(); + FILE *fp; + char line[130]; + QString lineStr, lineStrOld; + sleep(1); + cmd +=" 2>&1"; + fp = popen( (const char *) cmd, "r"); + if ( !fp ) { + qDebug("Could not execute '" + cmd + "'! err=%d", fp); + pclose(fp); + out("\nError while executing "+ cmd+"\n\n"); + return false; + } else { + while ( fgets( line, sizeof line, fp)) { + lineStr = line; + lineStr=lineStr.left(lineStr.length()-1); + //Configuring opie-oipkg...Done + if (lineStr.contains("Done")) + ret = true; + if (lineStr!=lineStrOld) + out(lineStr); + lineStrOld = lineStr; + } + pclose(fp); + } + //out( "Finished!"); + pvDebug(2,QString(ret?"success\n":"failure\n")); + return ret; } void PmIpkg::makeLinks(Package *pack) @@ -127,7 +116,7 @@ QStringList* PmIpkg::getList( QString packFileName, QString d ) if ( ! f.open(IO_ReadOnly) ) { pvDebug(1," Panik! Could not open"); - out( "Panik! Could not open:
"+packFileName ); + out( "Panik!\n Could not open:\n"+packFileName ); return (QStringList*)0; } QStringList *fileList = new QStringList(); @@ -243,15 +232,18 @@ void PmIpkg::commit() runwindow->progress->setTotalSteps(sizecount); qDebug("Install size %i",sizecount); installDialog->showMaximized(); + installDialog->show(); if ( installDialog->exec() ) doIt(); installDialog->close(); runwindow->showMaximized(); - out(tr("All done.")); + runwindow->show(); + out(tr("\nAll done.")); } void PmIpkg::doIt() { - show( true ); + runwindow->progress->setProgress(0); + show(); remove(); install(); } @@ -261,59 +253,59 @@ void PmIpkg::remove() { if ( to_remove.count() == 0 ) return; - out(""+tr("Removing")+"
"+tr("please wait")+"


"); + out(tr("Removing")+"\n"+tr("please wait")+"\n\n"); QStringList *fileList; for (uint i=0; i < to_remove.count(); i++) { if ( to_remove.at(i)->link() )fileList = getList( to_remove.at(i)->name(), to_remove.at(i)->dest() ); - if ( runIpkg("remove " + to_remove.at(i)->name(), to_remove.at(i)->dest() ) == 0) + if ( runIpkg("remove " + to_remove.at(i)->name(), to_remove.at(i)->dest() )) { runwindow->progress->setProgress( 1 ); linkOpp = removeLink; if ( to_remove.at(i)->link() ) { - out( "
removing links
" ); - out( "for package "+to_remove.at(i)->name()+" in "+to_remove.at(i)->dest()+"
" ); + out( "\nremoving links\n" ); + out( "for package "+to_remove.at(i)->name()+" in "+to_remove.at(i)->dest()+"\n" ); processFileList( fileList, to_remove.at(i)->dest() ); } to_remove.at(i)->processed(); to_remove.take( i ); - out("

"); + out("\n\n"); }else{ - out(""+tr("Error while removing")+"
"+to_remove.at(i)->name()); + out(tr("Error while removing")+to_remove.at(i)->name()+"\n"); } if ( to_remove.at(i)->link() )delete fileList; } to_remove.clear(); - out("
"); + out("\n"); } void PmIpkg::install() { if ( to_install.count() == 0 ) return; - out(""+tr("Installing")+"
"+tr("please wait")+"

"); + out(tr("Installing")+"\n"+tr("please wait")+"\n"); for (uint i=0; i < to_install.count(); i++) { - if ( runIpkg("install " + to_install.at(i)->installName(), to_install.at(i)->dest() ) == 0 ) + if ( runIpkg("install " + to_install.at(i)->installName(), to_install.at(i)->dest() )) { runwindow->progress->setProgress( to_install.at(i)->size().toInt() + runwindow->progress->progress()); linkOpp = createLink; if ( to_install.at(i)->link() ) { - out( "
creating links
" ); - out( "for package "+to_install.at(i)->name()+" in "+to_install.at(i)->dest()+"
" ); + out( "\ncreating links\n" ); + out( "for package "+to_install.at(i)->name()+" in "+to_install.at(i)->dest()+"\n" ); makeLinks( to_install.at(i) ); } to_install.at(i)->processed(); to_install.take( i ); - out("

"); + out("\n\n"); }else{ - out(""+tr("Error while installing")+"
"+to_install.at(i)->name()); + out(tr("Error while installing")+to_install.at(i)->name()+"\n"); } } - out("
"); + out("\n"); to_install.clear(); } @@ -339,7 +331,7 @@ void PmIpkg::removeLinks( const QString &dest ) void PmIpkg::update() { - show( false ); + show(); runIpkg( "update" ); runwindow->close(); } @@ -347,38 +339,25 @@ void PmIpkg::update() void PmIpkg::out( QString o ) { runwindow->outPut->append(o); - //runwindow->outPut->setCursorPosition(0, runwindow->outPut->contentsHeight()); -// runwindow->outPut->setText( runwindow->outPut->text()+o ); - runwindow->outPut->setContentsPos(0, runwindow->outPut->contentsHeight()); + runwindow->outPut->setCursorPosition(runwindow->outPut->numLines() + 1,0,FALSE); } -void PmIpkg::showButtons(bool b) -{ - if ( b ) - { - runwindow->cancelButton->hide(); - runwindow->doItButton->hide(); - runwindow->removeButton->hide(); - runwindow->installButton->hide(); - }else{ - runwindow->cancelButton->show(); - runwindow->doItButton->show(); - runwindow->removeButton->show(); - runwindow->installButton->show(); - } -} -void PmIpkg::show(bool b) +void PmIpkg::show() { if (!runwindow->isVisible()) + { runwindow->showMaximized(); - showButtons(b); - if ( !b ) - runwindow->progress->hide(); - else - runwindow->progress->show(); + runwindow->show(); + } + runwindow->outPut->setText(""); +// showButtons(b); +// if ( !b ) +// runwindow->progress->hide(); +// else +// runwindow->progress->show(); } void PmIpkg::installFile(const QString &fileName, const QString &dest) diff --git a/noncore/unsupported/oipkg/pmipkg.h b/noncore/unsupported/oipkg/pmipkg.h index 7bc62f1..f8ac39a 100644 --- a/noncore/unsupported/oipkg/pmipkg.h +++ b/noncore/unsupported/oipkg/pmipkg.h @@ -27,8 +27,7 @@ public: void loadList( PackageList* ); void commit(); void update(); - void showButtons(bool b=true); - void show( bool buttons=true ); + void show(); public slots: void doIt(); @@ -53,7 +52,7 @@ private: void makeLinks(Package*); void linkPackage( QString, QString ); void processLinkDir( QString , QString ); - int runIpkg(const QString& args, const QString& dest="" ); + bool runIpkg(const QString& args, const QString& dest="" ); void out( QString ); QStringList* getList( QString, QString ); void processFileList( QStringList*, QString ); diff --git a/noncore/unsupported/oipkg/runwindow.ui b/noncore/unsupported/oipkg/runwindow.ui index 8582ce8..839e151 100644 --- a/noncore/unsupported/oipkg/runwindow.ui +++ b/noncore/unsupported/oipkg/runwindow.ui @@ -11,7 +11,7 @@ 0 0 - 344 + 340 442 @@ -45,116 +45,8 @@ 0 - - QLayoutWidget - - name - buttons - - - - margin - 0 - - - spacing - 6 - - - QPushButton - - name - doItButton - - - sizePolicy - - 0 - 0 - - - - font - - 8 - - - - text - Do all - - - autoResize - false - - - - QPushButton - - name - installButton - - - font - - 8 - - - - text - Install - - - autoResize - true - - - - QPushButton - - name - removeButton - - - font - - 7 - - - - text - Remove - - - autoResize - true - - - - QPushButton - - name - cancelButton - - - font - - 8 - - - - text - Cancel - - - autoResize - true - - - - - QTextView + QMultiLineEdit name outPut @@ -162,9 +54,13 @@ font - 6 + 8 + + wordWrap + WidgetWidth + -- cgit v0.9.0.2