author | drw <drw> | 2003-04-13 22:32:47 (UTC) |
---|---|---|
committer | drw <drw> | 2003-04-13 22:32:47 (UTC) |
commit | 166ac140f8e01369a5d281c2918b0f8b9045f8e5 (patch) (unidiff) | |
tree | 672cbb8318703b6cedc7f83fb72c058d0b592c9e /noncore/settings/netsystemtime/settingstabwidget.cpp | |
parent | f47258125bac368987a90ca49a118721ecbc3a8b (diff) | |
download | opie-166ac140f8e01369a5d281c2918b0f8b9045f8e5.zip opie-166ac140f8e01369a5d281c2918b0f8b9045f8e5.tar.gz opie-166ac140f8e01369a5d281c2918b0f8b9045f8e5.tar.bz2 |
Revamped NetSystemTime! Changes include: 1. improved UI (e.g. ok/cancel work, timezone correctly changes date, new layout better suited for running in landscape mode, etc.) 2. improved code organization 3. smaller executable
Diffstat (limited to 'noncore/settings/netsystemtime/settingstabwidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/netsystemtime/settingstabwidget.cpp | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/noncore/settings/netsystemtime/settingstabwidget.cpp b/noncore/settings/netsystemtime/settingstabwidget.cpp new file mode 100644 index 0000000..2a7e28d --- a/dev/null +++ b/noncore/settings/netsystemtime/settingstabwidget.cpp | |||
@@ -0,0 +1,159 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | #include "settingstabwidget.h" | ||
30 | |||
31 | #include <qpe/config.h> | ||
32 | #include <qpe/qpeapplication.h> | ||
33 | |||
34 | #include <qcheckbox.h> | ||
35 | #include <qcombobox.h> | ||
36 | #include <qlabel.h> | ||
37 | #include <qlayout.h> | ||
38 | #include <qscrollview.h> | ||
39 | #include <qspinbox.h> | ||
40 | |||
41 | SettingsTabWidget::SettingsTabWidget( QWidget *parent ) | ||
42 | : QWidget( parent, 0x0, 0 ) | ||
43 | { | ||
44 | QVBoxLayout *tmpvb = new QVBoxLayout( this ); | ||
45 | QScrollView *sv = new QScrollView( this ); | ||
46 | tmpvb->addWidget( sv, 0, 0 ); | ||
47 | sv->setResizePolicy( QScrollView::AutoOneFit ); | ||
48 | sv->setFrameStyle( QFrame::NoFrame ); | ||
49 | QWidget *container = new QWidget( sv->viewport() ); | ||
50 | sv->addChild( container ); | ||
51 | |||
52 | QGridLayout *layout = new QGridLayout( container ); | ||
53 | layout->setMargin( 2 ); | ||
54 | layout->setSpacing( 4 ); | ||
55 | |||
56 | // Time server selector | ||
57 | layout->addWidget( new QLabel( tr( "Time server" ), container ), 0, 0 ); | ||
58 | cbTimeServer = new QComboBox( TRUE, container ); | ||
59 | layout->addMultiCellWidget( cbTimeServer, 1, 1, 0, 1 ); | ||
60 | |||
61 | // Lookup delay selector | ||
62 | layout->addWidget( new QLabel( tr( "minutes between time updates" ), container ), 2, 1 ); | ||
63 | sbNtpDelay = new QSpinBox( 1, 9999999, 1, container ); | ||
64 | sbNtpDelay->setWrapping( TRUE ); | ||
65 | sbNtpDelay->setMaximumWidth( 50 ); | ||
66 | connect( sbNtpDelay, SIGNAL(valueChanged(int)), this, SIGNAL(ntpDelayChanged(int)) ); | ||
67 | layout->addWidget( sbNtpDelay, 2, 0 ); | ||
68 | |||
69 | // Prediction delay selector | ||
70 | layout->addWidget( new QLabel( tr( "minutes between prediction updates" ), container ), 3, 1 ); | ||
71 | sbPredictDelay = new QSpinBox( 42, 9999999, 1, container ); | ||
72 | sbPredictDelay->setWrapping( TRUE ); | ||
73 | sbPredictDelay->setMaximumWidth( 50 ); | ||
74 | layout->addWidget( sbPredictDelay, 3, 0 ); | ||
75 | |||
76 | // Space filler | ||
77 | layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 4, 0 ); | ||
78 | |||
79 | // Display time server information selector | ||
80 | chNtpTab = new QCheckBox( tr( "Display time server information" ), container ); | ||
81 | connect( chNtpTab, SIGNAL( toggled( bool ) ), this, SIGNAL( displayNTPTab( bool ) ) ); | ||
82 | layout->addMultiCellWidget( chNtpTab, 5, 5, 0, 1 ); | ||
83 | |||
84 | // Display time prediction information selector | ||
85 | chPredictTab = new QCheckBox( tr( "Display time prediction information" ), container ); | ||
86 | connect( chPredictTab, SIGNAL( toggled( bool ) ), this, SIGNAL( displayPredictTab( bool ) ) ); | ||
87 | layout->addMultiCellWidget( chPredictTab, 6, 6, 0, 1 ); | ||
88 | |||
89 | // Space filler | ||
90 | layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 7, 0 ); | ||
91 | |||
92 | // Initialize values | ||
93 | QString ntpSrvsFile = QPEApplication::qpeDir(); | ||
94 | ntpSrvsFile.append( "etc/ntpservers" ); | ||
95 | Config ntpSrvs( ntpSrvsFile, Config::File ); | ||
96 | ntpSrvs.setGroup( "servers" ); | ||
97 | int srvCount = ntpSrvs.readNumEntry( "count", 0 ); | ||
98 | for ( int i = 0; i < srvCount; i++ ) | ||
99 | { | ||
100 | ntpSrvs.setGroup( QString::number( i ) ); | ||
101 | cbTimeServer->insertItem( ntpSrvs.readEntry( "name" ) ); | ||
102 | } | ||
103 | if ( srvCount==0 ) | ||
104 | cbTimeServer->insertItem( "time.fu-berlin.de" ); | ||
105 | |||
106 | Config config( "ntp" ); | ||
107 | config.setGroup( "settings" ); | ||
108 | sbPredictDelay->setValue( config.readNumEntry( "minLookupDiff", 720 ) ); | ||
109 | sbNtpDelay->setValue( config.readNumEntry( "ntpRefreshFreq", 1440 ) ); | ||
110 | cbTimeServer->setCurrentItem( config.readNumEntry( "ntpServer", 0 ) ); | ||
111 | chNtpTab->setChecked( config.readBoolEntry( "displayNtpTab", FALSE ) ); | ||
112 | chPredictTab->setChecked( config.readBoolEntry( "displayPredictTab", FALSE ) ); | ||
113 | } | ||
114 | |||
115 | SettingsTabWidget::~SettingsTabWidget() | ||
116 | { | ||
117 | } | ||
118 | |||
119 | void SettingsTabWidget::saveSettings() | ||
120 | { | ||
121 | int srvCount = cbTimeServer->count(); | ||
122 | bool serversChanged = TRUE; | ||
123 | int curSrv = cbTimeServer->currentItem(); | ||
124 | QString edit = cbTimeServer->currentText(); | ||
125 | for ( int i = 0; i < srvCount; i++ ) | ||
126 | { | ||
127 | if ( edit == cbTimeServer->text( i ) ) | ||
128 | serversChanged = FALSE; | ||
129 | } | ||
130 | if ( serversChanged ) | ||
131 | { | ||
132 | QString ntpSrvsFile = QPEApplication::qpeDir(); | ||
133 | ntpSrvsFile.append( "etc/ntpservers" ); | ||
134 | Config ntpSrvs( ntpSrvsFile, Config::File ); | ||
135 | ntpSrvs.setGroup( "servers" ); | ||
136 | ntpSrvs.writeEntry( "count", ++srvCount ); | ||
137 | ntpSrvs.setGroup( "0" ); | ||
138 | ntpSrvs.writeEntry( "name", edit ); | ||
139 | curSrv = 0; | ||
140 | for ( int i = 1; i < srvCount; i++ ) | ||
141 | { | ||
142 | // qDebug( "ntpSrvs[%i/%i]=%s", i, srvCount, cbTimeServer->text( i ).latin1() ); | ||
143 | ntpSrvs.setGroup( QString::number( i ) ); | ||
144 | ntpSrvs.writeEntry( "name", cbTimeServer->text( i-1 ) ); | ||
145 | } | ||
146 | } | ||
147 | Config config( "ntp", Config::User ); | ||
148 | config.setGroup( "settings" ); | ||
149 | config.writeEntry( "ntpServer", curSrv ); | ||
150 | config.writeEntry( "minLookupDiff", sbPredictDelay->value() ); | ||
151 | config.writeEntry( "ntpRefreshFreq", sbNtpDelay->value() ); | ||
152 | config.writeEntry( "displayNtpTab", chNtpTab->isChecked() ); | ||
153 | config.writeEntry( "displayPredictTab", chPredictTab->isChecked() ); | ||
154 | } | ||
155 | |||
156 | QString SettingsTabWidget::ntpServer() | ||
157 | { | ||
158 | return cbTimeServer->currentText(); | ||
159 | } | ||