-rw-r--r-- | noncore/settings/aqpkg/install.ui | 64 | ||||
-rw-r--r-- | noncore/settings/aqpkg/installdlgimpl.cpp | 37 | ||||
-rw-r--r-- | noncore/settings/aqpkg/installdlgimpl.h | 2 |
3 files changed, 84 insertions, 19 deletions
diff --git a/noncore/settings/aqpkg/install.ui b/noncore/settings/aqpkg/install.ui index daa0ff6..c5a3596 100644 --- a/noncore/settings/aqpkg/install.ui +++ b/noncore/settings/aqpkg/install.ui @@ -1,118 +1,146 @@ <!DOCTYPE UI><UI> <class>InstallDlg</class> <widget> <class>QDialog</class> <property stdset="1"> <name>name</name> <cstring>InstallDlg</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> <width>196</width> - <height>271</height> + <height>278</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Install</string> </property> <grid> <property stdset="1"> <name>margin</name> <number>11</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> - <widget row="0" column="0" > - <class>QLabel</class> + <widget row="0" column="1" > + <class>QComboBox</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel1</cstring> + <cstring>destination</cstring> + </property> + </widget> + <widget row="3" column="0" > + <class>QPushButton</class> + <property stdset="1"> + <name>name</name> + <cstring>btnInstall</cstring> </property> <property stdset="1"> <name>text</name> - <string>Destination</string> + <string>Start</string> </property> </widget> - <widget row="0" column="1" > - <class>QComboBox</class> + <widget row="3" column="1" > + <class>QPushButton</class> <property stdset="1"> <name>name</name> - <cstring>destination</cstring> + <cstring>btnOptions</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Options</string> </property> </widget> - <widget row="1" column="0" rowspan="1" colspan="2" > + <widget row="2" column="0" rowspan="1" colspan="2" > <class>QGroupBox</class> <property stdset="1"> <name>name</name> <cstring>GroupBox2</cstring> </property> <property stdset="1"> <name>title</name> <string>Output</string> </property> <grid> <property stdset="1"> <name>margin</name> <number>11</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget row="0" column="0" > <class>QMultiLineEdit</class> <property stdset="1"> <name>name</name> <cstring>output</cstring> </property> </widget> </grid> </widget> - <widget row="2" column="0" > - <class>QPushButton</class> + <widget row="0" column="0" > + <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>btnInstall</cstring> + <cstring>TextLabel1</cstring> </property> <property stdset="1"> <name>text</name> - <string>Start</string> + <string>Destination</string> </property> </widget> - <widget row="2" column="1" > - <class>QPushButton</class> + <widget row="1" column="0" > + <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>btnOptions</cstring> + <cstring>TextLabel3</cstring> </property> <property stdset="1"> <name>text</name> - <string>Options</string> + <string>Space Avail</string> + </property> + </widget> + <widget row="1" column="1" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>txtAvailableSpace</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>100000000</string> </property> </widget> </grid> </widget> <connections> <connection> <sender>btnOptions</sender> <signal>clicked()</signal> <receiver>InstallDlg</receiver> <slot>optionsSelected()</slot> </connection> <connection> <sender>btnInstall</sender> <signal>clicked()</signal> <receiver>InstallDlg</receiver> <slot>installSelected()</slot> </connection> + <connection> + <sender>destination</sender> + <signal>highlighted(const QString&)</signal> + <receiver>InstallDlg</receiver> + <slot>displayAvailableSpace( const QString& )</slot> + </connection> + <slot access="public">displayAvailableSpace( const QString& )</slot> <slot access="public">installSelected()</slot> - <slot access="public">displayText(const QString &)</slot> <slot access="public">optionsSelected()</slot> </connections> </UI> diff --git a/noncore/settings/aqpkg/installdlgimpl.cpp b/noncore/settings/aqpkg/installdlgimpl.cpp index 485fe3d..bfb4f62 100644 --- a/noncore/settings/aqpkg/installdlgimpl.cpp +++ b/noncore/settings/aqpkg/installdlgimpl.cpp @@ -1,239 +1,274 @@ /*************************************************************************** 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> #include <qpe/qpeapplication.h> +#include <qpe/storage.h> #endif #include <qmultilineedit.h> #include <qdialog.h> #include <qcombobox.h> #include <qcheckbox.h> #include <qpushbutton.h> +#include <qlabel.h> #include "datamgr.h" #include "instoptionsimpl.h" #include "destination.h" #include "installdlgimpl.h" +#include "utils.h" #include "global.h" InstallDlgImpl::InstallDlgImpl( vector<InstallData> &packageList, DataManager *dataManager, QWidget * parent, const char* name, bool modal, WFlags fl ) : InstallDlg( parent, name, modal, fl ) { pIpkg = 0; 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", 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<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 ) { InstallData item = *it; if ( item.option == "I" ) { installList.push_back( item ); install += " " + item.packageName + "\n"; } else if ( item.option == "D" ) { removeList.push_back( item ); remove += " " + item.packageName + "\n"; } else if ( item.option == "U" || item.option == "R" ) { updateList.push_back( item ); QString type = " (Upgrade)"; if ( item.option == "R" ) type = " (ReInstall)"; upgrade += " " + item.packageName + type + "\n"; } } output->setText( remove + install + upgrade ); + + displayAvailableSpace( destination->currentText() ); } InstallDlgImpl::InstallDlgImpl( Ipkg *ipkg, QString initialText, QWidget *parent, const char *name, bool modal, WFlags fl ) : InstallDlg( parent, name, modal, fl ) { pIpkg = ipkg; output->setText( initialText ); } 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 = opt.getFlags(); #ifdef QWS Config cfg( "aqpkg" ); cfg.setGroup( "settings" ); cfg.writeEntry( "installFlags", flags ); #endif } void InstallDlgImpl :: installSelected() { if ( btnInstall->text() == "Close" ) { done( 1 ); return; } // Disable buttons btnOptions->setEnabled( false ); btnInstall->setEnabled( false ); if ( pIpkg ) { output->setText( "" ); connect( pIpkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); pIpkg->runIpkg(); } else { output->setText( "" ); vector<Destination>::iterator d = dataMgr->getDestination( destination->currentText() ); QString dest = d->getDestinationName(); QString destDir = d->getDestinationPath(); int instFlags = flags; if ( d->linkToRoot() ) instFlags |= MAKE_LINKS; #ifdef QWS // Save settings Config cfg( "aqpkg" ); cfg.setGroup( "settings" ); cfg.writeEntry( "dest", dest ); #endif pIpkg = new Ipkg; connect( pIpkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); - + // First run through the remove list, then the install list then the upgrade list vector<InstallData>::iterator it; pIpkg->setOption( "remove" ); for ( it = removeList.begin() ; it != removeList.end() ; ++it ) { pIpkg->setDestination( it->destination->getDestinationName() ); pIpkg->setDestinationDir( it->destination->getDestinationPath() ); pIpkg->setPackage( it->packageName ); int tmpFlags = flags; if ( it->destination->linkToRoot() ) tmpFlags |= MAKE_LINKS; pIpkg->setFlags( tmpFlags ); pIpkg->runIpkg(); } pIpkg->setOption( "install" ); pIpkg->setDestination( dest ); pIpkg->setDestinationDir( destDir ); pIpkg->setFlags( instFlags ); for ( it = installList.begin() ; it != installList.end() ; ++it ) { pIpkg->setPackage( it->packageName ); pIpkg->runIpkg(); } flags |= FORCE_REINSTALL; for ( it = updateList.begin() ; it != updateList.end() ; ++it ) { if ( it->option == "R" ) pIpkg->setOption( "reinstall" ); else pIpkg->setOption( "upgrade" ); pIpkg->setDestination( it->destination->getDestinationName() ); pIpkg->setDestinationDir( it->destination->getDestinationPath() ); pIpkg->setPackage( it->packageName ); int tmpFlags = flags; if ( it->destination->linkToRoot() && it->recreateLinks ) tmpFlags |= MAKE_LINKS; pIpkg->setFlags( tmpFlags ); pIpkg->runIpkg(); } delete pIpkg; } btnOptions->setEnabled( true ); 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 ); } + + +void InstallDlgImpl :: displayAvailableSpace( const QString &text ) +{ + vector<Destination>::iterator d = dataMgr->getDestination( text ); + QString destDir = d->getDestinationPath(); + + long blockSize = 0; + long totalBlocks = 0; + long availBlocks = 0; + QString space; + if ( Utils::getStorageSpace( (const char *)destDir, &blockSize, &totalBlocks, &availBlocks ) ) + { + long mult = blockSize / 1024; + long div = 1024 / blockSize; + + if ( !mult ) mult = 1; + if ( !div ) div = 1; +// long total = totalBlocks * mult / div; + long avail = availBlocks * mult / div; +// long used = total - avail; + + space.sprintf( "%ld Kb", avail ); + } + else + space = "Unknown"; + + txtAvailableSpace->setText( space ); +} + diff --git a/noncore/settings/aqpkg/installdlgimpl.h b/noncore/settings/aqpkg/installdlgimpl.h index 9819b2e..2f80f08 100644 --- a/noncore/settings/aqpkg/installdlgimpl.h +++ b/noncore/settings/aqpkg/installdlgimpl.h @@ -1,65 +1,67 @@ /*************************************************************************** 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, R- reinstall U - upgrade QString packageName; Destination *destination; bool recreateLinks; }; class InstallDlgImpl : public InstallDlg { public: InstallDlgImpl( vector<InstallData> &packageList, DataManager *dataManager, QWidget * parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); InstallDlgImpl( Ipkg *ipkg, QString initialText, 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<InstallData> installList; vector<InstallData> removeList; vector<InstallData> updateList; int flags; Ipkg *pIpkg; bool upgradePackages; bool runIpkg( QString &option, const QString& package, const QString& dest, int flags ); void optionsSelected(); void installSelected(); void displayText(const QString &text ); + void displayAvailableSpace( const QString &text); }; #endif |