annotate mservtk.tcl @ 8:81b36e5b725b default tip

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