static void
avatar_chooser_response_cb (GtkWidget            *widget,
			    gint                  response,
			    EmpathyAvatarChooser *chooser)
{
	EmpathyAvatarChooserPriv *priv = GET_PRIV (chooser);

	priv->chooser_dialog = NULL;

	if (response == GTK_RESPONSE_OK) {
		gchar *filename;
		gchar *path;

		filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
		avatar_chooser_set_image_from_file (chooser, filename);
		g_free (filename);

		path = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (widget));
		if (path) {
			empathy_conf_set_string (empathy_conf_get (),
						 EMPATHY_PREFS_UI_AVATAR_DIRECTORY,
						 path);
			g_free (path);
		}
	}
	else if (response == GTK_RESPONSE_NO) {
		/* This corresponds to "No Image", not to "Cancel" */
		avatar_chooser_clear_image (chooser);
	}

	gtk_widget_destroy (widget);
}
static void
preferences_languages_save (EmpathyPreferences *preferences)
{
	GtkTreeView       *view;
	GtkTreeModel      *model;

	gchar             *languages = NULL;

	view = GTK_TREE_VIEW (preferences->treeview_spell_checker);
	model = gtk_tree_view_get_model (view);

	gtk_tree_model_foreach (model,
				(GtkTreeModelForeachFunc) preferences_languages_save_foreach,
				&languages);

	/* if user selects no languages, we don't want spell check */
	empathy_conf_set_bool (empathy_conf_get (),
			       EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
			       languages != NULL);

	empathy_conf_set_string (empathy_conf_get (),
				 EMPATHY_PREFS_CHAT_SPELL_CHECKER_LANGUAGES,
				 languages ? languages : "");

	g_free (languages);
}
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_entry_value_changed_cb (GtkWidget *entry,
				    gpointer   user_data)
{
	const gchar *key;

	key = g_object_get_data (G_OBJECT (entry), "key");

	empathy_conf_set_string (empathy_conf_get (),
				 key,
				 gtk_entry_get_text (GTK_ENTRY (entry)));
}
static void
preferences_string_combo_changed_cb (GtkWidget *combo,
				     gpointer   user_data)
{
	const gchar  *key;
	GtkTreeModel *model;
	GtkTreeIter   iter;
	gchar        *name;

	key = g_object_get_data (G_OBJECT (combo), "key");

	if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter)) {
		model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));

		gtk_tree_model_get (model, &iter,
				    COL_COMBO_NAME, &name,
				    -1);
		empathy_conf_set_string (empathy_conf_get (), key, name);
		g_free (name);
	}
}
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);
}