File: SetFactoryDefaults.tcl

package info (click to toggle)
coccinella 0.96.20-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 13,184 kB
  • sloc: tcl: 124,744; xml: 206; makefile: 66; sh: 62
file content (259 lines) | stat: -rw-r--r-- 8,142 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#  SetFactoryDefaults.tcl ---
#  
#      This file is part of The Coccinella application. 
#      Standard (factory) preferences are set here.
#      These are the hardcoded, application default, values, and can be
#      overridden by the ones in user default file.
#      
#      prefs:       preferences, application global
#      state:       state variables, specific to toplevel whiteboard
#      
#  Copyright (c) 2002-2005  Mats Bengtsson
#  
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#   
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#   
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#  
# $Id: SetFactoryDefaults.tcl,v 1.59 2007-11-24 08:18:27 matben Exp $

package provide FactoryDefaults 1.0

# Hardcoded configureation options:
# 
# How expressive shall we be with message boxes?
set config(talkative) 0

proc FactoryDefaults { } {
    global  prefs this state tmsec 
    global  timingClicksToSecs timingClicksToMilliSecs
    global  kPI kRad2Grad kGrad2Rad kTan225 kTan675
    global  tclwbProtMsg
    
    # If embedded in web browser we have no menubar.
    if {$this(embedded)} {
	set prefs(haveMenus) 0
    } else {
	set prefs(haveMenus) 1
    }
    
    # If we have -compound left -image ... -label ... working.
    set prefs(haveMenuImage) 0
    if {([package vcompare [info tclversion] 8.4] >= 0) &&  \
      ![string equal $this(platform) "macosx"]} {
	set prefs(haveMenuImage) 1
    }
    
    # Shall we run the httpd?
    set prefs(haveHttpd) 1
    if {[string equal $this(platform) "macintosh"]} {
	set prefs(haveHttpd) 0
    }
    
    # Dialog window custom geometries: {pathName wxh+x+y ...}
    set prefs(winGeom) {}
    
    # Same for panes.
    set prefs(paneGeom) {}
    set prefs(sashPos) {}
    
    # ip numbers, port numbers, and names.
    set prefs(remotePort) 8235
        
    # File transport method: putget, http, or si.
    # http and si identical from the whiteboards perspective.
    set prefs(trptMethod) putget
    #set prefs(trptMethod) sipub
        
    # so no server delay is needed
    set prefs(afterStartServer) 0   
    
    # it isn't done when client connects
    set prefs(afterConnect) 1000
    
    # Wraplength of text in message box for windows.
    set prefs(msgWrapLength) 60
            
    # Start server when launching application, if not client only?
    set prefs(autoStartServer) 1
    
    # Open connection in async mode.
    set prefs(asyncOpen) 1
    
    # Safe server interpretator.
    set prefs(makeSafeServ) 1
    
    # Maximum time to wait for any network action to respond. (secs and millisecs)
    set prefs(timeoutSecs) 30
    #set prefs(timeoutSecs) 4
    set prefs(timeoutMillis) [expr {1000 * $prefs(timeoutSecs)}]
    
    # How many milliseconds shall we wait before showing the progress window?
    set prefs(millisToProgWin) 0
    
    # How frequently shall the progress window be updated, in milliseconds.
    set prefs(progUpdateMillis) 500
    set prefs(progUpdateMillis) 1000
    
    set prefs(userPath) $this(appPath)
    
    # If it is the first time the application is launched, then welcome.
    set prefs(firstLaunch) 1
    
    # Shell print command in unix.
    if {[string equal $this(platform) "unix"]} {
	if {[info exists ::env(PRINTER)]} {
	    set prefs(unixPrintCmd) "lpr -P$::env(PRINTER)"
	} else {
	    set prefs(unixPrintCmd) "lpr"
	}
    } else {
	set prefs(unixPrintCmd) "lpr"
    }
    
    set prefs(clearCacheOnQuit) 0
    
    # Postscript options. A4 paper minus some margin (297m 210m).
    set prefs(postscriptOpts) {-pageheight 280m -pagewidth 190m -pageanchor c}
    
    # Useful time constants in seconds. Not used.
    set tmsec(min) 60
    set tmsec(hour)   [expr {60*$tmsec(min)}]
    set tmsec(day)    [expr {24*$tmsec(hour)}]
    set tmsec(week)   [expr {7*$tmsec(day)}]
    set tmsec(30days) [expr {30*$tmsec(day)}]
    
    # Various constants.
    set kPI 3.14159265359
    set kPI 3.141592653
    set kRad2Grad [expr {180.0/$kPI}]
    set kGrad2Rad [expr {$kPI/180.0}]
    set kTan225   [expr {tan($kPI/8.0)}]
    set kTan675   [expr {tan(3.0 * $kPI/8.0)}]
    
    #---- The state variables: 'state' ------------------------------------------
    
    # Is the internal server started?
    set state(isServerUp) 0
    
    # The reflector server?
    set state(reflectorStarted) 0
    
    # Any connections yet?
    set state(connectedOnce) 0
    
    # No -filetypes option in 'tk_getSaveFile' on latest MacTk.
    # Need to check the Mac Tk patchlevel also (>= 8.3.1).
    set prefs(haveSaveFiletypes) 1
    if {$this(platform) eq "macintosh"} {
	set prefs(haveSaveFiletypes) 0
    }
    
    #---- Shortcuts ----------------------------------------------------------------
    #----   domain names for open connection ---------------------------------------
    set prefs(shortcuts) {
	{{user specified} remote.computer.name}
	{{My Mac} 192.168.0.2}
	{{Home PC} 192.168.0.4}
	{other other.computer.name}
    }
    
    #-------------------------------------------------------------------------------
    
    # Mapping from error code to error message; 320+ own, rest HTTP codes.
    array set tclwbProtMsg {
	100 Continue
	101 {Switching Protocols}
	200 OK
	201 Created
	202 Accepted
	203 {Non-Authoritative Information}
	204 {No Content}
	205 {Reset Content}
	206 {Partial Content}
	300 {Multiple Choices}
	301 {Moved Permanently}
	302 Found
	303 {See Other}
	304 {Not Modified}
	305 {Use Proxy}
	307 {Temporary Redirect}
	320 {File already cached}
	321 {MIME type unsupported}
	322 {MIME type not given}
	323 {File obtained via url instead}
	340 {No other clients connected}
	400 {Bad Request}
	401 Unauthorized
	402 {Payment Required}
	403 Forbidden
	404 {Not Found}
	405 {Method Not Allowed}
	406 {Not Acceptable}
	407 {Proxy Authentication Required}
	408 {Request Time-out}
	409 Conflict
	410 Gone
	411 {Length Required}
	412 {Precondition Failed}
	413 {Request Entity Too Large}
	414 {Request-URI Too Large}
	415 {Unsupported Media Type}
	416 {Requested Range Not Satisfiable}
	417 {Expectation Failed}
	500 {Internal Server Error}	
	501 {Not Implemented}
	502 {Bad Gateway}
	503 {Service Unavailable}
	504 {Gateway Time-out}
	505 {HTTP Version not supported}
    }
    
    # Try to get own ip number from a temporary server socket.
    # This can be a bit complicated as different OS sometimes give 0.0.0.0 or
    # 127.0.0.1 instead of the real number.
    
    if {![catch {socket -server puts 0} s]} {
	set this(ipnum) [lindex [fconfigure $s -sockname] 0]
	catch {close $s}
	Debug 2 "1st: this(ipnum)=$this(ipnum)"
    }
    
    # If localhost or zero, try once again with '-myaddr'. 
    # My Linux box is not helped by this either!!!
    # Multiple ip interfaces are not recognized!
    if {[string equal $this(ipnum) "0.0.0.0"] ||  \
      [string equal $this(ipnum) "127.0.0.1"]} {
	if {![catch {socket -server xxx -myaddr $this(hostname) 0} s]} {
	    set this(ipnum) [lindex [fconfigure $s -sockname] 0]
	    catch {close $s}
	    Debug 2 "2nd: this(ipnum)=$this(ipnum)"
	}
    }
    if {[regexp {[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+} $this(ipnum)]} {
	set this(ipver) 4
    } else {
	set this(ipver) 6
    }
    
    set prefs(incomingPath) [file join $this(prefsPath) Incoming]
    
    # Make sure we've got the necessary directories.
    if {![file isdirectory $prefs(incomingPath)]} {
	file mkdir $prefs(incomingPath)
    }
    
    # Find out how many clicks or milliseconds there are on each second.
    set timingClicksToSecs 1000
    set timingClicksToMilliSecs 1.0    
}

#-------------------------------------------------------------------------------