gnome-panel r11014 - trunk/applets/clock



Author: vuntz
Date: Tue Apr  8 17:03:30 2008
New Revision: 11014
URL: http://svn.gnome.org/viewvc/gnome-panel?rev=11014&view=rev

Log:
2008-04-08  Vincent Untz  <vuntz gnome org>

	* clock-zoneinfo.[ch]: add some const to function declarations
	(clock_zoneinfo_new): fix a leak, fix a problem with localized city
	names for timezones that are just named after a city
	* clock-zonetable.c: (clock_zonetable_load_zonetab): add some casting
	(clock_zonetable_load_iso3166): add useful comment
	* clock.c: (sort_zoneinfo_by_l10n_name),
	(fill_timezone_combo_from_location): make some strings const


Modified:
   trunk/applets/clock/ChangeLog
   trunk/applets/clock/clock-zoneinfo.c
   trunk/applets/clock/clock-zoneinfo.h
   trunk/applets/clock/clock-zonetable.c
   trunk/applets/clock/clock.c

Modified: trunk/applets/clock/clock-zoneinfo.c
==============================================================================
--- trunk/applets/clock/clock-zoneinfo.c	(original)
+++ trunk/applets/clock/clock-zoneinfo.c	Tue Apr  8 17:03:30 2008
@@ -28,13 +28,15 @@
 #define PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CLOCK_ZONEINFO_TYPE, ClockZoneInfoPrivate))
 
 ClockZoneInfo *
