Module: Yast::TimezoneDialogsInclude

Defined in:
../../src/include/timezone/dialogs.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) initialize_timezone_dialogs(include_target)



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File '../../src/include/timezone/dialogs.rb', line 37

def initialize_timezone_dialogs(include_target)
  Yast.import "UI"
  textdomain "country"

  Yast.import "Arch"
  Yast.import "Directory"
  Yast.import "GetInstArgs"
  Yast.import "Label"
  Yast.import "Language"
  Yast.import "Mode"
  Yast.import "NetworkService"
  Yast.import "Package"
  Yast.import "Popup"
  Yast.import "ProductFeatures"
  Yast.import "Service"
  Yast.import "Stage"
  Yast.import "Timezone"
  Yast.import "Wizard"

  @hwclock_s_initial = :none

  # if system clock is configured to sync with NTP
  @ntp_used = false

  # ntp server configured to sync with
  @ntp_server = ""

  # if packages for NTP configuration are installed
  @ntp_installed = false

  # when checking for NTP status for first time, check the service status
  @ntp_first_time = true
end

- (Object) ntp_call(acall, args)

handles the complication that the package yast2-ntp-client may not be present



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File '../../src/include/timezone/dialogs.rb', line 104

def ntp_call(acall, args)
  args = deep_copy(args)
  if !@ntp_installed
    # replace "replace_point" by the widgets
    if acall == "ui_init"
      return false # deselect the RB
    # the help text
    elsif acall == "ui_help_text"
      return "" # or say "will install"? TODO recompute help text
    # save settings, return false if dialog should not exit
    elsif acall == "ui_try_save"
      return true # success, exit loop
    # Service::Enabled. FIXME too smart?
    elsif acall == "GetNTPEnabled"
      return false
    end

    # 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")
  end

  ret = WFM.CallFunction("ntp-client_proposal", [acall, args])
  deep_copy(ret)
end

- (Object) SetTimeDialog

Dialog for setinge system date and time

Returns:

  • true if user changed the time (dialog accepted)



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
# File '../../src/include/timezone/dialogs.rb', line 136

