annotate mservtk.tcl @ 6:b370e0bbe050

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