ethernet.scm 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. service))
  55. (define (run-ethernet-page)
  56. (let ((services (ethernet-services)))
  57. (if (null? services)
  58. (begin
  59. (run-error-page
  60. (G_ "No ethernet service available, please try again.")
  61. (G_ "No service"))
  62. (raise
  63. (condition
  64. (&installer-step-abort))))
  65. (run-listbox-selection-page
  66. #:info-text (G_ "Please select an ethernet network.")
  67. #:title (G_ "Ethernet connection")
  68. #:listbox-items services
  69. #:listbox-item->text ethernet-service->text
  70. #:button-text (G_ "Exit")
  71. #:button-callback-procedure
  72. (lambda _
  73. (raise
  74. (condition
  75. (&installer-step-abort))))
  76. #:listbox-callback-procedure connect-ethernet-service))))