ACC SHELL
/**
* File: include/ntp-client/dialogs.ycp
* Package: Configuration of ntp-client
* Summary: Dialogs definitions
* Authors: Jiri Srain <jsrain@suse.cz>
*
* $Id: dialogs.ycp 61806 2010-04-21 14:38:02Z varkoly $
*/
{
textdomain "ntp-client";
import "CWM";
import "CWMTab";
import "Label";
import "NtpClient";
import "Popup";
import "Stage";
import "SuSEFirewall";
import "Wizard";
import "Report";
import "Confirm";
include "ntp-client/misc.ycp";
include "ntp-client/widgets.ycp";
map<string,map<string,any> > widgets = nil;
/**
* Get the map of all widgets
* @return a map with all widgets for CWM
*/
define map<string,map<string,any> > GetWidgets () {
if (widgets == nil)
widgets = InitWidgets ();
return widgets;
}
/**
* Display the popup to confirm abort
* @return boolean true if confirmed
*/
define boolean abortPopup () ``{
return Popup::ReallyAbort (true);
}
/**
* Read settings dialog
* @return `abort if aborted and `next otherwise
*/
define symbol ReadDialog() ``{
Wizard::RestoreHelp(HELPS["read"]:"");
// checking for root permissions (#158483)
if (!Stage::initial() && !Confirm::MustBeRoot())
return `abort;
NtpClient::AbortFunction = PollAbort;
boolean ret = NtpClient::Read();
NtpClient::AbortFunction = nil;
return ret ? `next : `abort;
}
/**
* Write settings dialog
* @return `abort if aborted and `next otherwise
*/
define symbol WriteDialog() ``{
if (Stage::initial())
return `next;
Wizard::RestoreHelp(HELPS["write"]:"");
NtpClient::AbortFunction = PollAbort;
boolean ret = NtpClient::Write();
NtpClient::AbortFunction = nil;
return ret ? `next : `abort;
}
/**
* Main dialog
* @return symbol for wizard sequencer
*/
define symbol SimpleDialog () ``{
NtpClient::simple_dialog = true;
list<map<string,any> > w = CWM::CreateWidgets (["start", "interval", "server_address", "use_random_servers", "complex_button"],
GetWidgets ());
term contents = `HBox (`HSpacing (1), `VBox (
`VStretch (),
`HBox (
`HStretch (),
"start",
`HStretch ()
),
`VStretch (),
"interval",
`VStretch (),
`HBox (
`HStretch (),
`Frame (
// frame label
_("NTP Server Configuration"),
`VBox (
`Left("use_random_servers"),
"server_address"
)
),
`HStretch ()
),
`VStretch (),
"complex_button",
`VStretch ()
), `HSpacing (1));
// dialog caption
string caption = _("NTP Configuration");
string help = CWM::MergeHelps (w);
contents = CWM::PrepareDialog (contents, w);
Wizard::SetContentsButtons (caption, contents, help,
Label::BackButton (),
Stage::initial()? Label::AcceptButton() : Label::OKButton ());
Wizard::HideBackButton();
Wizard::SetAbortButton(`abort, Label::CancelButton() );
startInit (nil);
CWM::handleWidgets (w, $["ID" : "never"]);
symbol ret = CWM::Run (w,
// yes-no popup
$[`abort : reallyExitSimple ]);
// and now store the settings if needed
if (ret != `abort && ret != `back && ret != `cancel)
{
}
y2milestone ("Simple dialog: Returning %1", ret);
return ret;
}
/**
* Main dialog
* @return symbol for wizard sequencer
*/
define symbol MainDialog () ``{
NtpClient::simple_dialog = false;
term tab1 = `HBox (`HSpacing (1), `VBox (
`VSpacing (1),
`HBox (
`VBox (
"start",
`VSpacing(),
`HBox (
"policy_combo",
"custom_policy"
),
`VSpacing(),
"interval",
`VSpacing()
)
),
`VSpacing (1),
"overview",
`VSpacing(1)
), `HSpacing (1));
term tab2 = `HBox (`HSpacing (1), `VBox (
`VSpacing (1),
`HBox (
`VBox (
`Left ("run_chroot"),
`VSpacing(),
`Left ("secure"),
`VSpacing(),
`Frame (
// TRANSLATORS: UI frame label
_("Firewall Settings"),
"firewall"
)
)
),
`VStretch()
), `HSpacing (1));
map <string, any> tabs = $[
"general" : $[
"header" : _("General Settings"),
"contents" : tab1,
"widget_names" : ["start", "policy_combo", "custom_policy", "interval", "overview"],
],
"security" : $[
"header" : _("Security Settings"),
"contents" :tab2,
"widget_names" : [ "run_chroot", "secure", "firewall"]
]
];
map <string, any> wd = $[
"tab" : CWMTab::CreateWidget ($[
"tab_order" : ["general", "security"],
"tabs" : tabs,
"widget_descr" : GetWidgets(),
"initial_tab" : "general",
"tab_help" : ""
])
];
term contents = `VBox("tab");
list<map <string, any> > w = CWM::CreateWidgets (["tab"], (map <string, map <string, any> >)wd);
// dialog caption
string caption = _("Advanced NTP Configuration");
string help = CWM::MergeHelps (w);
contents = CWM::PrepareDialog (contents, w);
Wizard::SetContentsButtons (caption, contents, help,
Label::BackButton (),
Stage::initial()? Label::AcceptButton() : Label::OKButton ());
Wizard::HideBackButton();
Wizard::SetAbortButton(`abort, Label::CancelButton() );
//CWM::handleWidgets (w, $["ID" : "never"]);
return CWM::Run (w,
$[`abort : reallyExitComplex]);
}
/**
* Type of new peer selection dialog
* @return symbol for wizard sequencer
*/
define symbol TypeSelectDialog () ``{
term contents = `HBox (`HStretch (), `VBox (
`VSpacing (3),
"peer_types",
`VSpacing (3)
), `HStretch ());
// dialog caption
string caption = _("New Synchronization");
return CWM::ShowAndRun ($[
"widget_names" : ["peer_types"],
"widget_descr" : GetWidgets (),
"contents" : contents,
"caption" : caption,
"back_button" : Label::BackButton (),
"next_button" : Label::NextButton (),
"fallback_functions" : $[`abort : abortPopup ]
]);
}
/**
* Server editing dialog
* @return symbol for wizard sequencer
*/
define symbol ServerDialog () ``{
term contents = `HBox (`HStretch (), `VBox (
`VSpacing (2),
`Frame( _("Server Settings"),
`VBox (
"server_address",
`VSpacing (0.5),
"options",
`VSpacing(0.5),
"ac_options",
`VSpacing(0.5))
),
`VSpacing (2)
), `HStretch ());
// dialog caption
string caption = _("NTP Server");
return CWM::ShowAndRun ($[
"widget_names" : ["server_address", "options", "ac_options"],
"widget_descr" : GetWidgets (),
"contents" : contents,
"caption" : caption,
"back_button" : Label::BackButton (),
"next_button" : Label::OKButton (),
"fallback_functions" : $[`abort : abortPopup],
]);
}
/**
* Dialog for selecting local server from a list
* @return symbol for wizard sequencer
*/
define symbol LocalServerSelectionDialog () {
list<map<string,any> > widgets = CWM::CreateWidgets (
[ "found_servers", "select_test_local"],
GetWidgets ()
);
term contents = `HBox (
`HSpacing (1),
`VBox (
`Frame (
// TRANSLATORS: frame label
_("Local NTP Server"),
`VBox (
`VSpacing (1),
widgets[0, "widget"]:`Empty(),
`VSpacing (1),
widgets[1, "widget"]:`Empty()
)
),
`VSpacing (1),
`HBox (
`PushButton( `id(`next), Label::OKButton() ),
`PushButton( `id(`back), Label::CancelButton() )
)
),
`HSpacing (1)
);
UI::OpenDialog(`opt(`decorated), contents);
symbol ret = CWM::Run (widgets, $[
`abort : abortPopup,
`ok : true,
`back : false,
]);
UI::CloseDialog();
return ret;
}
/**
* Dialog for selecting local server from a list
* @return symbol for wizard sequencer
*/
define symbol PublicServerSelectionDialog () {
list<map<string,any> > widgets = CWM::CreateWidgets (
[ "servers_list", "select_test_public" ],
GetWidgets ()
);
term contents = `HBox (
`HSpacing (1),
`VBox (
`Frame (
// TRANSLATORS: frame label
_("Public NTP Server"),
`VBox (
`VSpacing (1),
widgets[0, "widget"]:`Empty(),
`VSpacing (1),
widgets[1, "widget"]:`Empty()
)
),
`VSpacing (1),
`HBox (
`PushButton( `id(`next), Label::OKButton() ),
`PushButton( `id(`back), Label::CancelButton() )
)
),
`HSpacing (1)
);
UI::OpenDialog(`opt(`decorated), contents);
symbol ret = CWM::Run (widgets, $[
`abort : abortPopup,
`ok : true,
`back : false,
]);
UI::CloseDialog();
return ret;
}
/**
* Peer editing dialog
* @return symbol for wizard sequencer
*/
define symbol PeerDialog () ``{
term contents = `HBox (`HStretch (), `VBox (
`VSpacing (3),
"paddress",
`VSpacing (1),
"options",
`VSpacing (3)
), `HStretch ());
// dialog caption
string caption = _("NTP Peer");
return CWM::ShowAndRun ($[
"widget_names" : ["paddress", "options"],
"widget_descr" : GetWidgets (),
"contents" : contents,
"caption" : caption,
"back_button" : Label::BackButton (),
"next_button" : Label::OKButton (),
"fallback_functions" : $[`abort : abortPopup]
]);
}
/**
* Reference clock editing dialog
* @return symbol for wizard sequencer
*/
define symbol RadioDialog () ``{
term contents = `HBox (`HSpacing (3), `VBox (
`VSpacing (0.5),
`HBox (
"clock_type",
`HStretch ()
),
`HBox (
"unit_number",
`HStretch ()
),
`VSpacing (0.5),
`HBox (
"create_symlink",
`HStretch ()
),
`HBox (
"device",
`VBox (
`Label (""),
"browse"
),
`HStretch ()
),
`VSpacing (0.5),
"options",
`VSpacing (0.5),
"fudge_button",
`VSpacing (1)
), `HSpacing (3));
// dialog caption
string caption = _("Local Reference Clock");
return CWM::ShowAndRun ($[
"widget_names" : ["clock_type", "unit_number",
"create_symlink", "device", "browse",
"options", "fudge_button"],
"widget_descr" : GetWidgets (),
"contents" : contents,
"caption" : caption,
"back_button" : Label::BackButton (),
"next_button" : Label::OKButton (),
"fallback_functions" : $[`abort : abortPopup]
]);
}
/**
* Broadcast editing dialog
* @return symbol for wizard sequencer
*/
define symbol BCastDialog () ``{
term contents = `HBox (`HStretch (), `VBox (
`VSpacing (3),
"bcaddress",
`VSpacing (1),
"options",
`VSpacing (3)
), `HStretch ());
// dialog caption
string caption = _("Outgoing Broadcast");
return CWM::ShowAndRun ($[
"widget_names" : ["bcaddress", "options"],
"widget_descr" : GetWidgets (),
"contents" : contents,
"caption" : caption,
"back_button" : Label::BackButton (),
"next_button" : Label::OKButton (),
"fallback_functions" : $[`abort : abortPopup]
]);
}
/**
* Broadcast client editing dialog
* @return symbol for wizard sequencer
*/
define symbol BCastClientDialog () ``{
term contents = `HBox (`HStretch (), `VBox (
`VStretch (),
"bccaddress",
`VStretch ()
), `HStretch ());
// dialog caption
string caption = _("Incoming Broadcast");
return CWM::ShowAndRun ($[
"widget_names" : ["bccaddress"],
"widget_descr" : GetWidgets (),
"contents" : contents,
"caption" : caption,
"back_button" : Label::BackButton (),
"next_button" : Label::OKButton (),
"fallback_functions" : $[`abort : abortPopup]
]);
}
/**
* Fudge factors dialog
* @return symbol for wizard sequencer
*/
define symbol FudgeDialog () ``{
term contents = `HBox (`HSpacing (3), `VBox (
`VSpacing (3),
`HBox (
// text entry
`HWeight (1, `TextEntry (`id (`refid), _("&Reference ID"), "")),
`HSpacing (3),
// int field
`HWeight (1, `IntField (`id (`stratum), _("&Stratum"), 0, 15, 2))
),
`VStretch (),
`HBox (
// text entry
`HWeight (1, `TextEntry (`id (`time1), _("Calibration Offset 1"))),
`HSpacing (3),
// text entry
`HWeight (1, `TextEntry (`id (`time2), _("Calibration Offset 2")))
),
`VStretch (),
`HBox (
// check box
`HWeight (1, `CheckBox (`id (`flag1), _("Flag &1"), false)),
`HSpacing (3),
// check box
`HWeight (1, `CheckBox (`id (`flag2), _("Flag &2"), false))
),
`VStretch (),
`HBox (
// check box
`HWeight (1, `CheckBox (`id (`flag3), _("Flag &3"), false)),
`HSpacing (3),
// check box
`HWeight (1, `CheckBox (`id (`flag4), _("Flag &4"), false))
),
`VSpacing (3)
), `HSpacing (3));
// dialog caption
string caption = _("Clock Driver Calibration");
Wizard::SetContentsButtons (caption, contents, fudgeHelp (),
Label::BackButton (), Label::NextButton ());
map options = string2opts (NtpClient::selected_record["fudge_options"]:"",
["time1", "time2", "stratum", "refid",
"flag1", "flag2", "flag3", "flag4"],
[]);
y2error ("Options: %1", options);
UI::ChangeWidget (`id (`refid), `Value, options["parsed", "refid"]:"");
UI::ChangeWidget (`id (`stratum), `Value, tointeger (options["parsed", "stratum"]:"3"));
UI::ChangeWidget (`id (`time1), `Value, options["parsed", "time1"]:"");
UI::ChangeWidget (`id (`time2), `Value, options["parsed", "time2"]:"");
UI::ChangeWidget (`id (`flag1), `Value, options["parsed", "flag1"]:"" == "1");
UI::ChangeWidget (`id (`flag2), `Value, options["parsed", "flag2"]:"" == "1");
UI::ChangeWidget (`id (`flag3), `Value, options["parsed", "flag3"]:"" == "1");
UI::ChangeWidget (`id (`flag4), `Value, options["parsed", "flag4"]:"" == "1");
UI::ChangeWidget (`id (`time1), `ValidChars, "1234567890.");
UI::ChangeWidget (`id (`time2), `ValidChars, "1234567890.");
any ret = nil;
while (ret == nil)
{
ret = UI::UserInput ();
}
if (ret == `cancel)
ret = `abort;
if (ret == `back || ret == `abort)
return (symbol)ret;
if (ret == `next)
{
options["parsed", "refid"] = UI::QueryWidget (`id (`refid), `Value);
options["parsed", "stratum"] = UI::QueryWidget (`id (`stratum), `Value);
options["parsed", "time1"] = UI::QueryWidget (`id (`time1), `Value);
options["parsed", "time2"] = UI::QueryWidget (`id (`time2), `Value);
options["parsed", "flag1"] = (boolean)UI::QueryWidget (`id (`flag1), `Value) ? 1 : 0;
options["parsed", "flag2"] = (boolean)UI::QueryWidget (`id (`flag2), `Value) ? 1 : 0;
options["parsed", "flag3"] = (boolean)UI::QueryWidget (`id (`flag3), `Value) ? 1 : 0;
options["parsed", "flag4"] = (boolean)UI::QueryWidget (`id (`flag4), `Value) ? 1 : 0;
NtpClient::selected_record["fudge_options"] = opts2string (
options["parsed"]:$[],
options["unknown"]:""
);
}
return (symbol)ret;
}
// fake dialogs (WS switches)
/**
* Pseudo-dialog to fetch information for the simple dialog
* @return symbol for wizard sequencer (always `next)
*/
symbol SimpleDialogPrepare () {
list<map> peers = NtpClient::getSyncRecords ();
list<map> servers = filter (map m, peers, ``(m["type"]:"" == "server"));
integer index = servers[0, "index"]:-1;
NtpClient::selectSyncRecord (index);
return `next;
}
/**
* Pseudo-dialog to store information after the simple dialog
* @return symbol for wizard sequencer (always `next)
*/
symbol SimpleDialogFinish () {
if (NtpClient::selected_record["address"]:"" != "")
NtpClient::storeSyncRecord ();
return `next;
}
/**
* Pseudo-dialog to store settings to main structure
* @return symbol for wizard sequencer
*/
define symbol StoreRecord () ``{
sync_record_modified = true;
NtpClient::storeSyncRecord ();
return `next;
}
/**
* Select the type of configuration - simple vs. complex
* @return symbol for ws `simple or `complex
*/
define symbol SelectConfigType () ``{
if (NtpClient::PolicyIsNonstatic ())
{
y2milestone ("Netconfig nonstatic configuration");
return `complex;
}
list<map> peers = NtpClient::getSyncRecords ();
list<map> servers = filter (map m, peers, ``(m["type"]:"" == "server"));
list<map> clocks = filter (map m, peers, ``(m["type"]:"" == "__clock"));
boolean random_pool_servers_enabled_only = (
// number of listed servers is the same as the needed servers for random_pool_servers function
(size (servers) == size (NtpClient::random_pool_servers))
// enabled means that all of needed servers are listed
&& NtpClient::IsRandomServersServiceEnabled()
);
if (size (peers) != size (servers) + size (clocks))
{
y2milestone ("Something else than server and clock present");
return `complex;
}
if (random_pool_servers_enabled_only && size (clocks) <= 1)
{
y2milestone("Simple settings with random_pool_servers");
return `simple;
}
if (size (servers) > 1 || size (clocks) > 1)
{
y2milestone ("More than one server or more than one clock present");
return `complex;
}
string clock_addr = clocks[0, "address"]:"";
if ("127.127.1.0" != clock_addr && "" != clock_addr)
{
y2milestone ("Non-standard clock present");
return `complex;
}
y2milestone ("Going simple dialog");
return `simple;
}
/* EOF */
}
ACC SHELL 2018