1#!/bin/sh
2#\
3exec XXX_WISH_XXX "$0" ${1+"$@"}
4
5#
6#
7#  Copyright (c) 1994-1998 A & A Custom Software.
8#  All rights reserved.
9#
10#  Redistribution and use in source and binary forms, with or without
11#  modification, are permitted provided that the following conditions
12#  are met:
13#  1. Redistributions of source code must retain the above copyright
14#     notice, this list of conditions and the following disclaimer.
15#  2. Redistributions in binary form must reproduce the above copyright
16#     notice, this list of conditions and the following disclaimer in the
17#     documentation and/or other materials provided with the distribution.
18#  3. All advertising materials mentioning features or use of this software
19#     must display the following acknowledgement:
20#       This product includes software developed by A & A Custom Software
21#       and its contributors.
22#  4. Neither the name of A & A Custom Software nor the names of its
23#     contributors may be used to endorse or promote products derived from this
24#     software without specific prior written permission.
25#
26#  THIS SOFTWARE IS PROVIDED BY A & A CUSTOM SOFTWARE AND CONTRIBUTORS ``AS IS''
27#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29#  ARE DISCLAIMED.  IN NO EVENT SHALL A & A CUSTOM SOFTWARE OR CONTRIBUTORS BE
30#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36#  POSSIBILITY OF SUCH DAMAGE.
37#
38# $Id: tkhylafax.unpatched,v 1.1 1998/01/04 23:11:02 abm Exp $
39#
40# Main for tkhylafax.
41#
42
43#
44# Globals
45#
46
47set Th_Info(lwidth) 15 ;# standard label length
48set Th_Info(ewidth) 15 ;# standard entry length
49set Th_Info(plen) 25 ;# phone field length
50set Th_Info(nlen) 36 ;# name field length
51set Th_Info(flen) 36 ;# from field length
52set Th_Info(clen) 36 ;# company field length
53set Th_Info(llen) 41 ;# location field length
54set Th_Info(rlen) 41 ;# regarding field length
55set Th_Info(libraryPath) XXX_TKHYLAFAX_XXX ;# tkhylafax library path
56
57proc tkhylafax_main { args } {
58
59    global Th_Info
60    global Comments
61
62    # Make the main panel.
63    set Th_Info(main) [mkFrame . main]
64    set Th_Info(menubar) [mkFrame $Th_Info(main) menubar {-side top -fill x}]
65    set Th_Info(docs) [mkFrame $Th_Info(main) docs]
66    set Th_Info(oper2) [mkFrame $Th_Info(main) oper2 {-side top -fill x}]
67    set Th_Info(cover) [mkFrame $Th_Info(main) cover {-side top -fill both}]
68    set Th_Info(schedule) [mkFrame $Th_Info(main) schedule \
69        {-side top -fill both}]
70    set Th_Info(oper1) [mkFrame $Th_Info(main) oper1 {-side bottom -fill x}]
71
72    # Make the menubuttons, menu items and set bindings
73    # File Menubutton
74    set Th_Info(fileMB) [mkMenuButton $Th_Info(menubar) file File]
75    mkMenuItem $Th_Info(fileMB) Browser {fileSelect .browser}
76    mkMenuItem $Th_Info(fileMB) {Enter File to Fax} fileToFax
77    mkMenuItem $Th_Info(fileMB) {Fax Server Status} {svrStatus .qstatus}
78    mkMenuItem $Th_Info(fileMB) Send sendFax
79    mkMenuItem $Th_Info(fileMB) {View Batch} {viewBatch .viewbatch}
80    mkMenuItem $Th_Info(fileMB) {Send Batch} sendBatch 5
81    mkMenuItem $Th_Info(fileMB) {Preview Cover Page} previewCover
82    mkMenuItem $Th_Info(fileMB) {Clear Cover Sheet} clearCover
83    mkMenuSeparator $Th_Info(fileMB)
84    mkMenuItem $Th_Info(fileMB) {Exit} {destroy .} 1
85
86    # Phone Menubutton
87    set Th_Info(phoneMB) [mkMenuButton $Th_Info(menubar) phone Phone]
88    mkMenuItem $Th_Info(phoneMB) Rolodex {rolodex .rolodex}
89    mkMenuItem $Th_Info(phoneMB) {Add Curent} updateRolodex
90    mkMenuItem $Th_Info(phoneMB) {Delete Current} deleteEntry
91    mkMenuItem $Th_Info(phoneMB) {Select Batch} {listBatches .listbatches}
92    mkMenuItem $Th_Info(phoneMB) {Clear Current Batch} {clearBatch .viewbatch}
93
94    # Options Menubutton
95    set Th_Info(optionsMB) [mkMenuButton $Th_Info(menubar) options Options]
96    mkMenuItem $Th_Info(optionsMB) Preferences {preferencesDialog .pref}
97    mkMenuSeparator $Th_Info(optionsMB)
98    mkRadioMenuItem $Th_Info(optionsMB) {196 lines/inch} \
99        Th_Info(faxResolution) { -m }
100    mkRadioMenuItem $Th_Info(optionsMB) {98 lines/inch} \
101        Th_Info(faxResolution) { -l }
102    mkMenuSeparator $Th_Info(optionsMB)
103    mkCheckMenuItem $Th_Info(optionsMB) {Notify when Complete} \
104        Th_Info(notifyOnCompletion) { -D }
105    mkCheckMenuItem $Th_Info(optionsMB) {Notify on Retry} \
106        Th_Info(notifyOnRetry) { -R }
107    mkMenuSeparator $Th_Info(optionsMB)
108    mkCheckMenuItem $Th_Info(optionsMB) {Initiate Poll} Th_Info(initiatePoll) \
109        { -p }
110    mkMenuSeparator $Th_Info(optionsMB)
111    if {![info exists Th_Info(coverPages)] ||
112        [llength $Th_Info(coverPages)] == 0} {
113        mkCheckMenuItem $Th_Info(optionsMB) {No Cover Page} \
114	   Th_Info(coverPage) { -n }
115    } else {
116        foreach cvrpg $Th_Info(coverPages) {
117	   mkRadioMenuItem $Th_Info(optionsMB) $cvrpg Th_Info(coverPage) \
118	       " -C $cvrpg "
119        }
120        mkRadioMenuItem $Th_Info(optionsMB) {No Cover Page} \
121	   Th_Info(coverPage) { -n }
122        set Th_Info(coverPage) " -C [lindex $Th_Info(coverPages) 0] "
123    }
124
125    # Make the listbox for documents to fax
126    mkLabel $Th_Info(docs) label {-side top -anchor n} -text {Documents to Fax}
127    set Th_Info(docsLB) [mkListbox $Th_Info(docs) -selectmode browse]
128
129    # Make the edit operations buttons
130    mkButton $Th_Info(oper2) edit {-side left} -text {Edit Document} \
131        -command {editDocument $Th_Info(docsLB)}
132    mkButton $Th_Info(oper2) remove {-side left} -text {Remove Document} \
133        -command {removeDocument $Th_Info(docsLB)}
134    mkButton $Th_Info(oper2) clear {-side left} -text {Clear List} \
135        -command {$Th_Info(docsLB) delete 0 end}
136
137    # Make the cover sheet panel
138    mkLabel $Th_Info(cover) label {-side top -anchor n} \
139        -text {Cover Sheet Information}
140    mkLabeledEntry $Th_Info(cover) phone {Fax Number:} Th_Info(phone) \
141        $Th_Info(plen)
142    mkLabeledEntry $Th_Info(cover) name Recipient: Th_Info(name) $Th_Info(nlen)
143    if {! $Th_Info(autoFrom)} {
144	mkLabeledEntry $Th_Info(cover) from From: Th_Info(from) $Th_Info(flen)
145    }
146    mkLabeledEntry $Th_Info(cover) company Company: Th_Info(company) \
147        $Th_Info(clen)
148    mkLabeledEntry $Th_Info(cover) location Location: Th_Info(location) \
149        $Th_Info(llen)
150    mkLabeledEntry $Th_Info(cover) regard Regarding: Th_Info(regard) \
151        $Th_Info(rlen)
152    mkLabeledEntry $Th_Info(cover) ln1 Comments: Comments(ln1) $Th_Info(rlen)
153    for {set i 2} {$i <= $Th_Info(commentLines)} {incr i} {
154        mkLabeledEntry $Th_Info(cover) ln${i} {} Comments(ln${i}) $Th_Info(rlen)
155    }
156
157    # Add some traces for the entry widgets for phone, name and company
158    setTrace Th_Info(phone) isPhoneNumber
159    setTrace Th_Info(phone) "entryInputLenChk $Th_Info(plen)"
160    setTrace Th_Info(name) "entryInputLenChk $Th_Info(nlen)"
161    setTrace Th_Info(company) "entryInputLenChk $Th_Info(clen)"
162
163    # Make the schedule info panel
164    mkLabel $Th_Info(schedule) label {-side top -anchor n} \
165        -text {Scheduling Information}
166
167    mkTransmitDelay $Th_Info(schedule) td
168    mkMaximumRetries $Th_Info(schedule) retry
169
170    # Make general operation buttons
171    mkButton $Th_Info(oper1) send {-side left} -text Send \
172	-command sendFax
173    mkButton $Th_Info(oper1) rolodex {-side left} -text Rolodex  \
174	-command {rolodex .rolodex}
175    mkButton $Th_Info(oper1) add {-side left} -text {Add Current} \
176	-command {updateRolodex}
177    mkButton $Th_Info(oper1) browser {-side left} -text Browser \
178	-command {fileSelect .browser}
179    mkButton $Th_Info(oper1) batch {-side left} -text {Select Batch} \
180	-command {listBatches .listbatches}
181    mkButton $Th_Info(oper1) exit {-side left} -text Exit -command {destroy .}
182    addPreference Th_Info(iconBitmap) iconBitmap
183    catch {wm iconbitmap . @$Th_Info(libraryPath)/$Th_Info(iconBitmap)}
184
185    # Here we collect any command line options that are not preferences
186    # and process them appropriately
187    set filename [getOption file]
188    if {$filename != ""} {
189        $Th_Info(docsLB) insert end $filename
190    }
191
192}
193
194proc mkTransmitDelay { parent frame } {
195
196    global Th_Info
197    frame $parent.$frame
198    pack $parent.$frame -fill x -expand true
199    mkLabel $parent.$frame tdLabel {-side left} -text {Transmit Delay:} \
200        -anchor w -width $Th_Info(lwidth)
201    mkLabel $parent.$frame tdHours {-side left} -text 0 \
202        -anchor w -textvar Th_Info(tdHours)
203    mkLabel $parent.$frame tdColon {-side left} -text {:} -anchor w
204    mkLabel $parent.$frame tdMin {-side left} -text 0 \
205        -anchor w -textvar Th_Info(tdMin)
206
207    mkRepeatButton $parent.$frame subMin {-side right} \
208        -bitmap @$Th_Info(libraryPath)/dn.xbm \
209        -padx 0 -pady 0 -command {incrXmitDelay -5}
210    mkRepeatButton $parent.$frame addMin {-side right} \
211        -bitmap @$Th_Info(libraryPath)/up.xbm \
212        -padx 0 -pady 0 -command {incrXmitDelay 5}
213    return $parent.$frame
214}
215
216proc mkMaximumRetries { parent frame } {
217
218    global Th_Info
219    frame $parent.$frame
220    pack $parent.$frame -fill x -expand true
221    mkLabel $parent.$frame retryLabel {-side left} -text {Maximum Retries:} \
222        -anchor w -width $Th_Info(lwidth)
223    mkLabel $parent.$frame retryCount {-side left} -text 0 \
224        -anchor w -textvar Th_Info(retryCount)
225
226    mkButton $parent.$frame subRetry {-side right} \
227        -bitmap @$Th_Info(libraryPath)/dn.xbm \
228        -padx 0 -pady 0 -command {incrLabelNum Th_Info(retryCount) -1}
229    mkButton $parent.$frame addRetry {-side right} \
230        -bitmap @$Th_Info(libraryPath)/up.xbm \
231        -padx 0 -pady 0 -command {incrLabelNum Th_Info(retryCount)}
232    return $parent.$frame
233}
234
235proc incrXmitDelay { {value 1} } {
236
237    global Th_Info
238    if {$Th_Info(tdHours) == 0 && $Th_Info(tdMin) == 0 && $value < 0} {
239	#tk_dialog .err "Ooops!" "Negative value not allowed." warning 0 OK
240	return
241    }
242
243    #
244    # Adjust time
245    #
246    if {$value > 0} {
247        if {[expr $Th_Info(tdMin) + $value] >= 60} {
248	   incr Th_Info(tdHours) 1
249	   set Th_Info(tdMin) 0
250        } else {
251	   incr Th_Info(tdMin) $value
252        }
253    } else {
254        if {$Th_Info(tdMin) <= 0} {
255	   incr Th_Info(tdHours) -1
256	   set Th_Info(tdMin) [expr 60 + $value]
257        } else {
258	   incr Th_Info(tdMin) $value
259        }
260    }
261}
262
263proc incrLabelNum { textvar {value 1}} {
264
265    global Th_Info
266    if {[set $textvar] == 0 && $value < 0} {
267	#tk_dialog .err "Ooops!" "Negative value not allowed." warning 0 OK
268	return
269    }
270    incr $textvar $value
271}
272
273
274proc editDocument { lb } {
275
276    global Th_Info
277
278    if {![info exists Th_Info(editorCmd)]} {
279         tk_dialog .err "Ooops!" "No editor command was defined." info 0 OK
280         $lb select clear 0 end
281         return
282    }
283
284    set idx [$lb curselection]
285    if {$idx == ""} {
286         return
287    }
288    set entry [$lb get $idx]
289    if {[catch {eval exec $Th_Info(editorCmd) $entry &} err]} {
290         tk_dialog .err "Ooops!" "$err" info 0 OK
291    }
292    $lb select clear 0 end
293}
294
295proc removeDocument { lb } {
296
297    set idx [$lb curselection]
298    if {$idx == ""} {
299         return
300    }
301    $lb delete $idx
302}
303
304#
305# Make a dialog box for user to enter a specific filename, then put
306# it in the list to fax.
307#
308#
309
310proc fileToFax { args } {
311
312    global Th_Info
313
314    set res [dialog_main -message "Enter file to fax. Remember pathnames!"]
315    if {$res != ""} {
316        $Th_Info(docsLB) insert end $res
317    }
318}
319
320#
321# Preview fax cover sheet via ghostview.
322#
323
324proc previewCover { args } {
325
326    set faxcmd "[mkCover] | XXX_GHOSTVIEW_XXX -"
327
328    # Exec it
329    if {[catch {eval exec $faxcmd &} err]} {
330        tk_dialog .err "Ooops!" "$err" questhead 0 OK
331    }
332}
333
334proc clearCover { args } {
335
336    global Th_Info
337    global Comments
338    foreach i {phone name company location regard} {
339        set Th_Info($i) {}
340    }
341    foreach i [array name Comments] {
342        set Comments($i) {}
343    }
344}
345
346proc sendFax { args } {
347
348    global Th_Info
349
350    if {$Th_Info(phone) != "" && $Th_Info(batchDest) != ""} {
351        set res \
352            [tk_dialog .err "Ooops!" "A batch destination AND a cover sheet \
353            destination have been defined! \n\nSelect a fax destination to use"\
354            questhead 0 "Abort" "Cover Sheet" "Batch" "Both"]
355
356        switch -exact -- $res 1 {
357            faxIt
358        } 2 {
359            sendBatch
360        } 3 {
361            # Must do cover sheet first so data isn't lost
362            faxIt
363            sendBatch
364        } default {}
365    } elseif {$Th_Info(phone) != ""} {
366        # Send fax from cover sheet.
367        faxIt
368    } elseif {$Th_Info(batchDest) != ""} {
369        # Send batch destinations.
370        sendBatch
371    } else {
372        # Notify user: where do you want to send a fax?
373        tk_dialog .err "Ooops!" "Huh!?!? \nNo batch destinations are defined \
374            AND no fax number is specified in the cover sheet section!" \
375            questhead 0 OK
376    }
377}
378
379lappend auto_path $Th_Info(libraryPath)
380initPreference $Th_Info(libraryPath)/tkhylafax-defaults
381setOptions
382initRolodex
383initBatch
384tkhylafax_main
385