2 # Find wish, even though the path is unknown, and run it on this script. \
5 # Dillo configuration script, by Bob Thomson (rjt@ee.ed.ac.uk).
7 # The settings are kept in the global array called $prefs[].
8 # It is indexed by key name.
10 # use the file in the home directory, or in /etc ??
11 proc find_source_file {} {
15 # this make some of the more awkward options into a convenient form
16 proc unpack_options {} {
17 global prefs width height colours
18 regexp {([0-9]+)[xX]([0-9]+)} $prefs(geometry) ignore width height
20 # tcl/tk doesn't like C-style colours
21 foreach c {link_color visited_color bg_color text_color} {
22 regsub {0[xX]} $prefs($c) \# colours($c)
26 # the reverse of unpack_options
27 proc pack_options {} {
28 global prefs width height colours
29 set prefs(geometry) ${width}x${height}
31 # dillo doesn't like tcl/tk-style colours
32 foreach c {link_color visited_color bg_color text_color} {
33 regsub \# $colours($c) "0x" prefs($c)
37 # update the display for new settings
40 .entries.b18 configure -bg $colours(link_color) \
41 -activebackground $colours(link_color)
42 .entries.b19 configure -bg $colours(visited_color) \
43 -activebackground $colours(visited_color)
44 .entries.b20 configure -bg $colours(text_color) \
45 -activebackground $colours(text_color)
46 .entries.b21 configure -bg $colours(bg_color) \
47 -activebackground $colours(bg_color)
50 # set everything to reasonable values
51 proc load_defaults {} {
53 # these values must be the same as the defaults that dillo uses
61 home "http://dillo.sourceforge.net/"
67 visited_color 0x800080
70 force_visited_color NO
88 # read from file f, which must be readable
89 proc read_a_file {f} {
94 # this next line skips comments, and finds options
95 if {![regexp {^[ \t]*\#} $line]
96 && [regexp {([^= \t]+)[ \t]*=[ \t]*(.+)} $line ignore a b]} {
104 global prefs oldprefs
105 # this next line makes sure all parameters are set, if not in the file
107 if {[file exists "~/.dillo/dillorc"]
108 &&[file readable "~/.dillo/dillorc"]} {
109 read_a_file "~/.dillo/dillorc"
111 # read /etc/dillorc if no per-user config file
112 if {[file exists "/etc/dillorc"]
113 &&[file readable "/etc/dillorc"]} {
114 read_a_file "/etc/dillorc"
118 array set oldprefs [array get prefs]
121 proc write_prefs {} {
122 global prefs oldprefs
125 # create the config dir?
126 if {[file exists "~/.dillo"] == 0} {
127 file mkdir "~/.dillo"
130 if {![file exists "~/.dillo/dillorc"]
131 || [file writable "~/.dillo/dillorc"]} {
132 set fh [open "~/.dillo/dillorc" "w"]
133 set keys [array names prefs]
135 # only write the line if there is a value
136 if {[regexp {[^ \t]} $prefs($k)]} {
137 puts $fh ${k}=$prefs($k)
142 tk_dialog .broken "ERROR" \
143 "The dillo configuration file \"~/.dillo/dillorc\" is unwritable!"\
146 array set oldprefs [array get prefs]
149 # leave, possibly popping up a dialogue asking whether or not to save
151 global prefs oldprefs
155 foreach {k v} [array get prefs] {
156 if {$v != $oldprefs($k)} {
163 set button [tk_dialog .savepopup "SAVE?" \
164 "Save changes before quitting?"\
165 "" 0 "Yes" "No" "Cancel"]
166 if {$button == 0} write_prefs
167 if {$button == 0 || $button == 1} exit
173 # construct the top-level window
174 proc build_window {} {
181 label .entries.l1 -text "Window width"
182 entry .entries.e1 -textvariable width -width 5 \
183 -validate key -vcmd {string is integer %P}
184 label .entries.l2 -text "Window height"
185 entry .entries.e2 -textvariable height -width 5 \
186 -validate key -vcmd {string is integer %P}
187 label .entries.l3 -text "Font scale factor"
188 entry .entries.e3 -textvariable prefs(font_factor) -width 5 \
189 -validate key -vcmd {string is double %P}
190 checkbutton .boxes.c4 -text "Use oblique fonts" -onvalue YES -offvalue NO \
191 -variable prefs(use_oblique)
192 checkbutton .boxes.c5 -text "Pop-up text for images" -onvalue YES \
193 -offvalue NO -variable prefs(show_alt)
194 label .urls.l6 -text "Home page URL"
195 entry .urls.e4 -textvariable prefs(home) -width 64
196 checkbutton .boxes.c7 -text "Allow white backgrounds" -onvalue YES \
197 -offvalue NO -variable prefs(allow_white_bg)
198 checkbutton .boxes.c8 -text "Show \"back\" button" -onvalue YES \
199 -offvalue NO -variable prefs(show_back)
200 checkbutton .boxes.c9 -text "Show \"forward\" button" -onvalue YES \
201 -offvalue NO -variable prefs(show_forw)
202 checkbutton .boxes.c10 -text "Show \"home\" button" -onvalue YES \
203 -offvalue NO -variable prefs(show_home)
204 checkbutton .boxes.c11 -text "Show \"reload\" button" -onvalue YES \
205 -offvalue NO -variable prefs(show_reload)
206 checkbutton .boxes.c12 -text "Show \"save\" button" -onvalue YES \
207 -offvalue NO -variable prefs(show_save)
208 checkbutton .boxes.c13 -text "Show \"stop\" button" -onvalue YES \
209 -offvalue NO -variable prefs(show_stop)
210 checkbutton .boxes.c14 -text "Show menu bar" -onvalue YES -offvalue NO \
211 -variable prefs(show_menubar)
212 checkbutton .boxes.c15 -text "Show URL bar" -onvalue YES -offvalue NO \
213 -variable prefs(show_url)
214 checkbutton .boxes.c16 -text "Show progress box" -onvalue YES \
215 -offvalue NO -variable prefs(show_progress_box)
216 checkbutton .boxes.c17 -text "Always use default colours" -onvalue YES \
217 -offvalue NO -variable prefs(force_my_colors)
218 checkbutton .boxes.c23 -text "Override visited link colours" -onvalue YES \
219 -offvalue NO -variable prefs(force_visited_color)
220 checkbutton .boxes.c18 -text "Use small icons" -onvalue YES -offvalue NO \
221 -variable prefs(small_icons)
222 checkbutton .boxes.c19 -text "Limit the width of text" -onvalue YES \
223 -offvalue NO -variable prefs(limit_text_width)
224 checkbutton .boxes.c20 -text "Cache decompressed images" -onvalue YES \
225 -offvalue NO -variable prefs(use_dicache)
226 checkbutton .boxes.c21 -text "Show clear URL button" -onvalue YES \
227 -offvalue NO -variable prefs(show_clear_url)
228 checkbutton .boxes.c22 -text "Allow transient dialogs" -onvalue YES \
229 -offvalue NO -variable prefs(transient_dialogs)
230 label .entries.l29 -text "Panel size"
231 tk_optionMenu .entries.o1 prefs(panel_size) tiny medium large
232 label .entries.l22 -text "Link colour"
233 # note that named colours work in tcl/tk; eg. "blue" will not break this
234 button .entries.b18 -bg $colours(link_color) \
235 -activebackground $colours(link_color) \
237 set c [tk_chooseColor -initialcolor $colours(link_color) \
238 -title "Set link colour"]
240 set colours(link_color) $c
241 .entries.b18 configure -bg $c -activebackground $c
244 label .entries.l23 -text "Visited link colour"
245 button .entries.b19 -bg $colours(visited_color) -activebackground \
246 $colours(visited_color) \
248 set c [tk_chooseColor -initialcolor $colours(visited_color) \
249 -title "Set visited link colour"]
251 set colours(visited_color) $c
252 .entries.b19 configure -bg $c -activebackground $c
255 label .entries.l24 -text "Text colour"
256 button .entries.b20 -bg $colours(text_color) \
257 -activebackground $colours(text_color) \
259 set c [tk_chooseColor -initialcolor $colours(text_color) \
260 -title "Set text colour"]
262 set colours(text_color) $c
263 .entries.b20 configure -bg $c -activebackground $c
266 label .entries.l25 -text "Background colour"
267 button .entries.b21 -bg $colours(bg_color) \
268 -activebackground $colours(bg_color) \
270 set c [tk_chooseColor -initialcolor $colours(bg_color) \
271 -title "Set background colour"]
273 set colours(bg_color) $c
274 .entries.b21 configure -bg $c -activebackground $c
277 label .urls.l26 -text "Proxy URL"
278 entry .urls.e27 -textvariable prefs(http_proxy) -width 64
279 label .urls.l28 -text "Unproxied domain"
280 entry .urls.e29 -textvariable prefs(no_proxy) -width 64
282 button .buttons.b1 -text "Use defaults" -command {
286 button .buttons.b2 -text "Reload" -command {
290 button .buttons.b3 -text "Save" -command write_prefs
291 button .buttons.b4 -text "Quit" -command quit_save
293 grid .buttons.b1 -row 0 -column 1
294 grid .buttons.b2 -row 0 -column 2
295 grid .buttons.b3 -row 0 -column 3
296 grid .buttons.b4 -row 0 -column 4
298 grid .boxes.c8 -row 0 -column 0 -sticky w
299 grid .boxes.c9 -row 1 -column 0 -sticky w
300 grid .boxes.c10 -row 2 -column 0 -sticky w
301 grid .boxes.c11 -row 3 -column 0 -sticky w
302 grid .boxes.c12 -row 4 -column 0 -sticky w
303 grid .boxes.c13 -row 5 -column 0 -sticky w
304 grid .boxes.c14 -row 6 -column 0 -sticky w
305 grid .boxes.c15 -row 7 -column 0 -sticky w
306 grid .boxes.c21 -row 8 -column 0 -sticky w
307 grid .boxes.c16 -row 9 -column 0 -sticky w
308 grid .boxes.c4 -row 0 -column 1 -sticky w
309 grid .boxes.c5 -row 1 -column 1 -sticky w
310 grid .boxes.c7 -row 2 -column 1 -sticky w
311 grid .boxes.c17 -row 3 -column 1 -sticky w
312 grid .boxes.c23 -row 4 -column 1 -sticky w
313 grid .boxes.c18 -row 5 -column 1 -sticky w
314 grid .boxes.c22 -row 6 -column 1 -sticky w
315 grid .boxes.c19 -row 7 -column 1 -sticky w
316 grid .boxes.c20 -row 8 -column 1 -sticky w
318 grid .entries.l1 -row 0 -column 0 -sticky e
319 grid .entries.e1 -row 0 -column 1 -sticky w
320 grid .entries.l2 -row 1 -column 0 -sticky e
321 grid .entries.e2 -row 1 -column 1 -sticky w
322 grid .entries.l3 -row 2 -column 0 -sticky e
323 grid .entries.e3 -row 2 -column 1 -sticky w
324 grid .entries.l22 -row 3 -column 0 -sticky e
325 grid .entries.b18 -row 3 -column 1 -sticky w
326 grid .entries.l23 -row 4 -column 0 -sticky e
327 grid .entries.b19 -row 4 -column 1 -sticky w
328 grid .entries.l24 -row 5 -column 0 -sticky e
329 grid .entries.b20 -row 5 -column 1 -sticky w
330 grid .entries.l25 -row 6 -column 0 -sticky e
331 grid .entries.b21 -row 6 -column 1 -sticky w
332 grid .entries.l29 -row 7 -column 0 -sticky e
333 grid .entries.o1 -row 7 -column 1 -sticky w
335 grid .urls.l6 -row 0 -column 0 -sticky e
336 grid .urls.e4 -row 0 -column 1 -sticky "ew"
337 grid .urls.l26 -row 1 -column 0 -sticky e
338 grid .urls.e27 -row 1 -column 1 -sticky "ew"
339 grid .urls.l28 -row 2 -column 0 -sticky e
340 grid .urls.e29 -row 2 -column 1 -sticky "ew"
342 grid .buttons -row 2 -column 0 -columnspan 2 -sticky "ew"
343 grid .urls -row 1 -column 0 -columnspan 2 -sticky "ew"
344 grid .boxes -row 0 -column 1 -sticky e
345 grid .entries -row 0 -column 0 -sticky w
346 # pack .buttons -side bottom -fill x -expand 1
347 # pack .urls -side bottom -fill x -expand 1
348 # pack .boxes -side left
349 # pack .entries -side right