00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <stdio.h>
00031
00032 #include <opie2/ofiledialog.h>
00033 #include <opie2/oresource.h>
00034
00035 #include <qpe/config.h>
00036 #include <qpe/fileselector.h>
00037 #include <qpe/qpeapplication.h>
00038 #include <qpe/storage.h>
00039
00040 #include <qcheckbox.h>
00041 #include <qcombobox.h>
00042 #include <qdialog.h>
00043 #include <qfileinfo.h>
00044 #include <qgroupbox.h>
00045 #include <qmultilineedit.h>
00046 #include <qlabel.h>
00047 #include <qlayout.h>
00048 #include <qpushbutton.h>
00049
00050 #include "datamgr.h"
00051 #include "destination.h"
00052 #include "instoptionsimpl.h"
00053 #include "installdlgimpl.h"
00054 #include "ipkg.h"
00055 #include "utils.h"
00056 #include "global.h"
00057
00058 using namespace Opie::Ui;
00059 enum {
00060 MAXLINES = 100,
00061 };
00062
00063 InstallDlgImpl::InstallDlgImpl( const QList<InstallData> &packageList, DataManager *dataManager, const char *title )
00064 : QWidget( 0, 0, 0 )
00065 {
00066 setCaption( title );
00067 init( TRUE );
00068
00069 pIpkg = 0;
00070 upgradePackages = false;
00071 dataMgr = dataManager;
00072
00073 QString defaultDest = "root";
00074 #ifdef QWS
00075 Config cfg( "aqpkg" );
00076 cfg.setGroup( "settings" );
00077 defaultDest = cfg.readEntry( "dest", "root" );
00078
00079
00080 flags = cfg.readNumEntry( "installFlags", 0 );
00081 infoLevel = cfg.readNumEntry( "infoLevel", 1 );
00082 #else
00083 flags = 0;
00084 #endif
00085
00086
00087 output->setReadOnly( true );
00088
00089
00090
00091
00092
00093
00094 int defIndex = 0;
00095 int i;
00096 QListIterator<Destination> dit( dataMgr->getDestinationList() );
00097 for ( i = 0; dit.current(); ++dit, ++i )
00098 {
00099 destination->insertItem( dit.current()->getDestinationName() );
00100 if ( dit.current()->getDestinationName() == defaultDest )
00101 defIndex = i;
00102 }
00103
00104 destination->setCurrentItem( defIndex );
00105
00106 QListIterator<InstallData> it( packageList );
00107
00108 QString remove = tr( "Remove\n" );
00109 QString install = tr( "Install\n" );
00110 QString upgrade = tr( "Upgrade\n" );
00111 for ( ; it.current(); ++it )
00112 {
00113 InstallData *item = it.current();
00114 InstallData *newitem = new InstallData();
00115
00116 newitem->option = item->option;
00117 newitem->packageName = item->packageName;
00118 newitem->destination = item->destination;
00119 newitem->recreateLinks = item->recreateLinks;
00120 packages.append( newitem );
00121
00122 if ( item->option == "I" )
00123 {
00124 install.append( QString( " %1\n" ).arg( item->packageName ) );
00125 }
00126 else if ( item->option == "D" )
00127 {
00128 remove.append( QString( " %1\n" ).arg( item->packageName ) );
00129 }
00130 else if ( item->option == "U" || item->option == "R" )
00131 {
00132 QString type;
00133 if ( item->option == "R" )
00134 type = tr( "(ReInstall)" );
00135 else
00136 type = tr( "(Upgrade)" );
00137 upgrade.append( QString( " %1 %2\n" ).arg( item->packageName ).arg( type ) );
00138 }
00139 }
00140
00141 output->setText( QString( "%1\n%2\n%3\n" ).arg( remove ).arg( install ).arg( upgrade ) );
00142
00143 displayAvailableSpace( destination->currentText() );
00144 }
00145
00146 InstallDlgImpl::InstallDlgImpl( Ipkg *ipkg, QString initialText, const char *title )
00147 : QWidget( 0, 0, 0 )
00148 {
00149 setCaption( title );
00150 init( FALSE );
00151 pIpkg = ipkg;
00152 output->setText( initialText );
00153 }
00154
00155
00156 InstallDlgImpl::~InstallDlgImpl()
00157 {
00158 if ( pIpkg )
00159 delete pIpkg;
00160 }
00161
00162 void InstallDlgImpl :: init( bool displayextrainfo )
00163 {
00164 QGridLayout *layout = new QGridLayout( this );
00165 layout->setSpacing( 4 );
00166 layout->setMargin( 4 );
00167
00168 if ( displayextrainfo )
00169 {
00170 QLabel *label = new QLabel( tr( "Destination" ), this );
00171 layout->addWidget( label, 0, 0 );
00172 destination = new QComboBox( FALSE, this );
00173 layout->addWidget( destination, 0, 1 );
00174 connect( destination, SIGNAL( highlighted(const QString&) ),
00175 this, SLOT( displayAvailableSpace(const QString&) ) );
00176
00177 QLabel *label2 = new QLabel( tr( "Space Avail" ), this );
00178 layout->addWidget( label2, 1, 0 );
00179 txtAvailableSpace = new QLabel( "", this );
00180 layout->addWidget( txtAvailableSpace, 1, 1 );
00181 }
00182 else
00183 {
00184 destination = 0x0;
00185 txtAvailableSpace = 0x0;
00186 }
00187
00188 QGroupBox *GroupBox2 = new QGroupBox( 0, Qt::Vertical, tr( "Output" ), this );
00189 GroupBox2->layout()->setSpacing( 0 );
00190 GroupBox2->layout()->setMargin( 4 );
00191
00192 QVBoxLayout *GroupBox2Layout = new QVBoxLayout( GroupBox2->layout() );
00193 output = new QMultiLineEdit( GroupBox2 );
00194 GroupBox2Layout->addWidget( output );
00195 layout->addMultiCellWidget( GroupBox2, 2, 2, 0, 1 );
00196
00197 btnInstall = new QPushButton( Opie::Core::OResource::loadPixmap( "aqpkg/apply", Opie::Core::OResource::SmallIcon ), tr( "Start" ), this );
00198 layout->addWidget( btnInstall, 3, 0 );
00199 connect( btnInstall, SIGNAL( clicked() ), this, SLOT( installSelected() ) );
00200
00201 btnOptions = new QPushButton( Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ), tr( "Options" ), this );
00202 layout->addWidget( btnOptions, 3, 1 );
00203 connect( btnOptions, SIGNAL( clicked() ), this, SLOT( optionsSelected() ) );
00204 }
00205
00206 void InstallDlgImpl :: optionsSelected()
00207 {
00208 if ( btnOptions->text() == tr( "Options" ) )
00209 {
00210 InstallOptionsDlgImpl opt( flags, infoLevel, this, "Option", true );
00211 if ( opt.exec() == QDialog::Accepted )
00212 {
00213
00214 flags = opt.getFlags();
00215 infoLevel = opt.getInfoLevel();
00216
00217 #ifdef QWS
00218 Config cfg( "aqpkg" );
00219 cfg.setGroup( "settings" );
00220 cfg.writeEntry( "installFlags", flags );
00221 cfg.writeEntry( "infoLevel", infoLevel );
00222 #endif
00223 }
00224 }
00225 else
00226 {
00227 QMap<QString, QStringList> map;
00228 map.insert( tr( "All" ), QStringList() );
00229 QStringList text;
00230 text << "text/*";
00231 map.insert(tr( "Text" ), text );
00232 text << "*";
00233 map.insert( tr( "All" ), text );
00234
00235 QString filename = OFileDialog::getSaveFileName( 2, "/", "ipkg-output", map );
00236 if( !filename.isEmpty() )
00237 {
00238 QString currentFileName = QFileInfo( filename ).fileName();
00239 DocLnk doc;
00240 doc.setType( "text/plain" );
00241 doc.setFile( filename );
00242 doc.setName( currentFileName );
00243 FileManager fm;
00244 fm.saveFile( doc, output->text() );
00245 }
00246 }
00247 }
00248
00249 void InstallDlgImpl :: installSelected()
00250 {
00251 if ( btnInstall->text() == tr( "Abort" ) )
00252 {
00253 if ( pIpkg )
00254 {
00255 displayText( tr( "\n**** User Clicked ABORT ***" ) );
00256 pIpkg->abort();
00257 displayText( tr( "**** Process Aborted ****" ) );
00258 }
00259
00260 btnInstall->setText( tr( "Close" ) );
00261 btnInstall->setIconSet( Opie::Core::OResource::loadPixmap( "enter", Opie::Core::OResource::SmallIcon ) );
00262 return;
00263 }
00264 else if ( btnInstall->text() == tr( "Close" ) )
00265 {
00266 emit reloadData( this );
00267 return;
00268 }
00269
00270
00271 btnOptions->setEnabled( false );
00272
00273
00274 btnInstall->setText( tr( "Abort" ) );
00275 btnInstall->setIconSet( Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ) );
00276
00277 if ( pIpkg )
00278 {
00279 output->setText( "" );
00280 connect( pIpkg, SIGNAL(outputText(const QString&)), this, SLOT(displayText(const QString&)));
00281 connect( pIpkg, SIGNAL(ipkgFinished()), this, SLOT(ipkgFinished()));
00282 pIpkg->runIpkg();
00283 }
00284 else
00285 {
00286 output->setText( "" );
00287 Destination *d = dataMgr->getDestination( destination->currentText() );
00288 QString dest = d->getDestinationName();
00289 QString destDir = d->getDestinationPath();
00290 int instFlags = flags;
00291 if ( d->linkToRoot() )
00292 instFlags |= MAKE_LINKS;
00293
00294 #ifdef QWS
00295
00296 Config cfg( "aqpkg" );
00297 cfg.setGroup( "settings" );
00298 cfg.writeEntry( "dest", dest );
00299 #endif
00300
00301 pIpkg = new Ipkg;
00302 connect( pIpkg, SIGNAL(outputText(const QString&)), this, SLOT(displayText(const QString&)));
00303 connect( pIpkg, SIGNAL(ipkgFinished()), this, SLOT(ipkgFinished()));
00304
00305 firstPackage = TRUE;
00306 ipkgFinished();
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362 }
00363 }
00364
00365
00366 void InstallDlgImpl :: displayText(const QString &text )
00367 {
00368 QString newtext = QString( "%1\n%2" ).arg( output->text() ).arg( text );
00369
00370
00371
00372
00373 if(output->numLines() >= MAXLINES)
00374 output->removeLine(0);
00375 output->setText( newtext );
00376 output->setCursorPosition( output->numLines(), 0 );
00377 }
00378
00379
00380 void InstallDlgImpl :: displayAvailableSpace( const QString &text )
00381 {
00382 Destination *d = dataMgr->getDestination( text );
00383 QString destDir = d->getDestinationPath();
00384
00385 long blockSize = 0;
00386 long totalBlocks = 0;
00387 long availBlocks = 0;
00388 QString space;
00389 if ( Utils::getStorageSpace( (const char *)destDir, &blockSize, &totalBlocks, &availBlocks ) )
00390 {
00391 long mult = blockSize / 1024;
00392 long div = 1024 / blockSize;
00393
00394 if ( !mult ) mult = 1;
00395 if ( !div ) div = 1;
00396 long avail = availBlocks * mult / div;
00397
00398 space = tr( "%1 Kb" ).arg( avail );
00399 }
00400 else
00401 space = tr( "Unknown" );
00402
00403 if ( txtAvailableSpace )
00404 txtAvailableSpace->setText( space );
00405 }
00406
00407 void InstallDlgImpl :: ipkgFinished()
00408 {
00409 InstallData *item;
00410 if ( firstPackage )
00411 item = packages.first();
00412 else
00413 {
00414
00415 pIpkg->createSymLinks();
00416
00417 item = packages.next();
00418 }
00419
00420 firstPackage = FALSE;
00421 if ( item )
00422 {
00423 pIpkg->setPackage( item->packageName );
00424 int tmpFlags = flags;
00425
00426 if ( item->option == "I" )
00427 {
00428 pIpkg->setOption( "install" );
00429 Destination *d = dataMgr->getDestination( destination->currentText() );
00430 pIpkg->setDestination( d->getDestinationName() );
00431 pIpkg->setDestinationDir( d->getDestinationPath() );
00432
00433 if ( d->linkToRoot() )
00434 tmpFlags |= MAKE_LINKS;
00435 }
00436 else if ( item->option == "D" )
00437 {
00438 pIpkg->setOption( "remove" );
00439 pIpkg->setDestination( item->destination->getDestinationName() );
00440 pIpkg->setDestinationDir( item->destination->getDestinationPath() );
00441
00442 if ( item->destination->linkToRoot() )
00443 tmpFlags |= MAKE_LINKS;
00444 }
00445 else
00446 {
00447 if ( item->option == "R" )
00448 pIpkg->setOption( "reinstall" );
00449 else
00450 pIpkg->setOption( "upgrade" );
00451
00452 pIpkg->setDestination( item->destination->getDestinationName() );
00453 pIpkg->setDestinationDir( item->destination->getDestinationPath() );
00454 pIpkg->setPackage( item->packageName );
00455
00456 tmpFlags |= FORCE_REINSTALL;
00457 if ( item->destination->linkToRoot() && item->recreateLinks )
00458 tmpFlags |= MAKE_LINKS;
00459 }
00460 pIpkg->setFlags( tmpFlags, infoLevel );
00461 pIpkg->runIpkg();
00462 }
00463 else
00464 {
00465 btnOptions->setEnabled( true );
00466 btnInstall->setText( tr( "Close" ) );
00467 btnInstall->setIconSet( Opie::Core::OResource::loadPixmap( "enter", Opie::Core::OResource::SmallIcon ) );
00468
00469 btnOptions->setText( tr( "Save output" ) );
00470 btnOptions->setIconSet( Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ) );
00471
00472 if ( destination && destination->currentText() != 0 && destination->currentText() != "" )
00473 displayAvailableSpace( destination->currentText() );
00474 }
00475 }