/soc/2013/bhaskar/plugins-window: f1bd5d97b2ae: Switching of cat...

Bhaskar Kandiyal bkandiyal at gmail.com
Mon Aug 12 16:29:33 EDT 2013


Changeset: f1bd5d97b2aeba2cf71880b1125b0f46895d0d8c
Author:	 Bhaskar Kandiyal <bkandiyal at gmail.com>
Date:	 2013-08-13 01:51 +0530
Branch:	 soc.2013.plugins_window
URL: https://hg.pidgin.im/soc/2013/bhaskar/plugins-window/rev/f1bd5d97b2ae

Description:

Switching of categories using GtkTreeModelFilter added

diffstat:

 pidgin/gtkplugin.c |  112 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 103 insertions(+), 9 deletions(-)

diffs (175 lines):

diff --git a/pidgin/gtkplugin.c b/pidgin/gtkplugin.c
--- a/pidgin/gtkplugin.c
+++ b/pidgin/gtkplugin.c
@@ -45,6 +45,12 @@ typedef enum {
 	PLUGINS_TAB_DOWNLOAD_PLUGINS = 1,
 } PluginTabs;
 
+typedef enum {
+	PLUGIN_FILTER_ENABLED_PLUGINS = 0,
+	PLUGIN_FILTER_DISABLED_PLUGINS = 1,
+	PLUGIN_FILTER_ALL_PLUGINS = 3,
+} PluginFilter;
+
 static const gchar* DEFAULT_URI = "http://bhaskar-kandiyal.rhcloud.com/";
 static gint FIRST_LOAD = TRUE;
 
@@ -56,7 +62,7 @@ static GtkWidget *event_view = NULL;
 static GtkWidget *plugin_dialog = NULL;
 static GtkWidget *plugin_details = NULL;
 static GtkWidget *download_plugins = NULL;
-
+static GtkWidget *category_tree = NULL;
 
 static GHashTable *plugin_pref_dialogs = NULL;
 
@@ -840,16 +846,66 @@ plugin_details_view_load_status_cb(WebKi
 	}
 }
 
+static void
+plugin_category_changed_cb(GtkTreeView *view, GdkEventButton *event, GtkTreeModelFilter *filter)
+{
+	GtkTreePath *path;
+
+	if(gtk_tree_view_get_path_at_pos(view, event->x, event->y, &path, NULL, NULL, NULL))
+	{
+		gtk_tree_view_set_cursor(view, path, NULL, FALSE);
+		gtk_tree_model_filter_refilter(filter);
+		gtk_tree_path_free(path);
+	}
+}
+
+static gboolean
+plugin_filter_function(GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
+{
+	gint category;
+	gboolean enabled;
+	GtkTreeModel *cat_model;
+	GtkTreeIter cat_iter;
+
+	if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(category_tree)),
+			&cat_model, &cat_iter)) {
+		return TRUE;
+	}
+	gtk_tree_model_get(cat_model, &cat_iter, 0, &category, -1);
+	gtk_tree_model_get(model, iter, 0, &enabled, -1);
+
+	switch(category)
+	{
+	case PLUGIN_FILTER_ALL_PLUGINS:
+		return TRUE;
+	break;
+	case PLUGIN_FILTER_ENABLED_PLUGINS:
+		if(enabled) {
+			return TRUE;
+		}
+	break;
+	case PLUGIN_FILTER_DISABLED_PLUGINS:
+		if(!enabled) {
+			return TRUE;
+		}
+	break;
+	}
+
+	return FALSE;
+}
+
 void pidgin_plugin_dialog_show()
 {
-	GtkListStore *ls;
+	GtkListStore *ls, *category_store;
 	GtkCellRenderer *rend, *rendt;
 	GtkTreeViewColumn *col;
 	GtkTreeSelection *sel;
-	GtkHPaned *paned;
+	GtkTreeModel *filter;
+	GtkHPaned *paned, *pane_container;
 	GtkNotebook *notebook;
 	gchar *file, *buf;
 	GError *error = NULL;
+	GtkTreeIter iter;
 
 	if (plugin_dialog != NULL) {
 		gtk_window_present(GTK_WINDOW(plugin_dialog));
@@ -865,6 +921,34 @@ void pidgin_plugin_dialog_show()
 				GTK_WIDGET(notebook),
 				TRUE, TRUE, 0);
 
+	pane_container = GTK_HPANED(gtk_hpaned_new());
+	gtk_paned_set_position(GTK_PANED(pane_container), 100);
+
+	/* Create the categories GtkTreeView */
+	category_store = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING);
+	gtk_list_store_insert_with_values(category_store, NULL, -1, 0, PLUGIN_FILTER_ENABLED_PLUGINS, 1, _("Enabled"), -1);
+	gtk_list_store_insert_with_values(category_store, NULL, -1, 0, PLUGIN_FILTER_DISABLED_PLUGINS, 1, _("Disabled"), -1);
+	gtk_list_store_insert_with_values(category_store, NULL, -1, 0, PLUGIN_FILTER_ALL_PLUGINS, 1, _("All Plugins"), -1);
+
+	rendt = gtk_cell_renderer_text_new();
+		g_object_set(rendt,
+			     "foreground", "#c0c0c0",
+			     NULL);
+
+	category_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(category_store));
+
+	col = gtk_tree_view_column_new_with_attributes(_("Categories"),
+							rendt,
+							"markup", 1,
+							NULL);
+
+	gtk_tree_view_append_column(GTK_TREE_VIEW (category_tree), col);
+	gtk_paned_add1(GTK_PANED(pane_container), pidgin_make_scrollable(category_tree, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC,
+				GTK_SHADOW_IN, -1, -1));
+	g_object_unref(G_OBJECT(category_store));
+
+	/* -- */
+
 	paned = GTK_HPANED(gtk_hpaned_new());
 	gtk_paned_set_position(GTK_PANED(paned), 480);
 
