Hello once again.

Here I leave a new version of the patch (now the end is nearer =]).

I have corrected several bugs that there have been appearing and removed
duplicated code.
I have also added KDE support. The method I have finally used to
determine which desktop is the user running is the same that the
desktop_integration plugin was using. I have adapted that function and
copied it into config.tcl.

I didn't know what else to do.
Tell me if it fits now (or what doesn't fit yet).

-- 
Regards, Pablo.


Youness Alaoui wrote:
> [...]
Index: lang/langen
===================================================================
--- lang/langen (revisión: 11095)
+++ lang/langen (copia de trabajo)
@@ -940,6 +940,7 @@
 subject Subject
 svnversion SVN Version
 syntaxerror Syntax Error
+systemconnection Use system proxy settings
 tabbedglobal A tabbed window for all users in the contact list
 tabbedgroups A tabbed window for users from the same group
 tabbed Tabbed Windows
Index: lang/langes
===================================================================
--- lang/langes (revisión: 11095)
+++ lang/langes (copia de trabajo)
@@ -941,6 +941,7 @@
 subjectrequired Asunto requerido
 svnversion Versión SVN
 syntaxerror Error de sintaxis
+systemconnection Usar los datos de proxy del sistema
 tabbedglobal Una ventana con pestañas para todos los usuarios
 tabbedgroups Una ventana con pestañas para cada grupo
 tabbed Ventanas con pestañas
Index: protocol.tcl
===================================================================
--- protocol.tcl        (revisión: 11095)
+++ protocol.tcl        (copia de trabajo)
@@ -7361,7 +7361,8 @@
                #::Proxy::Setup next readable_handler $name
 
 
-       } elseif { [::config::getKey connectiontype] == "proxy" && 
[::config::getKey proxytype] == "http" } {
+       } elseif { [::config::getKey connectiontype] == "proxy" && \
+                          ([::config::getKey proxytype] == "http" || 
[::config::getKey proxytype] == "system") } {
 
                #TODO: Right now it's always HTTP proxy!!
                #$name configure -connection_wrapper HTTPConnection
@@ -7394,7 +7395,6 @@
                $name configure -proxy_authenticate [::config::getKey 
proxyauthenticate]
                $name configure -proxy_user [::config::getKey proxyuser]
                $name configure -proxy_password [::config::getKey proxypass]
-
        } else {
                #$name configure -connection_wrapper DirectConnection
                ::config::setKey connectiontype "direct"
Index: login_screen.tcl
===================================================================
--- login_screen.tcl    (revisión: 11095)
+++ login_screen.tcl    (copia de trabajo)
@@ -786,6 +786,12 @@
                        CreateProfile $user
                }
 
+               #load system-wide proxy settings
+               #
+               if {[OnUnix] && [::config::getKey connectiontype] == "proxy" && 
[::config::getKey proxytype] == "system"} {
+                       load_unix_system_proxy
+               }
+
                # Login with them
                $self login $user $pass
        }
Index: preferences.tcl
===================================================================
--- preferences.tcl     (revisión: 11095)
+++ preferences.tcl     (copia de trabajo)
@@ -2221,6 +2221,11 @@
        grid $lfname.4.ssl -row 1 -column 2 -sticky w -pady 5 -padx 10
        grid $lfname.4.socks5 -row 1 -column 3 -sticky w -pady 5 -padx 10
 
+       #Only show this option if the OS supports a system-wide proxy 
configuration.
+       if { [OnUnix] } {
+               radiobutton $lfname.4.system -text "[trans systemconnection]" 
-value system -variable [::config::getVar proxytype] -command UpdatePreferences
+               grid $lfname.4.system -row 1 -column 4 -sticky w -pady 5 -padx 
10
+       }
                
        label $lfname.5.lserver -text "[trans server] :" -padx 5 -font sboldf
        entry $lfname.5.server -font splainf  -width 20 -textvariable 
proxy_server
@@ -3108,11 +3113,11 @@
                $lfname.lfname2.statelist.box insert end [lindex [StateList get 
$idx] 0]
        }
 
