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.cpp237
1 files changed, 204 insertions, 33 deletions
diff --git a/noncore/settings/aqpkg/settingsimpl.cpp b/noncore/settings/aqpkg/settingsimpl.cpp
index 4bb928a..c5a55d2 100644
--- a/noncore/settings/aqpkg/settingsimpl.cpp
+++ b/noncore/settings/aqpkg/settingsimpl.cpp
@@ -1,140 +1,322 @@
1/*************************************************************************** 1/***************************************************************************
2 settingsimpl.cpp - description 2 settingsimpl.cpp - description
3 ------------------- 3 -------------------
4 begin : Thu Aug 29 2002 4 begin : Thu Aug 29 2002
5 copyright : (C) 2002 by Andy Qua 5 copyright : (C) 2002 by Andy Qua
6 email : andy.qua@blueyonder.co.uk 6 email : andy.qua@blueyonder.co.uk
7 ***************************************************************************/ 7 ***************************************************************************/
8 8
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or * 13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. * 14 * (at your option) any later version. *
15 * * 15 * *
16 ***************************************************************************/ 16 ***************************************************************************/
17 17
18#include <fstream> 18#include <fstream>
19#include <algorithm> 19#include <algorithm>
20using namespace std; 20using namespace std;
21 21
22#include <qlistbox.h> 22#include <qcheckbox.h>
23#include <qgroupbox.h>
24#include <qlabel.h>
25#include <qlayout.h>
23#include <qlineedit.h> 26#include <qlineedit.h>
27#include <qlistbox.h>
24#include <qpushbutton.h> 28#include <qpushbutton.h>
25#include <qtabwidget.h> 29
26#include <qcheckbox.h> 30#include <opie/otabwidget.h>
27 31
28#ifdef QWS 32#ifdef QWS
29#include <qpe/config.h> 33#include <qpe/config.h>
34#include <qpe/resource.h>
30#endif 35#endif
31 36
32#include "settingsimpl.h" 37#include "settingsimpl.h"
33 38
34#include "global.h" 39#include "global.h"
35 40
36SettingsImpl :: SettingsImpl( DataManager *dataManager, QWidget * parent, const char* name, bool modal, WFlags fl ) 41SettingsImpl :: SettingsImpl( DataManager *dataManager, QWidget * parent, const char* name, bool modal, WFlags fl )
37 : SettingsBase( parent, name, modal, fl ) 42 : QDialog( parent, name, modal, fl )
38{ 43{
44 setCaption( tr( "Configuration" ) );
45
46 // Setup layout to make everything pretty
47 QVBoxLayout *layout = new QVBoxLayout( this );
48 layout->setMargin( 2 );
49 layout->setSpacing( 4 );
50
51 // Setup tabs for all info
52 OTabWidget *tabwidget = new OTabWidget( this );
53 layout->addWidget( tabwidget );
54
55 tabwidget->addTab( initServerTab(), "aqpkg/servertab", tr( "Servers" ) );
56 tabwidget->addTab( initDestinationTab(), "aqpkg/desttab", tr( "Destinations" ) );
57 tabwidget->addTab( initProxyTab(), "aqpkg/proxytab", tr( "Proxies" ) );
58 tabwidget->setCurrentTab( tr( "Servers" ) );
59
39 dataMgr = dataManager; 60 dataMgr = dataManager;
40
41 setupData(); 61 setupData();
42 changed = false; 62 changed = false;
43 newserver = false; 63 newserver = false;
44 newdestination = false; 64 newdestination = false;
45} 65}
46 66
47SettingsImpl :: ~SettingsImpl() 67SettingsImpl :: ~SettingsImpl()
48{ 68{
49 69
50} 70}
51 71
52bool SettingsImpl :: showDlg( int i ) 72bool SettingsImpl :: showDlg()
53{ 73{
54 TabWidget->setCurrentPage( i );
55 showMaximized(); 74 showMaximized();
56 exec(); 75 exec();
57 76
58 if ( changed ) 77 if ( changed )
59 dataMgr->writeOutIpkgConf(); 78 dataMgr->writeOutIpkgConf();
60 79
61 return changed; 80 return changed;
62} 81}
63 82
83QWidget *SettingsImpl :: initServerTab()
84{
85 QWidget *control = new QWidget( this );
86
87 QVBoxLayout *vb = new QVBoxLayout( control );
88
89 QScrollView *sv = new QScrollView( control );
90 vb->addWidget( sv, 0, 0 );
91 sv->setResizePolicy( QScrollView::AutoOneFit );
92 sv->setFrameStyle( QFrame::NoFrame );
93
94 QWidget *container = new QWidget( sv->viewport() );
95 sv->addChild( container );
96
97 QGridLayout *layout = new QGridLayout( container );
98 layout->setSpacing( 2 );
99 layout->setMargin( 4 );
100
101 servers = new QListBox( container );
102 servers->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
103 connect( servers, SIGNAL( highlighted( int ) ), this, SLOT( editServer( int ) ) );
104 layout->addMultiCellWidget( servers, 0, 0, 0, 1 );
105
106 QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), container );
107 connect( btn, SIGNAL( clicked() ), this, SLOT( newServer() ) );
108 layout->addWidget( btn, 1, 0 );
109
110 btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), container );
111 connect( btn, SIGNAL( clicked() ), this, SLOT( removeServer() ) );
112 layout->addWidget( btn, 1, 1 );
113
114 QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Server" ), container );
115 grpbox->layout()->setSpacing( 2 );
116 grpbox->layout()->setMargin( 4 );
117 layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 );
118
119 QGridLayout *grplayout = new QGridLayout( grpbox->layout() );
120
121 QLabel *label = new QLabel( tr( "Name:" ), grpbox );
122 grplayout->addWidget( label, 0, 0 );
123 servername = new QLineEdit( grpbox );
124 grplayout->addWidget( servername, 0, 1 );
125
126 label = new QLabel( tr( "Address:" ), grpbox );
127 grplayout->addWidget( label, 1, 0 );
128 serverurl = new QLineEdit( grpbox );
129 grplayout->addWidget( serverurl, 1, 1 );
130
131 active = new QCheckBox( tr( "Active Server" ), grpbox );
132 grplayout->addMultiCellWidget( active, 2, 2, 0, 1 );
133
134 btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Update" ), grpbox );
135 connect( btn, SIGNAL( clicked() ), this, SLOT( changeServerDetails() ) );
136 grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 );
137
138 return control;
139}
140
141QWidget *SettingsImpl :: initDestinationTab()
142{
143 QWidget *control = new QWidget( this );
144
145 QVBoxLayout *vb = new QVBoxLayout( control );
146
147 QScrollView *sv = new QScrollView( control );
148 vb->addWidget( sv, 0, 0 );
149 sv->setResizePolicy( QScrollView::AutoOneFit );
150 sv->setFrameStyle( QFrame::NoFrame );
151
152 QWidget *container = new QWidget( sv->viewport() );
153 sv->addChild( container );
154
155 QGridLayout *layout = new QGridLayout( container );
156 layout->setSpacing( 2 );
157 layout->setMargin( 4 );
158
159 destinations = new QListBox( container );
160 destinations->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
161 connect( destinations, SIGNAL( highlighted( int ) ), this, SLOT( editDestination( int ) ) );
162 layout->addMultiCellWidget( destinations, 0, 0, 0, 1 );
163
164 QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), container );
165 connect( btn, SIGNAL( clicked() ), this, SLOT( newDestination() ) );
166 layout->addWidget( btn, 1, 0 );
167
168 btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), container );
169 connect( btn, SIGNAL( clicked() ), this, SLOT( removeDestination() ) );
170 layout->addWidget( btn, 1, 1 );
171
172 QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Destination" ), container );
173 grpbox->layout()->setSpacing( 2 );
174 grpbox->layout()->setMargin( 4 );
175 layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 );
176
177 QGridLayout *grplayout = new QGridLayout( grpbox->layout() );
178
179 QLabel *label = new QLabel( tr( "Name:" ), grpbox );
180 grplayout->addWidget( label, 0, 0 );
181 destinationname = new QLineEdit( grpbox );
182 grplayout->addWidget( destinationname, 0, 1 );
183
184 label = new QLabel( tr( "Location:" ), grpbox );
185 grplayout->addWidget( label, 1, 0 );
186 destinationurl = new QLineEdit( grpbox );
187 grplayout->addWidget( destinationurl, 1, 1 );
188
189 linkToRoot = new QCheckBox( tr( "Link to root" ), grpbox );
190 grplayout->addMultiCellWidget( linkToRoot, 2, 2, 0, 1 );
191
192 btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Update" ), grpbox );
193 connect( btn, SIGNAL( clicked() ), this, SLOT( changeDestinationDetails() ) );
194 grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 );
195
196 return control;
197}
198
199QWidget *SettingsImpl :: initProxyTab()
200{
201 QWidget *control = new QWidget( this );
202
203 QVBoxLayout *vb = new QVBoxLayout( control );
204
205 QScrollView *sv = new QScrollView( control );
206 vb->addWidget( sv, 0, 0 );
207 sv->setResizePolicy( QScrollView::AutoOneFit );
208 sv->setFrameStyle( QFrame::NoFrame );
209
210 QWidget *container = new QWidget( sv->viewport() );
211 sv->addChild( container );
212
213 QGridLayout *layout = new QGridLayout( container );
214 layout->setSpacing( 2 );
215 layout->setMargin( 4 );
216
217 QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "HTTP Proxy" ), container );
218 grpbox->layout()->setSpacing( 2 );
219 grpbox->layout()->setMargin( 4 );
220 layout->addMultiCellWidget( grpbox, 0, 0, 0, 1 );
221 QVBoxLayout *grplayout = new QVBoxLayout( grpbox->layout() );
222 txtHttpProxy = new QLineEdit( grpbox );
223 grplayout->addWidget( txtHttpProxy );
224 chkHttpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox );
225 grplayout->addWidget( chkHttpProxyEnabled );
226
227 grpbox = new QGroupBox( 0, Qt::Vertical, tr( "FTP Proxy" ), container );
228 grpbox->layout()->setSpacing( 2 );
229 grpbox->layout()->setMargin( 4 );
230 layout->addMultiCellWidget( grpbox, 1, 1, 0, 1 );
231 grplayout = new QVBoxLayout( grpbox->layout() );
232 txtFtpProxy = new QLineEdit( grpbox );
233 grplayout->addWidget( txtFtpProxy );
234 chkFtpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox );
235 grplayout->addWidget( chkFtpProxyEnabled );
236
237 QLabel *label = new QLabel( tr( "Username:" ), container );
238 layout->addWidget( label, 2, 0 );
239 txtUsername = new QLineEdit( container );
240 layout->addWidget( txtUsername, 2, 1 );
241
242 label = new QLabel( tr( "Password:" ), container );
243 layout->addWidget( label, 3, 0 );
244 txtPassword = new QLineEdit( container );
245 layout->addWidget( txtPassword, 3, 1 );
246
247 QPushButton *btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Update" ), container );
248 connect( btn, SIGNAL( clicked() ), this, SLOT( proxyApplyChanges() ) );
249 layout->addMultiCellWidget( btn, 4, 4, 0, 1 );
250
251 return control;
252}
253
64void SettingsImpl :: setupData() 254void SettingsImpl :: setupData()
65{ 255{
66 // add servers 256 // add servers
67 vector<Server>::iterator it; 257 vector<Server>::iterator it;
68 for ( it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it ) 258 for ( it = dataMgr->getServerList().begin() ; it != dataMgr->getServerList().end() ; ++it )
69 { 259 {
70 if ( it->getServerName() == LOCAL_SERVER || it->getServerName() == LOCAL_IPKGS ) 260 if ( it->getServerName() == LOCAL_SERVER || it->getServerName() == LOCAL_IPKGS )
71 continue; 261 continue;
72 262
73 servers->insertItem( it->getServerName() ); 263 servers->insertItem( it->getServerName() );
74 } 264 }
75 265
266
76 // add destinations 267 // add destinations
77 vector<Destination>::iterator it2; 268 vector<Destination>::iterator it2;
78 for ( it2 = dataMgr->getDestinationList().begin() ; it2 != dataMgr->getDestinationList().end() ; ++it2 ) 269 for ( it2 = dataMgr->getDestinationList().begin() ; it2 != dataMgr->getDestinationList().end() ; ++it2 )
79 destinations->insertItem( it2->getDestinationName() ); 270 destinations->insertItem( it2->getDestinationName() );
80 271
81 // setup general tab
82#ifdef QWS
83 Config cfg( "aqpkg" );
84 cfg.setGroup( "settings" );
85 jumpTo->setChecked( cfg.readBoolEntry( "showJumpTo", "true" ) );
86#else
87 jumpTo->setChecked( true );
88#endif
89
90 // setup proxy tab 272 // setup proxy tab
91 txtHttpProxy->setText( dataMgr->getHttpProxy() ); 273 txtHttpProxy->setText( dataMgr->getHttpProxy() );
92 txtFtpProxy->setText( dataMgr->getFtpProxy() ); 274 txtFtpProxy->setText( dataMgr->getFtpProxy() );
93 txtUsername->setText( dataMgr->getProxyUsername() ); 275 txtUsername->setText( dataMgr->getProxyUsername() );
94 txtPassword->setText( dataMgr->getProxyPassword() ); 276 txtPassword->setText( dataMgr->getProxyPassword() );
95 chkHttpProxyEnabled->setChecked( dataMgr->getHttpProxyEnabled() ); 277 chkHttpProxyEnabled->setChecked( dataMgr->getHttpProxyEnabled() );
96 chkFtpProxyEnabled->setChecked( dataMgr->getFtpProxyEnabled() ); 278 chkFtpProxyEnabled->setChecked( dataMgr->getFtpProxyEnabled() );
97} 279}
98 280
99//------------------ Servers tab ---------------------- 281//------------------ Servers tab ----------------------
100 282
101void SettingsImpl :: editServer( int sel ) 283void SettingsImpl :: editServer( int sel )
102{ 284{
103 currentSelectedServer = sel; 285 currentSelectedServer = sel;
104 vector<Server>::iterator s = dataMgr->getServer( servers->currentText() ); 286 vector<Server>::iterator s = dataMgr->getServer( servers->currentText() );
105 serverName = s->getServerName(); 287 serverName = s->getServerName();
106 servername->setText( s->getServerName() ); 288 servername->setText( s->getServerName() );
107 serverurl->setText( s->getServerUrl() ); 289 serverurl->setText( s->getServerUrl() );
108 active->setChecked( s->isServerActive() ); 290 active->setChecked( s->isServerActive() );
109} 291}
110 292
111void SettingsImpl :: newServer() 293void SettingsImpl :: newServer()
112{ 294{
113 newserver = true; 295 newserver = true;
114 servername->setText( "" ); 296 servername->setText( "" );
115 serverurl->setText( "" ); 297 serverurl->setText( "" );
116 servername->setFocus(); 298 servername->setFocus();
117 active->setChecked( true ); 299 active->setChecked( true );
118} 300}
119 301
120void SettingsImpl :: removeServer() 302void SettingsImpl :: removeServer()
121{ 303{
122 changed = true; 304 changed = true;
123 vector<Server>::iterator s = dataMgr->getServer( servers->currentText() ); 305 vector<Server>::iterator s = dataMgr->getServer( servers->currentText() );
124 dataMgr->getServerList().erase( s ); 306 dataMgr->getServerList().erase( s );
125 servers->removeItem( currentSelectedServer ); 307 servers->removeItem( currentSelectedServer );
126} 308}
127 309
128void SettingsImpl :: changeServerDetails() 310void SettingsImpl :: changeServerDetails()
129{ 311{
130 changed = true; 312 changed = true;
131 313
132 QString newName = servername->text(); 314 QString newName = servername->text();
133 if ( !newserver ) 315 if ( !newserver )
134 { 316 {
135 vector<Server>::iterator s = dataMgr->getServer( servers->currentText() ); 317 vector<Server>::iterator s = dataMgr->getServer( servers->currentText() );
136 318
137 // Update url 319 // Update url
138 s->setServerUrl( serverurl->text() ); 320 s->setServerUrl( serverurl->text() );
139 s->setActive( active->isChecked() ); 321 s->setActive( active->isChecked() );
140 322
@@ -221,47 +403,36 @@ void SettingsImpl :: changeDestinationDetails()
221 destinations->changeItem( newName, currentSelectedDestination ); 403 destinations->changeItem( newName, currentSelectedDestination );
222 } 404 }
223#ifdef QWS 405#ifdef QWS
224 QString key = newName; 406 QString key = newName;
225 key += "_linkToRoot"; 407 key += "_linkToRoot";
226 int val = d->linkToRoot(); 408 int val = d->linkToRoot();
227 cfg.writeEntry( key, val ); 409 cfg.writeEntry( key, val );
228#endif 410#endif
229 } 411 }
230 else 412 else
231 { 413 {
232 dataMgr->getDestinationList().push_back( Destination( newName, destinationurl->text() ) ); 414 dataMgr->getDestinationList().push_back( Destination( newName, destinationurl->text() ) );
233 destinations->insertItem( newName ); 415 destinations->insertItem( newName );
234 destinations->setCurrentItem( destinations->count() ); 416 destinations->setCurrentItem( destinations->count() );
235 newdestination = false; 417 newdestination = false;
236 418
237#ifdef QWS 419#ifdef QWS
238 QString key = newName; 420 QString key = newName;
239 key += "_linkToRoot"; 421 key += "_linkToRoot";
240 cfg.writeEntry( key, true ); 422 cfg.writeEntry( key, true );
241#endif 423#endif
242 } 424 }
243} 425}
244 426
245//------------------ General tab ----------------------
246
247void SettingsImpl :: toggleJumpTo( bool val )
248{
249#ifdef QWS
250 Config cfg( "aqpkg" );
251 cfg.setGroup( "settings" );
252 cfg.writeEntry( "showJumpTo", val );
253#endif
254}
255
256//------------------ Proxy tab ---------------------- 427//------------------ Proxy tab ----------------------
257void SettingsImpl :: proxyApplyChanges() 428void SettingsImpl :: proxyApplyChanges()
258{ 429{
259 changed = true; 430 changed = true;
260 dataMgr->setHttpProxy( txtHttpProxy->text() ); 431 dataMgr->setHttpProxy( txtHttpProxy->text() );
261 dataMgr->setFtpProxy( txtFtpProxy->text() ); 432 dataMgr->setFtpProxy( txtFtpProxy->text() );
262 dataMgr->setProxyUsername( txtUsername->text() ); 433 dataMgr->setProxyUsername( txtUsername->text() );
263 dataMgr->setProxyPassword( txtPassword->text() ); 434 dataMgr->setProxyPassword( txtPassword->text() );
264 435
265 dataMgr->setHttpProxyEnabled( chkHttpProxyEnabled->isChecked() ); 436 dataMgr->setHttpProxyEnabled( chkHttpProxyEnabled->isChecked() );
266 dataMgr->setFtpProxyEnabled( chkFtpProxyEnabled->isChecked() ); 437 dataMgr->setFtpProxyEnabled( chkFtpProxyEnabled->isChecked() );
267} 438}