1# IaxPrefs.tcl -- 2# 3# iaxClient phone UI 4# 5# Copyright (c) 2006 Antonio Cano damas 6# 7# This program is free software: you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation, either version 3 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program. If not, see <http://www.gnu.org/licenses/>. 19# 20# $Id: IaxPrefs.tcl,v 1.12 2007-09-16 07:39:11 matben Exp $ 21 22package provide IaxPrefs 0.1 23 24namespace eval ::IaxPrefs { 25 26 ::hooks::register prefsInitHook ::IaxPrefs::InitPrefsHook 27 ::hooks::register prefsBuildHook ::IaxPrefs::BuildPrefsHook 28 ::hooks::register prefsSaveHook ::IaxPrefs::SavePrefsHook 29 ::hooks::register prefsCancelHook ::IaxPrefs::CancelPrefsHook 30 ::hooks::register prefsUserDefaultsHook ::IaxPrefs::UserDefaultsHook 31} 32 33################## Preferences Stuff ################### 34proc ::IaxPrefs::InitPrefsHook { } { 35 global prefs 36 37 set prefs(iaxPhone,user) "" 38 set prefs(iaxPhone,password) "" ;# Was 0 39 set prefs(iaxPhone,host) "" ;# Was 0 40 set prefs(iaxPhone,cidnum) 0 41 set prefs(iaxPhone,cidname) "" 42 set prefs(iaxPhone,codec) "SPEEX" 43 set prefs(iaxPhone,inputDevices) "" 44 set prefs(iaxPhone,outputDevices) "" 45 set prefs(iaxPhone,agc) 0 46 set prefs(iaxPhone,aagc) 0 47 set prefs(iaxPhone,noise) 0 48 set prefs(iaxPhone,comfort) 0 49# set prefs(iaxPhone,echo) 0 50 51 variable allKeys 52 set allKeys {user password host cidnum cidname codec \ 53 inputDevices outputDevices agc aagc noise comfort} 54 # echo 55 56 set plist {} 57 foreach key $allKeys { 58 set name prefs(iaxPhone,$key) 59 set rsrc prefs_iaxPhone_$key 60 set val [set $name] 61 lappend plist [list $name $rsrc $val] 62 } 63 ::PrefUtils::Add $plist 64 VerifySanity 65} 66 67proc ::IaxPrefs::VerifySanity { } { 68 global prefs 69 70 # Verify booleans. 71 foreach key {cidnum agc aagc noise comfort} { 72 set value $prefs(iaxPhone,$key) 73 if {!(($value == 0) || ($value == 1))} { 74 set prefs(iaxPhone,$key) 0 75 } 76 } 77} 78 79# IaxPrefs::GetAll -- 80# 81# A way to get all relevant IAX prefs with simple names. 82 83proc ::IaxPrefs::GetAll { } { 84 global prefs 85 variable allKeys 86 87 set plist {} 88 foreach key $allKeys { 89 lappend plist $key $prefs(iaxPhone,$key) 90 } 91 return $plist 92} 93 94proc ::IaxPrefs::BuildPrefsHook {wtree nbframe} { 95 global prefs 96 variable tmpPrefs 97 98 if {![::Preferences::HaveTableItem {phone}]} { 99 ::Preferences::NewTableItem {phone} [mc "Phone"] 100 } 101 ::Preferences::NewTableItem {phone iax} [mc "IAX Phone"] 102 103 set wpage [$nbframe page {iax}] 104 BuildPage $wpage 105 106} 107 108proc ::IaxPrefs::BuildPage {page} { 109 global prefs 110 variable tmpPrefs 111 112 set wc $page.i 113 ttk::frame $wc -padding [option get . notebookPageSmallPadding {}] 114 pack $wc -side top -anchor [option get . dialogAnchor {}] 115 116 set waccount $wc.ac 117 AccountFrame $waccount 118 119 set wnb $wc.nb 120 ttk::notebook $wnb -padding {8 12 8 8} 121 122 grid $waccount -sticky ew -padx 8 123 grid $wnb -sticky ew 124 125 # Switch off devices since can create a misery for some users! 126 $wnb add [DevicesFrame $wnb.de] -text [mc "Devices"] 127 $wnb add [FiltersFrame $wnb.fi] -text [mc "Filters"] 128 $wnb add [CodecsFrame $wnb.co] -text [mc "Codecs"] 129 130 bind $page <Destroy> +[namespace current]::Free 131} 132 133proc ::IaxPrefs::AccountFrame {win} { 134 global prefs 135 variable tmpPrefs 136 137 ttk::labelframe $win -text [mc "IAX Account"] \ 138 -padding [option get . groupSmallPadding {}] 139 pack $win -side top -anchor w 140 141 foreach key {user password host cidnum cidname} { 142 set tmpPrefs($key) $prefs(iaxPhone,$key) 143 } 144 145 ttk::label $win.luser -text [mc "Username"]: 146 ttk::entry $win.user -textvariable [namespace current]::tmpPrefs(user) 147 148 ttk::label $win.lpassword -text [mc "Password"]: 149 ttk::entry $win.password -textvariable [namespace current]::tmpPrefs(password) \ 150 -show {*} 151 152 ttk::label $win.lhost -text [mc "Host"]: 153 ttk::entry $win.host -textvariable [namespace current]::tmpPrefs(host) 154 155 ttk::label $win.lcidnum -text [mc "Caller ID number"]: 156 ttk::entry $win.cidnum -textvariable [namespace current]::tmpPrefs(cidnum) 157 158 ttk::label $win.lcidname -text [mc "Caller ID name"]: 159 ttk::entry $win.cidname -textvariable [namespace current]::tmpPrefs(cidname) 160 161 grid $win.luser $win.user -sticky e -pady 2 162 grid $win.lpassword $win.password -sticky e -pady 2 163 grid $win.lhost $win.host -sticky e -pady 2 164 grid $win.lcidnum $win.cidnum -sticky e -pady 2 165 grid $win.lcidname $win.cidname -sticky e -pady 2 166 167 return $win 168} 169 170proc ::IaxPrefs::DevicesFrame {win} { 171 global prefs 172 variable tmpPrefs 173 174 ttk::frame $win -padding [option get . groupSmallPadding {}] 175 pack $win -side top -anchor w 176 177 set listInputDevices [iaxclient::devices input] 178 set listOutputDevices [iaxclient::devices output] 179 180 # Workaround for old buggy linux build. 181 if {[catch { 182 set prefs(iaxPhone,inputDevices) [lindex [iaxclient::devices input -current] 0] 183 set prefs(iaxPhone,outputDevices) [lindex [iaxclient::devices output -current] 0] 184 }]} { 185 set prefs(iaxPhone,inputDevices) [lindex $listInputDevices 0 0] 186 set prefs(iaxPhone,outputDevices) [lindex $listOutputDevices 0 0] 187 } 188 set tmpPrefs(inputDevices) $prefs(iaxPhone,inputDevices) 189 set tmpPrefs(outputDevices) $prefs(iaxPhone,outputDevices) 190 191 foreach device $listInputDevices { 192 lappend inputDevices [lindex $device 0] 193 } 194 ttk::label $win.linputDev -text [mc "Microphone"]: 195 ttk::combobox $win.input_dev -state readonly \ 196 -textvariable [namespace current]::tmpPrefs(inputDevices) -values $inputDevices 197 198 foreach device $listOutputDevices { 199 lappend outputDevices [lindex $device 0] 200 } 201 ttk::label $win.loutputDev -text [mc "Speakers"]: 202 ttk::combobox $win.output_dev -state readonly \ 203 -textvariable [namespace current]::tmpPrefs(outputDevices) \ 204 -values $outputDevices 205 206 grid $win.linputDev $win.input_dev -sticky e -pady 2 207 grid $win.loutputDev $win.output_dev -sticky e -pady 2 208 209 return $win 210} 211 212proc ::IaxPrefs::FiltersFrame {win} { 213 global prefs 214 variable tmpPrefs 215 216 ttk::frame $win -padding [option get . groupSmallPadding {}] 217 pack $win -side top -anchor w 218 219 foreach key {agc aagc noise comfort} { 220 set tmpPrefs($key) $prefs(iaxPhone,$key) 221 } 222# set tmpPrefs(echo) $prefs(iaxPhone,echo) 223 224 ttk::checkbutton $win.agc -text [mc "Automatic gain control (AGC)"] \ 225 -variable [namespace current]::tmpPrefs(agc) 226 ttk::checkbutton $win.aagc -text [mc "Analog automatic gain control (AAGC)"] \ 227 -variable [namespace current]::tmpPrefs(aagc) 228 ttk::checkbutton $win.noise -text [mc "Noise reduction"] \ 229 -variable [namespace current]::tmpPrefs(noise) 230 ttk::checkbutton $win.comfort -text [mc "Comfort noise"] \ 231 -variable [namespace current]::tmpPrefs(comfort) 232# ttk::checkbutton $win.echo -text [mc "Echo"] \ 233# -variable [namespace current]::tmpPrefs(echo) 234 235 grid $win.agc -sticky w 236 grid $win.aagc -sticky w 237 grid $win.noise -sticky w 238 grid $win.comfort -sticky w 239# grid $win.echo -sticky w 240 241 ::balloonhelp::balloonforwindow $win.agc [mc "Automatically adjust volume levels"] 242 ::balloonhelp::balloonforwindow $win.aagc [mc "Can prevent clipping"] 243 ::balloonhelp::balloonforwindow $win.comfort [mc "Artificial background noise to fill silence"] 244 245 return $win 246} 247 248proc ::IaxPrefs::CodecsFrame {win} { 249 global prefs 250 variable tmpPrefs 251 252 ttk::frame $win -padding [option get . groupSmallPadding {}] 253 pack $win -side top -anchor w 254 255 set tmpPrefs(codec) $prefs(iaxPhone,codec) 256 257 ttk::label $win.lcodec -text [mc "Codec"]: 258 259 ttk::radiobutton $win.codeci -text "iLBC" -variable [namespace current]::tmpPrefs(codec) -value "ILBC" 260 ttk::radiobutton $win.codecs -text "Speex" -variable [namespace current]::tmpPrefs(codec) -value "SPEEX" 261 ttk::radiobutton $win.codeca -text "aLaw" -variable [namespace current]::tmpPrefs(codec) -value "ALAW" 262 ttk::radiobutton $win.codecu -text "uLaw" -variable [namespace current]::tmpPrefs(codec) -value "ULAW" 263 ttk::radiobutton $win.codecg -text "GSM" -variable [namespace current]::tmpPrefs(codec) -value "GSM" 264 265 # If you add more codecs use a new column. 266 grid $win.lcodec $win.codeci -sticky w 267 grid x $win.codecs -sticky w 268 grid x $win.codeca -sticky w 269 grid x $win.codecu -sticky w 270 grid x $win.codecg -sticky w 271 grid $win.lcodec -padx 4 272 273 ::balloonhelp::balloonforwindow $win.codeci [mc "iLBC (internet Low Bitrate Codec) is a free speech codec suitable for robust voice communication over IP"] 274 ::balloonhelp::balloonforwindow $win.codecs [mc "Speex is an Open Source/Free Software patent-free audio compression format designed for speech"] 275 ::balloonhelp::balloonforwindow $win.codeca [mc "Standard used in European digital communication systems (ITU-T)"] 276 ::balloonhelp::balloonforwindow $win.codecu [mc "Standard used in digital communication systems in North America and Japan (ITU-T)"] 277 ::balloonhelp::balloonforwindow $win.codecg [mc "GSM 06.10 provisional standard for full-rate speech transcoding (ETSI)"] 278 279 return $win 280} 281 282proc ::IaxPrefs::SavePrefsHook { } { 283 global prefs 284 variable tmpPrefs 285 variable allKeys 286 287 foreach key $allKeys { 288 if {[info exists tmpPrefs($key)]} { 289 set prefs(iaxPhone,$key) $tmpPrefs($key) 290 } 291 } 292 VerifySanity 293 ::Iax::Reload 294} 295 296proc ::IaxPrefs::CancelPrefsHook { } { 297 global prefs 298 variable tmpPrefs 299 variable allKeys 300 301 foreach key $allKeys { 302 if {[info exists tmpPrefs($key)]} { 303 if {![string equal $prefs(iaxPhone,$key) $tmpPrefs($key)]} { 304 ::Preferences::HasChanged 305 break 306 } 307 } 308 } 309} 310 311proc ::IaxPrefs::UserDefaultsHook { } { 312 global prefs 313 variable tmpPrefs 314 variable allKeys 315 316 foreach key $allKeys { 317 set tmpPrefs($key) $prefs(iaxPhone,$key) 318 } 319} 320 321proc ::IaxPrefs::Free { } { 322 variable tmpPrefs 323 324 unset -nocomplain tmpPrefs 325} 326