Comment 4 for bug 185206

Revision history for this message
muddog (muddogxp) wrote :

I made a patch to make proxy configurable for weather applet, but my calender also need it.
So it's better to add a global proxy configuration for all applets who require network access.

diff -uNr weather.orig/weatherconfig.py weather/weatherconfig.py
--- weather.orig/weatherconfig.py 2009-01-12 20:36:29.000000000 +0800
+++ weather/weatherconfig.py 2009-01-12 16:39:43.000000000 +0800
@@ -212,6 +212,24 @@
   search.connect("clicked", self.search_button, "search")
   vbox.pack_start(hbox2,True,False,2)

+ # proxy settings
+ self.proxy_checkbox = gtk.CheckButton(_("HTTP Proxy"))
+ # enable proxy editor
+ self.proxy_editor = gtk.Entry()
+ if applet.proxy:
+ self.proxy_checkbox.set_active(True)
+ self.proxy_editor.set_sensitive(True)
+ self.proxy_editor.set_text(applet.http_proxy)
+ else:
+ self.proxy_checkbox.set_active(False)
+ self.proxy_editor.set_sensitive(False)
+ hbox5 = gtk.HBox(True,0)
+ hbox5.pack_start(self.proxy_checkbox,True,False,0)
+ hbox5.pack_end(self.proxy_editor)
+ self.proxy_checkbox.connect("toggled", self.proxy_cb, "proxy")
+ vbox.pack_start(hbox5,True,False,0)
+
+ # ok/cancel button
   hbox4 = gtk.HBox(True, 0)
   ok = gtk.Button(stock=gtk.STOCK_OK)
   ok.connect("clicked", self.ok_button, "ok")
@@ -242,7 +260,16 @@
   self.applet.gconf_client.set_int(self.applet.gconf_path + "/temp_position", self.temp_pos.get_active())
   self.applet.gconf_client.set_bool(self.applet.gconf_path + "/open_til_clicked", self.click_checkbox.get_active())
   self.applet.gconf_client.set_bool(self.applet.gconf_path + "/curved_dialog", self.click_checkbox2.get_active())
+ self.applet.gconf_client.set_bool(self.applet.gconf_path + "/proxy", self.proxy_checkbox.get_active())
+ self.applet.gconf_client.set_string(self.applet.gconf_path + "/http_proxy", self.proxy_editor.get_text())
   self.destroy()

  def cancel_button(self, widget, event):
   self.destroy()
+
+ def proxy_cb(self, widget, event):
+ if self.proxy_checkbox.get_active():
+ self.proxy_editor.set_sensitive(True)
+ self.proxy_editor.set_text(self.applet.http_proxy)
+ else:
+ self.proxy_editor.set_sensitive(False)
diff -uNr weather.orig/weather.py weather/weather.py
--- weather.orig/weather.py 2009-01-13 19:29:06.000000000 +0800
+++ weather/weather.py 2009-01-12 16:34:37.000000000 +0800
@@ -98,6 +98,10 @@

  # Counts the number of minutes until the next attempted fetch.
  countdown = 0
+
+ # HTTP Proxy switch can proxy
+ proxy = False
+ http_proxy = "http://"

  def __init__(self, uid, orient, height):
   awn.AppletSimple.__init__ (self, uid, orient, height)
@@ -207,6 +211,14 @@
   # Curved Look
   self.curved_dialog = self.gconf_client.get_bool(self.gconf_path + "/curved_dialog")
   self.gconf_client.set_bool(self.gconf_path + "/curved_dialog", self.curved_dialog)
+
+ # HTTP Proxy
+ self.proxy = self.gconf_client.get_bool(self.gconf_path + "/proxy")
+ self.gconf_client.set_bool(self.gconf_path + "/proxy", self.proxy)
+ self.http_proxy = self.gconf_client.get_string(self.gconf_path + "/http_proxy")
+ if self.http_proxy == None:
+ self.gconf_client.set_string(self.gconf_path + "/http_proxy", "http://")
+
   return True

@@ -319,7 +331,11 @@
   if self.units == "Metric":
    url = url + '&unit=m'
   try:
- usock = urllib.urlopen(url)
+ if self.proxy:
+ proxies = {'http': self.http_proxy}
+ else:
+ proxies = {}
+ usock = urllib.urlopen(url, proxies=proxies)
    xmldoc = minidom.parse(usock)
    usock.close()
    weather_n = xmldoc.getElementsByTagName('weather')[0]
@@ -375,7 +391,11 @@
   if self.units == "Metric":
    url = url + '&unit=m'
   try:
- usock = urllib.urlopen(url)
+ if self.proxy:
+ proxies = {'http': self.http_proxy}
+ else:
+ proxies = {}
+ usock = urllib.urlopen(url, proxies=proxies)
    xmldoc = minidom.parse(usock)
    usock.close()
    location_n = xmldoc.getElementsByTagName('loc')[0]
@@ -421,7 +441,11 @@
   if self.map != "":
    old_map = self.map
   try:
- usock = urllib.urlopen('http://www.weather.com/outlook/travel/businesstraveler/map/' + self.location_code)
+ if self.proxy:
+ proxies = {'http': self.http_proxy}
+ else:
+ proxies = {}
+ usock = urllib.urlopen('http://www.weather.com/outlook/travel/businesstraveler/map/' + self.location_code, proxies=proxies)
    lines = usock.readlines()
    iframe_re = re.compile(".*[iI][fF][rR][aA][mM][eE].*")
    for line in lines:
@@ -430,7 +454,7 @@
      frame_src_end = line.find("?")
      if frame_src_start > -1 and frame_src_end > -1:
       frame_src = line[frame_src_start+5 : frame_src_end]
- usock2 = urllib.urlopen('http://www.weather.com' + frame_src)
+ usock2 = urllib.urlopen('http://www.weather.com' + frame_src, proxies=proxies)
       frame_lines = usock2.readlines()
       img_re = re.compile(".*[iI][mM][gG] [nN][aA][mM][eE]=\"mapImg\".*")
       for frame_line in frame_lines: