annotate mservtk.tcl @ 3:4343bc7f829a

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