diff options
author | Vivien Kraus <vivien@planete-kraus.eu> | 2021-10-05 11:25:18 +0200 |
---|---|---|
committer | Vivien Kraus <vivien@planete-kraus.eu> | 2021-10-07 12:34:19 +0200 |
commit | 381a7d0399434aa277aa86a30e742ee215f2576a (patch) | |
tree | 561589e60e93420aa831eb180c378f0e0ec4170b /src/scm/webid-oidc/client/gui/accounts-widget.scm | |
parent | dd18ea62055a95733db6c7bc507e01783e526858 (diff) |
gui: use the application API
Diffstat (limited to 'src/scm/webid-oidc/client/gui/accounts-widget.scm')
-rw-r--r-- | src/scm/webid-oidc/client/gui/accounts-widget.scm | 119 |
1 files changed, 41 insertions, 78 deletions
diff --git a/src/scm/webid-oidc/client/gui/accounts-widget.scm b/src/scm/webid-oidc/client/gui/accounts-widget.scm index b9e5403..be95960 100644 --- a/src/scm/webid-oidc/client/gui/accounts-widget.scm +++ b/src/scm/webid-oidc/client/gui/accounts-widget.scm @@ -38,6 +38,7 @@ #:use-module (webid-oidc client gui application-hooks) #:use-module (webid-oidc client gui authorizations-widget) #:use-module (webid-oidc client gui accounts-widget-logic) + #:use-module (webid-oidc client application) #:use-module (webid-oidc jwk) #:use-module (webid-oidc oidc-id-token) #:use-module (web uri) @@ -48,7 +49,7 @@ #:duplicates (merge-generics) #:export ( - accounts-widget + ->widget )) (push-duplicate-handler! 'merge-generics) @@ -57,88 +58,50 @@ (use-typelibs ("GdkPixbuf" "2.0") ("Gtk" "3.0")) -(define builder #f) -(define accounts-widget #f) +(define srfi-1:map (@ (srfi srfi-1) map)) -(define current-main-child '()) -(define current-other-children '()) +(define account:->widget + (@ (webid-oidc client gui account-widget) ->widget)) -(define (build-accounts-widget app) - (unless accounts-widget - (set! builder - (builder:new-from-file (string-append config:uidir "/accounts-widget.glade"))) - (set! accounts-widget - (builder:get-object builder "accounts_widget")) - (let ((main-account-box +(define-method (->widget (application <application-state>)) + (let ((builder + (builder:new-from-file (string-append config:uidir "/accounts-widget.glade")))) + (let ((accounts-widget + (builder:get-object builder "accounts_widget")) + (main-account-box (builder:get-object builder "main_account_box")) (other-accounts-box (builder:get-object builder "other_accounts_box")) (identity-provider-entry (builder:get-object builder "identity_provider_entry")) (add-account-button - (builder:get-object builder "add_account_button"))) - (define (set-accounts main other) - (for-each - (match-lambda - ((_ widget) - (container:remove main-account-box widget))) - current-main-child) - (set! current-main-child '()) - (for-each - (match-lambda - ((_ widget) - (container:remove other-accounts-box widget))) - current-other-children) - (set! current-other-children '()) - (receive (main-builder main-widget discard-button use-button) - (make-account-widget main) - (set! current-main-child - `((,main-builder ,main-widget))) - (when discard-button - ((@ (gi) connect) discard-button clicked - (lambda _ - (match other - ((new-main new-other ...) - (settings:main-account new-main) - (settings:other-accounts new-other)) - (() - (settings:main-account #f)))))) - (when use-button - (widget:set-sensitive use-button #f)) - (box:pack-end main-account-box main-widget #t #t 0)) - (for-each - (lambda (other-account) - (let ((not-represented (filter (lambda (a) (not (eq? a other-account))) - other))) - ;; We’re packing a widget for other-account, and if the - ;; discard button is clicked, replace the list of other - ;; accounts with not-represented. - (receive (builder widget discard-button use-button) - (make-account-widget other-account) - (set! current-other-children - `((,builder ,widget) ,@current-other-children)) - ((@ (gi) connect) discard-button clicked - (lambda _ - (settings:other-accounts not-represented))) - ((@ (gi) connect) use-button clicked - (lambda _ - (settings:main-account other-account) - (settings:other-accounts `(,main ,@not-represented)))) - (box:pack-end main-account-box widget #t #t 0)))) - other) - ((@ (gi) connect) add-account-button clicked - (lambda _ - ((@ (webid-oidc client gui accounts-widget-logic) add-account-button-clicked) - (entry:get-text identity-provider-entry) - (lambda () - (entry:set-text identity-provider-entry ""))))) - ((@ (gi) connect) identity-provider-entry activate - (lambda _ - ((@ (webid-oidc client gui accounts-widget-logic) add-account-button-clicked) - (entry:get-text identity-provider-entry) - (lambda () - (entry:set-text identity-provider-entry "")))))) - (set-accounts (settings:main-account) (settings:other-accounts)) - (add-hook! settings:accounts-changed-hook set-accounts)))) - -(add-hook! application-activated-hook build-accounts-widget) + (builder:get-object builder "add_account_button")) + (builders (list builder))) + (let ((main-widget + (let ((acct (main-account application))) + (if acct + (receive (additional-builder widget) + (account:->widget acct #f) + (set! builders `(,additional-builder ,@builders)) + widget) + (label:new (G_ "Please add an account."))))) + (other-widgets + (srfi-1:map + (lambda (account) + (receive (additional-builder widget) + (account:->widget account #t) + (set! builders `(,additional-builder ,@builders)) + widget)) + (other-accounts application)))) + (define (add-account-activated . _) + (add-account-button-clicked + (entry:get-text identity-provider-entry) + (lambda () + (widget:set-sensitive identity-provider-entry #f) + (widget:set-sensitive add-account-button #f)))) + (box:pack-end main-account-box main-widget #t #t 0) + (for-each (cute box:pack-end other-accounts-box <> #t #t 0) + other-widgets) + (connect identity-provider-entry activate add-account-activated) + (connect add-account-button clicked add-account-activated) + (values builder accounts-widget))))) |