-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschemep3-panel-database-query.scm
61 lines (49 loc) · 1.9 KB
/
schemep3-panel-database-query.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#lang scheme/gui
(provide query-panel%)
(require framework)
(require "schemep3-playlist.scm")
(require "schemep3-status.scm")
(require "schemep3-mixins-gui.scm")
(require "schemep3-helpers.scm")
(define query-panel%
(class (checkable-panel-mixin group-box-panel% "Database Query")
(define default-query-choices
(list
"RATING=5 ORDER BY RANDOM()"
"RATING>3 AND last_played IS NULL ORDER BY RANDOM()"
"RATING>3 AND artist NOT LIKE \"%beatles%\" ORDER BY RANDOM()"
"RATING=5 AND ARTIST LIKE \"%Nirvana%\""
"filename NOT NULL"
))
(define query-choices (preferences-backed-variable 'schemep3-queries default-query-choices))
(define (add-choice-if-necessary addition)
(let ((choices (query-choices)))
(unless (member addition choices)
(let ((z (append choices (list addition))))
(query-choices z)
(send query-text-field append addition)))))
(define (apply-query . ignore)
(let ((query-string (send query-text-field get-value)))
(playlist-set-from-database query-string)
(add-choice-if-necessary query-string)))
(super-new
(label "Database query")
(alignment '(left top))
(stretchable-height #f))
(define query-sub-panel
(new horizontal-panel%
(parent this)))
(define query-text-field
(new combo-field%
(parent query-sub-panel)
(label #f)
(choices (query-choices))
(callback
(lambda (tf e)
(when (equal? 'text-field-enter (send e get-event-type))
(apply-query))))))
(define query-apply-button
(new button%
(label "Apply")
(parent query-sub-panel)
(callback apply-query)))))