def SetTimeDialog
  ntp_help_text = Convert.to_string(ntp_call("ui_help_text", {}))
  # help text for set time dialog
  htext = Ops.add(
    _(
      "<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>"),
    ntp_help_text
  )

  dt_widgets = false

  hour = ""
  minute = ""
  second = ""
  day = ""
  month = ""
  year = ""

  # check current time and show it in the time widgets
  show_current_time = lambda do
    val = Timezone.GetDateTimeMap
    hour = Ops.get_string(val, "hour", "")
    minute = Ops.get_string(val, "minute", "")
    second = Ops.get_string(val, "second", "")
    day = Ops.get_string(val, "day", "")
    month = Ops.get_string(val, "month", "")
    year = Ops.get_string(val, "year", "")

    if dt_widgets
      UI.ChangeWidget(
        Id(:date),
        :Value,
        Builtins.sformat("%1-%2-%3", year, month, day)
      )
      UI.ChangeWidget(
        Id(:time),
        :Value,
        Builtins.sformat("%1:%2:%3", hour, minute, second)
      )
    else
      UI.ChangeWidget(Id(:hour), :Value, hour)
      UI.ChangeWidget(Id(:minute), :Value, minute)
      UI.ChangeWidget(Id(:second), :Value, second)
      UI.ChangeWidget(Id(:day), :Value, day)
      UI.ChangeWidget(Id(:month), :Value, month)
      UI.ChangeWidget(Id(:year), :Value, year)
    end

    nil
  end

  enable_disable_time_widgets = lambda do |enable|
    UI.ChangeWidget(Id(:change_now), :Enabled, enable)

    enable = enable &&
      Convert.to_boolean(UI.QueryWidget(Id(:change_now), :Value))

    if dt_widgets
      UI.ChangeWidget(Id(:date), :Enabled, enable)
      UI.ChangeWidget(Id(:time), :Enabled, enable)
    else
      UI.ChangeWidget(Id(:hour), :Enabled, enable)
      UI.ChangeWidget(Id(:minute), :Enabled, enable)
      UI.ChangeWidget(Id(:second), :Enabled, enable)
      UI.ChangeWidget(Id(:day), :Enabled, enable)
      UI.ChangeWidget(Id(:month), :Enabled, enable)
      UI.ChangeWidget(Id(:year), :Enabled, enable)
    end

    nil
  end

  dateterm = VBox(
    HBox(
      HSpacing(1),
      # label text, do not change "DD-MM-YYYY"
      Left(Label(_("Current Date in DD-MM-YYYY Format")))
    ),
    HBox(
      HSpacing(10),
      InputField(Id(:day), Opt(:shrinkable), ""),
      HSpacing(),
      InputField(Id(:month), Opt(:shrinkable), ""),
      HSpacing(),
      InputField(Id(:year), Opt(:shrinkable), ""),
      HSpacing(30)
    )
  )
  timeterm = VBox(
    HBox(
      HSpacing(1),
      # label text, do not change "HH:MM:SS"
      Left(Label(_("Current Time in HH:MM:SS Format")))
    ),
    HBox(
      HSpacing(10),
      InputField(Id(:hour), Opt(:shrinkable), ""),
      HSpacing(),
      InputField(Id(:minute), Opt(:shrinkable), ""),
      HSpacing(),
      InputField(Id(:second), Opt(:shrinkable), ""),
      HSpacing(30)
    )
  )
  if UI.HasSpecialWidget(:DateField) && UI.HasSpecialWidget(:TimeField)
    dateterm = HBox(
      # label text
      DateField(Id(:date), _("Current Date"), "")
    )
    timeterm = HBox(
      # label text
      TimeField(Id(:time), _("Current Time"), "")
    )
    dt_widgets = true
  end




  cont = HBox(
    HWeight(1, VBox()),
    HWeight(
      6,
      RadioButtonGroup(
        Id(:rb),
        VBox(
          # radio button label (= how to setup time)
          Left(RadioButton(Id(:manual), Opt(:notify), _("Manually"))),
          VSpacing(0.5),
          HBox(
            HSpacing(3),
            VBox(
              Left(timeterm),
              VSpacing(),
              Left(dateterm),
              VSpacing(),
              HBox(
                HSpacing(0.5),
                Left(
                  # check box label
                  CheckBox(
                    Id(:change_now),
                    Opt(:notify),
                    _("Change the Time Now"),
                    true
                  )
                )
              )
            )
          ),
          VSpacing(1),
          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.SetDesktopTitleAndIcon("timezone") if Mode.normal

  show_current_time.call

  ntp_rb = false
  ntp_rb = Convert.to_boolean(
    ntp_call(
      "ui_init",
      {
        "replace_point" => Id(:rp),
        "country"       => Language.GetLanguageCountry,
        "first_time"    => @ntp_first_time
      }
    )
  )
  @ntp_first_time = false
  UI.ChangeWidget(Id(:rb), :CurrentButton, ntp_rb ? :ntp : :manual)

  if !dt_widgets
    Builtins.foreach([:hour, :minute, :second, :day, :month, :year]) do |widget|
      UI.ChangeWidget(Id(widget), :ValidChars, "0123456789")
      UI.ChangeWidget(Id(widget), :InputMaxLength, widget == :year ? 4 : 2)
    end
  end

  ret = nil
  begin
    ntp_call("ui_enable_disable_widgets", { "enabled" => ntp_rb })
    enable_disable_time_widgets.call(!ntp_rb)

    ret = UI.UserInput
    Builtins.y2debug("UserInput ret:%1", ret)

    ntp_handled = Convert.to_symbol(ntp_call("ui_handle", { "ui" => ret }))
    ret = ntp_handled if ntp_handled != nil
    show_current_time.call if ret == :redraw

    if ret == :ntp || ret == :manual
      ntp_rb = ret == :ntp
      # need to install it first?
      if ntp_rb && !Stage.initial && !@ntp_installed
        @ntp_installed = Package.InstallAll(["yast2-ntp-client", "ntp"])
        # succeeded? create UI, otherwise revert the click
        if !@ntp_installed
          ntp_rb = false
          UI.ChangeWidget(Id(:rb), :CurrentButton, :manual)
        else
          # ignore retval, user clicked to use ntp
          ntp_call(
            "ui_init",
            {
              "replace_point" => Id(:rp),
              "country"       => Language.GetLanguageCountry,
              "first_time"    => false
            }
          )
        end
      end
    end

    if ret == :accept && ntp_rb
      # before the sync, save the time zone (bnc#467318)
      Timezone.Set(
        Timezone.timezone,
        Stage.initial && !Mode.live_installation
      )
      # true: go on, exit; false: loop on
      ntp_handled2 = Convert.to_boolean(ntp_call("ui_try_save", {}))
      if !ntp_handled2
        ret = :retry
      else
        # `ntp_address is constructed by ntp-client_proposal.ycp... :-(
        @ntp_server = Convert.to_string(
          UI.QueryWidget(Id(:ntp_address), :Value)
        )
        # after sync, show real time in the widget
        Timezone.diff = 0
      end
    end
    if ret == :accept && !ntp_rb &&
        UI.QueryWidget(Id(:change_now), :Value) == true
      if dt_widgets
        datel = Builtins.splitstring(
          Convert.to_string(UI.QueryWidget(Id(:date), :Value)),
          "-"
        )
        year = Ops.get_string(datel, 0, "")
        month = Ops.get_string(datel, 1, "")
        day = Ops.get_string(datel, 2, "")
        timel = Builtins.splitstring(
          Convert.to_string(UI.QueryWidget(Id(:time), :Value)),
          ":"
        )
        hour = Ops.get_string(timel, 0, "")
        minute = Ops.get_string(timel, 1, "")
        second = Ops.get_string(timel, 2, "")
      else
        hour = Convert.to_string(UI.QueryWidget(Id(:hour), :Value))
        minute = Convert.to_string(UI.QueryWidget(Id(:minute), :Value))
        second = Convert.to_string(UI.QueryWidget(Id(:second), :Value))
        day = Convert.to_string(UI.QueryWidget(Id(:day), :Value))
        month = Convert.to_string(UI.QueryWidget(Id(:month), :Value))
        year = Convert.to_string(UI.QueryWidget(Id(:year), :Value))
      end
      if !Timezone.CheckTime(hour, minute, second)
        tmp = Builtins.sformat("%1:%2:%3", hour, minute, second)
        # popup text, %1 is entered value
        tmp = Builtins.sformat(
          _("Invalid time (HH:MM:SS) %1.\nEnter the correct time.\n"),
          tmp
        )
        Popup.Error(tmp)
        ret = :retry
      elsif !Timezone.CheckDate(day, month, year)
        tmp = Builtins.sformat("%1-%2-%3", day, month, year)
        # popup text, %1 is entered value
        tmp = Builtins.sformat(
          _("Invalid date (DD-MM-YYYY) %1.\nEnter the correct date.\n"),
          tmp
        )
        Popup.Error(tmp)
        ret = :retry
      else
        # in case of local time, we need to call mkinitrd (after setting timezone)
        if Timezone.hwclock == "--localtime" && !Stage.initial
          Timezone.Set(Timezone.timezone, true)
          Timezone.call_mkinitrd = true
        end

        Timezone.SetTime(year, month, day, hour, minute, second)
      end
    end
  end until ret == :accept || ret == :cancel

  if ret == :accept
    # new system time from ntpdate must be saved to hw clock
    Timezone.SystemTime2HWClock if ntp_rb
    # remember ui
    ntp_call("SetUseNTP", { "ntp_used" => ntp_rb })
    @ntp_used = ntp_rb
  end

  Wizard.CloseDialog
  ret == :accept
end

- (Object) SetTimezone(hwclock, timezone, really, changed_time)

helper function for seting the time related stuff in module and possibly adapting current time according to it



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File '../../src/include/timezone/dialogs.rb', line 73

def SetTimezone(hwclock, timezone, really, changed_time)
  Builtins.y2milestone(
    "SetTimezone hw %1, tz %2 really %3 tchanged %4 initial:%5",
    hwclock,
    timezone,
    really,
    changed_time,
    @hwclock_s_initial
  )

  # simulate the time change
  if !really && hwclock != @hwclock_s_initial
    Timezone.diff = hwclock == :hwclock_utc ? 1 : -1
  else
    Timezone.diff = 0
  end

  Builtins.y2milestone("SetTimezone diff %1", Timezone.diff)

  Timezone.hwclock = hwclock == :hwclock_utc ? "-u" : "--localtime"
  Timezone.Set(timezone, really)

  # Redisplay date/time.
  #
  UI.ChangeWidget(Id(:date), :Value, Timezone.GetDateTime(really, false))

  nil
end

- (Object) TimezoneDialog(args)

Main dialog for time zone configuration

Parameters:

  • args (Hash)

    arguments passwd from the called (back/next buttons etc.)



458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
# File '../../src/include/timezone/dialogs.rb', line 458

def TimezoneDialog(args)
  args = deep_copy(args)
  first_run = Ops.get_string(args, "first_run", "no") == "yes"
  # inst_timezone as a part of installation sequence
  if first_run && Stage.initial
    Timezone.hwclock = "--localtime" if Timezone.ProposeLocaltime
  end


  # get current timezone and clock setting
  changed_time = false
  timezone = Timezone.timezone
  timezone_old = timezone
  timezone_initial = timezone
  hwclock = Timezone.hwclock

  Builtins.y2milestone("timezone_old %1", timezone_old)

  timezone = Timezone.UpdateTimezone(timezone)

  # Initially set the current timezone to establish a consistent state.
  sel = Timezone.Set(timezone, Stage.initial && !Mode.live_installation)

  utc_only = Timezone.utc_only
  Builtins.y2milestone("utc_only %1", utc_only)

  Timezone.PushVal


  settime = Empty()

  # "On a mainframe it is impossible for the user to change the hardware clock.
  # So you can only specify the timezone." (ihno)
  if !Arch.s390 && !Mode.config
    # button text
    settime = PushButton(Id(:settime), _("Cha&nge..."))
  end

  textmode = Language.GetTextMode

  timezone_selector = false

  zonemap = Timezone.get_zonemap

  # map of zones conversions
  yast2zonetab = deep_copy(Timezone.yast2zonetab)

  # map of timezone -> translated label to be passed to TimezoneSelector
  zones = {}

  # cache the zonemap with the order sorted according to current locale
  sorted_zonemap = {}

  Builtins.foreach(zonemap) do |region|
    Builtins.foreach(Ops.get_map(region, "entries", {})) do |key, name|
      if !Builtins.haskey(yast2zonetab, key)
        Ops.set(zones, Ops.get(yast2zonetab, key, key), name)
      end
    end
  end

  @ntp_installed = Stage.initial || Package.Installed("yast2-ntp-client")


  # read NTP status
  if first_run && NetworkService.isNetworkRunning && !Mode.live_installation &&
      !GetInstArgs.going_back &&
      ProductFeatures.GetBooleanFeature("globals", "default_ntp_setup") == true
    # true by default (fate#303520)
    @ntp_used = true
    # configure NTP client
    Builtins.srandom
    @ntp_server = Builtins.sformat(
      "%1.opensuse.pool.ntp.org",
      Builtins.random(4)
    )
    argmap = {
      "server"       => @ntp_server,
      # FIXME ntp-client_proposal doesn't understand 'servers' yet
      "servers"      => [
        "0.opensuse.pool.ntp.org",
        "1.opensuse.pool.ntp.org",
        "2.opensuse.pool.ntp.org",
        "3.opensuse.pool.ntp.org"
      ],
      "ntpdate_only" => true
    }
    rv = Convert.to_symbol(ntp_call("Write", argmap))
    if rv == :invalid_hostname
      Builtins.y2warning("Invalid NTP server hostname %1", @ntp_server)
      @ntp_used = false
    else
      Timezone.SystemTime2HWClock
      Builtins.y2milestone("proposing NTP server %1", @ntp_server)
      ntp_call("SetUseNTP", { "ntp_used" => @ntp_used })
    end
  elsif Stage.initial
    # from installation summaru
    @ntp_used = Timezone.ntp_used
  elsif @ntp_installed
    @ntp_used = Convert.to_boolean(ntp_call("GetNTPEnabled", {}))
    @ntp_used = @ntp_used == true # nil->false, just in case of parse error
  end

  time_frame_label =
    # frame label
    @ntp_used ?
      _("Date and Time (NTP is configured)") :
      # frame label
      _("Date and Time")

  # Read system date and time.
  date = Timezone.GetDateTime(true, false)

  timezoneterm = HBox()

  if UI.HasSpecialWidget(:TimezoneSelector) == true
    timezone_selector = true
    worldmap = Ops.add(Directory.themedir, "/current/worldmap/worldmap.jpg")
    timezoneterm = VBox(
      TimezoneSelector(Id(:timezonemap), Opt(:notify), worldmap, zones),
      HBox(
        HWeight(
          1,
          ComboBox(
            Id(:region),
            Opt(:notify),
            # label text
            _("&Region"),
            Timezone.Region
          )
        ),
        HSpacing(),
        HWeight(
          1,
          ReplacePoint(
            Id(:tzsel),
            # title for combo box 'timezone'
            ComboBox(Id(:timezone), Opt(:notify), _("Time &Zone"))
          )
        )
      )
    )
  else
    timezoneterm = HBox(
      SelectionBox(
        Id(:region),
        Opt(:notify, :immediate),
        # label text
        _("&Region"),
        Timezone.Region
      ),
      HSpacing(),
      ReplacePoint(
        Id(:tzsel),
        # title for selection box 'timezone'
        SelectionBox(Id(:timezone), Opt(:notify), _("Time &Zone"))
      )
    )
  end
  hwclock_term = VBox(
    CheckBox(
      Id(:hwclock),
      Opt(:hstretch, :notify),
      # check box label
      _("&Hardware Clock Set to UTC"),
      hwclock == "-u"
    ),
    textmode ? Label("") : Empty()
  )

  contents = MarginBox(
    term(:leftMargin, 2),
    term(:rightMargin, 2),
    term(:topMargin, 0),
    term(:bottomMargin, 0.2),
    VBox(
      timezoneterm,
      VSpacing(0.2),
      VSquash(
        HBox(
          HWeight(1, utc_only ? Empty() : hwclock_term),
          HSpacing(1),
          # frame label
          HWeight(
            1,
            Frame(
              Id(:time_fr),
              time_frame_label,
              MarginBox(
                term(:leftMargin, 1.2),
                term(:rightMargin, 1),
                term(:topMargin, 0),
                term(:bottomMargin, 0),
                textmode ?
                  VBox(
                    Label(Id(:date), Opt(:outputField, :hstretch), date),
                    Right(settime)
                  ) :
                  HBox(Label(Id(:date), date), HStretch(), Right(settime))
              )
            )
          )
        )
      )
    )
  )
  # cache for lists with timezone items
  timezones_for_region = {}
  get_timezones_for_region = lambda do |region, zone|
    if !Builtins.haskey(sorted_zonemap, region)
      reg_list = Builtins.maplist(
        Ops.get_map(zonemap, [region, "entries"], {})
      ) { |key, name| [name, key] }

      reg_list = Builtins.sort(
        Convert.convert(reg_list, :from => "list", :to => "list <list>")
      ) do |a, b|
        # bnc#385172: must use < instead of <=, the following means:
        # strcoll(x) <= strcoll(y) && strcoll(x) != strcoll(y)
        lsorted = Builtins.lsort(
          [Ops.get_string(a, 0, ""), Ops.get_string(b, 0, "")]
        )
        lsorted_r = Builtins.lsort(
          [Ops.get_string(b, 0, ""), Ops.get_string(a, 0, "")]
        )
        Ops.get_string(lsorted, 0, "") == Ops.get_string(a, 0, "") &&
          lsorted == lsorted_r
      end
      Ops.set(sorted_zonemap, region, reg_list)
    end
    Builtins.maplist(Ops.get_list(sorted_zonemap, region, [])) do |entry|
      Item(
        Id(Ops.get_string(entry, 1, "")),
        Ops.get_string(entry, 0, ""),
        Ops.get_string(entry, 1, "") == zone
      )
    end
  end
  # region was seleced: show the correct list of timezones
  show_selected_region = lambda do |sel2, zone|
    if timezone_selector
      UI.ChangeWidget(Id(:region), :Value, sel2)
    else
      UI.ChangeWidget(Id(:region), :CurrentItem, sel2)
    end

    UI.ReplaceWidget(
      Id(:tzsel),
      timezone_selector ?
        ComboBox(
          Id(:timezone),
          Opt(:notify),
          # label text
          _("Time &Zone"),
          get_timezones_for_region.call(sel2, zone)
        ) :
        SelectionBox(
          Id(:timezone),
          Opt(:notify),
          # label text
          _("Time &Zone"),
          get_timezones_for_region.call(sel2, zone)
        )
    )

    nil
  end
  # which region is selected?
  selected_region = lambda do
    timezone_selector ?
      Convert.to_integer(UI.QueryWidget(Id(:region), :Value)) :
      Convert.to_integer(UI.QueryWidget(Id(:region), :CurrentItem))
  end
  # which timezone is selected?
  selected_timezone = lambda do
    timezone_selector ?
      Convert.to_string(UI.QueryWidget(Id(:timezone), :Value)) :
      Convert.to_string(UI.QueryWidget(Id(:timezone), :CurrentItem))
  end

  # for given timezone (selected in map), find out to which region it belongs
  get_region_for_timezone = lambda do |current, zone|
    # first check if it is not in current region
    if Builtins.haskey(Ops.get_map(zonemap, [current, "entries"], {}), zone)
      return current
    end
    reg = 0
    Builtins.foreach(zonemap) do |region|
      if Builtins.haskey(Ops.get_map(region, "entries", {}), zone)
        raise Break
      end
      reg = Ops.add(reg, 1)
    end
    reg
  end

  # help for timezone screen
  help_text = _("\n<p><b><big>Time Zone and Clock Settings</big></b></p>") +
    # help for timezone screen
    _(
      "<p>\n" +
        "To select the time zone to use in your system, first select the <b>Region</b>.\n" +
        "In <b>Time Zone</b>, then select the appropriate time zone, country, or \n" +
        "region from those available.\n" +
        "</p>\n"
    )

  if !utc_only
    # help for time calculation basis:
    # hardware clock references local time or UTC?
    help_text = Ops.add(
      help_text,
      _(
        "<p>\n" +
          "Specify whether your machine is set to local time or UTC in <b>Hardware Clock Set To</b>.\n" +
          "Most PCs that also have other operating systems installed (such as Microsoft\n" +
          "Windows) use local time.\n" +
          "Machines that have only Linux installed are usually\n" +
          "set to Universal Time Coordinated (UTC).\n" +
          "If the hardware clock is set to UTC, your system can switch from standard time\n" +
          "to daylight saving time and back automatically.\n" +
          "</p>\n"
      )
    )

    # help text: extra note about localtim
    help_text = Ops.add(
      help_text,
      _(
        "<p>\n" +
          "Note: The internal system clock as used by the Linux kernel must\n" +
          "always be in UTC, because this is the reference for the correct localtime\n" +
          "in user space. If you are choosing localtime for CMOS clock,\n" +
          "check the user manual for background information about side effects.\n" +
          "</p>"
      )
    )
  end


  if !Arch.s390 && !Mode.config
    # general help trailer
    help_text = Ops.add(
      help_text,
      _(
        "<p>\n" +
          "If the current time is not correct, use <b>Change</b> to adjust it.\n" +
          "</p>"
      )
    )
  end

  # Screen title for timezone screen
  Wizard.SetContents(
    _("Clock and Time Zone"),
    contents,
    help_text,
    Ops.get_boolean(args, "enable_back", true),
    Ops.get_boolean(args, "enable_next", true)
  )

  if Stage.initial || Stage.firstboot
    Wizard.SetTitleIcon("yast-timezone")
  else
    Wizard.SetDesktopTitleAndIcon("timezone")
  end

  hwclock_s = hwclock == "-u" ? :hwclock_utc : :hwclock_localtime
  hwclock_s_old = hwclock_s
  @hwclock_s_initial = hwclock_s

  show_selected_region.call(sel, timezone)
  if timezone_selector
    UI.ChangeWidget(
      Id(:timezonemap),
      :CurrentItem,
      Ops.get(yast2zonetab, timezone, timezone)
    )
  end

  UI.SetFocus(Id(:region))

  ret = nil
  begin
    ret = Convert.to_symbol(Wizard.UserInput)

    Builtins.y2debug("ret %1", ret)

    ret = :next if ret == :ok

    break if !Mode.config && ret == :abort && Popup.ConfirmAbort(:painless)
    if ret == :region
      num = selected_region.call
      next if num == sel
      show_selected_region.call(num, "")
      tz = selected_timezone.call
      if tz != timezone
        timezone = tz
        changed_time = true if timezone != timezone_old
        timezone_old = timezone
        SetTimezone(hwclock_s, timezone, false, changed_time)
      end
      if timezone_selector
        UI.ChangeWidget(Id(:timezonemap), :CurrentItem, timezone)
      end
      sel = num
    elsif ret == :settime
      # timezone was not adapted in ncurses (bnc#617861)
      if textmode
        tz = selected_timezone.call
        if tz != timezone
          timezone = tz
          changed_time = true if timezone != timezone_old
          timezone_old = timezone
          SetTimezone(hwclock_s, timezone, false, changed_time)
        end
      end
      if SetTimeDialog()
        Timezone.diff = 0
        UI.ChangeWidget(
          Id(:date),
          :Value,
          Timezone.GetDateTime(false, false)
        )
        changed_time = true
        # adapt frame label, NTP status may be changed
        time_frame_label =
          # frame label
          @ntp_used ?
            _("Date and Time (NTP is configured)") :
            # frame label
            _("Date and Time")
        UI.ChangeWidget(Id(:time_fr), :Label, time_frame_label)
      end
    elsif ret == :next || ret == :timezone || ret == :timezonemap ||
        ret == :hwclock
      # Get current settings.
      # UTC vs. localtime, only if needed
      #
      hwclock_s = :hwclock_utc
      if !utc_only
        hwclock_s = Convert.to_boolean(UI.QueryWidget(Id(:hwclock), :Value)) ?
          :hwclock_utc :
          :hwclock_localtime

        if ret == :next && !Timezone.windows_partition &&
            hwclock_s == :hwclock_localtime
          # warning popup, in case local time is selected (bnc#732769)
          if !Popup.ContinueCancel(
              _(
                "\n" +
                  "You selected local time, but only Linux  seems to be installed on your system.\n" +
                  "In such case, it is strongly recommended to use UTC, and to click Cancel.\n" +
                  "\n" +
                  "If you want to keep local time, you must adjust the CMOS clock twice the year\n" +
                  "because of Day Light Saving switches. If you miss to adjust the clock, backups may fail,\n" +
                  "your mail system may drop mail messages, etc.\n" +
                  "\n" +
                  "If you use UTC, Linux will adjust the time automatically.\n" +
                  "\n" +
                  "Do you want to continue with your selection (local time)?"
              )
            )
            ret = :not_next
            next
          end
        end
      end
      if ret == :timezonemap
        timezone = Convert.to_string(
          UI.QueryWidget(Id(:timezonemap), :Value)
        )

        reg = get_region_for_timezone.call(sel, timezone)
        if reg == sel
          UI.ChangeWidget(Id(:timezone), :Value, timezone)
        else
          sel = reg
          show_selected_region.call(sel, timezone)
        end
      else
        timezone = selected_timezone.call
      end
      if ret == :timezone
        sel = selected_region.call
        if timezone_selector
          UI.ChangeWidget(
            Id(:timezonemap),
            :Value,
            Ops.get(yast2zonetab, timezone, timezone)
          )
        end
      end

      if timezone == nil || Builtins.size(timezone) == 0
        # popup text
        Popup.Error(_("Select a valid time zone."))
        ret = :again
        timezone = timezone_old
      end
      Builtins.y2milestone("timezone %1 ret %2", timezone, ret)

      if timezone != timezone_old || hwclock_s != hwclock_s_old ||
          ret == :next
        changed_time = true if timezone != timezone_old
        timezone_old = timezone
        hwclock_s_old = hwclock_s
        SetTimezone(hwclock_s, timezone, ret == :next, changed_time)
      end

      if ret == :next
        # User wants to keep his changes.
        # Set user_decision flag in timezone module.
        #
        Timezone.user_decision = true
        Timezone.user_hwclock = true
        Timezone.ntp_used = @ntp_used
        # See bnc#638185c5: refresh_initrd should be called if HWCLOCK is changed (--localtime <-> --utc) and/or
        # if --localtime is set and TIMEZONE will be changed.
        if hwclock_s != @hwclock_s_initial ||
            hwclock_s == :hwclock_localtime && timezone != timezone_initial
          Timezone.call_mkinitrd = true
        end

        if @ntp_used && @ntp_server != ""
          # save NTP client settings now
          ntp_call(
            "Write",
            { "server" => @ntp_server, "write_only" => true }
          )
        end
      end
    end
  end until ret == :next || ret == :back || ret == :cancel

  Timezone.PopVal if ret != :next
  ret
end