summaryrefslogtreecommitdiff
path: root/noncore/settings/aqpkg/settingsimpl.cpp
Unidiff
Diffstat (limited to 'noncore/settings/aqpkg/settingsimpl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/aqpkg/settingsimpl.cpp243
1 files changed, 122 insertions, 121 deletions
diff --git a/noncore/settings/aqpkg/settingsimpl.cpp b/noncore/settings/aqpkg/settingsimpl.cpp
index 4887ceb..9fdf31e 100644
--- a/noncore/settings/aqpkg/settingsimpl.cpp
+++ b/noncore/settings/aqpkg/settingsimpl.cpp
@@ -24,13 +24,21 @@
24    --        :-=` Free Software Foundation, Inc., 24    --        :-=` Free Software Foundation, Inc.,
25 59 Temple Place - Suite 330, 25 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27 27
28*/ 28*/
29 29
30#include <fstream> 30#include "settingsimpl.h"
31#include <algorithm> 31#include "global.h"
32using namespace std;
33 32
33/* OPIE */
34#include <opie/otabwidget.h>
35#ifdef QWS
36#include <qpe/config.h>
37#include <qpe/resource.h>
38#endif
39#include <qpe/qpeapplication.h>
40
41/* QT */
34#include <qcheckbox.h> 42#include <qcheckbox.h>
35#include <qgroupbox.h> 43#include <qgroupbox.h>
36#include <qlabel.h> 44#include <qlabel.h>
@@ -39,22 +47,16 @@ using namespace std;
39#include <qlistbox.h> 47#include <qlistbox.h>
40#include <qpushbutton.h> 48#include <qpushbutton.h>
41 49
42#include <opie/otabwidget.h> 50/* STD */
43 51#include <fstream>
44#ifdef QWS 52#include <algorithm>
45#include <qpe/config.h> 53using namespace std;
46#include <qpe/resource.h>
47#endif
48
49#include "settingsimpl.h"
50
51#include "global.h"
52 54
53SettingsImpl :: SettingsImpl( DataManager *dataManager, QWidget * parent, const char* name, bool modal, WFlags fl ) 55SettingsImpl :: SettingsImpl( DataManager *dataManager, QWidget * parent, const char* name, bool modal, WFlags fl )
54 : QDialog( parent, name, modal, fl ) 56 : QDialog( parent, name, modal, fl )
55{ 57{
56 setCaption( tr( "Configuration" ) ); 58 setCaption( tr( "Configuration" ) );
57 59
58 // Setup layout to make everything pretty 60 // Setup layout to make everything pretty
59 QVBoxLayout *layout = new QVBoxLayout( this ); 61 QVBoxLayout *layout = new QVBoxLayout( this );
60 layout->setMargin( 2 ); 62 layout->setMargin( 2 );
@@ -68,7 +70,7 @@ SettingsImpl :: SettingsImpl( DataManager *dataManager, QWidget * parent, const
68 tabwidget->addTab( initDestinationTab(), "aqpkg/desttab", tr( "Destinations" ) ); 70 tabwidget->addTab( initDestinationTab(), "aqpkg/desttab", tr( "Destinations" ) );
69 tabwidget->addTab( initProxyTab(), "aqpkg/proxytab", tr( "Proxies" ) ); 71 tabwidget->addTab( initProxyTab(), "aqpkg/proxytab", tr( "Proxies" ) );
70 tabwidget->setCurrentTab( tr( "Servers" ) ); 72 tabwidget->setCurrentTab( tr( "Servers" ) );
71 73
72 dataMgr = dataManager; 74 dataMgr = dataManager;
73 setupData(); 75 setupData();
74 changed = false; 76 changed = false;
@@ -78,18 +80,15 @@ SettingsImpl :: SettingsImpl( DataManager *dataManager, QWidget * parent, const
78 80
79SettingsImpl :: ~SettingsImpl() 81SettingsImpl :: ~SettingsImpl()
80{ 82{
81
82} 83}
83 84
84bool SettingsImpl :: showDlg() 85bool SettingsImpl :: showDlg()
85{ 86{
86 showMaximized(); 87 QPEApplication::execDialog( this );
87 exec(); 88 if ( changed )
88 89 dataMgr->writeOutIpkgConf();
89 if ( changed )
90 dataMgr->writeOutIpkgConf();
91 90
92 return changed; 91 return changed;
93} 92}
94 93
95QWidget *SettingsImpl :: initServerTab() 94QWidget *SettingsImpl :: initServerTab()
@@ -118,18 +117,18 @@ QWidget *SettingsImpl :: initServerTab()
118 QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), container ); 117 QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), container );
119 connect( btn, SIGNAL( clicked() ), this, SLOT( newServer() ) ); 118 connect( btn, SIGNAL( clicked() ), this, SLOT( newServer() ) );
120 layout->addWidget( btn, 1, 0 ); 119 layout->addWidget( btn, 1, 0 );
121 120
122 btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), container ); 121 btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), container );
123 connect( btn, SIGNAL( clicked() ), this, SLOT( removeServer() ) ); 122 connect( btn, SIGNAL( clicked() ), this, SLOT( removeServer() ) );
124 layout->addWidget( btn, 1, 1 ); 123 layout->addWidget( btn, 1, 1 );
125 124
126 QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Server" ), container ); 125 QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Server" ), container );
127 grpbox->layout()->setSpacing( 2 ); 126 grpbox->layout()->setSpacing( 2 );
128 grpbox->layout()->setMargin( 4 ); 127 grpbox->layout()->setMargin( 4 );
129 layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 ); 128 layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 );
130 129
131 QGridLayout *grplayout = new QGridLayout( grpbox->layout() ); 130 QGridLayout *grplayout = new QGridLayout( grpbox->layout() );
132 131
133 QLabel *label = new QLabel( tr( "Name:" ), grpbox ); 132 QLabel *label = new QLabel( tr( "Name:" ), grpbox );
134 grplayout->addWidget( label, 0, 0 ); 133 grplayout->addWidget( label, 0, 0 );
135 servername = new QLineEdit( grpbox ); 134 servername = new QLineEdit( grpbox );
@@ -142,11 +141,11 @@ QWidget *SettingsImpl :: initServerTab()
142 141
143 active = new QCheckBox( tr( "Active Server" ), grpbox ); 142 active = new QCheckBox( tr( "Active Server" ), grpbox );
144 grplayout->addMultiCellWidget( active, 2, 2, 0, 1 ); 143 grplayout->addMultiCellWidget( active, 2, 2, 0, 1 );
145 144
146 btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Update" ), grpbox ); 145 btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Update" ), grpbox );
147 connect( btn, SIGNAL( clicked() ), this, SLOT( changeServerDetails() ) ); 146 connect( btn, SIGNAL( clicked() ), this, SLOT( changeServerDetails() ) );
148 grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 ); 147 grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 );
149 148
150 return control; 149 return control;
151} 150}
152 151
@@ -176,18 +175,18 @@ QWidget *SettingsImpl :: initDestinationTab()
176 QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), container ); 175 QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), container );
177 connect( btn, SIGNAL( clicked() ), this, SLOT( newDestination() ) ); 176 connect( btn, SIGNAL( clicked() ), this, SLOT( newDestination() ) );
178 layout->addWidget( btn, 1, 0 ); 177 layout->addWidget( btn, 1, 0 );
179 178
180 btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), container ); 179 btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), container );
181 connect( btn, SIGNAL( clicked() ), this, SLOT( removeDestination() ) ); 180 connect( btn, SIGNAL( clicked() ), this, SLOT( removeDestination() ) );
182 layout->addWidget( btn, 1, 1 ); 181 layout->addWidget( btn, 1, 1 );
183 182
184 QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Destination" ), container ); 183 QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Destination" ), container );
185 grpbox->layout()->setSpacing( 2 ); 184 grpbox->layout()->setSpacing( 2 );
186 grpbox->layout()->setMargin( 4 ); 185 grpbox->layout()->setMargin( 4 );
187 layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 ); 186 layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 );
188 187
189 QGridLayout *grplayout = new QGridLayout( grpbox->layout() ); 188 QGridLayout *grplayout = new QGridLayout( grpbox->layout() );
190 189
191 QLabel *label = new QLabel( tr( "Name:" ), grpbox ); 190 QLabel *label = new QLabel( tr( "Name:" ), grpbox );
192 grplayout->addWidget( label, 0, 0 ); 191 grplayout->addWidget( label, 0, 0 );
193 destinationname = new QLineEdit( grpbox ); 192 destinationname = new QLineEdit( grpbox );
@@ -200,11 +199,11 @@ QWidget *SettingsImpl :: initDestinationTab()
200 199
201 linkToRoot = new QCheckBox( tr( "Link to root" ), grpbox ); 200 linkToRoot = new QCheckBox( tr( "Link to root" ), grpbox );
202 grplayout->addMultiCellWidget( linkToRoot, 2, 2, 0, 1 ); 201 grplayout->addMultiCellWidget( linkToRoot, 2, 2, 0, 1 );
203 202
204 btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Update" ), grpbox ); 203 btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Update" ), grpbox );
205 connect( btn, SIGNAL( clicked() ), this, SLOT( changeDestinationDetails() ) ); 204 connect( btn, SIGNAL( clicked() ), this, SLOT( changeDestinationDetails() ) );
206 grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 ); 205 grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 );
207 206
208 return control; 207 return control;
209} 208}
210 209
@@ -235,7 +234,7 @@ QWidget *SettingsImpl :: initProxyTab()
235 grplayout->addWidget( txtHttpProxy ); 234 grplayout->addWidget( txtHttpProxy );
236 chkHttpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox ); 235 chkHttpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox );
237 grplayout->addWidget( chkHttpProxyEnabled ); 236 grplayout->addWidget( chkHttpProxyEnabled );
238 237
239 grpbox = new QGroupBox( 0, Qt::Vertical, tr( "FTP Proxy" ), container ); 238 grpbox = new QGroupBox( 0, Qt::Vertical, tr( "FTP Proxy" ), container );
240 grpbox->layout()->setSpacing( 2 ); 239 grpbox->layout()->setSpacing( 2 );
241 grpbox->layout()->setMargin( 4 ); 240 grpbox->layout()->setMargin( 4 );
@@ -245,7 +244,7 @@ QWidget *SettingsImpl :: initProxyTab()
245 grplayout->addWidget( txtFtpProxy ); 244 grplayout->addWidget( txtFtpProxy );
246 chkFtpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox ); 245 chkFtpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox );
247 grplayout->addWidget( chkFtpProxyEnabled ); 246 grplayout->addWidget( chkFtpProxyEnabled );
248 247
249 QLabel *label = new QLabel( tr( "Username:" ), container ); 248 QLabel *label = new QLabel( tr( "Username:" ), container );
250 layout->addWidget( label, 2, 0 ); 249 layout->addWidget( label, 2, 0 );
251 txtUsername = new QLineEdit( container ); 250 txtUsername = new QLineEdit( container );
@@ -259,7 +258,7 @@ QWidget *SettingsImpl :: initProxyTab()
259 QPushButton *btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Update" ), container ); 258 QPushButton *btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Update" ), container );
260 connect( btn, SIGNAL( clicked() ), this, SLOT( proxyApplyChanges() ) ); 259 connect( btn, SIGNAL( clicked() ), this, SLOT( proxyApplyChanges() ) );
261 layout->addMultiCellWidget( btn, 4, 4, 0, 1 ); 260 layout->addMultiCellWidget( btn, 4, 4, 0, 1 );
262 261
263 return control; 262 return control;
264} 263}
265 264
@@ -269,20 +268,20 @@ void SettingsImpl :: setupData()
269 QString serverName; 268 QString serverName;
270 QListIterator<Server> it( dataMgr->getServerList() ); 269 QListIterator<Server> it( dataMgr->getServerList() );
271 for ( ; it.current(); ++it ) 270 for ( ; it.current(); ++it )
272 { 271 {
273 serverName = it.current()->getServerName(); 272 serverName = it.current()->getServerName();
274 if ( serverName == LOCAL_SERVER || serverName == LOCAL_IPKGS ) 273 if ( serverName == LOCAL_SERVER || serverName == LOCAL_IPKGS )
275 continue; 274 continue;
276 275
277 servers->insertItem( serverName ); 276 servers->insertItem( serverName );
278 } 277 }
279 278
280 279
281 // add destinations 280 // add destinations
282 QListIterator<Destination> it2( dataMgr->getDestinationList() ); 281 QListIterator<Destination> it2( dataMgr->getDestinationList() );
283 for ( ; it2.current(); ++it2 ) 282 for ( ; it2.current(); ++it2 )
284 destinations->insertItem( it2.current()->getDestinationName() ); 283 destinations->insertItem( it2.current()->getDestinationName() );
285 284
286 // setup proxy tab 285 // setup proxy tab
287 txtHttpProxy->setText( dataMgr->getHttpProxy() ); 286 txtHttpProxy->setText( dataMgr->getHttpProxy() );
288 txtFtpProxy->setText( dataMgr->getFtpProxy() ); 287 txtFtpProxy->setText( dataMgr->getFtpProxy() );
@@ -336,53 +335,53 @@ void SettingsImpl :: removeServer()
336 335
337void SettingsImpl :: changeServerDetails() 336void SettingsImpl :: changeServerDetails()
338{ 337{
339 changed = true; 338 changed = true;
340 339
341 QString newName = servername->text(); 340 QString newName = servername->text();
342 341
343 // Convert any spaces to underscores 342 // Convert any spaces to underscores
344 char *tmpStr = new char[newName.length() + 1]; 343 char *tmpStr = new char[newName.length() + 1];
345 for ( unsigned int i = 0 ; i < newName.length() ; ++i ) 344 for ( unsigned int i = 0 ; i < newName.length() ; ++i )
346 { 345 {
347 if ( newName[i] == ' ' ) 346 if ( newName[i] == ' ' )
348 tmpStr[i] = '_'; 347 tmpStr[i] = '_';
349 else 348 else
350 tmpStr[i] = newName[i].latin1(); 349 tmpStr[i] = newName[i].latin1();
351 } 350 }
352 tmpStr[newName.length()] = '\0'; 351 tmpStr[newName.length()] = '\0';
353 352
354 newName = tmpStr; 353 newName = tmpStr;
355 delete tmpStr; 354 delete tmpStr;
356 355
357 if ( !newserver ) 356 if ( !newserver )
358 { 357 {
359 Server *s = dataMgr->getServer( servers->currentText() ); 358 Server *s = dataMgr->getServer( servers->currentText() );
360 if ( s ) 359 if ( s )
361 { 360 {
362 // Update url 361 // Update url
363 s->setServerUrl( serverurl->text() ); 362 s->setServerUrl( serverurl->text() );
364 s->setActive( active->isChecked() ); 363 s->setActive( active->isChecked() );
365 364
366 // Check if server name has changed, if it has then we need to replace the key in the map 365 // Check if server name has changed, if it has then we need to replace the key in the map
367 if ( serverName != newName ) 366 if ( serverName != newName )
368 { 367 {
369 // Update server name 368 // Update server name
370 s->setServerName( newName ); 369 s->setServerName( newName );
371 } 370 }
372 371
373 // Update list box 372 // Update list box
374 servers->changeItem( newName, currentSelectedServer ); 373 servers->changeItem( newName, currentSelectedServer );
375 } 374 }
376 } 375 }
377 else 376 else
378 { 377 {
379 Server s( newName, serverurl->text() ); 378 Server s( newName, serverurl->text() );
380 dataMgr->getServerList().append( new Server( newName, serverurl->text() ) ); 379 dataMgr->getServerList().append( new Server( newName, serverurl->text() ) );
381 dataMgr->getServerList().last()->setActive( active->isChecked() ); 380 dataMgr->getServerList().last()->setActive( active->isChecked() );
382 servers->insertItem( newName ); 381 servers->insertItem( newName );
383 servers->setCurrentItem( servers->count() ); 382 servers->setCurrentItem( servers->count() );
384 newserver = false; 383 newserver = false;
385 } 384 }
386} 385}
387 386
388//------------------ Destinations tab ---------------------- 387//------------------ Destinations tab ----------------------
@@ -409,10 +408,10 @@ void SettingsImpl :: editDestination( int sel )
409 408
410void SettingsImpl :: newDestination() 409void SettingsImpl :: newDestination()
411{ 410{
412 newdestination = true; 411 newdestination = true;
413 destinationname->setText( "" ); 412 destinationname->setText( "" );
414 destinationurl->setText( "" ); 413 destinationurl->setText( "" );
415 destinationname->setFocus(); 414 destinationname->setFocus();
416 linkToRoot->setChecked( true ); 415 linkToRoot->setChecked( true );
417} 416}
418 417
@@ -429,7 +428,7 @@ void SettingsImpl :: removeDestination()
429 428
430void SettingsImpl :: changeDestinationDetails() 429void SettingsImpl :: changeDestinationDetails()
431{ 430{
432 changed = true; 431 changed = true;
433 432
434#ifdef QWS 433#ifdef QWS
435 Config cfg( "aqpkg" ); 434 Config cfg( "aqpkg" );
@@ -437,46 +436,48 @@ void SettingsImpl :: changeDestinationDetails()
437#endif 436#endif
438 437
439 QString newName = destinationname->text(); 438 QString newName = destinationname->text();
440 if ( !newdestination ) 439 if ( !newdestination )
441 { 440 {
442 Destination *d = dataMgr->getDestination( destinations->currentText() ); 441 Destination *d = dataMgr->getDestination( destinations->currentText() );
443 if ( d ) 442 if ( d )
444 { 443 {
445 // Update url 444 // Update url
446 d->setDestinationPath( destinationurl->text() ); 445 d->setDestinationPath( destinationurl->text() );
447 d->linkToRoot( linkToRoot->isChecked() ); 446 d->linkToRoot( linkToRoot->isChecked() );
448 447
449 // Check if server name has changed, if it has then we need to replace the key in the map 448 // Check if server name has changed, if it has then we need to replace the key in the map
450 if ( destinationName != newName ) 449 if ( destinationName != newName )
451 { 450 {
452 // Update server name 451 // Update server name
453 d->setDestinationName( newName ); 452 d->setDestinationName( newName );
454 453
455 // Update list box 454 // Update list box
456 destinations->changeItem( newName, currentSelectedDestination ); 455 destinations->changeItem( newName, currentSelectedDestination );
457 } 456 }
458 457
459#ifdef QWS 458#ifdef QWS
460 QString key = newName; 459 QString key = newName;
461 key += "_linkToRoot"; 460 key += "_linkToRoot";
462 int val = d->linkToRoot(); 461 int val = d->linkToRoot();
463 cfg.writeEntry( key, val ); 462 cfg.writeEntry( key, val );
464#endif 463#endif
465 } 464
466 } 465 }
467 else 466 }
468 { 467 else
469 dataMgr->getDestinationList().append( new Destination( newName, destinationurl->text() ) ); 468 {
470 destinations->insertItem( newName ); 469 dataMgr->getDestinationList().append( new Destination( newName, destinationurl->text() ) );
471 destinations->setCurrentItem( destinations->count() ); 470 destinations->insertItem( newName );
472 newdestination = false; 471 destinations->setCurrentItem( destinations->count() );
472 newdestination = false;
473 473
474#ifdef QWS 474#ifdef QWS
475 QString key = newName; 475 QString key = newName;
476 key += "_linkToRoot"; 476 key += "_linkToRoot";
477 cfg.writeEntry( key, true ); 477 cfg.writeEntry( key, true );
478#endif 478#endif
479 } 479
480 }
480} 481}
481 482
482//------------------ Proxy tab ---------------------- 483//------------------ Proxy tab ----------------------