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

settingstabwidget.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003 
00004                              Copyright (C) Opie Team <opie-devel@handhelds.org>
00005               =.
00006             .=l.
00007            .>+-=
00008  _;:,     .>    :=|.         This program is free software; you can
00009 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00010 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00011 .="- .-=="i,     .._         License as published by the Free Software
00012  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00013      ._= =}       :          or (at your option) any later version.
00014     .%`+i>       _;_.
00015     .i_,=:_.      -<s.       This program is distributed in the hope that
00016      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00017     : ..    .:,     . . .    without even the implied warranty of
00018     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00019   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00020 ..}^=.=       =       ;      Library General Public License for more
00021 ++=   -.     .`     .:       details.
00022 :     =  ...= . :.=-
00023  -.   .:....=;==+<;          You should have received a copy of the GNU
00024   -_. . .   )=.  =           Library General Public License along with
00025     --        :-=`           this library; see the file COPYING.LIB.
00026                              If not, write to the Free Software Foundation,
00027                              Inc., 59 Temple Place - Suite 330,
00028                              Boston, MA 02111-1307, USA.
00029 */
00030 
00031 #include "settingstabwidget.h"
00032 
00033 #include <qpe/config.h>
00034 #include <qpe/qpeapplication.h>
00035 
00036 #include <qcheckbox.h>
00037 #include <qcombobox.h>
00038 #include <qlabel.h>
00039 #include <qlayout.h>
00040 #include <qscrollview.h>
00041 #include <qspinbox.h>
00042 
00043 SettingsTabWidget::SettingsTabWidget( QWidget *parent )
00044         : QWidget( parent, 0x0, 0 )
00045 {
00046         QVBoxLayout *tmpvb = new QVBoxLayout( this );
00047         QScrollView *sv = new QScrollView( this );
00048         tmpvb->addWidget( sv, 0, 0 );
00049         sv->setResizePolicy( QScrollView::AutoOneFit );
00050         sv->setFrameStyle( QFrame::NoFrame );
00051         QWidget *container = new QWidget( sv->viewport() );
00052         sv->addChild( container );
00053     
00054         QGridLayout *layout = new QGridLayout( container );
00055         layout->setMargin( 2 );
00056         layout->setSpacing( 4 );
00057 
00058         // Time server selector
00059         layout->addWidget( new QLabel( tr( "Time server" ), container ), 0, 0 );
00060         cbTimeServer = new QComboBox( TRUE, container );
00061         layout->addMultiCellWidget( cbTimeServer, 1, 1, 0, 1 );
00062 
00063         // Lookup delay selector
00064         layout->addWidget( new QLabel( tr( "minutes between time updates" ), container ), 2, 1 );
00065         sbNtpDelay = new QSpinBox( 1, 9999999, 1, container );
00066         sbNtpDelay->setWrapping( TRUE );
00067         sbNtpDelay->setMaximumWidth( 50 );
00068         connect( sbNtpDelay, SIGNAL(valueChanged(int)), this, SIGNAL(ntpDelayChanged(int)) );
00069         layout->addWidget( sbNtpDelay, 2, 0 );
00070 
00071         // Prediction delay selector
00072         layout->addWidget( new QLabel( tr( "minutes between prediction updates" ), container ), 3, 1 );
00073         sbPredictDelay = new QSpinBox( 42, 9999999, 1, container );
00074         sbPredictDelay->setWrapping( TRUE );
00075         sbPredictDelay->setMaximumWidth( 50 );
00076         layout->addWidget( sbPredictDelay, 3, 0 );
00077 
00078         // Space filler
00079         layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 4, 0 );
00080 
00081         // Display time server information selector
00082         chNtpTab = new QCheckBox( tr( "Display time server information" ), container );
00083         connect( chNtpTab, SIGNAL( toggled(bool) ), this, SIGNAL( displayNTPTab(bool) ) );
00084         layout->addMultiCellWidget( chNtpTab, 5, 5, 0, 1 );
00085 
00086         // Display time prediction information selector
00087         chPredictTab = new QCheckBox( tr( "Display time prediction information" ), container );
00088         connect( chPredictTab, SIGNAL( toggled(bool) ), this, SIGNAL( displayPredictTab(bool) ) );
00089         layout->addMultiCellWidget( chPredictTab, 6, 6, 0, 1 );
00090 
00091         // Space filler
00092         layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 7, 0 );
00093 
00094         // Initialize values
00095         QString ntpSrvsFile = QPEApplication::qpeDir();
00096         ntpSrvsFile.append( "etc/ntpservers" );
00097         Config ntpSrvs( ntpSrvsFile, Config::File );
00098         ntpSrvs.setGroup( "servers" );
00099         int srvCount = ntpSrvs.readNumEntry( "count", 0 );
00100         for ( int i = 0; i < srvCount; i++ )
00101         {
00102                 ntpSrvs.setGroup( QString::number( i ) );
00103                 cbTimeServer->insertItem( ntpSrvs.readEntry( "name" ) );
00104         }
00105         if ( srvCount==0 ) {
00106                 cbTimeServer->insertItem( "time.fu-berlin.de" );
00107     cbTimeServer->insertItem( "time-a.nist.gov" );
00108     cbTimeServer->insertItem( "ntp.bri.connect.com.au" );
00109   }
00110         Config config( "ntp" );
00111         config.setGroup( "settings" );
00112         sbPredictDelay->setValue( config.readNumEntry( "minLookupDiff", 720 ) );
00113         sbNtpDelay->setValue( config.readNumEntry( "ntpRefreshFreq", 1440 ) );
00114         cbTimeServer->setCurrentItem( config.readNumEntry( "ntpServer", 0 ) );
00115         chNtpTab->setChecked( config.readBoolEntry( "displayNtpTab", FALSE ) );
00116         chPredictTab->setChecked( config.readBoolEntry( "displayPredictTab", FALSE ) );
00117 }
00118 
00119 SettingsTabWidget::~SettingsTabWidget()
00120 {
00121 }
00122 
00123 void SettingsTabWidget::saveSettings()
00124 {
00125         int srvCount = cbTimeServer->count();
00126         bool serversChanged = TRUE;
00127         int curSrv = cbTimeServer->currentItem();
00128         QString edit = cbTimeServer->currentText();
00129         for ( int i = 0; i < srvCount; i++ )
00130         {
00131                 if ( edit == cbTimeServer->text( i ) )
00132                         serversChanged = FALSE;
00133         }
00134         if ( serversChanged )
00135         {
00136                 QString ntpSrvsFile = QPEApplication::qpeDir();
00137                 ntpSrvsFile.append( "etc/ntpservers" );
00138                 Config ntpSrvs( ntpSrvsFile, Config::File );
00139                 ntpSrvs.setGroup( "servers" );
00140                 ntpSrvs.writeEntry( "count", ++srvCount );
00141                 ntpSrvs.setGroup( "0" );
00142                 ntpSrvs.writeEntry( "name", edit );
00143                 curSrv = 0;
00144                 for ( int i = 1; i < srvCount; i++ )
00145                 {
00146 //                      odebug << "ntpSrvs[" << i << "/" << srvCount << "]=" << cbTimeServer->text( i ).latin1() << "" << oendl; 
00147                         ntpSrvs.setGroup( QString::number( i ) );
00148                         ntpSrvs.writeEntry( "name", cbTimeServer->text( i-1 ) );
00149                 }
00150         }
00151         Config config( "ntp", Config::User );
00152         config.setGroup( "settings" );
00153         config.writeEntry( "ntpServer", curSrv );
00154         config.writeEntry( "minLookupDiff", sbPredictDelay->value() );
00155         config.writeEntry( "ntpRefreshFreq", sbNtpDelay->value() );
00156         config.writeEntry( "displayNtpTab", chNtpTab->isChecked() );
00157         config.writeEntry( "displayPredictTab", chPredictTab->isChecked() );
00158 }
00159 
00160 QString SettingsTabWidget::ntpServer()
00161 {
00162         return cbTimeServer->currentText();
00163 }

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