1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (gnu installer newt user)
20 #:use-module (gnu installer user)
21 #:use-module (gnu installer newt page)
22 #:use-module (gnu installer newt utils)
23 #:use-module (guix i18n)
25 #:use-module (ice-9 match)
26 #:use-module (ice-9 receive)
27 #:use-module (srfi srfi-1)
28 #:use-module (srfi srfi-26)
29 #:export (run-user-page))
31 (define (run-user-add-page)
32 (define (pad-label label)
33 (string-pad-right label 20))
36 (make-label -1 -1 (pad-label (G_ "Name"))))
38 (make-label -1 -1 (pad-label (G_ "Home directory"))))
40 (entry-name (make-entry -1 -1 entry-width))
41 (entry-home-directory (make-entry -1 -1 entry-width))
42 (entry-grid (make-grid 2 2))
43 (button-grid (make-grid 1 1))
44 (ok-button (make-button -1 -1 (G_ "Ok")))
45 (grid (make-grid 1 2))
46 (title (G_ "User creation"))
48 (cut set-grid-field entry-grid <> <> GRID-ELEMENT-COMPONENT <>))
51 (set-entry-grid-field 0 0 label-name)
52 (set-entry-grid-field 1 0 entry-name)
53 (set-entry-grid-field 0 1 label-home-directory)
54 (set-entry-grid-field 1 1 entry-home-directory)
56 (set-grid-field button-grid 0 0 GRID-ELEMENT-COMPONENT ok-button)
58 (add-component-callback
61 (set-entry-text entry-home-directory
62 (string-append "/home/" (entry-value entry-name)))))
64 (add-components-to-form form
65 label-name label-home-directory
66 entry-name entry-home-directory
69 (make-wrapped-grid-window (vertically-stacked-grid
70 GRID-ELEMENT-SUBGRID entry-grid
71 GRID-ELEMENT-SUBGRID button-grid)
75 (run-error-page (G_ "Empty inputs are not allowed.")
76 (G_ "Empty input")))))
77 (receive (exit-reason argument)
82 (when (eq? exit-reason 'exit-component)
84 ((components=? argument ok-button)
85 (let ((name (entry-value entry-name))
86 (home-directory (entry-value entry-home-directory)))
87 (if (or (string=? name "")
88 (string=? home-directory ""))
94 (home-directory home-directory))))))))
96 (destroy-form-and-pop form)))))))
98 (define (run-user-page)
100 (let* ((listbox (make-listbox
102 (logior FLAG-SCROLL FLAG-BORDER)))
104 (make-reflowed-textbox
106 (G_ "Please add at least one user to system\
107 using the 'Add' button.")
108 40 #:flags FLAG-BORDER))
109 (add-button (make-compact-button -1 -1 (G_ "Add")))
110 (del-button (make-compact-button -1 -1 (G_ "Delete")))
113 vertically-stacked-grid
114 GRID-ELEMENT-COMPONENT add-button
115 `(,@(if (null? users)
117 (list GRID-ELEMENT-COMPONENT del-button)))))
118 (ok-button (make-button -1 -1 (G_ "Ok")))
119 (exit-button (make-button -1 -1 (G_ "Exit")))
120 (title "User creation")
122 (vertically-stacked-grid
123 GRID-ELEMENT-COMPONENT info-textbox
124 GRID-ELEMENT-SUBGRID (horizontal-stacked-grid
125 GRID-ELEMENT-COMPONENT listbox
126 GRID-ELEMENT-SUBGRID listbox-button-grid)
127 GRID-ELEMENT-SUBGRID (horizontal-stacked-grid
128 GRID-ELEMENT-COMPONENT ok-button
129 GRID-ELEMENT-COMPONENT exit-button)))
130 (sorted-users (sort users (lambda (a b)
131 (string<= (user-name a)
136 `((key . ,(append-entry-to-listbox listbox
143 (add-form-to-grid grid form #t)
144 (make-wrapped-grid-window grid title)
146 (set-current-component form add-button)
147 (set-current-component form ok-button))
149 (receive (exit-reason argument)
154 (when (eq? exit-reason 'exit-component)
156 ((components=? argument add-button)
157 (run (cons (run-user-add-page) users)))
158 ((components=? argument del-button)
159 (let* ((current-user-key (current-listbox-entry listbox))
161 (map (cut assoc-ref <> 'user)
162 (remove (lambda (element)
163 (equal? (assoc-ref element 'key)
167 ((components=? argument ok-button)
169 (run-error-page (G_ "Please create at least one user.")
174 (destroy-form-and-pop form))))))