Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

settingsimpl.cpp

Go to the documentation of this file.
00001 /*
00002                      This file is part of the OPIE Project
00003 
00004                =.            Copyright (c)  2002 Andy Qua <andy.qua@blueyonder.co.uk>
00005       .=l.                                Dan Williams <drw@handhelds.org>
00006      .>+-=
00007 _;:,   .>  :=|.         This file is free software; you can
00008 .> <`_,  > .  <=          redistribute it and/or modify it under
00009 :`=1 )Y*s>-.--  :           the terms of the GNU General Public
00010 .="- .-=="i,   .._         License as published by the Free Software
00011 - .  .-<_>   .<>         Foundation; either version 2 of the License,
00012   ._= =}    :          or (at your option) any later version.
00013   .%`+i>    _;_.
00014   .i_,=:_.   -<s.       This file is distributed in the hope that
00015   + . -:.    =       it will be useful, but WITHOUT ANY WARRANTY;
00016   : ..  .:,   . . .    without even the implied warranty of
00017   =_    +   =;=|`    MERCHANTABILITY or FITNESS FOR A
00018  _.=:.    :  :=>`:     PARTICULAR PURPOSE. See the GNU General
00019 ..}^=.=    =    ;      Public License for more details.
00020 ++=  -.   .`   .:
00021 :   = ...= . :.=-        You should have received a copy of the GNU
00022 -.  .:....=;==+<;          General Public License along with this file;
00023  -_. . .  )=. =           see the file COPYING. If not, write to the
00024   --    :-=`           Free Software Foundation, Inc.,
00025                              59 Temple Place - Suite 330,
00026                              Boston, MA 02111-1307, USA.
00027 
00028 */
00029 
00030 #include "settingsimpl.h"
00031 #include "global.h"
00032 
00033 /* OPIE */
00034 #include <opie2/otabwidget.h>
00035 #include <opie2/oresource.h>
00036 #include <qpe/config.h>
00037 #include <qpe/qpeapplication.h>
00038 
00039 /* QT */
00040 #include <qcheckbox.h>
00041 #include <qgroupbox.h>
00042 #include <qlabel.h>
00043 #include <qlayout.h>
00044 #include <qlineedit.h>
00045 #include <qlistbox.h>
00046 #include <qpushbutton.h>
00047 
00048 using namespace Opie::Ui;
00049 using namespace Opie::Ui;
00050 SettingsImpl :: SettingsImpl( DataManager *dataManager, QWidget * parent, const char* name, bool modal, WFlags fl )
00051         : QDialog( parent, name, modal, fl )
00052 {
00053     setCaption( tr( "Configuration" ) );
00054 
00055     // Setup layout to make everything pretty
00056     QVBoxLayout *layout = new QVBoxLayout( this );
00057     layout->setMargin( 2 );
00058     layout->setSpacing( 4 );
00059 
00060     // Setup tabs for all info
00061     OTabWidget *tabwidget = new OTabWidget( this );
00062     layout->addWidget( tabwidget );
00063 
00064     tabwidget->addTab( initServerTab(), "aqpkg/servertab", tr( "Servers" ) );
00065     tabwidget->addTab( initDestinationTab(), "aqpkg/desttab", tr( "Destinations" ) );
00066     tabwidget->addTab( initProxyTab(), "aqpkg/proxytab", tr( "Proxies" ) );
00067     tabwidget->setCurrentTab( tr( "Servers" ) );
00068 
00069     dataMgr = dataManager;
00070     setupData();
00071     changed = false;
00072     newserver = false;
00073     newdestination = false;
00074 }
00075 
00076 SettingsImpl :: ~SettingsImpl()
00077 {
00078 }
00079 
00080 bool SettingsImpl :: showDlg()
00081 {
00082     QPEApplication::execDialog( this );
00083     if ( changed )
00084         dataMgr->writeOutIpkgConf();
00085 
00086     return changed;
00087 }
00088 
00089 QWidget *SettingsImpl :: initServerTab()
00090 {
00091     QWidget *control = new QWidget( this );
00092 
00093     QVBoxLayout *vb = new QVBoxLayout( control );
00094 
00095     QScrollView *sv = new QScrollView( control );
00096     vb->addWidget( sv, 0, 0 );
00097     sv->setResizePolicy( QScrollView::AutoOneFit );
00098     sv->setFrameStyle( QFrame::NoFrame );
00099 
00100     QWidget *container = new QWidget( sv->viewport() );
00101     sv->addChild( container );
00102 
00103     QGridLayout *layout = new QGridLayout( container );
00104     layout->setSpacing( 2 );
00105     layout->setMargin( 4 );
00106 
00107     servers = new QListBox( container );
00108     servers->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
00109     connect( servers, SIGNAL( highlighted(int) ), this, SLOT( editServer(int) ) );
00110     layout->addMultiCellWidget( servers, 0, 0, 0, 1 );
00111 
00112     QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ),
00113                                         tr( "New" ), container );
00114     connect( btn, SIGNAL( clicked() ), this, SLOT( newServer() ) );
00115     layout->addWidget( btn, 1, 0 );
00116 
00117     btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), container );
00118     connect( btn, SIGNAL( clicked() ), this, SLOT( removeServer() ) );
00119     layout->addWidget( btn, 1, 1 );
00120 
00121     QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Server" ), container );
00122     grpbox->layout()->setSpacing( 2 );
00123     grpbox->layout()->setMargin( 4 );
00124     layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 );
00125 
00126     QGridLayout *grplayout = new QGridLayout( grpbox->layout() );
00127 
00128     QLabel *label = new QLabel( tr( "Name:" ), grpbox );
00129     grplayout->addWidget( label, 0, 0 );
00130     servername = new QLineEdit( grpbox );
00131     grplayout->addWidget( servername, 0, 1 );
00132 
00133     label = new QLabel( tr( "Address:" ), grpbox );
00134     grplayout->addWidget( label, 1, 0 );
00135     serverurl = new QLineEdit( grpbox );
00136     grplayout->addWidget( serverurl, 1, 1 );
00137 
00138     active = new QCheckBox( tr( "Active Server" ), grpbox );
00139     grplayout->addMultiCellWidget( active, 2, 2, 0, 1 );
00140 
00141     btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), grpbox );
00142     connect( btn, SIGNAL( clicked() ), this, SLOT( changeServerDetails() ) );
00143     grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 );
00144 
00145     return control;
00146 }
00147 
00148 QWidget *SettingsImpl :: initDestinationTab()
00149 {
00150     QWidget *control = new QWidget( this );
00151 
00152     QVBoxLayout *vb = new QVBoxLayout( control );
00153 
00154     QScrollView *sv = new QScrollView( control );
00155     vb->addWidget( sv, 0, 0 );
00156     sv->setResizePolicy( QScrollView::AutoOneFit );
00157     sv->setFrameStyle( QFrame::NoFrame );
00158 
00159     QWidget *container = new QWidget( sv->viewport() );
00160     sv->addChild( container );
00161 
00162     QGridLayout *layout = new QGridLayout( container );
00163     layout->setSpacing( 2 );
00164     layout->setMargin( 4 );
00165 
00166     destinations = new QListBox( container );
00167     destinations->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) );
00168     connect( destinations, SIGNAL( highlighted(int) ), this, SLOT( editDestination(int) ) );
00169     layout->addMultiCellWidget( destinations, 0, 0, 0, 1 );
00170 
00171     QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), tr( "New" ), container );
00172     connect( btn, SIGNAL( clicked() ), this, SLOT( newDestination() ) );
00173     layout->addWidget( btn, 1, 0 );
00174 
00175     btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), container );
00176     connect( btn, SIGNAL( clicked() ), this, SLOT( removeDestination() ) );
00177     layout->addWidget( btn, 1, 1 );
00178 
00179     QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Destination" ), container );
00180     grpbox->layout()->setSpacing( 2 );
00181     grpbox->layout()->setMargin( 4 );
00182     layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 );
00183 
00184     QGridLayout *grplayout = new QGridLayout( grpbox->layout() );
00185 
00186     QLabel *label = new QLabel( tr( "Name:" ), grpbox );
00187     grplayout->addWidget( label, 0, 0 );
00188     destinationname = new QLineEdit( grpbox );
00189     grplayout->addWidget( destinationname, 0, 1 );
00190 
00191     label = new QLabel( tr( "Location:" ), grpbox );
00192     grplayout->addWidget( label, 1, 0 );
00193     destinationurl = new QLineEdit( grpbox );
00194     grplayout->addWidget( destinationurl, 1, 1 );
00195 
00196     linkToRoot = new QCheckBox( tr( "Link to root" ), grpbox );
00197     grplayout->addMultiCellWidget( linkToRoot, 2, 2, 0, 1 );
00198 
00199     btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), grpbox );
00200     connect( btn, SIGNAL( clicked() ), this, SLOT( changeDestinationDetails() ) );
00201     grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 );
00202 
00203     return control;
00204 }
00205 
00206 QWidget *SettingsImpl :: initProxyTab()
00207 {
00208     QWidget *control = new QWidget( this );
00209 
00210     QVBoxLayout *vb = new QVBoxLayout( control );
00211 
00212     QScrollView *sv = new QScrollView( control );
00213     vb->addWidget( sv, 0, 0 );
00214     sv->setResizePolicy( QScrollView::AutoOneFit );
00215     sv->setFrameStyle( QFrame::NoFrame );
00216 
00217     QWidget *container = new QWidget( sv->viewport() );
00218     sv->addChild( container );
00219 
00220     QGridLayout *layout = new QGridLayout( container );
00221     layout->setSpacing( 2 );
00222     layout->setMargin( 4 );
00223 
00224     QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "HTTP Proxy" ), container );
00225     grpbox->layout()->setSpacing( 2 );
00226     grpbox->layout()->setMargin( 4 );
00227     layout->addMultiCellWidget( grpbox, 0, 0, 0, 1 );
00228     QVBoxLayout *grplayout = new QVBoxLayout( grpbox->layout() );
00229     txtHttpProxy = new QLineEdit( grpbox );
00230     grplayout->addWidget( txtHttpProxy );
00231     chkHttpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox );
00232     grplayout->addWidget( chkHttpProxyEnabled );
00233 
00234     grpbox = new QGroupBox( 0, Qt::Vertical, tr( "FTP Proxy" ), container );
00235     grpbox->layout()->setSpacing( 2 );
00236     grpbox->layout()->setMargin( 4 );
00237     layout->addMultiCellWidget( grpbox, 1, 1, 0, 1 );
00238     grplayout = new QVBoxLayout( grpbox->layout() );
00239     txtFtpProxy = new QLineEdit( grpbox );
00240     grplayout->addWidget( txtFtpProxy );
00241     chkFtpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox );
00242     grplayout->addWidget( chkFtpProxyEnabled );
00243 
00244     QLabel *label = new QLabel( tr( "Username:" ), container );
00245     layout->addWidget( label, 2, 0 );
00246     txtUsername = new QLineEdit( container );
00247     layout->addWidget( txtUsername, 2, 1 );
00248 
00249     label = new QLabel( tr( "Password:" ), container );
00250     layout->addWidget( label, 3, 0 );
00251     txtPassword = new QLineEdit( container );
00252     layout->addWidget( txtPassword, 3, 1 );
00253 
00254     QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), container );
00255     connect( btn, SIGNAL( clicked() ), this, SLOT( proxyApplyChanges() ) );
00256     layout->addMultiCellWidget( btn, 4, 4, 0, 1 );
00257 
00258     return control;
00259 }
00260 
00261 void SettingsImpl :: setupData()
00262 {
00263     // add servers
00264     QString serverName;
00265     QListIterator<Server> it( dataMgr->getServerList() );
00266     for ( ; it.current(); ++it )
00267     {
00268         serverName = it.current()->getServerName();
00269         if ( serverName == LOCAL_SERVER || serverName == LOCAL_IPKGS )
00270             continue;
00271 
00272         servers->insertItem( serverName );
00273     }
00274 
00275 
00276     // add destinations
00277     QListIterator<Destination> it2( dataMgr->getDestinationList() );
00278     for ( ; it2.current(); ++it2 )
00279         destinations->insertItem( it2.current()->getDestinationName() );
00280 
00281     // setup proxy tab
00282     txtHttpProxy->setText( dataMgr->getHttpProxy() );
00283     txtFtpProxy->setText( dataMgr->getFtpProxy() );
00284     txtUsername->setText( dataMgr->getProxyUsername() );
00285     txtPassword->setText( dataMgr->getProxyPassword() );
00286     chkHttpProxyEnabled->setChecked( dataMgr->getHttpProxyEnabled() );
00287     chkFtpProxyEnabled->setChecked( dataMgr->getFtpProxyEnabled() );
00288 }
00289 
00290 //------------------ Servers tab ----------------------
00291 
00292 void SettingsImpl :: editServer( int sel )
00293 {
00294     currentSelectedServer = sel;
00295     Server *s = dataMgr->getServer( servers->currentText() );
00296     if ( s )
00297     {
00298         serverName = s->getServerName();
00299         servername->setText( s->getServerName() );
00300         serverurl->setText( s->getServerUrl() );
00301         active->setChecked( s->isServerActive() );
00302     }
00303     else
00304     {
00305         serverName = "";
00306         servername->setText( "" );
00307         serverurl->setText( "" );
00308         active->setChecked( false );
00309     }
00310 }
00311 
00312 void SettingsImpl :: newServer()
00313 {
00314     newserver = true;
00315     servername->setText( "" );
00316     serverurl->setText( "" );
00317     servername->setFocus();
00318     active->setChecked( true );
00319 }
00320 
00321 void SettingsImpl :: removeServer()
00322 {
00323     changed = true;
00324     Server *s = dataMgr->getServer( servers->currentText() );
00325     if ( s )
00326     {
00327         dataMgr->getServerList().removeRef( s );
00328         servers->removeItem( currentSelectedServer );
00329     }
00330 }
00331 
00332 void SettingsImpl :: changeServerDetails()
00333 {
00334     changed = true;
00335 
00336     QString newName = servername->text();
00337 
00338     // Convert any spaces to underscores
00339     char *tmpStr = new char[newName.length() + 1];
00340     for ( unsigned int i = 0 ; i < newName.length() ; ++i )
00341     {
00342         if ( newName[i] == ' ' )
00343             tmpStr[i] = '_';
00344         else
00345             tmpStr[i] = newName[i].latin1();
00346     }
00347     tmpStr[newName.length()] = '\0';
00348 
00349     newName = tmpStr;
00350     delete tmpStr;
00351 
00352     if ( !newserver )
00353     {
00354         Server *s = dataMgr->getServer( servers->currentText() );
00355         if ( s )
00356         {
00357             // Update url
00358             s->setServerUrl( serverurl->text() );
00359             s->setActive( active->isChecked() );
00360 
00361             // Check if server name has changed, if it has then we need to replace the key in the map
00362             if ( serverName != newName )
00363             {
00364                 // Update server name
00365                 s->setServerName( newName );
00366             }
00367 
00368             // Update list box
00369             servers->changeItem( newName, currentSelectedServer );
00370         }
00371     }
00372     else
00373     {
00374         Server s( newName, serverurl->text() );
00375         dataMgr->getServerList().append( new Server( newName, serverurl->text() ) );
00376         dataMgr->getServerList().last()->setActive( active->isChecked() );
00377         servers->insertItem( newName );
00378         servers->setCurrentItem( servers->count() );
00379         newserver = false;
00380     }
00381 }
00382 
00383 //------------------ Destinations tab ----------------------
00384 
00385 void SettingsImpl :: editDestination( int sel )
00386 {
00387     currentSelectedDestination = sel;
00388     Destination *d = dataMgr->getDestination( destinations->currentText() );
00389     if ( d )
00390     {
00391         destinationName = d->getDestinationName();
00392         destinationname->setText( d->getDestinationName() );
00393         destinationurl->setText( d->getDestinationPath() );
00394         linkToRoot->setChecked( d->linkToRoot() );
00395     }
00396     else
00397     {
00398         destinationName = "";
00399         destinationname->setText( "" );
00400         destinationurl->setText( "" );
00401         linkToRoot->setChecked( false );
00402     }
00403 }
00404 
00405 void SettingsImpl :: newDestination()
00406 {
00407     newdestination = true;
00408     destinationname->setText( "" );
00409     destinationurl->setText( "" );
00410     destinationname->setFocus();
00411     linkToRoot->setChecked( true );
00412 }
00413 
00414 void SettingsImpl :: removeDestination()
00415 {
00416     changed = true;
00417     Destination *d = dataMgr->getDestination( destinations->currentText() );
00418     if ( d )
00419     {
00420         dataMgr->getDestinationList().removeRef( d );
00421         destinations->removeItem( currentSelectedDestination );
00422     }
00423 }
00424 
00425 void SettingsImpl :: changeDestinationDetails()
00426 {
00427     changed = true;
00428 
00429 #ifdef QWS
00430     Config cfg( "aqpkg" );
00431     cfg.setGroup( "destinations" );
00432 #endif
00433 
00434     QString newName = destinationname->text();
00435     if ( !newdestination )
00436     {
00437         Destination *d = dataMgr->getDestination( destinations->currentText() );
00438         if ( d )
00439         {
00440             // Update url
00441             d->setDestinationPath( destinationurl->text() );
00442             d->linkToRoot( linkToRoot->isChecked() );
00443 
00444             // Check if server name has changed, if it has then we need to replace the key in the map
00445             if ( destinationName != newName )
00446             {
00447                 // Update server name
00448                 d->setDestinationName( newName );
00449 
00450                 // Update list box
00451                 destinations->changeItem( newName, currentSelectedDestination );
00452             }
00453 
00454 #ifdef QWS
00455             QString key = newName;
00456             key += "_linkToRoot";
00457             int val = d->linkToRoot();
00458             cfg.writeEntry( key, val );
00459 #endif
00460 
00461         }
00462     }
00463     else
00464     {
00465         dataMgr->getDestinationList().append( new Destination( newName, destinationurl->text() ) );
00466         destinations->insertItem( newName );
00467         destinations->setCurrentItem( destinations->count() );
00468         newdestination = false;
00469 
00470 #ifdef QWS
00471         QString key = newName;
00472         key += "_linkToRoot";
00473         cfg.writeEntry( key, true );
00474 #endif
00475 
00476     }
00477 }
00478 
00479 //------------------ Proxy tab ----------------------
00480 void SettingsImpl :: proxyApplyChanges()
00481 {
00482     changed = true;
00483     dataMgr->setHttpProxy( txtHttpProxy->text() );
00484     dataMgr->setFtpProxy( txtFtpProxy->text() );
00485     dataMgr->setProxyUsername( txtUsername->text() );
00486     dataMgr->setProxyPassword( txtPassword->text() );
00487 
00488     dataMgr->setHttpProxyEnabled( chkHttpProxyEnabled->isChecked() );
00489     dataMgr->setFtpProxyEnabled( chkFtpProxyEnabled->isChecked() );
00490 }

Generated on Sat Nov 5 16:17:48 2005 for OPIE by  doxygen 1.4.2