-rw-r--r-- | noncore/settings/aqpkg/networkpkgmgr.cpp | 97 | ||||
-rw-r--r-- | noncore/settings/aqpkg/networkpkgmgr.h | 2 |
2 files changed, 75 insertions, 24 deletions
diff --git a/noncore/settings/aqpkg/networkpkgmgr.cpp b/noncore/settings/aqpkg/networkpkgmgr.cpp index 0bc01df..318b26d 100644 --- a/noncore/settings/aqpkg/networkpkgmgr.cpp +++ b/noncore/settings/aqpkg/networkpkgmgr.cpp @@ -30,32 +30,41 @@ using namespace std; #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 * ) @@ -71,25 +80,25 @@ void NetworkPackageManager :: timerEvent ( QTimerEvent * ) 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 ) { serversList->insertItem( it->getServerName() ); - if ( it->getServerName() == dataMgr->getActiveServer() ) + if ( it->getServerName() == currentlySelectedServer ) activeItem = i; } // set selected server to be active server if ( activeItem != -1 ) serversList->setCurrentItem( activeItem ); serverSelected( 0 ); } void NetworkPackageManager :: initGui() { @@ -97,24 +106,40 @@ void NetworkPackageManager :: initGui() 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() { @@ -131,26 +156,35 @@ void NetworkPackageManager :: showProgressDialog( char *initialText ) 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 ); +// 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(); @@ -197,39 +231,38 @@ void NetworkPackageManager :: serverSelected( int ) 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 list for "; - status += serverName; + 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 +// 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() ); @@ -293,98 +326,96 @@ void NetworkPackageManager :: downloadPackage() // 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 &))); - QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); ipkg.setOption( "download" ); ipkg.setRuntimeDirectory( dir ); - do + 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( ); } - - item = (QCheckListItem *)item->nextSibling(); - } while ( item ); + } } else if ( download->text() == "Remove" ) { - QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); - do + 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(); } - item = (QCheckListItem *)item->nextSibling(); - } while ( item ); + } } dataMgr->reloadServerData( LOCAL_IPKGS ); serverSelected( -1 ); } void NetworkPackageManager :: applyChanges() { // Disable buttons to stop silly people clicking lots on them :) - + // 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; - QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); - do + for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); + item != 0 ; + item = (QCheckListItem *)item->nextSibling() ) { if ( item->isOn() ) { QString p = dealWithItem( item ); workingPackages.push_back( p ); } - - item = (QCheckListItem *)item->nextSibling(); - } while ( item ); + } // 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 @@ -442,12 +473,30 @@ QString NetworkPackageManager :: dealWithItem( QCheckListItem *item ) // User hit cancel (on dlg - assume remove) return QString( "D" ) + name; } else return QString( "U" ) + name; } } void NetworkPackageManager :: displayText( const QString &t ) { cout << t << endl; } + + +void NetworkPackageManager :: letterPushed( QString t ) +{ + QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); + do + { + if ( item->text().lower().startsWith( t.lower() ) ) + { + cout << "Found - item->text()" << endl; + packagesList->setSelected( item, true ); + packagesList->ensureItemVisible( item ); + break; + } + + item = (QCheckListItem *)item->nextSibling(); + } while ( item ); +} diff --git a/noncore/settings/aqpkg/networkpkgmgr.h b/noncore/settings/aqpkg/networkpkgmgr.h index 8a88b35..0ae64a6 100644 --- a/noncore/settings/aqpkg/networkpkgmgr.h +++ b/noncore/settings/aqpkg/networkpkgmgr.h @@ -41,32 +41,34 @@ public: 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 ); public slots: void serverSelected( int index ); void applyChanges(); void upgradePackages(); void downloadPackage(); void updateServer(); void displayText( const QString &t ); + void letterPushed( QString t ); }; #endif |