-rw-r--r-- | noncore/settings/aqpkg/installdlgimpl.cpp | 67 | ||||
-rw-r--r-- | noncore/settings/aqpkg/installdlgimpl.h | 17 | ||||
-rw-r--r-- | noncore/settings/aqpkg/ipkg.cpp | 21 | ||||
-rw-r--r-- | noncore/settings/aqpkg/networkpkgmgr.cpp | 74 | ||||
-rw-r--r-- | noncore/settings/aqpkg/networkpkgmgr.h | 4 |
5 files changed, 128 insertions, 55 deletions
diff --git a/noncore/settings/aqpkg/installdlgimpl.cpp b/noncore/settings/aqpkg/installdlgimpl.cpp index b92a245..bbb0be75 100644 --- a/noncore/settings/aqpkg/installdlgimpl.cpp +++ b/noncore/settings/aqpkg/installdlgimpl.cpp @@ -1,219 +1,240 @@ /*************************************************************************** installdlgimpl.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. * * * ***************************************************************************/ #ifdef QWS #include <qpe/config.h> #endif #include <qmultilineedit.h> #include <qdialog.h> #include <qcombobox.h> #include <qcheckbox.h> #include <qpushbutton.h> #include "datamgr.h" #include "instoptionsimpl.h" #include "destination.h" #include "installdlgimpl.h" #include "global.h" -InstallDlgImpl::InstallDlgImpl( vector<QString> &packageList, DataManager *dataManager, QWidget * parent, const char* name, bool modal, WFlags fl ) +InstallDlgImpl::InstallDlgImpl( vector<InstallData> &packageList, DataManager *dataManager, QWidget * parent, const char* name, bool modal, WFlags fl ) : InstallDlg( parent, name, modal, fl ) { upgradePackages = false; dataMgr = dataManager; vector<Destination>::iterator dit; QString defaultDest = "root"; #ifdef QWS Config cfg( "aqpkg" ); cfg.setGroup( "settings" ); defaultDest = cfg.readEntry( "dest", "root" ); // Grab flags - Turn MAKE_LINKS on by default (if no flags found) - flags = cfg.readNumEntry( "installFlags", MAKE_LINKS ); +// flags = cfg.readNumEntry( "installFlags", MAKE_LINKS ); + flags = 0; #else flags = 0; #endif // Output text is read only output->setReadOnly( true ); QFont f( "helvetica" ); f.setPointSize( 10 ); output->setFont( f ); // setup destination data int defIndex = 0; int i; for ( i = 0 , dit = dataMgr->getDestinationList().begin() ; dit != dataMgr->getDestinationList().end() ; ++dit, ++i ) { destination->insertItem( dit->getDestinationName() ); if ( dit->getDestinationName() == defaultDest ) defIndex = i; } destination->setCurrentItem( defIndex ); - vector<QString>::iterator it; + vector<InstallData>::iterator it; // setup package data QString remove = "Remove\n"; QString install = "\nInstall\n"; QString upgrade = "\nUpgrade\n"; for ( it = packageList.begin() ; it != packageList.end() ; ++it ) { - QString name = *it; - if ( name.startsWith( "I" ) ) + InstallData item = *it; + if ( item.option == "I" ) { - installList.push_back( name.mid(1) ); - install += " " + name.mid(1) + "\n"; + installList.push_back( item ); + install += " " + item.packageName + "\n"; } - else if ( name.startsWith( "D" ) ) + else if ( item.option == "D" ) { - removeList.push_back( name.mid(1) ); - remove += " " + name.mid(1) + "\n"; + removeList.push_back( item ); + remove += " " + item.packageName + "\n"; } - else if ( name.startsWith( "U" ) ) + else if ( item.option == "U" ) { - updateList.push_back( name.mid(1) ); - upgrade += " " + name.mid(1) + "\n"; + updateList.push_back( item ); + upgrade += " " + item.packageName + "\n"; } } output->setText( remove + install + upgrade ); connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); } InstallDlgImpl::InstallDlgImpl( QWidget *parent, const char *name, bool modal, WFlags fl ) : InstallDlg( parent, name, modal, fl ) { upgradePackages = true; output->setText( "Upgrading installed packages" ); connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); } InstallDlgImpl::~InstallDlgImpl() { } bool InstallDlgImpl :: showDlg() { showMaximized(); bool ret = exec(); return ret; } void InstallDlgImpl :: optionsSelected() { InstallOptionsDlgImpl opt( flags, this, "Option", true ); opt.exec(); // set options selected from dialog flags = 0; if ( opt.forceDepends->isChecked() ) flags |= FORCE_DEPENDS; if ( opt.forceReinstall->isChecked() ) flags |= FORCE_REINSTALL; if ( opt.forceRemove->isChecked() ) flags |= FORCE_REMOVE; if ( opt.forceOverwrite->isChecked() ) flags |= FORCE_OVERWRITE; - if ( opt.makeLinks->isChecked() ) - flags |= MAKE_LINKS; #ifdef QWS Config cfg( "aqpkg" ); cfg.setGroup( "settings" ); cfg.writeEntry( "installFlags", flags ); #endif } void InstallDlgImpl :: installSelected() { if ( btnInstall->text() == "Close" ) { done( 1 ); return; } btnInstall->setEnabled( false ); if ( upgradePackages ) { output->setText( "" ); Ipkg ipkg; connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); ipkg.setOption( "upgrade" ); ipkg.runIpkg(); } else { output->setText( "" ); Destination *d = dataMgr->getDestination( destination->currentText() ); QString dest = d->getDestinationName(); QString destDir = d->getDestinationPath(); + int instFlags = 0; + if ( d->linkToRoot() ) + instFlags = MAKE_LINKS; #ifdef QWS // Save settings Config cfg( "aqpkg" ); cfg.setGroup( "settings" ); cfg.writeEntry( "dest", dest ); #endif // First run through the remove list, then the install list then the upgrade list - vector<QString>::iterator it; + vector<InstallData>::iterator it; ipkg.setOption( "remove" ); - ipkg.setDestination( dest ); - ipkg.setDestinationDir( destDir ); - ipkg.setFlags( flags ); for ( it = removeList.begin() ; it != removeList.end() ; ++it ) { - ipkg.setPackage( *it ); + ipkg.setDestination( it->destination->getDestinationName() ); + ipkg.setDestinationDir( it->destination->getDestinationPath() ); + ipkg.setPackage( it->packageName ); + + int tmpFlags = flags; + if ( it->destination->linkToRoot() ) + tmpFlags |= MAKE_LINKS; + else + tmpFlags ^= MAKE_LINKS; + + ipkg.setFlags( tmpFlags ); ipkg.runIpkg(); } ipkg.setOption( "install" ); + ipkg.setDestination( dest ); + ipkg.setDestinationDir( destDir ); + ipkg.setFlags( instFlags ); for ( it = installList.begin() ; it != installList.end() ; ++it ) { - ipkg.setPackage( *it ); + ipkg.setPackage( it->packageName ); ipkg.runIpkg(); } flags |= FORCE_REINSTALL; - ipkg.setFlags( flags ); + ipkg.setOption( "reinstall" ); for ( it = updateList.begin() ; it != updateList.end() ; ++it ) { - ipkg.setPackage( *it ); + ipkg.setDestination( it->destination->getDestinationName() ); + ipkg.setDestinationDir( it->destination->getDestinationPath() ); + ipkg.setPackage( it->packageName ); + + int tmpFlags = flags; + if ( it->destination->linkToRoot() && it->recreateLinks ) + tmpFlags |= MAKE_LINKS; + else + tmpFlags ^= MAKE_LINKS; + ipkg.setFlags( tmpFlags ); ipkg.runIpkg(); } } btnInstall->setEnabled( true ); btnInstall->setText( tr( "Close" ) ); } void InstallDlgImpl :: displayText(const QString &text ) { QString t = output->text() + "\n" + text; output->setText( t ); output->setCursorPosition( output->numLines(), 0 ); } diff --git a/noncore/settings/aqpkg/installdlgimpl.h b/noncore/settings/aqpkg/installdlgimpl.h index 8b05c52..3a5d8b8 100644 --- a/noncore/settings/aqpkg/installdlgimpl.h +++ b/noncore/settings/aqpkg/installdlgimpl.h @@ -1,56 +1,65 @@ /*************************************************************************** installdlgimpl.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 INSTALLDLGIMPL_H #define INSTALLDLGIMPL_H #include <vector> using namespace std; #include <qstring.h> #include "ipkg.h" #include "install.h" +class InstallData +{ +public: + QString option; // I - install, D - delete, U - upgrade + QString packageName; + Destination *destination; + bool recreateLinks; +}; + class InstallDlgImpl : public InstallDlg { public: - InstallDlgImpl( vector<QString> &packageList, DataManager *dataManager, QWidget * parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); + InstallDlgImpl( vector<InstallData> &packageList, DataManager *dataManager, QWidget * parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); InstallDlgImpl( QWidget * parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); ~InstallDlgImpl(); bool showDlg(); bool upgradeServer( QString &server ); protected: private: DataManager *dataMgr; - vector<QString> installList; - vector<QString> removeList; - vector<QString> updateList; + vector<InstallData> installList; + vector<InstallData> removeList; + vector<InstallData> updateList; int flags; Ipkg ipkg; bool upgradePackages; bool runIpkg( QString &option, const QString& package, const QString& dest, int flags ); void optionsSelected(); void installSelected(); void displayText(const QString &text ); }; #endif diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp index 6d0edad..02d4258 100644 --- a/noncore/settings/aqpkg/ipkg.cpp +++ b/noncore/settings/aqpkg/ipkg.cpp @@ -1,361 +1,368 @@ /*************************************************************************** ipkg.cpp - description ------------------- begin : Sat Aug 31 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 <fstream> using namespace std; #include <stdio.h> #include <unistd.h> #ifdef QWS #include <qpe/qpeapplication.h> #else #include <qapplication.h> #endif #include <qdir.h> #include <qtextstream.h> #include "utils.h" #include "ipkg.h" #include "global.h" Ipkg :: Ipkg() { } Ipkg :: ~Ipkg() { } -// Option is what we are going to do - install, upgrade, download +// Option is what we are going to do - install, upgrade, download, reinstall // package is the package name to install - either a fully qualified path and ipk // file (if stored locally) or just the name of the package (for a network package) // packageName is the package name - (for a network package this will be the same as // package parameter) // dest is the destination alias (from ipk.conf) // destDir is the dir that the destination alias points to (used to link to root) // flags is the ipkg options flags // dir is the directory to run ipkg in (defaults to "") bool Ipkg :: runIpkg( ) { bool ret = false; QDir::setCurrent( "/tmp" ); QString cmd = ""; if ( runtimeDir != "" ) { cmd += "cd "; cmd += runtimeDir; cmd += " ; "; } cmd += "ipkg"; if ( option != "update" && option != "download" && option != "upgrade" ) { cmd += " -dest "+ destination; cmd += " -force-defaults"; if ( flags & FORCE_DEPENDS ) cmd += " -force-depends"; if ( flags & FORCE_REINSTALL ) cmd += " -force-reinstall"; if ( flags & FORCE_REMOVE ) cmd += " -force-removal-of-essential-packages"; if ( flags & FORCE_OVERWRITE ) cmd += " -force-overwrite"; // Handle make links // Rules - If make links is switched on, create links to root // if destDir is NOT / if ( flags & MAKE_LINKS ) { // If destDir == / turn off make links as package is being insalled // to root already. if ( destDir == "/" ) flags ^= MAKE_LINKS; } - } #ifdef X86 cmd += " -f "; cmd += IPKG_CONF; #endif + + if ( option == "reinstall" ) + cmd += " install"; + else cmd += " " + option; if ( option != "upgrade" ) cmd += " " + package; cmd += " 2>&1"; + + emit outputText( QString( "Dealing with package " ) + package ); + qApp->processEvents(); // If we are removing packages and make links option is selected // create the links - if ( option == "remove" ) + if ( option == "remove" || option == "reinstall" ) { createLinks = false; if ( flags & MAKE_LINKS ) { emit outputText( QString( "Removing symbolic links...\n" ) ); linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); emit outputText( QString( " " ) ); } } emit outputText( cmd ); // Execute command dependantPackages = new QList<QString>; dependantPackages->setAutoDelete( true ); ret = executeIpkgCommand( cmd, option ); - if ( option == "install" ) + if ( option == "install" || option == "reinstall" ) { // If we are not removing packages and make links option is selected // create the links createLinks = true; if ( flags & MAKE_LINKS ) { emit outputText( " " ); emit outputText( QString( "Creating symbolic links for " )+ package ); linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); // link dependant packages that were installed with this release QString *pkg; for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) { if ( *pkg == package ) continue; emit outputText( " " ); emit outputText( QString( "Creating symbolic links for " )+ (*pkg) ); linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); } } } delete dependantPackages; emit outputText( QString( "Finished - status=" ) + (ret ? "success" : "failure") ); + emit outputText( "" ); return ret; } int Ipkg :: executeIpkgCommand( QString &cmd, const QString option ) { FILE *fp = NULL; char line[130]; QString lineStr, lineStrOld; int ret = false; fp = popen( (const char *) cmd, "r"); if ( fp == NULL ) { cout << "Couldn't execute " << cmd << "! err = " << fp << endl; QString text; text.sprintf( "Couldn't execute %s! See stdout for error code", (const char *)cmd ); emit outputText( text ); } else { while ( fgets( line, sizeof line, fp) != NULL ) { lineStr = line; lineStr=lineStr.left( lineStr.length()-1 ); if ( lineStr != lineStrOld ) { //See if we're finished - if ( option == "install" ) + if ( option == "install" || option == "reinstall" ) { // Need to keep track of any dependant packages that get installed // so that we can create links to them as necessary if ( lineStr.startsWith( "Installing " ) ) { cout << "LineStr = " << lineStr << endl; int start = lineStr.find( " " ) + 1; int end = lineStr.find( " ", start ); QString *package = new QString( lineStr.mid( start, end-start ) ); dependantPackages->append( package ); cout << "installing dependant package <" << *package << ">" << endl; } } if ( option == "update" ) { if (lineStr.contains("Updated list")) ret = true; } else if ( option == "download" ) { if (lineStr.contains("Downloaded")) ret = true; } else { if (lineStr.contains("Done")) ret = true; } emit outputText( lineStr ); } lineStrOld = lineStr; qApp->processEvents(); } pclose(fp); } return ret; } void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) { if ( dest == "root" || dest == "/" ) return; qApp->processEvents(); QStringList *fileList = getList( packFileName, destDir ); qApp->processEvents(); processFileList( fileList, destDir ); delete fileList; } QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) { QString packageFileDir = destDir+"/usr/lib/ipkg/info/"+packageFilename+".list"; QFile f( packageFileDir ); - cout << "Try to open " << packageFileDir.latin1() << endl; + cout << "Try to open " << packageFileDir << endl; if ( !f.open(IO_ReadOnly) ) { // Couldn't open from dest, try from / -// cout << "Could not open:" << packageFileDir << endl; + cout << "Could not open:" << packageFileDir << endl; f.close(); packageFileDir = "/usr/lib/ipkg/info/"+packageFilename+".list"; f.setName( packageFileDir ); // cout << "Try to open " << packageFileDir.latin1() << endl; if ( ! f.open(IO_ReadOnly) ) { cout << "Could not open:" << packageFileDir << endl; emit outputText( QString( "Could not open :" ) + packageFileDir ); return (QStringList*)0; } } QStringList *fileList = new QStringList(); QTextStream t( &f ); while ( !t.eof() ) *fileList += t.readLine(); f.close(); return fileList; } void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) { if ( !fileList || fileList->isEmpty() ) return; QString baseDir = ROOT; if ( createLinks == true ) { for ( uint i=0; i < fileList->count(); i++ ) { processLinkDir( (*fileList)[i], baseDir, destDir ); qApp->processEvents(); } } else { for ( int i = fileList->count()-1; i >= 0 ; i-- ) { processLinkDir( (*fileList)[i], baseDir, destDir ); qApp->processEvents(); } } } void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) { QString sourceFile = baseDir + file; QString linkFile = destDir; if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) { linkFile += file.mid( 1 ); } else { linkFile += file; } QString text; if ( createLinks ) { // If this file is a directory (ends with a /) and it doesn't exist, // we need to create it if ( file.right(1) == "/" ) { QFileInfo f( linkFile ); if ( !f.exists() ) { emit outputText( QString( "Creating directory " ) + linkFile ); QDir d; d.mkdir( linkFile, true ); } else emit outputText( QString( "Directory " ) + linkFile + " exists" ); } else { int rc = symlink( sourceFile, linkFile ); text = (rc == 0 ? "Linked " : "Failed to link "); text += sourceFile + " to " + linkFile; emit outputText( text ); } } else { QFileInfo f( linkFile ); if ( f.exists() ) { if ( f.isFile() ) { QFile f( linkFile ); bool rc = f.remove(); text = (rc ? "Removed " : "Failed to remove "); text += linkFile; emit outputText( text ); } else if ( f.isDir() ) { QDir d; bool rc = d.rmdir( linkFile, true ); text = (rc ? "Removed " : "Failed to remove "); text += linkFile; emit outputText( text ); } } } } diff --git a/noncore/settings/aqpkg/networkpkgmgr.cpp b/noncore/settings/aqpkg/networkpkgmgr.cpp index 6f528a1..ed5bf75 100644 --- a/noncore/settings/aqpkg/networkpkgmgr.cpp +++ b/noncore/settings/aqpkg/networkpkgmgr.cpp @@ -1,524 +1,558 @@ /*************************************************************************** networkpkgmgr.cpp - description ------------------- begin : Mon Aug 26 13:32:30 BST 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 <fstream> #include <iostream> using namespace std; #include <unistd.h> #include <stdlib.h> #include <linux/limits.h> #ifdef QWS #include <qpe/qpeapplication.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/config.h> #else #include <qapplication.h> #endif #include <qlabel.h> #include <qfile.h> #include <qmessagebox.h> #include "datamgr.h" #include "networkpkgmgr.h" #include "installdlgimpl.h" #include "ipkg.h" #include "inputdlg.h" #include "letterpushbutton.h" #include "global.h" NetworkPackageManager::NetworkPackageManager( DataManager *dataManager, QWidget *parent, const char *name) : QWidget(parent, name) { dataMgr = dataManager; #ifdef QWS // read download directory from config file Config cfg( "aqpkg" ); cfg.setGroup( "settings" ); currentlySelectedServer = cfg.readEntry( "selectedServer", "local" ); #endif initGui(); setupConnections(); progressDlg = 0; timerId = startTimer( 100 ); } NetworkPackageManager::~NetworkPackageManager() { } void NetworkPackageManager :: timerEvent ( QTimerEvent * ) { killTimer( timerId ); // showProgressDialog(); // Add server names to listbox updateData(); // progressDlg->hide(); } void NetworkPackageManager :: updateData() { serversList->clear(); packagesList->clear(); vector<Server>::iterator it; int activeItem = -1; int i; for ( i = 0, it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it, ++i ) { if ( !it->isServerActive() ) { i--; continue; } serversList->insertItem( it->getServerName() ); if ( it->getServerName() == currentlySelectedServer ) activeItem = i; } // set selected server to be active server if ( activeItem != -1 ) serversList->setCurrentItem( activeItem ); serverSelected( 0 ); } void NetworkPackageManager :: initGui() { QLabel *l = new QLabel( "Servers", this ); serversList = new QComboBox( this ); packagesList = new QListView( this ); update = new QPushButton( "Refresh List", this ); download = new QPushButton( "Download", this ); upgrade = new QPushButton( "Upgrade", this ); apply = new QPushButton( "Apply", this ); QVBoxLayout *vbox = new QVBoxLayout( this, 0, -1, "VBox" ); QHBoxLayout *hbox1 = new QHBoxLayout( vbox, -1, "HBox1" ); hbox1->addWidget( l ); hbox1->addWidget( serversList ); QHBoxLayout *hbox3 = new QHBoxLayout( vbox, -1, "HBox1" ); QHBoxLayout *hbox4 = new QHBoxLayout( vbox, -1, "HBox1" ); char text[2]; text[1] = '\0'; for ( int i = 0 ; i < 26 ; ++i ) { text[0] = 'A' + i; LetterPushButton *b = new LetterPushButton( text, this ); connect( b, SIGNAL( released( QString ) ), this, SLOT( letterPushed( QString ) ) ); if ( i < 16 ) hbox3->addWidget( b ); else hbox4->addWidget( b ); } vbox->addWidget( packagesList ); packagesList->addColumn( "Packages" ); QHBoxLayout *hbox2 = new QHBoxLayout( vbox, -1, "HBox2" ); hbox2->addWidget( update ); hbox2->addWidget( download ); hbox2->addWidget( upgrade ); hbox2->addWidget( apply ); } void NetworkPackageManager :: setupConnections() { connect( serversList, SIGNAL(activated( int )), this, SLOT(serverSelected( int ))); connect( apply, SIGNAL(released()), this, SLOT(applyChanges()) ); connect( download, SIGNAL(released()), this, SLOT(downloadPackage()) ); connect( upgrade, SIGNAL( released()), this, SLOT(upgradePackages()) ); connect( update, SIGNAL(released()), this, SLOT(updateServer()) ); } void NetworkPackageManager :: showProgressDialog( char *initialText ) { if ( !progressDlg ) progressDlg = new ProgressDlg( this, "Progress", false ); progressDlg->setText( initialText ); progressDlg->show(); } void NetworkPackageManager :: serverSelected( int ) { packagesList->clear(); // display packages QString serverName = serversList->currentText(); currentlySelectedServer = serverName; #ifdef QWS // read download directory from config file Config cfg( "aqpkg" ); cfg.setGroup( "settings" ); cfg.writeEntry( "selectedServer", currentlySelectedServer ); #endif Server *s = dataMgr->getServer( serverName ); // dataMgr->setActiveServer( serverName ); vector<Package> &list = s->getPackageList(); vector<Package>::iterator it; for ( it = list.begin() ; it != list.end() ; ++it ) { QString text = ""; // If the local server, only display installed packages if ( serverName == LOCAL_SERVER && !it->isInstalled() ) continue; text += it->getPackageName(); if ( it->isInstalled() ) { text += " (installed)"; // If a different version of package is available, postfix it with an * if ( it->getVersion() != it->getInstalledVersion() ) text += "*"; } QCheckListItem *item = new QCheckListItem( packagesList, text, QCheckListItem::CheckBox ); + + if ( it->isInstalled() ) + { + QString destName = ""; + if ( it->getLocalPackage() ) + { + if ( it->getLocalPackage()->getInstalledTo() ) + destName = it->getLocalPackage()->getInstalledTo()->getDestinationName(); + } + else + { + if ( it->getInstalledTo() ) + destName = it->getInstalledTo()->getDestinationName(); + } + if ( destName != "" ) + new QCheckListItem( item, QString( "Installed To - " ) + destName ); + } + if ( !it->isPackageStoredLocally() ) new QCheckListItem( item, QString( "Description - " ) + it->getDescription() ); else new QCheckListItem( item, QString( "Filename - " ) + it->getFilename() ); new QCheckListItem( item, QString( "V. Available - " ) + it->getVersion() ); if ( it->getLocalPackage() ) { if ( it->isInstalled() ) new QCheckListItem( item, QString( "V. Installed - " ) + it->getInstalledVersion() ); } packagesList->insertItem( item ); } // If the local server or the local ipkgs server disable the download button if ( serverName == LOCAL_SERVER ) { upgrade->setEnabled( false ); download->setText( "Download" ); download->setEnabled( false ); } else if ( serverName == LOCAL_IPKGS ) { upgrade->setEnabled( false ); download->setEnabled( true ); download->setText( "Remove" ); } else { upgrade->setEnabled( true ); download->setEnabled( true ); download->setText( "Download" ); } } void NetworkPackageManager :: updateServer() { QString serverName = serversList->currentText(); // Update the current server // Display dialog ProgressDlg *dlg = new ProgressDlg( this ); QString status = "Updating package lists..."; dlg->show(); dlg->setText( status ); // Disable buttons to stop silly people clicking lots on them :) // First, write out ipkg_conf file so that ipkg can use it dataMgr->writeOutIpkgConf(); -// if ( serverName == LOCAL_SERVER ) -// ; -// else if ( serverName == LOCAL_IPKGS ) -// ; -// else - { QString option = "update"; QString dummy = ""; Ipkg ipkg; connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); ipkg.setOption( option ); ipkg.runIpkg( ); - } // Reload data dataMgr->reloadServerData( serversList->currentText() ); serverSelected(-1); delete dlg; } void NetworkPackageManager :: upgradePackages() { // We're gonna do an upgrade of all packages // First warn user that this isn't recommended QString text = "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n"; QMessageBox warn("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 dataMgr->writeOutIpkgConf(); // Now run upgrade InstallDlgImpl dlg( this, "Upgrade", true ); dlg.showDlg(); // Reload data dataMgr->reloadServerData( LOCAL_SERVER ); dataMgr->reloadServerData( serversList->currentText() ); serverSelected(-1); } } void NetworkPackageManager :: downloadPackage() { if ( download->text() == "Download" ) { // First, write out ipkg_conf file so that ipkg can use it dataMgr->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() ) { 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 ); ipkg.setPackage( name ); ipkg.runIpkg( ); } } } else if ( download->text() == "Remove" ) { 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 = dataMgr->getServer( serversList->currentText() )->getPackage( name ); QFile f( p->getFilename() ); f.remove(); } } } dataMgr->reloadServerData( LOCAL_IPKGS ); serverSelected( -1 ); } void NetworkPackageManager :: applyChanges() { - // Disable buttons to stop silly people clicking lots on them :) + stickyOption = ""; // First, write out ipkg_conf file so that ipkg can use it dataMgr->writeOutIpkgConf(); // Now for each selected item // deal with it - vector<QString> workingPackages; + vector<InstallData> workingPackages; for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); item != 0 ; item = (QCheckListItem *)item->nextSibling() ) { if ( item->isOn() ) { - QString p = dealWithItem( item ); - workingPackages.push_back( p ); + InstallData data = dealWithItem( item ); + workingPackages.push_back( data ); } } // do the stuff InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true ); dlg.showDlg(); // Reload data dataMgr->reloadServerData( LOCAL_SERVER ); dataMgr->reloadServerData( serversList->currentText() ); serverSelected(-1); #ifdef QWS // Finally let the main system update itself QCopEnvelope e("QPE/System", "linkChanged(QString)"); QString lf = QString::null; e << lf; #endif } // 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 -QString NetworkPackageManager :: dealWithItem( QCheckListItem *item ) +InstallData NetworkPackageManager :: dealWithItem( QCheckListItem *item ) { 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 ); // Get package Server *s = dataMgr->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() ) - return QString( "I" ) + name; + { + InstallData item; + item.option = "I"; + item.packageName = name; + return item; + } else { - if ( p->getVersion() == p->getInstalledVersion() ) + InstallData item; + item.option = "D"; + item.packageName = name; + if ( p->getInstalledTo() ) + item.destination = p->getInstalledTo(); + else + item.destination = p->getLocalPackage()->getInstalledTo(); + + // Sticky option not implemented yet, but will eventually allow + // the user to say something like 'remove all' + if ( stickyOption == "" ) { QString msgtext; msgtext.sprintf( "Do you wish to remove or reinstall\n%s?", (const char *)name ); switch( QMessageBox::information( this, "Remove or ReInstall", msgtext, "Remove", "ReInstall" ) ) { case 0: // Try again or Enter - return QString( "D" ) + name; + item.option = "D"; break; case 1: // Quit or Escape - return QString( "U" ) + name; + item.option = "U"; break; } - - // User hit cancel (on dlg - assume remove) - return QString( "D" ) + name; } else - return QString( "U" ) + name; + { +// item.option = stickyOption; + } + + // Check if we are reinstalling the same version + if ( p->getVersion() != p->getInstalledVersion() ) + item.recreateLinks = true; + else + item.recreateLinks = false; + + // User hit cancel (on dlg - assume remove) + return item; } } void NetworkPackageManager :: displayText( const QString &t ) { cout << t << endl; } void NetworkPackageManager :: letterPushed( QString t ) { QCheckListItem *top = (QCheckListItem *)packagesList->firstChild(); QCheckListItem *start = (QCheckListItem *)packagesList->currentItem(); if ( packagesList->firstChild() == 0 ) return; QCheckListItem *item; if ( start == 0 ) { item = (QCheckListItem *)packagesList->firstChild(); start = top; } else item = (QCheckListItem *)start->nextSibling(); if ( item == 0 ) item = (QCheckListItem *)packagesList->firstChild(); do { if ( item->text().lower().startsWith( t.lower() ) ) { packagesList->setSelected( item, true ); packagesList->ensureItemVisible( item ); break; } item = (QCheckListItem *)item->nextSibling(); if ( !item ) item = (QCheckListItem *)packagesList->firstChild(); } while ( item != start); } diff --git a/noncore/settings/aqpkg/networkpkgmgr.h b/noncore/settings/aqpkg/networkpkgmgr.h index 0ae64a6..7efa42c 100644 --- a/noncore/settings/aqpkg/networkpkgmgr.h +++ b/noncore/settings/aqpkg/networkpkgmgr.h @@ -1,74 +1,76 @@ /*************************************************************************** networkpkgmgr.h - description ------------------- begin : Mon Aug 26 13:32:30 BST 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 NETWORKPKGMGR_H #define NETWORKPKGMGR_H #include <qlayout.h> #include <qpushbutton.h> #include <qwidget.h> #include <qcombobox.h> #include <qlistview.h> #include "datamgr.h" #include "progressdlg.h" +class InstallData; /** NetworkPackageManager is the base class of the project */ class NetworkPackageManager : public QWidget { Q_OBJECT public: /** construtor */ NetworkPackageManager( DataManager *dataManager, QWidget* parent=0, const char *name=0); /** destructor */ ~NetworkPackageManager(); void updateData(); private: DataManager *dataMgr; QComboBox *serversList; QListView *packagesList; QPushButton *update; QPushButton *upgrade; QPushButton *download; QPushButton *apply; ProgressDlg *progressDlg; QString currentlySelectedServer; int timerId; void timerEvent ( QTimerEvent * ); void initGui(); void setupConnections(); void showProgressDialog( char *initialText ); - QString dealWithItem( QCheckListItem *item ); + InstallData dealWithItem( QCheckListItem *item ); + QString stickyOption; public slots: void serverSelected( int index ); void applyChanges(); void upgradePackages(); void downloadPackage(); void updateServer(); void displayText( const QString &t ); void letterPushed( QString t ); }; #endif |