-rw-r--r-- | noncore/settings/packagemanager/ChangeLog | 5 | ||||
-rw-r--r-- | noncore/settings/packagemanager/mainwindow.cpp | 5 | ||||
-rw-r--r-- | noncore/settings/packagemanager/oipkg.cpp | 69 | ||||
-rw-r--r-- | noncore/settings/packagemanager/oipkg.h | 8 | ||||
-rw-r--r-- | noncore/settings/packagemanager/opackage.cpp | 5 | ||||
-rw-r--r-- | noncore/settings/packagemanager/opackage.h | 15 | ||||
-rw-r--r-- | noncore/settings/packagemanager/packageinfodlg.cpp | 96 | ||||
-rw-r--r-- | noncore/settings/packagemanager/packageinfodlg.h | 10 |
8 files changed, 169 insertions, 44 deletions
diff --git a/noncore/settings/packagemanager/ChangeLog b/noncore/settings/packagemanager/ChangeLog index efa75b1..72e6169 100644 --- a/noncore/settings/packagemanager/ChangeLog +++ b/noncore/settings/packagemanager/ChangeLog @@ -1,15 +1,20 @@ +2004-mm-dd Dan Williams <drw@handhelds.org> + + * Package information dialog implemented + * What's This app icon enabled + 2004-01-23 Dan Williams <drw@handhelds.org> * Added package download functionality * Have Opie update links after install/removal so that apps will display properly in Launcher 2004-01-20 Dan Williams <drw@handhelds.org> * Released version 0.2.0 * Converted to use libipkg in place of spawning ipkg process 2004-01-13 Dan Williams <drw@handhelds.org> * Released version 0.1.0 * Initial check-in of new package management client to eventually replace AQPkg diff --git a/noncore/settings/packagemanager/mainwindow.cpp b/noncore/settings/packagemanager/mainwindow.cpp index 05f21bc..8b374ab 100644 --- a/noncore/settings/packagemanager/mainwindow.cpp +++ b/noncore/settings/packagemanager/mainwindow.cpp @@ -1,683 +1,682 @@ /* This file is part of the OPIE Project =. Copyright (c) 2003 Dan Williams <drw@handhelds.org> .=l. .>+-= _;:, .> :=|. 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. */ #include <qaction.h> #include <qdir.h> #include <qlayout.h> #include <qlineedit.h> #include <qmenubar.h> #include <qmessagebox.h> #include <qpopupmenu.h> #include <qtimer.h> #include <qtoolbar.h> #include <qwhatsthis.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include "mainwindow.h" #include "installdlg.h" #include "filterdlg.h" #include "promptdlg.h" #include "entrydlg.h" #include "packageinfodlg.h" -MainWindow::MainWindow( QWidget *parent, const char *name, WFlags fl ) - : QMainWindow( parent, name, fl || WStyle_ContextHelp ) +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() ) ); } 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\nClick inside the box at the left to select a package." ) ); 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() { // Build menu and tool bars setToolBarsMovable( false ); m_menuBar.setHorizontalStretchable( true ); QMenuBar *mb = new QMenuBar( &m_menuBar ); mb->setMargin( 0 ); // Find toolbar addToolBar( &m_findBar, QMainWindow::Top, true ); m_findBar.setHorizontalStretchable( true ); m_findEdit = new QLineEdit( &m_findBar ); QWhatsThis::add( m_findEdit, tr( "Type the text to search for here." ) ); m_findBar.setStretchableWidget( m_findEdit ); connect( m_findEdit, SIGNAL(textChanged(const QString &)), this, SLOT(slotFindChanged(const QString &)) ); // Packages menu QPopupMenu *popup = new QPopupMenu( this ); QAction *a = new QAction( tr( "Update lists" ), Resource::loadPixmap( "packagemanager/update" ), QString::null, 0, this, 0 ); a->setWhatsThis( tr( "Click here to update package lists from servers." ) ); connect( a, SIGNAL(activated()), this, SLOT(slotUpdate()) ); a->addTo( popup ); a->addTo( &m_toolBar ); QAction *actionUpgrade = new QAction( tr( "Upgrade" ), Resource::loadPixmap( "packagemanager/upgrade" ), QString::null, 0, this, 0 ); actionUpgrade->setWhatsThis( tr( "Click here to upgrade all installed packages if a newer version is available." ) ); connect( actionUpgrade, SIGNAL(activated()), this, SLOT(slotUpgrade()) ); actionUpgrade->addTo( popup ); actionUpgrade->addTo( &m_toolBar ); QPixmap iconDownload = Resource::loadPixmap( "packagemanager/download" ); QPixmap iconRemove = Resource::loadPixmap( "packagemanager/remove" ); QAction *actionDownload = new QAction( tr( "Download" ), iconDownload, QString::null, 0, this, 0 ); actionDownload->setWhatsThis( tr( "Click here to download the currently selected package(s)." ) ); connect( actionDownload, SIGNAL(activated()), this, SLOT(slotDownload()) ); actionDownload->addTo( popup ); actionDownload->addTo( &m_toolBar ); a = new QAction( tr( "Apply changes" ), Resource::loadPixmap( "packagemanager/apply" ), QString::null, 0, this, 0 ); a->setWhatsThis( tr( "Click here to install, remove or upgrade currently selected package(s)." ) ); connect( a, SIGNAL(activated()), this, SLOT(slotApply()) ); a->addTo( popup ); a->addTo( &m_toolBar ); popup->insertSeparator(); a = new QAction( tr( "Configure" ), Resource::loadPixmap( "SettingsIcon" ), QString::null, 0, this, 0 ); a->setWhatsThis( tr( "Click here to configure this application." ) ); connect( a, SIGNAL(activated()), this, SLOT(slotConfigure()) ); a->addTo( popup ); mb->insertItem( tr( "Actions" ), popup ); // View menu popup = new QPopupMenu( this ); m_actionShowNotInstalled = new QAction( tr( "Show packages not installed" ), QString::null, 0, this, 0 ); m_actionShowNotInstalled->setToggleAction( true ); m_actionShowNotInstalled->setWhatsThis( tr( "Click here to show packages available which have not been installed." ) ); connect( m_actionShowNotInstalled, SIGNAL(activated()), this, SLOT(slotShowNotInstalled()) ); m_actionShowNotInstalled->addTo( popup ); m_actionShowInstalled = new QAction( tr( "Show installed packages" ), QString::null, 0, this, 0 ); m_actionShowInstalled->setToggleAction( true ); m_actionShowInstalled->setWhatsThis( tr( "Click here to show packages currently installed on this device." ) ); connect( m_actionShowInstalled, SIGNAL(activated()), this, SLOT(slotShowInstalled()) ); m_actionShowInstalled->addTo( popup ); m_actionShowUpdated = new QAction( tr( "Show updated packages" ), QString::null, 0, this, 0 ); m_actionShowUpdated->setToggleAction( true ); m_actionShowUpdated->setWhatsThis( tr( "Click here to show packages currently installed on this device which have a newer version available." ) ); connect( m_actionShowUpdated, SIGNAL(activated()), this, SLOT(slotShowUpdated()) ); m_actionShowUpdated->addTo( popup ); popup->insertSeparator(); a = new QAction( tr( "Configure filter" ), QString::null, 0, this, 0 ); a->setWhatsThis( tr( "Click here to change package filter criteria." ) ); connect( a, SIGNAL(activated()), this, SLOT(slotFilterChange()) ); a->addTo( popup ); m_actionFilter = new QAction( tr( "Filter" ), Resource::loadPixmap( "packagemanager/filter" ), QString::null, 0, this, 0 ); m_actionFilter->setToggleAction( true ); m_actionFilter->setWhatsThis( tr( "Click here to apply current filter." ) ); connect( m_actionFilter, SIGNAL(toggled(bool)), this, SLOT(slotFilter(bool)) ); m_actionFilter->addTo( popup ); popup->insertSeparator(); a = new QAction( tr( "Find" ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); a->setWhatsThis( tr( "Click here to search for text in package names." ) ); connect( a, SIGNAL(activated()), this, SLOT(slotFindShowToolbar()) ); a->addTo( popup ); m_actionFindNext = new QAction( tr( "Find next" ), Resource::loadIconSet( "next" ), QString::null, 0, this, 0 ); m_actionFindNext->setEnabled( false ); m_actionFindNext->setWhatsThis( tr( "Click here to find the next package name containing the text you are searching for." ) ); connect( m_actionFindNext, SIGNAL(activated()), this, SLOT(slotFindNext()) ); m_actionFindNext->addTo( popup ); m_actionFindNext->addTo( &m_findBar ); mb->insertItem( tr( "View" ), popup ); // Finish find toolbar creation a = new QAction( QString::null, Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); a->setWhatsThis( tr( "Click here to hide the find toolbar." ) ); connect( a, SIGNAL(activated()), this, SLOT(slotFindHideToolbar()) ); a->addTo( &m_findBar ); m_findBar.hide(); } void MainWindow::loadPackageList( OPackageList *packages, bool clearList ) { if ( clearList ) m_packageList.clear(); 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::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 ); } 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 InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Upgrade installed packages" ), false, OPackage::Upgrade ); connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) ); // Display widget m_widgetStack.addWidget( dlg, 3 ); m_widgetStack.raiseWidget( dlg ); } void MainWindow::slotDownload() { // Retrieve list of packages selected for download (if any) QStringList *workingPackages = new QStringList(); for ( QCheckListItem *item = static_cast<QCheckListItem *>(m_packageList.firstChild()); item != 0 ; item = static_cast<QCheckListItem *>(item->nextSibling()) ) { if ( item->isOn() ) workingPackages->append( item->text() ); } if ( workingPackages->isEmpty() ) { QMessageBox::information( this, tr( "Nothing to do" ), tr( "No packages selected" ), tr( "OK" ) ); return; } else { // Download selected packages m_config.setGroup( "settings" ); QString workingDir = m_config.readEntry( "DownloadDir", "/tmp" ); bool ok = false; QString text = EntryDlg::getText( tr( "Download" ), tr( "Enter path to download package to:" ), workingDir, &ok, this ); if ( ok && !text.isEmpty() ) workingDir = text; // user entered something and pressed ok else return; // user entered nothing or pressed cancel // Store download directory in config file m_config.writeEntry( "DownloadDir", workingDir ); // Get starting directory QDir::setCurrent( workingDir ); // Create package manager output widget InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Download packages" ), false, OPackage::Download, workingPackages ); connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) ); // Display widget m_widgetStack.addWidget( dlg, 3 ); m_widgetStack.raiseWidget( dlg ); } } void MainWindow::slotApply() { QStringList *removeList = 0x0; QStringList *installList = 0x0; QStringList *upgradeList = 0x0; for ( QCheckListItem *item = static_cast<QCheckListItem *>(m_packageList.firstChild()); item != 0 ; item = static_cast<QCheckListItem *>(item->nextSibling()) ) { if ( item->isOn() ) { OPackage *package = m_packman.findPackage( item->text() ); if ( package ) { if ( !package->versionInstalled().isNull() ) { if ( m_packman.compareVersions( package->version(), package->versionInstalled() ) == 1 ) { // Remove/upgrade package int answer = PromptDlg::ask( tr( "Remove or upgrade" ), tr( QString( "Do you wish to remove or upgrade\n%1?" ).arg( item->text() ) ), tr( "Remove" ), tr( "Upgrade" ), this ); if ( answer == 1 ) // Remove { if ( !removeList ) removeList = new QStringList(); removeList->append( item->text() ); } else if ( answer == 2 ) // Upgrade { if ( !upgradeList ) upgradeList = new QStringList(); upgradeList->append( item->text() ); } } else { // Remove/reinstall package int answer = PromptDlg::ask( tr( "Remove or reinstall" ), tr( QString( "Do you wish to remove or reinstall\n%1?" ).arg( item->text() ) ), tr( "Remove" ), tr( "Reinstall" ), this ); if ( answer == 1 ) // Remove { if ( !removeList ) removeList = new QStringList(); removeList->append( item->text() ); } else if ( answer == 2 ) // Reinstall { if ( !installList ) installList = new QStringList(); installList->append( item->text() ); } } } else { // Install package 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::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; } 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 ); packageList = m_packman.filterPackages( QString::null, QString::null, QString::null, OPackageManager::NotInstalled, QString::null ); } else packageList = m_packman.packages(); if ( packageList ) { loadPackageList( packageList, true ); delete packageList; } } void MainWindow::slotShowInstalled() { OPackageList *packageList; if ( m_actionShowInstalled->isOn() ) { m_actionShowNotInstalled->setOn( false ); m_actionShowUpdated->setOn( false ); packageList = m_packman.filterPackages( QString::null, QString::null, QString::null, OPackageManager::Installed, QString::null ); } else packageList = m_packman.packages(); if ( packageList ) { loadPackageList( packageList, true ); delete packageList; } } void MainWindow::slotShowUpdated() { OPackageList *packageList; if ( m_actionShowUpdated->isOn() ) { m_actionShowInstalled->setOn( false ); m_actionShowNotInstalled->setOn( false ); packageList = m_packman.filterPackages( QString::null, QString::null, QString::null, OPackageManager::Updated, QString::null ); } else packageList = m_packman.packages(); if ( packageList ) { loadPackageList( packageList, true ); delete packageList; } } void MainWindow::slotFilterChange() { FilterDlg dlg( this, &m_packman, m_filterName, m_filterServer, m_filterDest, m_filterStatus, m_filterCategory ); if ( dlg.exec() == QDialog::Accepted ) { m_filterName = dlg.name(); m_filterServer = dlg.server(); m_filterDest = dlg.destination(); m_filterStatus = dlg.status(); m_filterCategory = dlg.category(); m_actionFilter->setOn( true ); slotFilter( true ); } else { m_actionFilter->setOn( false ); slotFilter( false ); } } void MainWindow::slotFilter( bool isOn ) { OPackageList *packageList; if ( isOn ) { packageList = m_packman.filterPackages( m_filterName, m_filterServer, m_filterDest, m_filterStatus, m_filterCategory ); } else packageList = m_packman.packages(); if ( packageList ) { loadPackageList( packageList, true ); delete packageList; } } void MainWindow::slotFindShowToolbar() { m_findBar.show(); m_findEdit->setFocus(); } void MainWindow::slotFindHideToolbar() { m_findBar.hide(); } void MainWindow::slotFindChanged( const QString &findText ) { m_actionFindNext->setEnabled( !findText.isEmpty() ); searchForPackage( findText ); } void MainWindow::slotFindNext() { searchForPackage( m_findEdit->text() ); } void MainWindow::slotDisplayPackageInfo( QListViewItem *packageItem ) { QString packageName( ( static_cast<QCheckListItem*>( packageItem ) )->text() ); // Create package manager output widget PackageInfoDlg *dlg = new PackageInfoDlg( this, &m_packman, packageName ); - connect( dlg, SIGNAL(closeInfoDlg()), this, SLOT(slotCloseDlg()) ); // Display widget m_widgetStack.addWidget( dlg, 3 ); m_widgetStack.raiseWidget( dlg ); } diff --git a/noncore/settings/packagemanager/oipkg.cpp b/noncore/settings/packagemanager/oipkg.cpp index ed9ea10..eb07a61 100644 --- a/noncore/settings/packagemanager/oipkg.cpp +++ b/noncore/settings/packagemanager/oipkg.cpp @@ -1,464 +1,511 @@ /* This file is part of the Opie Project Copyright (c) 2003 Dan Williams <drw@handhelds.org> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library 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 program 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 ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "oipkg.h" +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <qdir.h> #include <qfile.h> #include <qmessagebox.h> #include <qtextstream.h> const QString IPKG_CONF = "/etc/ipkg.conf"; // Fully-qualified name of Ipkg primary configuration file const QString IPKG_CONF_DIR = "/etc/ipkg"; // Directory of secondary Ipkg configuration files const QString IPKG_PKG_PATH = "/usr/lib/ipkg/lists"; // Directory containing server package lists const QString IPKG_STATUS_PATH = "usr/lib/ipkg/status"; // Destination status file location OIpkg *oipkg; -int fIpkgMessage( ipkg_conf_t */*conf*/, message_level_t /*level*/, char *msg ) +// Ipkg callback functions + +int fsignalIpkgMessage( ipkg_conf_t */*conf*/, message_level_t /*level*/, char *msg ) { - oipkg->ipkgOutput( msg ); + oipkg->ipkgMessage( msg ); return 0; } -char* fIpkgResponse( char */*question*/ ) +char *fIpkgResponse( char */*question*/ ) { return 0x0; } +int fIpkgStatus( char */*name*/, int /*status*/, char *desc, void */*userdata*/ ) +{ + oipkg->ipkgStatus( desc ); + return 0; +} + +int fIpkgFiles( char */*name*/, char *desc, char */*version*/, pkg_state_status_t /*status*/, + void */*userdata*/ ) +{ +printf( "*****List*****\n%s\n", desc ); + oipkg->ipkgList( desc ); + return 0; +} + OIpkg::OIpkg( Config *config, QObject *parent, const char *name ) : QObject( parent, name ) , m_config( config ) , m_confInfo( NULL ) , m_ipkgExecOptions( 0 ) , m_ipkgExecVerbosity( 1 ) { oipkg = this; // Initialize libipkg - if ( ipkg_init( &fIpkgMessage, &fIpkgResponse, &m_ipkgArgs ) ) + if ( ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs ) ) QMessageBox::critical( 0, tr( "OIpkg" ), tr( "Error initialing libipkg" ) ); // Default ipkg run-time arguments m_ipkgArgs.noaction = false; m_ipkgArgs.force_defaults = true; } OIpkg::~OIpkg() { // Upon destruction, ensure that items in config list are deleted with list if ( m_confInfo ) m_confInfo->setAutoDelete( true ); // Free up libipkg resources if ( ipkg_deinit( &m_ipkgArgs ) ) QMessageBox::critical( 0, tr( "OIpkg" ), tr( "Error freeing libipkg" ) ); } OConfItemList *OIpkg::configItems() { // Retrieve all configuration items return filterConfItems(); } OConfItemList *OIpkg::servers() { // Retrieve only servers return filterConfItems( OConfItem::Source ); } OConfItemList *OIpkg::destinations() { // Retrieve only destinations return filterConfItems( OConfItem::Destination ); } OConfItemList *OIpkg::options() { // Retrieve only destinations return filterConfItems( OConfItem::Option ); } void OIpkg::setConfigItems( OConfItemList *configList ) { if ( m_confInfo ) delete m_confInfo; m_confInfo = configList; } void OIpkg::saveSettings() { // Save Ipkg execution options to application configuration file if ( m_config ) { m_config->setGroup( "Ipkg" ); m_config->writeEntry( "ExecOptions", m_ipkgExecOptions ); m_config->writeEntry( "Verbosity", m_ipkgExecVerbosity ); } } OPackageList *OIpkg::availablePackages( const QString &server ) { // Load Ipkg configuration info if not already cached if ( !m_confInfo ) loadConfiguration(); // Build new server list (caller is responsible for deleting) OPackageList *pl = new OPackageList; // Open package list file QFile f( IPKG_PKG_PATH + "/" + server ); if ( !f.open( IO_ReadOnly ) ) return NULL; QTextStream t( &f ); // Process all information in package list file OPackage *package = NULL; QString line = t.readLine(); while ( !t.eof() ) { // Determine key/value pair int pos = line.find( ':', 0 ); QString key; if ( pos > -1 ) key = line.mid( 0, pos ); else key = QString::null; QString value = line.mid( pos+2, line.length()-pos ); // Allocate new package and insert into list if ( package == NULL && !key.isEmpty() ) { package = new OPackage( value ); package->setSource( server ); pl->append( package ); } // Update package data if ( key == "Package" ) package->setName( value ); else if ( key == "Version" ) package->setVersion( value ); else if ( key == "Section" ) package->setCategory( value ); //DataManager::setAvailableCategories( value ); else if ( key.isEmpty() && value.isEmpty() ) package = NULL; // Skip past all description lines if ( key == "Description" ) { line = t.readLine(); while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() ) line = t.readLine(); } else line = t.readLine(); } f.close(); return pl; } OPackageList *OIpkg::installedPackages( const QString &destName, const QString &destPath ) { // Load Ipkg configuration info if not already cached if ( !m_confInfo ) loadConfiguration(); // Build new server list (caller is responsible for deleting) OPackageList *pl = new OPackageList; // Open status file QString path = destPath; if ( path.right( 1 ) != "/" ) path.append( "/" ); path.append( IPKG_STATUS_PATH ); QFile f( path ); if ( !f.open( IO_ReadOnly ) ) return NULL; QTextStream t( &f ); // Process all information in status file bool newPackage = false; QString line = t.readLine(); QString name; QString version; QString status; while ( !t.eof() ) { // Determine key/value pair int pos = line.find( ':', 0 ); QString key; if ( pos > -1 ) key = line.mid( 0, pos ); else key = QString::null; QString value = line.mid( pos+2, line.length()-pos ); // Allocate new package and insert into list if ( newPackage && !key.isEmpty() ) { // Add to list only if it has a valid name and is installed if ( !name.isNull() && status.contains( " installed" ) ) { pl->append( new OPackage( name, QString::null, version, QString::null, destName ) ); name = QString::null; version = QString::null; status = QString::null; newPackage = false; } } // Update package data if ( key == "Package" ) name = value; else if ( key == "Version" ) version = value; else if ( key == "Status" ) status = value; else if ( key.isEmpty() && value.isEmpty() ) newPackage = true; // Skip past all description lines if ( key == "Description" ) { line = t.readLine(); while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() ) line = t.readLine(); } else line = t.readLine(); } f.close(); return pl; } bool OIpkg::executeCommand( OPackage::Command command, QStringList *parameters, const QString &destination, const QObject *receiver, const char *slotOutput, bool rawOutput ) { if ( command == OPackage::NotDefined ) return false; // Set ipkg run-time options/arguments m_ipkgArgs.force_depends = ( m_ipkgExecOptions & FORCE_DEPENDS ); m_ipkgArgs.force_reinstall = ( m_ipkgExecOptions & FORCE_REINSTALL ); // TODO m_ipkgArgs.force_remove = ( m_ipkgExecOptions & FORCE_REMOVE ); m_ipkgArgs.force_overwrite = ( m_ipkgExecOptions & FORCE_OVERWRITE ); m_ipkgArgs.verbosity = m_ipkgExecVerbosity; if ( m_ipkgArgs.dest ) free( m_ipkgArgs.dest ); if ( !destination.isNull() ) { int len = destination.length() + 1; m_ipkgArgs.dest = (char *)malloc( len ); strncpy( m_ipkgArgs.dest, destination, destination.length() ); m_ipkgArgs.dest[ len - 1 ] = '\0'; } else m_ipkgArgs.dest = 0x0; // Connect output signal to widget + if ( rawOutput ) { - if ( slotOutput ) - connect( this, SIGNAL(execOutput(char *)), receiver, slotOutput ); +// if ( slotOutput ) +// connect( this, SIGNAL(signalIpkgMessage(char *)), receiver, slotOutput ); } else { - // TODO - connect to local slot and parse output before emitting execOutput + // TODO - connect to local slot and parse output before emitting signalIpkgMessage } switch( command ) { - case OPackage::Update : ipkg_lists_update( &m_ipkgArgs ); + case OPackage::Update : { + connect( this, SIGNAL(signalIpkgMessage(char *)), receiver, slotOutput ); + ipkg_lists_update( &m_ipkgArgs ); + }; break; - case OPackage::Upgrade : ipkg_packages_upgrade( &m_ipkgArgs ); + case OPackage::Upgrade : { + connect( this, SIGNAL(signalIpkgMessage(char *)), receiver, slotOutput ); + ipkg_packages_upgrade( &m_ipkgArgs ); + }; break; case OPackage::Install : { + connect( this, SIGNAL(signalIpkgMessage(char *)), receiver, slotOutput ); for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) { ipkg_packages_install( &m_ipkgArgs, (*it) ); } }; break; case OPackage::Remove : { + connect( this, SIGNAL(signalIpkgMessage(char *)), receiver, slotOutput ); for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) { ipkg_packages_remove( &m_ipkgArgs, (*it), true ); } }; break; case OPackage::Download : { + connect( this, SIGNAL(signalIpkgMessage(char *)), receiver, slotOutput ); for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it ) { ipkg_packages_download( &m_ipkgArgs, (*it) ); } }; break; + case OPackage::Info : { + connect( this, SIGNAL(signalIpkgStatus(char *)), receiver, slotOutput ); + ipkg_packages_info( &m_ipkgArgs, (*parameters->begin()), &fIpkgStatus, 0x0 ); + }; + break; + case OPackage::Files : { + connect( this, SIGNAL(signalIpkgList(char *)), receiver, slotOutput ); + ipkg_package_files( &m_ipkgArgs, (*parameters->begin()), &fIpkgFiles, 0x0 ); + }; + break; default : break; }; return true; } -void OIpkg::ipkgOutput( char *msg ) +void OIpkg::ipkgMessage( char *msg ) +{ + emit signalIpkgMessage( msg ); +} + +void OIpkg::ipkgStatus( char *status ) +{ + emit signalIpkgStatus( status ); +} + +void OIpkg::ipkgList( char *filelist ) { - emit execOutput( msg ); + emit signalIpkgList( filelist ); } void OIpkg::loadConfiguration() { if ( m_confInfo ) delete m_confInfo; // Load configuration item list m_confInfo = new OConfItemList(); QStringList confFiles; QDir confDir( IPKG_CONF_DIR ); if ( confDir.exists() ) { confDir.setNameFilter( "*.conf" ); confDir.setFilter( QDir::Files ); confFiles = confDir.entryList( "*.conf", QDir::Files ); confFiles << IPKG_CONF; for ( QStringList::Iterator it = confFiles.begin(); it != confFiles.end(); ++it ) { // Create absolute file path if necessary QString absFile = (*it); if ( !absFile.startsWith( "/" ) ) absFile.prepend( QString( IPKG_CONF_DIR ) + "/" ); // Read in file QFile f( absFile ); if ( f.open( IO_ReadOnly ) ) { QTextStream s( &f ); while ( !s.eof() ) { QString line = s.readLine().simplifyWhiteSpace(); // Parse line and save info to the conf options list if ( !line.isEmpty() ) { if ( !line.startsWith( "#" ) || line.startsWith( "#src" ) || line.startsWith( "#dest" ) || line.startsWith( "#arch" ) || line.startsWith( "#option" ) ) { int pos = line.find( ' ', 1 ); // Type QString typeStr = line.left( pos ); OConfItem::Type type; if ( typeStr == "src" || typeStr == "#src" ) type = OConfItem::Source; else if ( typeStr == "dest" || typeStr == "#dest" ) type = OConfItem::Destination; else if ( typeStr == "option" || typeStr == "#option" ) type = OConfItem::Option; else if ( typeStr == "arch" || typeStr == "#arch" ) type = OConfItem::Arch; else type = OConfItem::NotDefined; ++pos; int endpos = line.find( ' ', pos ); // Name QString name = line.mid( pos, endpos - pos ); // Value QString value = ""; if ( endpos > -1 ) value = line.right( line.length() - endpos - 1 ); // Active bool active = !line.startsWith( "#" ); // Add to list m_confInfo->append( new OConfItem( absFile, type, name, value, active ) ); } } } f.close(); } } } // Load Ipkg execution options from application configuration file if ( m_config ) { m_config->setGroup( "Ipkg" ); m_ipkgExecOptions = m_config->readNumEntry( "ExecOptions", m_ipkgExecOptions ); m_ipkgExecVerbosity = m_config->readNumEntry( "Verbosity", m_ipkgExecVerbosity ); } } OConfItemList *OIpkg::filterConfItems( OConfItem::Type typefilter ) { // Load Ipkg configuration info if not already cached if ( !m_confInfo ) loadConfiguration(); // Build new server list (caller is responsible for deleting) OConfItemList *sl = new OConfItemList; // If typefilter is empty, retrieve all items bool retrieveAll = ( typefilter == OConfItem::NotDefined ); // Parse configuration info for servers OConfItemListIterator it( *m_confInfo ); for ( ; it.current(); ++it ) { OConfItem *item = it.current(); if ( retrieveAll || item->type() == typefilter ) { sl->append( item ); } } return sl; } diff --git a/noncore/settings/packagemanager/oipkg.h b/noncore/settings/packagemanager/oipkg.h index 824fa17..ea126cf 100644 --- a/noncore/settings/packagemanager/oipkg.h +++ b/noncore/settings/packagemanager/oipkg.h @@ -1,101 +1,105 @@ /* This file is part of the Opie Project Copyright (c) 2003 Dan Williams <drw@handhelds.org> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library 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 program 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 ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef OIPKG_H #define OIPKG_H extern "C" { #include <libipkg.h> }; #include <qobject.h> #include <qpe/config.h> #include "oconfitem.h" #include "opackage.h" // Ipkg execution options (m_ipkgExecOptions) #define FORCE_DEPENDS 0x0001 #define FORCE_REMOVE 0x0002 #define FORCE_REINSTALL 0x0004 #define FORCE_OVERWRITE 0x0008 class OConfItemList; class OIpkg : public QObject { Q_OBJECT public: OIpkg( Config *config = 0x0, QObject *parent = 0x0, const char *name = 0x0 ); ~OIpkg(); OConfItemList *configItems(); OConfItemList *servers(); OConfItemList *destinations(); OConfItemList *options(); int ipkgExecOptions() { return m_ipkgExecOptions; } int ipkgExecVerbosity() { return m_ipkgExecVerbosity; } void setConfigItems( OConfItemList *configList ); void setIpkgExecOptions( int options ) { m_ipkgExecOptions = options; } void setIpkgExecVerbosity( int verbosity ) { m_ipkgExecVerbosity = verbosity; } void saveSettings(); OPackageList *availablePackages( const QString &server = QString::null ); OPackageList *installedPackages( const QString &destName = QString::null, const QString &destPath = QString::null ); bool executeCommand( OPackage::Command command = OPackage::NotDefined, QStringList *parameters = 0x0, const QString &destination = QString::null, const QObject *receiver = 0x0, const char *slotOutput = 0x0, bool rawOutput = true ); void abortCommand(); - void ipkgOutput( char *msg ); + void ipkgMessage( char *msg ); + void ipkgStatus( char *status ); + void ipkgList( char *filelist ); private: Config *m_config; // Pointer to application configuration file args_t m_ipkgArgs; // libipkg configuration arguments OConfItemList *m_confInfo; // Contains info from all Ipkg configuration files int m_ipkgExecOptions; // Bit-mapped flags for Ipkg execution options int m_ipkgExecVerbosity; // Ipkg execution verbosity level void loadConfiguration(); OConfItemList *filterConfItems( OConfItem::Type typefilter = OConfItem::NotDefined ); signals: - void execOutput( char *msg ); + void signalIpkgMessage( char *msg ); + void signalIpkgStatus( char *status ); + void signalIpkgList( char *filelist ); }; #endif diff --git a/noncore/settings/packagemanager/opackage.cpp b/noncore/settings/packagemanager/opackage.cpp index 34717e3..37963fa 100644 --- a/noncore/settings/packagemanager/opackage.cpp +++ b/noncore/settings/packagemanager/opackage.cpp @@ -1,43 +1,46 @@ /* This file is part of the Opie Project Copyright (c) 2003 Dan Williams <drw@handhelds.org> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library 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 program 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 ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "opackage.h" OPackage::OPackage( const QString &name, const QString &version, const QString &versionInstalled, - const QString &source, const QString &destination, const QString &category ) + const QString &source, const QString &destination, const QString &category, + const QString &information, const QString &files ) : m_name( name ) , m_version( version ) , m_versionInstalled( versionInstalled ) , m_source( source ) , m_destination( destination ) , m_category( category ) + , m_information( information ) + , m_files( files ) { } diff --git a/noncore/settings/packagemanager/opackage.h b/noncore/settings/packagemanager/opackage.h index 1e2e49f..fbd9ec0 100644 --- a/noncore/settings/packagemanager/opackage.h +++ b/noncore/settings/packagemanager/opackage.h @@ -1,74 +1,81 @@ /* This file is part of the Opie Project Copyright (c) 2003 Dan Williams <drw@handhelds.org> =. .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library 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 program 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 ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef OPACKAGE_H #define OPACKAGE_H #include <qlist.h> #include <qstring.h> class OPackage { public: enum Command { Install, Remove, Update, Upgrade, Download, Info, Files, Version, NotDefined }; - OPackage( const QString &name = 0x0, - const QString &version = 0x0, const QString &versionInstalled = 0x0, - const QString &source = 0x0, const QString &destination = 0x0, - const QString &category = "misc" ); + OPackage( const QString &name= QString::null, + const QString &version= QString::null, const QString &versionInstalled= QString::null, + const QString &source= QString::null, const QString &destination= QString::null, + const QString &category = "misc", const QString &information = QString::null, + const QString &files = QString::null ); const QString &name() { return m_name; } const QString &version() { return m_version; } const QString &versionInstalled() { return m_versionInstalled; } const QString &source() { return m_source; } const QString &destination() { return m_destination; } const QString &category() { return m_category; } + const QString &information() { return m_information; } + const QString &files() { return m_files; } void setName( const QString &name ) { m_name = name; } void setVersion( const QString &version ) { m_version = version; } void setVersionInstalled( const QString &version ) { m_versionInstalled = version; } void setSource( const QString &source ) { m_source = source; } void setDestination( const QString &destination ) { m_destination = destination; } void setCategory( const QString &category ) { m_category = category; } + void setInformation( const QString &information ) { m_information = information; } + void setFiles( const QString &files ) { m_files = files; } private: QString m_name; // Name of item QString m_version; // Available version number of item QString m_versionInstalled; // Installed version number of item, null if not installed QString m_source; // Source feed of available version QString m_destination; // Location item is installed to, null if not installed QString m_category; // Item category + QString m_information; // Package information + QString m_files; // File list information }; typedef QList<OPackage> OPackageList; typedef QListIterator<OPackage> OPackageListIterator; #endif diff --git a/noncore/settings/packagemanager/packageinfodlg.cpp b/noncore/settings/packagemanager/packageinfodlg.cpp index 26356b9..7daf336 100644 --- a/noncore/settings/packagemanager/packageinfodlg.cpp +++ b/noncore/settings/packagemanager/packageinfodlg.cpp @@ -1,82 +1,140 @@ /* This file is part of the OPIE Project =. Copyright (c) 2003 Dan Williams <drw@handhelds.org> .=l. .>+-= _;:, .> :=|. 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. */ #include "packageinfodlg.h" +#include "opackage.h" +#include "opackagemanager.h" #include <qlayout.h> #include <qpushbutton.h> #include <qpe/resource.h> #include <opie/otabwidget.h> PackageInfoDlg::PackageInfoDlg( QWidget *parent, OPackageManager *pm, const QString &package ) : QWidget( 0x0 ) , m_packman( pm ) , m_information( this ) , m_files( this ) { // Initialize UI if ( parent ) parent->setCaption( package ); - QVBoxLayout *layout = new QVBoxLayout( this, 4, 0 ); + QVBoxLayout *layout = new QVBoxLayout( this, 4, 2 ); OTabWidget *tabWidget = new OTabWidget( this ); layout->addWidget( tabWidget ); - QPushButton *btn = new QPushButton( Resource::loadPixmap( "enter" ), tr( "Close" ), this ); - layout->addWidget( btn ); - connect( btn, SIGNAL(clicked()), this, SLOT(slotBtnClose()) ); - // Information tab m_information.reparent( tabWidget, QPoint( 0, 0 ) ); m_information.setReadOnly( true ); tabWidget->addTab( &m_information, "UtilsIcon", tr( "Information" ) ); - // Files tab - QWidget *filesWidget = new QWidget( tabWidget ); - QVBoxLayout *filesLayout = new QVBoxLayout( filesWidget, 4, 0 ); - m_files.reparent( filesWidget, QPoint( 0, 0 ) ); - m_files.setReadOnly( true ); - filesLayout->addWidget( &m_files ); + // Retrive package information + m_package = m_packman->findPackage( package ); + if ( !m_package ) + { + m_information.setText( tr( "Unable to retrieve package information." ) ); + return; + } + + // Display package information + if ( !m_package->information().isNull() ) + m_information.setText( m_package->information() ); + else + { + // Package information is not cached, retrieve it + QStringList list( package ); + m_packman->executeCommand( OPackage::Info, &list, QString::null, this, SLOT(slotInfo(char*)), true ); + } + + // Files tab (display only if package is installed) + if ( !m_package->versionInstalled().isNull() ) + { + QWidget *filesWidget = new QWidget( tabWidget ); + QVBoxLayout *filesLayout = new QVBoxLayout( filesWidget, 2, 2 ); + m_files.reparent( filesWidget, QPoint( 0, 0 ) ); + m_files.setReadOnly( true ); + filesLayout->addWidget( &m_files ); + + QPushButton *btn = new QPushButton( Resource::loadPixmap( "packagemanager/apply" ), + tr( "Retrieve file list" ), filesWidget ); + filesLayout->addWidget( btn ); + connect( btn, SIGNAL(clicked()), this, SLOT(slotBtnFileScan()) ); + tabWidget->addTab( filesWidget, "binary", tr( "File list" ) ); + + tabWidget->setCurrentTab( tr( "Information" ) ); + + // If file list is already cached, display + if ( !m_package->files().isNull() ) + m_files.setText( m_package->files() ); + } + else + m_files.hide(); +} + +PackageInfoDlg::~PackageInfoDlg() +{ + if ( !m_package ) + return; + + // Cache package information + if ( !m_information.text().isNull() ) + m_package->setInformation( m_information.text() ); - btn = new QPushButton( Resource::loadPixmap( "packagemanager/apply" ), tr( "Retrieve file list" ), - filesWidget ); - filesLayout->addWidget( btn ); -// TODO connect( btn, SIGNAL(clicked()), this, SLOT(slotFileScan()) ); - tabWidget->addTab( filesWidget, "binary", tr( "Files" ) ); + // Cache package file list + if ( !m_files.text().isNull() ) + m_package->setFiles( m_files.text() ); +} - tabWidget->setCurrentTab( tr( "Information" ) ); +void PackageInfoDlg::slotBtnFileScan() +{ + m_files.clear(); + + QStringList list( m_package->name() ); + m_packman->executeCommand( OPackage::Files, &list, QString::null, this, SLOT(slotFiles(char*)), true ); } -void PackageInfoDlg::slotBtnClose() +void PackageInfoDlg::slotInfo( char *info ) { - emit closeInfoDlg(); + m_information.append( info ); +} + +void PackageInfoDlg::slotFiles( char *filelist ) +{ + QString str = filelist; + + // Skip first line of output ("Package xxx is installed...") + if ( str.startsWith( "Package " ) ) + str = str.right( str.length() - str.find( '\n' ) - 1 ); + + m_files.append( str ); } diff --git a/noncore/settings/packagemanager/packageinfodlg.h b/noncore/settings/packagemanager/packageinfodlg.h index 09af6f4..13a15e2 100644 --- a/noncore/settings/packagemanager/packageinfodlg.h +++ b/noncore/settings/packagemanager/packageinfodlg.h @@ -1,65 +1,67 @@ /* This file is part of the OPIE Project =. Copyright (c) 2003 Dan Williams <drw@handhelds.org> .=l. .>+-= _;:, .> :=|. 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 PACKAGEINFODLG_H #define PACKAGEINFODLG_H #include <qmultilineedit.h> #include <qwidget.h> #include <opie/oprocess.h> #include "opackage.h" class QPushButton; +class OPackage; class OPackageManager; class PackageInfoDlg : public QWidget { Q_OBJECT public: PackageInfoDlg( QWidget *parent = 0x0, OPackageManager *pm = 0x0, const QString &package = QString::null ); + ~PackageInfoDlg(); private: OPackageManager *m_packman; // Pointer to application instance of package manager + OPackage *m_package; // Pointer to package to display information for // UI controls QMultiLineEdit m_information; // Multi-line edit to display package information QMultiLineEdit m_files; // Multi-line edit to display package file list private slots: - void slotBtnClose(); - -signals: - void closeInfoDlg(); + void slotBtnFileScan(); + void slotInfo( char *info ); + void slotFiles( char *filelist ); }; #endif |