projects/guix·blob python-team · refs

81 lines · 3.1 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2018 Mathieu Othacehe <[email protected]>
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
19(define-module (gnu installer newt timezone)
20 #:use-module (gnu installer steps)
21 #:use-module (gnu installer timezone)
22 #:use-module (gnu installer newt page)
23 #:use-module (guix i18n)
24 #:use-module (srfi srfi-1)
25 #:use-module (srfi srfi-26)
26 #:use-module (srfi srfi-34)
27 #:use-module (srfi srfi-35)
28 #:use-module (ice-9 match)
29 #:use-module (ice-9 receive)
30 #:use-module (newt)
31 #:export (run-timezone-page))
32
33;; Information textbox width.
34(define info-textbox-width (make-parameter 40))
35
36(define (fill-timezones listbox timezones)
37 "Fill the given LISTBOX with TIMEZONES. Return an association list
38correlating listbox keys with timezones."
39 (map (lambda (timezone)
40 (let ((key (append-entry-to-listbox listbox timezone)))
41 (cons key timezone)))
42 timezones))
43
44(define (run-timezone-page zonetab)
45 "Run a page displaying available timezones, grouped by regions. The user is
46invited to select a timezone. The selected timezone, under Posix format is
47returned."
48 (define (all-but-last list)
49 (reverse (cdr (reverse list))))
50
51 (define (run-page timezone-tree)
52 (define (loop path)
53 ;; XXX: Translation of time zones isn't perfect here because the
54 ;; "iso_3166-1" domain contains translation for "territories" (like
55 ;; "Antarctic") but not for continents (like "Africa").
56 (let ((timezones (locate-children timezone-tree path)))
57 (run-listbox-selection-page
58 #:title (G_ "Timezone")
59 #:info-text (G_ "Please select a timezone.")
60 #:listbox-items timezones
61 #:listbox-item->text (cut gettext <> "iso_3166-1")
62 #:button-text (if (null? path)
63 (G_ "Exit")
64 (G_ "Back"))
65 #:button-callback-procedure
66 (if (null? path)
67 (lambda _
68 (abort-to-prompt 'installer-step 'abort))
69 (lambda _
70 (loop (all-but-last path))))
71 #:listbox-callback-procedure
72 (lambda (timezone)
73 (let* ((timezone* (append path (list timezone)))
74 (tz (timezone->posix-tz timezone*)))
75 (if (timezone-has-child? timezone-tree timezone*)
76 (loop timezone*)
77 tz))))))
78 (loop '()))
79
80 (let ((timezone-tree (zonetab->timezone-tree zonetab)))
81 (run-page timezone-tree)))