author | andyq <andyq> | 2002-11-02 14:02:34 (UTC) |
---|---|---|
committer | andyq <andyq> | 2002-11-02 14:02:34 (UTC) |
commit | e622033e90f34ba60075f30a9049b0b266c61cb5 (patch) (side-by-side diff) | |
tree | 19c93b79359661222902edf71e9ea89c6ff66aef | |
parent | cf34849ac5c3eb9d16929cc88834973910209f74 (diff) | |
download | opie-e622033e90f34ba60075f30a9049b0b266c61cb5.zip opie-e622033e90f34ba60075f30a9049b0b266c61cb5.tar.gz opie-e622033e90f34ba60075f30a9049b0b266c61cb5.tar.bz2 |
Nows asks before deleting local ipk files
-rw-r--r-- | noncore/settings/aqpkg/networkpkgmgr.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/noncore/settings/aqpkg/networkpkgmgr.cpp b/noncore/settings/aqpkg/networkpkgmgr.cpp index dee834e..ccce401 100644 --- a/noncore/settings/aqpkg/networkpkgmgr.cpp +++ b/noncore/settings/aqpkg/networkpkgmgr.cpp @@ -173,467 +173,480 @@ void NetworkPackageManager :: initGui() vbox->addWidget( packagesList ); packagesList->addColumn( "Packages" ); QHBoxLayout *hbox2 = new QHBoxLayout( vbox, -1, "HBox2" ); hbox2->addWidget( update ); hbox2->addWidget( download ); hbox2->addWidget( upgrade ); hbox2->addWidget( apply ); } void NetworkPackageManager :: setupConnections() { connect( serversList, SIGNAL(activated( int )), this, SLOT(serverSelected( int ))); connect( apply, SIGNAL(released()), this, SLOT(applyChanges()) ); connect( download, SIGNAL(released()), this, SLOT(downloadPackage()) ); connect( upgrade, SIGNAL( released()), this, SLOT(upgradePackages()) ); connect( update, SIGNAL(released()), this, SLOT(updateServer()) ); } void NetworkPackageManager :: showProgressDialog( char *initialText ) { if ( !progressDlg ) progressDlg = new ProgressDlg( this, "Progress", false ); progressDlg->setText( initialText ); progressDlg->show(); } void NetworkPackageManager :: serverSelected( int ) { packagesList->clear(); // display packages QString serverName = serversList->currentText(); currentlySelectedServer = serverName; #ifdef QWS // read download directory from config file Config cfg( "aqpkg" ); cfg.setGroup( "settings" ); cfg.writeEntry( "selectedServer", currentlySelectedServer ); #endif Server *s = dataMgr->getServer( serverName ); vector<Package> &list = s->getPackageList(); vector<Package>::iterator it; for ( it = list.begin() ; it != list.end() ; ++it ) { QString text = ""; // If the local server, only display installed packages if ( serverName == LOCAL_SERVER && !it->isInstalled() ) continue; text += it->getPackageName(); if ( it->isInstalled() ) { text += " (installed)"; // If a different version of package is available, postfix it with an * if ( it->getVersion() != it->getInstalledVersion() ) { if ( compareVersions( it->getInstalledVersion(), it->getVersion() ) == 1 ) text += "*"; } } QCheckListItem *item = new QCheckListItem( packagesList, text, QCheckListItem::CheckBox ); if ( it->isInstalled() ) { QString destName = ""; if ( it->getLocalPackage() ) { if ( it->getLocalPackage()->getInstalledTo() ) destName = it->getLocalPackage()->getInstalledTo()->getDestinationName(); } else { if ( it->getInstalledTo() ) destName = it->getInstalledTo()->getDestinationName(); } if ( destName != "" ) new QCheckListItem( item, QString( "Installed To - " ) + destName ); } if ( !it->isPackageStoredLocally() ) new QCheckListItem( item, QString( "Description - " ) + it->getDescription() ); else new QCheckListItem( item, QString( "Filename - " ) + it->getFilename() ); if ( serverName == LOCAL_SERVER ) { new QCheckListItem( item, QString( "V. Installed - " ) + it->getVersion() ); } else { new QCheckListItem( item, QString( "V. Available - " ) + it->getVersion() ); if ( it->getLocalPackage() ) { if ( it->isInstalled() ) new QCheckListItem( item, QString( "V. Installed - " ) + it->getInstalledVersion() ); } } packagesList->insertItem( item ); } // If the local server or the local ipkgs server disable the download button if ( serverName == LOCAL_SERVER ) { upgrade->setEnabled( false ); download->setText( "Download" ); download->setEnabled( false ); } else if ( serverName == LOCAL_IPKGS ) { upgrade->setEnabled( false ); download->setEnabled( true ); download->setText( "Remove" ); } else { upgrade->setEnabled( true ); download->setEnabled( true ); download->setText( "Download" ); } } void NetworkPackageManager :: updateServer() { QString serverName = serversList->currentText(); // Update the current server // Display dialog // ProgressDlg *progDlg = new ProgressDlg( this ); // QString status = "Updating package lists..."; // progDlg->show(); // progDlg->setText( status ); // Disable buttons to stop silly people clicking lots on them :) // First, write out ipkg_conf file so that ipkg can use it dataMgr->writeOutIpkgConf(); Ipkg ipkg; ipkg.setOption( "update" ); InstallDlgImpl dlg( &ipkg, "Refreshing server package lists", this, "Upgrade", true ); dlg.showDlg(); // Reload data dataMgr->reloadServerData(); serverSelected(-1); // delete progDlg; } void NetworkPackageManager :: upgradePackages() { // We're gonna do an upgrade of all packages // First warn user that this isn't recommended QString text = "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n"; QMessageBox warn("Warning", text, QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No | QMessageBox::Escape | QMessageBox::Default , 0, this ); warn.adjustSize(); if ( warn.exec() == QMessageBox::Yes ) { // First, write out ipkg_conf file so that ipkg can use it dataMgr->writeOutIpkgConf(); // Now run upgrade Ipkg ipkg; ipkg.setOption( "upgrade" ); InstallDlgImpl dlg( &ipkg, "Upgrading installed packages", this, "Upgrade", true ); dlg.showDlg(); // Reload data dataMgr->reloadServerData(); serverSelected(-1); } } void NetworkPackageManager :: downloadPackage() { + bool doUpdate = true; if ( download->text() == "Download" ) { // First, write out ipkg_conf file so that ipkg can use it dataMgr->writeOutIpkgConf(); // Display dialog to user asking where to download the files to bool ok = FALSE; QString dir = ""; #ifdef QWS // read download directory from config file Config cfg( "aqpkg" ); cfg.setGroup( "settings" ); dir = cfg.readEntry( "downloadDir", "/home/root/Documents/application/ipkg" ); #endif QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), dir, &ok, this ); if ( ok && !text.isEmpty() ) dir = text; // user entered something and pressed ok else return; // user entered nothing or pressed cancel #ifdef QWS // Store download directory in config file cfg.writeEntry( "downloadDir", dir ); #endif // Get starting directory char initDir[PATH_MAX]; getcwd( initDir, PATH_MAX ); // Download each package Ipkg ipkg; connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); ipkg.setOption( "download" ); ipkg.setRuntimeDirectory( dir ); for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); item != 0 ; item = (QCheckListItem *)item->nextSibling() ) { if ( item->isOn() ) { QString name = item->text(); int pos = name.find( "*" ); name.truncate( pos ); // if (there is a (installed), remove it pos = name.find( "(installed)" ); if ( pos > 0 ) name.truncate( pos - 1 ); ipkg.setPackage( name ); ipkg.runIpkg( ); } } } else if ( download->text() == "Remove" ) { + doUpdate = false; for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); item != 0 ; item = (QCheckListItem *)item->nextSibling() ) { if ( item->isOn() ) { QString name = item->text(); int pos = name.find( "*" ); name.truncate( pos ); // if (there is a (installed), remove it pos = name.find( "(installed)" ); if ( pos > 0 ) name.truncate( pos - 1 ); Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name ); + + QString msgtext; + msgtext.sprintf( "Are you sure you wish to delete\n%s?", (const char *)p->getPackageName() ); + if ( QMessageBox::information( this, "Are you sure?", + msgtext, "No", "Yes" ) == 1 ) + { + doUpdate = true; QFile f( p->getFilename() ); f.remove(); } } } + } + if ( doUpdate ) + { dataMgr->reloadServerData(); serverSelected( -1 ); } +} void NetworkPackageManager :: applyChanges() { stickyOption = ""; // First, write out ipkg_conf file so that ipkg can use it dataMgr->writeOutIpkgConf(); // Now for each selected item // deal with it vector<InstallData> workingPackages; for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); item != 0 ; item = (QCheckListItem *)item->nextSibling() ) { if ( item->isOn() ) { InstallData data = dealWithItem( item ); workingPackages.push_back( data ); } } if ( workingPackages.size() == 0 ) { // Nothing to do QMessageBox::information( this, "Nothing to do", "No packages selected", "OK" ); return; } // do the stuff InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true ); dlg.showDlg(); // Reload data dataMgr->reloadServerData(); serverSelected(-1); #ifdef QWS // Finally let the main system update itself QCopEnvelope e("QPE/System", "linkChanged(QString)"); QString lf = QString::null; e << lf; #endif } // decide what to do - either remove, upgrade or install // Current rules: // If not installed - install // If installed and different version available - upgrade // If installed and version up to date - remove InstallData NetworkPackageManager :: dealWithItem( QCheckListItem *item ) { QString name = item->text(); int pos = name.find( "*" ); name.truncate( pos ); // if (there is a (installed), remove it pos = name.find( "(installed)" ); if ( pos > 0 ) name.truncate( pos - 1 ); // Get package Server *s = dataMgr->getServer( serversList->currentText() ); Package *p = s->getPackage( name ); // If the package has a filename then it is a local file if ( p->isPackageStoredLocally() ) name = p->getFilename(); QString option; QString dest = "root"; if ( !p->isInstalled() ) { InstallData item; item.option = "I"; item.packageName = name; return item; } else { InstallData item; item.option = "D"; if ( !p->isPackageStoredLocally() ) item.packageName = p->getInstalledPackageName(); else item.packageName = name; if ( p->getInstalledTo() ) { item.destination = p->getInstalledTo(); cout << "dest - " << p->getInstalledTo()->getDestinationName() << endl; cout << "dest - " << p->getInstalledTo()->getDestinationPath() << endl; } else { item.destination = p->getLocalPackage()->getInstalledTo(); } // Now see if version is newer or not int val = compareVersions( p->getInstalledVersion(), p->getVersion() ); // If the version requested is older and user selected a local ipk file, then reinstall the file if ( p->isPackageStoredLocally() && val == -1 ) val = 0; if ( val == -2 ) { // Error - should handle } else if ( val == -1 ) { // Version available is older - remove only item.option = "D"; } else { QString caption; QString text; QString secondButton; QString secondOption; if ( val == 0 ) { // Version available is the same - option to remove or reinstall caption = "Do you wish to remove or reinstall\n%s?"; text = "Remove or ReInstall"; secondButton = "ReInstall"; secondOption = "R"; } else if ( val == 1 ) { // Version available is newer - option to remove or upgrade caption = "Do you wish to remove or upgrade\n%s?"; text = "Remove or Upgrade"; secondButton = "Upgrade"; secondOption = "U"; } // Sticky option not implemented yet, but will eventually allow // the user to say something like 'remove all' if ( stickyOption == "" ) { QString msgtext; msgtext.sprintf( caption, (const char *)name ); switch( QMessageBox::information( this, text, msgtext, "Remove", secondButton ) ) { case 0: // Try again or Enter // option 0 = Remove item.option = "D"; break; case 1: // Quit or Escape item.option = secondOption; break; } } else { // item.option = stickyOption; } } // Check if we are reinstalling the same version if ( item.option != "R" ) item.recreateLinks = true; else item.recreateLinks = false; // User hit cancel (on dlg - assume remove) return item; } } void NetworkPackageManager :: displayText( const QString &t ) { cout << t << endl; } void NetworkPackageManager :: letterPushed( QString t ) { QCheckListItem *top = (QCheckListItem *)packagesList->firstChild(); QCheckListItem *start = (QCheckListItem *)packagesList->currentItem(); if ( packagesList->firstChild() == 0 ) return; QCheckListItem *item; if ( start == 0 ) |