1 # ui-timeedit.tcl --
2 #
3 # Defines a widget that allows for editing a time and date
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 Combobox
32
33 # Constructs and manages a window that is used to edit the times
34 # at which an SDP session description is active.
35 Class SDPTimeEditWindow
36
37 SDPTimeEditWindow set times_(minute) 60
38 SDPTimeEditWindow set times_(hour) 3600
39 SDPTimeEditWindow set times_(day) 86400
40 SDPTimeEditWindow set times_(week) 604800
41
42 SDPTimeEditWindow set numbers_(one) 1
43 SDPTimeEditWindow set numbers_(two) 2
44 SDPTimeEditWindow set numbers_(three) 3
45 SDPTimeEditWindow set numbers_(four) 4
46 SDPTimeEditWindow set numbers_(five) 5
47 SDPTimeEditWindow set numbers_(six) 6
48 SDPTimeEditWindow set numbers_(seven) 7
49 SDPTimeEditWindow set numbers_(eight) 8
50 SDPTimeEditWindow set numbers_(nine) 9
51 SDPTimeEditWindow set numbers_(ten) 10
52 SDPTimeEditWindow set numbers_(eleven) 11
53 SDPTimeEditWindow set numbers_(twelve) 12
54
55 # should redo as:
56 #
57 # +------------+------------+
58 # | | |
59 # | calendar | repeat |
60 # | | |
61 # +------------+------------+
62 #
63
64 # Creates the user interface elements needed for this window. As
65 # with SDPEditWindow and SDPMediaEditWindow, the times described in
66 # the SDPMessage object <i>msg</i> will be displayed initially or
67 # defaults will be displayed if <i>msg</i> is an empty string.
68 SDPTimeEditWindow public init {w msg} {
69 $self set win_ $w
70 $self set msg_ $msg
71
72 if [$self yesno simpleInterface] {
73 $self build-simple
74 } else {
75 $self build-advanced
76 }
77 }
78
79 SDPTimeEditWindow private build-simple {} {
80 $self instvar win_
81 catch {
82 foreach w [winfo children $win_] { destroy $w }
83 }
84 pack [label $win_.l -text "NEED TO IMPLEMENT SIMPLE INTERFACE"]
85 }
86
87 SDPTimeEditWindow private build-advanced {} {
88 $self instvar win_ msg_ src_
89
90 catch {
91 foreach w [winfo children $win_] { destroy $w }
92 }
93
94 $self instvar startentry_ durationbox_ repeatsbox_
95
96 # start time
97 label $win_.startl -text "Start Time:" -anchor e
98 grid $win_.startl -row 0 -column 0 -sticky ew
99 if {$msg_ == ""} {
100 # round to nearst half hour
101 set now [clock format [expr ([clock seconds]+1)/1800 * 1800] \
102 -format "%I:%M %p %b %d"]
103 } else {
104 if [$msg_ have_field r] {
105 set l [$msg_ field_value r]
106 }
107 set now "FIXME"
108 }
109 set startentry_ [entry $win_.starte]
110 $startentry_ insert 0 $now
111 grid $startentry_ -row 0 -column 1 -sticky ew
112 # button $win_.startb -text "Edit..." -command "$self edit-start"
113 # grid $win_.startb -row 0 -column 2 -sticky ew
114
115 # duration
116 label $win_.durl -text "Duration:" -anchor e
117 grid $win_.durl -row 1 -column 0 -sticky ew
118 if {$msg_ == ""} {
119 set duration "2 hours"
120 } else {
121 set duration "FIXME"
122 }
123 #FIXME
124 set durationbox_ [new Combobox $win_.durc $duration "$self valid-duration" "1 hour" "1 day" "1 week"]
125 grid $win_.durc -row 1 -column 1 -sticky ew
126
127 # repeats
128 label $win_.repl -text "Repeat:" -anchor e
129 grid $win_.repl -row 2 -column 0 -sticky ew
130 #FIXME get current value from msg
131 menubutton $win_.repm -text "No" -anchor w -menu $win_.repm.m \
132 -indicatoron yes -relief raised -bd 2
133 grid $win_.repm -row 2 -column 1 -sticky ew
134 menu $win_.repm.m
135 foreach r {"No" "Daily" "Weekly" "Every Two Weeks"} {
136 $win_.repm.m add command -label $r \
137 -command "$self set-repeat \"$r\""
138 }
139
140 label $win_.repsl -text "for:" -anchor e
141 grid $win_.repsl -row 3 -column 0 -sticky ew
142 #FIXME
143 set repeatsbox_ [new Combobox $win_.repsc "1 Week" "$self valid-duration" \
144 "1 Week" "2 Weeks" "1 Month" "2 Months"]
145 $repeatsbox_ disable
146 grid $win_.repsc -row 3 -column 1 -sticky ew
147 }
148
149 #
150 SDPTimeEditWindow private duration2secs {s} {
151 $class instvar times_ numbers_
152 set l [split $s]
153 if {[llength $l] != 2} {
154 return -1
155 }
156
157 # check if first component is a number
158 set n [lindex $l 0]
159 if {![regexp {[0-9]+} $n]} {
160 # not a literal number, check if it is a spelled out
161 # number (e.g., "one")
162 set n [string tolower $n]
163 if ![info exists numbers_($n)] {
164 return -1
165 }
166 set n $numbers_($n)
167 }
168
169 # check if second component is duration (e.g., "days", "months", etc.)
170 set u [string tolower [lindex $l 1]]
171 set i [string last "s" $u]
172 if {$i != -1} {
173 set u [string range $u 0 [expr $i-1]]
174 }
175 if ![info exists times_($u)] {
176 return -1
177 }
178
179 set n [expr $n * $times_($u)]
180 return $n
181 }
182
183 # Used as a callback for TextEntry widgets. Determines if the
184 # string <i>t</i> is a valid duration (i.e., that is consists of
185 # a number and a unit of time) so that invalid durations cannot be
186 # entered.
187 SDPTimeEditWindow private valid-duration {t} {
188 set s [$self duration2secs $t]
189 if {$s < 0} {
190 return 1
191 }
192 return 0
193
194 }
195
196 # Called when a selection is made in the repeat menu. Enables or
197 # disables the repeat duration menu as necessary.
198 SDPTimeEditWindow private set-repeat {r} {
199 $self instvar win_ repeatsbox_
200 $win_.repm configure -text $r
201 if {$r == "No"} {
202 $repeatsbox_ disable
203 } else {
204 $repeatsbox_ enable
205 }
206
207 #FIXME set menu items on repeat for how long menu appropriately
208 }
209
210 #
211 SDPTimeEditWindow public buildmsg {} {
212 $self instvar startentry_ durationbox_ win_ repeatsbox_
213
214 set start [unix_to_ntp [clock scan [$startentry_ get]]]
215 set duration [$self duration2secs [$durationbox_ get]]
216 set end [format %u [expr $start + $duration]]
217 set text "t=$start $end\n"
218
219 # FIXME handle repeat
220
221 return $text
222 }
223
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.