-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 | |||
@@ -36,20 +36,29 @@ using namespace std; | |||
36 | 36 | ||
37 | #include "datamgr.h" | 37 | #include "datamgr.h" |
38 | #include "networkpkgmgr.h" | 38 | #include "networkpkgmgr.h" |
39 | #include "installdlgimpl.h" | 39 | #include "installdlgimpl.h" |
40 | #include "ipkg.h" | 40 | #include "ipkg.h" |
41 | #include "inputdlg.h" | 41 | #include "inputdlg.h" |
42 | #include "letterpushbutton.h" | ||
42 | 43 | ||
43 | #include "global.h" | 44 | #include "global.h" |
44 | 45 | ||
45 | NetworkPackageManager::NetworkPackageManager( DataManager *dataManager, QWidget *parent, const char *name) | 46 | NetworkPackageManager::NetworkPackageManager( DataManager *dataManager, QWidget *parent, const char *name) |
46 | : QWidget(parent, name) | 47 | : QWidget(parent, name) |
47 | { | 48 | { |
48 | dataMgr = dataManager; | 49 | dataMgr = dataManager; |
49 | 50 | ||
51 | #ifdef QWS | ||
52 | // read download directory from config file | ||
53 | Config cfg( "aqpkg" ); | ||
54 | cfg.setGroup( "settings" ); | ||
55 | currentlySelectedServer = cfg.readEntry( "selectedServer", "local" ); | ||
56 | #endif | ||
57 | |||
58 | |||
50 | initGui(); | 59 | initGui(); |
51 | setupConnections(); | 60 | setupConnections(); |
52 | 61 | ||
53 | progressDlg = 0; | 62 | progressDlg = 0; |
54 | timerId = startTimer( 100 ); | 63 | timerId = startTimer( 100 ); |
55 | } | 64 | } |
@@ -77,13 +86,13 @@ void NetworkPackageManager :: updateData() | |||
77 | vector<Server>::iterator it; | 86 | vector<Server>::iterator it; |
78 | int activeItem = -1; | 87 | int activeItem = -1; |
79 | int i; | 88 | int i; |
80 | for ( i = 0, it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it, ++i ) | 89 | for ( i = 0, it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it, ++i ) |
81 | { | 90 | { |
82 | serversList->insertItem( it->getServerName() ); | 91 | serversList->insertItem( it->getServerName() ); |
83 | if ( it->getServerName() == dataMgr->getActiveServer() ) | 92 | if ( it->getServerName() == currentlySelectedServer ) |
84 | activeItem = i; | 93 | activeItem = i; |
85 | } | 94 | } |
86 | 95 | ||
87 | // set selected server to be active server | 96 | // set selected server to be active server |
88 | if ( activeItem != -1 ) | 97 | if ( activeItem != -1 ) |
89 | serversList->setCurrentItem( activeItem ); | 98 | serversList->setCurrentItem( activeItem ); |
@@ -103,12 +112,28 @@ void NetworkPackageManager :: initGui() | |||
103 | 112 | ||
104 | QVBoxLayout *vbox = new QVBoxLayout( this, 0, -1, "VBox" ); | 113 | QVBoxLayout *vbox = new QVBoxLayout( this, 0, -1, "VBox" ); |
105 | QHBoxLayout *hbox1 = new QHBoxLayout( vbox, -1, "HBox1" ); | 114 | QHBoxLayout *hbox1 = new QHBoxLayout( vbox, -1, "HBox1" ); |
106 | hbox1->addWidget( l ); | 115 | hbox1->addWidget( l ); |
107 | hbox1->addWidget( serversList ); | 116 | hbox1->addWidget( serversList ); |
108 | 117 | ||
118 | QHBoxLayout *hbox3 = new QHBoxLayout( vbox, -1, "HBox1" ); | ||
119 | QHBoxLayout *hbox4 = new QHBoxLayout( vbox, -1, "HBox1" ); | ||
120 | |||
121 | char text[2]; | ||
122 | text[1] = '\0'; | ||
123 | for ( int i = 0 ; i < 26 ; ++i ) | ||
124 | { | ||
125 | text[0] = 'A' + i; | ||
126 | LetterPushButton *b = new LetterPushButton( text, this ); | ||
127 | connect( b, SIGNAL( released( QString ) ), this, SLOT( letterPushed( QString ) ) ); | ||
128 | if ( i < 16 ) | ||
129 | hbox3->addWidget( b ); | ||
130 | else | ||
131 | hbox4->addWidget( b ); | ||
132 | } | ||
133 | |||
109 | vbox->addWidget( packagesList ); | 134 | vbox->addWidget( packagesList ); |
110 | packagesList->addColumn( "Packages" ); | 135 | packagesList->addColumn( "Packages" ); |
111 | 136 | ||
112 | QHBoxLayout *hbox2 = new QHBoxLayout( vbox, -1, "HBox2" ); | 137 | QHBoxLayout *hbox2 = new QHBoxLayout( vbox, -1, "HBox2" ); |
113 | hbox2->addWidget( update ); | 138 | hbox2->addWidget( update ); |
114 | hbox2->addWidget( download ); | 139 | hbox2->addWidget( download ); |
@@ -137,14 +162,23 @@ void NetworkPackageManager :: showProgressDialog( char *initialText ) | |||
137 | void NetworkPackageManager :: serverSelected( int ) | 162 | void NetworkPackageManager :: serverSelected( int ) |
138 | { | 163 | { |
139 | packagesList->clear(); | 164 | packagesList->clear(); |
140 | 165 | ||
141 | // display packages | 166 | // display packages |
142 | QString serverName = serversList->currentText(); | 167 | QString serverName = serversList->currentText(); |
168 | currentlySelectedServer = serverName; | ||
169 | |||
170 | #ifdef QWS | ||
171 | // read download directory from config file | ||
172 | Config cfg( "aqpkg" ); | ||
173 | cfg.setGroup( "settings" ); | ||
174 | cfg.writeEntry( "selectedServer", currentlySelectedServer ); | ||
175 | #endif | ||
176 | |||
143 | Server *s = dataMgr->getServer( serverName ); | 177 | Server *s = dataMgr->getServer( serverName ); |
144 | dataMgr->setActiveServer( serverName ); | 178 | // dataMgr->setActiveServer( serverName ); |
145 | 179 | ||
146 | vector<Package> &list = s->getPackageList(); | 180 | vector<Package> &list = s->getPackageList(); |
147 | vector<Package>::iterator it; | 181 | vector<Package>::iterator it; |
148 | for ( it = list.begin() ; it != list.end() ; ++it ) | 182 | for ( it = list.begin() ; it != list.end() ; ++it ) |
149 | { | 183 | { |
150 | QString text = ""; | 184 | QString text = ""; |
@@ -203,27 +237,26 @@ void NetworkPackageManager :: updateServer() | |||
203 | { | 237 | { |
204 | QString serverName = serversList->currentText(); | 238 | QString serverName = serversList->currentText(); |
205 | 239 | ||
206 | // Update the current server | 240 | // Update the current server |
207 | // Display dialog | 241 | // Display dialog |
208 | ProgressDlg *dlg = new ProgressDlg( this ); | 242 | ProgressDlg *dlg = new ProgressDlg( this ); |
209 | QString status = "Updating package list for "; | 243 | QString status = "Updating package lists..."; |
210 | status += serverName; | ||
211 | dlg->show(); | 244 | dlg->show(); |
212 | dlg->setText( status ); | 245 | dlg->setText( status ); |
213 | 246 | ||
214 | // Disable buttons to stop silly people clicking lots on them :) | 247 | // Disable buttons to stop silly people clicking lots on them :) |
215 | 248 | ||
216 | // First, write out ipkg_conf file so that ipkg can use it | 249 | // First, write out ipkg_conf file so that ipkg can use it |
217 | dataMgr->writeOutIpkgConf(); | 250 | dataMgr->writeOutIpkgConf(); |
218 | 251 | ||
219 | if ( serverName == LOCAL_SERVER ) | 252 | // if ( serverName == LOCAL_SERVER ) |
220 | ; | 253 | // ; |
221 | else if ( serverName == LOCAL_IPKGS ) | 254 | // else if ( serverName == LOCAL_IPKGS ) |
222 | ; | 255 | // ; |
223 | else | 256 | // else |
224 | { | 257 | { |
225 | QString option = "update"; | 258 | QString option = "update"; |
226 | QString dummy = ""; | 259 | QString dummy = ""; |
227 | Ipkg ipkg; | 260 | Ipkg ipkg; |
228 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); | 261 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); |
229 | ipkg.setOption( option ); | 262 | ipkg.setOption( option ); |
@@ -299,16 +332,17 @@ void NetworkPackageManager :: downloadPackage() | |||
299 | getcwd( initDir, PATH_MAX ); | 332 | getcwd( initDir, PATH_MAX ); |
300 | 333 | ||
301 | // Download each package | 334 | // Download each package |
302 | Ipkg ipkg; | 335 | Ipkg ipkg; |
303 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); | 336 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); |
304 | 337 | ||
305 | QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | ||
306 | ipkg.setOption( "download" ); | 338 | ipkg.setOption( "download" ); |
307 | ipkg.setRuntimeDirectory( dir ); | 339 | ipkg.setRuntimeDirectory( dir ); |
308 | do | 340 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); |
341 | item != 0 ; | ||
342 | item = (QCheckListItem *)item->nextSibling() ) | ||
309 | { | 343 | { |
310 | if ( item->isOn() ) | 344 | if ( item->isOn() ) |
311 | { | 345 | { |
312 | QString name = item->text(); | 346 | QString name = item->text(); |
313 | int pos = name.find( "*" ); | 347 | int pos = name.find( "*" ); |
314 | name.truncate( pos ); | 348 | name.truncate( pos ); |
@@ -318,20 +352,19 @@ void NetworkPackageManager :: downloadPackage() | |||
318 | if ( pos > 0 ) | 352 | if ( pos > 0 ) |
319 | name.truncate( pos - 1 ); | 353 | name.truncate( pos - 1 ); |
320 | 354 | ||
321 | ipkg.setPackage( name ); | 355 | ipkg.setPackage( name ); |
322 | ipkg.runIpkg( ); | 356 | ipkg.runIpkg( ); |
323 | } | 357 | } |
324 | 358 | } | |
325 | item = (QCheckListItem *)item->nextSibling(); | ||
326 | } while ( item ); | ||
327 | } | 359 | } |
328 | else if ( download->text() == "Remove" ) | 360 | else if ( download->text() == "Remove" ) |
329 | { | 361 | { |
330 | QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | 362 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); |
331 | do | 363 | item != 0 ; |
364 | item = (QCheckListItem *)item->nextSibling() ) | ||
332 | { | 365 | { |
333 | if ( item->isOn() ) | 366 | if ( item->isOn() ) |
334 | { | 367 | { |
335 | QString name = item->text(); | 368 | QString name = item->text(); |
336 | int pos = name.find( "*" ); | 369 | int pos = name.find( "*" ); |
337 | name.truncate( pos ); | 370 | name.truncate( pos ); |
@@ -342,43 +375,41 @@ void NetworkPackageManager :: downloadPackage() | |||
342 | name.truncate( pos - 1 ); | 375 | name.truncate( pos - 1 ); |
343 | 376 | ||
344 | Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name ); | 377 | Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name ); |
345 | QFile f( p->getFilename() ); | 378 | QFile f( p->getFilename() ); |
346 | f.remove(); | 379 | f.remove(); |
347 | } | 380 | } |
348 | item = (QCheckListItem *)item->nextSibling(); | 381 | } |
349 | } while ( item ); | ||
350 | } | 382 | } |
351 | 383 | ||
352 | dataMgr->reloadServerData( LOCAL_IPKGS ); | 384 | dataMgr->reloadServerData( LOCAL_IPKGS ); |
353 | serverSelected( -1 ); | 385 | serverSelected( -1 ); |
354 | } | 386 | } |
355 | 387 | ||
356 | 388 | ||
357 | void NetworkPackageManager :: applyChanges() | 389 | void NetworkPackageManager :: applyChanges() |
358 | { | 390 | { |
359 | // Disable buttons to stop silly people clicking lots on them :) | 391 | // Disable buttons to stop silly people clicking lots on them :) |
360 | 392 | ||
361 | // First, write out ipkg_conf file so that ipkg can use it | 393 | // First, write out ipkg_conf file so that ipkg can use it |
362 | dataMgr->writeOutIpkgConf(); | 394 | dataMgr->writeOutIpkgConf(); |
363 | 395 | ||
364 | // Now for each selected item | 396 | // Now for each selected item |
365 | // deal with it | 397 | // deal with it |
366 | 398 | ||
367 | vector<QString> workingPackages; | 399 | vector<QString> workingPackages; |
368 | QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | 400 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); |
369 | do | 401 | item != 0 ; |
402 | item = (QCheckListItem *)item->nextSibling() ) | ||
370 | { | 403 | { |
371 | if ( item->isOn() ) | 404 | if ( item->isOn() ) |
372 | { | 405 | { |
373 | QString p = dealWithItem( item ); | 406 | QString p = dealWithItem( item ); |
374 | workingPackages.push_back( p ); | 407 | workingPackages.push_back( p ); |
375 | } | 408 | } |
376 | 409 | } | |
377 | item = (QCheckListItem *)item->nextSibling(); | ||
378 | } while ( item ); | ||
379 | 410 | ||
380 | // do the stuff | 411 | // do the stuff |
381 | InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true ); | 412 | InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true ); |
382 | dlg.showDlg(); | 413 | dlg.showDlg(); |
383 | 414 | ||
384 | // Reload data | 415 | // Reload data |
@@ -448,6 +479,24 @@ QString NetworkPackageManager :: dealWithItem( QCheckListItem *item ) | |||
448 | } | 479 | } |
449 | 480 | ||
450 | void NetworkPackageManager :: displayText( const QString &t ) | 481 | void NetworkPackageManager :: displayText( const QString &t ) |
451 | { | 482 | { |
452 | cout << t << endl; | 483 | cout << t << endl; |
453 | } | 484 | } |
485 | |||
486 | |||
487 | void NetworkPackageManager :: letterPushed( QString t ) | ||
488 | { | ||
489 | QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | ||
490 | do | ||
491 | { | ||
492 | if ( item->text().lower().startsWith( t.lower() ) ) | ||
493 | { | ||
494 | cout << "Found - item->text()" << endl; | ||
495 | packagesList->setSelected( item, true ); | ||
496 | packagesList->ensureItemVisible( item ); | ||
497 | break; | ||
498 | } | ||
499 | |||
500 | item = (QCheckListItem *)item->nextSibling(); | ||
501 | } while ( item ); | ||
502 | } | ||
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 | |||
@@ -47,12 +47,13 @@ private: | |||
47 | QPushButton *update; | 47 | QPushButton *update; |
48 | QPushButton *upgrade; | 48 | QPushButton *upgrade; |
49 | QPushButton *download; | 49 | QPushButton *download; |
50 | QPushButton *apply; | 50 | QPushButton *apply; |
51 | 51 | ||
52 | ProgressDlg *progressDlg; | 52 | ProgressDlg *progressDlg; |
53 | QString currentlySelectedServer; | ||
53 | 54 | ||
54 | int timerId; | 55 | int timerId; |
55 | 56 | ||
56 | void timerEvent ( QTimerEvent * ); | 57 | void timerEvent ( QTimerEvent * ); |
57 | 58 | ||
58 | void initGui(); | 59 | void initGui(); |
@@ -64,9 +65,10 @@ public slots: | |||
64 | void serverSelected( int index ); | 65 | void serverSelected( int index ); |
65 | void applyChanges(); | 66 | void applyChanges(); |
66 | void upgradePackages(); | 67 | void upgradePackages(); |
67 | void downloadPackage(); | 68 | void downloadPackage(); |
68 | void updateServer(); | 69 | void updateServer(); |
69 | void displayText( const QString &t ); | 70 | void displayText( const QString &t ); |
71 | void letterPushed( QString t ); | ||
70 | }; | 72 | }; |
71 | 73 | ||
72 | #endif | 74 | #endif |