File: Coccinella.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 (348 lines) | stat: -rwxr-xr-x 9,038 bytes parent folder | download | duplicates (2)
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/usr/bin/env wish8.6
      
#  Coccinella.tcl ---
#  
#       This file is the main of the jabber/whiteboard application. 
#       It controls the startup sequence and therefore needs a number
#       of code files/images to be succesful.
#      
#  Copyright (c) 1999-2008  Mats Bengtsson
#  
#  See the README file for license, bugs etc.
#
# $Id: Coccinella.tcl,v 1.188 2008-08-19 14:06:27 matben Exp $	

# Level of detail for printouts; >= 2 for my outputs; >= 6 to logfile.
set debugLevel 0

# TclKit loading mechanism.
package provide app-Coccinella 1.0

# We want 8.4 at least.
if {[catch {package require Tk 8.5}]} {
    return -code error "We need Tk 8.5 or later here. Run Wish or find a tclkit!"
}

# The main window "." shall never be displayed. Use it for QT sounds etc.
wm withdraw .
tk appname coccinella

# Keep 'launchStatus' around for the complete launch process to help components.
set state(launchStatus) start
set state(launchSecs) [clock seconds]

# MacOSX adds a -psn_* switch.
set argv [lsearch -all -not -inline -regexp $argv {-psn_\d*}]
set argc [llength $argv]

# We use a variable 'this(platform)' that is more convenient for MacOSX.
switch -- $::tcl_platform(platform) {
    unix {
	if {[string equal [tk windowingsystem] "aqua"]} {
	    set this(platform) "macosx"
	} else {
	    set this(platform) $::tcl_platform(platform)
	}
    }
    default {
	set this(platform) $::tcl_platform(platform)
    }
}

# Early platform dependent stuff.
switch -- $this(platform) {
    windows {
	
	# We should only allow a single instance of this application.
	# A COM interface would be better... (safer)
	package require dde
	
	# If any services available for coccinella then provide the argv.
	set services [dde services TclEval coccinella]
	if {$services != {}} {
	    dde execute TclEval coccinella [concat SecondCoccinella $argv]
	    exit
	}
	dde servername coccinella
    }
    macosx {
	
	# CoreGraphics don't align to pixel boundaries by default!
	#set tk::mac::useCGDrawing 0
	if {[info tclversion] >= 8.5} {
	    #set ::tk::mac::useCustomMDEF 1
	    proc ::tk::mac::OnHide {} {puts ::tk::mac::OnHide}
	    proc ::tk::mac::OnShow {} {puts ::tk::mac::OnShow}
	    proc ::tk::mac::ShowPreferences {} {puts ::tk::mac::ShowPreferences}
	    proc ::tk::mac::Quit {} {puts ::tk::mac::Quit}
	}
    }
}

# Find program real pathname, resolve all links in between. Unix only.
#
# Contributed by Raymond Tang. Starkit fix by David Zolli.

proc resolve_cmd_realpath {infile} {
    
    if {[file exists $infile]} {
	if {[file type $infile] == "link"} {
	    set olddir [pwd]
	    set dirname [file dirname $infile]
	    set filename [file tail $infile]
	    cd $dirname
	    if {[file type $filename] == "link"} {
		set filename [file readlink $filename]
		if {[file pathtype $filename] == "absolute"} {
		    set realname [resolve_cmd_realpath $filename]
		} else {
		    set realname [file join [pwd] $filename]
		}
	    } else {
		# found the destination
		set realname $infile
	    }
	    cd $olddir
	    return [resolve_cmd_realpath $realname]
	} else {
	    # found the desintation
	    return $infile
	}
    } else {
	foreach name [split $::env(PATH) :] {
	    set filename [file join $name $infile]
	    if {[file exists $filename] && [file executable $filename]} {
		return [resolve_cmd_realpath $filename]
	    }
	}

	# Kroc : for tclkit support :
        if {[info exists ::starkit::topdir]} {
            return $::starkit::topdir
        } else {
            return $infile
        }
    }
}

# Identify our own position in the file system.
if {[string equal $this(platform) "unix"]} {
    set thisScript [file normalize [resolve_cmd_realpath [info script]]]
} else {
    set thisScript [file normalize [info script]]
}
set thisPath [file normalize [file dirname $thisScript]]

# Debug support.
source [file join $thisPath lib Debug.tcl]

::Debug 2 "Installation rootdir:  [file dirname $thisScript]"

# Set up 'this' array which contains search paths admin stuff.
source [file join $thisPath lib Init.tcl]
::Init::SetThis $thisScript
::Init::SetThisVersion
::Init::SetThisEmbedded
::Init::SetAutoPath
::Init::LoadTkPng

set prefs(appName)    "Coccinella"
set prefs(theAppName) "Coccinella"

# Read our prefs file containing the theme name and locale needed before splash.
package require PrefUtils
package require Theme
::PrefUtils::Init
::Theme::Init

# Find our language and load message catalog.
::Init::Msgcat

# Sets the window titlebar icon. Win98 bails.
catch {
    wm iconphoto . -default \
      [::Theme::FindIconSize 16 coccinella] \
      [::Theme::FindIconSize 32 coccinella] \
      [::Theme::FindIconSize 64 coccinella]
}

# Splash! Need a full update here, at least on Windows.
package require Splash
::Splash::SplashScreen
# TRANSLATORS: splash screen strings; shown at startup
::Splash::SetMsg [mc "Sourcing Tcl code"]...
set state(launchStatus) splash
update

# Make sure we have the extra packages necessary and some optional.
::Splash::SetMsg [mc "Searching for our hostname"]...
::Init::SetHostname
::Init::LoadPackages

set state(launchStatus) tile
set prefs(tileTheme) [option get . prefs_tileTheme {}]

if {[lsearch -exact [ttk::themes] $prefs(tileTheme)] >= 0} {
    ttk::setTheme $prefs(tileTheme)
} elseif {[tk windowingsystem] eq "x11"} {
    
    # We use the 'clam' theme as a fallback (and default in resources).
    catch {ttk::setTheme clam}
}
::Theme::ReadTileResources

# The packages are divided into categories depending on their degree
# of generality.
::Splash::SetMsg [mc "Loading Tcl packages"]...
set state(launchStatus) packages

set packages(generic) {
    component
    hooks
    pipes
    tileutils
    undo
    uri
    uri::urn
    utils
}
set packages(uibase) {
    balloonhelp
    Tablelist_tile
    ttoolbar
    ui::util
    ui::combomenu
    ui::dialog
    ui::optionmenu
}
set packages(application) {
    AMenu
    Component
    Dialogs
    EditDialogs
    FactoryDefaults
    Httpd
    HttpTrpt
    Media
    Network
    Preferences
    PrefGeneral
    PrefHelpers
    PrefNet
    Proxy
    SetupAss
    TheServer
    Types
    UI
    UserActions
    Utils
}
foreach class {generic uibase application} {
    foreach name $packages($class) {
	package require $name
    }
}
tileutils::configure -themechanged ::Theme::TileThemeChanged

# Platform dependent packages.
switch -- $this(platform) {
    macosx {
	package require MacintoshUtils
    }
    windows {
	package require WindowsUtils
    }
}
::UI::InitDlgs

# The Jabber stuff. 
::Splash::SetMsg [mc "Sourcing Jabber code"]...
set state(launchStatus) jabber
package require Jabber

# Define MIME types etc.
::Types::Init

# Standard (factory) preferences are set here.
# These are the hardcoded, application default, values, and can be
# overridden by the ones in user default file.
::Splash::SetMsg [mc "Initializing"]...
FactoryDefaults
::Jabber::FactoryDefaults
::Jabber::LoadWhiteboard

# To provide code to be run before loading componenets.
::Debug 2 "--> earlyInitHook"
::hooks::run earlyInitHook

# Components.
::Debug 2 "++> component::load"
::Component::Load

# Set the user preferences from the preferences file.
::Splash::SetMsg [mc "Setting preferences"]...
set state(launchStatus) preferences
::Preferences::SetMiscPrefs

# Override any 'config's. 
# Must be after all sources and components loaded but before any init hooks.
::Init::Config

# Components that need to add their own preferences need to be registered here.
# @@@ Is this really necessary? Can't they call ::PrefUtils::Add anytime?
::Debug 2 "--> prefsInitHook"
::hooks::run prefsInitHook

# Parse some command line options.
# @@@ There is a conflict here if some prefs settings depend on, say protocol.
::PrefUtils::ParseCommandLineOptions $argv

# Check that the mime type preference settings are consistent.
::Types::VerifyInternal

# Various initializations for canvas stuff and UI.
# In initHook UI before hooks BAD!
::UI::Init
::UI::InitMenuDefs
::UI::InitCommonBinds
::UI::InitVirtualEvents

# All components that requires some kind of initialization should register here.
# Beware, order may be important!
::Debug 2 "--> initHook"
::hooks::run initHook

# Code that requires stuff done in initHook registers for this one.
::Debug 2 "--> postInitHook"
::hooks::run postInitHook

# At this point we should be finished with the launch and delete the splash 
# screen.
::Splash::SetMsg ""
after 200 {catch {destroy $::wDlgs(splash)}}

# This builds the main window etc.
::Jabber::Init

::Debug 2 "--> initFinalHook"
::hooks::run initFinalHook

if {$prefs(firstLaunch)} {
    ::hooks::run firstLaunchHook
}

update idletasks

::Debug 2 "--> launchFinalHook"
::hooks::run launchFinalHook
unset -nocomplain state(launchStatus)
set prefs(firstLaunch) 0

# This is for late init hooks that are slow to avoid locking the UI.
after 200 {
    ::Debug 2 "--> afterFinalHook"
    ::hooks::run afterFinalHook
    ::hooks::run postAfterFinalHook
}

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