Country selection is now saved, so city list can be filtered

This commit is contained in:
Gergely Polonkai 2014-08-23 13:40:29 +02:00
parent 45ba859582
commit 9c96e61308
2 changed files with 66 additions and 14 deletions

View File

@ -59,6 +59,13 @@ struct _AgWindowPrivate {
AgDbSave *saved_data; AgDbSave *saved_data;
GtkEntryCompletion *country_comp; GtkEntryCompletion *country_comp;
GtkEntryCompletion *city_comp; GtkEntryCompletion *city_comp;
gchar *selected_country;
};
struct cc_search {
const gchar *target;
GtkTreeIter *ret_iter;
gchar *ret_code;
}; };
G_DEFINE_QUARK(ag_window_error_quark, ag_window_error); G_DEFINE_QUARK(ag_window_error_quark, ag_window_error);
@ -1486,15 +1493,6 @@ ag_window_list_selection_changed_cb(GdMainView *view, AgWindow *window)
// Here it is possible to set button sensitivity later // Here it is possible to set button sensitivity later
} }
gboolean
ag_window_country_selected_callback(GtkEntryCompletion *country_comp,
GtkTreeModel *list,
GtkTreeIter *iter,
AgWindow *window)
{
return FALSE;
}
static void static void
ag_window_init(AgWindow *window) ag_window_init(AgWindow *window)
{ {
@ -1623,9 +1621,66 @@ ag_window_name_changed_cb(GtkEntry *name_entry, AgWindow *window)
gtk_header_bar_set_subtitle(GTK_HEADER_BAR(priv->header_bar), name); gtk_header_bar_set_subtitle(GTK_HEADER_BAR(priv->header_bar), name);
} }
static gboolean
ag_window_find_country(GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
struct cc_search *search)
{
gchar *name,
*ccode;
gboolean found = FALSE;
gtk_tree_model_get(
model, iter,
AG_COUNTRY_NAME, &name,
AG_COUNTRY_CODE, &ccode,
-1
);
if (g_utf8_collate(search->target, name) == 0) {
found = TRUE;
search->ret_iter = gtk_tree_iter_copy(iter);
search->ret_code = ccode;
} else {
g_free(ccode);
}
return found;
}
/**
* ag_window_country_changed_callback:
* @country: the #GtkSearchEntry for country search
* @window: the window in which the event happens
*
* This function is called whenever the text in the country search entry is
* changed.
*/
static void static void
ag_window_country_changed_callback(GtkSearchEntry *country, AgWindow *window) ag_window_country_changed_callback(GtkSearchEntry *country, AgWindow *window)
{ {
struct cc_search search;
AgWindowPrivate *priv = ag_window_get_instance_private(window);
search.target = gtk_entry_get_text(GTK_ENTRY(country));
search.ret_iter = NULL;
gtk_tree_model_foreach(
country_list,
(GtkTreeModelForeachFunc)ag_window_find_country,
&search
);
g_free(priv->selected_country);
if (search.ret_iter != NULL) {
g_debug("Country (entry-changed): %s", search.ret_code);
gtk_tree_iter_free(search.ret_iter);
priv->selected_country = search.ret_code;
} else {
priv->selected_country = NULL;
}
} }
static void static void
@ -1785,10 +1840,6 @@ ag_window_class_init(AgWindowClass *klass)
widget_class, widget_class,
ag_window_name_changed_cb ag_window_name_changed_cb
); );
gtk_widget_class_bind_template_callback(
widget_class,
ag_window_country_selected_callback
);
gtk_widget_class_bind_template_callback( gtk_widget_class_bind_template_callback(
widget_class, widget_class,
ag_window_country_changed_callback ag_window_country_changed_callback

View File

@ -137,9 +137,10 @@
</columns> </columns>
</object> </object>
<object class="GtkEntryCompletion" id="country_comp"> <object class="GtkEntryCompletion" id="country_comp">
<signal name="match-selected" handler="ag_window_country_selected_callback" swapped="no"/> <property name="inline_completion">True</property>
</object> </object>
<object class="GtkEntryCompletion" id="city_comp"> <object class="GtkEntryCompletion" id="city_comp">
<property name="inline_completion">True</property>
</object> </object>
<template class="AgWindow" parent="GtkApplicationWindow"> <template class="AgWindow" parent="GtkApplicationWindow">
<property name="can_focus">False</property> <property name="can_focus">False</property>