;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2018 Mathieu Othacehe ;;; Copyright © 2019 Meiyo Peng ;;; Copyright © 2019 Tobias Geerinckx-Rice ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (gnu installer newt wifi) #:use-module (gnu installer connman) #:use-module (gnu installer steps) #:use-module (gnu installer newt utils) #:use-module (gnu installer newt page) #:use-module (guix i18n) #:use-module (guix records) #:use-module (ice-9 format) #:use-module (ice-9 popen) #:use-module (ice-9 receive) #:use-module (ice-9 regex) #:use-module (ice-9 rdelim) #:use-module (srfi srfi-1) #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) #:use-module (newt) #:export (run-wifi-page)) ;; This record associates a connman service to its key the listbox. (define-record-type* service-item make-service-item service-item? (service service-item-service) ; connman (key service-item-key)) ; newt listbox-key (define (strength->string strength) "Convert STRENGTH as an integer percentage into a text printable strength bar using unicode characters. Taken from NetworkManager's nmc_wifi_strength_bars." (let ((quarter #\x2582) (half #\x2584) (three-quarter #\x2586) (full #\x2588)) (cond ((> strength 80) ;; ▂▄▆█ (string quarter half three-quarter full)) ((> strength 55) ;; ▂▄▆_ (string quarter half three-quarter #\_)) ((> strength 30) ;; ▂▄__ (string quarter half #\_ #\_)) ((> strength 5) ;; ▂___ (string quarter #\_ #\_ #\_)) (else ;; ____ (string quarter #\_ #\_ #\_ #\_))))) (define (force-wifi-scan) "Force a wifi scan. Raise a condition if no wifi technology is available." (let* ((technologies (connman-technologies)) (wifi-technology (find (lambda (technology) (string=? (technology-type technology) "wifi")) technologies))) (if wifi-technology (connman-scan-technology wifi-technology) (raise (condition (&message (message (G_ "Unable to find a wifi technology")))))))) (define (draw-scanning-page) "Draw a page to indicate a wifi scan in progress." (draw-info-page (G_ "Scanning wifi for available networks, please wait.") (G_ "Scan in progress"))) (define (run-wifi-password-page) "Run a page prompting user for a password and return it." (run-input-page (G_ "Please enter the wifi password.") (G_ "Password required") #:input-visibility-checkbox? #t)) (define (run-wrong-password-page service-name) "Run a page to inform user of a wrong password input." (run-error-page (format #f (G_ "The password you entered for ~a is incorrect.") service-name) (G_ "Wrong password"))) (define (run-unknown-error-page service-name) "Run a page to inform user that a connection error happened." (run-error-page (format #f (G_ "An error occurred while trying to connect to ~a, please retry.") service-name) (G_ "Connection error"))) (define (password-callback) (run-wifi-password-page)) (define (connect-wifi-service listbox service-items) "Connect to the wifi service selected in LISTBOX. SERVICE-ITEMS is the list of records present in LISTBOX." (let* ((listbox-key (current-listbox-entry listbox)) (item (find (lambda (item) (eq? (service-item-key item) listbox-key)) service-items)) (service (service-item-service item)) (service-name (service-name service)) (form (draw-connecting-page service-name))) (dynamic-wind (const #t) (lambda () (guard (c ((connman-password-error? c) (run-wrong-password-page service-name) #f) ((connman-already-connected-error? c) #t) ((connman-connection-error? c) (run-unknown-error-page service-name) #f)) (connman-connect-with-auth service password-callback))) (lambda () (destroy-form-and-pop form))))) (define (run-wifi-scan-page) "Force a wifi scan and draw a page during the operation." (let ((form 2024-04-03store: database: Remove with-statement and associated code....I think using dynamic-wind to finalize all statements is the wrong approach. Firstly it would be good to allow reseting statements rather than finalizing them. Then for the problem of handling errors, the approach I've settled on in the build coordinator is to close the database connection, since that'll trigger guile-sqlite3 to finalize all the cached statements. This reverts commit 5d6e2255286e591def122ec2f4a3cbda497fea21. * .dir-locals.el (scheme-mode): Remove with-statement. * guix/store/database.scm (call-with-statement): Remove procedure. (with-statement): Remove syntax rule. (call-with-transaction, last-insert-row-id, path-id, update-or-insert, add-references): Don't use with-statement. Change-Id: I2fd976b3f12ec8105cc56350933a953cf53647e8 Christopher Baines 2024-04-03store: database: Remove call-with-savepoint and associated code....While care does need to be taken with making updates or inserts to the ValidPaths table, I think that trying to ensure this within update-or-insert is the wrong approach. Instead, when working with the store database, only one connection should be used to make changes to the database and those changes should happen in transactions that ideally begin immediately. This reverts commit 37545de4a3bf59611c184b31506fe9a16abe4c8b. * .dir-locals.el (scheme-mode): Remove entries for call-with-savepoint and call-with-retrying-savepoint. * guix/store/database.scm (call-with-savepoint, call-with-retrying-savepoint): Remove procedures. (update-or-insert): Remove use of call-with-savepoint. Change-Id: I2f986e8623d8235a90c40d5f219c1292c1ab157b Christopher Baines LL FLAG-BORDER FLAG-RETURNEXIT))) (form (make-form)) (buttons-grid (make-grid 1 1)) (middle-grid (make-grid 2 1)) (info-text (G_ "Please select a wifi network.")) (info-textbox (make-reflowed-textbox -1 -1 info-text (info-textbox-width) #:flags FLAG-BORDER)) (exit-button (make-button -1 -1 (G_ "Exit"))) (scan-button (make-button -1 -1 (G_ "Scan"))) (services (wifi-services)) (service-items '())) (if (null? services) (append-entry-to-listbox listbox (G_ "No wifi detected")) (set! service-items (fill-wifi-services listbox services))) (set-grid-field middle-grid 0 0 GRID-ELEMENT-COMPONENT listbox) (set-grid-field middle-grid 1 0 GRID-ELEMENT-COMPONENT scan-button #:anchor ANCHOR-TOP #:pad-left 2) (set-grid-field buttons-grid 0 0 GRID-ELEMENT-COMPONENT exit-button) (add-components-to-form form info-textbox listbox scan-button exit-button) (make-wrapped-grid-window (basic-window-grid info-textbox middle-grid buttons-grid) (G_ "Wifi")) (receive (exit-reason argument) (run-form form) (dynamic-wind (const #t) (lambda () (when (eq? exit-reason 'exit-component) (cond ((components=? argument scan-button) (run-wifi-scan-page) (run-wifi-page)) ((components=? argument exit-button) (abort-to-prompt 'installer-step 'abort)) ((components=? argument listbox) (let ((result (connect-wifi-service listbox service-items))) (unless result (run-wifi-page))))))) (lambda () (destroy-form-and-pop form))))))