timezone.scm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. (let ((timezones (locate-children timezone-tree path)))
  49. (run-listbox-selection-page
  50. #:title (G_ "Timezone")
  51. #:info-text (G_ "Please select a timezone.")
  52. #:listbox-items timezones
  53. #:listbox-item->text identity
  54. #:button-text (if (null? path)
  55. (G_ "Exit")
  56. (G_ "Back"))
  57. #:button-callback-procedure
  58. (if (null? path)
  59. (lambda _
  60. (raise
  61. (condition
  62. (&installer-step-abort))))
  63. (lambda _
  64. (loop (all-but-last path))))
  65. #:listbox-callback-procedure
  66. (lambda (timezone)
  67. (let* ((timezone* (append path (list timezone)))
  68. (tz (timezone->posix-tz timezone*)))
  69. (if (timezone-has-child? timezone-tree timezone*)
  70. (loop timezone*)
  71. tz))))))
  72. (loop '()))
  73. (let ((timezone-tree (zonetab->timezone-tree zonetab)))
  74. (run-page timezone-tree)))