aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Terry <mike@mterry.name>2011-03-23 16:03:29 -0500
committerMichael Terry <mike@mterry.name>2011-03-23 16:03:29 -0500
commit64d76856cb691d998c070086d31ad51f18d68cdf (patch)
tree7355fd70343ca102a5295acc74a2cd24a2481a4a /src
parent736dde41f6046b8610e27568f394031c9b6f72fd (diff)
downloadayatana-indicator-datetime-64d76856cb691d998c070086d31ad51f18d68cdf.tar.gz
ayatana-indicator-datetime-64d76856cb691d998c070086d31ad51f18d68cdf.tar.bz2
ayatana-indicator-datetime-64d76856cb691d998c070086d31ad51f18d68cdf.zip
sort locations by name, starting with prefixes
Diffstat (limited to 'src')
-rw-r--r--src/timezone-completion.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/timezone-completion.c b/src/timezone-completion.c
index aaf6bdc..2cd2340 100644
--- a/src/timezone-completion.c
+++ b/src/timezone-completion.c
@@ -87,6 +87,39 @@ save_and_use_model (TimezoneCompletion * completion, GtkTreeModel * model)
g_signal_emit_by_name (priv->entry, "changed");
}
+static gint
+sort_zone (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b,
+ gpointer user_data)
+{
+ /* Anything that has text as a prefix goes first, in mostly sorted order.
+ Then everything else goes after, in mostly sorted order. */
+ const gchar *casefolded_text = (const gchar *)user_data;
+
+ const gchar *namea = NULL, *nameb = NULL;
+ gtk_tree_model_get (model, a, TIMEZONE_COMPLETION_NAME, &namea, -1);
+ gtk_tree_model_get (model, b, TIMEZONE_COMPLETION_NAME, &nameb, -1);
+
+ gchar *casefolded_namea = NULL, *casefolded_nameb = NULL;
+ casefolded_namea = g_utf8_casefold (namea, -1);
+ casefolded_nameb = g_utf8_casefold (nameb, -1);
+
+ gboolean amatches = FALSE, bmatches = FALSE;
+ amatches = strncmp (casefolded_text, casefolded_namea, strlen(casefolded_text)) == 0;
+ bmatches = strncmp (casefolded_text, casefolded_nameb, strlen(casefolded_text)) == 0;
+
+ gint rv;
+ if (amatches && !bmatches)
+ rv = -1;
+ else if (bmatches && !amatches)
+ rv = 1;
+ else
+ rv = g_utf8_collate (casefolded_namea, casefolded_nameb);
+
+ g_free (casefolded_namea);
+ g_free (casefolded_nameb);
+ return rv;
+}
+
static void
json_parse_ready (GObject *object, GAsyncResult *res, gpointer user_data)
{
@@ -179,6 +212,13 @@ json_parse_ready (GObject *object, GAsyncResult *res, gpointer user_data)
TIMEZONE_COMPLETION_LONGITUDE, longitude,
TIMEZONE_COMPLETION_LATITUDE, latitude,
-1);
+ gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
+ TIMEZONE_COMPLETION_NAME, sort_zone,
+ g_utf8_casefold(priv->request_text, -1),
+ g_free);
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
+ TIMEZONE_COMPLETION_NAME,
+ GTK_SORT_ASCENDING);
}
prev_name = name;