← Back to team overview

registry team mailing list archive

[Merge] lp:~roignac/weather-indicator/Bug618108 into lp:weather-indicator

 

Vadim Rutkovsky has proposed merging lp:~roignac/weather-indicator/Bug618108 into lp:weather-indicator.

Requested reviews:
  Registry Administrators (registry)
Related bugs:
  #618108 Label is not shown in the dialogs when specified
  https://bugs.launchpad.net/bugs/618108


These changes allow user to use labels instead of full city names (including names in their native languages). 
Don't forget to reset gconf settings ('places' variable, in particular)
-- 
https://code.launchpad.net/~roignac/weather-indicator/Bug618108/+merge/32704
Your team Registry Administrators is requested to review the proposed merge of lp:~roignac/weather-indicator/Bug618108 into lp:weather-indicator.
=== modified file 'bin/indicator-weather'
--- bin/indicator-weather	2010-07-10 23:10:38 +0000
+++ bin/indicator-weather	2010-08-15 11:07:42 +0000
@@ -164,14 +164,14 @@
             breaker.show()
             self.menu.append(breaker)
             
-            loco1 = gtk.RadioMenuItem(None, self.places[0])
+            loco1 = gtk.RadioMenuItem(None, self.places[0][1])
             if self.placechosen == 0:
                 loco1.set_active(True)
             loco1.connect("toggled", self.on_city_changed)
             loco1.show()
             self.menu.append(loco1)
             for place in self.places[1:]:
-                loco = gtk.RadioMenuItem(loco1, place)
+                loco = gtk.RadioMenuItem(loco1, place[1])
                 if self.places.index(place) == self.placechosen:
                     loco.set_active(True)
                 loco.connect("toggled", self.on_city_changed)
@@ -212,14 +212,14 @@
             breaker.show()
             self.menu.append(breaker)
             
-            loco1 = gtk.RadioMenuItem(None, self.places[0])
+            loco1 = gtk.RadioMenuItem(None, self.places[0][1])
             if self.placechosen == 0:
                 loco1.set_active(True)
             loco1.connect("toggled", self.on_city_changed)
             loco1.show()
             self.menu.append(loco1)
             for place in self.places[1:]:
-                loco = gtk.RadioMenuItem(loco1, place)
+                loco = gtk.RadioMenuItem(loco1, place[1])
                 if self.places.index(place) == self.placechosen:
                     loco.set_active(True)
                 loco.connect("toggled", self.on_city_changed)
@@ -245,7 +245,10 @@
     
     def on_city_changed(self,widget):
         if widget.get_active():
-            self.placechosen = self.places.index(widget.get_label())
+            for place in self.places:
+                if (place[1] == widget.get_label()):
+                    self.placechosen = self.places.index(place)
+                    break
             gconfClient.set_int("/apps/indicator-weather/placechosen", self.placechosen)
             self.update_weather(False)
 
@@ -261,7 +264,7 @@
             night = False
         self.condition = current
         
-        print 'Update :',current,'(every',self.rate,'min. for',self.places[self.placechosen]+')'
+        print 'Update :',current,'(every',self.rate,'min. for',self.places[self.placechosen][1]+')'
         
         current = self.icon
         
@@ -309,7 +312,7 @@
             a=False
         #self.city_table.attach(gtk.Label("City"), 0, 1, 0, 1)
         
-        self.city_show.set_label(self.city)
+        self.city_show.set_label(self.cityLabel)
         self.cond_show.set_label(self.condition)
         self.temp_show.set_label(self.temp)
         self.humid_show.set_label(self.humid)
@@ -350,7 +353,7 @@
         if replace == False:
             if not (entry.get_text() in self.places):
                 self.places.append(entry.get_text())
-                gconfClient.set_string("/apps/indicator-weather/places", str(self.places))
+                gconfClient.set_string("/apps/indicator-weather/places", str([self.places]))
                 dialog.destroy()
                 return True
             else:
@@ -359,12 +362,12 @@
         else:
             self.places = list()
             self.places.append(entry.get_text())
-            gconfClient.set_string("/apps/indicator-weather/places", str(self.places))
+            gconfClient.set_string("/apps/indicator-weather/places", str([self.places]))
         dialog.destroy()
         
         #self.update_weather()
     def get_sun(self,city):
-        url = 'http://maps.google.com/maps/api/geocode/json?address='+urllib2.quote(city)+'&sensor=false'
+        url = 'http://maps.google.com/maps/api/geocode/json?address='+urllib2.quote(city[0])+'&sensor=false'
         try:
             result = simplejson.load(urllib2.urlopen(url))
         except:
@@ -389,7 +392,7 @@
         import locale
         localebad = locale.getlocale()[0]
         locale = localebad.split ('_')
-        url = "http://www.google.com/ig/api?weather="; + urllib2.quote(city) + "&hl=" + locale[0]
+        url = "http://www.google.com/ig/api?weather="; + urllib2.quote(city[0]) + "&hl=" + locale[0]
         
         try:
             # open google weather api url
@@ -399,6 +402,7 @@
             # if there was an error opening the url, return
             self.temp = "Connexion Problem"
             self.city = "Connexion Problem"
+            self.cityLabel = "Connection Problem"
             self.humid = "Connexion Problem"
             self.wind = "Connexion Problem"
             self.icon = "Connexion Problem"
