aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2011-03-23 10:33:31 -0500
committerTed Gould <ted@gould.cx>2011-03-23 10:33:31 -0500
commit6e9e1719c75bf9bcf890b7ea4b5b5c78d81bd902 (patch)
treee7c35ccfe00f91d9828cfefc01ccd5b07a5bf54e
parent1685931d9c57696662a56a4877605440f29734c4 (diff)
parent09dc8ae0299f9288ba6c2a34f4df8ef9ceab53b6 (diff)
downloadayatana-indicator-datetime-6e9e1719c75bf9bcf890b7ea4b5b5c78d81bd902.tar.gz
ayatana-indicator-datetime-6e9e1719c75bf9bcf890b7ea4b5b5c78d81bd902.tar.bz2
ayatana-indicator-datetime-6e9e1719c75bf9bcf890b7ea4b5b5c78d81bd902.zip
Ensure no duplicate entries
-rw-r--r--src/timezone-completion.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/timezone-completion.c b/src/timezone-completion.c
index 4df50e0..fd6c97b 100644
--- a/src/timezone-completion.c
+++ b/src/timezone-completion.c
@@ -88,6 +88,9 @@ json_parse_ready (GObject *object, GAsyncResult *res, gpointer user_data)
TimezoneCompletion * completion = TIMEZONE_COMPLETION (user_data);
TimezoneCompletionPrivate * priv = TIMEZONE_COMPLETION_GET_PRIVATE(completion);
GError * error = NULL;
+ const gchar * prev_name = NULL;
+ const gchar * prev_admin1 = NULL;
+ const gchar * prev_country = NULL;
json_parser_load_from_stream_finish (JSON_PARSER (object), res, &error);
@@ -128,6 +131,7 @@ json_parse_ready (GObject *object, GAsyncResult *res, gpointer user_data)
const gchar * country = NULL;
const gchar * longitude = NULL;
const gchar * latitude = NULL;
+ gboolean skip = FALSE;
if (json_reader_read_member (reader, "name")) {
name = json_reader_get_string_value (reader);
json_reader_end_member (reader);
@@ -149,16 +153,30 @@ json_parse_ready (GObject *object, GAsyncResult *res, gpointer user_data)
json_reader_end_member (reader);
}
- GtkTreeIter iter;
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- TIMEZONE_COMPLETION_ZONE, NULL,
- TIMEZONE_COMPLETION_NAME, name,
- TIMEZONE_COMPLETION_ADMIN1, admin1,
- TIMEZONE_COMPLETION_COUNTRY, country,
- TIMEZONE_COMPLETION_LONGITUDE, longitude,
- TIMEZONE_COMPLETION_LATITUDE, latitude,
- -1);
+ if (g_strcmp0(name, prev_name) == 0 &&
+ g_strcmp0(admin1, prev_admin1) == 0 &&
+ g_strcmp0(country, prev_country) == 0) {
+ // Sometimes the data will have duplicate entries that only differ
+ // in longitude and latitude. e.g. "rio de janeiro", "wellington"
+ skip = TRUE;
+ }
+
+ if (!skip) {
+ GtkTreeIter iter;
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ TIMEZONE_COMPLETION_ZONE, NULL,
+ TIMEZONE_COMPLETION_NAME, name,
+ TIMEZONE_COMPLETION_ADMIN1, admin1,
+ TIMEZONE_COMPLETION_COUNTRY, country,
+ TIMEZONE_COMPLETION_LONGITUDE, longitude,
+ TIMEZONE_COMPLETION_LATITUDE, latitude,
+ -1);
+ }
+
+ prev_name = name;
+ prev_admin1 = admin1;
+ prev_country = country;
}
json_reader_end_element (reader);