[libgweather] Deprecate properties and constructors with world GWeatherLocation
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather] Deprecate properties and constructors with world GWeatherLocation
- Date: Sun, 19 May 2013 15:01:23 +0000 (UTC)
commit 0a0bd05d20b14a0d5cacdbee919c2db47461d3c4
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Sun May 19 16:19:45 2013 +0200
Deprecate properties and constructors with world GWeatherLocation
Now you're expected to use the shared world, so just pass NULL
to top/world properties.
Also, use proper boxed types to handle GWeatherLocations.
libgweather/location-entry.c | 28 +++++++++++++++-------------
libgweather/timezone-menu.c | 37 +++++++++++++++++++++++--------------
libgweather/weather.c | 7 +++++--
3 files changed, 43 insertions(+), 29 deletions(-)
---
diff --git a/libgweather/location-entry.c b/libgweather/location-entry.c
index 310bf44..8e5f5c2 100644
--- a/libgweather/location-entry.c
+++ b/libgweather/location-entry.c
@@ -277,9 +277,8 @@ set_location_internal (GWeatherLocationEntry *entry,
if (iter) {
gtk_tree_model_get (model, iter,
GWEATHER_LOCATION_ENTRY_COL_DISPLAY_NAME, &name,
- GWEATHER_LOCATION_ENTRY_COL_LOCATION, &loc,
+ GWEATHER_LOCATION_ENTRY_COL_LOCATION, &priv->location,
-1);
- priv->location = gweather_location_ref (loc);
gtk_entry_set_text (GTK_ENTRY (entry), name);
priv->custom_text = FALSE;
g_free (name);
@@ -329,8 +328,11 @@ gweather_location_entry_set_location (GWeatherLocationEntry *entry,
-1);
if (gweather_location_equal (loc, cmploc)) {
set_location_internal (entry, model, &iter, NULL);
+ gweather_location_unref (cmploc);
return;
}
+
+ gweather_location_unref (cmploc);
} while (gtk_tree_model_iter_next (model, &iter));
set_location_internal (entry, model, NULL, loc);
@@ -415,12 +417,15 @@ gweather_location_entry_set_city (GWeatherLocationEntry *entry,
-1);
cmpcode = gweather_location_get_code (cmploc);
- if (!cmpcode || strcmp (cmpcode, code) != 0)
+ if (!cmpcode || strcmp (cmpcode, code) != 0) {
+ gweather_location_unref (cmploc);
continue;
+ }
if (city_name) {
cmpname = gweather_location_get_city_name (cmploc);
if (!cmpname || strcmp (cmpname, city_name) != 0) {
+ gweather_location_unref (cmploc);
g_free (cmpname);
continue;
}
@@ -428,6 +433,7 @@ gweather_location_entry_set_city (GWeatherLocationEntry *entry,
}
set_location_internal (entry, model, &iter, NULL);
+ gweather_location_unref (cmploc);
return TRUE;
} while (gtk_tree_model_iter_next (model, &iter));
@@ -551,10 +557,13 @@ gweather_location_entry_build_model (GWeatherLocationEntry *entry,
{
GtkTreeStore *store = NULL;
- entry->priv->top = gweather_location_ref (top);
+ if (top)
+ entry->priv->top = gweather_location_ref (top);
+ else
+ entry->priv->top = gweather_location_new_world (TRUE);
- store = gtk_tree_store_new (4, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING);
- fill_location_entry_model (store, top, NULL, NULL);
+ store = gtk_tree_store_new (4, G_TYPE_STRING, GWEATHER_TYPE_LOCATION, G_TYPE_STRING, G_TYPE_STRING);
+ fill_location_entry_model (store, entry->priv->top, NULL, NULL);
gtk_entry_completion_set_model (gtk_entry_get_completion (GTK_ENTRY (entry)),
GTK_TREE_MODEL (store));
g_object_unref (store);
@@ -603,21 +612,14 @@ matcher (GtkEntryCompletion *completion, const char *key,
GtkTreeIter *iter, gpointer user_data)
{
char *name, *name_mem;
- GWeatherLocation *loc;
gboolean is_first_word = TRUE, match;
int len;
gtk_tree_model_get (gtk_entry_completion_get_model (completion), iter,
GWEATHER_LOCATION_ENTRY_COL_COMPARE_NAME, &name_mem,
- GWEATHER_LOCATION_ENTRY_COL_LOCATION, &loc,
-1);
name = name_mem;
- if (!loc) {
- g_free (name_mem);
- return FALSE;
- }
-
/* All but the last word in KEY must match a full word from NAME,
* in order (but possibly skipping some words from NAME).
*/
diff --git a/libgweather/timezone-menu.c b/libgweather/timezone-menu.c
index a38bb7d..f4592fb 100644
--- a/libgweather/timezone-menu.c
+++ b/libgweather/timezone-menu.c
@@ -102,10 +102,11 @@ gweather_timezone_menu_class_init (GWeatherTimezoneMenuClass *timezone_menu_clas
/* properties */
g_object_class_install_property (
object_class, PROP_TOP,
- g_param_spec_pointer ("top",
- "Top Location",
- "The GWeatherLocation whose children will be used to fill in the menu",
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+ g_param_spec_boxed ("top",
+ "Top Location",
+ "The GWeatherLocation whose children will be used to fill in the menu",
+ GWEATHER_TYPE_LOCATION,
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (
object_class, PROP_TZID,
g_param_spec_string ("tzid",
@@ -123,7 +124,7 @@ set_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_TOP:
- model = gweather_timezone_model_new (g_value_get_pointer (value));
+ model = gweather_timezone_model_new (g_value_get_boxed (value));
gtk_combo_box_set_model (GTK_COMBO_BOX (object), model);
g_object_unref (model);
gtk_combo_box_set_active (GTK_COMBO_BOX (object), 0);
@@ -174,9 +175,6 @@ changed (GtkComboBox *combo)
GWEATHER_TIMEZONE_MENU_ZONE, &menu->zone,
-1);
- if (menu->zone)
- gweather_timezone_ref (menu->zone);
-
g_object_notify (G_OBJECT (combo), "tzid");
}
@@ -223,7 +221,7 @@ insert_location (GtkTreeStore *store, GWeatherTimezone *zone, const char *loc_na
gtk_tree_store_append (store, &iter, parent);
gtk_tree_store_set (store, &iter,
GWEATHER_TIMEZONE_MENU_NAME, name,
- GWEATHER_TIMEZONE_MENU_ZONE, gweather_timezone_ref (zone),
+ GWEATHER_TIMEZONE_MENU_ZONE, zone,
-1);
g_free (name);
g_free (offset);
@@ -240,7 +238,6 @@ insert_locations (GtkTreeStore *store, GWeatherLocation *loc)
children = gweather_location_get_children (loc);
for (i = 0; children[i]; i++)
insert_locations (store, children[i]);
- gweather_location_free_children (loc, children);
} else {
GWeatherTimezone **zones;
GtkTreeIter iter;
@@ -271,8 +268,9 @@ gweather_timezone_model_new (GWeatherLocation *top)
GtkTreeIter iter;
char *unknown;
GWeatherTimezone *utc;
+ GWeatherLocation *world;
- store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
+ store = gtk_tree_store_new (2, G_TYPE_STRING, GWEATHER_TYPE_TIMEZONE);
model = GTK_TREE_MODEL (store);
unknown = g_markup_printf_escaped ("<i>%s</i>", C_("timezone", "Unknown"));
@@ -293,7 +291,14 @@ gweather_timezone_model_new (GWeatherLocation *top)
g_free (unknown);
- insert_locations (store, top);
+ if (top)
+ world = gweather_location_ref (top);
+ else
+ world = gweather_location_new_world (TRUE);
+
+ insert_locations (store, world);
+
+ gweather_location_unref (world);
return model;
}
@@ -354,6 +359,7 @@ check_tzid (GtkTreeModel *model, GtkTreePath *path,
{
SetTimezoneData *tzd = data;
GWeatherTimezone *zone;
+ gboolean ok;
gtk_tree_model_get (model, iter,
GWEATHER_TIMEZONE_MENU_ZONE, &zone,
@@ -363,9 +369,12 @@ check_tzid (GtkTreeModel *model, GtkTreePath *path,
if (!strcmp (gweather_timezone_get_tzid (zone), tzd->tzid)) {
gtk_combo_box_set_active_iter (tzd->combo, iter);
- return TRUE;
+ ok = TRUE;
} else
- return FALSE;
+ ok = FALSE;
+
+ gweather_timezone_unref (zone);
+ return ok;
}
/**
diff --git a/libgweather/weather.c b/libgweather/weather.c
index 974cd35..97b7d95 100644
--- a/libgweather/weather.c
+++ b/libgweather/weather.c
@@ -1969,7 +1969,7 @@ gweather_info_set_location_internal (GWeatherInfo *info,
priv->world = gweather_location_ref_world (location);
if (!priv->world)
- priv->world = gweather_location_new_world (FALSE);
+ priv->world = gweather_location_new_world (TRUE);
priv->glocation = location;
if (priv->glocation) {
@@ -2117,7 +2117,7 @@ gweather_info_class_init (GWeatherInfoClass *klass)
"World",
"The hierarchy of locations containing the desired location",
GWEATHER_TYPE_LOCATION,
- G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_DEPRECATED);
g_object_class_install_property (gobject_class, PROP_WORLD, pspec);
pspec = g_param_spec_boxed ("location",
@@ -2200,6 +2200,9 @@ gweather_info_new (GWeatherLocation *location,
* GSettings) belongs.
*
* Returns: (transfer full): a new #GWeatherInfo
+ *
+ * Deprecated: there is only one world-level #GWeatherLocation at any time, so
+ * this is the same as gweather_info_new().
*/
GWeatherInfo *
gweather_info_new_for_world (GWeatherLocation *world,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]