summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-09-19 23:18:26 (UTC)
committer llornkcor <llornkcor>2004-09-19 23:18:26 (UTC)
commit83272b7645c639669dddd676f17f64ad78ef9c63 (patch) (unidiff)
tree5f2544600b6c468c6411d8abc605b95b2c0df95a
parentf3f74eed5dcf210562ef1c29f30fdbe893f0f7cd (diff)
downloadopie-83272b7645c639669dddd676f17f64ad78ef9c63.zip
opie-83272b7645c639669dddd676f17f64ad78ef9c63.tar.gz
opie-83272b7645c639669dddd676f17f64ad78ef9c63.tar.bz2
add more default servers in case ntpservers file is not found
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/settingstabwidget.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/noncore/settings/netsystemtime/settingstabwidget.cpp b/noncore/settings/netsystemtime/settingstabwidget.cpp
index 1307082..9315d2e 100644
--- a/noncore/settings/netsystemtime/settingstabwidget.cpp
+++ b/noncore/settings/netsystemtime/settingstabwidget.cpp
@@ -39,121 +39,123 @@
39#include <qspinbox.h> 39#include <qspinbox.h>
40 40
41SettingsTabWidget::SettingsTabWidget( QWidget *parent ) 41SettingsTabWidget::SettingsTabWidget( QWidget *parent )
42 : QWidget( parent, 0x0, 0 ) 42 : QWidget( parent, 0x0, 0 )
43{ 43{
44 QVBoxLayout *tmpvb = new QVBoxLayout( this ); 44 QVBoxLayout *tmpvb = new QVBoxLayout( this );
45 QScrollView *sv = new QScrollView( this ); 45 QScrollView *sv = new QScrollView( this );
46 tmpvb->addWidget( sv, 0, 0 ); 46 tmpvb->addWidget( sv, 0, 0 );
47 sv->setResizePolicy( QScrollView::AutoOneFit ); 47 sv->setResizePolicy( QScrollView::AutoOneFit );
48 sv->setFrameStyle( QFrame::NoFrame ); 48 sv->setFrameStyle( QFrame::NoFrame );
49 QWidget *container = new QWidget( sv->viewport() ); 49 QWidget *container = new QWidget( sv->viewport() );
50 sv->addChild( container ); 50 sv->addChild( container );
51 51
52 QGridLayout *layout = new QGridLayout( container ); 52 QGridLayout *layout = new QGridLayout( container );
53 layout->setMargin( 2 ); 53 layout->setMargin( 2 );
54 layout->setSpacing( 4 ); 54 layout->setSpacing( 4 );
55 55
56 // Time server selector 56 // Time server selector
57 layout->addWidget( new QLabel( tr( "Time server" ), container ), 0, 0 ); 57 layout->addWidget( new QLabel( tr( "Time server" ), container ), 0, 0 );
58 cbTimeServer = new QComboBox( TRUE, container ); 58 cbTimeServer = new QComboBox( TRUE, container );
59 layout->addMultiCellWidget( cbTimeServer, 1, 1, 0, 1 ); 59 layout->addMultiCellWidget( cbTimeServer, 1, 1, 0, 1 );
60 60
61 // Lookup delay selector 61 // Lookup delay selector
62 layout->addWidget( new QLabel( tr( "minutes between time updates" ), container ), 2, 1 ); 62 layout->addWidget( new QLabel( tr( "minutes between time updates" ), container ), 2, 1 );
63 sbNtpDelay = new QSpinBox( 1, 9999999, 1, container ); 63 sbNtpDelay = new QSpinBox( 1, 9999999, 1, container );
64 sbNtpDelay->setWrapping( TRUE ); 64 sbNtpDelay->setWrapping( TRUE );
65 sbNtpDelay->setMaximumWidth( 50 ); 65 sbNtpDelay->setMaximumWidth( 50 );
66 connect( sbNtpDelay, SIGNAL(valueChanged(int)), this, SIGNAL(ntpDelayChanged(int)) ); 66 connect( sbNtpDelay, SIGNAL(valueChanged(int)), this, SIGNAL(ntpDelayChanged(int)) );
67 layout->addWidget( sbNtpDelay, 2, 0 ); 67 layout->addWidget( sbNtpDelay, 2, 0 );
68 68
69 // Prediction delay selector 69 // Prediction delay selector
70 layout->addWidget( new QLabel( tr( "minutes between prediction updates" ), container ), 3, 1 ); 70 layout->addWidget( new QLabel( tr( "minutes between prediction updates" ), container ), 3, 1 );
71 sbPredictDelay = new QSpinBox( 42, 9999999, 1, container ); 71 sbPredictDelay = new QSpinBox( 42, 9999999, 1, container );
72 sbPredictDelay->setWrapping( TRUE ); 72 sbPredictDelay->setWrapping( TRUE );
73 sbPredictDelay->setMaximumWidth( 50 ); 73 sbPredictDelay->setMaximumWidth( 50 );
74 layout->addWidget( sbPredictDelay, 3, 0 ); 74 layout->addWidget( sbPredictDelay, 3, 0 );
75 75
76 // Space filler 76 // Space filler
77 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 4, 0 ); 77 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 4, 0 );
78 78
79 // Display time server information selector 79 // Display time server information selector
80 chNtpTab = new QCheckBox( tr( "Display time server information" ), container ); 80 chNtpTab = new QCheckBox( tr( "Display time server information" ), container );
81 connect( chNtpTab, SIGNAL( toggled(bool) ), this, SIGNAL( displayNTPTab(bool) ) ); 81 connect( chNtpTab, SIGNAL( toggled(bool) ), this, SIGNAL( displayNTPTab(bool) ) );
82 layout->addMultiCellWidget( chNtpTab, 5, 5, 0, 1 ); 82 layout->addMultiCellWidget( chNtpTab, 5, 5, 0, 1 );
83 83
84 // Display time prediction information selector 84 // Display time prediction information selector
85 chPredictTab = new QCheckBox( tr( "Display time prediction information" ), container ); 85 chPredictTab = new QCheckBox( tr( "Display time prediction information" ), container );
86 connect( chPredictTab, SIGNAL( toggled(bool) ), this, SIGNAL( displayPredictTab(bool) ) ); 86 connect( chPredictTab, SIGNAL( toggled(bool) ), this, SIGNAL( displayPredictTab(bool) ) );
87 layout->addMultiCellWidget( chPredictTab, 6, 6, 0, 1 ); 87 layout->addMultiCellWidget( chPredictTab, 6, 6, 0, 1 );
88 88
89 // Space filler 89 // Space filler
90 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 7, 0 ); 90 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 7, 0 );
91 91
92 // Initialize values 92 // Initialize values
93 QString ntpSrvsFile = QPEApplication::qpeDir(); 93 QString ntpSrvsFile = QPEApplication::qpeDir();
94 ntpSrvsFile.append( "etc/ntpservers" ); 94 ntpSrvsFile.append( "etc/ntpservers" );
95 Config ntpSrvs( ntpSrvsFile, Config::File ); 95 Config ntpSrvs( ntpSrvsFile, Config::File );
96 ntpSrvs.setGroup( "servers" ); 96 ntpSrvs.setGroup( "servers" );
97 int srvCount = ntpSrvs.readNumEntry( "count", 0 ); 97 int srvCount = ntpSrvs.readNumEntry( "count", 0 );
98 for ( int i = 0; i < srvCount; i++ ) 98 for ( int i = 0; i < srvCount; i++ )
99 { 99 {
100 ntpSrvs.setGroup( QString::number( i ) ); 100 ntpSrvs.setGroup( QString::number( i ) );
101 cbTimeServer->insertItem( ntpSrvs.readEntry( "name" ) ); 101 cbTimeServer->insertItem( ntpSrvs.readEntry( "name" ) );
102 } 102 }
103 if ( srvCount==0 ) 103 if ( srvCount==0 ) {
104 cbTimeServer->insertItem( "time.fu-berlin.de" ); 104 cbTimeServer->insertItem( "time.fu-berlin.de" );
105 105 cbTimeServer->insertItem( "time-a.nist.gov" );
106 cbTimeServer->insertItem( "ntp.bri.connect.com.au" );
107 }
106 Config config( "ntp" ); 108 Config config( "ntp" );
107 config.setGroup( "settings" ); 109 config.setGroup( "settings" );
108 sbPredictDelay->setValue( config.readNumEntry( "minLookupDiff", 720 ) ); 110 sbPredictDelay->setValue( config.readNumEntry( "minLookupDiff", 720 ) );
109 sbNtpDelay->setValue( config.readNumEntry( "ntpRefreshFreq", 1440 ) ); 111 sbNtpDelay->setValue( config.readNumEntry( "ntpRefreshFreq", 1440 ) );
110 cbTimeServer->setCurrentItem( config.readNumEntry( "ntpServer", 0 ) ); 112 cbTimeServer->setCurrentItem( config.readNumEntry( "ntpServer", 0 ) );
111 chNtpTab->setChecked( config.readBoolEntry( "displayNtpTab", FALSE ) ); 113 chNtpTab->setChecked( config.readBoolEntry( "displayNtpTab", FALSE ) );
112 chPredictTab->setChecked( config.readBoolEntry( "displayPredictTab", FALSE ) ); 114 chPredictTab->setChecked( config.readBoolEntry( "displayPredictTab", FALSE ) );
113} 115}
114 116
115SettingsTabWidget::~SettingsTabWidget() 117SettingsTabWidget::~SettingsTabWidget()
116{ 118{
117} 119}
118 120
119void SettingsTabWidget::saveSettings() 121void SettingsTabWidget::saveSettings()
120{ 122{
121 int srvCount = cbTimeServer->count(); 123 int srvCount = cbTimeServer->count();
122 bool serversChanged = TRUE; 124 bool serversChanged = TRUE;
123 int curSrv = cbTimeServer->currentItem(); 125 int curSrv = cbTimeServer->currentItem();
124 QString edit = cbTimeServer->currentText(); 126 QString edit = cbTimeServer->currentText();
125 for ( int i = 0; i < srvCount; i++ ) 127 for ( int i = 0; i < srvCount; i++ )
126 { 128 {
127 if ( edit == cbTimeServer->text( i ) ) 129 if ( edit == cbTimeServer->text( i ) )
128 serversChanged = FALSE; 130 serversChanged = FALSE;
129 } 131 }
130 if ( serversChanged ) 132 if ( serversChanged )
131 { 133 {
132 QString ntpSrvsFile = QPEApplication::qpeDir(); 134 QString ntpSrvsFile = QPEApplication::qpeDir();
133 ntpSrvsFile.append( "etc/ntpservers" ); 135 ntpSrvsFile.append( "etc/ntpservers" );
134 Config ntpSrvs( ntpSrvsFile, Config::File ); 136 Config ntpSrvs( ntpSrvsFile, Config::File );
135 ntpSrvs.setGroup( "servers" ); 137 ntpSrvs.setGroup( "servers" );
136 ntpSrvs.writeEntry( "count", ++srvCount ); 138 ntpSrvs.writeEntry( "count", ++srvCount );
137 ntpSrvs.setGroup( "0" ); 139 ntpSrvs.setGroup( "0" );
138 ntpSrvs.writeEntry( "name", edit ); 140 ntpSrvs.writeEntry( "name", edit );
139 curSrv = 0; 141 curSrv = 0;
140 for ( int i = 1; i < srvCount; i++ ) 142 for ( int i = 1; i < srvCount; i++ )
141 { 143 {
142 // odebug << "ntpSrvs[" << i << "/" << srvCount << "]=" << cbTimeServer->text( i ).latin1() << "" << oendl; 144 // odebug << "ntpSrvs[" << i << "/" << srvCount << "]=" << cbTimeServer->text( i ).latin1() << "" << oendl;
143 ntpSrvs.setGroup( QString::number( i ) ); 145 ntpSrvs.setGroup( QString::number( i ) );
144 ntpSrvs.writeEntry( "name", cbTimeServer->text( i-1 ) ); 146 ntpSrvs.writeEntry( "name", cbTimeServer->text( i-1 ) );
145 } 147 }
146 } 148 }
147 Config config( "ntp", Config::User ); 149 Config config( "ntp", Config::User );
148 config.setGroup( "settings" ); 150 config.setGroup( "settings" );
149 config.writeEntry( "ntpServer", curSrv ); 151 config.writeEntry( "ntpServer", curSrv );
150 config.writeEntry( "minLookupDiff", sbPredictDelay->value() ); 152 config.writeEntry( "minLookupDiff", sbPredictDelay->value() );
151 config.writeEntry( "ntpRefreshFreq", sbNtpDelay->value() ); 153 config.writeEntry( "ntpRefreshFreq", sbNtpDelay->value() );
152 config.writeEntry( "displayNtpTab", chNtpTab->isChecked() ); 154 config.writeEntry( "displayNtpTab", chNtpTab->isChecked() );
153 config.writeEntry( "displayPredictTab", chPredictTab->isChecked() ); 155 config.writeEntry( "displayPredictTab", chPredictTab->isChecked() );
154} 156}
155 157
156QString SettingsTabWidget::ntpServer() 158QString SettingsTabWidget::ntpServer()
157{ 159{
158 return cbTimeServer->currentText(); 160 return cbTimeServer->currentText();
159} 161}