Author: mvidner
Date: Tue Mar 31 17:21:51 2009
New Revision: 56511
URL: http://svn.opensuse.org/viewcvs/yast?rev=56511&view=rev
Log:
Moved more code dealing with NTP setup from yast2-country
to yast2-ntp-client to make the API less fragile (bnc#483787).
Modified:
trunk/country/VERSION
trunk/country/package/yast2-country.changes
trunk/country/timezone/src/dialogs.ycp
trunk/country/yast2-country.spec.in
trunk/ntp-client/VERSION
trunk/ntp-client/package/yast2-ntp-client.changes
trunk/ntp-client/src/ntp-client_proposal.ycp
Modified: trunk/country/VERSION
URL: http://svn.opensuse.org/viewcvs/yast/trunk/country/VERSION?rev=56511&r1=56510&r2=56511&view=diff
==============================================================================
--- trunk/country/VERSION (original)
+++ trunk/country/VERSION Tue Mar 31 17:21:51 2009
@@ -1 +1 @@
-2.18.2
+2.18.3
Modified: trunk/country/package/yast2-country.changes
URL: http://svn.opensuse.org/viewcvs/yast/trunk/country/package/yast2-country.changes?rev=56511&r1=56510&r2=56511&view=diff
==============================================================================
--- trunk/country/package/yast2-country.changes (original)
+++ trunk/country/package/yast2-country.changes Tue Mar 31 17:21:51 2009
@@ -1,4 +1,11 @@
-------------------------------------------------------------------
+Tue Mar 31 16:52:04 CEST 2009 - mvidner@suse.cz
+
+- Moved more code dealing with NTP setup from yast2-country
+ to yast2-ntp-client to make the API less fragile (bnc#483787).
+- 2.18.3
+
+-------------------------------------------------------------------
Wed Feb 25 19:22:48 CET 2009 - jsuchome@suse.cz
- install language dependent packages in firstboot (bnc#479553)
Modified: trunk/country/timezone/src/dialogs.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/country/timezone/src/dialogs.ycp?rev=56511&r1=56510&r2=56511&view=diff
==============================================================================
--- trunk/country/timezone/src/dialogs.ycp (original)
+++ trunk/country/timezone/src/dialogs.ycp Tue Mar 31 17:21:51 2009
@@ -66,23 +66,51 @@
UI::ChangeWidget(`id(`date), `Value, Timezone::GetDateTime (really, false));
};
+
+ // handles the complication that the package yast2-ntp-client may not be present
+ any ntp_call(string acall, map args) {
+ if (!ntp_installed) {
+ // replace "replace_point" by the widgets
+ if (acall == "ui_init")
+ return false; // deselect the RB
+ // the help text
+ else if (acall == "ui_help_text")
+ return ""; // or say "will install"? TODO recompute help text
+ // save settings, return false if dialog should not exit
+ else if (acall == "ui_try_save")
+ return true; // success, exit loop
+ // Service::Enabled. FIXME too smart?
+ else if (acall == "GetNTPEnabled")
+ return false;
+
+ // default: do nothing
+ return nil;
+ /*
+ other API for completeness:
+ // before UserInput
+ else if (acall == "ui_enable_disable_widgets")
+ else if (acall == "SetUseNTP")
+ else if (acall == "Write")
+ */
+ }
+
+ any ret = WFM::CallFunction ("ntp-client_proposal", [ acall, args ]);
+ return ret;
+ }
+
/**
* Dialog for setinge system date and time
* @return true if user changed the time (dialog accepted)
*/
define boolean SetTimeDialog() {
+ string ntp_help_text = (string) ntp_call("ui_help_text", $[]);
// help text for set time dialog
string htext = _("<p>The current system time and date are displayed. If required change them to the correct values manually, or use Network Time Protocol (NTP).</p>") +
+ // help text, cont.
+ _("<p>Press <b>Accept</b> to save your changes.</p>") +
- // help text, cont.
- _("<p>Press <b>Synchronize Now</b>, to get your system time set correctly using the selected NTP server. If you want to make use of NTP permanently, enable the <b>Save NTP Configuration</b> option</p>") +
-
- // help text, cont.
- _("<p>Using the <b>Configure</b> button, open the advanced NTP configuration. Press <b>Accept</b> to save your changes.</p>") +
-
- // help text, cont.
- _("<p>Synchronization with the NTP server can be done only when the network is configured.</p>");
+ ntp_help_text;
boolean dt_widgets = false;
@@ -168,40 +196,8 @@
dt_widgets = true;
}
- boolean ntp_was_used = false;
-
- void enable_disable_widgets () {
- UI::ChangeWidget (`id (`ntp_address), `Enabled, ntp_used);
- UI::ChangeWidget (`id (`ntp_configure), `Enabled, ntp_used);
- UI::ChangeWidget (`id (`ntp_now), `Enabled, ntp_used);
- UI::ChangeWidget (`id (`ntp_save), `Enabled, ntp_used);
- }
-
- void handle_invalid_hostname( string server ) {
- // translators: error popup
- Popup::Error( sformat(_("Invalid NTP server hostname %1"), server) );
- }
-
- // param: when asking for first time, we check if service is running
- void CreateUI (boolean first_time) {
- WFM::CallFunction("ntp-client_proposal", ["CreateUI"]);
- if (first_time && !Stage::initial ())
- ntp_used = (boolean)
- WFM::CallFunction("ntp-client_proposal", ["GetNTPEnabled"]);
- else
- ntp_used = (boolean)
- WFM::CallFunction("ntp-client_proposal", ["GetUseNTP"]);
- if ( UI::WidgetExists(`id(`ntp_content)) )
- {
- UI::ChangeWidget(`id(`rb), `CurrentButton, (ntp_used ? `ntp : `manual));
- enable_disable_widgets ();
- if (first_time)
- // ntp_used with first_time means that ntp service is enabled
- UI::ChangeWidget (`id(`ntp_save), `Value, ntp_used);
- }
- }
term cont = `HBox (
`HWeight (1, `VBox ()),
@@ -218,29 +214,28 @@
)
),
`VSpacing (1),
- `VBox (`id(`ntp_content),
- `Left (`RadioButton (`id (`ntp), `opt (`notify),
- // radio button label
- _("Synchronize with NTP Server"), false)
- ),
- `ReplacePoint(`id(`rp), `Empty())
- )
+ `Left (`RadioButton (`id (`ntp), `opt (`notify),
+ // radio button label
+ _("Synchronize with NTP Server"), false)
+ ),
+ `ReplacePoint(`id(`rp), `Empty())
))),
`HWeight (1, `VBox ())
);
Wizard::OpenAcceptDialog ();
+ // TODO replace help text after ntp_installed, is.
Wizard::SetContents (_("Change Date and Time"), cont, htext, true, true);
Wizard::SetDesktopIcon("timezone");
show_current_time ();
- if (ntp_installed) {
- CreateUI (true);
- ntp_was_used = ntp_used;
- if (ntp_used)
- WFM::CallFunction ("ntp-client_proposal", [ "MakeProposal",
- $[ "country" : Language::GetLanguageCountry() ] ]);
- }
+
+ boolean ntp_rb = false;
+ ntp_rb = (boolean) ntp_call ("ui_init", $[
+ "replace_point": `id (`rp),
+ "country" : Language::GetLanguageCountry(),
+ /*WTF*/"first_time" : true ]);
+ UI::ChangeWidget(`id(`rb), `CurrentButton, (ntp_rb ? `ntp : `manual));
if (!dt_widgets)
{
@@ -255,71 +250,50 @@
any ret = nil;
repeat
{
+ ntp_call ("ui_enable_disable_widgets", $["enabled": ntp_rb]);
+
ret = UI::UserInput();
y2debug ("UserInput ret:%1", ret );
+
+ symbol ntp_handled = (symbol) ntp_call ("ui_handle", $["ui": ret]);
+ if (ntp_handled != nil) {
+ ret = ntp_handled;
+ }
+ if (ret == `redraw)
+ show_current_time ();
+
if (ret == `ntp || ret == `manual)
{
- ntp_used = (ret == `ntp);
- if (ntp_used && !Stage::initial () && !ntp_installed)
+ ntp_rb = (ret == `ntp);
+ // need to install it first?
+ if (ntp_rb && !Stage::initial () && !ntp_installed)
{
ntp_installed = Package::Install ("yast2-ntp-client");
+ // succeeded? create UI, otherwise revert the click
if (!ntp_installed)
{
- ntp_used = false;
- UI::ChangeWidget (`id (`manual), `Value, true);
- UI::ChangeWidget (`id (`ntp), `Value, false);
+ ntp_rb = false;
+ UI::ChangeWidget (`id(`rb), `CurrentButton, `manual);
}
else
- CreateUI (false);
- }
- if (ntp_used )
- {
- WFM::CallFunction("ntp-client_proposal", [ "MakeProposal", $[
- "country" : Language::GetLanguageCountry() ] ]
- );
- }
- enable_disable_widgets ();
- }
- if (ret == `ntp_configure)
- {
- symbol rv = (symbol) WFM::CallFunction ("ntp-client_proposal", ["AskUser"]);
- if( rv == `invalid_hostname)
- {
- handle_invalid_hostname (
- (string) UI::QueryWidget (`id (`ntp_address), `Value));
- ret = `retry;
- continue;
- }
- if (rv != `next)
- continue;
- else if (!Stage::initial ())
- {
- // show the 'save' status after configuration
- boolean enabled = (boolean)
- WFM::CallFunction("ntp-client_proposal", ["GetNTPEnabled"]);
- UI::ChangeWidget (`id(`ntp_save), `Value, enabled);
+ {
+ // ignore retval, user clicked to use ntp
+ ntp_call ("ui_init", $[
+ "replace_point": `id (`rp),
+ "country" : Language::GetLanguageCountry(),
+ "first_time" : false ]);
+ }
}
}
- if (ret == `ntp_now)
+
+ if (ret == `accept && ntp_rb)
{
- map argmap = $[
- "ntpdate_only" : true
- ];
- symbol rv = (symbol) WFM::CallFunction ("ntp-client_proposal",
- ["Write", argmap]);
- if( rv == `invalid_hostname)
- {
- handle_invalid_hostname (
- (string) UI::QueryWidget (`id (`ntp_address), `Value));
- ret = `retry;
- continue;
- }
- if (rv == `success)
- {
- show_current_time ();
- }
+ // true: go on, exit; false: loop on
+ boolean ntp_handled = (boolean) ntp_call ("ui_try_save", $[]);
+ if (!ntp_handled)
+ ret = `retry; // loop on
}
- if (ret == `accept && !ntp_used)
+ if (ret == `accept && !ntp_rb)
{
if (dt_widgets)
{
@@ -367,54 +341,18 @@
{
Timezone::SetTime( year, month, day, hour, minute, second );
}
-// if (ntp_was_used) FIXME remove NTP config now?
- }
- if (ret == `accept && ntp_used)
- {
- map argmap = $[];
- if (UI::QueryWidget (`id (`ntp_save), `Value) == false)
- argmap["ntpdate_only"] = true;
- symbol rv = (symbol) WFM::CallFunction ("ntp-client_proposal",
- ["Write", argmap]);
-
- string server = (string) UI::QueryWidget (`id(`ntp_address),`Value);
-
- if (rv == `invalid_hostname)
- {
- handle_invalid_hostname( server );
- ret = `retry;
- continue;
- }
- else if ( rv == `ntpdate_failed)
- {
- // Translators: yes-no popup,
- // ntpdate is a command, %1 is the server address
- if (Popup::YesNo( sformat(_("'ntpdate %1' failed. Revisit NTP server configuration?"), server) ))
- {
- ret = `retry;
- continue;
- }
- else
- {
- ntp_used = false;
- UI::ChangeWidget (`id(`rb), `CurrentButton, `manual);
- }
- }
- else
- {
- // new system time from ntpdate must be saved to hw clock
- Timezone::SystemTime2HWClock ();
- }
}
}
until( ret==`accept || ret==`cancel );
- if (ret == `accept && ntp_installed)
+ if (ret == `accept)
{
- ntp_used = (UI::QueryWidget (`id(`rb), `Value) == `ntp) &&
- (UI::QueryWidget (`id(`ntp_save), `Value) == true);
- WFM::CallFunction("ntp-client_proposal", [ "SetUseNTP", $["ntp_used" : ntp_used] ]);
+ // new system time from ntpdate must be saved to hw clock
+ Timezone::SystemTime2HWClock ();
+ // remember ui
+ ntp_call ("SetUseNTP", $["ntp_used" : ntp_rb]);
}
+
Wizard::CloseDialog ();
return (ret == `accept);
};
@@ -501,7 +439,7 @@
// configure NTP client
srandom ();
string server = sformat ("%1.opensuse.pool.ntp.org", random (4));
- map argmap = $[
+ map argmap = $[
"server" : server,
// FIXME ntp-client_proposal doesn't understand 'servers' yet
"servers" : [
@@ -511,8 +449,7 @@
"3.opensuse.pool.ntp.org",
],
];
- symbol rv = (symbol)
- WFM::CallFunction ("ntp-client_proposal", ["Write", argmap]);
+ symbol rv = (symbol) ntp_call ("Write", argmap);
if (rv == `invalid_hostname)
{
y2warning ("Invalid NTP server hostname %1", server);
@@ -522,8 +459,7 @@
{
Timezone::SystemTime2HWClock ();
y2milestone ("proposing NTP server %1", server);
- WFM::CallFunction ("ntp-client_proposal",
- [ "SetUseNTP", $["ntp_used" : ntp_used] ]);
+ ntp_call ("SetUseNTP", $["ntp_used" : ntp_used]);
}
}
else if (Stage::initial ())
@@ -531,9 +467,10 @@
// from installation summaru
ntp_used = Timezone::ntp_used;
}
- else if (ntp_installed)
- ntp_used = (boolean)
- WFM::CallFunction ("ntp-client_proposal", ["GetNTPEnabled"]);
+ else if (ntp_installed) {
+ ntp_used = (boolean) ntp_call ("GetNTPEnabled", $[]);
+ ntp_used = ntp_used == true; // nil->false, just in case of parse error
+ }
string time_frame_label =
// frame label
Modified: trunk/country/yast2-country.spec.in
URL: http://svn.opensuse.org/viewcvs/yast/trunk/country/yast2-country.spec.in?rev=56511&r1=56510&r2=56511&view=diff
==============================================================================
--- trunk/country/yast2-country.spec.in (original)
+++ trunk/country/yast2-country.spec.in Tue Mar 31 17:21:51 2009
@@ -9,6 +9,8 @@
Requires: yast2-pkg-bindings >= 2.15.3
# IconPath support for MultiSelectionBox
Requires: yast2-core >= 2.16.28
+# new API of ntp-client_proposal.ycp
+Conflicts: yast2-ntp-client < 2.18.0
Requires: yast2-country-data
Modified: trunk/ntp-client/VERSION
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ntp-client/VERSION?rev=56511&r1=56510&r2=56511&view=diff
==============================================================================
--- trunk/ntp-client/VERSION (original)
+++ trunk/ntp-client/VERSION Tue Mar 31 17:21:51 2009
@@ -1 +1 @@
-2.17.14
+2.18.0
Modified: trunk/ntp-client/package/yast2-ntp-client.changes
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ntp-client/package/yast2-ntp-client.changes?rev=56511&r1=56510&r2=56511&view=diff
==============================================================================
--- trunk/ntp-client/package/yast2-ntp-client.changes (original)
+++ trunk/ntp-client/package/yast2-ntp-client.changes Tue Mar 31 17:21:51 2009
@@ -1,4 +1,11 @@
-------------------------------------------------------------------
+Tue Mar 31 16:52:04 CEST 2009 - mvidner@suse.cz
+
+- Moved more code dealing with NTP setup from yast2-country
+ to yast2-ntp-client to make the API less fragile (bnc#483787).
+- 2.18.0
+
+-------------------------------------------------------------------
Tue Mar 17 14:01:57 CET 2009 - mvidner@suse.cz
- Do not pop up with questions in CLI mode (bnc#456553).
Modified: trunk/ntp-client/src/ntp-client_proposal.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/ntp-client/src/ntp-client_proposal.ycp?rev=56511&r1=56510&r2=56511&view=diff
==============================================================================
--- trunk/ntp-client/src/ntp-client_proposal.ycp (original)
+++ trunk/ntp-client/src/ntp-client_proposal.ycp Tue Mar 31 17:21:51 2009
@@ -21,10 +21,7 @@
import "Popup";
import "Progress";
import "Report";
-
-y2milestone("----------------------------------------");
-y2milestone("Ntp client proposal started");
-y2milestone("Arguments: %1", WFM::Args());
+import "Wizard";
/*
API:
@@ -32,12 +29,9 @@
Usual *_proposal functions: MakeProposal, AskUser, Write.
(but not Description; see, it just *looks* like *_proposal)
Additionally:
- CreateUI (thick and fragile interface, grr)
GetNTPEnabled (queries Service::Enabled)
- GetUseNTP (queries NtpClient::ntp_selected, just a storage for the caller)
SetUseNTP [ntp_used]
*/
-
any ret = nil;
string func = "";
map param = $[];
@@ -48,7 +42,69 @@
param = (map)WFM::Args(1);
}
-void ProposeSomething()
+
+string ui_help_text() {
+ // help text
+ return _("<p>Press <b>Synchronize Now</b>, to get your system time set correctly using the selected NTP server. If you want to make use of NTP permanently, enable the <b>Save NTP Configuration</b> option</p>") +
+
+ // help text, cont.
+ _("<p>Using the <b>Configure</b> button, open the advanced NTP configuration.</p>") +
+
+ // help text, cont.
+ _("<p>Synchronization with the NTP server can be done only when the network is configured.</p>");
+}
+
+// FIXME must go to module to preserve value
+boolean ntp_was_used = false;
+
+void ui_enable_disable_widgets (boolean enabled) {
+ UI::ChangeWidget (`id (`ntp_address), `Enabled, enabled);
+ UI::ChangeWidget (`id (`ntp_now), `Enabled, enabled);
+ UI::ChangeWidget (`id (`ntp_save), `Enabled, enabled);
+ if (UI::WidgetExists (`id (`ntp_configure))) // bnc#483787
+ UI::ChangeWidget (`id (`ntp_configure), `Enabled, enabled);
+}
+
+void handle_invalid_hostname( string server ) {
+ // translators: error popup
+ Popup::Error( sformat(_("Invalid NTP server hostname %1"), server) );
+}
+
+boolean GetNTPEnabled () {
+ return Service::Enabled (NtpClient::service_name);
+}
+
+boolean ValidateSingleServer( string ntp_server )
+{
+ if (!Address::Check(ntp_server) )
+ {
+ UI::SetFocus(`id(`ntp_address));
+ return false;
+ }
+
+ return true;
+}
+
+void AddSingleServer( string server )
+{
+
+ integer idx = NtpClient::findSyncRecord("server", server);
+
+ // -1 means adding new server
+ if (idx == -1)
+ {
+ NtpClient::selected_record["address"] = server;
+ NtpClient::selected_record["type"] = "server";
+ }
+ else
+ NtpClient::selectSyncRecord(idx);
+
+ NtpClient::storeSyncRecord();
+}
+
+
+// @param cc country code
+void MakeProposal(string cc)
{
list ntp_items = [];
@@ -74,116 +130,93 @@
// avoid calling Read again (bnc #427712)
NtpClient::config_has_been_read = true;
}
+/*
+ FIXME: does MakeProposal have sense?
+ would it have sense if implemented properly?
+real proposal starts here, it is ui_read before...
+*/
+
if( ntp_items == [])
{
- string cc = param["country"]:NtpClient::GetCurrentLanguageCode();
y2milestone("Nothing found in /etc/ntp.conf, proposing current language-based NTP server list");
ntp_items = NtpClient::GetNtpServersByCountry( cc, true );
NtpClient::config_has_been_read = true;
}
ntp_items = add(ntp_items, "");
UI::ChangeWidget(`id(`ntp_address), `Items, ntp_items);
-
-}
-
-void AddSingleServer( string server )
-{
-
- integer idx = NtpClient::findSyncRecord("server", server);
-
- // -1 means adding new server
- if (idx == -1)
- {
- NtpClient::selected_record["address"] = server;
- NtpClient::selected_record["type"] = "server";
- }
- else
- NtpClient::selectSyncRecord(idx);
-
- NtpClient::storeSyncRecord();
}
-boolean ValidateSingleServer( string ntp_server )
-{
- if (!Address::Check(ntp_server) )
- {
- UI::SetFocus(`id(`ntp_address));
- return false;
- }
-
- return true;
-}
-
-if (func == "CreateUI")
-{
+/**
+@param first_time when asking for first time, we check if service is running
+@return should our radio button be selected
+*/
+boolean ui_init(term rp, string country, boolean first_time) {
term cont = `VBox (`VSpacing (0.5), `HBox (
`HSpacing (3),
`HWeight (1, `VBox (
`Left (`ComboBox (`id (`ntp_address), `opt (`editable, `hstretch),
// combo box label
- _("NTP Server Address")
+ _("&NTP Server Address")
)),
`VSpacing (0.3),
`HBox (
`HSpacing (0.5),
// check box label
- `Left (`CheckBox (`id (`ntp_save), _("Save NTP Configuration")))
+ `Left (`CheckBox (`id (`ntp_save), _("&Save NTP Configuration")))
)
)),
`HWeight (1, `VBox (
- `Label (""),
+ `Label (""),
`VSpacing (0.3), // try to line up the widgets horizontally
- // push button label
- `Left (`PushButton (`id (`ntp_now), _("Synchronize now"))),
+ // push button label
+ `Left (`PushButton (`id (`ntp_now), _("S&ynchronize now"))),
`VSpacing (0.3),
- // push button label
+ // push button label
// bnc#449615: only simple config for inst-sys
- Stage::initial() ? `Label("") : `Left (`PushButton (`id (`ntp_configure), _("Configure...")))
+ Stage::initial() ? `Label("") : `Left (`PushButton (`id (`ntp_configure), _("&Configure...")))
))
));
- if (UI::WidgetExists(`id(`rp)))
- {
- UI::ReplaceWidget(`id(`rp), cont);
-
- if (!NetworkService::isNetworkRunning())
- {
- y2warning("Network is not running, NTP synchronization will not be available");
- UI::ChangeWidget(`id(`ntp_content), `Enabled, false);
- }
- }
+ UI::ReplaceWidget(rp, cont);
- ret = true;
-}
+ if (!NetworkService::isNetworkRunning())
+ {
+ y2warning("Network is not running, NTP synchronization will not be available");
+ UI::ChangeWidget(`id(`ntp_content), `Enabled, false); // FIXME it is outside
+ }
-else if (func == "GetNTPEnabled")
-{
- ret = Service::Enabled (NtpClient::service_name);
-}
+// ^ createui0
+ // FIXME is it correct? move out?
+ boolean ntp_used = (first_time && !Stage::initial ()) ?
+ GetNTPEnabled () : NtpClient::ntp_selected;
-else if (func == "GetUseNTP")
-{
- /*
- if (param["first_time"]:false && !Stage::initial ())
- {
- ret = Service::Enabled (NtpClient::service_name);
- }
- else
- */
- ret = NtpClient::ntp_selected;
-}
+ if (first_time)
+ // ntp_used with first_time means that ntp service is enabled
+ UI::ChangeWidget (`id(`ntp_save), `Value, ntp_used);
-else if (func == "SetUseNTP")
-{
- NtpClient::ntp_selected = param["ntp_used"]:false;
- ret = true;
+ // ntp_was_used = ntp_used;
+ if (ntp_used)
+ MakeProposal (country);
+ return ntp_used;
}
-else if (func == "MakeProposal")
-{
- ProposeSomething();
- ret = true;
+symbol AskUser () {
+ symbol ret = nil;
+ string ntp_server = (string) UI::QueryWidget(`id(`ntp_address), `Value);
+ if ( !ValidateSingleServer( ntp_server ) )
+ ret = `invalid_hostname;
+ else
+ {
+ string ntp_server = (string) UI::QueryWidget(`id(`ntp_address), `Value);
+ AddSingleServer(ntp_server);
+ boolean retval = (boolean) WFM::CallFunction("ntp-client");
+ if (retval)
+ ret = `next;
+ string cc = NtpClient::GetCurrentLanguageCode();
+ MakeProposal(cc);
+ }
+ return ret;
}
/*
@@ -192,100 +225,194 @@
servers (intended to use all of opensuse.pool.ntp.org,
but I did not have time to make it work)
ntpdate_only (TODO rename to onetime)
+return:
+ `success, `invalid_hostname or `ntpdate_failed
*/
-else if (func == "Write")
-{
+symbol Write(map param) {
+ symbol ret = nil;
string ntp_server = param["server"]:"";
if (ntp_server == "")
// get the value from UI only when it wasn't given as a parameter
ntp_server = (string) UI::QueryWidget(`id(`ntp_address), `Value);
+ if ( !ValidateSingleServer( ntp_server ) )
+ return `invalid_hostname;
// One-time adjusment without running the ntp daemon
// Meanwhile, ntpdate was replaced by sntp
boolean ntpdate_only = param["ntpdate_only"]:false;
- if ( !ValidateSingleServer( ntp_server ) )
- ret = `invalid_hostname;
- else
+ string required_package = "ntp";
+
+ //In 1st stage, schedule packages for installation
+ //but not in case user wants to set the time only (F#302917)
+ //(ntpdate is in inst-sys so we don't need the package)
+ if (Stage::initial() && !ntpdate_only)
{
- string required_package = "ntp";
+ import "Packages";
+ Packages::addAdditionalPackage(required_package);
+ // bugzilla #327050
+ // Agent for writing /etc/ntp.conf needs to be installed
+ // to write the settings at the end of the installation
+ Packages::addAdditionalPackage("yast2-ntp-client");
+ }
+ //Otherwise, prompt user for confirming pkg installation
+ else if (!Stage::initial ())
+ {
+ if (!PackageSystem::CheckAndInstallPackages([ required_package ]))
+ {
+ Report::Error(sformat( _("Synchronization with NTP server is not possible
+without having package %1 installed"), required_package));
+ }
+ }
- //In 1st stage, schedule packages for installation
- //but not in case user wants to set the time only (F#302917)
- //(ntpdate is in inst-sys so we don't need the package)
- if (Stage::initial() && !ntpdate_only)
+ Popup::ShowFeedback("", _("Synchronizing with NTP server..."));
+
+ y2milestone("Running sntp to sync with %1", ntp_server);
+
+ // -r: do set the system time
+ // -P no: do not ask if time difference is too large
+ // -c 1 -d 15: delay 15s, only one try (bnc#442287)
+ integer r = (integer) SCR::Execute (.target.bash, sformat ("/usr/sbin/sntp -c 1 -d 15 -r -P no '%1'", String::Quote(ntp_server)));
+ y2milestone ("'sntp %1' returned %2", ntp_server, r);
+
+ Popup::ClearFeedback();
+
+ if (r != 0)
+ return `ntpdate_failed;
+
+ // User wants to more than running sntp (synchronize on boot)
+ if (!ntpdate_only)
+ {
+ NtpClient::modified = true;
+ AddSingleServer(ntp_server);
+
+ //OK, so we stored the server address
+ //In inst-sys we don't need to care further
+ //ntp-client_finish will do the job
+ //In installed system we must write the settings
+ if (!Stage::initial()) {
+ Wizard::OpenAcceptDialog(); // FIXME so that the progress does not disturb the dialog to be returned to
+ NtpClient::Write();
+ Wizard::CloseDialog();
+ }
+ }
+
+ return `success;
+}
+
+// ui = UI::UserInput
+symbol ui_handle(any ui) {
+ boolean redraw = false;
+ if (ui == `ntp_configure)
+ {
+ symbol rv = AskUser ();
+ if( rv == `invalid_hostname)
{
- import "Packages";
- Packages::addAdditionalPackage(required_package);
- // bugzilla #327050
- // Agent for writing /etc/ntp.conf needs to be installed
- // to write the settings at the end of the installation
- Packages::addAdditionalPackage("yast2-ntp-client");
+ handle_invalid_hostname (
+ (string) UI::QueryWidget (`id (`ntp_address), `Value));
}
- //Otherwise, prompt user for confirming pkg installation
- else if (!Stage::initial ())
+ else if (rv == `next && !Stage::initial ())
{
- if (!PackageSystem::CheckAndInstallPackages([ required_package ]))
- {
- Report::Error(sformat( _("Synchronization with NTP server is not possible
-without having package %1 installed"), required_package));
- }
+ // show the 'save' status after configuration
+ UI::ChangeWidget (`id(`ntp_save), `Value, GetNTPEnabled ());
+ }
+ }
+ if (ui == `ntp_now)
+ {
+ symbol rv = Write ($["ntpdate_only" : true]);
+ if( rv == `invalid_hostname)
+ {
+ handle_invalid_hostname (
+ (string) UI::QueryWidget (`id (`ntp_address), `Value));
}
+ else if (rv == `success)
+ {
+ redraw = true; // update time widgets
+ }
+ }
+
+ return redraw? `redraw : nil;
+}
+
+boolean ui_try_save() {
+ map argmap = $[];
+ if (UI::QueryWidget (`id (`ntp_save), `Value) == false)
+ argmap["ntpdate_only"] = true;
- Popup::ShowFeedback("", _("Synchronizing with NTP server..."));
+ symbol rv = Write (argmap);
- y2milestone("Running sntp to sync with %1", ntp_server);
+ string server = (string) UI::QueryWidget (`id(`ntp_address),`Value);
- // -r: do set the system time
- // -P no: do not ask if time difference is too large
- // -c 1 -d 15: delay 15s, only one try (bnc#442287)
- integer r = (integer) SCR::Execute (.target.bash, sformat ("/usr/sbin/sntp -c 1 -d 15 -r -P no '%1'", String::Quote(ntp_server)));
- y2milestone ("'sntp %1' returned %2", ntp_server, r);
-
- Popup::ClearFeedback();
-
- if (r == 0)
- {
- ret = `success;
-
- // User wants to more than running sntp (synchronize on boot)
- if (!ntpdate_only)
- {
- NtpClient::modified = true;
- AddSingleServer(ntp_server);
-
- //OK, so we stored the server address
- //In inst-sys we don't need to care further
- //ntp-client_finish will do the job
- //In installed system we must write the settings
- if (!Stage::initial())
- NtpClient::Write();
- }
- }
- else
- ret = `ntpdate_failed;
+ if (rv == `invalid_hostname)
+ {
+ handle_invalid_hostname( server );
+ return false; // loop on
+ }
+ else if ( rv == `ntpdate_failed)
+ {
+ // Translators: yes-no popup,
+ // ntpdate is a command, %1 is the server address
+ if (Popup::YesNo( sformat(_("'ntpdate %1' failed. Revisit NTP server configuration?"), server) ))
+ {
+ return false; // loop on
+ }
}
+ // success, exit
+ return true;
}
-else if (func == "AskUser")
+
+
+if (false)
{
- string ntp_server = (string) UI::QueryWidget(`id(`ntp_address), `Value);
- if ( !ValidateSingleServer( ntp_server ) )
- ret = `invalid_hostname;
- else
- {
- string ntp_server = (string) UI::QueryWidget(`id(`ntp_address), `Value);
- AddSingleServer(ntp_server);
- boolean retval = (boolean) WFM::CallFunction("ntp-client");
- if (retval)
- ret = `next;
- ProposeSomething();
- }
+ return;
+}
+else if (func == "GetNTPEnabled")
+{
+ ret = GetNTPEnabled ();
}
-y2milestone("Ntp client proposal finished");
-y2milestone("----------------------------------------");
-return ret;
+
+else if (func == "SetUseNTP")
+{
+ NtpClient::ntp_selected = param["ntp_used"]:false;
+ ret = true;
+}
+
+else if (func == "MakeProposal")
+{
+ string cc = param["country"]:NtpClient::GetCurrentLanguageCode();
+ ret = MakeProposal(cc);
+}
+
+else if (func == "Write")
+{
+ ret = Write (param);
}
+else if (func == "ui_help_text")
+{
+ ret = ui_help_text();
+}
+else if (func == "ui_init")
+{
+ term rp = param["replace_point"]:`id(`rp);
+ string cc = param["country"]:NtpClient::GetCurrentLanguageCode();
+ boolean ft = param["first_time"]:false;
+ ret = ui_init(rp, cc, ft);
+}
+else if (func == "ui_try_save")
+{
+ ret = ui_try_save();
+}
+else if (func == "ui_enable_disable_widgets")
+{
+ ret = ui_enable_disable_widgets(param["enabled"]:false);
+}
+else if (func == "ui_handle")
+{
+ ret = ui_handle(param["ui"]:nil);
+}
+return ret;
+}
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org