@@ -416,6 +420,7 @@
                 
                 weather = s.split("<current_conditions><condition data=\"")[-1].split("\"")[0]
                 self.city = s.split("<city data=\"")[-1].split("\"")[0]
+                self.cityLabel = city[1]
                 if firstrun and self.unitsystem == 'SI':
                         self.unit = 'C'
                         gconfClient.set_string("/apps/indicator-weather/unit", 'C')
@@ -478,6 +483,7 @@
                 if weather == "<?xml version=":
                     self.temp = "Invalid city"
                     self.city = "Invalid city"
+                    self.cityLabel = "Invalid city"
                     self.humid = "Invalid city"
                     self.wind = "Invalid city"
                     return "Invalid city"
@@ -588,7 +594,9 @@
         end = len(wi.places)
         for place in wi.places:
             newplace = list()
-            newplace.append(place)
+            newplace.append(place[0])
+            newplace.append(place[1])
+            
             self.builder.get_object('citieslist').append(newplace)
             
         self.builder.connect_signals(self)
@@ -646,7 +654,10 @@
         newplaces = list()
         item = self.builder.get_object('citieslist').get_iter_first()
         while ( item != None ):
-            newplaces.append(self.builder.get_object('citieslist').get_value (item, 0))
+            newplace = list()
+            newplace.append(self.builder.get_object('citieslist').get_value (item, 0))
+            newplace.append(self.builder.get_object('citieslist').get_value (item, 1))
+            newplaces.append(newplace)
             item = self.builder.get_object('citieslist').iter_next(item)
         if newplaces != wi.places:
             wi.places = newplaces
@@ -662,7 +673,7 @@
             else:
                 wi.placechosen = 0
                 gconfClient.set_int("/apps/indicator-weather/placechosen", wi.placechosen)
-                gconfClient.set_string("/apps/indicator-weather/places", str(wi.places))
+                gconfClient.set_string("/apps/indicator-weather/places", str([wi.places]))
                 wi.winder.set_icon("weather-clear")
                 wi.menu_noplace()
                 needupdate = False
@@ -703,7 +714,7 @@
         self.builder = builder
         self.builder.connect_signals(self)
         
-        self.builder.get_object('extended_forecast').set_title(_('Weather Forecast for ')+wi.places[wi.placechosen])
+        self.builder.get_object('extended_forecast').set_title(_('Weather Forecast for ')+wi.places[wi.placechosen][1])
         
         wi.get_weather(wi.places[wi.placechosen],False,True)
         
@@ -819,7 +830,7 @@
     
     def get_city(self,current_page):
         if self.builder.get_object("assistant").get_current_page() == 1:
-            self.label = wi.get_weather(self.builder.get_object("entry").get_text(),onlycity=True)
+            self.label = wi.get_weather([self.builder.get_object("entry").get_text()],onlycity=True)
             if not self.label in ('Error opening url','<?xml version='):
                 self.builder.get_object("lblplace").set_label('<big>'+self.label+'</big>')
                 self.builder.get_object("assistant").set_page_complete(self.builder.get_object("confirmplace"),True)
@@ -845,10 +856,19 @@
         self.destroy()
         
     def on_apply(self,widget):
-        wi.placeadded = self.label
-        self.hide()
+        _city_name = self.label
+        _city_label = self.builder.get_object("entrylbl").get_text()
+        places = list()
+        places.append(_city_name)
+        if (_city_label == ''):
+            _city_label = _city_name
+        places.append(_city_label)
+
+        wi.placeadded = _city_name
         wi.places = list()
-        wi.places.append(wi.placeadded)
+        wi.places.append(places)
+        
+        self.hide()
         gconfClient.set_string("/apps/indicator-weather/places", str(wi.places))
         wi.menu_normal()
         wi.place = wi.places[wi.placechosen]
@@ -885,7 +905,7 @@
     
     def get_city(self,current_page):
         if self.builder.get_object("assistant2").get_current_page() == 0:
-            self.label = wi.get_weather(self.builder.get_object("entry").get_text(),onlycity=True)
+            self.label = wi.get_weather([self.builder.get_object("entry").get_text()],onlycity=True)
             if not self.label in ('Error opening url','<?xml version='):
                 self.builder.get_object("lblplace").set_label('<big>'+self.label+'</big>')
                 self.builder.get_object("assistant2").set_page_complete(self.builder.get_object("confirmplace"),True)
@@ -898,8 +918,13 @@
         self.destroy()
         
     def on_apply(self,widget):
+        _city_name = self.label
+        _city_label = self.builder.get_object("entrylbl").get_text()
         newplace = list()
-        newplace.append(self.label)
+        newplace.append(_city_name)
+        if (_city_label == ''):
+            _city_label = _city_name
+        newplace.append(_city_label)
         wi.prefswindow.builder.get_object('citieslist').append(newplace)
         self.hide()
         

=== modified file 'data/ui/PreferencesDialog.ui'
--- data/ui/PreferencesDialog.ui	2010-07-10 19:30:11 +0000
+++ data/ui/PreferencesDialog.ui	2010-08-15 11:07:42 +0000
@@ -5,6 +5,8 @@
   <!-- interface-naming-policy project-wide -->
   <object class="GtkListStore" id="citieslist">
     <columns>
+      <!-- column-name Label -->
+      <column type="gchararray"/>
       <!-- column-name City -->
       <column type="gchararray"/>
     </columns>