Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

mainwindow.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003 
00004                              Copyright (C)2004, 2005 Dan Williams <drw@handhelds.org>
00005               =.
00006             .=l.
00007            .>+-=
00008  _;:,     .>    :=|.         This program is free software; you can
00009 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00010 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00011 .="- .-=="i,     .._         License as published by the Free Software
00012  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00013      ._= =}       :          or (at your option) any later version.
00014     .%`+i>       _;_.
00015     .i_,=:_.      -<s.       This program is distributed in the hope that
00016      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00017     : ..    .:,     . . .    without even the implied warranty of
00018     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00019   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00020 ..}^=.=       =       ;      Library General Public License for more
00021 ++=   -.     .`     .:       details.
00022 :     =  ...= . :.=-
00023  -.   .:....=;==+<;          You should have received a copy of the GNU
00024   -_. . .   )=.  =           Library General Public License along with
00025     --        :-=`           this library; see the file COPYING.LIB.
00026                              If not, write to the Free Software Foundation,
00027                              Inc., 59 Temple Place - Suite 330,
00028                              Boston, MA 02111-1307, USA.
00029 */
00030 
00031 #include "mainwindow.h"
00032 #include "installdlg.h"
00033 #include "filterdlg.h"
00034 #include "promptdlg.h"
00035 #include "entrydlg.h"
00036 #include "packageinfodlg.h"
00037 
00038 #include <opie2/ofiledialog.h>
00039 #include <opie2/oresource.h>
00040 
00041 #include <qpe/qcopenvelope_qws.h>
00042 #include <qpe/qpeapplication.h>
00043 
00044 #include <qaction.h>
00045 #include <qdir.h>
00046 #include <qlayout.h>
00047 #include <qlineedit.h>
00048 #include <qmenubar.h>
00049 #include <qmessagebox.h>
00050 #include <qpopupmenu.h>
00051 #include <qtimer.h>
00052 #include <qtoolbar.h>
00053 #include <qwhatsthis.h>
00054 
00055 MainWindow::MainWindow( QWidget *parent, const char *name, WFlags /*fl*/ )
00056     : QMainWindow( parent, name, WStyle_ContextHelp )
00057     , m_config( "packman" )
00058     , m_packman( &m_config, this )
00059     , m_menuBar( this )
00060     , m_toolBar( this )
00061     , m_findBar( this )
00062     , m_widgetStack( this )
00063     , m_packageList( this )
00064     , m_statusWidget( this )
00065     , m_statusText( &m_statusWidget )
00066     , m_statusBar( &m_statusWidget )
00067     , m_iconUpdated( Opie::Core::OResource::loadPixmap( "packagemanager/updated" ) )
00068     , m_iconInstalled( Opie::Core::OResource::loadPixmap( "installed" ) )
00069     , m_iconNull( m_iconUpdated.size() )
00070     , m_filterName( QString::null )
00071     , m_filterServer( QString::null )
00072     , m_filterDest( QString::null )
00073     , m_filterStatus( OPackageManager::NotDefined )
00074     , m_filterCategory( QString::null )
00075 
00076 {
00077 //    setCaption( tr( "Package Manager" ) );
00078 
00079     m_iconNull.fill( colorGroup().base() );
00080 
00081     connect( &m_widgetStack, SIGNAL(aboutToShow(QWidget*)), this, SLOT(slotWidgetStackShow(QWidget*)) );
00082 
00083     // Initialize widget stack, package list and status widget
00084     initStatusWidget();
00085     initPackageList();
00086 
00087     m_widgetStack.addWidget( &m_statusWidget, 2 );
00088     m_widgetStack.addWidget( &m_packageList, 1 );
00089     setCentralWidget( &m_widgetStack );
00090 
00091     // Initialize remaining user interface items
00092     initUI();
00093 
00094     // Initialize package information
00095     QTimer::singleShot( -1, this, SLOT( initPackageInfo() ) );
00096 }
00097 
00098 void MainWindow::closeEvent( QCloseEvent *event )
00099 {
00100     // Close app only if either the package or status widgets are currently active
00101     bool close = m_widgetStack.visibleWidget() == &m_packageList ||
00102                  m_widgetStack.visibleWidget() == &m_statusWidget;
00103     if ( close )
00104     {
00105         // TODO - write out application configuration settings
00106 
00107         // Write out package manager configuration settings
00108         m_packman.saveSettings();
00109         event->accept();
00110     }
00111     else
00112     {
00113         delete m_widgetStack.visibleWidget();
00114         m_widgetStack.raiseWidget( &m_packageList );
00115         event->ignore();
00116     }
00117 }
00118 
00119 void MainWindow::initPackageList()
00120 {
00121     m_packageList.addColumn( tr( "Packages" ) );
00122     QWhatsThis::add( &m_packageList, tr( "This is a listing of all packages.\n\nA blue dot next to the package name indicates that the package is currently installed.\n\nA blue dot with a star indicates that a newer version of the package is available from the server feed.\n\nTap inside the box at the left to select a package.  Tap and hold to view package details." ) );
00123     QPEApplication::setStylusOperation( m_packageList.viewport(), QPEApplication::RightOnHold );
00124     connect( &m_packageList, SIGNAL(rightButtonPressed(QListViewItem*,const QPoint&,int)),
00125              this, SLOT(slotDisplayPackageInfo(QListViewItem*)) );
00126 }
00127 
00128 void MainWindow::initStatusWidget()
00129 {
00130     QVBoxLayout *layout = new QVBoxLayout( &m_statusWidget, 4, 4 );
00131 
00132     m_statusText.setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00133     layout->addWidget( &m_statusText );
00134 
00135     connect( &m_packman, SIGNAL(initStatus(int)), this, SLOT(slotInitStatusBar(int)) );
00136     connect( &m_packman, SIGNAL(statusText(const QString&)), this, SLOT(slotStatusText(const QString&)) );
00137     connect( &m_packman, SIGNAL(statusBar(int)), this, SLOT(slotStatusBar(int)) );
00138 
00139     layout->addWidget( &m_statusBar );
00140 }
00141 
00142 void MainWindow::initUI()
00143 {
00144     // Build menu and tool bars
00145     setToolBarsMovable( false );
00146 
00147     m_menuBar.setHorizontalStretchable( true );
00148     QMenuBar *mb = new QMenuBar( &m_menuBar );
00149     mb->setMargin( 0 );
00150 
00151     // Find toolbar
00152     addToolBar( &m_findBar, QMainWindow::Top, true );
00153     m_findBar.setHorizontalStretchable( true );
00154     m_findEdit = new QLineEdit( &m_findBar );
00155     QWhatsThis::add( m_findEdit, tr( "Type the text to search for here." ) );
00156     m_findBar.setStretchableWidget( m_findEdit );
00157     connect( m_findEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotFindChanged(const QString&)) );
00158 
00159     // Packages menu
00160     QPopupMenu *popup = new QPopupMenu( this );
00161 
00162     QAction *a = new QAction( tr( "Update lists" ), Opie::Core::OResource::loadPixmap( "packagemanager/update",
00163                               Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
00164     a->setWhatsThis( tr( "Tap here to update package lists from servers." ) );
00165     connect( a, SIGNAL(activated()), this, SLOT(slotUpdate()) );
00166     a->addTo( popup );
00167     a->addTo( &m_toolBar );
00168 
00169     QAction *actionUpgrade = new QAction( tr( "Upgrade" ), Opie::Core::OResource::loadPixmap( "packagemanager/upgrade",
00170                                           Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
00171     actionUpgrade->setWhatsThis( tr( "Tap here to upgrade all installed packages if a newer version is available." ) );
00172     connect( actionUpgrade, SIGNAL(activated()), this, SLOT(slotUpgrade()) );
00173     actionUpgrade->addTo( popup );
00174     actionUpgrade->addTo( &m_toolBar );
00175 
00176     QPixmap iconDownload = Opie::Core::OResource::loadPixmap( "packagemanager/download", Opie::Core::OResource::SmallIcon );
00177     QPixmap iconRemove = Opie::Core::OResource::loadPixmap( "packagemanager/remove", Opie::Core::OResource::SmallIcon );
00178     QAction *actionDownload = new QAction( tr( "Download" ), iconDownload, QString::null, 0, this, 0 );
00179     actionDownload->setWhatsThis( tr( "Tap here to download the currently selected package(s)." ) );
00180     connect( actionDownload, SIGNAL(activated()), this, SLOT(slotDownload()) );
00181     actionDownload->addTo( popup );
00182     actionDownload->addTo( &m_toolBar );
00183 
00184     a = new QAction( tr( "Apply changes" ), Opie::Core::OResource::loadPixmap( "packagemanager/apply",
00185                      Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
00186     a->setWhatsThis( tr( "Tap here to install, remove or upgrade currently selected package(s)." ) );
00187     connect( a, SIGNAL(activated()), this, SLOT(slotApply()) );
00188     a->addTo( popup );
00189     a->addTo( &m_toolBar );
00190 
00191     a = new QAction( tr( "Install local package" ), Opie::Core::OResource::loadPixmap( "folder",
00192                      Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
00193     a->setWhatsThis( tr( "Tap here to install a package file located on device." ) );
00194     connect( a, SIGNAL(activated()), this, SLOT(slotInstallLocal()) );
00195     a->addTo( popup );
00196     //a->addTo( &m_toolBar );
00197 
00198     popup->insertSeparator();
00199 
00200     a = new QAction( tr( "Configure" ), Opie::Core::OResource::loadPixmap( "SettingsIcon",
00201                      Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
00202     a->setWhatsThis( tr( "Tap here to configure this application." ) );
00203     connect( a, SIGNAL(activated()), this, SLOT(slotConfigure()) );
00204     a->addTo( popup );
00205     mb->insertItem( tr( "Actions" ), popup );
00206 
00207     // View menu
00208     popup = new QPopupMenu( this );
00209 
00210     m_actionShowNotInstalled = new QAction( tr( "Show packages not installed" ), QString::null, 0, this, 0 );
00211     m_actionShowNotInstalled->setToggleAction( true );
00212     m_actionShowNotInstalled->setWhatsThis( tr( "Tap here to show packages available which have not been installed." ) );
00213     connect( m_actionShowNotInstalled, SIGNAL(activated()), this, SLOT(slotShowNotInstalled()) );
00214     m_actionShowNotInstalled->addTo( popup );
00215 
00216     m_actionShowInstalled = new QAction( tr( "Show installed packages" ), QString::null, 0, this, 0 );
00217     m_actionShowInstalled->setToggleAction( true );
00218     m_actionShowInstalled->setWhatsThis( tr( "Tap here to show packages currently installed on this device." ) );
00219     connect( m_actionShowInstalled, SIGNAL(activated()), this, SLOT(slotShowInstalled()) );
00220     m_actionShowInstalled->addTo( popup );
00221 
00222     m_actionShowUpdated = new QAction( tr( "Show updated packages" ), QString::null, 0, this, 0 );
00223     m_actionShowUpdated->setToggleAction( true );
00224     m_actionShowUpdated->setWhatsThis( tr( "Tap here to show packages currently installed on this device which have a newer version available." ) );
00225     connect( m_actionShowUpdated, SIGNAL(activated()), this, SLOT(slotShowUpdated()) );
00226     m_actionShowUpdated->addTo( popup );
00227 
00228     popup->insertSeparator();
00229 
00230     m_actionFilter = new QAction( tr( "Filter" ), Opie::Core::OResource::loadPixmap( "packagemanager/filter",
00231                                   Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
00232     m_actionFilter->setToggleAction( true );
00233     m_actionFilter->setWhatsThis( tr( "Tap here to apply current filter." ) );
00234     connect( m_actionFilter, SIGNAL(toggled(bool)), this, SLOT(slotFilter(bool)) );
00235     m_actionFilter->addTo( popup );
00236 
00237     a = new QAction( tr( "Filter settings" ),  QString::null, 0, this, 0 );
00238     a->setWhatsThis( tr( "Tap here to change the package filter criteria." ) );
00239     connect( a, SIGNAL(activated()), this, SLOT(slotFilterChange()) );
00240     a->addTo( popup );
00241 
00242     popup->insertSeparator();
00243 
00244     a = new QAction( tr( "Find" ), Opie::Core::OResource::loadPixmap( "find", Opie::Core::OResource::SmallIcon ),
00245                      QString::null, 0, this, 0 );
00246     a->setWhatsThis( tr( "Tap here to search for text in package names." ) );
00247     connect( a, SIGNAL(activated()), this, SLOT(slotFindShowToolbar()) );
00248     a->addTo( popup );
00249 
00250     m_actionFindNext = new QAction( tr( "Find next" ), Opie::Core::OResource::loadPixmap( "next",
00251                                     Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
00252     m_actionFindNext->setEnabled( false );
00253     m_actionFindNext->setWhatsThis( tr( "Tap here to find the next package name containing the text you are searching for." ) );
00254     connect( m_actionFindNext, SIGNAL(activated()), this, SLOT(slotFindNext()) );
00255     m_actionFindNext->addTo( popup );
00256     m_actionFindNext->addTo( &m_findBar );
00257 
00258     mb->insertItem( tr( "View" ), popup );
00259 
00260     // Finish find toolbar creation
00261     a = new QAction( QString::null, Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ),
00262                      QString::null, 0, this, 0 );
00263     a->setWhatsThis( tr( "Tap here to hide the find toolbar." ) );
00264     connect( a, SIGNAL(activated()), this, SLOT(slotFindHideToolbar()) );
00265     a->addTo( &m_findBar );
00266     m_findBar.hide();
00267 }
00268 
00269 void MainWindow::loadPackageList( OPackageList *packages, bool clearList )
00270 {
00271     if ( clearList )
00272         m_packageList.clear();
00273 
00274     if ( packages )
00275     {
00276         for ( OPackageListIterator packageIt( *packages ); packageIt.current(); ++packageIt )
00277         {
00278             OPackage *package = packageIt.current();
00279             QCheckListItem *item = new QCheckListItem( &m_packageList, package->name(),
00280                                                     QCheckListItem::CheckBox );
00281             m_packageList.insertItem( item );
00282 
00283             // If a different version of package is available, show update available icon
00284             // Otherwise, show installed icon
00285             if ( !package->versionInstalled().isNull() )
00286             {
00287                 if ( m_packman.compareVersions( package->version(), package->versionInstalled() ) == 1 )
00288                     item->setPixmap( 0, m_iconUpdated );
00289                 else
00290                     item->setPixmap( 0, m_iconInstalled );
00291             }
00292             else
00293                 item->setPixmap( 0, m_iconNull );
00294         }
00295     }
00296 }
00297 
00298 void MainWindow::searchForPackage( const QString &text )
00299 {
00300     if ( !text.isEmpty() )
00301     {
00302         // look through package list for text startng at current position
00303         QCheckListItem *start = static_cast<QCheckListItem *>(m_packageList.currentItem());
00304         if ( start == 0 )
00305             start = static_cast<QCheckListItem *>(m_packageList.firstChild());
00306 
00307 //        for ( QCheckListItem *item = static_cast<QCheckListItem *>(start->nextSibling()); item != 0 ;
00308         for ( QCheckListItem *item = static_cast<QCheckListItem *>(start); item != 0 ;
00309               item = static_cast<QCheckListItem *>(item->nextSibling()) )
00310         {
00311             if ( item->text().lower().find( text ) != -1 )
00312             {
00313                 m_packageList.ensureItemVisible( item );
00314                 m_packageList.setCurrentItem( item );
00315                 break;
00316             }
00317         }
00318     }
00319 }
00320 
00321 void MainWindow::installLocalPackage( const QString &ipkFile )
00322 {
00323     // Install selected file
00324     InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Install local package" ),
00325                                       OPackage::Install, ipkFile );
00326     connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) );
00327 
00328     // Display widget
00329     m_widgetStack.addWidget( dlg, 3 );
00330     m_widgetStack.raiseWidget( dlg );
00331 }
00332 
00333 void MainWindow::setDocument( const QString &ipkFile )
00334 {
00335     QString file = ipkFile;
00336     DocLnk lnk( ipkFile );
00337     if ( lnk.isValid() )
00338         file = lnk.file();
00339     
00340     installLocalPackage( file );
00341 }
00342 
00343 void MainWindow::initPackageInfo()
00344 {
00345     m_widgetStack.raiseWidget( &m_statusWidget );
00346 
00347     // Load package list
00348     m_packman.loadAvailablePackages();
00349     m_packman.loadInstalledPackages();
00350 
00351     OPackageList *packageList = m_packman.packages();
00352     if ( packageList )
00353     {
00354         loadPackageList( packageList, true );
00355         delete packageList;
00356     }
00357 
00358     QWidget *widget = m_widgetStack.widget( 3 );
00359     if ( !widget )
00360         widget = &m_packageList;
00361     m_widgetStack.raiseWidget( widget );
00362 }
00363 
00364 void MainWindow::slotWidgetStackShow( QWidget *widget )
00365 {
00366     if ( widget == &m_packageList )
00367     {
00368         setCaption( tr( "Package Manager" ) );
00369 
00370         m_menuBar.show();
00371         m_toolBar.show();
00372     }
00373     else
00374     {
00375         m_menuBar.hide();
00376         m_toolBar.hide();
00377     }
00378 }
00379 
00380 void MainWindow::slotInitStatusBar( int numSteps )
00381 {
00382     m_statusBar.setTotalSteps( numSteps );
00383 }
00384 
00385 void MainWindow::slotStatusText( const QString &status )
00386 {
00387     m_statusText.setText( status );
00388 }
00389 
00390 void MainWindow::slotStatusBar( int currStep )
00391 {
00392     m_statusBar.setProgress( currStep );
00393 }
00394 
00395 void MainWindow::slotUpdate()
00396 {
00397     // Create package manager output widget
00398     InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Update package information" ),
00399                                       OPackage::Update );
00400     connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) );
00401 
00402     // Display widget
00403     m_widgetStack.addWidget( dlg, 3 );
00404     m_widgetStack.raiseWidget( dlg );
00405 }
00406 
00407 void MainWindow::slotUpgrade()
00408 {
00409     // Create package manager output widget
00410     InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Upgrade installed packages" ),
00411                                       OPackage::Upgrade );
00412     connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) );
00413 
00414     // Display widget
00415     m_widgetStack.addWidget( dlg, 3 );
00416     m_widgetStack.raiseWidget( dlg );
00417 }
00418 
00419 void MainWindow::slotDownload()
00420 {
00421     // Retrieve list of packages selected for download (if any)
00422     QStringList workingPackages;
00423 
00424     for ( QCheckListItem *item = static_cast<QCheckListItem *>(m_packageList.firstChild());
00425           item != 0 ;
00426           item = static_cast<QCheckListItem *>(item->nextSibling()) )
00427     {
00428         if ( item->isOn() )
00429             workingPackages.append( item->text() );
00430     }
00431 
00432     if ( workingPackages.isEmpty() )
00433     {
00434         QMessageBox::information( this, tr( "Nothing to do" ), tr( "No packages selected" ), tr( "OK" ) );
00435         return;
00436     }
00437     else
00438     {
00439         // Download selected packages
00440         m_config.setGroup( "settings" );
00441         QString workingDir = m_config.readEntry( "DownloadDir", "/tmp" );
00442 
00443         bool ok = false;
00444         QString text = EntryDlg::getText( tr( "Download" ), tr( "Enter path to download package to:" ), workingDir, &ok, this );
00445         if ( ok && !text.isEmpty() )
00446             workingDir = text;   // user entered something and pressed ok
00447         else
00448             return; // user entered nothing or pressed cancel
00449 
00450         // Store download directory in config file
00451         m_config.writeEntry( "DownloadDir", workingDir );
00452 
00453         // Get starting directory
00454         QDir::setCurrent( workingDir );
00455 
00456         // Create package manager output widget
00457         InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Download packages" ),
00458                                           OPackage::Download, workingPackages );
00459         connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) );
00460 
00461         // Display widget
00462         m_widgetStack.addWidget( dlg, 3 );
00463         m_widgetStack.raiseWidget( dlg );
00464     }
00465 }
00466 
00467 void MainWindow::slotApply()
00468 {
00469     QStringList removeList;
00470     QStringList installList;
00471     QStringList upgradeList;
00472 
00473     for ( QCheckListItem *item = static_cast<QCheckListItem *>(m_packageList.firstChild());
00474           item != 0 ;
00475           item = static_cast<QCheckListItem *>(item->nextSibling()) )
00476     {
00477         if ( item->isOn() )
00478         {
00479             OPackage *package = m_packman.findPackage( item->text() );
00480             if ( package )
00481             {
00482                 if ( !package->versionInstalled().isNull() )
00483                 {
00484                     if ( m_packman.compareVersions( package->version(), package->versionInstalled() ) == 1 )
00485                     {
00486                         // Remove/upgrade package
00487                         int answer =  PromptDlg::ask( tr( "Remove or upgrade" ),
00488                                       tr( QString( "Do you wish to remove or upgrade\n%1?" ).arg( item->text() ) ),
00489                                       tr( "Remove" ), tr( "Upgrade" ), this );
00490                         if ( answer == 1 )  // Remove
00491                         {
00492                             removeList.append( item->text() );
00493                         }
00494                         else if ( answer == 2 )  // Upgrade
00495                         {
00496                             upgradeList.append( item->text() );
00497                         }
00498                     }
00499                     else
00500                     {
00501                         // Remove/reinstall package
00502                         int answer =  PromptDlg::ask( tr( "Remove or reinstall" ),
00503                                       tr( QString( "Do you wish to remove or reinstall\n%1?" ).arg( item->text() ) ),
00504                                       tr( "Remove" ), tr( "Reinstall" ), this );
00505                         if ( answer == 1 )  // Remove
00506                         {
00507                             removeList.append( item->text() );
00508                         }
00509                         else if ( answer == 2 )  // Reinstall
00510                         {
00511                             installList.append( item->text() );
00512                         }
00513                     }
00514                 }
00515                 else
00516                 {
00517                     // Install package
00518                     installList.append( item->text() );
00519                 }
00520             }
00521         }
00522     }
00523 
00524     // If nothing is selected, display message and exit
00525     if ( removeList.isEmpty() && installList.isEmpty() && upgradeList.isEmpty() )
00526     {
00527         QMessageBox::information( this, tr( "Nothing to do" ), tr( "No packages selected" ), tr( "OK" ) );
00528         return;
00529     }
00530 
00531     // Send command only if there are packages to process
00532     OPackage::Command removeCmd = !removeList.isEmpty() ? OPackage::Remove
00533                                                         : OPackage::NotDefined;
00534     OPackage::Command installCmd = !installList.isEmpty() ? OPackage::Install
00535                                                           : OPackage::NotDefined;
00536     OPackage::Command upgradeCmd = !upgradeList.isEmpty() ? OPackage::Upgrade
00537                                                           : OPackage::NotDefined;
00538 
00539     // Create package manager output widget
00540     InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Apply changes" ),
00541                                       removeCmd, removeList,
00542                                       installCmd, installList,
00543                                       upgradeCmd, upgradeList );
00544     connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) );
00545 
00546     // Display widget
00547     m_widgetStack.addWidget( dlg, 3 );
00548     m_widgetStack.raiseWidget( dlg );
00549 }
00550 
00551 void MainWindow::slotInstallLocal()
00552 {
00553     // Display file open dialog with only package files
00554     MimeTypes type;
00555     QStringList packages;
00556     packages << "application/ipkg";
00557     type.insert( tr( "Application Packages" ), packages );
00558     QString package = Opie::Ui::OFileDialog::getOpenFileName( Opie::Ui::OFileSelector::NORMAL,
00559                                                               "/", QString::null, type );
00560     if ( !package.isNull() )
00561         installLocalPackage( package );
00562 }
00563 
00564 void MainWindow::slotCloseDlg()
00565 {
00566     // Close install dialog
00567     delete m_widgetStack.visibleWidget();
00568 
00569     // Reload package list
00570     initPackageInfo();
00571 
00572     // Update Opie launcher links
00573     QCopEnvelope e("QPE/System", "linkChanged(QString)");
00574     QString lf = QString::null;
00575     e << lf;
00576     
00577     // Reapply any filters previously set
00578     if ( m_actionShowNotInstalled->isOn() )
00579         slotShowNotInstalled();
00580     else if ( m_actionShowInstalled->isOn() )
00581         slotShowInstalled();
00582     else if ( m_actionShowUpdated->isOn() )
00583         slotShowUpdated();
00584     else if ( m_actionFilter->isOn() )
00585         slotFilter( true );
00586 }
00587 
00588 void MainWindow::slotConfigure()
00589 {
00590     if ( m_packman.configureDlg( false ) )
00591     {
00592         if ( PromptDlg::ask( tr( "Config updated" ),
00593              tr( "The configuration has been updated.  Do you want to update server and package information now?" ),
00594              tr( "Yes" ), tr( "No" ), this ) == 1 )
00595         {
00596             // Update package list and reload package info
00597             slotUpdate();
00598         }
00599     }
00600 }
00601 
00602 void MainWindow::slotShowNotInstalled()
00603 {
00604     OPackageList *packageList;
00605     if ( m_actionShowNotInstalled->isOn() )
00606     {
00607         m_actionShowInstalled->setOn( false );
00608         m_actionShowUpdated->setOn( false );
00609         m_actionFilter->setOn( false );
00610         packageList = m_packman.filterPackages( QString::null, QString::null, QString::null,
00611                                                 OPackageManager::NotInstalled, QString::null );
00612     }
00613     else
00614         packageList = m_packman.packages();
00615 
00616     if ( packageList )
00617     {
00618         loadPackageList( packageList, true );
00619         delete packageList;
00620     }
00621 }
00622 
00623 void MainWindow::slotShowInstalled()
00624 {
00625     OPackageList *packageList;
00626     if ( m_actionShowInstalled->isOn() )
00627     {
00628         m_actionShowNotInstalled->setOn( false );
00629         m_actionShowUpdated->setOn( false );
00630         m_actionFilter->setOn( false );
00631         packageList = m_packman.filterPackages( QString::null, QString::null, QString::null,
00632                                                 OPackageManager::Installed, QString::null );
00633     }
00634     else
00635         packageList = m_packman.packages();
00636 
00637     if ( packageList )
00638     {
00639         loadPackageList( packageList, true );
00640         delete packageList;
00641     }
00642 }
00643 
00644 void MainWindow::slotShowUpdated()
00645 {
00646     OPackageList *packageList;
00647     if ( m_actionShowUpdated->isOn() )
00648     {
00649         m_actionShowInstalled->setOn( false );
00650         m_actionShowNotInstalled->setOn( false );
00651         m_actionFilter->setOn( false );
00652         packageList = m_packman.filterPackages( QString::null, QString::null, QString::null,
00653                                                 OPackageManager::Updated, QString::null );
00654     }
00655     else
00656         packageList = m_packman.packages();
00657 
00658     if ( packageList )
00659     {
00660         loadPackageList( packageList, true );
00661         delete packageList;
00662     }
00663 }
00664 
00665 void MainWindow::slotFilterChange()
00666 {
00667     FilterDlg dlg( this, &m_packman, m_filterName, m_filterServer, m_filterDest, m_filterStatus,
00668                    m_filterCategory );
00669     if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted )
00670     {
00671         m_filterName = dlg.name();
00672         m_filterServer = dlg.server();
00673         m_filterDest = dlg.destination();
00674         m_filterStatus = dlg.status();
00675         m_filterCategory = dlg.category();
00676         m_actionFilter->setOn( true );
00677         slotFilter( true );
00678     }
00679     else
00680     {
00681         m_actionFilter->setOn( false );
00682         slotFilter( false );
00683     }
00684 }
00685 
00686 void MainWindow::slotFilter( bool isOn )
00687 {
00688     OPackageList *packageList;
00689     if ( isOn )
00690     {
00691         // Turn off other filtering options
00692         m_actionShowNotInstalled->setOn( false );
00693         m_actionShowInstalled->setOn( false );
00694         m_actionShowUpdated->setOn( false );
00695 
00696         // If the filter settings have not been set yet, display filter dialog
00697         if ( m_filterName.isNull() && m_filterServer.isNull() && m_filterDest.isNull() &&
00698              m_filterStatus == OPackageManager::NotDefined && m_filterCategory.isNull() )
00699         {
00700             FilterDlg dlg( this, &m_packman, m_filterName, m_filterServer, m_filterDest, m_filterStatus,
00701                         m_filterCategory );
00702             if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted )
00703             {
00704                 m_filterName = dlg.name();
00705                 m_filterServer = dlg.server();
00706                 m_filterDest = dlg.destination();
00707                 m_filterStatus = dlg.status();
00708                 m_filterCategory = dlg.category();
00709                 m_actionFilter->setOn( true );
00710                 packageList = m_packman.filterPackages( m_filterName, m_filterServer, m_filterDest,
00711                                                         m_filterStatus, m_filterCategory );
00712             }
00713             else
00714             {
00715                 m_actionFilter->setOn( false );
00716                 packageList = m_packman.packages();
00717             }
00718         }
00719         else
00720         {
00721             m_actionFilter->setOn( true );
00722             packageList = m_packman.filterPackages( m_filterName, m_filterServer, m_filterDest,
00723                                                     m_filterStatus, m_filterCategory );
00724         }
00725 
00726 
00727     }
00728     else
00729         packageList = m_packman.packages();
00730 
00731     if ( packageList )
00732     {
00733         loadPackageList( packageList, true );
00734         delete packageList;
00735     }
00736 }
00737 
00738 void MainWindow::slotFindShowToolbar()
00739 {
00740     m_findBar.show();
00741     m_findEdit->setFocus();
00742 }
00743 
00744 void MainWindow::slotFindHideToolbar()
00745 {
00746     m_findBar.hide();
00747 }
00748 
00749 void MainWindow::slotFindChanged( const QString &findText )
00750 {
00751 
00752     m_actionFindNext->setEnabled( !findText.isEmpty() );
00753     searchForPackage( findText );
00754 }
00755 
00756 void MainWindow::slotFindNext()
00757 {
00758     searchForPackage( m_findEdit->text() );
00759 }
00760 
00761 void MainWindow::slotDisplayPackageInfo( QListViewItem *packageItem )
00762 {
00763     QString packageName( ( static_cast<QCheckListItem*>( packageItem ) )->text() );
00764 
00765     // Create package manager output widget
00766     PackageInfoDlg *dlg = new PackageInfoDlg( this, &m_packman, packageName );
00767 
00768     // Display widget
00769     m_widgetStack.addWidget( dlg, 3 );
00770     m_widgetStack.raiseWidget( dlg );
00771 }

Generated on Sat Nov 5 16:15:53 2005 for OPIE by  doxygen 1.4.2