Adding settings.

This commit is contained in:
2026-07-08 00:09:45 +02:00
parent 5e332522e3
commit f949e2dbb3
10 changed files with 438 additions and 75 deletions
+48 -25
View File
@@ -11,6 +11,7 @@
"translate.rkt"
"playlist.rkt"
"player.rkt"
"settings.rkt"
)
(provide
@@ -24,15 +25,14 @@
(define player-menu
(λ ()
(wv-menu 'main-menu
(wv-menu-item 'm-file (tr "File")
#:submenu
(wv-menu
(wv-menu-item 'm-add-tab (tr "Add Playlist"))
(wv-menu-item 'm-select-library-dir (tr "Select Music Library Folder"))
(wv-menu-item 'm-set-lang (tr "Set language"))
(wv-menu-item 'm-quit (tr "Quit") #:separator #t)))
(wv-menu-item 'm-file (tr 'file)
#:submenu (wv-menu 'file-menu
(wv-menu-item 'm-select-library-dir (tr 'select-library-dir))
(wv-menu-item 'm-settings (tr 'settings))
(wv-menu-item 'm-quit (tr 'quit) #:separator #t)
)
)
))
)))
(define rktplayer%
(class wv-window%
@@ -60,11 +60,12 @@
(define el-format #f)
(define el-channels #f)
(define el-bits #f)
(define cfg (send settings clone 'settings))
(define current-tab 0)
(define music-library
(let ((path (format "~a" (send settings get 'music-library (find-system-path 'home-dir)))))
(let ((path (format "~a" (send cfg get 'music-library (find-system-path 'home-dir)))))
(when (eq? (system-type 'os) 'windows)
(set! path (string-replace path "/" "\\")))
(dbg-rktplayer "music-library: ~a" path)
@@ -79,7 +80,7 @@
(define/public (update-volume)
(let ((el (send this element 'volume-percentage)))
(let ((percentage (send player get-volume)))
(send el set-innerHTML! (sprintf "%s %d%" (tr "Volume:") percentage)))
(send el set-innerHTML! (sprintf "%s %d%" (tr 'volume) percentage)))
)
)
@@ -157,7 +158,7 @@
(send this bind! 'album-image 'contextmenu
(λ (el evt data)
(let ((mnu (wv-menu 'image-menu
(wv-menu-item 'm-booklet (tr "Open booklet")
(wv-menu-item 'm-booklet (tr 'open-booklet)
#:callback (λ () (send this open-booklet booklet-file #t)))))
(clientX (hash-ref data 'clientX 60))
(clientY (hash-ref data 'clientY 60)))
@@ -188,20 +189,20 @@
(let ((el (send this element 'paused)))
(cond ((or (eq? st 'playing) (eq? st 'play))
(set-play-button "buttons/pause.svg")
(send el set-innerHTML! '(span (tr "playing"))))
(send el set-innerHTML! (list 'span (tr 'playing))))
((eq? st 'stopped)
(set-play-button "buttons/play.svg")
(send el set-innerHTML! '(span (tr "stopped"))))
(send el set-innerHTML! (list 'span (tr 'stopped))))
((eq? st 'paused)
(set-play-button "buttons/play.svg")
(send el set-innerHTML! '(span ((class "blink")) (tr "paused"))))
(send el set-innerHTML! (list 'span '((class "blink")) (tr 'paused))))
((eq? st 'quit)
(void))
(else
(warn-rktplayer "Unkown state for update-state ~a" st)
(send el set-innerHTML! (list 'span
'((class "blink"))
(format "~a: ~a" (tr "Unknown state") st))))
(format "~a: ~a" (tr 'unknown-state) st))))
))
(set! state st)
)
@@ -250,9 +251,9 @@
(define/public (tab-context evt tab-id tab-idx)
(let ((items (list
(wv-menu-item 'm-tab-rename (tr "Rename playlist") #:callback (λ () (send this rename-tab! tab-id tab-idx)))
(wv-menu-item 'm-tab-drop (tr "Remove playlist") #:callback (λ () (send this drop-tab! tab-id tab-idx)))
(wv-menu-item 'm-tab-add (tr "Add playlist") #:callback (λ () (send this add-tab)))
(wv-menu-item 'm-tab-rename (tr 'rename-playlist) #:callback (λ () (send this rename-tab! tab-id tab-idx)))
(wv-menu-item 'm-tab-drop (tr 'remove-playlist) #:callback (λ () (send this drop-tab! tab-id tab-idx)))
(wv-menu-item 'm-tab-add (tr 'add-playlist) #:callback (λ () (send this add-tab)))
)
)
)
@@ -321,8 +322,8 @@
(define (update-audio-info rate channels bits audio-format)
(let ((format-num (λ (x) (if (= x 0) "-" x)))
(format-dec (λ (x) (if (eq? x 'none) "-" x))))
(send el-bits set-innerHTML! (format "~a ~a" (format-num bits) (tr "bits")))
(send el-channels set-innerHTML! (format "~a ~a" (format-num channels) (tr "channels")))
(send el-bits set-innerHTML! (format "~a ~a" (format-num bits) (tr 'bits)))
(send el-channels set-innerHTML! (format "~a ~a" (format-num channels) (tr 'channels)))
(send el-rate set-innerHTML! (format "~a Hz" (format-num rate)))
(send el-format set-innerHTML! (format "~a" (format-dec audio-format)))
)
@@ -403,6 +404,7 @@
(send this set-menu! (player-menu))
(send this connect-menu! 'm-quit (λ () (send this quit)))
(send this connect-menu! 'm-select-library-dir (λ () (send this select-library)))
(send this connect-menu! 'm-settings (λ () (send this settings-dlg)))
(send this connect-menu! 'm-add-tab (λ () (send this add-tab)))
(dbg-rktplayer "page-loaded, playlist = ~a" playlist)
@@ -542,20 +544,20 @@
(define/public (context-for-path evt path)
(let ((items (list
(wv-menu-item 'm-play-this (tr "Play this") #:callback (λ () (send this play-path path))))))
(wv-menu-item 'm-play-this (tr 'play-this) #:callback (λ () (send this play-path path))))))
(when (file-exists? path)
(set! items (append items
(list
(wv-menu-item 'm-add-this (tr "Add this") #:callback (λ () (send this add-path path)))))))
(wv-menu-item 'm-add-this (tr 'add-this) #:callback (λ () (send this add-path path)))))))
(when (file-exists? (build-path path "booklet.pdf"))
(set! items (append items
(list
(wv-menu-item 'm-booklet (tr "Open booklet") #:callback (λ () (send this open-booklet path))) ;; todo check if pdf file exists
(wv-menu-item 'm-booklet (tr 'open-booklet) #:callback (λ () (send this open-booklet path))) ;; todo check if pdf file exists
))))
(set! items (append items
(list
(wv-menu-item 'm-folder (tr "Open containing folder") #:callback (λ () (send this open-folder path)))
(wv-menu-item 'm-folder (tr 'open-containing-folder) #:callback (λ () (send this open-folder path)))
)))
(let* ((mnu (wv-menu 'library-popup items))
(clientX (hash-ref evt 'clientX 60))
@@ -566,6 +568,21 @@
)
)
(define play-remote #f)
(define/public (toggle-remote)
(info-rktplayer "Toggling remote playing")
(set! play-remote (not play-remote))
;(displayln (format "player = ~a" player))
(if play-remote
(send player change-player 'remote
#:host "hans@mahler.thuis.local"
#:basepaths '(("\\\\panderleou\\music" . "/muziek")
("//panderleou/music" . "/muziek")
))
(send player change-player 'local))
(info-rktplayer "Playing remote: ~a" play-remote)
)
(define/public (play-path path)
(dbg-rktplayer "Playing ~a" path)
(let ((pl (new playlist% [start-map path] [settings (send settings clone 'playlists)] [id current-tab])))
@@ -674,7 +691,7 @@
(define/public (select-library)
(let ((dir (send this choose-dir
(tr "Choose the folder containing your music library")
(tr 'choose-lib-folder)
(if (string? music-library) music-library (path->string music-library))
)))
(if (eq? dir 'showing)
@@ -689,6 +706,12 @@
)
)
(define/public (settings-dlg)
(let ((dlg (new settings% [settings (send settings clone 'settings-dlg)]
[parent this])))
(send dlg show)))
(define/public (show-hide)
(let ((st (send this window-state)))
(if (eq? st 'hidden)