author | drw <drw> | 2003-05-16 23:17:49 (UTC) |
---|---|---|
committer | drw <drw> | 2003-05-16 23:17:49 (UTC) |
commit | eac84192decbd60ecb680b82c92b55e70b5fd015 (patch) (side-by-side diff) | |
tree | 3e47155aff48679a971bccb82b58c6b89fe4c358 | |
parent | db67960cfab97f9897e0fdc1cb9c8e8794f4a2ba (diff) | |
download | opie-eac84192decbd60ecb680b82c92b55e70b5fd015.zip opie-eac84192decbd60ecb680b82c92b55e70b5fd015.tar.gz opie-eac84192decbd60ecb680b82c92b55e70b5fd015.tar.bz2 |
Fix for bug #914 (correct dialog cancel behaviour)
-rw-r--r-- | noncore/settings/aqpkg/mainwin.cpp | 69 | ||||
-rw-r--r-- | noncore/settings/aqpkg/mainwin.h | 21 |
2 files changed, 84 insertions, 6 deletions
diff --git a/noncore/settings/aqpkg/mainwin.cpp b/noncore/settings/aqpkg/mainwin.cpp index 0102292..0efa1e0 100644 --- a/noncore/settings/aqpkg/mainwin.cpp +++ b/noncore/settings/aqpkg/mainwin.cpp @@ -768,399 +768,456 @@ void MainWindow :: updateServer() void MainWindow :: upgradePackages() { // We're gonna do an upgrade of all packages // First warn user that this isn't recommended // TODO - ODevice???? QString text = tr( "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n" ); QMessageBox warn( tr( "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 mgr->writeOutIpkgConf(); // Now run upgrade Ipkg *ipkg = new Ipkg; ipkg->setOption( "upgrade" ); InstallDlgImpl *dlg = new InstallDlgImpl( ipkg, tr( "Upgrading installed packages" ), tr ( "Upgrade" ) ); connect( dlg, SIGNAL( reloadData( InstallDlgImpl * ) ), this, SLOT( reloadData( InstallDlgImpl * ) ) ); reloadDocuments = TRUE; stack->addWidget( dlg, 3 ); stack->raiseWidget( dlg ); } } void MainWindow :: downloadPackage() { bool doUpdate = true; if ( downloadEnabled ) { // See if any packages are selected bool found = false; if ( serversList->currentText() != LOCAL_SERVER ) { for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); item != 0 && !found; item = (QCheckListItem *)item->nextSibling() ) { if ( item->isOn() ) found = true; } } // If user selected some packages then download the and store the locally // otherwise, display dialog asking user what package to download from an http server // and whether to install it if ( found ) downloadSelectedPackages(); else downloadRemotePackage(); } else { 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 = mgr->getServer( serversList->currentText() )->getPackage( name ); QString msgtext; msgtext = tr( "Are you sure you wish to delete\n%1?" ).arg( (const char *)p->getPackageName() ); if ( QMessageBox::information( this, tr( "Are you sure?" ), msgtext, tr( "No" ), tr( "Yes" ) ) == 1 ) { doUpdate = true; QFile f( p->getFilename() ); f.remove(); } } } } if ( doUpdate ) { reloadData( 0x0 ); } } void MainWindow :: downloadSelectedPackages() { // First, write out ipkg_conf file so that ipkg can use it mgr->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() ) { ipkg.setPackage( item->text() ); ipkg.runIpkg( ); } } } void MainWindow :: downloadRemotePackage() { // Display dialog bool ok; QString package = InputDialog::getText( tr( "Install Remote Package" ), tr( "Enter package location" ), "http://", &ok, this ); if ( !ok || package.isEmpty() ) return; // DownloadRemoteDlgImpl dlg( this, "Install", true ); // if ( dlg.exec() == QDialog::Rejected ) // return; // grab details from dialog // QString package = dlg.getPackageLocation(); InstallData *item = new InstallData(); item->option = "I"; item->packageName = package; QList<InstallData> workingPackages; workingPackages.setAutoDelete( TRUE ); workingPackages.append( item ); InstallDlgImpl *dlg = new InstallDlgImpl( workingPackages, mgr, tr( "Download" ) ); connect( dlg, SIGNAL( reloadData( InstallDlgImpl * ) ), this, SLOT( reloadData( InstallDlgImpl * ) ) ); reloadDocuments = TRUE; stack->addWidget( dlg, 3 ); stack->raiseWidget( dlg ); } void MainWindow :: applyChanges() { stickyOption = ""; // First, write out ipkg_conf file so that ipkg can use it mgr->writeOutIpkgConf(); // Now for each selected item // deal with it QList<InstallData> workingPackages; workingPackages.setAutoDelete( TRUE ); for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); item != 0 ; item = (QCheckListItem *)item->nextSibling() ) { if ( item->isOn() ) { - workingPackages.append( dealWithItem( item ) ); + InstallData *instdata = dealWithItem( item ); + if ( instdata ) + workingPackages.append( instdata ); + else + return; } } if ( workingPackages.count() == 0 ) { // Nothing to do QMessageBox::information( this, tr( "Nothing to do" ), tr( "No packages selected" ), tr( "OK" ) ); return; } // do the stuff InstallDlgImpl *dlg = new InstallDlgImpl( workingPackages, mgr, tr( "Apply changes" ) ); connect( dlg, SIGNAL( reloadData( InstallDlgImpl * ) ), this, SLOT( reloadData( InstallDlgImpl * ) ) ); reloadDocuments = TRUE; stack->addWidget( dlg, 3 ); stack->raiseWidget( dlg ); } // 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 *MainWindow :: dealWithItem( QCheckListItem *item ) { QString name = item->text(); // Get package Server *s = mgr->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 *newitem = new InstallData(); newitem->option = "I"; newitem->packageName = name; return newitem; } else { InstallData *newitem = new InstallData(); newitem->option = "D"; if ( !p->isPackageStoredLocally() ) newitem->packageName = p->getInstalledPackageName(); else newitem->packageName = name; if ( p->getInstalledTo() ) { newitem->destination = p->getInstalledTo(); } else { newitem->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 newitem->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 = tr( "Do you wish to remove or reinstall\n%1?" ); text = tr( "Remove or ReInstall" ); secondButton = tr( "ReInstall" ); secondOption = tr( "R" ); } else if ( val == 1 ) { // Version available is newer - option to remove or upgrade caption = tr( "Do you wish to remove or upgrade\n%1?" ); text = tr( "Remove or Upgrade" ); secondButton = tr( "Upgrade" ); secondOption = tr( "U" ); } // Sticky option not implemented yet, but will eventually allow // the user to say something like 'remove all' if ( stickyOption == "" ) { QString msgtext; msgtext = caption.arg( ( const char * )name ); - switch( QMessageBox::information( this, text, - msgtext, tr( "Remove" ), secondButton ) ) +// switch( QMessageBox::information( this, text, +// msgtext, tr( "Remove" ), secondButton ) ) + QuestionDlg dlg( text, msgtext, secondButton ); + switch( dlg.exec() ) { - case 0: // Try again or Enter - // option 0 = Remove + case 0: // Cancel + delete newitem; + return 0x0; + break; + case 1: // Remove newitem->option = "D"; break; - case 1: // Quit or Escape + case 2: // Reinstall or Upgrade newitem->option = secondOption; break; } } else { // newitem->option = stickyOption; } } // Check if we are reinstalling the same version if ( newitem->option != "R" ) newitem->recreateLinks = true; else newitem->recreateLinks = false; // User hit cancel (on dlg - assume remove) return newitem; } } void MainWindow :: reloadData( InstallDlgImpl *dlg ) { stack->raiseWidget( progressWindow ); if ( dlg ) { dlg->close(); delete dlg; } mgr->reloadServerData(); serverSelected( -1, FALSE ); #ifdef QWS if ( reloadDocuments ) { m_status->setText( tr( "Updating Launcher..." ) ); // Finally let the main system update itself QCopEnvelope e("QPE/System", "linkChanged(QString)"); QString lf = QString::null; e << lf; } #endif stack->raiseWidget( networkPkgWindow ); } void MainWindow :: letterPushed( QString t ) { QCheckListItem *top = (QCheckListItem *)packagesList->firstChild(); QCheckListItem *start = (QCheckListItem *)packagesList->currentItem(); if ( packagesList->firstChild() == 0 ) return; QCheckListItem *item; if ( start == 0 ) { item = (QCheckListItem *)packagesList->firstChild(); start = top; } else item = (QCheckListItem *)start->nextSibling(); if ( item == 0 ) item = (QCheckListItem *)packagesList->firstChild(); do { if ( item->text().lower().startsWith( t.lower() ) ) { packagesList->setSelected( item, true ); packagesList->ensureItemVisible( item ); break; } item = (QCheckListItem *)item->nextSibling(); if ( !item ) item = (QCheckListItem *)packagesList->firstChild(); } while ( item != start); } void MainWindow :: slotDisplayPackage( QListViewItem *item ) { QString itemstr( ((QCheckListItem*)item)->text() ); PackageWindow *p = new PackageWindow( mgr->getServer( serversList->currentText() )->getPackage( itemstr ) ); p->showMaximized(); } + +QuestionDlg::QuestionDlg( const QString &caption, const QString &text, const QString &secondbtn ) + : QWidget( 0x0, 0x0, WType_Modal | WType_TopLevel | WStyle_Dialog ) +{ + setCaption( caption ); + resize( 175, 100 ); + + QGridLayout *layout = new QGridLayout( this ); + + QLabel *l = new QLabel( text, this ); + l->setAlignment( AlignCenter | WordBreak ); + layout->addMultiCellWidget( l, 0, 0, 0, 1 ); + + btn1 = new QPushButton( tr( "Remove" ), this ); + connect( btn1, SIGNAL(clicked()), this, SLOT(slotButtonPressed()) ); + layout->addWidget( btn1, 1, 0 ); + + btn2 = new QPushButton( secondbtn, this ); + connect( btn2, SIGNAL(clicked()), this, SLOT(slotButtonPressed()) ); + layout->addWidget( btn2, 1, 1 ); + + executing = FALSE; +} + +int QuestionDlg::exec() +{ + show(); + + if ( !executing ) + { + executing = TRUE; + qApp->enter_loop(); + } + + return buttonpressed; +} + +void QuestionDlg::slotButtonPressed() +{ + if ( sender() == btn1 ) + buttonpressed = 1; + else if ( sender() == btn2 ) + buttonpressed = 2; + else + buttonpressed = 0; + + qApp->exit_loop(); +} diff --git a/noncore/settings/aqpkg/mainwin.h b/noncore/settings/aqpkg/mainwin.h index 9f48321..615ff8b 100644 --- a/noncore/settings/aqpkg/mainwin.h +++ b/noncore/settings/aqpkg/mainwin.h @@ -1,154 +1,175 @@ /* This file is part of the OPIE Project =. Copyright (c) 2002 Andy Qua <andy.qua@blueyonder.co.uk> .=l. Dan Williams <drw@handhelds.org> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef MAINWIN_H #define MAINWIN_H #include <qmainwindow.h> #include <qpixmap.h> class DataManager; class InstallData; class InstallDlgImpl; class QAction; class QCheckListItem; class QComboBox; class QLabel; class QLineEdit; class QListView; class QListViewItem; class QToolBar; class QProgressBar; +class QPushButton; class QWidgetStack; class MainWindow :public QMainWindow { Q_OBJECT public: MainWindow(); ~MainWindow(); protected: void closeEvent( QCloseEvent* e ); private: DataManager *mgr; QWidgetStack *stack; QToolBar *findBar; QToolBar *jumpBar; QLineEdit *findEdit; QAction *actionFindNext; QAction *actionFilter; QAction *actionUpgrade; QAction *actionDownload; QAction *actionUninstalled; QAction *actionInstalled; QAction *actionUpdated; QPixmap iconDownload; QPixmap iconRemove; int mnuShowUninstalledPkgsId; int mnuShowInstalledPkgsId; int mnuShowUpgradedPkgsId; int mnuFilterByCategory; int mnuSetFilterCategory; // Main package list widget QWidget *networkPkgWindow; QComboBox *serversList; QListView *packagesList; QPixmap installedIcon; QPixmap updatedIcon; QString currentlySelectedServer; QString categoryFilter; QString stickyOption; bool categoryFilterEnabled; bool showJumpTo; bool showUninstalledPkgs; bool showInstalledPkgs; bool showUpgradedPkgs; bool downloadEnabled; bool reloadDocuments; void initMainWidget(); void updateData(); void serverSelected( int index, bool showProgress ); void searchForPackage( const QString & ); bool filterByCategory( bool val ); void downloadSelectedPackages(); void downloadRemotePackage(); InstallData *dealWithItem( QCheckListItem *item ); // Progress widget QWidget *progressWindow; QLabel *m_status; QProgressBar *m_progress; void initProgressWidget(); public slots: void setDocument( const QString &doc ); void displayFindBar(); void displayJumpBar(); void repeatFind(); void findPackage( const QString & ); void hideFindBar(); void hideJumpBar(); void displaySettings(); void filterUninstalledPackages(); void filterInstalledPackages(); void filterUpgradedPackages(); void filterCategory(); bool setFilterCategory(); void raiseMainWidget(); void raiseProgressWidget(); void enableUpgrade( bool ); void enableDownload( bool ); void reloadData( InstallDlgImpl * ); private slots: void init(); void setProgressSteps( int ); void setProgressMessage( const QString & ); void updateProgress( int ); void serverSelected( int index ); void updateServer(); void upgradePackages(); void downloadPackage(); void applyChanges(); void letterPushed( QString t ); void slotDisplayPackage( QListViewItem * ); }; + +class QuestionDlg : public QWidget +{ + Q_OBJECT +public: + QuestionDlg( const QString &caption, const QString &text, const QString &secondbtn ); + + int exec(); + +private: + QPushButton *btn1; + QPushButton *btn2; + + bool executing; + int buttonpressed; + +private slots: + void slotButtonPressed(); +}; + #endif |