author | drw <drw> | 2003-04-20 23:58:21 (UTC) |
---|---|---|
committer | drw <drw> | 2003-04-20 23:58:21 (UTC) |
commit | 9163bfcc25b78477a75a153f2a75be30ad297c6a (patch) (side-by-side diff) | |
tree | 668e10a9bb0ca7937e3f630a62d3afbbbbf06438 | |
parent | 6b78c023f67433b8f38d9e77598b8530988bfec8 (diff) | |
download | opie-9163bfcc25b78477a75a153f2a75be30ad297c6a.zip opie-9163bfcc25b78477a75a153f2a75be30ad297c6a.tar.gz opie-9163bfcc25b78477a75a153f2a75be30ad297c6a.tar.bz2 |
Finally fixed it so that packages are not incorrectly marked as having an update available
-rw-r--r-- | noncore/settings/aqpkg/mainwin.cpp | 6 | ||||
-rw-r--r-- | noncore/settings/aqpkg/package.cpp | 5 | ||||
-rw-r--r-- | noncore/settings/aqpkg/package.h | 19 | ||||
-rw-r--r-- | noncore/settings/aqpkg/server.cpp | 2 |
4 files changed, 16 insertions, 16 deletions
diff --git a/noncore/settings/aqpkg/mainwin.cpp b/noncore/settings/aqpkg/mainwin.cpp index 6ea619c..fb40d52 100644 --- a/noncore/settings/aqpkg/mainwin.cpp +++ b/noncore/settings/aqpkg/mainwin.cpp @@ -258,794 +258,792 @@ void MainWindow :: initProgressWidget() m_status = new QLabel( progressWindow ); m_status->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); layout->addWidget( m_status ); m_progress = new QProgressBar( progressWindow ); layout->addWidget( m_progress ); } void MainWindow :: init() { #ifdef QWS // read download directory from config file Config cfg( "aqpkg" ); cfg.setGroup( "settings" ); currentlySelectedServer = cfg.readEntry( "selectedServer", "local" ); // showJumpTo = cfg.readBoolEntry( "showJumpTo", "true" ); #endif stack->raiseWidget( progressWindow ); mgr = new DataManager(); connect( mgr, SIGNAL( progressSetSteps( int ) ), this, SLOT( setProgressSteps( int ) ) ); connect( mgr, SIGNAL( progressSetMessage( const QString & ) ), this, SLOT( setProgressMessage( const QString & ) ) ); connect( mgr, SIGNAL( progressUpdate( int ) ), this, SLOT( updateProgress( int ) ) ); mgr->loadServers(); showUninstalledPkgs = false; showInstalledPkgs = false; showUpgradedPkgs = false; categoryFilterEnabled = false; updateData(); stack->raiseWidget( networkPkgWindow ); } /* void MainWindow :: setDocument( const QString &doc ) { // Remove path from package QString package = Utils::getPackageNameFromIpkFilename( doc ); // std::cout << "Selecting package " << package << std::endl; // First select local server for ( int i = 0 ; i < serversList->count() ; ++i ) { if ( serversList->text( i ) == LOCAL_IPKGS ) { serversList->setCurrentItem( i ); break; } } serverSelected( 0 ); // Now set the check box of the selected package for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); item != 0 ; item = (QCheckListItem *)item->nextSibling() ) { if ( item->text().startsWith( package ) ) { item->setOn( true ); break; } } } */ void MainWindow :: displaySettings() { SettingsImpl *dlg = new SettingsImpl( mgr, this, "Settings", true ); if ( dlg->showDlg() ) { stack->raiseWidget( progressWindow ); updateData(); stack->raiseWidget( networkPkgWindow ); } delete dlg; } void MainWindow :: closeEvent( QCloseEvent *e ) { // If install dialog is visible, return to main view, otherwise close app QWidget *widget = stack->visibleWidget(); if ( widget != networkPkgWindow && widget != progressWindow ) { if ( widget ) delete widget; stack->raiseWidget( networkPkgWindow ); e->ignore(); } else { e->accept(); } } void MainWindow :: displayFindBar() { findBar->show(); findEdit->setFocus(); } void MainWindow :: displayJumpBar() { jumpBar->show(); } void MainWindow :: repeatFind() { searchForPackage( findEdit->text() ); } void MainWindow :: findPackage( const QString &text ) { actionFindNext->setEnabled( !text.isEmpty() ); searchForPackage( text ); } void MainWindow :: hideFindBar() { findBar->hide(); } void MainWindow :: hideJumpBar() { jumpBar->hide(); } void MainWindow :: filterUninstalledPackages() { showUninstalledPkgs = actionUninstalled->isOn(); if ( showUninstalledPkgs ) { showInstalledPkgs = FALSE; showUpgradedPkgs = FALSE; } serverSelected( -1 ); actionInstalled->setOn( FALSE ); actionUpdated->setOn( FALSE ); } void MainWindow :: filterInstalledPackages() { showInstalledPkgs = actionInstalled->isOn(); if ( showInstalledPkgs ) { showUninstalledPkgs = FALSE; showUpgradedPkgs = FALSE; } serverSelected( -1 ); actionUninstalled->setOn( FALSE ); actionUpdated->setOn( FALSE ); } void MainWindow :: filterUpgradedPackages() { showUpgradedPkgs = actionUpdated->isOn(); if ( showUpgradedPkgs ) { showUninstalledPkgs = FALSE; showInstalledPkgs = FALSE; } serverSelected( -1 ); actionUninstalled->setOn( FALSE ); actionInstalled->setOn( FALSE ); } bool MainWindow :: setFilterCategory() { // Get categories; CategoryFilterImpl dlg( DataManager::getAvailableCategories(), categoryFilter, this ); if ( dlg.exec() == QDialog::Accepted ) { categoryFilter = dlg.getSelectedFilter(); if ( categoryFilter == "" ) return false; categoryFilterEnabled = true; serverSelected( -1 ); actionFilter->setOn( TRUE ); return true; } return false; } void MainWindow :: filterCategory() { if ( !actionFilter->isOn() ) { filterByCategory( FALSE ); } else { actionFilter->setOn( filterByCategory( TRUE ) ); } } bool MainWindow :: filterByCategory( bool val ) { if ( val ) { if ( categoryFilter == "" ) { if ( !setFilterCategory() ) return false; } categoryFilterEnabled = true; serverSelected( -1 ); return true; } else { // Turn off filter categoryFilterEnabled = false; serverSelected( -1 ); return false; } } void MainWindow :: raiseMainWidget() { stack->raiseWidget( networkPkgWindow ); } void MainWindow :: raiseProgressWidget() { stack->raiseWidget( progressWindow ); } void MainWindow :: enableUpgrade( bool enabled ) { actionUpgrade->setEnabled( enabled ); } void MainWindow :: enableDownload( bool enabled ) { if ( enabled ) { actionDownload->setIconSet( iconDownload ); actionDownload->setText( tr( "Download" ) ); actionDownload->setWhatsThis( tr( "Click here to download the currently selected package(s)." ) ); } else { actionDownload->setIconSet( iconRemove ); actionDownload->setText( tr( "Remove" ) ); actionDownload->setWhatsThis( tr( "Click here to uninstall the currently selected package(s)." ) ); } } void MainWindow :: setProgressSteps( int numsteps ) { m_progress->setTotalSteps( numsteps ); } void MainWindow :: setProgressMessage( const QString &msg ) { m_status->setText( msg ); } void MainWindow :: updateProgress( int progress ) { m_progress->setProgress( progress ); } void MainWindow :: updateData() { m_progress->setTotalSteps( mgr->getServerList().count() ); serversList->clear(); packagesList->clear(); int activeItem = -1; int i = 0; QString serverName; QListIterator<Server> it( mgr->getServerList() ); Server *server; for ( ; it.current(); ++it, ++i ) { server = it.current(); serverName = server->getServerName(); m_status->setText( tr( "Building server list:\n\t%1" ).arg( serverName ) ); m_progress->setProgress( i ); qApp->processEvents(); // cout << "Adding " << it->getServerName() << " to combobox" << endl; if ( !server->isServerActive() ) { // cout << serverName << " is not active" << endl; i--; continue; } serversList->insertItem( serverName ); if ( serverName == currentlySelectedServer ) activeItem = i; } // set selected server to be active server if ( activeItem != -1 ) serversList->setCurrentItem( activeItem ); serverSelected( 0, FALSE ); } void MainWindow :: serverSelected( int index ) { serverSelected( index, TRUE ); } void MainWindow :: serverSelected( int, bool raiseProgress ) { QPixmap nullIcon( installedIcon.size() ); nullIcon.fill( colorGroup().base() ); // display packages QString serverName = serversList->currentText(); currentlySelectedServer = serverName; Server *s = mgr->getServer( serverName ); QList<Package> &list = s->getPackageList(); QListIterator<Package> it( list ); // Display progress widget while loading list bool doProgress = ( list.count() > 200 ); if ( doProgress ) { if ( raiseProgress ) { stack->raiseWidget( progressWindow ); } m_progress->setTotalSteps( list.count() ); m_status->setText( tr( "Building package list for:\n\t%1" ).arg( serverName ) ); } packagesList->clear(); #ifdef QWS // read download directory from config file Config cfg( "aqpkg" ); cfg.setGroup( "settings" ); cfg.writeEntry( "selectedServer", currentlySelectedServer ); #endif int i = 0; Package *package; for ( ; it.current(); ++it ) { // Update progress after every 100th package (arbitrary value, seems to give good balance) i++; if ( ( i % 100 ) == 0 ) { if ( doProgress ) { m_progress->setProgress( i ); } qApp->processEvents(); } QString text = ""; package = it.current(); // Apply show only uninstalled packages filter if ( showUninstalledPkgs && package->isInstalled() ) continue; // Apply show only installed packages filter if ( showInstalledPkgs && !package->isInstalled() ) continue; // Apply show only new installed packages filter if ( showUpgradedPkgs ) { - if ( !package->isInstalled() || - compareVersions( package->getInstalledVersion(), package->getVersion() ) != 1 ) + if ( !package->isInstalled() || !package->getNewVersionAvailable() ) continue; } // Apply the section filter if ( categoryFilterEnabled && categoryFilter != "" ) { if ( package->getSection() == "" || categoryFilter.find( package->getSection().lower() ) == -1 ) continue; } // If the local server, only display installed packages if ( serverName == LOCAL_SERVER && !package->isInstalled() ) continue; QCheckListItem *item = new QCheckListItem( packagesList, package->getPackageName(), QCheckListItem::CheckBox ); if ( package->isInstalled() ) { // If a different version of package is available, show update available icon // Otherwise, show installed icon - if ( package->getVersion() != package->getInstalledVersion() && - compareVersions( package->getInstalledVersion(), package->getVersion() ) == 1) + if ( package->getNewVersionAvailable()) { item->setPixmap( 0, updatedIcon ); } else { item->setPixmap( 0, installedIcon ); } QString destName = ""; if ( package->getLocalPackage() ) { if ( package->getLocalPackage()->getInstalledTo() ) destName = package->getLocalPackage()->getInstalledTo()->getDestinationName(); } else { if ( package->getInstalledTo() ) destName = package->getInstalledTo()->getDestinationName(); } if ( destName != "" ) new QCheckListItem( item, QString( tr( "Installed To - %1" ).arg( destName ) ) ); } else { item->setPixmap( 0, nullIcon ); } if ( !package->isPackageStoredLocally() ) { new QCheckListItem( item, QString( tr( "Description - %1" ).arg( package->getDescription() ) ) ); new QCheckListItem( item, QString( tr( "Size - %1" ).arg( package->getPackageSize() ) ) ); new QCheckListItem( item, QString( tr( "Section - %1" ).arg( package->getSection() ) ) ); } else new QCheckListItem( item, QString( tr( "Filename - %1" ).arg( package->getFilename() ) ) ); if ( serverName == LOCAL_SERVER ) { new QCheckListItem( item, QString( tr( "V. Installed - %1" ).arg( package->getVersion() ) ) ); } else { new QCheckListItem( item, QString( tr( "V. Available - %1" ).arg( package->getVersion() ) ) ); if ( package->getLocalPackage() ) { if ( package->isInstalled() ) new QCheckListItem( item, QString( tr( "V. Installed - %1" ).arg( package->getInstalledVersion() ) ) ); } } packagesList->insertItem( item ); } // If the local server or the local ipkgs server disable the download button if ( serverName == LOCAL_SERVER ) { downloadEnabled = TRUE; actionUpgrade->setEnabled( FALSE ); } else if ( serverName == LOCAL_IPKGS ) { downloadEnabled = FALSE; actionUpgrade->setEnabled( FALSE ); } else { downloadEnabled = TRUE; actionUpgrade->setEnabled( TRUE ); } enableDownload( downloadEnabled ); // Display this widget once everything is done if ( doProgress && raiseProgress ) { stack->raiseWidget( networkPkgWindow ); } } void MainWindow :: searchForPackage( const QString &text ) { if ( !text.isEmpty() ) { // cout << "searching for " << text << endl; // look through package list for text startng at current position // vector<InstallData> workingPackages; QCheckListItem *start = (QCheckListItem *)packagesList->currentItem(); // if ( start != 0 ) // start = (QCheckListItem *)start->nextSibling(); if ( start == 0 ) start = (QCheckListItem *)packagesList->firstChild(); for ( QCheckListItem *item = start; item != 0 ; item = (QCheckListItem *)item->nextSibling() ) { // cout << "checking " << item->text().lower() << endl; if ( item->text().lower().find( text ) != -1 ) { // cout << "matched " << item->text() << endl; packagesList->ensureItemVisible( item ); packagesList->setCurrentItem( item ); break; } } } } void MainWindow :: updateServer() { QString serverName = serversList->currentText(); // Update the current server // Display dialog // Disable buttons to stop silly people clicking lots on them :) // First, write out ipkg_conf file so that ipkg can use it mgr->writeOutIpkgConf(); Ipkg *ipkg = new Ipkg; ipkg->setOption( "update" ); InstallDlgImpl *dlg = new InstallDlgImpl( ipkg, tr( "Refreshing server package lists" ), tr( "Update lists" ) ); connect( dlg, SIGNAL( reloadData( InstallDlgImpl * ) ), this, SLOT( reloadData( InstallDlgImpl * ) ) ); stack->addWidget( dlg, 3 ); stack->raiseWidget( dlg ); // delete progDlg; } void MainWindow :: upgradePackages() { // We're gonna do an upgrade of all packages // First warn user that this isn't recommended // TODO - ODevice???? QString text = tr( "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n" ); QMessageBox warn( tr( "Warning" ), text, QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No | QMessageBox::Escape | QMessageBox::Default , 0, this ); warn.adjustSize(); if ( warn.exec() == QMessageBox::Yes ) { // First, write out ipkg_conf file so that ipkg can use it mgr->writeOutIpkgConf(); // Now run upgrade Ipkg *ipkg = new Ipkg; ipkg->setOption( "upgrade" ); InstallDlgImpl *dlg = new InstallDlgImpl( ipkg, tr( "Upgrading installed packages" ), tr ( "Upgrade" ) ); connect( dlg, SIGNAL( reloadData( InstallDlgImpl * ) ), this, SLOT( reloadData( InstallDlgImpl * ) ) ); stack->addWidget( dlg, 3 ); stack->raiseWidget( dlg ); } } void MainWindow :: downloadPackage() { bool doUpdate = true; if ( downloadEnabled ) { // See if any packages are selected bool found = false; if ( serversList->currentText() != LOCAL_SERVER ) { for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); item != 0 && !found; item = (QCheckListItem *)item->nextSibling() ) { if ( item->isOn() ) found = true; } } // If user selected some packages then download the and store the locally // otherwise, display dialog asking user what package to download from an http server // and whether to install it if ( found ) downloadSelectedPackages(); else downloadRemotePackage(); } else { doUpdate = false; for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); item != 0 ; item = (QCheckListItem *)item->nextSibling() ) { if ( item->isOn() ) { QString name = item->text(); int pos = name.find( "*" ); name.truncate( pos ); // if (there is a (installed), remove it pos = name.find( "(installed)" ); if ( pos > 0 ) name.truncate( pos - 1 ); Package *p = mgr->getServer( serversList->currentText() )->getPackage( name ); QString msgtext; msgtext = tr( "Are you sure you wish to delete\n%1?" ).arg( (const char *)p->getPackageName() ); if ( QMessageBox::information( this, tr( "Are you sure?" ), msgtext, tr( "No" ), tr( "Yes" ) ) == 1 ) { doUpdate = true; QFile f( p->getFilename() ); f.remove(); } } } } if ( doUpdate ) { reloadData( 0x0 ); } } void MainWindow :: downloadSelectedPackages() { // First, write out ipkg_conf file so that ipkg can use it mgr->writeOutIpkgConf(); // Display dialog to user asking where to download the files to bool ok = FALSE; QString dir = ""; #ifdef QWS // read download directory from config file Config cfg( "aqpkg" ); cfg.setGroup( "settings" ); dir = cfg.readEntry( "downloadDir", "/home/root/Documents/application/ipkg" ); #endif QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), dir, &ok, this ); if ( ok && !text.isEmpty() ) dir = text; // user entered something and pressed ok else return; // user entered nothing or pressed cancel #ifdef QWS // Store download directory in config file cfg.writeEntry( "downloadDir", dir ); #endif // Get starting directory char initDir[PATH_MAX]; getcwd( initDir, PATH_MAX ); // Download each package Ipkg ipkg; connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); ipkg.setOption( "download" ); ipkg.setRuntimeDirectory( dir ); for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); item != 0 ; item = (QCheckListItem *)item->nextSibling() ) { if ( item->isOn() ) { ipkg.setPackage( item->text() ); ipkg.runIpkg( ); } } } void MainWindow :: downloadRemotePackage() { // Display dialog bool ok; QString package = InputDialog::getText( tr( "Install Remote Package" ), tr( "Enter package location" ), "http://", &ok, this ); if ( !ok || package.isEmpty() ) return; // DownloadRemoteDlgImpl dlg( this, "Install", true ); // if ( dlg.exec() == QDialog::Rejected ) // return; // grab details from dialog // QString package = dlg.getPackageLocation(); InstallData *item = new InstallData(); item->option = "I"; item->packageName = package; QList<InstallData> workingPackages; workingPackages.setAutoDelete( TRUE ); workingPackages.append( item ); InstallDlgImpl *dlg = new InstallDlgImpl( workingPackages, mgr, tr( "Download" ) ); connect( dlg, SIGNAL( reloadData( InstallDlgImpl * ) ), this, SLOT( reloadData( InstallDlgImpl * ) ) ); stack->addWidget( dlg, 3 ); stack->raiseWidget( dlg ); } void MainWindow :: applyChanges() { stickyOption = ""; // First, write out ipkg_conf file so that ipkg can use it mgr->writeOutIpkgConf(); // Now for each selected item // deal with it QList<InstallData> workingPackages; workingPackages.setAutoDelete( TRUE ); for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); item != 0 ; item = (QCheckListItem *)item->nextSibling() ) { if ( item->isOn() ) { workingPackages.append( dealWithItem( item ) ); } } if ( workingPackages.count() == 0 ) { // Nothing to do QMessageBox::information( this, tr( "Nothing to do" ), tr( "No packages selected" ), tr( "OK" ) ); return; } // do the stuff InstallDlgImpl *dlg = new InstallDlgImpl( workingPackages, mgr, tr( "Apply changes" ) ); connect( dlg, SIGNAL( reloadData( InstallDlgImpl * ) ), this, SLOT( reloadData( InstallDlgImpl * ) ) ); stack->addWidget( dlg, 3 ); stack->raiseWidget( dlg ); } // decide what to do - either remove, upgrade or install // Current rules: // If not installed - install // If installed and different version available - upgrade // If installed and version up to date - remove InstallData *MainWindow :: dealWithItem( QCheckListItem *item ) { QString name = item->text(); // Get package Server *s = mgr->getServer( serversList->currentText() ); Package *p = s->getPackage( name ); // If the package has a filename then it is a local file if ( p->isPackageStoredLocally() ) name = p->getFilename(); QString option; QString dest = "root"; if ( !p->isInstalled() ) { InstallData *newitem = new InstallData();; newitem->option = "I"; newitem->packageName = name; return newitem; } else { InstallData *newitem = new InstallData();; newitem->option = "D"; if ( !p->isPackageStoredLocally() ) newitem->packageName = p->getInstalledPackageName(); else newitem->packageName = name; if ( p->getInstalledTo() ) { newitem->destination = p->getInstalledTo(); // cout << "dest - " << p->getInstalledTo()->getDestinationName() << endl; // cout << "dest - " << p->getInstalledTo()->getDestinationPath() << endl; } else { diff --git a/noncore/settings/aqpkg/package.cpp b/noncore/settings/aqpkg/package.cpp index 83e0706..3395870 100644 --- a/noncore/settings/aqpkg/package.cpp +++ b/noncore/settings/aqpkg/package.cpp @@ -1,144 +1,145 @@ /*************************************************************************** package.cpp - description ------------------- begin : Mon Aug 26 2002 copyright : (C) 2002 by Andy Qua email : andy.qua@blueyonder.co.uk ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "package.h" #include "global.h" Package::Package( QString &name ) { packageName = name; version = "N/A"; description = "N/A"; packageSize = "N/A"; section = "N/A"; localPackage = 0; installed = false; packageStoredLocally = false; installedToRoot = false; installed = false; installedTo = 0; } Package::Package( char *name ) { packageName = name; version = "N/A"; description = "N/A"; packageSize = "N/A"; section = "N/A"; localPackage = 0; installed = false; packageStoredLocally = false; installedToRoot = false; installed = false; installedTo = 0; + differentVersionAvailable = false; } Package::~Package() { } QString Package :: toString() { QString ret = "Package - " + getPackageName() + "\n version - " + getVersion(); if ( localPackage ) ret += "\n inst version - " + localPackage->getVersion(); return ret; } void Package :: setStatus( const QString &s ) { QString state_status; int two, three; status = s.simplifyWhiteSpace( ); two = status.find( " " ); // find second column three = status.find( " ", two + 1 ); // find third column state_status = status.mid( three ).stripWhiteSpace( ); if ( state_status == "installed" ) installed = true; } void Package :: setLocalPackage( Package *p ) { localPackage = p; if ( localPackage ) - if ( localPackage->getVersion() != getVersion() ) + if ( localPackage->getVersion() < getVersion() && !installed ) differentVersionAvailable = true; else differentVersionAvailable = false; } void Package :: setVersion( const QString &v ) { version = v; if ( localPackage ) - if ( localPackage->getVersion() != getVersion() ) + if ( localPackage->getVersion() < getVersion() && !installed ) differentVersionAvailable = true; else differentVersionAvailable = false; } void Package :: setPackageName( const QString &name ) { packageName = name; } void Package :: setDescription( const QString &d ) { description = d; } void Package :: setFilename( const QString &f ) { filename = f; } QString Package :: getInstalledVersion() { if ( localPackage ) return localPackage->getVersion(); else return getVersion(); } QString Package :: getInstalledPackageName() { if ( localPackage ) return localPackage->getPackageName(); else return getPackageName(); } bool Package :: isInstalled() { return installed || ( localPackage && localPackage->isInstalled() ); } diff --git a/noncore/settings/aqpkg/package.h b/noncore/settings/aqpkg/package.h index f5a132f..110ae91 100644 --- a/noncore/settings/aqpkg/package.h +++ b/noncore/settings/aqpkg/package.h @@ -1,89 +1,90 @@ /*************************************************************************** package.h - description ------------------- begin : Mon Aug 26 2002 copyright : (C) 2002 by Andy Qua email : andy.qua@blueyonder.co.uk ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef PACKAGE_H #define PACKAGE_H #include <stdlib.h> /** *@author Andy Qua */ #include <qstring.h> #include "destination.h" class Package { public: Package( QString &name ); Package( char *name ); ~Package(); void setLocalPackage( Package *p ); void setPackageName( const QString &name ); void setVersion( const QString &v ); void setStatus( const QString &s ); void setDescription( const QString &d ); void setFilename( const QString &f ); void setPackageStoredLocally( bool local ) { packageStoredLocally = local; } void setInstalledToRoot( bool root ) { installedToRoot = root; } void setInstalledTo( Destination *d ) { installedTo = d; } void setDependancies( QString &deps ) { dependancies = deps; } void setPackageSize( const QString &size ) { packageSize = size; } void setSection( const QString §) { section = sect; } - Package *getLocalPackage() { return localPackage; } - QString getPackageName() { return packageName; } - QString getVersion() { return version; } - QString getStatus() { return status; } - QString getDescription() { return description; } - QString getFilename() { return filename; } - QString getDependancies() { return dependancies; } - QString getPackageSize() { return packageSize; } - QString getSection() { return section; } + Package *getLocalPackage() { return localPackage; } + QString getPackageName() { return packageName; } + QString getVersion() { return version; } + QString getStatus() { return status; } + QString getDescription() { return description; } + QString getFilename() { return filename; } + QString getDependancies() { return dependancies; } + QString getPackageSize() { return packageSize; } + QString getSection() { return section; } + bool getNewVersionAvailable() { return differentVersionAvailable; } bool isInstalled(); bool isPackageStoredLocally() { return packageStoredLocally; } bool isInstalledToRoot() { return installedToRoot; } QString getInstalledVersion(); QString getInstalledPackageName(); Destination *getInstalledTo() { return installedTo; } QString toString(); private: Package *localPackage; QString packageName; QString version; QString status; QString description; QString filename; bool packageStoredLocally; bool installedToRoot; bool installed; bool differentVersionAvailable; QString dependancies; QString packageSize; QString section; Destination *installedTo; }; #endif diff --git a/noncore/settings/aqpkg/server.cpp b/noncore/settings/aqpkg/server.cpp index 9a239a5..e2b8096 100644 --- a/noncore/settings/aqpkg/server.cpp +++ b/noncore/settings/aqpkg/server.cpp @@ -1,307 +1,307 @@ /*************************************************************************** server.cpp - description ------------------- begin : Mon Aug 26 2002 copyright : (C) 2002 by Andy Qua email : andy.qua@blueyonder.co.uk description : This class holds details about a server : e.g. all the packages that contained on the server : the installation status ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "server.h" #include "datamgr.h" #include <qfile.h> #include <qtextstream.h> #ifdef QWS #include <qpe/global.h> #include <qpe/applnk.h> #include <qlist.h> #endif #include "utils.h" #include "global.h" Server :: Server( const char *name, const char *url ) { serverName = name; serverUrl = url; packageFile = IPKG_DIR; active = true; packageFile += "lists/" + serverName; } Server :: ~Server() { cleanUp(); } void Server :: cleanUp() { packageList.clear(); } void Server :: readStatusFile( QList<Destination> &destList ) { cleanUp(); Destination *dest; QListIterator<Destination> dit( destList ); bool rootRead = false; for ( ; dit.current(); ++dit ) { dest = dit.current(); bool installingToRoot = false; QString path = dest->getDestinationPath(); if ( path.right( 1 ) != "/" ) path.append( "/" ); if ( path == "/" ) { rootRead = true; installingToRoot = true; } packageFile = path; packageFile.append( "usr/lib/ipkg/status" ); readPackageFile( 0, false, installingToRoot, &( *dest ) ); } // Ensure that the root status file is read if ( !rootRead ) { //cout << "Reading status file " << "/usr/lib/ipkg/status" << endl; packageFile = "/usr/lib/ipkg/status"; readPackageFile( 0, false, true ); } } void Server :: readLocalIpks( Server *local ) { cleanUp(); #ifdef QWS // First, get any local IPKGs in the documents area // Only applicable to Qtopie/Opie DocLnkSet files; Global::findDocuments( &files, "application/ipkg" ); // Now add the items to the list QListIterator<DocLnk> it( files.children() ); for ( ; it.current() ; ++it ) { // OK, we have a local IPK file, I think the standard naming conventions // for these are packagename_version_arm.ipk QString file = (*it)->file(); // Changed to display the filename (excluding the path) QString packageName = Utils::getFilenameFromIpkFilename( file ); QString ver = Utils::getPackageVersionFromIpkFilename( file ); Package *package = new Package( packageName ); package->setVersion( ver ); package->setFilename( file ); package->setPackageStoredLocally( true ); packageList.append( package ); } #else QString names[] = { "advancedfm_0.9.1-20020811_arm.ipk", "libopie_0.9.1-20020811_arm.ipk", "libopieobex_0.9.1-20020811.1_arm.ipk", "opie-addressbook_0.9.1-20020811_arm.ipk" }; for ( int i = 0 ; i < 4 ; ++i ) { // OK, we have a local IPK file, I think the standard naming conventions // for these are packagename_version_arm.ipk QString file = names[i]; int p = file.find( "_" ); QString tmp = file.mid( 0, p ); packageList.push_back( Package( tmp ) ); int p2 = file.find( "_", p+1 ); tmp = file.mid( p+1, p2-(p+1) ); packageList.back().setVersion( tmp ); packageList.back().setPackageStoredLocally( true ); } #endif // build local packages buildLocalPackages( local ); } void Server :: readPackageFile( Server *local, bool clearAll, bool installingToRoot, Destination *dest ) { QFile f( packageFile ); if ( !f.open( IO_ReadOnly ) ) return; QTextStream t( &f ); QString line; QString key; QString value; int pos; if ( clearAll ) cleanUp(); Package *currPackage = 0; bool newPackage = true; while ( !t.eof() ) { line = t.readLine(); pos = line.find( ':', 0 ); if ( pos > -1 ) key = line.mid( 0, pos ).stripWhiteSpace(); else key = QString::null; value = line.mid( pos+1, line.length()-pos ).stripWhiteSpace(); if ( key == "Package" && newPackage ) { newPackage = false; currPackage = getPackage( value ); if ( !currPackage ) { Package *package = new Package( value ); packageList.append( package ); currPackage = package; currPackage->setInstalledTo( dest ); if ( installingToRoot ) currPackage->setInstalledToRoot( true ); } else { - if (currPackage->getStatus().find( "deinstall" ) != -1 ) + if ( currPackage->isInstalled() ) currPackage->setInstalledTo( dest ); } } else if ( key == "Version" ) { if ( currPackage ) currPackage->setVersion( value ); } else if ( key == "Status" ) { if ( currPackage ) currPackage->setStatus( value ); } else if ( key == "Description" ) { if ( currPackage ) currPackage->setDescription( value ); } else if ( key == "Filename" ) { if ( currPackage ) currPackage->setFilename( value ); } else if ( key == "Size" ) { if ( currPackage ) currPackage->setPackageSize( value ); } else if ( key == "Section" ) { if ( currPackage ) currPackage->setSection( value ); DataManager::setAvailableCategories( value ); } else if ( key == QString::null ) { newPackage = true; } } f.close(); // build local packages buildLocalPackages( local ); } void Server :: buildLocalPackages( Server *local ) { Package *curr; QListIterator<Package> it( packageList ); for ( ; it.current(); ++it ) { curr = it.current(); QString name = curr->getPackageName(); // If the package name is an ipk name, then convert the filename to a package name if ( name.find( ".ipk" ) != -1 ) name = Utils::getPackageNameFromIpkFilename( curr->getFilename() ); if ( local ) { Package *p = local->getPackage( name ); curr->setLocalPackage( p ); if ( p ) { // Set some default stuff like size and things if ( p->getInstalledVersion() == curr->getVersion() ) { p->setPackageSize( curr->getPackageSize() ); p->setSection( curr->getSection() ); p->setDescription( curr->getDescription() ); } } } else curr->setLocalPackage( 0 ); } } Package *Server :: getPackage( QString &name ) { return getPackage( (const char *)name ); } Package *Server :: getPackage( const char *name ) { Package *ret = 0; QListIterator<Package> it( packageList ); for ( ; it.current(); ++it ) { if ( it.current()->getPackageName() == name ) ret = it.current(); } return ret; } QString Server :: toString() { QString ret = QString( "Server\n name - %1\n url - %2\n" ).arg( serverName ).arg( serverUrl ); QListIterator<Package> it( packageList ); for ( ; it.current(); ++it ) { ret.append( QString( "\n %1" ).arg( it.current()->toString() ) ); } return ret; } QList<Package> &Server::getPackageList() { return packageList; } |