timezone.scm 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (gnu installer newt timezone)
  19. #:use-module (gnu installer steps)
  20. #:use-module (gnu installer timezone)
  21. #:use-module (gnu installer newt page)
  22. #:use-module (guix i18n)
  23. #:use-module (srfi srfi-1)
  24. #:use-module (srfi srfi-26)
  25. #:use-module (srfi srfi-34)
  26. #:use-module (srfi srfi-35)
  27. #:use-module (ice-9 match)
  28. #:use-module (ice-9 receive)
  29. #:use-module (newt)
  30. #:export (run-timezone-page))
  31. ;; Information textbox width.
  32. (define info-textbox-width (make-parameter 40))
  33. (define (fill-timezones listbox timezones)
  34. "Fill the given LISTBOX with TIMEZONES. Return an association list
  35. correlating listbox keys with timezones."
  36. (map (lambda (timezone)
  37. (let ((key (append-entry-to-listbox listbox timezone)))
  38. (cons key timezone)))
  39. timezones))
  40. (define (run-timezone-page zonetab)
  41. "Run a page displaying available timezones, grouped by regions. The user is
  42. invited to select a timezone. The selected timezone, under Posix format is
  43. returned."
  44. (define (all-but-last list)
  45. (reverse (cdr (reverse list))))
  46. (define (run-page timezone-tree)
  47. (define (loop path)
  48. ;; XXX: Translation of time zones isn't perfect here because the
  49. ;; "iso_3166-1" domain contains translation for "territories" (like
  50. ;; "Antarctic") but not for continents (like "Africa").
  51. (let ((timezones (locate-children timezone-tree path)))
  52. (run-listbox-selection-page
  53. #:title (G_ "Timezone")
  54. #:info-text (G_ "Please select a timezone.")
  55. #:listbox-items timezones
  56. #:listbox-item->text (cut gettext <> "iso_3166-1")
  57. #:button-text (if (null? path)
  58. (G_ "Exit")
  59. (G_ "Back"))
  60. #:button-callback-procedure
  61. (if (null? path)
  62. (lambda _
  63. (abort-to-prompt 'installer-step 'abort))
  64. (lambda _
  65. (loop (all-but-last path))))
  66. #:listbox-callback-procedure
  67. (lambda (timezone)
  68. (let* ((timezone* (append path (list timezone)))
  69. (tz (timezone->posix-tz timezone*)))
  70. (if (timezone-has-child? timezone-tree timezone*)
  71. (loop timezone*)
  72. tz))))))
  73. (loop '()))
  74. (let ((timezone-tree (zonetab->timezone-tree zonetab)))
  75. (run-page timezone-tree)))