-rw-r--r-- | noncore/settings/netsystemtime/settingstabwidget.cpp | 6 |
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 | |||
@@ -1,159 +1,161 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | =. | 3 | =. |
4 | .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> | 4 | .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This file is free software; you can | 6 | _;:, .> :=|. This file is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This file is distributed in the hope that | 13 | .i_,=:_. -<s. This file is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "settingstabwidget.h" | 29 | #include "settingstabwidget.h" |
30 | 30 | ||
31 | #include <qpe/config.h> | 31 | #include <qpe/config.h> |
32 | #include <qpe/qpeapplication.h> | 32 | #include <qpe/qpeapplication.h> |
33 | 33 | ||
34 | #include <qcheckbox.h> | 34 | #include <qcheckbox.h> |
35 | #include <qcombobox.h> | 35 | #include <qcombobox.h> |
36 | #include <qlabel.h> | 36 | #include <qlabel.h> |
37 | #include <qlayout.h> | 37 | #include <qlayout.h> |
38 | #include <qscrollview.h> | 38 | #include <qscrollview.h> |
39 | #include <qspinbox.h> | 39 | #include <qspinbox.h> |
40 | 40 | ||
41 | SettingsTabWidget::SettingsTabWidget( QWidget *parent ) | 41 | SettingsTabWidget::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 | ||
115 | SettingsTabWidget::~SettingsTabWidget() | 117 | SettingsTabWidget::~SettingsTabWidget() |
116 | { | 118 | { |
117 | } | 119 | } |
118 | 120 | ||
119 | void SettingsTabWidget::saveSettings() | 121 | void 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 | ||
156 | QString SettingsTabWidget::ntpServer() | 158 | QString SettingsTabWidget::ntpServer() |
157 | { | 159 | { |
158 | return cbTimeServer->currentText(); | 160 | return cbTimeServer->currentText(); |
159 | } | 161 | } |