@@ -878,10 +962,22 @@ void pidgin_plugin_dialog_show()
 
 	update_plugin_list(ls);
 
-	event_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ls));
+	/* Create a GtkTreeModelFilter */
+
+	filter = gtk_tree_model_filter_new(GTK_TREE_MODEL(ls), NULL);
+	gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(filter),
+			(GtkTreeModelFilterVisibleFunc)plugin_filter_function, NULL, NULL);
+
+	/* -- */
+
+	event_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(filter));
 
 	gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(event_view), TRUE);
 
+
+	g_signal_connect(G_OBJECT(category_tree), "button-press-event",
+							G_CALLBACK(plugin_category_changed_cb), filter);
+
 	g_signal_connect(G_OBJECT(event_view), "row-activated",
 				G_CALLBACK(show_plugin_prefs_cb), plugin_dialog);
 
@@ -902,10 +998,6 @@ void pidgin_plugin_dialog_show()
 	g_signal_connect(G_OBJECT(rend), "toggled",
 			 G_CALLBACK(plugin_toggled), ls);
 
-	rendt = gtk_cell_renderer_text_new();
-	g_object_set(rendt,
-		     "foreground", "#c0c0c0",
-		     NULL);
 	col = gtk_tree_view_column_new_with_attributes (_("Name"),
 							rendt,
 							"markup", 1,
@@ -949,7 +1041,9 @@ void pidgin_plugin_dialog_show()
 
 	/* -- Create the download plugins webview -- */
 
-	gtk_notebook_append_page(notebook, GTK_WIDGET(paned), gtk_label_new(_("Installed Plugins")));
+	gtk_paned_add2(GTK_PANED(pane_container), GTK_WIDGET(paned));
+
+	gtk_notebook_append_page(notebook, GTK_WIDGET(pane_container), gtk_label_new(_("Installed Plugins")));
 	gtk_notebook_append_page(notebook, pidgin_make_scrollable(GTK_WIDGET(download_plugins), GTK_POLICY_AUTOMATIC,
 		GTK_POLICY_AUTOMATIC, GTK_SHADOW_IN, -1, -1), gtk_label_new(_("Get New Plugins")));
 



More information about the Commits mailing list