00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
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
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
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
00079 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 4, 0 );
00080
00081
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
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
00092 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 7, 0 );
00093
00094
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
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 }