annotate mservtk.tcl @ 5:b6c495b5eeda

- Use wish8.2 - Ack, use the temp variable we copied the rtlist into! (not the recently blanked out rtlist state variable) - Add some locking to try and fix out of sync problems.. Still broken.
author darius
date Tue, 03 Oct 2000 10:18:34 +0000
parents 32f624fc18cc
children b370e0bbe050
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1 #!/usr/bin/env wish8.2
1
c36994199c5e Initial revision
darius
parents:
diff changeset
2
c36994199c5e Initial revision
darius
parents:
diff changeset
3 #
c36994199c5e Initial revision
darius
parents:
diff changeset
4 # This software is copyright Daniel O'Connor (darius@dons.net.au) 2000
c36994199c5e Initial revision
darius
parents:
diff changeset
5 #
c36994199c5e Initial revision
darius
parents:
diff changeset
6 # Redistribution and use in source and binary forms, with or without
c36994199c5e Initial revision
darius
parents:
diff changeset
7 # modification, are permitted provided that the following conditions
c36994199c5e Initial revision
darius
parents:
diff changeset
8 # are met:
c36994199c5e Initial revision
darius
parents:
diff changeset
9 # 1. Redistributions of source code must retain the above copyright
c36994199c5e Initial revision
darius
parents:
diff changeset
10 # notice, this list of conditions and the following disclaimer.
c36994199c5e Initial revision
darius
parents:
diff changeset
11 # 2. Redistributions in binary form must reproduce the above copyright
c36994199c5e Initial revision
darius
parents:
diff changeset
12 # notice, this list of conditions and the following disclaimer in the
c36994199c5e Initial revision
darius
parents:
diff changeset
13 # documentation and/or other materials provided with the distribution.
c36994199c5e Initial revision
darius
parents:
diff changeset
14 # 3. Neither the name Daniel O'Connor nor the names of its contributors
c36994199c5e Initial revision
darius
parents:
diff changeset
15 # may be used to endorse or promote products derived from this software
c36994199c5e Initial revision
darius
parents:
diff changeset
16 # without specific prior written permission.
c36994199c5e Initial revision
darius
parents:
diff changeset
17 #
c36994199c5e Initial revision
darius
parents:
diff changeset
18 # THIS SOFTWARE IS PROVIDED BY DANIEL O'CONNOR AND CONTRIBUTORS ``AS IS'' AND
c36994199c5e Initial revision
darius
parents:
diff changeset
19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
c36994199c5e Initial revision
darius
parents:
diff changeset
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
c36994199c5e Initial revision
darius
parents:
diff changeset
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
c36994199c5e Initial revision
darius
parents:
diff changeset
22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
c36994199c5e Initial revision
darius
parents:
diff changeset
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
c36994199c5e Initial revision
darius
parents:
diff changeset
24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
c36994199c5e Initial revision
darius
parents:
diff changeset
25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
c36994199c5e Initial revision
darius
parents:
diff changeset
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
c36994199c5e Initial revision
darius
parents:
diff changeset
27 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
c36994199c5e Initial revision
darius
parents:
diff changeset
28 # SUCH DAMAGE.
c36994199c5e Initial revision
darius
parents:
diff changeset
29 #
c36994199c5e Initial revision
darius
parents:
diff changeset
30
c36994199c5e Initial revision
darius
parents:
diff changeset
31 proc main {} {
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
32 global argv0 argv state albums songs tcl_platform;
1
c36994199c5e Initial revision
darius
parents:
diff changeset
33
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
34 if {[string first "Windows" $tcl_platform(os)] == -1} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
35 set state(conffile) "~/.mservtk";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
36 set state(windows) 0;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
37 } else {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
38 package require registry 1.0;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
39 set state(windows) 1;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
40 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
41
1
c36994199c5e Initial revision
darius
parents:
diff changeset
42 set state(port) "4444";
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
43 set state(exit) 0;
1
c36994199c5e Initial revision
darius
parents:
diff changeset
44 set state(tmpphrase) "";
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
45 set state(sortmode) "Title";
1
c36994199c5e Initial revision
darius
parents:
diff changeset
46
4
32f624fc18cc Resolve merge conflicts..
darius
parents: 3
diff changeset
47 set state(rtlist) "";
32f624fc18cc Resolve merge conflicts..
darius
parents: 3
diff changeset
48
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
49 wm withdraw .;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
50
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
51 f_readconf;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
52 gui_conf;
1
c36994199c5e Initial revision
darius
parents:
diff changeset
53
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
54 if {$state(host) == "NONE"} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
55 log "%s" "Login cancelled";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
56 exit;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
57 } else {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
58 log "%s" "Login OK'd";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
59 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
60
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
61 f_writeconf;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
62
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
63 wm deiconify .;
1
c36994199c5e Initial revision
darius
parents:
diff changeset
64 con_mserv;
c36994199c5e Initial revision
darius
parents:
diff changeset
65
c36994199c5e Initial revision
darius
parents:
diff changeset
66 con_getalbums albums;
c36994199c5e Initial revision
darius
parents:
diff changeset
67 con_getsongs songs albums;
c36994199c5e Initial revision
darius
parents:
diff changeset
68
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
69 gui_build;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
70 focus -force .;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
71
1
c36994199c5e Initial revision
darius
parents:
diff changeset
72 gui_updatesongs;
c36994199c5e Initial revision
darius
parents:
diff changeset
73 gui_updatequeue;
c36994199c5e Initial revision
darius
parents:
diff changeset
74
c36994199c5e Initial revision
darius
parents:
diff changeset
75 update_timer;
c36994199c5e Initial revision
darius
parents:
diff changeset
76
c36994199c5e Initial revision
darius
parents:
diff changeset
77 while {1} {
4
32f624fc18cc Resolve merge conflicts..
darius
parents: 3
diff changeset
78 vwait state;
32f624fc18cc Resolve merge conflicts..
darius
parents: 3
diff changeset
79
32f624fc18cc Resolve merge conflicts..
darius
parents: 3
diff changeset
80 if {$state(rtlist) != ""} {
32f624fc18cc Resolve merge conflicts..
darius
parents: 3
diff changeset
81 # Copy it so we don't stomp any new additions
32f624fc18cc Resolve merge conflicts..
darius
parents: 3
diff changeset
82 set tmp $state(rtlist);
32f624fc18cc Resolve merge conflicts..
darius
parents: 3
diff changeset
83 set state(rtlist) "";
32f624fc18cc Resolve merge conflicts..
darius
parents: 3
diff changeset
84
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
85 foreach t $tmp {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
86 # log "%s" "Handle $t";
4
32f624fc18cc Resolve merge conflicts..
darius
parents: 3
diff changeset
87 n_rthandler [lindex $t 0] [lindex $t 1];
32f624fc18cc Resolve merge conflicts..
darius
parents: 3
diff changeset
88 }
32f624fc18cc Resolve merge conflicts..
darius
parents: 3
diff changeset
89 }
1
c36994199c5e Initial revision
darius
parents:
diff changeset
90
c36994199c5e Initial revision
darius
parents:
diff changeset
91 if {$state(exit) == 1} {
c36994199c5e Initial revision
darius
parents:
diff changeset
92 exit;
c36994199c5e Initial revision
darius
parents:
diff changeset
93 }
c36994199c5e Initial revision
darius
parents:
diff changeset
94 }
c36994199c5e Initial revision
darius
parents:
diff changeset
95 }
c36994199c5e Initial revision
darius
parents:
diff changeset
96
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
97 proc f_readconf {} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
98 global state;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
99
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
100 set state(host) "NONE";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
101 set state(user) "NONE";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
102 set state(pass) "";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
103
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
104 if {$state(windows) == 1} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
105 if {[catch {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
106 set state(host) [registry get {HKEY_CURRENT_USER\Software\MServTk} host];
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
107 set state(user) [registry get {HKEY_CURRENT_USER\Software\MServTk} user];
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
108 set state(pass) [registry get {HKEY_CURRENT_USER\Software\MServTk} pass];
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
109 } msg]} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
110 log "%s" "Failed to read registry keys - $msg";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
111 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
112 } else {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
113 if {![catch {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
114 set fh [open $state(conffile)];
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
115 } msg]} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
116 if {[gets $fh] != "mservtk-0.1"} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
117 log "%s" "Conf file has the wrong version";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
118 } else {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
119 set state(host) [gets $fh];
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
120 set state(user) [gets $fh];
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
121 set state(pass) [gets $fh];
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
122 close $fh;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
123 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
124 } else {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
125 log "%s" "Failed to open $state(conffile) - $msg";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
126 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
127 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
128 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
129
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
130 proc f_writeconf {} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
131 global state;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
132
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
133 if {$state(windows) == 1} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
134 if {[catch {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
135 registry set {HKEY_CURRENT_USER\Software\MServTk} host $state(host);
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
136 registry set {HKEY_CURRENT_USER\Software\MServTk} user $state(user);
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
137 registry set {HKEY_CURRENT_USER\Software\MServTk} pass $state(pass);
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
138 } msg]} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
139 log "%s" "Failed to set registry keys - $msg";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
140 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
141 } else {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
142 if {![catch {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
143 set fh [open $state(conffile) w];
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
144 } msg]} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
145 puts $fh "mservtk-0.1";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
146 puts $fh $state(host);
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
147 puts $fh $state(user);
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
148 puts $fh $state(pass);
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
149
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
150 close $fh;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
151 } else {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
152 log "%s" "Failed to open $state(conffile) - $msg";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
153 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
154 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
155 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
156
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
157 proc gui_conf {} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
158 global state;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
159
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
160 catch {destroy .conf};
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
161
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
162 toplevel .conf -class Dialog;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
163 wm title .conf "Authentication";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
164 wm iconname .conf "Authentication";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
165
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
166 frame .conf.host;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
167 pack .conf.host -side top -pady 2m -fill x;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
168 label .conf.host.label -text "Host:" -width 10 -anchor e;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
169
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
170 entry .conf.host.entry -relief sunken -width 30 -textvariable state(host)
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
171 pack .conf.host.label .conf.host.entry -side left -padx 1m
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
172
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
173 frame .conf.user
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
174 pack .conf.user -side top -pady 2m -fill x
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
175 label .conf.user.label -text "User:" -width 10 -anchor e
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
176 entry .conf.user.entry -relief sunken -width 8 -textvariable state(user)
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
177 pack .conf.user.label .conf.user.entry -side left -padx 1m
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
178
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
179 frame .conf.password
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
180 pack .conf.password -side top -pady 2m -fill x
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
181 label .conf.password.label -text "Password:" -width 10 -anchor e
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
182 entry .conf.password.entry -relief sunken -width 8 -textvariable state(pass) -show *;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
183 bind .conf.password.entry <Return> ".conf.buttons.ok invoke";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
184 pack .conf.password.label .conf.password.entry -side left -padx 1m
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
185
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
186 frame .conf.buttons
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
187 pack .conf.buttons -side top -pady 1m -fill x
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
188 button .conf.buttons.ok -text OK -width 6 -command {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
189 destroy .conf;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
190 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
191 button .conf.buttons.cancel -text Cancel -width 6 -command {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
192 set state(host) "NONE";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
193 set state(user) "NONE";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
194 set state(pass) "NONE";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
195 destroy .conf;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
196 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
197 pack .conf.buttons.ok -side left -padx 1m;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
198 pack .conf.buttons.cancel -side right -padx 1m;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
199
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
200
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
201 # Withdraw the window, then update all the geometry information
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
202 # so we know how big it wants to be, then center the window in the
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
203 # display and de-iconify it.
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
204
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
205 wm withdraw .conf
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
206 update idletasks
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
207 set x [expr [winfo screenwidth .conf]/2 - [winfo reqwidth .conf]/2 \
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
208 - [winfo vrootx [winfo parent .conf]]]
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
209 set y [expr [winfo screenheight .conf]/2 - [winfo reqheight .conf]/2 \
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
210 - [winfo vrooty [winfo parent .conf]]]
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
211 wm geom .conf +$x+$y
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
212 wm deiconify .conf
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
213
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
214 # Set a grab and claim the focus too.
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
215
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
216 set oldFocus [focus]
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
217 set oldGrab [grab current .conf]
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
218 if {$oldGrab != ""} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
219 set grabStatus [grab status $oldGrab]
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
220 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
221 grab .conf
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
222 tkwait visibility .conf
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
223 if {$state(host) == "NONE"} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
224 focus .conf.host.entry;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
225 } else {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
226 focus .conf.password.entry;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
227 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
228 tkwait window .conf;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
229 if {$oldGrab != ""} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
230 if {$grabStatus == "global"} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
231 grab -global $oldGrab
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
232 } else {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
233 grab $oldGrab
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
234 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
235 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
236
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
237 log "%s" "Host $state(host)";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
238 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
239
1
c36994199c5e Initial revision
darius
parents:
diff changeset
240 proc quit_now {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
241 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
242
c36994199c5e Initial revision
darius
parents:
diff changeset
243 set state(exit) 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
244 }
c36994199c5e Initial revision
darius
parents:
diff changeset
245
c36994199c5e Initial revision
darius
parents:
diff changeset
246 proc gui_build {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
247 # create the toplevel
c36994199c5e Initial revision
darius
parents:
diff changeset
248 eval destroy [winfo child .];
c36994199c5e Initial revision
darius
parents:
diff changeset
249 wm title . "MServ-Tk";
c36994199c5e Initial revision
darius
parents:
diff changeset
250 wm minsize . 600 500;
c36994199c5e Initial revision
darius
parents:
diff changeset
251 wm geometry . 600x500;
c36994199c5e Initial revision
darius
parents:
diff changeset
252
c36994199c5e Initial revision
darius
parents:
diff changeset
253 # Let's have a menubar
c36994199c5e Initial revision
darius
parents:
diff changeset
254 frame .menubar -relief raised -bd 2;
c36994199c5e Initial revision
darius
parents:
diff changeset
255 pack .menubar -side top -fill x;
c36994199c5e Initial revision
darius
parents:
diff changeset
256
c36994199c5e Initial revision
darius
parents:
diff changeset
257 # Add the File menu
c36994199c5e Initial revision
darius
parents:
diff changeset
258 menubutton .menubar.file -text "File" -menu .menubar.file.m -underline 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
259 menu .menubar.file.m -tearoff 0;
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
260 .menubar.file.m add command -label " Top" -command "gui_top"
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
261 .menubar.file.m add command -label " Update Queue" -command "gui_updatequeue"
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
262 .menubar.file.m add separator;
1
c36994199c5e Initial revision
darius
parents:
diff changeset
263 .menubar.file.m add command -label " Quit" -command "quit_now" \
c36994199c5e Initial revision
darius
parents:
diff changeset
264 -underline 2 -accelerator "Alt-q";
c36994199c5e Initial revision
darius
parents:
diff changeset
265 pack .menubar.file -side left;
c36994199c5e Initial revision
darius
parents:
diff changeset
266
c36994199c5e Initial revision
darius
parents:
diff changeset
267 # Add the Rate menu
c36994199c5e Initial revision
darius
parents:
diff changeset
268 menubutton .menubar.rate -text "Rate" -menu .menubar.rate.m -underline 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
269 menu .menubar.rate.m -tearoff 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
270 .menubar.rate.m add command -label " Superb" -command "rate_song SUPERB";
c36994199c5e Initial revision
darius
parents:
diff changeset
271 .menubar.rate.m add command -label " Good" -command "rate_song GOOD";
c36994199c5e Initial revision
darius
parents:
diff changeset
272 .menubar.rate.m add command -label " Neutral" -command "rate_song NEUTRAL";
c36994199c5e Initial revision
darius
parents:
diff changeset
273 .menubar.rate.m add command -label " Bad" -command "rate_song BAD";
c36994199c5e Initial revision
darius
parents:
diff changeset
274 .menubar.rate.m add command -label " Awful" -command "rate_song AWFUL";
c36994199c5e Initial revision
darius
parents:
diff changeset
275
c36994199c5e Initial revision
darius
parents:
diff changeset
276 pack .menubar.rate -side left;
c36994199c5e Initial revision
darius
parents:
diff changeset
277
c36994199c5e Initial revision
darius
parents:
diff changeset
278 # Add the Control menu
c36994199c5e Initial revision
darius
parents:
diff changeset
279 menubutton .menubar.control -text "Control" -menu .menubar.control.m -underline 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
280 menu .menubar.control.m -tearoff 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
281 .menubar.control.m add command -label " Next" -command "control_player NEXT";
c36994199c5e Initial revision
darius
parents:
diff changeset
282 .menubar.control.m add command -label " Pause" -command "control_player PAUSE";
c36994199c5e Initial revision
darius
parents:
diff changeset
283 .menubar.control.m add command -label " Stop" -command "control_player STOP"
c36994199c5e Initial revision
darius
parents:
diff changeset
284 .menubar.control.m add command -label " Play" -command "control_player PLAY";
c36994199c5e Initial revision
darius
parents:
diff changeset
285
c36994199c5e Initial revision
darius
parents:
diff changeset
286 pack .menubar.control -side left;
c36994199c5e Initial revision
darius
parents:
diff changeset
287
c36994199c5e Initial revision
darius
parents:
diff changeset
288 # Add the Volume menu
c36994199c5e Initial revision
darius
parents:
diff changeset
289 menubutton .menubar.vol -text "Volume" -menu .menubar.vol.m -underline 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
290 menu .menubar.vol.m -tearoff 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
291 .menubar.vol.m add command -label " Increase" -command "set_vol +3" \
c36994199c5e Initial revision
darius
parents:
diff changeset
292 -accelerator "+";
c36994199c5e Initial revision
darius
parents:
diff changeset
293 .menubar.vol.m add command -label " Decrease" -command "set_vol -3" \
c36994199c5e Initial revision
darius
parents:
diff changeset
294 -accelerator "-";
c36994199c5e Initial revision
darius
parents:
diff changeset
295 .menubar.vol.m add separator;
c36994199c5e Initial revision
darius
parents:
diff changeset
296 .menubar.vol.m add command -label " 100%" -command "set_vol 100";
c36994199c5e Initial revision
darius
parents:
diff changeset
297 .menubar.vol.m add command -label " 90%" -command "set_vol 90";
c36994199c5e Initial revision
darius
parents:
diff changeset
298 .menubar.vol.m add command -label " 80%" -command "set_vol 80";
c36994199c5e Initial revision
darius
parents:
diff changeset
299 .menubar.vol.m add command -label " 70%" -command "set_vol 70";
c36994199c5e Initial revision
darius
parents:
diff changeset
300 .menubar.vol.m add command -label " 60%" -command "set_vol 60";
c36994199c5e Initial revision
darius
parents:
diff changeset
301 .menubar.vol.m add command -label " 50%" -command "set_vol 50";
c36994199c5e Initial revision
darius
parents:
diff changeset
302 .menubar.vol.m add command -label " 40%" -command "set_vol 40";
c36994199c5e Initial revision
darius
parents:
diff changeset
303 .menubar.vol.m add command -label " 30%" -command "set_vol 30";
c36994199c5e Initial revision
darius
parents:
diff changeset
304 .menubar.vol.m add command -label " 20%" -command "set_vol 20";
c36994199c5e Initial revision
darius
parents:
diff changeset
305 .menubar.vol.m add command -label " 10%" -command "set_vol 10";
c36994199c5e Initial revision
darius
parents:
diff changeset
306 .menubar.vol.m add command -label " 0%" -command "set_vol 0";
c36994199c5e Initial revision
darius
parents:
diff changeset
307
c36994199c5e Initial revision
darius
parents:
diff changeset
308 pack .menubar.vol -side left;
c36994199c5e Initial revision
darius
parents:
diff changeset
309
c36994199c5e Initial revision
darius
parents:
diff changeset
310 # Add the Sort menu
c36994199c5e Initial revision
darius
parents:
diff changeset
311 menubutton .menubar.sort -text "Sort" -menu .menubar.sort.m -underline 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
312 menu .menubar.sort.m -tearoff 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
313 .menubar.sort.m add command -label " Artist" \
c36994199c5e Initial revision
darius
parents:
diff changeset
314 -command "global state; set state(sortmode) Artist; gui_updatesongs";
c36994199c5e Initial revision
darius
parents:
diff changeset
315 .menubar.sort.m add command -label " Title" \
c36994199c5e Initial revision
darius
parents:
diff changeset
316 -command "global state; set state(sortmode) Title; gui_updatesongs";
c36994199c5e Initial revision
darius
parents:
diff changeset
317 .menubar.sort.m add command -label " Album" \
c36994199c5e Initial revision
darius
parents:
diff changeset
318 -command "global state; set state(sortmode) Album; gui_updatesongs";
c36994199c5e Initial revision
darius
parents:
diff changeset
319
c36994199c5e Initial revision
darius
parents:
diff changeset
320 pack .menubar.sort -side left;
c36994199c5e Initial revision
darius
parents:
diff changeset
321
c36994199c5e Initial revision
darius
parents:
diff changeset
322 # Add the Help menu
c36994199c5e Initial revision
darius
parents:
diff changeset
323 menubutton .menubar.help -text "Help" -menu .menubar.help.m -underline 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
324 menu .menubar.help.m -tearoff 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
325 .menubar.help.m add command -label " About" -command "about_box" \
c36994199c5e Initial revision
darius
parents:
diff changeset
326 -underline 2;
c36994199c5e Initial revision
darius
parents:
diff changeset
327 pack .menubar.help -side right;
c36994199c5e Initial revision
darius
parents:
diff changeset
328
c36994199c5e Initial revision
darius
parents:
diff changeset
329 # Top frame holding tracklist and trackinfo frames
c36994199c5e Initial revision
darius
parents:
diff changeset
330 frame .top -relief raised -bd 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
331 pack .top -fill both -expand 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
332
c36994199c5e Initial revision
darius
parents:
diff changeset
333 # Tracklist
c36994199c5e Initial revision
darius
parents:
diff changeset
334 frame .top.tlist -relief raised -bd 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
335 pack .top.tlist -side left -fill both -expand 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
336 label .top.tlist.label -text "Track List";
c36994199c5e Initial revision
darius
parents:
diff changeset
337 pack .top.tlist.label -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
338 listbox .top.tlist.list -relief raised -borderwidth 2 \
c36994199c5e Initial revision
darius
parents:
diff changeset
339 -yscrollcommand ".top.tlist.scr set";
c36994199c5e Initial revision
darius
parents:
diff changeset
340 pack .top.tlist.list -side left -fill both -expand 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
341 scrollbar .top.tlist.scr -command ".top.tlist.list yview";
c36994199c5e Initial revision
darius
parents:
diff changeset
342 pack .top.tlist.scr -side right -fill y;
c36994199c5e Initial revision
darius
parents:
diff changeset
343 bind .top.tlist.list <Double-Button-1> {
c36994199c5e Initial revision
darius
parents:
diff changeset
344 queue_song [.top.tlist.list curselection];
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
345 gui_updatequeue;
1
c36994199c5e Initial revision
darius
parents:
diff changeset
346 }
c36994199c5e Initial revision
darius
parents:
diff changeset
347
c36994199c5e Initial revision
darius
parents:
diff changeset
348 # Trackinfo
c36994199c5e Initial revision
darius
parents:
diff changeset
349 frame .top.tinfo -relief raised -bd 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
350 pack .top.tinfo -side right -fill both -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
351 label .top.tinfo.label -text "Track Info";
c36994199c5e Initial revision
darius
parents:
diff changeset
352 pack .top.tinfo.label -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
353 frame .top.tinfo.sub -relief raised -bd 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
354 pack .top.tinfo.sub -side right -fill both -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
355 label .top.tinfo.sub.author -text "Author:";
c36994199c5e Initial revision
darius
parents:
diff changeset
356 pack .top.tinfo.sub.author -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
357 label .top.tinfo.sub.title -text "Title:";
c36994199c5e Initial revision
darius
parents:
diff changeset
358 pack .top.tinfo.sub.title -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
359 label .top.tinfo.sub.length -text "Length:";
c36994199c5e Initial revision
darius
parents:
diff changeset
360 pack .top.tinfo.sub.length -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
361 label .top.tinfo.sub.time -text "Time:";
c36994199c5e Initial revision
darius
parents:
diff changeset
362 pack .top.tinfo.sub.time -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
363 label .top.tinfo.sub.album -text "Album:";
c36994199c5e Initial revision
darius
parents:
diff changeset
364 pack .top.tinfo.sub.album -side top -expand 0;
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
365 label .top.tinfo.sub.misc -text "Misc:";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
366 pack .top.tinfo.sub.misc -side top -expand 0;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
367 label .top.tinfo.sub.rate1 -text "Rating:";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
368 pack .top.tinfo.sub.rate1 -side top -expand 0;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
369 label .top.tinfo.sub.rate2 -text "Temporally Adjusted:";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
370 pack .top.tinfo.sub.rate2 -side top -expand 0;
1
c36994199c5e Initial revision
darius
parents:
diff changeset
371 label .top.tinfo.sub.vol -text "Volume:";
c36994199c5e Initial revision
darius
parents:
diff changeset
372 pack .top.tinfo.sub.vol -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
373
c36994199c5e Initial revision
darius
parents:
diff changeset
374 # Queue (and the frame holding it)
c36994199c5e Initial revision
darius
parents:
diff changeset
375 frame .bot -relief raised -bd 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
376 pack .bot -fill both -expand 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
377 label .bot.qlabel -text "Queue";
c36994199c5e Initial revision
darius
parents:
diff changeset
378 pack .bot.qlabel -side top -expand 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
379 frame .bot.queue;
c36994199c5e Initial revision
darius
parents:
diff changeset
380 pack .bot.queue -fill both -expand 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
381 listbox .bot.queue.list -relief raised -borderwidth 2 \
c36994199c5e Initial revision
darius
parents:
diff changeset
382 -yscrollcommand ".bot.queue.scr set";
c36994199c5e Initial revision
darius
parents:
diff changeset
383 pack .bot.queue.list -side left -fill both -expand 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
384 scrollbar .bot.queue.scr -command ".bot.queue.list yview";
c36994199c5e Initial revision
darius
parents:
diff changeset
385 pack .bot.queue.scr -side right -fill y;
c36994199c5e Initial revision
darius
parents:
diff changeset
386 bind .bot.queue.list <Double-Button-1> {
c36994199c5e Initial revision
darius
parents:
diff changeset
387 gui_delqueue [.bot.queue.list curselection];
c36994199c5e Initial revision
darius
parents:
diff changeset
388 }
c36994199c5e Initial revision
darius
parents:
diff changeset
389
c36994199c5e Initial revision
darius
parents:
diff changeset
390 bind . <Destroy> {quit_now};
c36994199c5e Initial revision
darius
parents:
diff changeset
391 bind all <Alt-q> {quit_now};
c36994199c5e Initial revision
darius
parents:
diff changeset
392
c36994199c5e Initial revision
darius
parents:
diff changeset
393 bind all <KP_Add> {set_vol +3};
c36994199c5e Initial revision
darius
parents:
diff changeset
394 bind all <KP_Subtract> {set_vol -3};
c36994199c5e Initial revision
darius
parents:
diff changeset
395 bind all <plus> {set_vol +3};
c36994199c5e Initial revision
darius
parents:
diff changeset
396 bind all <equal> {set_vol +3};
c36994199c5e Initial revision
darius
parents:
diff changeset
397 bind all <minus> {set_vol -3};
c36994199c5e Initial revision
darius
parents:
diff changeset
398 bind all <F1> {set_vol 10};
c36994199c5e Initial revision
darius
parents:
diff changeset
399 bind all <F2> {set_vol 20};
c36994199c5e Initial revision
darius
parents:
diff changeset
400 bind all <F3> {set_vol 30};
c36994199c5e Initial revision
darius
parents:
diff changeset
401 bind all <F4> {set_vol 40};
c36994199c5e Initial revision
darius
parents:
diff changeset
402 bind all <F5> {set_vol 50};
c36994199c5e Initial revision
darius
parents:
diff changeset
403 bind all <F6> {set_vol 60};
c36994199c5e Initial revision
darius
parents:
diff changeset
404 bind all <F7> {set_vol 70};
c36994199c5e Initial revision
darius
parents:
diff changeset
405 bind all <F8> {set_vol 80};
c36994199c5e Initial revision
darius
parents:
diff changeset
406 bind all <F9> {set_vol 90};
c36994199c5e Initial revision
darius
parents:
diff changeset
407 bind all <F10> {set_vol 100};
c36994199c5e Initial revision
darius
parents:
diff changeset
408
c36994199c5e Initial revision
darius
parents:
diff changeset
409 bind all <Pause> {control_player PAUSE};
c36994199c5e Initial revision
darius
parents:
diff changeset
410 bind all <End> {control_player NEXT};
c36994199c5e Initial revision
darius
parents:
diff changeset
411 bind all <Delete> {control_player STOP};
c36994199c5e Initial revision
darius
parents:
diff changeset
412 bind all <Home> {control_player PLAY};
c36994199c5e Initial revision
darius
parents:
diff changeset
413
c36994199c5e Initial revision
darius
parents:
diff changeset
414 update;
c36994199c5e Initial revision
darius
parents:
diff changeset
415 }
c36994199c5e Initial revision
darius
parents:
diff changeset
416
c36994199c5e Initial revision
darius
parents:
diff changeset
417 proc queue_song {id} {
c36994199c5e Initial revision
darius
parents:
diff changeset
418 global songs state;
c36994199c5e Initial revision
darius
parents:
diff changeset
419
c36994199c5e Initial revision
darius
parents:
diff changeset
420 set tmp [lindex [lindex [array get songs *:listid:$id] 1] 0];
c36994199c5e Initial revision
darius
parents:
diff changeset
421 log "%s" "Queue - '$songs($tmp:name)' by '$songs($tmp:author)' ($tmp)";
c36994199c5e Initial revision
darius
parents:
diff changeset
422
c36994199c5e Initial revision
darius
parents:
diff changeset
423 n_write "QUEUE [split $tmp {:}]";
c36994199c5e Initial revision
darius
parents:
diff changeset
424 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
425
c36994199c5e Initial revision
darius
parents:
diff changeset
426 if {$rtn(code) != 247} {
c36994199c5e Initial revision
darius
parents:
diff changeset
427 if {$rtn(code) == 510} {
c36994199c5e Initial revision
darius
parents:
diff changeset
428 msg_box "Queue" "You can't have the same\nsong in the queue twice!";
c36994199c5e Initial revision
darius
parents:
diff changeset
429 } else {
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
430 log "%s" "Failed to queue track ($rtn(code) $rtn(data))";
1
c36994199c5e Initial revision
darius
parents:
diff changeset
431 }
c36994199c5e Initial revision
darius
parents:
diff changeset
432 }
c36994199c5e Initial revision
darius
parents:
diff changeset
433 }
c36994199c5e Initial revision
darius
parents:
diff changeset
434
c36994199c5e Initial revision
darius
parents:
diff changeset
435 proc msg_box {title msg} {
c36994199c5e Initial revision
darius
parents:
diff changeset
436 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
437
c36994199c5e Initial revision
darius
parents:
diff changeset
438 catch {destroy .msg};
c36994199c5e Initial revision
darius
parents:
diff changeset
439
c36994199c5e Initial revision
darius
parents:
diff changeset
440 toplevel .msg -class Dialog;
c36994199c5e Initial revision
darius
parents:
diff changeset
441 wm title .msg $title;
c36994199c5e Initial revision
darius
parents:
diff changeset
442 wm iconname .msg $title;
c36994199c5e Initial revision
darius
parents:
diff changeset
443
c36994199c5e Initial revision
darius
parents:
diff changeset
444 # text region
c36994199c5e Initial revision
darius
parents:
diff changeset
445 frame .msg.frame;
c36994199c5e Initial revision
darius
parents:
diff changeset
446 pack .msg.frame -side top -fill both -expand yes;
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
447 text .msg.frame.text -font fixed -yscroll ".msg.frame.scroll set" -wrap none;
1
c36994199c5e Initial revision
darius
parents:
diff changeset
448 scrollbar .msg.frame.scroll -command ".msg.frame.text yview";
c36994199c5e Initial revision
darius
parents:
diff changeset
449 pack .msg.frame.text -side left -expand y -fill both;
c36994199c5e Initial revision
darius
parents:
diff changeset
450 pack .msg.frame.scroll -side right -fill y;
c36994199c5e Initial revision
darius
parents:
diff changeset
451
c36994199c5e Initial revision
darius
parents:
diff changeset
452 # close button
c36994199c5e Initial revision
darius
parents:
diff changeset
453 button .msg.close -text "Close" -command "destroy .msg";
c36994199c5e Initial revision
darius
parents:
diff changeset
454 pack .msg.close -side bottom -fill x;
c36994199c5e Initial revision
darius
parents:
diff changeset
455
c36994199c5e Initial revision
darius
parents:
diff changeset
456 # read text into the text widget
c36994199c5e Initial revision
darius
parents:
diff changeset
457 .msg.frame.text insert end $msg;
c36994199c5e Initial revision
darius
parents:
diff changeset
458 }
c36994199c5e Initial revision
darius
parents:
diff changeset
459
c36994199c5e Initial revision
darius
parents:
diff changeset
460 proc about_box {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
461 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
462
c36994199c5e Initial revision
darius
parents:
diff changeset
463 catch {destroy .about};
c36994199c5e Initial revision
darius
parents:
diff changeset
464
c36994199c5e Initial revision
darius
parents:
diff changeset
465 toplevel .about -class Dialog;
c36994199c5e Initial revision
darius
parents:
diff changeset
466 wm title .about "About...";
c36994199c5e Initial revision
darius
parents:
diff changeset
467 wm iconname .about "About";
c36994199c5e Initial revision
darius
parents:
diff changeset
468
c36994199c5e Initial revision
darius
parents:
diff changeset
469 # text region
c36994199c5e Initial revision
darius
parents:
diff changeset
470 frame .about.frame;
c36994199c5e Initial revision
darius
parents:
diff changeset
471 pack .about.frame -side top -fill both -expand yes;
c36994199c5e Initial revision
darius
parents:
diff changeset
472 text .about.frame.text -font fixed -height 10 -width 40 -yscroll ".about.frame.scroll set" \
c36994199c5e Initial revision
darius
parents:
diff changeset
473 -wrap none;
c36994199c5e Initial revision
darius
parents:
diff changeset
474 scrollbar .about.frame.scroll -command ".about.frame.text yview";
c36994199c5e Initial revision
darius
parents:
diff changeset
475 pack .about.frame.text -side left -expand y;
c36994199c5e Initial revision
darius
parents:
diff changeset
476 pack .about.frame.scroll -side right -fill y;
c36994199c5e Initial revision
darius
parents:
diff changeset
477
c36994199c5e Initial revision
darius
parents:
diff changeset
478 # close button
c36994199c5e Initial revision
darius
parents:
diff changeset
479 button .about.close -text "Close" -command "destroy .about";
c36994199c5e Initial revision
darius
parents:
diff changeset
480 pack .about.close -side bottom -fill x;
c36994199c5e Initial revision
darius
parents:
diff changeset
481
c36994199c5e Initial revision
darius
parents:
diff changeset
482 # read text into the text widget
c36994199c5e Initial revision
darius
parents:
diff changeset
483 .about.frame.text insert end "Mserv Client\n";
c36994199c5e Initial revision
darius
parents:
diff changeset
484 .about.frame.text insert end "Copyright Daniel O'Connor 2000\n";
c36994199c5e Initial revision
darius
parents:
diff changeset
485 .about.frame.text insert end "\n";
c36994199c5e Initial revision
darius
parents:
diff changeset
486 .about.frame.text insert end "http://www.dons.net.au/~darius/\n";
c36994199c5e Initial revision
darius
parents:
diff changeset
487 }
c36994199c5e Initial revision
darius
parents:
diff changeset
488
c36994199c5e Initial revision
darius
parents:
diff changeset
489 proc set_vol {vol} {
c36994199c5e Initial revision
darius
parents:
diff changeset
490 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
491
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
492 set cookie [acquire_lock];
1
c36994199c5e Initial revision
darius
parents:
diff changeset
493 n_write "VOLUME $vol"
c36994199c5e Initial revision
darius
parents:
diff changeset
494 n_getrtn rtn;
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
495 release_lock $cookie;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
496
1
c36994199c5e Initial revision
darius
parents:
diff changeset
497 if {$rtn(code) != 255} {
c36994199c5e Initial revision
darius
parents:
diff changeset
498 log "%s" "Couldn't set volume ($rtn(code) $rtn(data))";
c36994199c5e Initial revision
darius
parents:
diff changeset
499 }
c36994199c5e Initial revision
darius
parents:
diff changeset
500 }
c36994199c5e Initial revision
darius
parents:
diff changeset
501
c36994199c5e Initial revision
darius
parents:
diff changeset
502 proc rate_song {rate} {
c36994199c5e Initial revision
darius
parents:
diff changeset
503 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
504
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
505 set cookie [acquire_lock];
1
c36994199c5e Initial revision
darius
parents:
diff changeset
506 n_write "RATE $rate";
c36994199c5e Initial revision
darius
parents:
diff changeset
507 n_getrtn rtn;
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
508 release_lock $cookie;
1
c36994199c5e Initial revision
darius
parents:
diff changeset
509
c36994199c5e Initial revision
darius
parents:
diff changeset
510 if {$rtn(code) != 270} {
c36994199c5e Initial revision
darius
parents:
diff changeset
511 log "%s" "Failed to get rate song ($rtn(code) $rtn(data))";
c36994199c5e Initial revision
darius
parents:
diff changeset
512 }
c36994199c5e Initial revision
darius
parents:
diff changeset
513
c36994199c5e Initial revision
darius
parents:
diff changeset
514 }
c36994199c5e Initial revision
darius
parents:
diff changeset
515
c36994199c5e Initial revision
darius
parents:
diff changeset
516 proc control_player {cmd} {
c36994199c5e Initial revision
darius
parents:
diff changeset
517 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
518
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
519 set cookie [acquire_lock];
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
520 log "%s" "Writing $cmd";
1
c36994199c5e Initial revision
darius
parents:
diff changeset
521 n_write "$cmd";
c36994199c5e Initial revision
darius
parents:
diff changeset
522 n_getrtn rtn;
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
523 release_lock $cookie;
1
c36994199c5e Initial revision
darius
parents:
diff changeset
524
c36994199c5e Initial revision
darius
parents:
diff changeset
525 log "%s" "Control Got $rtn(code) $rtn(data)";
c36994199c5e Initial revision
darius
parents:
diff changeset
526 }
c36994199c5e Initial revision
darius
parents:
diff changeset
527
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
528 proc gui_top {} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
529 global state;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
530
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
531 set cookie [acquire_lock];
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
532 n_write "TOP"
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
533 n_getrtn rtn;
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
534 release_lock $cookie;
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
535
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
536 set msg "List of songs most likely to be played next\n\n";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
537
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
538 foreach t $rtn(lines) {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
539 set tmp [split $t \011];
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
540 append msg "[lindex $tmp 0]%\t[lindex $tmp 4] by [lindex $tmp 3]\n";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
541 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
542
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
543 msg_box "Top Listing" $msg;
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
544 }
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
545
1
c36994199c5e Initial revision
darius
parents:
diff changeset
546 proc gui_updatesongs {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
547 global state songs;
c36994199c5e Initial revision
darius
parents:
diff changeset
548
c36994199c5e Initial revision
darius
parents:
diff changeset
549 .top.tlist.list delete 0 end;
c36994199c5e Initial revision
darius
parents:
diff changeset
550
c36994199c5e Initial revision
darius
parents:
diff changeset
551 set tmp "";
c36994199c5e Initial revision
darius
parents:
diff changeset
552
c36994199c5e Initial revision
darius
parents:
diff changeset
553 foreach tag [array names songs "*:id"] {
c36994199c5e Initial revision
darius
parents:
diff changeset
554 set a $songs($tag);
c36994199c5e Initial revision
darius
parents:
diff changeset
555 lappend tmp [list $a $songs($a:name) $songs($a:author) $songs($a:albumname)];
c36994199c5e Initial revision
darius
parents:
diff changeset
556 }
c36994199c5e Initial revision
darius
parents:
diff changeset
557
c36994199c5e Initial revision
darius
parents:
diff changeset
558 switch -- $state(sortmode) {
c36994199c5e Initial revision
darius
parents:
diff changeset
559 "Title" {
c36994199c5e Initial revision
darius
parents:
diff changeset
560 set idx 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
561 }
c36994199c5e Initial revision
darius
parents:
diff changeset
562
c36994199c5e Initial revision
darius
parents:
diff changeset
563 "Artist" {
c36994199c5e Initial revision
darius
parents:
diff changeset
564 set idx 2;
c36994199c5e Initial revision
darius
parents:
diff changeset
565 }
c36994199c5e Initial revision
darius
parents:
diff changeset
566
c36994199c5e Initial revision
darius
parents:
diff changeset
567 "Album" {
c36994199c5e Initial revision
darius
parents:
diff changeset
568 set idx 3;
c36994199c5e Initial revision
darius
parents:
diff changeset
569 }
c36994199c5e Initial revision
darius
parents:
diff changeset
570
c36994199c5e Initial revision
darius
parents:
diff changeset
571 default {
c36994199c5e Initial revision
darius
parents:
diff changeset
572 set idx 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
573 }
c36994199c5e Initial revision
darius
parents:
diff changeset
574 }
c36994199c5e Initial revision
darius
parents:
diff changeset
575 set tmp [lsort -dictionary -index $idx $tmp];
c36994199c5e Initial revision
darius
parents:
diff changeset
576
c36994199c5e Initial revision
darius
parents:
diff changeset
577 foreach a [array names songs *:listid:*] {
c36994199c5e Initial revision
darius
parents:
diff changeset
578 unset songs($a);
c36994199c5e Initial revision
darius
parents:
diff changeset
579 }
c36994199c5e Initial revision
darius
parents:
diff changeset
580
c36994199c5e Initial revision
darius
parents:
diff changeset
581 set i 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
582 foreach a $tmp {
c36994199c5e Initial revision
darius
parents:
diff changeset
583 .top.tlist.list insert end "'[lindex $a 1]' by '[lindex $a 2]' on '[lindex $a 3]'"
c36994199c5e Initial revision
darius
parents:
diff changeset
584 set songs([lindex $a 0]:listid:$i) $a;
c36994199c5e Initial revision
darius
parents:
diff changeset
585 incr i;
c36994199c5e Initial revision
darius
parents:
diff changeset
586 }
c36994199c5e Initial revision
darius
parents:
diff changeset
587 }
c36994199c5e Initial revision
darius
parents:
diff changeset
588
c36994199c5e Initial revision
darius
parents:
diff changeset
589 proc gui_updatequeue {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
590 global state songs queue;
c36994199c5e Initial revision
darius
parents:
diff changeset
591
c36994199c5e Initial revision
darius
parents:
diff changeset
592 log "%s" "Updating queue";
c36994199c5e Initial revision
darius
parents:
diff changeset
593
c36994199c5e Initial revision
darius
parents:
diff changeset
594 .bot.queue.list delete 0 end;
c36994199c5e Initial revision
darius
parents:
diff changeset
595
c36994199c5e Initial revision
darius
parents:
diff changeset
596 con_getqueue queue;
c36994199c5e Initial revision
darius
parents:
diff changeset
597
c36994199c5e Initial revision
darius
parents:
diff changeset
598 foreach tag [lsort [array names queue]] {
c36994199c5e Initial revision
darius
parents:
diff changeset
599 .bot.queue.list insert end "'$songs($queue($tag):name)' by '$songs($queue($tag):author)' on '$songs($queue($tag):albumname)'";
c36994199c5e Initial revision
darius
parents:
diff changeset
600 }
c36994199c5e Initial revision
darius
parents:
diff changeset
601 }
c36994199c5e Initial revision
darius
parents:
diff changeset
602
c36994199c5e Initial revision
darius
parents:
diff changeset
603 proc gui_delqueue {id} {
c36994199c5e Initial revision
darius
parents:
diff changeset
604 global queue;
c36994199c5e Initial revision
darius
parents:
diff changeset
605
c36994199c5e Initial revision
darius
parents:
diff changeset
606 if {$id == ""} {
c36994199c5e Initial revision
darius
parents:
diff changeset
607 return;
c36994199c5e Initial revision
darius
parents:
diff changeset
608 }
c36994199c5e Initial revision
darius
parents:
diff changeset
609
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
610 set cookie [acquire_lock];
1
c36994199c5e Initial revision
darius
parents:
diff changeset
611 n_write "UNQUEUE [split $queue($id) {:}]";
c36994199c5e Initial revision
darius
parents:
diff changeset
612 n_getrtn rtn;
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
613 release_lock $cookie;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
614
1
c36994199c5e Initial revision
darius
parents:
diff changeset
615 if {$rtn(code) != 254} {
c36994199c5e Initial revision
darius
parents:
diff changeset
616 log "%s" "Failed to remove $id ($queue($id))";
c36994199c5e Initial revision
darius
parents:
diff changeset
617 msg_box "Queue" "Failed to dequeue the song";
c36994199c5e Initial revision
darius
parents:
diff changeset
618 }
c36994199c5e Initial revision
darius
parents:
diff changeset
619 }
c36994199c5e Initial revision
darius
parents:
diff changeset
620
c36994199c5e Initial revision
darius
parents:
diff changeset
621 proc gui_updateinfo {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
622 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
623
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
624 set cookie [acquire_lock];
1
c36994199c5e Initial revision
darius
parents:
diff changeset
625 n_write "VOLUME";
c36994199c5e Initial revision
darius
parents:
diff changeset
626 n_getrtn rtn;
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
627 release_lock $cookie;
1
c36994199c5e Initial revision
darius
parents:
diff changeset
628
c36994199c5e Initial revision
darius
parents:
diff changeset
629 if {$rtn(code) != 235} {
c36994199c5e Initial revision
darius
parents:
diff changeset
630 set vol "??";
c36994199c5e Initial revision
darius
parents:
diff changeset
631 } else {
c36994199c5e Initial revision
darius
parents:
diff changeset
632 set vol "[lindex [lindex $rtn(lines) 0] 0]";
c36994199c5e Initial revision
darius
parents:
diff changeset
633 }
c36994199c5e Initial revision
darius
parents:
diff changeset
634
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
635 set cookie [acquire_lock];
1
c36994199c5e Initial revision
darius
parents:
diff changeset
636 n_write "INFO";
c36994199c5e Initial revision
darius
parents:
diff changeset
637 n_getrtn rtn;
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
638 release_lock $cookie;
1
c36994199c5e Initial revision
darius
parents:
diff changeset
639
c36994199c5e Initial revision
darius
parents:
diff changeset
640 if {$rtn(code) == 246} {
c36994199c5e Initial revision
darius
parents:
diff changeset
641 set data [split [lindex $rtn(lines) 0] "\t"];
c36994199c5e Initial revision
darius
parents:
diff changeset
642 set author [lindex $data 4];
c36994199c5e Initial revision
darius
parents:
diff changeset
643 set title [lindex $data 5];
c36994199c5e Initial revision
darius
parents:
diff changeset
644 set length [lindex $data 14];
c36994199c5e Initial revision
darius
parents:
diff changeset
645 set album [lindex $data 3];
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
646 set rate1 [lindex $data 9];
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
647 set rate2 [lindex $data 10];
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
648 set misc [lindex $data 15];
1
c36994199c5e Initial revision
darius
parents:
diff changeset
649 } else {
c36994199c5e Initial revision
darius
parents:
diff changeset
650 set author "N/A";
c36994199c5e Initial revision
darius
parents:
diff changeset
651 set title "N/A";
c36994199c5e Initial revision
darius
parents:
diff changeset
652 set length "N/A";
c36994199c5e Initial revision
darius
parents:
diff changeset
653 set album "N/A";
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
654 set rate1 "N/A";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
655 set rate2 "N/A";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
656 set misc "N/A";
1
c36994199c5e Initial revision
darius
parents:
diff changeset
657 if {$rtn(code) != 401} {
c36994199c5e Initial revision
darius
parents:
diff changeset
658 log "%s" "Failed to get track info ($rtn(code) $rtn(data))";
c36994199c5e Initial revision
darius
parents:
diff changeset
659 }
c36994199c5e Initial revision
darius
parents:
diff changeset
660 }
c36994199c5e Initial revision
darius
parents:
diff changeset
661
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
662 set cookie [acquire_lock];
1
c36994199c5e Initial revision
darius
parents:
diff changeset
663 n_write "STATUS";
c36994199c5e Initial revision
darius
parents:
diff changeset
664 n_getrtn rtn;
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
665 release_lock $cookie;
1
c36994199c5e Initial revision
darius
parents:
diff changeset
666
c36994199c5e Initial revision
darius
parents:
diff changeset
667 if {$rtn(code) != 222} {
c36994199c5e Initial revision
darius
parents:
diff changeset
668 set left "x:xx";
c36994199c5e Initial revision
darius
parents:
diff changeset
669 set played "x:xx";
c36994199c5e Initial revision
darius
parents:
diff changeset
670 } else {
c36994199c5e Initial revision
darius
parents:
diff changeset
671 set played [lindex [split [lindex $rtn(lines) 0] "\t"] 8];
c36994199c5e Initial revision
darius
parents:
diff changeset
672
c36994199c5e Initial revision
darius
parents:
diff changeset
673 # scan $played "%d:%d" played_m played_s;
c36994199c5e Initial revision
darius
parents:
diff changeset
674 # set played [expr ($played_m * 60) + $played_s];
c36994199c5e Initial revision
darius
parents:
diff changeset
675 # scan $length "%d:%f" len_m len_s;
c36994199c5e Initial revision
darius
parents:
diff changeset
676 # set len [expr ($len_m * 60) + $len_s];
c36994199c5e Initial revision
darius
parents:
diff changeset
677
c36994199c5e Initial revision
darius
parents:
diff changeset
678 # set left [expr $len - $played];
c36994199c5e Initial revision
darius
parents:
diff changeset
679 # set left_m [expr int($left / 60)];
c36994199c5e Initial revision
darius
parents:
diff changeset
680 # set left [format "%02d:%02d" $left_m [expr int($left - ($left_m * 60))]];
c36994199c5e Initial revision
darius
parents:
diff changeset
681 }
c36994199c5e Initial revision
darius
parents:
diff changeset
682
c36994199c5e Initial revision
darius
parents:
diff changeset
683 .top.tinfo.sub.author configure -text "Author: $author";
c36994199c5e Initial revision
darius
parents:
diff changeset
684 .top.tinfo.sub.title configure -text "Title: $title";
c36994199c5e Initial revision
darius
parents:
diff changeset
685 .top.tinfo.sub.length configure -text "Length: $length";
c36994199c5e Initial revision
darius
parents:
diff changeset
686 .top.tinfo.sub.time configure -text "Time: $played";
c36994199c5e Initial revision
darius
parents:
diff changeset
687 .top.tinfo.sub.album configure -text "Album: $album";
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
688 .top.tinfo.sub.misc configure -text "Misc: $misc";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
689 .top.tinfo.sub.rate1 configure -text "Rating: $rate1";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
690 .top.tinfo.sub.rate2 configure -text "Temporally Adjusted: $rate2";
1
c36994199c5e Initial revision
darius
parents:
diff changeset
691 .top.tinfo.sub.vol configure -text "Volume: $vol";
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
692
1
c36994199c5e Initial revision
darius
parents:
diff changeset
693 }
c36994199c5e Initial revision
darius
parents:
diff changeset
694
c36994199c5e Initial revision
darius
parents:
diff changeset
695 proc con_getqueue {queuevar} {
c36994199c5e Initial revision
darius
parents:
diff changeset
696 upvar $queuevar queue;
c36994199c5e Initial revision
darius
parents:
diff changeset
697
c36994199c5e Initial revision
darius
parents:
diff changeset
698 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
699
c36994199c5e Initial revision
darius
parents:
diff changeset
700 catch {unset queue};
c36994199c5e Initial revision
darius
parents:
diff changeset
701
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
702 set cookie [acquire_lock];
1
c36994199c5e Initial revision
darius
parents:
diff changeset
703 n_write "QUEUE"
c36994199c5e Initial revision
darius
parents:
diff changeset
704 n_getrtn rtn;
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
705 release_lock $cookie;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
706
1
c36994199c5e Initial revision
darius
parents:
diff changeset
707 if {$rtn(code) == 225} {
c36994199c5e Initial revision
darius
parents:
diff changeset
708 set i 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
709 foreach line $rtn(lines) {
c36994199c5e Initial revision
darius
parents:
diff changeset
710 set foo [split $line \011];
c36994199c5e Initial revision
darius
parents:
diff changeset
711 set id "[lindex $foo 1]:[lindex $foo 2]";
c36994199c5e Initial revision
darius
parents:
diff changeset
712
c36994199c5e Initial revision
darius
parents:
diff changeset
713 set queue($i) $id;
c36994199c5e Initial revision
darius
parents:
diff changeset
714 incr i;
c36994199c5e Initial revision
darius
parents:
diff changeset
715 }
c36994199c5e Initial revision
darius
parents:
diff changeset
716 } elseif {$rtn(code) == 404} {
c36994199c5e Initial revision
darius
parents:
diff changeset
717 log "%s" "Queue empty";
c36994199c5e Initial revision
darius
parents:
diff changeset
718 } else {
c36994199c5e Initial revision
darius
parents:
diff changeset
719 log "%s" "Failed to get queue ($rtn(code) $rtn(data))";
c36994199c5e Initial revision
darius
parents:
diff changeset
720 }
c36994199c5e Initial revision
darius
parents:
diff changeset
721 }
c36994199c5e Initial revision
darius
parents:
diff changeset
722
c36994199c5e Initial revision
darius
parents:
diff changeset
723 proc con_getsongs {songsvar albumsvar} {
c36994199c5e Initial revision
darius
parents:
diff changeset
724 upvar $songsvar songs;
c36994199c5e Initial revision
darius
parents:
diff changeset
725 upvar $albumsvar albums;
c36994199c5e Initial revision
darius
parents:
diff changeset
726
c36994199c5e Initial revision
darius
parents:
diff changeset
727 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
728
c36994199c5e Initial revision
darius
parents:
diff changeset
729 catch { unset songs };
c36994199c5e Initial revision
darius
parents:
diff changeset
730
c36994199c5e Initial revision
darius
parents:
diff changeset
731 foreach i [array names albums "*:"] {
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
732 set cookie [acquire_lock];
1
c36994199c5e Initial revision
darius
parents:
diff changeset
733 n_write "TRACKS $albums($i)";
c36994199c5e Initial revision
darius
parents:
diff changeset
734 n_getrtn rtn;
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
735 release_lock $cookie;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
736
1
c36994199c5e Initial revision
darius
parents:
diff changeset
737 if {$rtn(code) != "228"} {
c36994199c5e Initial revision
darius
parents:
diff changeset
738 error "Got bogus response to track request ($rtn(code) $rtn(data))";
c36994199c5e Initial revision
darius
parents:
diff changeset
739 }
c36994199c5e Initial revision
darius
parents:
diff changeset
740
c36994199c5e Initial revision
darius
parents:
diff changeset
741 foreach trk $rtn(lines) {
c36994199c5e Initial revision
darius
parents:
diff changeset
742 set foo [split $trk \011];
c36994199c5e Initial revision
darius
parents:
diff changeset
743 if {[llength $foo] != 6} {
c36994199c5e Initial revision
darius
parents:
diff changeset
744 continue;
c36994199c5e Initial revision
darius
parents:
diff changeset
745 }
c36994199c5e Initial revision
darius
parents:
diff changeset
746
c36994199c5e Initial revision
darius
parents:
diff changeset
747 set albid [lindex $foo 0];
c36994199c5e Initial revision
darius
parents:
diff changeset
748 set num [lindex $foo 1]
c36994199c5e Initial revision
darius
parents:
diff changeset
749 set songs($albid:$num:id) "$albid:$num";
c36994199c5e Initial revision
darius
parents:
diff changeset
750 set songs($albid:$num:author) [lindex $foo 2];
c36994199c5e Initial revision
darius
parents:
diff changeset
751 set songs($albid:$num:name) [lindex $foo 3];
c36994199c5e Initial revision
darius
parents:
diff changeset
752 set songs($albid:$num:rating) [lindex $foo 4];
c36994199c5e Initial revision
darius
parents:
diff changeset
753 set songs($albid:$num:length) [lindex $foo 5];
c36994199c5e Initial revision
darius
parents:
diff changeset
754 set songs($albid:$num:albumname) $albums($albid:name);
c36994199c5e Initial revision
darius
parents:
diff changeset
755 }
c36994199c5e Initial revision
darius
parents:
diff changeset
756 }
c36994199c5e Initial revision
darius
parents:
diff changeset
757
c36994199c5e Initial revision
darius
parents:
diff changeset
758 }
c36994199c5e Initial revision
darius
parents:
diff changeset
759
c36994199c5e Initial revision
darius
parents:
diff changeset
760 proc con_getalbums {albumsvar} {
c36994199c5e Initial revision
darius
parents:
diff changeset
761 upvar $albumsvar albums;
c36994199c5e Initial revision
darius
parents:
diff changeset
762
c36994199c5e Initial revision
darius
parents:
diff changeset
763 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
764
c36994199c5e Initial revision
darius
parents:
diff changeset
765 catch {unset albums};
c36994199c5e Initial revision
darius
parents:
diff changeset
766
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
767 set cookie [acquire_lock];
1
c36994199c5e Initial revision
darius
parents:
diff changeset
768 n_write "ALBUMS";
c36994199c5e Initial revision
darius
parents:
diff changeset
769 n_getrtn rtn;
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
770 release_lock $cookie;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
771
1
c36994199c5e Initial revision
darius
parents:
diff changeset
772 if {$rtn(code) != 227} {
c36994199c5e Initial revision
darius
parents:
diff changeset
773 error "Server gave bogus response to album request ($rtn(code) $rtn(data))";
c36994199c5e Initial revision
darius
parents:
diff changeset
774 }
c36994199c5e Initial revision
darius
parents:
diff changeset
775
c36994199c5e Initial revision
darius
parents:
diff changeset
776 foreach alb $rtn(lines) {
c36994199c5e Initial revision
darius
parents:
diff changeset
777 set foo [split $alb \011];
c36994199c5e Initial revision
darius
parents:
diff changeset
778 set id [lindex $foo 0];
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
779 if {$id == ""} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
780 continue;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
781 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
782 set albums($id:) $id;
1
c36994199c5e Initial revision
darius
parents:
diff changeset
783 set albums($id:author) [lindex $foo 1];
c36994199c5e Initial revision
darius
parents:
diff changeset
784 set albums($id:name) [lindex $foo 2];
c36994199c5e Initial revision
darius
parents:
diff changeset
785
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
786 # log "%s" "Album $id, ID '$albums($id:)' called '$albums($id:name)' by '$albums($id:author)'";
1
c36994199c5e Initial revision
darius
parents:
diff changeset
787 }
c36994199c5e Initial revision
darius
parents:
diff changeset
788 }
c36994199c5e Initial revision
darius
parents:
diff changeset
789
c36994199c5e Initial revision
darius
parents:
diff changeset
790 proc update_timer {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
791
c36994199c5e Initial revision
darius
parents:
diff changeset
792 gui_updateinfo;
c36994199c5e Initial revision
darius
parents:
diff changeset
793
c36994199c5e Initial revision
darius
parents:
diff changeset
794 after 900 update_timer;
c36994199c5e Initial revision
darius
parents:
diff changeset
795 }
c36994199c5e Initial revision
darius
parents:
diff changeset
796
c36994199c5e Initial revision
darius
parents:
diff changeset
797 proc con_mserv {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
798 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
799
c36994199c5e Initial revision
darius
parents:
diff changeset
800 # Close old FD
c36994199c5e Initial revision
darius
parents:
diff changeset
801 catch {close state(serv_fd)};
c36994199c5e Initial revision
darius
parents:
diff changeset
802 catch {unset state(serv_fd)};
c36994199c5e Initial revision
darius
parents:
diff changeset
803
c36994199c5e Initial revision
darius
parents:
diff changeset
804 catch {fileevent $state(serv_fd) readable ""};
c36994199c5e Initial revision
darius
parents:
diff changeset
805 set state(serv_fd) [ socket $state(host) $state(port) ];
c36994199c5e Initial revision
darius
parents:
diff changeset
806 set state(pushbuf) "";
c36994199c5e Initial revision
darius
parents:
diff changeset
807 fileevent $state(serv_fd) readable n_rtinput;
c36994199c5e Initial revision
darius
parents:
diff changeset
808 fconfigure $state(serv_fd) -blocking 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
809
c36994199c5e Initial revision
darius
parents:
diff changeset
810 # Greeting from server
c36994199c5e Initial revision
darius
parents:
diff changeset
811 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
812 puts $rtn(data);
c36994199c5e Initial revision
darius
parents:
diff changeset
813 if {$rtn(code) != "200"} {
c36994199c5e Initial revision
darius
parents:
diff changeset
814 error "Server failed to send greeting";
c36994199c5e Initial revision
darius
parents:
diff changeset
815 }
c36994199c5e Initial revision
darius
parents:
diff changeset
816
c36994199c5e Initial revision
darius
parents:
diff changeset
817 # Login
c36994199c5e Initial revision
darius
parents:
diff changeset
818 n_write "USER $state(user)"
c36994199c5e Initial revision
darius
parents:
diff changeset
819 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
820 if {$rtn(code) != "201"} {
c36994199c5e Initial revision
darius
parents:
diff changeset
821 error "Server failed to send password request";
c36994199c5e Initial revision
darius
parents:
diff changeset
822 }
c36994199c5e Initial revision
darius
parents:
diff changeset
823
c36994199c5e Initial revision
darius
parents:
diff changeset
824 n_write "PASS $state(pass) RTCOMPUTER";
c36994199c5e Initial revision
darius
parents:
diff changeset
825 n_getrtn rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
826 if {$rtn(code) == "507"} {
c36994199c5e Initial revision
darius
parents:
diff changeset
827 error "Server rejected our credentials";
c36994199c5e Initial revision
darius
parents:
diff changeset
828 }
c36994199c5e Initial revision
darius
parents:
diff changeset
829
c36994199c5e Initial revision
darius
parents:
diff changeset
830 if {$rtn(code) != "202"} {
c36994199c5e Initial revision
darius
parents:
diff changeset
831 error "Unknown response to PASS command - $rtn(code) $rtn(data)"
c36994199c5e Initial revision
darius
parents:
diff changeset
832 }
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
833
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
834 set state(lock) "";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
835 # trace variable state(lock) rw foobar;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
836
1
c36994199c5e Initial revision
darius
parents:
diff changeset
837 log "%s" "Logged in";
c36994199c5e Initial revision
darius
parents:
diff changeset
838 }
c36994199c5e Initial revision
darius
parents:
diff changeset
839
c36994199c5e Initial revision
darius
parents:
diff changeset
840 proc n_write {text} {
c36994199c5e Initial revision
darius
parents:
diff changeset
841 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
842
c36994199c5e Initial revision
darius
parents:
diff changeset
843 puts $state(serv_fd) $text;
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
844 flush $state(serv_fd);
1
c36994199c5e Initial revision
darius
parents:
diff changeset
845
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
846 if {[eof $state(serv_fd)]} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
847 log "%s" "Server went away on write";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
848 exit 1;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
849 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
850 # log "%s" "Wrote - $text";
1
c36994199c5e Initial revision
darius
parents:
diff changeset
851 }
c36994199c5e Initial revision
darius
parents:
diff changeset
852
c36994199c5e Initial revision
darius
parents:
diff changeset
853 proc n_rthandler {code data} {
c36994199c5e Initial revision
darius
parents:
diff changeset
854 global songs;
c36994199c5e Initial revision
darius
parents:
diff changeset
855
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
856 log "%s" "Got RT - $code $data";
1
c36994199c5e Initial revision
darius
parents:
diff changeset
857
c36994199c5e Initial revision
darius
parents:
diff changeset
858 switch -- $code {
c36994199c5e Initial revision
darius
parents:
diff changeset
859 600 {
c36994199c5e Initial revision
darius
parents:
diff changeset
860 log "%s" "User '$data' connected";
c36994199c5e Initial revision
darius
parents:
diff changeset
861 }
c36994199c5e Initial revision
darius
parents:
diff changeset
862
c36994199c5e Initial revision
darius
parents:
diff changeset
863 601 {
c36994199c5e Initial revision
darius
parents:
diff changeset
864 log "%s" "User '$data' disconnected";
c36994199c5e Initial revision
darius
parents:
diff changeset
865 }
c36994199c5e Initial revision
darius
parents:
diff changeset
866
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
867 240 -
1
c36994199c5e Initial revision
darius
parents:
diff changeset
868 618 -
c36994199c5e Initial revision
darius
parents:
diff changeset
869 619 -
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
870 620 -
1
c36994199c5e Initial revision
darius
parents:
diff changeset
871 622 -
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
872 623 -
1
c36994199c5e Initial revision
darius
parents:
diff changeset
873 627 -
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
874 628 -
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
875 629 {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
876 log "%s" "Updating queue on idle";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
877 gui_updatequeue;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
878 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
879
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
880 default {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
881 log "%s" "Got unhandled RT event $code $data";
1
c36994199c5e Initial revision
darius
parents:
diff changeset
882 }
c36994199c5e Initial revision
darius
parents:
diff changeset
883 }
c36994199c5e Initial revision
darius
parents:
diff changeset
884 }
c36994199c5e Initial revision
darius
parents:
diff changeset
885
c36994199c5e Initial revision
darius
parents:
diff changeset
886 proc n_rtinput {} {
c36994199c5e Initial revision
darius
parents:
diff changeset
887 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
888
c36994199c5e Initial revision
darius
parents:
diff changeset
889 set rth "";
c36994199c5e Initial revision
darius
parents:
diff changeset
890
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
891 while {1} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
892 set line [gets $state(serv_fd)];
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
893 if {[eof $state(serv_fd)]} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
894 log "%s" "Server went away on read";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
895 exit 1;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
896 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
897 # log "%s" "Read - $line";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
898 if {$line == ""} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
899 return;
1
c36994199c5e Initial revision
darius
parents:
diff changeset
900 }
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
901 # Check for RT text
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
902 set foo [split $line "\t"];
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
903 if {[string index $line 0] == "="} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
904 lappend state(rtlist) [list [string range [lindex $foo 0] 1 3] [lrange $foo 1 end]];
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
905 # log "%s" "RT event";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
906 } else {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
907 lappend state(tmpphrase) $line
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
908 if {$line == "."} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
909 set state(pushbuf) [linsert $state(pushbuf) 0 $state(tmpphrase)];
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
910 # log "%s" "push buffer - '$state(tmpphrase)'";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
911 set state(tmpphrase) "";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
912 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
913 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
914 }
1
c36994199c5e Initial revision
darius
parents:
diff changeset
915 }
c36994199c5e Initial revision
darius
parents:
diff changeset
916
c36994199c5e Initial revision
darius
parents:
diff changeset
917 proc n_getrtn {var} {
c36994199c5e Initial revision
darius
parents:
diff changeset
918 upvar $var rtn;
c36994199c5e Initial revision
darius
parents:
diff changeset
919 global state;
c36994199c5e Initial revision
darius
parents:
diff changeset
920
c36994199c5e Initial revision
darius
parents:
diff changeset
921 set gotcode 0;
c36994199c5e Initial revision
darius
parents:
diff changeset
922 catch {unset rtn(code)};
c36994199c5e Initial revision
darius
parents:
diff changeset
923 catch {unset rtn(data)};
c36994199c5e Initial revision
darius
parents:
diff changeset
924 catch {unset rtn(lines)}
c36994199c5e Initial revision
darius
parents:
diff changeset
925
c36994199c5e Initial revision
darius
parents:
diff changeset
926 while {[llength $state(pushbuf)] == 0} {
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
927 # log "%s" "Sleeping for data";
1
c36994199c5e Initial revision
darius
parents:
diff changeset
928 vwait state(pushbuf);
c36994199c5e Initial revision
darius
parents:
diff changeset
929 }
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
930
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
931 # log "%s" "Waking up, got $state(pushbuf)";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
932
1
c36994199c5e Initial revision
darius
parents:
diff changeset
933 set buf [lindex $state(pushbuf) 0];
c36994199c5e Initial revision
darius
parents:
diff changeset
934 set state(pushbuf) [lrange $state(pushbuf) 1 end];
c36994199c5e Initial revision
darius
parents:
diff changeset
935
c36994199c5e Initial revision
darius
parents:
diff changeset
936 while {1} {
c36994199c5e Initial revision
darius
parents:
diff changeset
937 if {[llength $buf] == 0} {
c36994199c5e Initial revision
darius
parents:
diff changeset
938 break;
c36994199c5e Initial revision
darius
parents:
diff changeset
939 }
c36994199c5e Initial revision
darius
parents:
diff changeset
940
c36994199c5e Initial revision
darius
parents:
diff changeset
941 set line [lindex $buf 0];
c36994199c5e Initial revision
darius
parents:
diff changeset
942 set buf [lrange $buf 1 end];
c36994199c5e Initial revision
darius
parents:
diff changeset
943
c36994199c5e Initial revision
darius
parents:
diff changeset
944 if {[string index $line 0] == "."} {
c36994199c5e Initial revision
darius
parents:
diff changeset
945 break;
c36994199c5e Initial revision
darius
parents:
diff changeset
946 }
c36994199c5e Initial revision
darius
parents:
diff changeset
947
c36994199c5e Initial revision
darius
parents:
diff changeset
948 if {$gotcode == 0} {
c36994199c5e Initial revision
darius
parents:
diff changeset
949 set rtn(code) [string range $line 0 2];
c36994199c5e Initial revision
darius
parents:
diff changeset
950 set rtn(data) [string range $line 4 end];
c36994199c5e Initial revision
darius
parents:
diff changeset
951 set gotcode 1;
c36994199c5e Initial revision
darius
parents:
diff changeset
952 continue;
c36994199c5e Initial revision
darius
parents:
diff changeset
953 }
c36994199c5e Initial revision
darius
parents:
diff changeset
954
c36994199c5e Initial revision
darius
parents:
diff changeset
955 lappend rtn(lines) $line;
c36994199c5e Initial revision
darius
parents:
diff changeset
956 }
c36994199c5e Initial revision
darius
parents:
diff changeset
957
c36994199c5e Initial revision
darius
parents:
diff changeset
958 if {$gotcode == 0} {
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
959 log "%s" "Failed to parse phrase (got . before server response)";
1
c36994199c5e Initial revision
darius
parents:
diff changeset
960 }
c36994199c5e Initial revision
darius
parents:
diff changeset
961 }
c36994199c5e Initial revision
darius
parents:
diff changeset
962
c36994199c5e Initial revision
darius
parents:
diff changeset
963 ##################################################################
c36994199c5e Initial revision
darius
parents:
diff changeset
964 # Log a message to stderr
c36994199c5e Initial revision
darius
parents:
diff changeset
965 #
c36994199c5e Initial revision
darius
parents:
diff changeset
966 proc log {format args} {
c36994199c5e Initial revision
darius
parents:
diff changeset
967 # Extract the calling function's name
3
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
968 if {[catch {set fname [lindex [info level -1] 0]}]} {
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
969 set fname "unknown";
4343bc7f829a Add config file/registry support.
darius
parents: 1
diff changeset
970 }
1
c36994199c5e Initial revision
darius
parents:
diff changeset
971
c36994199c5e Initial revision
darius
parents:
diff changeset
972 # Evaluate the supplied format string and arguments
c36994199c5e Initial revision
darius
parents:
diff changeset
973 if {[catch {set csm [eval format {$format} $args]} msg]} {
c36994199c5e Initial revision
darius
parents:
diff changeset
974 set csm "bad log message. format='$format' args='$args'";
c36994199c5e Initial revision
darius
parents:
diff changeset
975 }
c36994199c5e Initial revision
darius
parents:
diff changeset
976
c36994199c5e Initial revision
darius
parents:
diff changeset
977 # Emit the message
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
978 catch {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
979 puts stderr "[clock format [clock seconds] -format {%y/%m/%d %H:%M:%S} -gmt yes]:$fname: $csm";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
980 flush stderr;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
981 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
982 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
983
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
984 proc acquire_lock {} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
985 global state;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
986
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
987 # Extract the calling function's name
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
988 if {[catch {set fname [lindex [info level -1] 0]}]} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
989 set fname "unknown";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
990 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
991
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
992 # log "%s" "Acquiring lock for $fname";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
993
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
994 set foo 0;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
995
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
996 if {[info exists state(lock)]} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
997 while {$state(lock) != ""} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
998 set foo 1;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
999 log "%s" "$fname waiting for lock (held by [lindex $state(lock) 1])";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1000 vwait state(lock);
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1001 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1002
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1003 if {$foo == 1} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1004 log "%s" "Lock released";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1005 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1006
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1007 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1008
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1009 set cookie [clock clicks];
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1010 set state(lock) [list $cookie $fname];
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1011 # log "%s" "Lock acquired";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1012 return $cookie;
1
c36994199c5e Initial revision
darius
parents:
diff changeset
1013 }
c36994199c5e Initial revision
darius
parents:
diff changeset
1014
5
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1015 proc release_lock {cookie} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1016 global state;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1017
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1018 # Extract the calling function's name
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1019 if {[catch {set fname [lindex [info level -1] 0]}]} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1020 set fname "unknown";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1021 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1022
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1023 if {$cookie == ""} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1024 log "%s" "$fname trying to unlock without being locked";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1025 exit 1;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1026 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1027
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1028 if {$cookie != [lindex $state(lock) 0]} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1029 log "%s" "Lock cookie not matched!";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1030 exit 1;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1031 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1032
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1033 if {$fname != [lindex $state(lock) 1]} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1034 log "%s" "$fname tried to free [lindex $state(lock) 1]'s lock!";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1035 exit 1;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1036 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1037
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1038 set state(lock) "";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1039 # log "%s" "Lock for $fname now free";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1040 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1041
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1042 proc foobar {n1 n2 op} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1043 global state;
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1044
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1045 log "%s" "$op, now $state(lock)";
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1046 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1047
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1048 if {[catch {main} msg]} {
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1049 catch {tk_dialog .dummy "Error!" $msg error 0 "OK"};
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1050 }
b6c495b5eeda - Use wish8.2
darius
parents: 4
diff changeset
1051