static void main_window_view_sort_contacts_cb (GtkRadioAction *action, GtkRadioAction *current, EmpathyMainWindow *window) { EmpathyContactListStoreSort value; GSList *group; GType type; GEnumClass *enum_class; GEnumValue *enum_value; value = gtk_radio_action_get_current_value (action); group = gtk_radio_action_get_group (action); /* Get string from index */ type = empathy_contact_list_store_sort_get_type (); enum_class = G_ENUM_CLASS (g_type_class_peek (type)); enum_value = g_enum_get_value (enum_class, g_slist_index (group, current)); if (!enum_value) { g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioAction index:%d", g_slist_index (group, action)); } else { empathy_conf_set_string (empathy_conf_get (), EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM, enum_value->value_nick); } empathy_contact_list_store_set_sort_criterium (window->list_store, value); }
static void preferences_widget_sync_string (const gchar *key, GtkWidget *widget) { gchar *value; if (empathy_conf_get_string (empathy_conf_get (), key, &value) && value) { if (GTK_IS_ENTRY (widget)) { gtk_entry_set_text (GTK_ENTRY (widget), value); } else if (GTK_IS_RADIO_BUTTON (widget)) { if (strcmp (key, EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM) == 0) { GType type; GEnumClass *enum_class; GEnumValue *enum_value; GSList *list; GtkWidget *toggle_widget; /* Get index from new string */ type = empathy_contact_list_store_sort_get_type (); enum_class = G_ENUM_CLASS (g_type_class_peek (type)); enum_value = g_enum_get_value_by_nick (enum_class, value); if (enum_value) { list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget)); toggle_widget = g_slist_nth_data (list, enum_value->value); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle_widget), TRUE); } } else { g_warning ("Unhandled key:'%s' just had string change", key); } } g_free (value); } }
static void main_window_notify_sort_contact_cb (EmpathyConf *conf, const gchar *key, EmpathyMainWindow *window) { gchar *str = NULL; if (empathy_conf_get_string (conf, key, &str) && str) { GType type; GEnumClass *enum_class; GEnumValue *enum_value; type = empathy_contact_list_store_sort_get_type (); enum_class = G_ENUM_CLASS (g_type_class_peek (type)); enum_value = g_enum_get_value_by_nick (enum_class, str); if (enum_value) { /* By changing the value of the GtkRadioAction, it emits a signal that calls main_window_view_sort_contacts_cb which updates the contacts list */ gtk_radio_action_set_current_value (window->sort_by_name, enum_value->value); } else { g_warning ("Wrong value for sort_criterium configuration : %s", str); } g_free (str); } }
static void preferences_radio_button_toggled_cb (GtkWidget *button, gpointer user_data) { const gchar *key; const gchar *value = NULL; if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) { return; } key = g_object_get_data (G_OBJECT (button), "key"); if (key && strcmp (key, EMPATHY_PREFS_CONTACTS_SORT_CRITERIUM) == 0) { GSList *group; GType type; GEnumClass *enum_class; GEnumValue *enum_value; group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)); /* Get string from index */ type = empathy_contact_list_store_sort_get_type (); enum_class = G_ENUM_CLASS (g_type_class_peek (type)); enum_value = g_enum_get_value (enum_class, g_slist_index (group, button)); if (!enum_value) { g_warning ("No GEnumValue for EmpathyContactListSort with GtkRadioButton index:%d", g_slist_index (group, button)); return; } value = enum_value->value_nick; } empathy_conf_set_string (empathy_conf_get (), key, value); }