You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

81 lines
3.0 KiB

  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 ethernet)
  19. #:use-module (gnu installer connman)
  20. #:use-module (gnu installer steps)
  21. #:use-module (gnu installer newt utils)
  22. #:use-module (gnu installer newt page)
  23. #:use-module (guix i18n)
  24. #:use-module (ice-9 format)
  25. #:use-module (srfi srfi-34)
  26. #:use-module (srfi srfi-35)
  27. #:use-module (newt)
  28. #:export (run-ethernet-page))
  29. (define (ethernet-services)
  30. "Return all the connman services of ethernet type."
  31. (let ((services (connman-services)))
  32. (filter (lambda (service)
  33. (and (string=? (service-type service) "ethernet")
  34. (not (string-null? (service-name service)))))
  35. services)))
  36. (define (ethernet-service->text service)
  37. "Return a string describing the given ethernet SERVICE."
  38. (let* ((name (service-name service))
  39. (path (service-path service))
  40. (full-name (string-append name "-" path))
  41. (state (service-state service))
  42. (connected? (or (string=? state "online")
  43. (string=? state "ready"))))
  44. (format #f "~c ~a~%"
  45. (if connected? #\* #\ )
  46. full-name)))
  47. (define (connect-ethernet-service service)
  48. "Connect to the given ethernet SERVICE. Display a connecting page while the
  49. connection is pending."
  50. (let* ((service-name (service-name service))
  51. (form (draw-connecting-page service-name)))
  52. (connman-connect service)
  53. (destroy-form-and-pop form)))
  54. (define (run-ethernet-page)
  55. (let ((services (ethernet-services)))
  56. (if (null? services)
  57. (begin
  58. (run-error-page
  59. (G_ "No ethernet service available, please try again.")
  60. (G_ "No service"))
  61. (raise
  62. (condition
  63. (&installer-step-abort))))
  64. (run-listbox-selection-page
  65. #:info-text (G_ "Please select an ethernet network.")
  66. #:title (G_ "Ethernet connection")
  67. #:listbox-items services
  68. #:listbox-item->text ethernet-service->text
  69. #:button-text (G_ "Cancel")
  70. #:button-callback-procedure
  71. (lambda _
  72. (raise
  73. (condition
  74. (&installer-step-abort))))
  75. #:listbox-callback-procedure connect-ethernet-service))))