-clock_zoneinfo_new (gchar *zone, gchar *country, gchar *comment,
+clock_zoneinfo_new (const gchar *zone,
+                    const gchar *country,
+                    const gchar *comment,
 		    gfloat latitude, gfloat longitude)
 {
         ClockZoneInfo *this;
         ClockZoneInfoPrivate *priv;
         int i;
-        gchar *city;
+        const gchar *city;
         gchar *l10n_city;
 
         this = g_object_new (CLOCK_ZONEINFO_TYPE, NULL);
@@ -44,15 +46,20 @@
         priv->country = g_strdup (country);
 
         city = g_strrstr (zone, "/");
-        if (city == NULL) {
-                city = g_strdup (zone);
-        } else {
-                city = g_strdup (city + 1);
-        }
+        if (city == NULL)
+                priv->city = g_strdup (zone);
+        else
+                priv->city = g_strdup (city + 1);
 
-        priv->city = g_strdup (city);
+        /* replace underscores in the city with spaces */
+        for (i = 0; priv->city[i] != '\0'; i++) {
+                if (priv->city[i] == '_') {
+                        priv->city[i] = ' ';
+                }
+        }
 
-        priv->l10n_name = g_strdup (dgettext (EVOLUTION_TEXTDOMAIN, priv->name));
+        priv->l10n_name = g_strdup (dgettext (EVOLUTION_TEXTDOMAIN,
+                                              priv->name));
 
         /* replace underscores in the localized zone name with spaces */
         for (i = 0; priv->l10n_name[i] != '\0'; i++) {
@@ -62,18 +69,10 @@
         }
 
         l10n_city = g_strrstr (priv->l10n_name, "/");
-        if (l10n_city == NULL) {
-                priv->l10n_city = g_strdup (l10n_city);
-        } else {
+        if (l10n_city == NULL)
+                priv->l10n_city = g_strdup (priv->l10n_name);
+        else
                 priv->l10n_city = g_strdup (l10n_city + 1);
-        }
-
-        /* replace underscores in the city with spaces */
-        for (i = 0; priv->city[i] != '\0'; i++) {
-                if (priv->city[i] == '_') {
-                        priv->city[i] = ' ';
-                }
-        }
 
         priv->comment = g_strdup (comment);
 
@@ -147,7 +146,7 @@
         G_OBJECT_CLASS (clock_zoneinfo_parent_class)->finalize (g_obj);
 }
 
-gchar *
+const gchar *
 clock_zoneinfo_get_name (ClockZoneInfo *this)
 {
         ClockZoneInfoPrivate *priv = PRIVATE (this);
@@ -155,7 +154,7 @@
         return priv->name;
 }
 
-gchar *
+const gchar *
 clock_zoneinfo_get_l10n_name (ClockZoneInfo *this)
 {
         ClockZoneInfoPrivate *priv = PRIVATE (this);
@@ -163,7 +162,7 @@
         return priv->l10n_name;
 }
 
-gchar *
+const gchar *
 clock_zoneinfo_get_country (ClockZoneInfo *this)
 {
         ClockZoneInfoPrivate *priv = PRIVATE (this);
@@ -171,7 +170,7 @@
         return priv->country;
 }
 
-gchar *
+const gchar *
 clock_zoneinfo_get_city (ClockZoneInfo *this)
 {
         ClockZoneInfoPrivate *priv = PRIVATE (this);
@@ -179,7 +178,7 @@
         return priv->city;
 }
 
-gchar *
+const gchar *
 clock_zoneinfo_get_l10n_city (ClockZoneInfo *this)
 {
         ClockZoneInfoPrivate *priv = PRIVATE (this);

Modified: trunk/applets/clock/clock-zoneinfo.h
==============================================================================
--- trunk/applets/clock/clock-zoneinfo.h	(original)
+++ trunk/applets/clock/clock-zoneinfo.h	Tue Apr  8 17:03:30 2008
@@ -31,16 +31,17 @@
 
 GType clock_zoneinfo_get_type (void);
 
-ClockZoneInfo *clock_zoneinfo_new (gchar *zone, gchar *country,
-				   gchar *comment,
+ClockZoneInfo *clock_zoneinfo_new (const gchar *zone,
+                                   const gchar *country,
+				   const gchar *comment,
 				   gfloat latitude, gfloat longitude);
 
 
-gchar *clock_zoneinfo_get_city (ClockZoneInfo *this);
-gchar *clock_zoneinfo_get_l10n_city (ClockZoneInfo *this);
-gchar *clock_zoneinfo_get_country (ClockZoneInfo *this);
-gchar *clock_zoneinfo_get_name (ClockZoneInfo *this);
-gchar *clock_zoneinfo_get_l10n_name (ClockZoneInfo *this);
+const gchar *clock_zoneinfo_get_city (ClockZoneInfo *this);
+const gchar *clock_zoneinfo_get_l10n_city (ClockZoneInfo *this);
+const gchar *clock_zoneinfo_get_country (ClockZoneInfo *this);
+const gchar *clock_zoneinfo_get_name (ClockZoneInfo *this);
+const gchar *clock_zoneinfo_get_l10n_name (ClockZoneInfo *this);
 void clock_zoneinfo_get_coords (ClockZoneInfo *this,
 				gfloat *lat, gfloat *lon);
 

Modified: trunk/applets/clock/clock-zonetable.c
==============================================================================
--- trunk/applets/clock/clock-zonetable.c	(original)
+++ trunk/applets/clock/clock-zonetable.c	Tue Apr  8 17:03:30 2008
@@ -297,10 +297,10 @@
 
                 priv->list = g_list_prepend (priv->list, info);
                 g_hash_table_replace (priv->table,
-                                      clock_zoneinfo_get_name (info),
+                                      (char *) clock_zoneinfo_get_name (info),
                                       g_object_ref_sink (info));
                 g_hash_table_replace (priv->l10n_table,
-                                      clock_zoneinfo_get_l10n_name (info),
+                                      (char *) clock_zoneinfo_get_l10n_name (info),
                                       g_object_ref_sink (info));
         }
         g_free (old_line);

Modified: trunk/applets/clock/clock.c
==============================================================================
--- trunk/applets/clock/clock.c	(original)
+++ trunk/applets/clock/clock.c	Tue Apr  8 17:03:30 2008
@@ -3135,8 +3135,8 @@
         ClockZoneInfo *info_a = CLOCK_ZONEINFO (a);
         ClockZoneInfo *info_b = CLOCK_ZONEINFO (b);
 
-        char *name_a = clock_zoneinfo_get_l10n_name (info_a);
-        char *name_b = clock_zoneinfo_get_l10n_name (info_b);
+        const char *name_a = clock_zoneinfo_get_l10n_name (info_a);
+        const char *name_b = clock_zoneinfo_get_l10n_name (info_b);
 
         return strcmp (name_a, name_b); /* FIXME: should this be g_utf8_collate() ? */
 }
@@ -3152,7 +3152,7 @@
         int timezone_idx = -1;
         int i = 0;
 
-        gchar *loc_timezone = NULL;
+        const gchar *loc_timezone = NULL;
 
         if (loc != NULL) {
                 ClockZoneInfo *info;
@@ -3175,7 +3175,7 @@
 
         cur = list;
         while (cur) {
-                gchar *timezone = clock_zoneinfo_get_l10n_name (CLOCK_ZONEINFO (cur->data));
+                const gchar *timezone = clock_zoneinfo_get_l10n_name (CLOCK_ZONEINFO (cur->data));
 
                 gtk_combo_box_append_text (GTK_COMBO_BOX (zone_combo), timezone);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]