-        # Fill the user's lists
-        #set lfname [Rnotebook:frame $nb $Preftabs(privacy)]
+       # Fill the user's lists
+       #set lfname [Rnotebook:frame $nb $Preftabs(privacy)]
        set lfname [$nb.nn getframe privacy]
        set lfname [$lfname.sw.sf getframe]
-        Fill_users_list "$lfname.lfname" "$lfname.lfname2"
+       Fill_users_list "$lfname.lfname" "$lfname.lfname2"
 
 }
 
@@ -3120,6 +3125,9 @@
 # This is where the preferences entries get enabled disabled
 proc UpdatePreferences {} {
        global Preftabs
+       global proxy_server proxy_port proxy_user proxy_pass
+       global manual_proxy_settings  #cambiar old por manual 
+       global old_proxy_settings #the proxy before user changed anything (when 
opening prefs window)
 
        set nb .cfg.notebook
 
@@ -3164,12 +3172,40 @@
                $lfname.4.post configure -state normal
                $lfname.4.ssl configure -state disable
                $lfname.4.socks5 configure -state normal
+               $lfname.4.system configure -state normal
                $lfname.5.server configure -state normal
                $lfname.5.port configure -state normal
+
+               if { ![info exists old_proxy_settings] } {
+                       set old_proxy_settings [list $proxy_server $proxy_port 
[::config::getKey proxyauthenticate] \
+                                                                               
$proxy_user $proxy_pass [::config::getKey proxytype]]
+               }
+
+               if { [info exists manual_proxy_settings] } {
+                       set proxy_server [lindex $manual_proxy_settings 0]
+                       set proxy_port [lindex $manual_proxy_settings 1]
+                       ::config::setKey proxyauthenticate [lindex 
$manual_proxy_settings 2]
+                       set proxy_user [lindex $manual_proxy_settings 3]
+                       set proxy_pass [lindex $manual_proxy_settings 4]
+                       unset manual_proxy_settings
+               }
+
                if { [::config::getKey proxytype] == "socks5" || 
[::config::getKey proxytype] == "http"} {
                        $lfname.5.user configure -state normal
                        $lfname.5.pass configure -state normal
+               } elseif { [::config::getKey proxytype] == "system"} {
+
+                       if { [lindex $old_proxy_settings 5] != "system" } {
+                               set manual_proxy_settings [list $proxy_server 
$proxy_port [::config::getKey proxyauthenticate] $proxy_user $proxy_pass]
+                       }
+
+                       load_unix_system_proxy
+                       $lfname.5.server configure -state disabled
+                       $lfname.5.port configure -state disabled
+                       $lfname.5.user configure -state disabled
+                       $lfname.5.pass configure -state disabled
                } else {
+                       
                        $lfname.5.user configure -state disabled
                        $lfname.5.pass configure -state disabled
                }
@@ -3177,6 +3213,7 @@
                $lfname.4.post configure -state disabled
                $lfname.4.ssl configure -state disabled
                $lfname.4.socks5 configure -state disabled
+               $lfname.4.system configure -state disabled
                $lfname.5.server configure -state disabled
                $lfname.5.port configure -state disabled
                $lfname.5.user configure -state disabled
@@ -3249,6 +3286,7 @@
 proc SavePreferences {} {
        global auto_path HOME2 tlsinstalled
        global myconfig proxy_server proxy_port list_BLP temp_BLP Preftabs 
libtls proxy_user proxy_pass pager locale_codes
+       global old_proxy_settings
 
        set nb .cfg.notebook
 
@@ -3279,6 +3317,10 @@
                ::config::setKey proxyauthenticate 0
        }
 
+       catch {
+               unset old_proxy_settings
+       }
+
        if {![string is digit [::config::getKey initialftport]] || [string 
length [::config::getKey initialftport]] == 0 } {
                ::config::setKey initialftport 6891
        }
@@ -3449,8 +3491,25 @@
        
        if { $win != ".cfg" } { return }
 
