timezone.scm 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. (raise
  64. (condition
  65. (&installer-step-abort))))
  66. (lambda _
  67. (loop (all-but-last path))))
  68. #:listbox-callback-procedure
  69. (lambda (timezone)
  70. (let* ((timezone* (append path (list timezone)))
  71. (tz (timezone->posix-tz timezone*)))
  72. (if (timezone-has-child? timezone-tree timezone*)
  73. (loop timezone*)
  74. tz))))))
  75. (loop '()))
  76. (let ((timezone-tree (zonetab->timezone-tree zonetab)))
  77. (run-page timezone-tree)))