1 # ui-edit.tcl --
2 #
3 # Creates the UI for editing a session announcement.
4 #
5 # Copyright (c) 1998-2002 The Regents of the University of California.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are met:
10 #
11 # A. Redistributions of source code must retain the above copyright notice,
12 # this list of conditions and the following disclaimer.
13 # B. Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16 # C. Neither the names of the copyright holders nor the names of its
17 # contributors may be used to endorse or promote products derived from this
18 # software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 import TextEntry SDPMediaEditWindow SDPTimeEditWindow mashutils
32
33 #FIXME
34 import SDPParser
35
36 # This class constructs and manages a toplevel window that can be
37 # used to edit the contents of a session announcement described
38 # with SDP. It is used by nsdr for editing existing announcements
39 # as well as for creating new announcement.
40 Class SDPEditWindow
41
42 # Creates a new window for editing the message in the SDPMessage
43 # object <i>msg</i>. If <i>msg</i> is an empty string, the window
44 # is used to construct a new session announcement and being
45 # announcing it. <i>src</i> is a ProgramSource object that is does
46 # the actual advertisement.
47 SDPEditWindow public init {msg src args} {
48 eval $self next $args
49
50 $self instvar win_ msg_ src_
51 set win_ .new$self
52 set msg_ $msg
53 set src_ $src
54
55 $self buildwin $win_
56 }
57
58 # Destroys this window. Invoked when the Cancel button is pressed.
59 SDPEditWindow public destroy {} {
60 $self instvar mediawin_ timewin_ win_
61 $self instvar title_ url_ email_ phone_
62
63 foreach o "$mediawin_ $timewin_ $title_ $url_ $email_ $phone_" {
64 delete $o
65 }
66 destroy $win_
67 }
68
69 # Constructs the user interface elements for a new session announcement
70 # editing window.
71 SDPEditWindow private buildwin w {
72 $self instvar msg_ src_ switchbutton_ mediawin_ timewin_ simple_
73
74 toplevel $w
75 wm title $w "nsdr: Edit Program"
76
77 $self instvar notebook_
78 set notebook_ [notebook $w.n -width 500 -height 200 \
79 -tabheight 27 -tabpadx 2 -bd 2 \
80 -font [$self get_option smallfont]]
81 pack $notebook_ -side bottom -fill both -expand yes -padx 2 -pady 2
82
83 set f $w.buttons
84 frame $f
85 set switchbutton_ [button $f.switch -command "$self toggle-advanced"]
86 button $f.cancel -text "Cancel" -command "delete $self"
87 pack $f.switch $f.cancel -side left
88 if {$msg_ == ""} {
89 button $f.create -text "Create" -command "$self create"
90 pack $f.create -side left
91 } else {
92 button $f.change -text "Change" -command "$self change"
93 pack $f.change -side left
94 }
95 pack $f -side bottom -before $notebook_
96
97 $notebook_ addTab "Session Information"
98 set f [frame $notebook_.info]
99 $notebook_ addFrame $f 0 -expand yes -fill both -padx 2 -pady 2
100 $self build-info $f
101
102 $notebook_ addTab "Media Streams"
103 set f [frame $notebook_.streams]
104 $notebook_ addFrame $f 1 -expand yes -fill both -padx 2 -pady 2
105 set mediawin_ [new SDPMediaEditWindow $f $msg_ $src_]
106
107 $notebook_ addTab "Times"
108 set f [frame $notebook_.times]
109 $notebook_ addFrame $f 2 -expand yes -fill both -padx 2 -pady 2
110 set timewin_ [new SDPTimeEditWindow $f $msg_]
111
112 #FIXME encryption tab
113
114 set simple_ [$self yesno simpleInterface]
115 if {$simple_ == 0} {
116 $switchbutton_ configure -text "Simple"
117 } else {
118 $switchbutton_ configure -text "Advanced"
119 }
120
121 $notebook_ tabPress 0
122 }
123
124 SDPEditWindow private toggle-advanced {} {
125 $self instvar simple_ switchbutton_ mediawin_ timewin_
126 if {$simple_ == 0} {
127 set simple_ 1
128 $switchbutton_ configure -text "Advanced"
129 $mediawin_ build-simple
130 $timewin_ build-simple
131 } else {
132 set simple_ 0
133 $switchbutton_ configure -text "Simple"
134 $mediawin_ build-advanced
135 $timewin_ build-advanced
136 }
137 }
138
139 # Constructs the portion of the SDP editing window that is used to
140 # edit session-wide information (e.g., title, description, etc...)
141 SDPEditWindow private build-info w {
142 $self instvar msg_
143
144 $self instvar title_ desc_ url_ email_ phone_
145 if {$msg_ == ""} {
146 set title "New Session"
147 set desc ""
148 set url ""
149
150 set name [$self get_option nsdrName]
151 set addr [$self get_option rtpEmail]
152 if {$addr == "" } {
153 set addr [email_heuristic]
154 }
155 set email "$name <$addr>"
156 set phone "$name [$self get_option nsdrPhone]"
157 } else {
158 set title [$msg_ field_value s]
159 set desc [$msg_ field_value i]
160 set url [$msg_ field_value u]
161 set email [$msg_ field_value e]
162 set phone [$msg_ field_value p]
163 }
164
165 # title
166 set f $w.title
167 frame $f
168 label $f.l -text "Session Title:"
169 pack $f.l -side left
170 set title_ [new TextEntry "$self notnull" $f.entry $title]
171 pack $f.entry -side left -fill x -expand yes
172 pack $f -side top -fill x
173
174 # session description
175 set f $w.desc
176 frame $f
177 label $f.l -text "Session Description:"
178 pack $f.l -side top
179 set desc_ $f.t
180 text $f.t -bg white -height 4 -font [$self get_option entryFont]
181 $f.t insert 0.0 $desc
182 pack $f.t -fill both
183 pack $f -fill x
184
185 # web page
186 set f $w.web
187 frame $f
188 label $f.l -text "Web Page:" -anchor e
189 pack $f.l -side left
190 set url_ [new TextEntry "1" $f.e $url]
191 pack $f.e -side left -fill x -expand yes
192 button $f.b -text "Test" \
193 -command "[Application instance] gourl \[$url_ entry-value\]"
194 pack $f.b
195 pack $f -fill x
196
197 # e-mail address
198 set f $w.mail
199 frame $f
200 label $f.l -text "E-Mail:" -anchor e
201 pack $f.l -side left
202 set email_ [new TextEntry "1" $f.e $email]
203 pack $f.e -side left -fill x -expand yes
204 pack $f -fill x
205
206 # phone
207 set f $w.phone
208 frame $f
209 label $f.l -text "Phone:" -anchor e
210 pack $f.l -side left
211 set phone_ [new TextEntry "1" $f.e $phone]
212 pack $f.e -side left -fill x -expand yes
213 pack $f -fill x
214 }
215
216 # Used as a callback for a TextEntry object, rejects an empty string.
217 SDPEditWindow private notnull s {
218 if {$s == ""} {
219 return 1
220 }
221 return 0
222 }
223
224 # Called when the Create button is pressed. Creates a new SDPMessage
225 # object from what has been entered in the user interface and hands
226 # it to the ProgramSource to start advertising.
227 SDPEditWindow private create {} {
228 $self instvar title_ timewin_ mediawin_ src_
229
230 set base "v=0\n"
231 append base "o=[$self generate_o]\n"
232 append base "s=[string trim [$title_ entry-value]]\n"
233
234 set time [$timewin_ buildmsg]
235
236 # b=, z=, k= fields? (bandwidth, time zone adjustment, encryption key)
237 set media [$mediawin_ buildmsgs]
238 if {[llength $media] == 0} {
239 puts "returning coz media is '$media'"
240 return
241 }
242
243 # base announcement contains all info
244 set text $base
245 append text [$self build_details]
246 append text $time
247 append text "a=tool:Nsdr-[version]\n"
248 #FIXME other global attrs?
249 append text [lindex $media 0]
250
251 set msgs [list $text]
252
253 #further announcements don't contain details
254 foreach m [lrange $media 1 end] {
255 set text $base
256 append text $time
257 append text "a=Nsdr-[version]\n"
258 append text $m
259 lappend msgs $text
260 }
261
262 #FIXME why does SDPParser need to be instantiated?
263 set parser [new SDPParser]
264 set objs {}
265 foreach msg $msgs {
266 lappend objs [$parser parse $msg]
267 }
268 destroy $parser
269 set prog [eval new Program $objs]
270
271 #puts "\n\nbuilt messages:\n[join $msgs "\n"]"
272 set announcer [[Application instance] set announcer_]
273 $announcer announce $prog
274 }
275
276 #
277 SDPEditWindow private build_details {} {
278 $self instvar desc_ url_ email_ phone_
279
280 set text ""
281 set desc [$desc_ get 0.0 end]
282 regsub -all "\n|\r" $desc " " desc
283 set desc [string trim $desc]
284 if {$desc != ""} {
285 append text "i=$desc\n"
286 }
287
288 set url [string trim [$url_ entry-value]]
289 if {$url != ""} {
290 append text "u=$url\n"
291 }
292
293 set email [string trim [$email_ entry-value]]
294 if {$email != ""} {
295 append text "e=$email\n"
296 }
297
298 set phone [string trim [$phone_ entry-value]]
299 if {$phone != ""} {
300 append text "p=$phone\n"
301 }
302
303 #FIXME
304 after 1 "delete $self"
305
306 return $text
307 }
308
309 #
310 SDPEditWindow private generate_o {} {
311 set user [user_heuristic]
312 # ntp time is recommended for these; is local time okay?
313 set sid [clock seconds]
314 set version [clock seconds]
315 set addr "IN IP4 [localaddr]"
316 return "$user $sid $version $addr"
317 }
318
319 # Called when the Change button is pressed. Modifies the SDPMessage
320 # object that describes this session and then notifies the ProgramSource
321 # to modify what is being announced.
322 SDPEditWindow private change {} {
323 #FIXME
324 puts "change"
325 }
326
327
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.