summaryrefslogtreecommitdiff
path: root/noncore/settings/packagemanager/oipkgconfigdlg.cpp
Unidiff
Diffstat (limited to 'noncore/settings/packagemanager/oipkgconfigdlg.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/packagemanager/oipkgconfigdlg.cpp558
1 files changed, 558 insertions, 0 deletions
diff --git a/noncore/settings/packagemanager/oipkgconfigdlg.cpp b/noncore/settings/packagemanager/oipkgconfigdlg.cpp
new file mode 100644
index 0000000..e335f8f
--- a/dev/null
+++ b/noncore/settings/packagemanager/oipkgconfigdlg.cpp
@@ -0,0 +1,558 @@
1/*
2                This file is part of the Opie Project
3
4              Copyright (c) 2003 Dan Williams <drw@handhelds.org>
5 =.
6 .=l.
7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details.
22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA.
29
30*/
31
32#include "oipkgconfigdlg.h"
33
34#include <qcheckbox.h>
35#include <qcombobox.h>
36#include <qgroupbox.h>
37#include <qlabel.h>
38#include <qlineedit.h>
39#include <qlistbox.h>
40#include <qpushbutton.h>
41#include <qscrollview.h>
42
43#include <qpe/resource.h>
44
45OIpkgConfigDlg::OIpkgConfigDlg( OIpkg *ipkg, bool installOptions, QWidget *parent )
46 : QDialog( parent, QString::null, true )
47 , m_ipkg( ipkg )
48 , m_configs( 0x0 )
49 , m_installOptions( installOptions )
50 , m_serverNew( false )
51 , m_serverCurrent( -1 )
52 , m_destNew( false )
53 , m_destCurrent( -1 )
54 , m_layout( this, 2, 4 )
55 , m_tabWidget( this )
56{
57 setCaption( tr( "Configuration" ) );
58
59 // Initialize configuration widgets
60 if ( !installOptions )
61 {
62 initServerWidget();
63 initDestinationWidget();
64 initProxyWidget();
65 }
66 initOptionsWidget();
67
68 // Load configuration information
69 initData();
70
71 // Setup tabs for all info
72 m_layout.addWidget( &m_tabWidget );
73 if ( !m_installOptions )
74 {
75 m_tabWidget.addTab( m_serverWidget, "packagemanager/servertab", tr( "Servers" ) );
76 m_tabWidget.addTab( m_destWidget, "packagemanager/desttab", tr( "Destinations" ) );
77 m_tabWidget.addTab( m_proxyWidget, "packagemanager/proxytab", tr( "Proxies" ) );
78 m_tabWidget.addTab( m_optionsWidget, "exec", tr( "Options" ) );
79 m_tabWidget.setCurrentTab( tr( "Servers" ) );
80 }
81 else
82 {
83 m_tabWidget.addTab( m_optionsWidget, "exec", tr( "Options" ) );
84 }
85
86 showMaximized();
87}
88
89void OIpkgConfigDlg::accept()
90{
91 // Save server, destination and proxy configuration
92 if ( !m_installOptions )
93 m_ipkg->setConfigItems( m_configs );
94
95 // Save options configuration
96 int options = 0;
97 if ( m_optForceDepends->isChecked() )
98 options |= FORCE_DEPENDS;
99 if ( m_optForceReinstall->isChecked() )
100 options |= FORCE_REINSTALL;
101 if ( m_optForceRemove->isChecked() )
102 options |= FORCE_REMOVE;
103 if ( m_optForceOverwrite->isChecked() )
104 options |= FORCE_OVERWRITE;
105 m_ipkg->setIpkgExecOptions( options );
106 m_ipkg->setIpkgExecVerbosity( m_optVerboseIpkg->currentItem() );
107
108 QDialog::accept();
109}
110
111void OIpkgConfigDlg::reject()
112{
113 if ( m_configs )
114 delete m_configs;
115}
116
117void OIpkgConfigDlg::initServerWidget()
118{
119 m_serverWidget = new QWidget( this );
120
121 // Initialize UI
122 QVBoxLayout *vb = new QVBoxLayout( m_serverWidget );
123 QScrollView *sv = new QScrollView( m_serverWidget );
124 vb->addWidget( sv, 0, 0 );
125 sv->setResizePolicy( QScrollView::AutoOneFit );
126 sv->setFrameStyle( QFrame::NoFrame );
127 QWidget *container = new QWidget( sv->viewport() );
128 sv->addChild( container );
129 QGridLayout *layout = new QGridLayout( container, 3, 2, 2, 4 );
130
131 m_serverList = new QListBox( container );
132 m_serverList->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
133 connect( m_serverList, SIGNAL(highlighted(int)), this, SLOT(slotServerEdit(int)) );
134 layout->addMultiCellWidget( m_serverList, 0, 0, 0, 1 );
135
136 QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), container );
137 connect( btn, SIGNAL(clicked()), this, SLOT(slotServerNew()) );
138 layout->addWidget( btn, 1, 0 );
139
140 btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), container );
141 connect( btn, SIGNAL(clicked()), this, SLOT(slotServerDelete()) );
142 layout->addWidget( btn, 1, 1 );
143
144 QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Server" ), container );
145 grpbox->layout()->setSpacing( 2 );
146 grpbox->layout()->setMargin( 4 );
147 layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 );
148
149 QGridLayout *grplayout = new QGridLayout( grpbox->layout() );
150
151 QLabel *label = new QLabel( tr( "Name:" ), grpbox );
152 grplayout->addWidget( label, 0, 0 );
153 m_serverName = new QLineEdit( grpbox );
154 grplayout->addWidget( m_serverName, 0, 1 );
155
156 label = new QLabel( tr( "Address:" ), grpbox );
157 grplayout->addWidget( label, 1, 0 );
158 m_serverLocation = new QLineEdit( grpbox );
159 grplayout->addWidget( m_serverLocation, 1, 1 );
160
161 m_serverActive = new QCheckBox( tr( "Active Server" ), grpbox );
162 grplayout->addMultiCellWidget( m_serverActive, 2, 2, 0, 1 );
163
164 btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Update" ), grpbox );
165 connect( btn, SIGNAL(clicked()), this, SLOT(slotServerUpdate()) );
166 grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 );
167}
168
169void OIpkgConfigDlg::initDestinationWidget()
170{
171 m_destWidget = new QWidget( this );
172
173 // Initialize UI
174 QVBoxLayout *vb = new QVBoxLayout( m_destWidget );
175 QScrollView *sv = new QScrollView( m_destWidget );
176 vb->addWidget( sv, 0, 0 );
177 sv->setResizePolicy( QScrollView::AutoOneFit );
178 sv->setFrameStyle( QFrame::NoFrame );
179 QWidget *container = new QWidget( sv->viewport() );
180 sv->addChild( container );
181 QGridLayout *layout = new QGridLayout( container, 3, 2, 2, 4 );
182
183 m_destList = new QListBox( container );
184 m_destList->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
185 connect( m_destList, SIGNAL(highlighted(int)), this, SLOT(slotDestEdit(int)) );
186 layout->addMultiCellWidget( m_destList, 0, 0, 0, 1 );
187
188 QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), container );
189 connect( btn, SIGNAL(clicked()), this, SLOT(slotDestNew()) );
190 layout->addWidget( btn, 1, 0 );
191
192 btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), container );
193 connect( btn, SIGNAL(clicked()), this, SLOT(slotDestDelete()) );
194 layout->addWidget( btn, 1, 1 );
195
196 QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Server" ), container );
197 grpbox->layout()->setSpacing( 2 );
198 grpbox->layout()->setMargin( 4 );
199 layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 );
200
201 QGridLayout *grplayout = new QGridLayout( grpbox->layout() );
202
203 QLabel *label = new QLabel( tr( "Name:" ), grpbox );
204 grplayout->addWidget( label, 0, 0 );
205 m_destName = new QLineEdit( grpbox );
206 grplayout->addWidget( m_destName, 0, 1 );
207
208 label = new QLabel( tr( "Address:" ), grpbox );
209 grplayout->addWidget( label, 1, 0 );
210 m_destLocation = new QLineEdit( grpbox );
211 grplayout->addWidget( m_destLocation, 1, 1 );
212
213 m_destActive = new QCheckBox( tr( "Active Server" ), grpbox );
214 grplayout->addMultiCellWidget( m_destActive, 2, 2, 0, 1 );
215
216 btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Update" ), grpbox );
217 connect( btn, SIGNAL(clicked()), this, SLOT(slotDestUpdate()) );
218 grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 );
219}
220
221void OIpkgConfigDlg::initProxyWidget()
222{
223 m_proxyWidget = new QWidget( this );
224
225 // Initialize UI
226 QVBoxLayout *vb = new QVBoxLayout( m_proxyWidget );
227 QScrollView *sv = new QScrollView( m_proxyWidget );
228 vb->addWidget( sv, 0, 0 );
229 sv->setResizePolicy( QScrollView::AutoOneFit );
230 sv->setFrameStyle( QFrame::NoFrame );
231 QWidget *container = new QWidget( sv->viewport() );
232 sv->addChild( container );
233 QGridLayout *layout = new QGridLayout( container, 4, 2, 2, 4 );
234
235 // HTTP proxy server configuration
236 QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "HTTP Proxy" ), container );
237 grpbox->layout()->setSpacing( 2 );
238 grpbox->layout()->setMargin( 4 );
239 layout->addMultiCellWidget( grpbox, 0, 0, 0, 1 );
240 QVBoxLayout *grplayout = new QVBoxLayout( grpbox->layout() );
241 m_proxyHttpServer = new QLineEdit( grpbox );
242 grplayout->addWidget( m_proxyHttpServer );
243 m_proxyHttpActive = new QCheckBox( tr( "Enabled" ), grpbox );
244 grplayout->addWidget( m_proxyHttpActive );
245
246 // FTP proxy server configuration
247 grpbox = new QGroupBox( 0, Qt::Vertical, tr( "FTP Proxy" ), container );
248 grpbox->layout()->setSpacing( 2 );
249 grpbox->layout()->setMargin( 4 );
250 layout->addMultiCellWidget( grpbox, 1, 1, 0, 1 );
251 grplayout = new QVBoxLayout( grpbox->layout() );
252 m_proxyFtpServer = new QLineEdit( grpbox );
253 grplayout->addWidget( m_proxyFtpServer );
254 m_proxyFtpActive = new QCheckBox( tr( "Enabled" ), grpbox );
255 grplayout->addWidget( m_proxyFtpActive );
256
257 // Proxy server username and password configuration
258 QLabel *label = new QLabel( tr( "Username:" ), container );
259 layout->addWidget( label, 2, 0 );
260 m_proxyUsername = new QLineEdit( container );
261 layout->addWidget( m_proxyUsername, 2, 1 );
262
263 label = new QLabel( tr( "Password:" ), container );
264 layout->addWidget( label, 3, 0 );
265 m_proxyPassword = new QLineEdit( container );
266 layout->addWidget( m_proxyPassword, 3, 1 );
267}
268
269void OIpkgConfigDlg::initOptionsWidget()
270{
271 m_optionsWidget = new QWidget( this );
272
273 // Initialize UI
274 QVBoxLayout *vb = new QVBoxLayout( m_optionsWidget );
275 QScrollView *sv = new QScrollView( m_optionsWidget );
276 vb->addWidget( sv, 0, 0 );
277 sv->setResizePolicy( QScrollView::AutoOneFit );
278 sv->setFrameStyle( QFrame::NoFrame );
279 QWidget *container = new QWidget( sv->viewport() );
280 sv->addChild( container );
281 QVBoxLayout *layout = new QVBoxLayout( container, 2, 4 );
282
283 m_optForceDepends = new QCheckBox( tr( "Force Depends" ), container );
284 layout->addWidget( m_optForceDepends );
285
286 m_optForceReinstall = new QCheckBox( tr( "Force Reinstall" ), container );
287 layout->addWidget( m_optForceReinstall );
288
289 m_optForceRemove = new QCheckBox( tr( "Force Remove" ), container );
290 layout->addWidget( m_optForceRemove );
291
292 m_optForceOverwrite = new QCheckBox( tr( "Force Overwrite" ), container );
293 layout->addWidget( m_optForceOverwrite );
294
295 QLabel *l = new QLabel( tr( "Information Level" ), container );
296 layout->addWidget( l );
297
298 m_optVerboseIpkg = new QComboBox( container );
299 m_optVerboseIpkg->insertItem( tr( "Errors only" ) );
300 m_optVerboseIpkg->insertItem( tr( "Normal messages" ) );
301 m_optVerboseIpkg->insertItem( tr( "Informative messages" ) );
302 m_optVerboseIpkg->insertItem( tr( "Troubleshooting output" ) );
303 layout->addWidget( m_optVerboseIpkg );
304
305 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
306}
307
308void OIpkgConfigDlg::initData()
309{
310 // Read ipkg configuration (server/destination/proxy) information
311 if ( m_ipkg && !m_installOptions )
312 {
313 m_configs = m_ipkg->configItems();
314 if ( m_configs )
315 {
316 for ( OConfItemListIterator configIt( *m_configs ); configIt.current(); ++configIt )
317 {
318 OConfItem *config = configIt.current();
319
320 // Add configuration item to the appropriate dialog controls
321 if ( config )
322 {
323 if ( config->type() == OConfItem::Source )
324 {
325 m_serverList->insertItem( config->name() );
326 }
327 else if ( config->type() == OConfItem::Destination )
328 {
329 m_destList->insertItem( config->name() );
330 }
331 else if ( config->type() == OConfItem::Option )
332 {
333 if ( config->name() == "http_proxy" )
334 {
335 m_proxyHttpServer->setText( config->value() );
336 m_proxyHttpActive->setChecked( config->active() );
337 }
338 else if ( config->name() == "ftp_proxy" )
339 {
340 m_proxyFtpServer->setText( config->value() );
341 m_proxyFtpActive->setChecked( config->active() );
342 }
343 else if ( config->name() == "proxy_username" )
344 {
345 m_proxyUsername->setText( config->value() );
346 }
347 else if ( config->name() == "proxy_password" )
348 {
349 m_proxyPassword->setText( config->value() );
350 }
351 }
352 }
353 }
354 }
355 }
356
357 // Get Ipkg execution options
358 int options = m_ipkg->ipkgExecOptions();
359 if ( options & FORCE_DEPENDS )
360 m_optForceDepends->setChecked( true );
361 if ( options & FORCE_REINSTALL )
362 m_optForceReinstall->setChecked( true );
363 if ( options & FORCE_REMOVE )
364 m_optForceRemove->setChecked( true );
365 if ( options & FORCE_OVERWRITE )
366 m_optForceOverwrite->setChecked( true );
367
368 m_optVerboseIpkg->setCurrentItem( m_ipkg->ipkgExecVerbosity() );
369}
370
371OConfItem *OIpkgConfigDlg::findConfItem( OConfItem::Type type, const QString &name )
372{
373 // Find selected server in list
374 OConfItemListIterator configIt( *m_configs );
375 OConfItem *config = 0x0;
376 for ( ; configIt.current(); ++configIt )
377 {
378 config = configIt.current();
379 if ( config->type() == type && config->name() == name )
380 break;
381 }
382
383 if ( config && config->type() == type && config->name() == name )
384 return config;
385
386 return 0x0;
387}
388
389void OIpkgConfigDlg::slotServerEdit( int index )
390{
391 m_serverNew = false;
392 m_serverCurrent = index;
393
394 // Find selected server in list
395 OConfItem *server = findConfItem( OConfItem::Source, m_serverList->currentText() );
396
397 // Display server details
398 if ( server )
399 {
400 m_serverCurrName = server->name();
401 m_serverName->setText( server->name() );
402 m_serverLocation->setText( server->value() );
403 m_serverActive->setChecked( server->active() );
404 m_serverName->setFocus();
405 }
406}
407
408void OIpkgConfigDlg::slotServerNew()
409{
410 m_serverNew = true;
411
412 m_serverName->setText( QString::null );
413 m_serverLocation->setText( QString::null );
414 m_serverActive->setChecked( true );
415 m_serverName->setFocus();
416}
417
418void OIpkgConfigDlg::slotServerDelete()
419{
420 // Find selected server in list
421 OConfItem *server = findConfItem( OConfItem::Source, m_serverList->currentText() );
422
423 // Delete server
424 if ( server )
425 {
426 m_configs->removeRef( server );
427 m_serverList->removeItem( m_serverCurrent );
428 }
429}
430
431void OIpkgConfigDlg::slotServerUpdate()
432{
433 QString newName = m_serverName->text();
434
435 // Convert any spaces to underscores
436 newName.replace( QRegExp( " " ), "_" );
437
438 if ( !m_serverNew )
439 {
440 // Find selected server in list
441 OConfItem *server = findConfItem( OConfItem::Source, m_serverCurrName );
442
443 // Delete server
444 if ( server )
445 {
446 // Update url
447 server->setValue( m_serverLocation->text() );
448 server->setActive( m_serverActive->isChecked() );
449
450 // Check if server name has changed, if it has then we need to replace the key in the map
451 if ( m_serverCurrName != newName )
452 {
453 // Update server name
454 server->setName( newName );
455
456 // Update list box
457 m_serverList->changeItem( newName, m_serverCurrent );
458 }
459 }
460 }
461 else
462 {
463 // Add new destination to configuration list
464 m_configs->append( new OConfItem( QString::null, OConfItem::Source, newName,
465 m_serverLocation->text(), m_serverActive->isChecked() ) );
466 m_configs->sort();
467
468 m_serverList->insertItem( newName );
469 m_serverList->setCurrentItem( m_serverList->count() );
470 m_serverNew = false;
471 m_serverList->insertItem( newName );
472 }
473}
474
475void OIpkgConfigDlg::slotDestEdit( int index )
476{
477 m_destNew = false;
478 m_destCurrent = index;
479
480 // Find selected destination in list
481 OConfItem *destination = findConfItem( OConfItem::Destination, m_destList->currentText() );
482
483 // Display destination details
484 if ( destination )
485 {
486 m_destCurrName = destination->name();
487 m_destName->setText( destination->name() );
488 m_destLocation->setText( destination->value() );
489 m_destActive->setChecked( destination->active() );
490 m_destName->setFocus();
491 }
492}
493
494void OIpkgConfigDlg::slotDestNew()
495{
496 m_destNew = true;
497
498 m_destName->setText( QString::null );
499 m_destLocation->setText( QString::null );
500 m_destActive->setChecked( true );
501 m_destName->setFocus();
502}
503
504void OIpkgConfigDlg::slotDestDelete()
505{
506 // Find selected destination in list
507 OConfItem *destination = findConfItem( OConfItem::Destination, m_destList->currentText() );
508
509 // Delete destination
510 if ( destination )
511 {
512 m_configs->removeRef( destination );
513 m_destList->removeItem( m_destCurrent );
514 }
515}
516
517void OIpkgConfigDlg::slotDestUpdate()
518{
519 QString newName = m_destName->text();
520
521 // Convert any spaces to underscores
522 newName.replace( QRegExp( " " ), "_" );
523
524 if ( !m_destNew )
525 {
526 // Find selected destination in list
527 OConfItem *destination = findConfItem( OConfItem::Destination, m_destCurrName );
528
529 // Display destination details
530 if ( destination )
531 {
532 // Update url
533 destination->setValue( m_destLocation->text() );
534 destination->setActive( m_destActive->isChecked() );
535
536 // Check if destination name has changed, if it has then we need to replace the key in the map
537 if ( m_destCurrName != newName )
538 {
539 // Update destination name
540 destination->setName( newName );
541
542 // Update list box
543 m_destList->changeItem( newName, m_destCurrent );
544 }
545 }
546 }
547 else
548 {
549 // Add new destination to configuration list
550 m_configs->append( new OConfItem( QString::null, OConfItem::Destination, newName,
551 m_destLocation->text(), m_destActive->isChecked() ) );
552 m_configs->sort();
553
554 m_destList->insertItem( newName );
555 m_destList->setCurrentItem( m_destList->count() );
556 m_destNew = false;
557 }
558}