aboutsummaryrefslogtreecommitdiff
path: root/src/timezone-completion.c
diff options
context:
space:
mode:
authorMichael Terry <mike@mterry.name>2011-03-23 09:08:24 -0400
committerMichael Terry <mike@mterry.name>2011-03-23 09:08:24 -0400
commit09dc8ae0299f9288ba6c2a34f4df8ef9ceab53b6 (patch)
treeeabb87ecda5392da37ca80dfc8aa6cbf09080f6f /src/timezone-completion.c
parentff7b647f722a837545c605c196eb3c26e42fd405 (diff)
downloadayatana-indicator-datetime-09dc8ae0299f9288ba6c2a34f4df8ef9ceab53b6.tar.gz
ayatana-indicator-datetime-09dc8ae0299f9288ba6c2a34f4df8ef9ceab53b6.tar.bz2
ayatana-indicator-datetime-09dc8ae0299f9288ba6c2a34f4df8ef9ceab53b6.zip
avoid duplicates in geonames data
Diffstat (limited to 'src/timezone-completion.c')
-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 f570c33..1138d0b 100644
--- a/src/timezone-completion.c
+++ b/src/timezone-completion.c
@@ -74,6 +74,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);
@@ -112,6 +115,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);
@@ -133,16 +137,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);