/usr/share/pfm/options.tcl is in pfm 2.0.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | # options.tcl
class PfmOptions {
protected common optionStructure {
general {browser tmpdir printcmd printencoding theme}
postgresql {psql dblist dbname host port user usePGPASSWORD}
geometry {main sql form text}
}
protected variable optionDict
protected variable optionArray
protected variable window
constructor {} {
set optionDict {}
dict for {type list} $optionStructure {
set subDict {}
foreach option $list {
dict append subDict $option {}
}
dict append optionDict $type $subDict
}
return
}
destructor {
return
}
public method initOptions {} {
global env
global tcl_platform
if {$tcl_platform(platform) eq {windows}} then {
set filename [file join $env(APPDATA) pfm pfm2.conf]
} else {
set filename "~/.pfm2"
}
if {[file exists $filename]} then {
set chan [open $filename r]
set fileDict [chan read -nonewline $chan]
chan close $chan
} else {
set fileDict {}
}
dict for {type list} $optionStructure {
foreach option $list {
if {[dict exists $fileDict $type $option]} then {
dict set optionDict $type $option \
[dict get $fileDict $type $option]
} else {
dict set optionDict $type $option \
[getDefault $type $option]
}
}
}
saveOptions
return
}
public method saveOptions {} {
global env
global tcl_platform
if {$tcl_platform(platform) eq {windows}} then {
set filename [file join $env(APPDATA) pfm pfm2.conf]
set dirname [file join $env(APPDATA) pfm]
if {![file exists $dirname]} then {
file mkdir $dirname
}
} else {
set filename "~/.pfm2"
}
set chan [open $filename w]
chan puts $chan $optionDict
chan close $chan
return
}
public method getDefault {type option} {
switch $type {
general {
set value [getGeneralDefault $option]
}
postgresql {
set value [getPostgresqlDefault $option]
}
geometry {
set value [getGeometryDefault $option]
}
default {
set value {}
}
}
return $value
}
protected method getGeneralDefault {option} {
global env
global tcl_platform
variable ::config::defaultBrowser
variable ::config::defaultPrintcmd
switch -- $option {
"browser" {
switch -- $tcl_platform(platform) {
"unix" {
set value $defaultBrowser
}
"windows" {
if {[info exists env(ProgramFiles)]} then {
set iexplorer \
[file normalize [file join $env(ProgramFiles) \
{Internet Explorer} \
{iexplore.exe}]]
set value [list $iexplorer %s]
} else {
set value {iexplore.exe %s}
}
}
default {
set value {}
}
}
}
"printcmd" {
switch -- $tcl_platform(platform) {
"unix" {
set value $defaultPrintcmd
}
"windows" {
if {[info exists env(ProgramFiles)]} then {
set wordpad \
[file normalize [file join $env(ProgramFiles) \
{Windows NT} \
{Bureau-accessoires} \
{wordpad.exe}]]
set value [list [list $wordpad %txt]]
} else {
set value [list [list wordpad.exe %txt]]
}
}
}
}
"printencoding" {
set value [encoding system]
}
"tmpdir" {
switch -- $tcl_platform(platform) {
"unix" {
set value {/tmp}
}
"windows" {
if {[info exists env(TEMP)]} then {
set value [file normalize $env(TEMP)]
} else {
set value [file normalize "~/tmp"]
}
}
default {
set value {}
}
}
}
"theme" {
switch -- $tcl_platform(platform) {
"unix" {
set value default
}
"windows" {
set value xpnative
}
default {
set value default
}
}
}
default {
set value {}
}
}
return $value
}
protected method getGeometryDefault {option} {
switch $option {
main {
set value {400 300}
}
sql {
set value {600 700}
}
form {
set value {640 480}
}
text {
set value {600 400}
}
default {
set value {600 400}
}
}
return $value
}
public method getOption {type option} {
return [dict get $optionDict $type $option]
}
public method setOption {type option newValue} {
dict set optionDict $type $option $newValue
return
}
public method editOptions {} {
foreach type {general postgresql} {
foreach option [dict get $optionStructure $type] {
set optionArray($type,$option) [dict get $optionDict $type $option]
}
}
set window [toplevel ".opt[namespace tail $this]"]
wm transient $window {.}
wm title $window [mc optionsTitle]
set noteBook [ttk::notebook ${window}.nb -takefocus 0]
set fGeneral [setupGeneral ${noteBook}.general]
set fPostgresql [setupPostgresql ${noteBook}.postgresql]
addNotebookTab $noteBook $fGeneral optTabGeneral
addNotebookTab $noteBook $fPostgresql optTabPostgresql
ttk::notebook::enableTraversal $noteBook
pack $noteBook -side top -expand 1 -fill both
set frmButtons [ttk::frame ${window}.frmbtns]
set btnOK [defineButton ${frmButtons}.btnok $window btnOK \
[list $this onOK]]
set btnCancel [defineButton ${frmButtons}.btncancel $window \
btnCancel [list destroy $window]]
pack $btnCancel -side right
pack $btnOK -side right
pack $frmButtons -side top -fill x -pady {10 10} -padx {10 10}
bindToplevelOnly $window <Destroy> [list $this onDestroyWindow]
bind $window <KeyPress-Down> {focus [tk_focusNext [focus]]}
bind $window <KeyPress-Up> {focus [tk_focusPrev [focus]]}
bind $window <KeyPress-Escape> [list destroy $window]
return
}
protected method setupGeneral {pathname} {
set frm [ttk::frame $pathname]
set idx 0
foreach option [dict get $optionStructure general] {
set lbl [ttk::label ${frm}.lb$idx -text $option]
grid $lbl -column 0 -row $idx -sticky w
switch -- $option {
printencoding {
set control [ttk::combobox ${frm}.con$idx \
-textvariable [scope optionArray(general,$option)] \
-values [lsort [encoding names]]]
$control configure -state readonly
}
theme {
set control [ttk::combobox ${frm}.con$idx \
-textvariable [scope optionArray(general,$option)] \
-values [ttk::style theme names]]
$control configure -state readonly
}
default {
set control [entry ${frm}.con$idx \
-textvariable [scope optionArray(general,$option)]]
}
}
if {$option in {tmpdir}} then {
set btnSelect [defineButton ${frm}.sel$idx $control \
btnSelect [list $this onSelect general $option]]
$btnSelect configure -style SButton
grid $control -column 1 -row $idx -sticky wens
grid $btnSelect -column 2 -row $idx -sticky we
$control configure -state {readonly}
} else {
grid $control -column 1 -columnspan 2 -row $idx \
-sticky wens
}
set btnExpand [defineButton ${frm}.exp$idx $control \
btnExpand [list $this onExpand general $option]]
$btnExpand configure -style SButton
grid $btnExpand -column 3 -row $idx -sticky we
set btnDefault [defineButton ${frm}.def$idx $control \
btnDefault [list $this onDefault general $option]]
$btnDefault configure -style SButton
grid $btnDefault -column 4 -row $idx -sticky we
set btnHelp [defineButton ${frm}.help$idx $control \
btnHelp [list $this onHelp general $option]]
$btnHelp configure -style SButton
grid $btnHelp -column 5 -row $idx -sticky we
incr idx
}
grid columnconfigure $frm 1 -weight 1
grid anchor $frm center
return $frm
}
protected method setupPostgresql {pathname} {
set frm [ttk::frame $pathname]
set idx 0
foreach option [dict get $optionStructure postgresql] {
set lbl [ttk::label ${frm}.lb$idx -text $option]
grid $lbl -column 0 -row $idx -sticky w
switch -- $option {
usePGPASSWORD {
set control [ttk::checkbutton ${frm}.con$idx \
-text {} \
-variable [scope optionArray(postgresql,$option)] \
-onvalue 1 -offvalue 0]
}
default {
set control [entry ${frm}.con$idx \
-textvariable [scope optionArray(postgresql,$option)]]
}
}
if {$option in {psql}} then {
set btnSelect [defineButton ${frm}.sel$idx $control \
btnSelect [list $this onSelect postgresql $option]]
$btnSelect configure -style SButton
grid $control -column 1 -row $idx -sticky wens
grid $btnSelect -column 2 -row $idx -sticky we
$control configure -state {readonly}
} else {
grid $control -column 1 -columnspan 2 -row $idx \
-sticky wens
}
set btnExpand [defineButton ${frm}.exp$idx $control \
btnExpand [list $this onExpand postgresql $option]]
$btnExpand configure -style SButton
grid $btnExpand -column 3 -row $idx -sticky we
set btnDefault [defineButton ${frm}.def$idx $control \
btnDefault [list $this onDefault postgresql $option]]
$btnDefault configure -style SButton
grid $btnDefault -column 4 -row $idx -sticky we
set btnHelp [defineButton ${frm}.help$idx $control \
btnHelp [list $this onHelp postgresql $option]]
$btnHelp configure -style SButton
grid $btnHelp -column 5 -row $idx -sticky we
incr idx
}
grid columnconfigure $frm 1 -weight 1
grid anchor $frm center
return $frm
}
public method onOK {} {
foreach type {general postgresql} {
foreach option [dict get $optionStructure $type] {
dict set optionDict $type $option $optionArray($type,$option)
}
}
saveOptions
destroy $window
installTheme [getOption general theme]
return
}
public method onDestroyWindow {} {
array unset optionArray
return
}
public method onExpand {type option} {
set textEdit [TextEdit "#auto" $window $option \
$optionArray($type,$option) 0]
if {$option in {browser printcmd}} then {
$textEdit addMenuItem [mc optPasteFilename] command {
%T insert insert [tk_getOpenFile \
-parent [winfo toplevel %T]]
}
}
if {[$textEdit wait result]} then {
set optionArray($type,$option) $result
}
return
}
public method onDefault {type option} {
set optionArray($type,$option) [getDefault $type $option]
return
}
public method onHelp {type option} {
set textEdit [TextEdit "#auto" $window [mc optHelpTitle $option] \
[mc optHelp_${option}] 1]
return
}
public method onSelect {type option} {
global env
global tcl_platform
switch -- $type {
general {
switch -- $option {
tmpdir {
set dirname [tk_chooseDirectory \
-initialdir $optionArray($type,$option) \
-parent $window]
if {$dirname ne {}} then {
set optionArray($type,$option) $dirname
}
}
}
}
postgresql {
switch -- $option {
psql {
if {$tcl_platform(platform) eq {windows}} then {
set filetypes {
{{Executables} {.exe}}
{{All files} *}
}
set initialdir $env(ProgramFiles)
} else {
set filetypes {}
set initialdir {/usr/bin}
}
set psqlLoc [tk_getOpenFile \
-filetypes $filetypes \
-initialdir $initialdir \
-parent $window]
if {$psqlLoc ne {}} then {
set optionArray($type,$option) $psqlLoc
}
}
}
}
}
return
}
}
|