|
From: <bu...@us...> - 2006-03-22 18:17:45
|
Revision: 574 Author: bugant Date: 2006-03-22 10:17:32 -0800 (Wed, 22 Mar 2006) ViewCVS: http://svn.sourceforge.net/yaacs/?rev=574&view=rev Log Message: ----------- setting preferences stuff almost finished; Modified Paths: -------------- trunk/tkyaacs/tclIndex trunk/yaacs/yaconf.tcl trunk/yacco.tcl trunk/yadmin.tcl Added Paths: ----------- trunk/tkyaacs/yatk_settings.tcl Modified: trunk/tkyaacs/tclIndex =================================================================== --- trunk/tkyaacs/tclIndex 2006-03-22 18:13:06 UTC (rev 573) +++ trunk/tkyaacs/tclIndex 2006-03-22 18:17:32 UTC (rev 574) @@ -14,6 +14,8 @@ set auto_index(::yatk_themes::parseIcon) [list source [file join $dir yatk_themes.tcl]] set auto_index(::yatk_themes::load) [list source [file join $dir yatk_themes.tcl]] set auto_index(::yatk_print::print) [list source [file join $dir yatk_print.tcl]] +set auto_index(::yatk_settings::settings) [list source [file join $dir yatk_settings.tcl]] +set auto_index(::yatk_setting::configDb) [list source [file join $dir yatk_settings.tcl]] set auto_index(::yatk_balloon::balloon) [list source [file join $dir yatk_balloon.tcl]] set auto_index(::yatk_balloon::balloonShow) [list source [file join $dir yatk_balloon.tcl]] set auto_index(::yatk_wm::center) [list source [file join $dir yatk_wm.tcl]] Added: trunk/tkyaacs/yatk_settings.tcl =================================================================== --- trunk/tkyaacs/yatk_settings.tcl (rev 0) +++ trunk/tkyaacs/yatk_settings.tcl 2006-03-22 18:17:32 UTC (rev 574) @@ -0,0 +1,267 @@ +# This source code file is part of the YaaCs package. +# +# Copyright (C) 2002-2005 YaaCers +# +# 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 2 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 (probably in a file named "LICENSE"); +# if not, write to: +# +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +# settings 'dialog' + +namespace eval ::yatk_settings { + +} + +# Display the settings dialog in the mode you specified +# +# @param mode specify which options can be setted; supported +# mode are: yacco, yadmin. +# @param w parent window (optional) +# @param title window's title (optional) +proc ::yatk_settings::settings {mode {w ""} {title "Preferences"}} { + set ::yatk_settings::mode $mode + set w $w.preferences + set ::yatk_settings::w $w + + toplevel $w -bd 1 -relief raised -class TkSDialog + wm title $w $title + wm iconname $w $title + wm transient $w [winfo toplevel [winfo parent $w]] + + set btndb [button $w.db -image $::yatk_icons::big_db -text "Database Connection" -compound top \ + -width 130 -command {::yatk_settings::configDb}] + set btnth [button $w.themes -image $::yatk_icons::big_themes -text "Themes" -compound top \ + -width 130 -command {::yatk_settings::configThemes}] + + switch -exact -- $mode { + "yacco" { + set btnre [button $w.remote -image $::yatk_icons::big_remote -text "Remote Secure Shell" -compound top \ + -width 130 -command {::yacco::configRemote}] + set btnop [button $w.opst -image $::yatk_icons::big_optypes -text "Operator Types" -compound top \ + -width 130 -command {::yacco::configOpst}] + set btnte [button $w.temp -image $::yatk_icons::big_template -text "Documents Template" -compound top \ + -width 130 -command {::yacco::configTemp}] + + grid $btndb $btnre $btnop -padx 10 -pady 10 + grid $btnte $btnth -padx 10 -pady 10 + } + "yadmin" { + set btnfa [button $w.fax -image $::yatk_icons::big_fax -text "Fax" -compound top \ + -width 130 -command {::yadmin::configFax}] + set btnem [button $w.email -image $::yatk_icons::big_email -text "Email" -compound top \ + -width 130 -command {::yadmin::configEmail}] + + grid $btndb $btnfa -padx 10 -pady 10 + grid $btnem $btnth -padx 10 -pady 10 + } + + default { + set msg [mc "No settings available for mode"] + set msg "$msg '$mode'" + ::yatk_dlg::error $msg + destroy $w + } + } +} + +proc ::yatk_settings::configDb {} { + set w $::yatk_settings::w.confDb + set title [mc "Database settings"] + toplevel $w -bd 1 -relief raised -class TkSDialog + wm title $w $title + wm iconname $w $title + wm transient $w [winfo toplevel [winfo parent $w]] + + labelframe $w.sample -text [mc "Main database"] + message $w.sample.txt -text [mc "Configure parameters to be able to connect \ + to the main yaacs's database (sampling)"] -width 200 + label $w.sample.lblName -text [mc "Database name"] + entry $w.sample.name -bg white + label $w.sample.lblHost -text [mc "Host"] + entry $w.sample.host -bg white + label $w.sample.lblUser -text [mc "User"] + entry $w.sample.user -bg white + label $w.sample.lblPort -text [mc "Port"] + entry $w.sample.port -bg white + + grid $w.sample.txt - -padx 5 -pady 5 + grid $w.sample.lblName $w.sample.name -sticky nw -padx 5 -pady 5 + grid $w.sample.lblHost $w.sample.host -sticky nw -padx 5 -pady 5 + grid $w.sample.lblUser $w.sample.user -sticky nw -padx 5 -pady 5 + grid $w.sample.lblPort $w.sample.port -sticky nw -padx 5 -pady 5 + + labelframe $w.op -text "Operator database (will be soon removed)" + message $w.op.txt -text [mc "Configure parameters to be able to connect \ + to the operators yaacs's database"] -width 200 + label $w.op.lblName -text [mc "Database name"] + entry $w.op.name -bg white + label $w.op.lblHost -text [mc "Host"] + entry $w.op.host -bg white + label $w.op.lblUser -text [mc "User"] + entry $w.op.user -bg white + label $w.op.lblPort -text [mc "Port"] + entry $w.op.port -bg white + + grid $w.op.txt - -padx 5 -pady 5 + grid $w.op.lblName $w.op.name -sticky nw -padx 5 -pady 5 + grid $w.op.lblHost $w.op.host -sticky nw -padx 5 -pady 5 + grid $w.op.lblUser $w.op.user -sticky nw -padx 5 -pady 5 + grid $w.op.lblPort $w.op.port -sticky nw -padx 5 -pady 5 + + frame $w.bts + button $w.bts.ok -image $::yatk_icons::ok -text [mc "Ok"] -compound left \ + -command { + set newDbSample [$::yatk_settings::w.confDb.sample.name get] + set newHostSample [$::yatk_settings::w.confDb.sample.host get] + set newUserSample [$::yatk_settings::w.confDb.sample.user get] + set newPortSample [$::yatk_settings::w.confDb.sample.port get] + + set newDbInt [$::yatk_settings::w.confDb.op.name get] + set newHostInt [$::yatk_settings::w.confDb.op.host get] + set newUserInt [$::yatk_settings::w.confDb.op.user get] + set newPortInt [$::yatk_settings::w.confDb.op.port get] + + set db_int_new [::yadb::connect $newDbInt $newHostInt $newUserInt $newPortInt] + set db_sample_new [::yadb::connect $newDbSample $newHostSample $newUserSample $newPortSample] + + if {($db_int_new == -1) || ($db_sample_new == -1)} { + ::yatk_dlg::error [mc "Cannot connect to dbs please check your settings. Old parameters + has been taken back."] + return + } + + switch -exact -- $::yatk_settings::mode { + "yacco" { + array set myconfig [array get ::yadmin::config] + ::yacco::confDb $db_sample_new $db_int_new + } + "yadmin" { + array set myconfig [array get ::yacco::config] + ::yadmin::confDb $db_sample_new $db_int_new + } + } + + array set myconfig [array get [list]] + set myconfig(DB_SAMPLE) $newDbSample + set myconfig(HOST_SAMPLE) $newHostSample + set myconfig(USER_SAMPLE) $newUserSample + set myconfig(PORT_SAMPLE) $newPortSample + set myconfig(DB_INT) $newDbInt + set myconfig(HOST_INT) $newHostInt + set myconfig(USER_INT) $newUserInt + set myconfig(PORT_INT) $newPortInt + + set pathConf [::yaconf::checkLocalConf] + switch -exact -- $::yatk_settings::mode { + "yacco" {array set ::yacco::config [array get myconfig]; set pathConf "$pathConf/yacco"} + "yadmin" {array set ::yadmin::config [array get myconfig]; set pathConf "$pathConf/yadmin"} + } + + ::yaconf::writeConfig $pathConf [array get myconfig] + } + + button $w.bts.cancel -image $::yatk_icons::cancel -text [mc "Close"] -compound left \ + -command {destroy $::yatk_settings::w.confDb} + + grid $w.bts.cancel $w.bts.ok -sticky se -padx [list 6 0] + + grid $w.sample -padx 12 -pady [list 12 5] + grid $w.op -padx 12 -pady 5 + grid $w.bts -padx 12 -pady 12 -sticky se + + #set intial values + + array set my [array get [list]] + switch -exact -- $::yatk_settings::mode { + "yacco" { + set my(DB_SAMPLE) $::yacco::config(DB_SAMPLE) + set my(HOST_SAMPLE) $::yacco::config(HOST_SAMPLE) + set my(USER_SAMPLE) $::yacco::config(USER_SAMPLE) + set my(PORT_SAMPLE) $::yacco::config(PORT_SAMPLE) + set my(DB_INT) $::yacco::config(DB_INT) + set my(HOST_INT) $::yacco::config(HOST_INT) + set my(USER_INT) $::yacco::config(USER_INT) + set my(PORT_INT) $::yacco::config(PORT_INT) + } + "yadmin" { + set my(DB_SAMPLE) $::yadmin::config(DB_SAMPLE) + set my(HOST_SAMPLE) $::yadmin::config(HOST_SAMPLE) + set my(USER_SAMPLE) $::yadmin::config(USER_SAMPLE) + set my(PORT_SAMPLE) $::yadmin::config(PORT_SAMPLE) + set my(DB_INT) $::yadmin::config(DB_INT) + set my(HOST_INT) $::yadmin::config(HOST_INT) + set my(USER_INT) $::yadmin::config(USER_INT) + set my(PORT_INT) $::yadmin::config(PORT_INT) + } + } + + $w.sample.name insert 0 $my(DB_SAMPLE) + $w.sample.host insert 0 $my(HOST_SAMPLE) + $w.sample.user insert 0 $my(USER_SAMPLE) + $w.sample.port insert 0 $my(PORT_SAMPLE) + + $w.op.name insert 0 $my(DB_INT) + $w.op.host insert 0 $my(HOST_INT) + $w.op.user insert 0 $my(USER_INT) + $w.op.port insert 0 $my(PORT_INT) +} + +proc ::yatk_settings::configThemes {} { + set w $::yatk_settings::w.confThemes + set title [mc "Choose a theme"] + toplevel $w -bd 1 -relief raised -class TkSDialog + wm title $w $title + wm iconname $w $title + wm transient $w [winfo toplevel [winfo parent $w]] + + set ::yatk_settings::availableThemes [list] + foreach file [glob -nocomplain -directory $::yatk_themes::basePath -types d *] { + set theme [lindex [file split $file] [expr [llength [file split $file]] -1]] + lappend ::yatk_settings::availableThemes $theme + } + + labelframe $w.th -text [mc "Themes"] + scrollbar $w.th.sbThemes -orient vertical -command {$::yatk_settings::w.confThemes.th.lstThemes yview} -borderwidth 0 + listbox $w.th.lstThemes -listvariable ::yatk_settings::availableThemes -bg white \ + -yscrollcommand {$::yatk_settings::w.confThemes.th.sbThemes set} + grid $w.th.lstThemes $w.th.sbThemes -sticky ns -pady 5 + + frame $w.bts + button $w.bts.ok -image $::yatk_icons::ok -text [mc "Apply theme"] -compound left \ + -command { + set curSel [$::yatk_settings::w.confThemes.th.lstThemes curselection] + if {[llength $curSel] == 0} { + ::yatk_dlg::error [mc "Choose a theme first"] + return + } + set pathConf [::yaconf::checkLocalConf] + switch -exact -- $::yatk_settings::mode { + "yacco" {array set ::yacco::config [array get myconfig]; set pathConf "$pathConf/yacco"} + "yadmin" {array set ::yadmin::config [array get myconfig]; set pathConf "$pathConf/yadmin"} + } + + set t [lindex $::yatk_settings::availableThemes $curSel] + ::yatk_themes::init $t + set myconfig(THEME) $t + ::yaconf::writeConfig $pathConf [array get myconfig] + } + button $w.bts.cancel -image $::yatk_icons::cancel -text [mc "Close"] -compound left \ + -command {destroy $::yatk_settings::w.confThemes} + + grid $w.bts.cancel $w.bts.ok -padx [list 6 0] + + grid $w.th -sticky news -padx 12 -pady 12 + grid $w.bts -sticky se -padx 12 -pady 12 +} Modified: trunk/yaacs/yaconf.tcl =================================================================== --- trunk/yaacs/yaconf.tcl 2006-03-22 18:13:06 UTC (rev 573) +++ trunk/yaacs/yaconf.tcl 2006-03-22 18:17:32 UTC (rev 574) @@ -28,6 +28,12 @@ # @param file file with path containing configuration # @return hash with configuration keys proc ::yaconf::conf {file} { + array set c [array get [list]] + + if {!([file exists $file] && [file isfile $file])} { + return [array get c] + } + set cf [open $file] set data [split [read $cf] \n] close $cf @@ -53,32 +59,72 @@ # @param newC array containing the new configuration to be saved # @return returns 0 on success; -1 on error. proc ::yaconf::writeConfig {file newC} { - + + array set oldconf [array get [list]] + + set data [list] + + if {[file exists $file] && [file isfile $file]} { + set oldf [open $file] + set data [split [read $oldf] \n] + close $oldf + } + + foreach line $data { + if { ! ( ([string match "#*" $line]) || ([string match "" $line]) ) } { + set pos [string first "=" $line] + if {$pos != -1} { + set optName [string range $line 0 [expr $pos - 1]] + set optVal [string range $line [expr $pos + 1] end] + set oldconf($optName) $optVal + } + } + } + array set newconf $newC + foreach conf [array names newconf] { + set val $newconf($conf) + set oldconf($conf) $val + } - # read the old file to re-write - # user's comment and such. - - set cf [open $file] - set data [split [read $cf] \n] - close $cf + array set written [array get [list]] + foreach c [array names oldconf] { + set written($c) 0 + } # write the new file - set cf [open $file w] - - foreach line $data { - if {[string match "#*" $line] || [string match "" $line]} { - puts $cf $line - } else { + + set out "" + if {[llength $data] != 0} { + foreach line $data { + if {[string match "#*" $line] || [string match "" $line]} { + set out "$out\n$line" + continue + } set pos [string first "=" $line] if {$pos != -1} { set optName [string range $line 0 [expr $pos - 1]] - set optVal $newconf($optName) - puts $cf "$optName=$optVal" + set out "$out\n$optName=$oldconf($optName)" + set written($optName) 1 } } - } + foreach c [array names oldconf] { + if {$written($c) == 0} { + set out "$out\n$c=$oldconf($c)" + } + } + } else { + foreach optName [lsort [array names oldconf]] { + set out "$out\n$optName=$oldconf($optName)" + } + } + + # remove the first useless \n + set out [string range $out 1 end] + + set cf [open $file w] + puts -nonewline $cf $out close $cf } Modified: trunk/yacco.tcl =================================================================== --- trunk/yacco.tcl 2006-03-22 18:13:06 UTC (rev 573) +++ trunk/yacco.tcl 2006-03-22 18:17:32 UTC (rev 574) @@ -32,19 +32,6 @@ option add *Dialog.msg.font {lucidasans 16} -set yaacsHome [::yaconf::checkLocalConf] -set themeRcFile [join $yaacsHome yacco.theme] -if {[file exist $themeRcFile] && [file isfile $themeRcFile]} { - set f [open $themeRcFile] - set theme [lindex [read $f] 0] - close $f -} -if {[info exists theme]} { - ::yatk_themes::init $theme -} else { - ::yatk_themes::init -} - namespace eval ::yacco { variable ::yacco::is_new_contact 0 variable ::yacco::maxSmsChars 160 @@ -60,6 +47,43 @@ } +set yaacsHome [::yaconf::checkLocalConf] + +## +# Getting cmdline opt +set carg [list "c.arg" "/etc/yaacs/yaacs.conf" [mc "config file"]] +set larg [list "l.arg" "" [mc "Log level"]] +set yaccoptions [list $carg $larg] +set yaccousage "yacco: \[-c <config file>\] \[-l <log level>\]" + +if { [catch {array set gettedopts [::cmdline::getoptions argv $yaccoptions $yaccousage]} err] } { + cmderrmsg "" $yaccoptions $yaccousage + exit 1 +} + +if { !([file exists $gettedopts(c)] && [file isfile $gettedopts(c)]) } { + cmderrmsg [mc "error: couldn't find %s" $gettedopts(c)] $yaccoptions $yaccousage + exit 1 +} +## +# Init config package +array set ::yacco::config [::yaconf::conf $gettedopts(c)] +array set userconf [::yaconf::conf "$yaacsHome/yacco"] +foreach k [array names userconf] { + set ::yacco::config($k) $userconf($k) +} + +if {[info exists ::yacco::config(THEME)]} { + ::yatk_themes::init $::yacco::config(THEME) +} else { + ::yatk_themes::init +} + +set ::yacco::confFile $gettedopts(c) + +## +# GUI + set info [labelframe .info -text [mc "Operator information"]] # Initialize notebook @@ -79,6 +103,7 @@ entry $ifr.name -validate key -validatecommand {::yacco::onValidateString %P %W } label $ifr.lbsex -text [mc "Sex"] iwidgets::combobox $ifr.sex +[$ifr.sex component arrowBtn] configure -takefocus 0 label $ifr.lbbdate -text [mc "Birthday"] entry $ifr.bdate -validate focusout -validatecommand {::yacco::onValidateDate %P} -invcmd { @@ -87,12 +112,15 @@ after idle {%W config -validate focusout} } bind $ifr.bdate <Leave> {$ifr.bdate validate} + label $ifr.lbbplace -text [mc "Bitrh place"] entry $ifr.bplace -validate key -validatecommand {::yacco::onValidateString %P %W} label $ifr.lbcf -text [mc "Cod. Fisc."] button $ifr.btcf -text [mc "Cod. Fisc."] -command {::yacco::onPressCodFis $db_int} -takefocus 0 \ -image $::yatk_icons::hours -compound left -entry $ifr.cf -takefocus {::yacco::onPressCodFis $db_int} +entry $ifr.cf -takefocus { + ::yacco::onPressCodFis $db_int +} label $ifr.lblogin -text [mc "Login"] entry $ifr.login -validate key -validatecommand {::yacco::onValidateString %P %W} @@ -576,8 +604,9 @@ -command { set codFisc [.fnd.fr.cod get] set yacco::is_new_contact 0 - ::yacco::update_status edit + ::yacco::set_editfields_state normal if {[::yacco::fillInData $db_int $codFisc] != -1} { + ::yacco::update_status edit set ::yacco::fButton 1 } } @@ -1120,8 +1149,14 @@ $ret(bank) $ret(bank_addr) $ret(bank_city) $ret(bank_abi) $ret(bank_cab) $ret(bank_cc) \ $ret(bank_owner) $ret(morning) $ret(afternoon) $ret(evening) $ret(aviablefrom) \ $ret(login) $yacco::is_new_contact] == -1} { + set msg "" + switch -exact -- $::op::err $::op::ERR_INSOP {set msg [mc "Invalid user's data. Please re-check them"]} \ + $::op::ERR_INSBANK {set msg [mc "Bank data are invalid."]} \ + $::op::ERR_INSAVAIL {set msg [mc "Error on user's availability settings"]} \ + $::op::ERR_INSLOGIN {set msg [mc "Soemthing strange happened. For sure this could be a bug. Please report it"]} \ + $::op::ERR_DUPLOGIN {set msg [mc "This login name is already in use.\nPlease change it."]} ::yalog::error "cannot save operator data" - return [yatk_dlg::error [mc "Something ges wrong, check your data, maybe."]] + return [yatk_dlg::error $msg] } ::yalog::debug "data saved" @@ -1152,145 +1187,23 @@ #trigged when the user press "settings" button #that will enable him/her to configure some... settings :) proc ::yacco::onPressSettings {} { - set w .preferences - set title [mc "Settings"] - toplevel $w -bd 1 -relief raised -class TkSDialog - wm title $w $title - wm iconname $w $title - wm transient $w [winfo toplevel [winfo parent $w]] - - button $w.db -image $::yatk_icons::big_db -text "Database Connection" -compound top \ - -width 130 -command {::yacco::configDb} - button $w.remote -image $::yatk_icons::big_remote -text "Remote Secure Shell" -compound top \ - -width 130 -command {::yacco::configRemote} - button $w.opst -image $::yatk_icons::big_optypes -text "Operator Types" -compound top \ - -width 130 -command {::yacco::configOpst} - button $w.temp -image $::yatk_icons::big_template -text "Documents Template" -compound top \ - -width 130 -command {::yacco::configTemp} - button $w.themes -image $::yatk_icons::big_themes -text "Themes" -compound top \ - -width 130 -command {::yacco::configThemes} - - grid $w.db $w.remote $w.opst -padx 10 -pady 10 - grid $w.temp $w.themes -padx 10 -pady 10 + ::yatk_settings::settings "yacco" } proc ::yacco::configWriteError {} { ::yatk_dlg::error [mc "Error while saving the new configuration to file. Please check and try again"] } -proc ::yacco::configDb {} { - set w .preferences.confDb - set title [mc "Database settings"] - toplevel $w -bd 1 -relief raised -class TkSDialog - wm title $w $title - wm iconname $w $title - wm transient $w [winfo toplevel [winfo parent $w]] - labelframe $w.sample -text "Main database" - message $w.sample.txt -text [mc "Configure parameters to be able to connect \ - to the main yaacs's database (sampling)"] -width 200 - label $w.sample.lblName -text [mc "Database name"] - entry $w.sample.name -bg white - label $w.sample.lblHost -text [mc "Host"] - entry $w.sample.host -bg white - label $w.sample.lblUser -text [mc "User"] - entry $w.sample.user -bg white - label $w.sample.lblPort -text [mc "Port"] - entry $w.sample.port -bg white +proc ::yacco::confDb {dbs dbi} { + global db_int db_sample - grid $w.sample.txt - -padx 5 -pady 5 - grid $w.sample.lblName $w.sample.name -sticky nw -padx 5 -pady 5 - grid $w.sample.lblHost $w.sample.host -sticky nw -padx 5 -pady 5 - grid $w.sample.lblUser $w.sample.user -sticky nw -padx 5 -pady 5 - grid $w.sample.lblPort $w.sample.port -sticky nw -padx 5 -pady 5 + ::yadb::disconnect $db_int + ::yadb::disconnect $db_sample - labelframe $w.op -text "Operator database (will be soon removed)" - - message $w.op.txt -text [mc "Configure parameters to be able to connect \ - to the operators yaacs's database"] -width 200 - label $w.op.lblName -text [mc "Database name"] - entry $w.op.name -bg white - label $w.op.lblHost -text [mc "Host"] - entry $w.op.host -bg white - label $w.op.lblUser -text [mc "User"] - entry $w.op.user -bg white - label $w.op.lblPort -text [mc "Port"] - entry $w.op.port -bg white - - grid $w.op.txt - -padx 5 -pady 5 - grid $w.op.lblName $w.op.name -sticky nw -padx 5 -pady 5 - grid $w.op.lblHost $w.op.host -sticky nw -padx 5 -pady 5 - grid $w.op.lblUser $w.op.user -sticky nw -padx 5 -pady 5 - grid $w.op.lblPort $w.op.port -sticky nw -padx 5 -pady 5 - - frame $w.bts - button $w.bts.ok -image $::yatk_icons::ok -text [mc "Ok"] -compound left \ - -command { - set newDbSample [.preferences.confDb.sample.name get] - set newHostSample [.preferences.confDb.sample.host get] - set newUserSample [.preferences.confDb.sample.user get] - set newPortSample [.preferences.confDb.sample.port get] - - set newDbInt [.preferences.confDb.op.name get] - set newHostInt [.preferences.confDb.op.host get] - set newUserInt [.preferences.confDb.op.user get] - set newPortInt [.preferences.confDb.op.port get] - - #array set oldConf [::yaconf::conf $::yacco::confFile] - - #set oldConf(DB_SAMPLE) $newDbSample - #set oldConf(HOST_SAMPLE) $newHostSample - #set oldConf(USER_SAMPLE) $newUserSample - - #set oldConf(DB_INT) $newDbInt - #set oldConf(HOST_INT) $newHostInt - #set oldConf(USER_INT) $newUserInt - - #if {[::yaconf::writeConfig $::yacco::confFile [array get oldConf]] == -1} { - # ::yacco::configWriteError - #} - - global db_int db_sample - - set db_int_new [::yadb::connect $newDbInt $newHostInt $newUserInt $newPortInt] - set db_sample_new [::yadb::connect $newDbSample $newHostSample $newUserSample $newPortSample] - - if {($db_int_new == -1) || ($db_sample_new == -1)} { - yatk_dlg::error [mc "Cannot connect to dbs please check your settings. Old parameters - has been taken back."] - return - } - - ::yadb::disconnect $db_int - ::yadb::disconnect $db_sample - - set db_sample $db_sample_new - set db_int $db_int_new - set ::yacco::db_int $db_int_new - - destroy .preferences.confDb - } - - button $w.bts.cancel -image $::yatk_icons::cancel -text [mc "Close"] -compound left \ - -command {destroy .preferences.confDb} - - grid $w.bts.cancel $w.bts.ok -sticky se -padx [list 6 0] - - grid $w.sample -padx 12 -pady [list 12 5] - grid $w.op -padx 12 -pady 5 - grid $w.bts -padx 12 -pady 12 -sticky se - - #set intial values - - $w.sample.name insert 0 $::yacco::config(DB_SAMPLE) - $w.sample.host insert 0 $::yacco::config(HOST_SAMPLE) - $w.sample.user insert 0 $::yacco::config(USER_SAMPLE) - $w.sample.port insert 0 $::yacco::config(PORT_SAMPLE) - - $w.op.name insert 0 $::yacco::config(DB_INT) - $w.op.host insert 0 $::yacco::config(HOST_INT) - $w.op.user insert 0 $::yacco::config(USER_INT) - $w.op.port insert 0 $::yacco::config(PORT_INT) + set db_sample $dbs + set db_int $dbi + set ::yacco::db_int $dbi } proc ::yacco::configRemote {} { @@ -1318,6 +1231,14 @@ -command { set ::yacco::config(REMOTE_HOST) [.preferences.confRemote.fr.host get] set ::yacco::config(REMOTE_USER) [.preferences.confRemote.fr.user get] + + set pathConf [::yaconf::checkLocalConf] + set pathConf "$pathConf/yacco" + + set myconfig(REMOTE_HOST) $::yacco::config(REMOTE_HOST) + set myconfig(REMOTE_USER) $::yacco::config(REMOTE_USER) + ::yaconf::writeConfig $pathConf [array get myconfig] + destroy .preferences.confRemote } button $w.bts.cancel -image $::yatk_icons::cancel -text [mc "Close"] -compound left \ @@ -1478,39 +1399,6 @@ return } -proc ::yacco::configThemes {} { - set w .preferences.confThemes - set title [mc "Choose a theme"] - toplevel $w -bd 1 -relief raised -class TkSDialog - wm title $w $title - wm iconname $w $title - wm transient $w [winfo toplevel [winfo parent $w]] - - set ::yacco::availableThemes [list] - foreach file [glob -nocomplain -directory $::yatk_themes::basePath -types d *] { - set theme [lindex [file split $file] [expr [llength [file split $file]] -1]] - lappend ::yacco::availableThemes $theme - } - - labelframe $w.th -text [mc "Themes"] - scrollbar $w.th.sbThemes -orient vertical -command {.preferences.confThemes.th.lstThemes yview} -borderwidth 0 - listbox $w.th.lstThemes -listvariable ::yacco::availableThemes -bg white \ - -yscrollcommand {.preferences.confThemes.th.sbThemes set} - grid $w.th.lstThemes $w.th.sbThemes -sticky ns -pady 5 - - frame $w.bts - button $w.bts.ok -image $::yatk_icons::ok -text [mc "Apply theme"] -compound left \ - -command {::yatk_themes::init [lindex $::yacco::availableThemes \ - [.preferences.confThemes.th.lstThemes curselection]]} - button $w.bts.cancel -image $::yatk_icons::cancel -text [mc "Close"] -compound left \ - -command {destroy .preferences.confThemes} - - grid $w.bts.cancel $w.bts.ok -padx [list 6 0] - - grid $w.th -sticky news -padx 12 -pady 12 - grid $w.bts -sticky se -padx 12 -pady 12 -} - # trigged when the user press button Quit proc ::yacco::onPressQuit {} { exit @@ -1530,7 +1418,14 @@ set cf [yamisc::calc_cod_fisc $db_int $tmp(surname) $tmp(name) $tmp(bdate) $tmp(bplace) $tmp(sex)] if { $cf== -1 } { - yatk_dlg::error [mc "Some entry to calculate cod.fisc. are wrong, please check the vaules"] + set msg "Some entry caused an error on code calculation" + switch -exact -- $::yamisc::err $::yamisc::ERR_NOCOM {set msg [mc "Operator's birth place caused \ + an error on code calculation."]} \ + $::yamisc::ERR_SURALG {set msg [mc "Operator's surname caused an error on code calculation due \ + to a lack in the algorithm used."]} \ + $::yamisc::ERR_NAMALG {set msg [mc "Operator's name value caused an error on code calculation due \ + to a lack in the algorithm used."]} + yatk_dlg::error $msg } else { yacco::setWdjValue codfis $cf } @@ -2378,18 +2273,19 @@ } "edit" { - yacco::configureWdj btsms state normal - yacco::configureWdj btlink state normal - yacco::configureWdj btreset state normal - yacco::configureWdj btconv state normal - yacco::configureWdj btrit state normal - yacco::configureWdj btsave state normal - yacco::configureWdj btdelete state normal - yacco::configureWdj btnew state normal - yacco::configureWdj btfind state normal + ::yacco::configureWdj btsms state normal + ::yacco::configureWdj btlink state normal + ::yacco::configureWdj btreset state normal + ::yacco::configureWdj btconv state normal + ::yacco::configureWdj btrit state normal + ::yacco::configureWdj btsave state normal + ::yacco::configureWdj btdelete state normal + ::yacco::configureWdj btnew state normal + ::yacco::configureWdj btfind state normal ::yacco::configureWdj btcodfis state normal - ::yacco::set_editfields_state normal + ::yacco::set_editfields_state normal + ::yacco::configureWdj login state disabled } default { puts "DOH $status" @@ -2468,26 +2364,6 @@ # main ## -# Getting cmdline opt -set carg [list "c.arg" "/etc/yaacs/yaacs.conf" [mc "config file"]] -set larg [list "l.arg" "" [mc "Log level"]] -set yaccoptions [list $carg $larg] -set yaccousage "yacco: \[-c <config file>\] \[-l <log level>\]" - -if { [catch {array set gettedopts [::cmdline::getoptions argv $yaccoptions $yaccousage]} err] } { - cmderrmsg "" $yaccoptions $yaccousage - exit 1 -} - -if { !([file exists $gettedopts(c)] && [file isfile $gettedopts(c)]) } { - cmderrmsg [mc "error: couldn't find %s" $gettedopts(c)] $yaccoptions $yaccousage - exit 1 -} -## -# Init config package -array set ::yacco::config [::yaconf::conf $gettedopts(c)] -set ::yacco::confFile $gettedopts(c) -## # Init log ::yalog::setFile [::yaconf::getLogFile] if { ($gettedopts(l)!="") } { @@ -2510,19 +2386,18 @@ ## # Init db packages -yalog::message "Connecting to db..." +::yalog::message "Connecting to db..." set db_int [::yadb::connect $::yacco::config(DB_INT) $::yacco::config(HOST_INT) $::yacco::config(USER_INT) \ $::yacco::config(PORT_INT)] set db_sample [::yadb::connect $::yacco::config(DB_SAMPLE) $::yacco::config(HOST_SAMPLE) \ $::yacco::config(USER_SAMPLE) $::yacco::config(PORT_SAMPLE)] if {($db_int==-1) || ($db_sample==-1)} { - yatk_dlg::error [mc "Cannot connect to dbs please check your conf"] - exit + yatk_dlg::error [mc "Cannot connect to database(s) please check your conf"] + exit } set ::yacco::db_int $db_int - ## # Setting up connection loss handler set loss_sample { Modified: trunk/yadmin.tcl =================================================================== --- trunk/yadmin.tcl 2006-03-22 18:13:06 UTC (rev 573) +++ trunk/yadmin.tcl 2006-03-22 18:17:32 UTC (rev 574) @@ -110,8 +110,20 @@ set yadmin::pj $gettedopts(p) } +set yaacsHome [::yaconf::checkLocalConf] array set config [::yaconf::conf $gettedopts(c)] +array set userconf [::yaconf::conf "$yaacsHome/yadmin"] +foreach k [array names userconf] { + set config($k) $userconf($k) +} +array set ::yadmin::config [array get config] +if {[info exists ::yadmin::config(THEME)]} { + ::yatk_themes::init $::yadmin::config(THEME) +} else { + ::yatk_themes::init +} + #log settings #default settings @@ -136,33 +148,6 @@ } } -set yaacsHome [::yaconf::checkLocalConf] -set themeRcFile [file join $yaacsHome yadmin.theme] -if {[file exist $themeRcFile] && [file isfile $themeRcFile]} { - set f [open $themeRcFile] - set theme [lindex [read $f] 0] - close $f -} -if {[info exists theme]} { - if {[::yatk_themes::init $theme] == -1} { - puts "bad theme!!! go configure it in the right way." - exit - } else { - set ::yadmin::theme $theme - } -} else { - if {[::yatk_themes::init] == -1} { - puts "bad theme!!! go configure it in the right way." - exit - } -} - -if {[info exists ::config(THEMES)] && $config(THEMES) == "yes"} { - set ::yadmin::allowChangeTheme 1 -} else { - set ::yadmin::allowChangeTheme 0 -} - #GUI DEFINITION # handle the "exitY" wm event @@ -243,9 +228,9 @@ .mbar.mpj add separator .mbar.mpj add command -label [mc "Turns definition"] -command {::yadmin::turnDef $db_sample} .mbar.mpj add separator -.mbar.mpj add command -label [mc "Massive fax..."] -command {::yadmin::massiveFax $db_sample $config(FAX_SERVER)} -.mbar.mpj add command -label [mc "Massive mail..."] -command {::yadmin::massiveMail $db_sample $config(MAIL_SERVER) \ - $config(MAIL_SENDER)} +.mbar.mpj add command -label [mc "Massive fax..."] -command {::yadmin::massiveFax $db_sample $::yadmin::config(FAX_SERVER)} +.mbar.mpj add command -label [mc "Massive mail..."] -command {::yadmin::massiveMail $db_sample $::yadmin::config(MAIL_SERVER) \ + $::yadmin::config(MAIL_SENDER)} .mbar.mpj add separator .mbar.mpj add cascade -label [mc "Stats managment"] -menu .mbar.mpj.statmgmt @@ -3287,60 +3272,99 @@ } proc ::yadmin::preferences {} { - set w .preferences - set title [mc "Settings"] + ::yatk_settings::settings "yadmin" +} + +proc ::yadmin::confDb {dbs dbi} { + global db_int db_sample + + ::yadb::disconnect $db_int + ::yadb::disconnect $db_sample + + set db_sample $dbs + set db_int $dbi +} + +proc ::yadmin::configFax {} { + set w .preferences.confFax + set title [mc "Fax server configuration"] toplevel $w -bd 1 -relief raised -class TkSDialog wm title $w $title wm iconname $w $title wm transient $w [winfo toplevel [winfo parent $w]] - button $w.db -image $::yatk_icons::big_db -text "Database Connection" -compound top \ - -width 130 -command {} - button $w.fax -image $::yatk_icons::big_fax -text "Fax" -compound top \ - -width 130 -command {} - button $w.email -image $::yatk_icons::big_email -text "Email" -compound top \ - -width 130 -command {} - button $w.themes -image $::yatk_icons::big_themes -text "Themes" -compound top \ - -width 130 -command {::yadmin::configThemes} + labelframe $w.fr + message $w.fr.txt -text [mc "Configure fax server parameters"] -width 300 + label $w.fr.lblHost -text [mc "Fax server"] + entry $w.fr.host -bg white - grid $w.db $w.fax -padx 10 -pady 10 - grid $w.email $w.themes -padx 10 -pady 10 + grid $w.fr.txt - -sticky we -padx 5 -pady 5 + grid $w.fr.lblHost $w.fr.host -sticky w -padx 5 -pady 5 + + frame $w.bts + button $w.bts.ok -image $::yatk_icons::ok -text [mc "Ok"] -compound left \ + -command { + set ::yadmin::config(FAX_SERVER) [.preferences.confFax.fr.host get] + + set pathConf [::yaconf::checkLocalConf] + set pathConf "$pathConf/yadmin" + + set myconfig(FAX_SERVER) $::yadmin::config(FAX_SERVER) + ::yaconf::writeConfig $pathConf [array get myconfig] + } + button $w.bts.cancel -image $::yatk_icons::cancel -text [mc "Close"] -compound left \ + -command {destroy .preferences.confFax} + + grid $w.bts.cancel $w.bts.ok -padx [list 6 0] -sticky se + + grid $w.fr -padx 12 -pady [list 12 24] -sticky news + grid $w.bts -padx 12 -pady 12 -sticky se + + $w.fr.host insert 0 $::yadmin::config(FAX_SERVER) } -proc ::yadmin::configThemes {} { - set w .preferences.confThemes - set title [mc "Choose a theme"] +proc ::yadmin::configEmail {} { + set w .preferences.confEmail + set title [mc "Email sending configuration"] toplevel $w -bd 1 -relief raised -class TkSDialog wm title $w $title wm iconname $w $title wm transient $w [winfo toplevel [winfo parent $w]] - set ::yadmin::availableThemes [list] - foreach file [glob -nocomplain -directory $::yatk_themes::basePath -types d *] { - set theme [lindex [file split $file] [expr [llength [file split $file]] -1]] - lappend ::yadmin::availableThemes $theme - } + labelframe $w.fr + message $w.fr.txt -text [mc "Configure email sending parameters"] -width 300 + label $w.fr.lblHost -text [mc "Mail (smtp) server"] + entry $w.fr.host -bg white + label $w.fr.lblSender -text [mc "Mail sender address"] + entry $w.fr.sender -bg white - labelframe $w.th -text [mc "Themes"] - scrollbar $w.th.sbThemes -orient vertical -command {.preferences.confThemes.th.lstThemes yview} -borderwidth 0 - listbox $w.th.lstThemes -listvariable ::yadmin::availableThemes -bg white \ - -yscrollcommand {.preferences.confThemes.th.sbThemes set} - grid $w.th.lstThemes $w.th.sbThemes -sticky ns -pady 10 + grid $w.fr.txt - -sticky we -padx 5 -pady 5 + grid $w.fr.lblHost $w.fr.host -sticky w -padx 5 -pady 5 + grid $w.fr.lblSender $w.fr.sender -sticky w -padx 5 -pady 5 - button $w.ok -image $::yatk_icons::ok -text [mc "Apply theme"] -compound left \ + frame $w.bts + button $w.bts.ok -image $::yatk_icons::ok -text [mc "Ok"] -compound left \ -command { - # potrei usare questa ::yadmin::saveSetTheme {theme} - # ma a questo punto converra' fare un rc file unico - # per l'applicazione invece che averne uno solo per il tema ;) + set ::yadmin::config(MAIL_SERVER) [.preferences.confEmail.fr.host get] + set ::yadmin::config(MAIL_SENDER) [.preferences.confEmail.fr.sender get] - ::yatk_themes::init [lindex $::yadmin::availableThemes \ - [.preferences.confThemes.th.lstThemes curselection]] - } - button $w.cancel -image $::yatk_icons::cancel -text [mc "Close"] -compound left \ - -command {destroy .preferences.confThemes} - - grid $w.th - -padx 10 -pady 5 - grid $w.ok $w.cancel -padx 5 -pady 10 + set pathConf [::yaconf::checkLocalConf] + set pathConf "$pathConf/yadmin" + + set myconfig(MAIL_SERVER) $::yadmin::config(MAIL_SERVER) + set myconfig(MAIL_SENDER) $::yadmin::config(MAIL_SENDER) + ::yaconf::writeConfig $pathConf [array get myconfig] + } + button $w.bts.cancel -image $::yatk_icons::cancel -text [mc "Close"] -compound left \ + -command {destroy .preferences.confEmail} + + grid $w.bts.cancel $w.bts.ok -padx [list 6 0] -sticky se + + grid $w.fr -padx 12 -pady [list 12 24] -sticky news + grid $w.bts -padx 12 -pady 12 -sticky se + + $w.fr.host insert 0 $::yadmin::config(MAIL_SERVER) + $w.fr.sender insert 0 $::yadmin::config(MAIL_SENDER) } # INITIALIZATION @@ -3406,44 +3430,6 @@ yadmin::setOssPBackto $db_sample $yadmin::turnBack array set yadmin::turns [yadmin::turnArray $db_sample] -bind . <Button-3> [list ::yadmin::showpopup %X %Y] - -proc ::yadmin::saveSetTheme {theme} { - if {[::yatk_themes::init $theme] != -1} { - set yaacsHome [::yaconf::checkLocalConf] - set themeRcFile [file join $yaacsHome yadmin.theme] - set f [open $themeRcFile w+] - puts $f $theme - close $f - } else { - # if something goes wrong goes back to the previous one - if {$::yadmin::theme != ""} { - ::yatk_themes::init $::yadmin::theme - } else { - ::yatk_themes::init - } - } -} - -proc ::yadmin::showpopup {x y} { - # create menu to popup - catch {destroy .mclick} - set m [menu .mclick -tearoff 0 -relief flat -bg lightyellow -bd 1] - if {$::yadmin::allowChangeTheme} { - set subTheme [menu .mclick.theme -tearoff 0 -bg lightyellow -relief flat -bd 1] - # add a command for each theme installed - foreach file [glob -nocomplain -directory $::yatk_themes::basePath -types d *] { - set theme [lindex [file split $file] [expr [llength [file split $file]] -1]] - $subTheme add command -label $theme -command "::yadmin::saveSetTheme $theme" - } - $m add cascade -label themes -menu $subTheme - } - - # pop the menu up - - tk_popup $m $x $y -} - set x [expr {[winfo screenwidth .]/2 - [winfo reqwidth .]/2 - [winfo vrootx .]}] set y [expr {[winfo screenheight .]/2 - [winfo reqheight .]/2 - [winfo vrooty .]}] wm geom . +$x+$y This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |