-rw-r--r-- | noncore/settings/packagemanager/mainwindow.cpp | 40 | ||||
-rw-r--r-- | noncore/settings/packagemanager/mainwindow.h | 3 |
2 files changed, 31 insertions, 12 deletions
diff --git a/noncore/settings/packagemanager/mainwindow.cpp b/noncore/settings/packagemanager/mainwindow.cpp index 5a942a1..349094d 100644 --- a/noncore/settings/packagemanager/mainwindow.cpp +++ b/noncore/settings/packagemanager/mainwindow.cpp @@ -46,97 +46,97 @@ _;:, .> :=|. This file is free software; you can #include <qlineedit.h> #include <qmenubar.h> #include <qmessagebox.h> #include <qpopupmenu.h> #include <qtimer.h> #include <qtoolbar.h> #include <qwhatsthis.h> MainWindow::MainWindow( QWidget *parent, const char *name, WFlags /*fl*/ ) : QMainWindow( parent, name, WStyle_ContextHelp ) , m_config( "packman" ) , m_packman( &m_config, this ) , m_menuBar( this ) , m_toolBar( this ) , m_findBar( this ) , m_widgetStack( this ) , m_packageList( this ) , m_statusWidget( this ) , m_statusText( &m_statusWidget ) , m_statusBar( &m_statusWidget ) , m_iconUpdated( Resource::loadPixmap( "packagemanager/updated" ) ) , m_iconInstalled( Resource::loadPixmap( "installed" ) ) , m_iconNull( m_iconUpdated.size() ) , m_filterName( QString::null ) , m_filterServer( QString::null ) , m_filterDest( QString::null ) , m_filterStatus( OPackageManager::NotDefined ) , m_filterCategory( QString::null ) { // setCaption( tr( "Package Manager" ) ); m_iconNull.fill( colorGroup().base() ); connect( &m_widgetStack, SIGNAL(aboutToShow(QWidget*)), this, SLOT(slotWidgetStackShow(QWidget*)) ); // Initialize widget stack, package list and status widget initStatusWidget(); initPackageList(); m_widgetStack.addWidget( &m_statusWidget, 2 ); m_widgetStack.addWidget( &m_packageList, 1 ); setCentralWidget( &m_widgetStack ); // Initialize remaining user interface items initUI(); // Initialize package information - QTimer::singleShot( 100, this, SLOT( initPackageInfo() ) ); + QTimer::singleShot( -1, this, SLOT( initPackageInfo() ) ); } void MainWindow::closeEvent( QCloseEvent *event ) { // Close app only if either the package or status widgets are currently active bool close = m_widgetStack.visibleWidget() == &m_packageList || m_widgetStack.visibleWidget() == &m_statusWidget; if ( close ) { // TODO - write out application configuration settings // Write out package manager configuration settings m_packman.saveSettings(); event->accept(); } else { delete m_widgetStack.visibleWidget(); m_widgetStack.raiseWidget( &m_packageList ); event->ignore(); } } void MainWindow::initPackageList() { m_packageList.addColumn( tr( "Packages" ) ); 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." ) ); QPEApplication::setStylusOperation( m_packageList.viewport(), QPEApplication::RightOnHold ); connect( &m_packageList, SIGNAL(rightButtonPressed(QListViewItem*,const QPoint&,int)), this, SLOT(slotDisplayPackageInfo(QListViewItem*)) ); } void MainWindow::initStatusWidget() { QVBoxLayout *layout = new QVBoxLayout( &m_statusWidget, 4, 4 ); m_statusText.setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); layout->addWidget( &m_statusText ); connect( &m_packman, SIGNAL(initStatus(int)), this, SLOT(slotInitStatusBar(int)) ); connect( &m_packman, SIGNAL(statusText(const QString&)), this, SLOT(slotStatusText(const QString&)) ); connect( &m_packman, SIGNAL(statusBar(int)), this, SLOT(slotStatusBar(int)) ); layout->addWidget( &m_statusBar ); } void MainWindow::initUI() { @@ -264,112 +264,137 @@ void MainWindow::loadPackageList( OPackageList *packages, bool clearList ) if ( packages ) { for ( OPackageListIterator packageIt( *packages ); packageIt.current(); ++packageIt ) { OPackage *package = packageIt.current(); QCheckListItem *item = new QCheckListItem( &m_packageList, package->name(), QCheckListItem::CheckBox ); m_packageList.insertItem( item ); // If a different version of package is available, show update available icon // Otherwise, show installed icon if ( !package->versionInstalled().isNull() ) { if ( m_packman.compareVersions( package->version(), package->versionInstalled() ) == 1 ) item->setPixmap( 0, m_iconUpdated ); else item->setPixmap( 0, m_iconInstalled ); } else item->setPixmap( 0, m_iconNull ); } } } void MainWindow::searchForPackage( const QString &text ) { if ( !text.isEmpty() ) { // look through package list for text startng at current position QCheckListItem *start = static_cast<QCheckListItem *>(m_packageList.currentItem()); if ( start == 0 ) start = static_cast<QCheckListItem *>(m_packageList.firstChild()); // for ( QCheckListItem *item = static_cast<QCheckListItem *>(start->nextSibling()); item != 0 ; for ( QCheckListItem *item = static_cast<QCheckListItem *>(start); item != 0 ; item = static_cast<QCheckListItem *>(item->nextSibling()) ) { if ( item->text().lower().find( text ) != -1 ) { m_packageList.ensureItemVisible( item ); m_packageList.setCurrentItem( item ); break; } } } } +void MainWindow::installLocalPackage( const QString &ipkFile ) +{ + // Install selected file + InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Install local package" ), true, + OPackage::Install, new QStringList( ipkFile ) ); + connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) ); + + // Display widget + m_widgetStack.addWidget( dlg, 3 ); + m_widgetStack.raiseWidget( dlg ); +} + +void MainWindow::setDocument( const QString &ipkFile ) +{ + QString file = ipkFile; + DocLnk lnk( ipkFile ); + if ( lnk.isValid() ) + file = lnk.file(); + + installLocalPackage( file ); +} + void MainWindow::initPackageInfo() { m_widgetStack.raiseWidget( &m_statusWidget ); // Load package list m_packman.loadAvailablePackages(); m_packman.loadInstalledPackages(); OPackageList *packageList = m_packman.packages(); if ( packageList ) { loadPackageList( packageList, true ); delete packageList; } - m_widgetStack.raiseWidget( &m_packageList ); + QWidget *widget = m_widgetStack.widget( 3 ); + if ( !widget ) + widget = &m_packageList; + m_widgetStack.raiseWidget( widget ); } void MainWindow::slotWidgetStackShow( QWidget *widget ) { if ( widget == &m_packageList ) { setCaption( tr( "Package Manager" ) ); m_menuBar.show(); m_toolBar.show(); } else { m_menuBar.hide(); m_toolBar.hide(); } } void MainWindow::slotInitStatusBar( int numSteps ) { m_statusBar.setTotalSteps( numSteps ); } void MainWindow::slotStatusText( const QString &status ) { m_statusText.setText( status ); } void MainWindow::slotStatusBar( int currStep ) { m_statusBar.setProgress( currStep ); } void MainWindow::slotUpdate() { // Create package manager output widget InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Update package information" ), false, OPackage::Update ); connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) ); // Display widget m_widgetStack.addWidget( dlg, 3 ); m_widgetStack.raiseWidget( dlg ); } void MainWindow::slotUpgrade() { // Create package manager output widget @@ -492,106 +517,97 @@ void MainWindow::slotApply() if ( !installList ) installList = new QStringList(); installList->append( item->text() ); } } } } // If nothing is selected, display message and exit if ( !removeList && !installList && !upgradeList ) { QMessageBox::information( this, tr( "Nothing to do" ), tr( "No packages selected" ), tr( "OK" ) ); return; } // Send command only if there are packages to process OPackage::Command removeCmd = OPackage::NotDefined; if ( removeList && !removeList->isEmpty() ) removeCmd = OPackage::Remove; OPackage::Command installCmd = OPackage::NotDefined; if ( installList && !installList->isEmpty() ) installCmd = OPackage::Install; OPackage::Command upgradeCmd = OPackage::NotDefined; if ( upgradeList && !upgradeList->isEmpty() ) upgradeCmd = OPackage::Upgrade; // Create package manager output widget InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Apply changes" ), true, removeCmd, removeList, installCmd, installList, upgradeCmd, upgradeList ); connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) ); // Display widget m_widgetStack.addWidget( dlg, 3 ); m_widgetStack.raiseWidget( dlg ); } void MainWindow::slotInstallLocal() { // Display file open dialog with only package files MimeTypes type; QStringList packages; packages << "application/ipkg"; type.insert( tr( "Application Packages" ), packages ); QString package = Opie::Ui::OFileDialog::getOpenFileName( Opie::Ui::OFileSelector::NORMAL, "/", QString::null, type ); if ( !package.isNull() ) - { - // Install selected file - InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Install local package" ), true, - OPackage::Install, new QStringList( package ) ); - connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) ); - - // Display widget - m_widgetStack.addWidget( dlg, 3 ); - m_widgetStack.raiseWidget( dlg ); - } + installLocalPackage( package ); } void MainWindow::slotCloseDlg() { // Close install dialog delete m_widgetStack.visibleWidget(); // Reload package list initPackageInfo(); // Update Opie launcher links QCopEnvelope e("QPE/System", "linkChanged(QString)"); QString lf = QString::null; e << lf; // Reapply any filters previously set if ( m_actionShowNotInstalled->isOn() ) slotShowNotInstalled(); else if ( m_actionShowInstalled->isOn() ) slotShowInstalled(); else if ( m_actionShowUpdated->isOn() ) slotShowUpdated(); else if ( m_actionFilter->isOn() ) slotFilter( true ); } void MainWindow::slotConfigure() { if ( m_packman.configureDlg( false ) ) { if ( PromptDlg::ask( tr( "Config updated" ), tr( "The configuration has been updated. Do you want to update server and package information now?" ), tr( "Yes" ), tr( "No" ), this ) == 1 ) { // Update package list and reload package info slotUpdate(); } } } void MainWindow::slotShowNotInstalled() { OPackageList *packageList; if ( m_actionShowNotInstalled->isOn() ) { m_actionShowInstalled->setOn( false ); m_actionShowUpdated->setOn( false ); m_actionFilter->setOn( false ); diff --git a/noncore/settings/packagemanager/mainwindow.h b/noncore/settings/packagemanager/mainwindow.h index 7968614..103c664 100644 --- a/noncore/settings/packagemanager/mainwindow.h +++ b/noncore/settings/packagemanager/mainwindow.h @@ -56,85 +56,88 @@ public: protected: void closeEvent( QCloseEvent *event ); private: Config m_config; // Configuration file OPackageManager m_packman; // Package manager // Toolbars QToolBar m_menuBar; // Main toolbar containing menu QToolBar m_toolBar; // Main toolbar QToolBar m_findBar; // Find toolbar QWidgetStack m_widgetStack; // Main widget stack which contains m_packageList & m_statusWidget QListView m_packageList; // Main list view of all packages QLineEdit *m_findEdit; // Line edit box used for find toolbar // Status widget controls QWidget m_statusWidget; // Widget to display status during long operations QLabel m_statusText; // Text status message QProgressBar m_statusBar; // Progress bar showing % completed // Icon pixmaps QPixmap m_iconUpdated; // Cached icon which shows when package can be updated QPixmap m_iconInstalled; // Cached icon which shows when package is installed QPixmap m_iconNull; // Cached icon which shows when package is not installed // Menu/tool bar actions QAction *m_actionShowNotInstalled; // Action to show pakages not currently installed QAction *m_actionShowInstalled; // Action to show pakages currently installed QAction *m_actionShowUpdated; // Action to show pakages currently installed with update available QAction *m_actionFilter; // Action to filter packages QAction *m_actionFindNext; // Action to find next match // Cached filter settings QString m_filterName; // Cached name filter value QString m_filterServer; // Cached server name filter value QString m_filterDest; // Cached destination name filter value OPackageManager::Status m_filterStatus; // Cached status filter value QString m_filterCategory; // Cached category filter value void initPackageList(); void initStatusWidget(); void initUI(); void loadPackageList( OPackageList *packages = 0x0, bool clearList = true ); void searchForPackage( const QString &text ); + void installLocalPackage( const QString &ipkFile ); private slots: + void setDocument( const QString &ipkFile ); + void initPackageInfo(); void slotWidgetStackShow( QWidget *widget ); // Status widget slots void slotInitStatusBar( int numSteps ); void slotStatusText( const QString &status ); void slotStatusBar( int currStep ); // Actions menu action slots void slotUpdate(); void slotUpgrade(); void slotDownload(); void slotApply(); void slotInstallLocal(); void slotCloseDlg(); void slotConfigure(); // View menu action slots void slotShowNotInstalled(); void slotShowInstalled(); void slotShowUpdated(); void slotFilterChange(); void slotFilter( bool isOn ); // Find action slots void slotFindShowToolbar(); void slotFindHideToolbar(); void slotFindChanged( const QString &findText ); void slotFindNext(); // Other slots void slotDisplayPackageInfo( QListViewItem * ); }; #endif |