-       global myconfig proxy_server proxy_port
+       global myconfig
+       global proxy_server proxy_user proxy_pass 
+       global manual_proxy_settings old_proxy_settings
+
+       if { [info exists old_proxy_settings] } {
+               status_log "resetting to from $old_proxy_settings" red
+               status_log "others: [array size myconfig]" red
+               set myconfig(proxy) [list [lindex $old_proxy_settings 0] 
[lindex $old_proxy_settings 1]]
+               set myconfig(proxyauthenticate) [lindex $old_proxy_settings 2] 
+               set proxy_user [lindex $old_proxy_settings 3]
+               set proxy_pass [lindex $old_proxy_settings 4]
+               set myconfig(proxytype) [lindex $old_proxy_settings 5]
+       }
        
+       catch {
+               unset manual_proxy_settings
+               unset old_proxy_settings
+       }
+
        ::config::setAll [array get myconfig]
        array unset myconfig
 
Index: soap.tcl
===================================================================
--- soap.tcl    (revisión: 11095)
+++ soap.tcl    (copia de trabajo)
@@ -63,7 +63,8 @@
                        ::http::config -proxyhost "" -proxyport ""
                        http::register https 443 ::tls::socket
                        http::register http 80 ::socket
-               } elseif { [::config::getKey connectiontype] == "proxy" && 
[::config::getKey proxytype] == "http" } {
+               } elseif { [::config::getKey connectiontype] == "proxy" && \
+                                ([::config::getKey proxytype] == "http" || 
[::config::getKey proxytype] == "system") } {
                        if {$proxy_host == "" } {
                                ::http::config -proxyhost "" -proxyport ""
                        } else {
Index: config.tcl
===================================================================
--- config.tcl  (revisión: 11095)
+++ config.tcl  (copia de trabajo)
@@ -29,7 +29,7 @@
 
                ::config::setKey connectiontype direct  ;# Connection type: 
direct|http|proxy
                ::config::setKey proxy ""                       ;# If using 
proxy, proxy host
-               ::config::setKey proxytype "http"               ;# Proxy type: 
http|ssl|socks5
+               ::config::setKey proxytype "http"               ;# Proxy type: 
http|ssl|socks5|system
                ::config::setKey proxyauthenticate 0            ;# SOCKS5 use 
username/password
                ::config::setKey proxyuser ""           ;# user and password 
for SOCKS5 proxy
                ::config::setKey proxypass ""           ;#
@@ -836,6 +836,197 @@
 
 }
 
+#Original by Isma from desktop_integration plugin
+#Modified by PabloCastellano
+#######################################################################
+#   It says which desktop are we using, and so, what program          #
+# Return values: gnome, kde, xfce, unknown                            #
+#######################################################################
+proc WhichDesktop {} {
+       variable plugin_name 
+       global env
+
+       # Find zenity and kdialog
+       catch {exec which zenity} zenity_path
+       catch {exec which kdialog} kdialog_path
+
+       #See which one of the programs do we have
+       set has_zenity [file executable $zenity_path ]
+       set has_kdialog [file executable $kdialog_path ]
+
+       #If we only have one of them, we choose it
+       if {$has_zenity && !$has_kdialog} {
+               status_log "Found Gnome" red
+               return "gnome"
+       } elseif {!$has_zenity && $has_kdialog} {
+               status_log "Found KDE" red
+               return "kde"
+       } elseif {!$has_zenity && !$has_kdialog} {
+               # If no program is installed, we return 'noone'
+               status_log "Found neither Gnome nor KDE" red
+               return "unknown"
+       }
+               
+       # If both of them are installed, we guess the desktop
+       status_log "Found both Gnome and KDE" red
+
+       # First, see if environment var exists
+       if  { [info exists env(DESKTOP_SESSION)] } {
+               set session_var $env(DESKTOP_SESSION)
+
+               if {$session_var == "gnome" || $session_var == "kde" || 
$session_var == "xfce"} {
+                       return $session_var
+               }
+       }
+
+       # If the variable doesn't help, let's see the number of processes
+       if { [catch {exec ps -A | grep gnome | wc -l} n_gnome] } {
+               set n_gnome 0
+       }
+
+       if { [catch {exec ps -A | grep kde | wc -l} n_kde] } {
+               set n_kde 0
+       }
+               
+
+       if {$n_gnome >= $n_kde} { 
+               return "gnome"
+       } else {
+               return "kde"
+       }
+
+}
+
+
+#Returns a gnome gconf key 
+proc get_gconf_key { key {default ""} } {
+       
+       if { ! [catch { eval [concat [list "exec"] "gconftool -g $key"]} value 
] } {
+               return $value
+       } else {
+               return $default
+       }
+}
+
+
+#Returns a kde kconf key
+proc get_kconf_key { rcfile group key {default ""} } {
+
+       set command "kreadconfig --file $rcfile --group $group --key $key 
--default $default"
+       catch { eval [concat [list "exec"] $command]} value 
+       return value
+
+}
+
+
+#///////////////////////////////////////////////////////////////////////////////
+# System-wide proxy settings by PabloCastellano
+# Called when key proxytype == "system" and [OnUnix].
+# Note that at the moment it only supports http proxy.
+# It first tries to get the configuration from your windows manager and if it
+#  fails then it tries to get envvar $http_proxy
+# Also note that $::env(http_proxy) will only exist if amsn is launched from a 
terminal
+#  and that won't be updated until you open a new terminal.
+proc load_unix_system_proxy {} {
+
+       global proxy_server proxy_port proxy_user proxy_pass proxyauthenticate
+
+       set mydesktop [WhichDesktop]
+       set g_proxymode [get_gconf_key "/system/proxy/mode" PROXYERROR]
+       set k_proxymode [get_kconf_key kioslaverc "Proxy Settings" ProxyType 
PROXYERROR]
+
+       if { $mydesktop == "gnome" && $g_proxymode != "PROXYERROR"} {
+
+               #Maybe use_same_proxy and autoconfig_url keys should be 
considered in future.
+               status_log "systemproxy: using gconf\n" red
+
+               set usehttp [get_gconf_key "/system/http_proxy/use_http_proxy"]
+
+               if {$usehttp == "true" && $g_proxymode != "none"} {
+                       #Should I check if the returned data is valid?
+                       set proxy_server [get_gconf_key 
"/system/http_proxy/host"]
+                       set proxy_port [get_gconf_key "/system/http_proxy/port"]
+                       set proxyauth [get_gconf_key 
"/system/http_proxy/use_authentication"]
+
+                       if {$proxyauth == "true"} {
+                               set proxyauthenticate 1
+                               set proxy_user [get_gconf_key 
"/system/http_proxy/authentication_user"]
+                               set proxy_pass [get_gconf_key 
"/system/http_proxy/authentication_password"]
+                       } else { # use_authentication == "false"
+                               set proxyauthenticate 0
+                               set proxy_user ""
+                               set proxy_pass ""
+                       }               
+               } else { 
+                       #Configure as direct. (use_http_proxy == "false" || 
mode == "none")
+                       set proxy_server ""
+                       set proxy_port ""
+                       set proxyauthenticate 0
+                       set proxy_user ""
+                       set proxy_pass ""
+               }
+
+       #TODO: Improve KDE authentication support.
+       } elseif { $mydesktop == "kde" && $k_proxymode != "PROXYERROR" } {
+
+               status_log "systemproxy: using kconf\n" red
+               set proxy [get_kconf_key kioslaverc "Proxy Settings" httpProxy]
+
+               if { $k_proxymode == 1 && $proxy != "" } {
+                       #regexp. http://%s:%...@%s:%d
+                       regsub 
{^(?:(?:[^:/?#]+):)?(?://(?:(?:(?:([^:@]*):?([^:@]*))?@)?([^:/?#]*)(?::(\d*).*)?))?}
 $proxy {"\1" "\2" "\3" "\4"} result
+                       set     proxy_user [lindex $result 0]
+                       set proxy_pass [lindex $result 1]
+                       set proxy_server [lindex $result 2]
+                       set proxy_port [lindex $result 3]
+
+                       set proxyauthenticate [get_kconf_key kioslaverc "Proxy 
Settings" AuthMode]
+
+               } else {
+                       #Configure as direct.
+                       set proxy_server ""
+                       set proxy_port ""
+                       set proxyauthenticate 0
+                       set proxy_user ""
+                       set proxy_pass ""
+               }
+
+       } elseif { [info exists ::env(http_proxy)] } {
+               status_log "systemproxy: using 
\$http_proxy=$::env(http_proxy)\n" red
+               #regexp. http://%s:%...@%s:%d
+               regsub 
{^(?:(?:[^:/?#]+):)?(?://(?:(?:(?:([^:@]*):?([^:@]*))?@)?([^:/?#]*)(?::(\d*).*)?))?}
 $::env(http_proxy) {"\1" "\2" "\3" "\4"} result
+
+               set     proxy_user [lindex $result 0]
+               set proxy_pass [lindex $result 1]
+               set proxy_server [lindex $result 2]
+               set proxy_port [lindex $result 3]
+
+               if { [llength $proxy_user] == 0 } {
+                       set proxyauthenticate 0
+               } else {
+                       set proxyauthenticate 1
+               }
+
+       } else { #it's not gnome nor kde and ENV $http_proxy is not set. => 
Don't use proxy
+               status_log "systemproxy: couldn't find any system proxy 
configuration\n" red
+                       
+               #Configure as direct
+               set proxy_server ""
+               set proxy_port ""
+               set proxyauthenticate 0
+               set proxy_user ""
+               set proxy_pass ""
+       }
+
+       #Print result
+       status_log "systemproxy: host is: $proxy_server\n" red
+       status_log "systemproxy: port is: $proxy_port\n" red
+       status_log "systemproxy: auth is: $proxyauthenticate\n" red
+       status_log "systemproxy: user is: $proxy_user\n" red
+       status_log "systemproxy: pass is: $proxy_pass\n" red
+
+}
+
 proc load_config {} {
        global HOME password osspecific_keys
 
@@ -955,6 +1146,17 @@
            ::ChatWindow::ShowHideChatWindowMenus . 0
        }
 
+#      #load system-wide proxy settings
+#      #
+       if { [::config::getKey connectiontype] == "proxy" && [::config::getKey 
proxytype] == "system" } {
+               if { [OnUnix] } {
+                       load_unix_system_proxy
+               } else {
+                       status_log "connectiontype reset to direct"
+                       ::config::setKey connectiontype direct
+               }
+       }
+
        #load Snack
        if {![catch {require_snack} res]} {
                # TODO this is bad because it already gets called by 
require_snack once... 
Index: proxy.tcl
===================================================================
--- proxy.tcl   (revisión: 11095)
+++ proxy.tcl   (copia de trabajo)
@@ -172,6 +172,16 @@
                        install proxy using ProxyDirect %AUTO% -name $self
                } elseif { [::config::getKey connectiontype] == "proxy" && 
[::config::getKey proxytype] == "socks5" } {
                        install proxy using ProxyDirect %AUTO% -name $self
+               } elseif { [::config::getKey connectiontype] == "proxy" && 
[::config::getKey proxytype] == "system" } {
+
+                       global proxy_server
+
+                       if { $proxy_server != "" } {
+                               install proxy using ProxyHTTP %AUTO% -name 
$self -direct 0
+                       } else {
+                               install proxy using ProxyDirect %AUTO% -name 
$self
+                       }
+
                } else {
                        ::config::setKey connectiontype "direct"
                        install proxy using ProxyDirect %AUTO% -name $self
@@ -899,7 +909,6 @@
 
                variable proxy_session_id
 #              variable proxy_gateway_ip
-               variable proxy_data
                variable options
 
                after cancel [list $self HTTPPoll $name]
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Amsn-devel mailing list
Amsn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amsn-devel

Reply via email to