annotate mservtk.tcl @ 4:32f624fc18cc

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