Mercurial > audlegacy
changeset 3985:ba5af8e85857
remove some duplicated code
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Fri, 23 Nov 2007 19:26:35 +0100 |
parents | bf5c5dea45dc |
children | a77a1b3f493f |
files | src/audacious/ui_preferences.c |
diffstat | 1 files changed, 44 insertions(+), 104 deletions(-) [+] |
line wrap: on
line diff
--- a/src/audacious/ui_preferences.c Thu Nov 22 17:34:46 2007 +0100 +++ b/src/audacious/ui_preferences.c Fri Nov 23 19:26:35 2007 +0100 @@ -209,120 +209,58 @@ } static void -input_plugin_toggle(GtkCellRendererToggle * cell, - const gchar * path_str, - gpointer data) +plugin_toggle(GtkCellRendererToggle * cell, + const gchar * path_str, + gpointer data) { GtkTreeModel *model = GTK_TREE_MODEL(data); GtkTreeIter iter; GtkTreePath *path = gtk_tree_path_new_from_string(path_str); gint pluginnr; - Plugin *plugin; - /*GList *diplist, *tmplist; */ - - /* get toggled iter */ - gtk_tree_model_get_iter(model, &iter, path); - gtk_tree_model_get(model, &iter, - PLUGIN_VIEW_COL_ID, &pluginnr, - PLUGIN_VIEW_COL_PLUGIN_PTR, &plugin, - -1); - - /* do something with the value */ - plugin->enabled ^= 1; - - /* set new value */ - gtk_list_store_set(GTK_LIST_STORE(model), &iter, - PLUGIN_VIEW_COL_ACTIVE, plugin->enabled, -1); - - /* clean up */ - gtk_tree_path_free(path); -} - - -static void -vis_plugin_toggle(GtkCellRendererToggle * cell, - const gchar * path_str, - gpointer data) -{ - GtkTreeModel *model = GTK_TREE_MODEL(data); - GtkTreeIter iter; - GtkTreePath *path = gtk_tree_path_new_from_string(path_str); - gboolean fixed; - gint pluginnr; + gint plugin_type = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), "plugin_type")); /* get toggled iter */ gtk_tree_model_get_iter(model, &iter, path); - gtk_tree_model_get(model, &iter, - PLUGIN_VIEW_COL_ACTIVE, &fixed, - PLUGIN_VIEW_COL_ID, &pluginnr, -1); - /* do something with the value */ - fixed ^= 1; - - enable_vis_plugin(pluginnr, fixed); - - /* set new value */ - gtk_list_store_set(GTK_LIST_STORE(model), &iter, - PLUGIN_VIEW_COL_ACTIVE, fixed, -1); - - /* clean up */ - gtk_tree_path_free(path); -} + if (plugin_type == PLUGIN_VIEW_TYPE_INPUT) { + Plugin *plugin; + /*GList *diplist, *tmplist; */ -static void -effect_plugin_toggle(GtkCellRendererToggle * cell, - const gchar * path_str, - gpointer data) -{ - GtkTreeModel *model = GTK_TREE_MODEL(data); - GtkTreeIter iter; - GtkTreePath *path = gtk_tree_path_new_from_string(path_str); - gboolean fixed; - gint pluginnr; + gtk_tree_model_get(model, &iter, + PLUGIN_VIEW_COL_ID, &pluginnr, + PLUGIN_VIEW_COL_PLUGIN_PTR, &plugin, -1); - /* get toggled iter */ - gtk_tree_model_get_iter(model, &iter, path); - gtk_tree_model_get(model, &iter, - PLUGIN_VIEW_COL_ACTIVE, &fixed, - PLUGIN_VIEW_COL_ID, &pluginnr, -1); + /* do something with the value */ + plugin->enabled ^= 1; - /* do something with the value */ - fixed ^= 1; + /* set new value */ + gtk_list_store_set(GTK_LIST_STORE(model), &iter, + PLUGIN_VIEW_COL_ACTIVE, plugin->enabled, -1); + } else { + gboolean fixed; + gtk_tree_model_get(model, &iter, + PLUGIN_VIEW_COL_ACTIVE, &fixed, + PLUGIN_VIEW_COL_ID, &pluginnr, -1); - enable_effect_plugin(pluginnr, fixed); - - /* set new value */ - gtk_list_store_set(GTK_LIST_STORE(model), &iter, - PLUGIN_VIEW_COL_ACTIVE, fixed, -1); + /* do something with the value */ + fixed ^= 1; - /* clean up */ - gtk_tree_path_free(path); -} -static void -general_plugin_toggle(GtkCellRendererToggle * cell, - const gchar * path_str, - gpointer data) -{ - GtkTreeModel *model = GTK_TREE_MODEL(data); - GtkTreeIter iter; - GtkTreePath *path = gtk_tree_path_new_from_string(path_str); - gboolean fixed; - gint pluginnr; + switch (plugin_type) { + case PLUGIN_VIEW_TYPE_GENERAL: + enable_general_plugin(pluginnr, fixed); + break; + case PLUGIN_VIEW_TYPE_VIS: + enable_vis_plugin(pluginnr, fixed); + break; + case PLUGIN_VIEW_TYPE_EFFECT: + enable_effect_plugin(pluginnr, fixed); + break; + } - /* get toggled iter */ - gtk_tree_model_get_iter(model, &iter, path); - gtk_tree_model_get(model, &iter, - PLUGIN_VIEW_COL_ACTIVE, &fixed, - PLUGIN_VIEW_COL_ID, &pluginnr, -1); - - /* do something with the value */ - fixed ^= 1; - - enable_general_plugin(pluginnr, fixed); - - /* set new value */ - gtk_list_store_set(GTK_LIST_STORE(model), &iter, - PLUGIN_VIEW_COL_ACTIVE, fixed, -1); + /* set new value */ + gtk_list_store_set(GTK_LIST_STORE(model), &iter, + PLUGIN_VIEW_COL_ACTIVE, fixed, -1); + } /* clean up */ gtk_tree_path_free(path); @@ -368,7 +306,8 @@ static void on_plugin_view_realize(GtkTreeView * treeview, GCallback callback, - gpointer data) + gpointer data, + gint plugin_type) { GtkListStore *store; GtkTreeIter iter; @@ -385,6 +324,7 @@ store = gtk_list_store_new(PLUGIN_VIEW_N_COLS, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_POINTER); + g_object_set_data(G_OBJECT(store), "plugin_type" , GINT_TO_POINTER(plugin_type)); column = gtk_tree_view_column_new(); gtk_tree_view_column_set_title(column, _("Enabled")); @@ -455,28 +395,28 @@ on_input_plugin_view_realize(GtkTreeView * treeview, gpointer data) { - on_plugin_view_realize(treeview, G_CALLBACK(input_plugin_toggle), ip_data.input_list); + on_plugin_view_realize(treeview, G_CALLBACK(plugin_toggle), ip_data.input_list, PLUGIN_VIEW_TYPE_INPUT); } static void on_effect_plugin_view_realize(GtkTreeView * treeview, gpointer data) { - on_plugin_view_realize(treeview, G_CALLBACK(effect_plugin_toggle), ep_data.effect_list); + on_plugin_view_realize(treeview, G_CALLBACK(plugin_toggle), ep_data.effect_list, PLUGIN_VIEW_TYPE_EFFECT); } static void on_general_plugin_view_realize(GtkTreeView * treeview, gpointer data) { - on_plugin_view_realize(treeview, G_CALLBACK(general_plugin_toggle), gp_data.general_list); + on_plugin_view_realize(treeview, G_CALLBACK(plugin_toggle), gp_data.general_list, PLUGIN_VIEW_TYPE_GENERAL); } static void on_vis_plugin_view_realize(GtkTreeView * treeview, gpointer data) { - on_plugin_view_realize(treeview, G_CALLBACK(vis_plugin_toggle), vp_data.vis_list); + on_plugin_view_realize(treeview, G_CALLBACK(plugin_toggle), vp_data.vis_list, PLUGIN_VIEW_TYPE_VIS); } static void