/soc/2013/bhaskar/plugins-window: 005bedecb603: Added support fo...

Bhaskar Kandiyal bkandiyal at gmail.com
Sun Aug 25 15:30:30 EDT 2013


Changeset: 005bedecb6034766c65f31d83f92b5c847e39bd0
Author:	 Bhaskar Kandiyal <bkandiyal at gmail.com>
Date:	 2013-08-25 22:06 +0530
Branch:	 soc.2013.plugins_window
URL: https://hg.pidgin.im/soc/2013/bhaskar/plugins-window/rev/005bedecb603

Description:

Added support for filtering downloaded plugins. Also the Purple-Resource-Type header is now used to save the plugins to their appropriate place

diffstat:

 pidgin/gtkplugin.c |  62 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 56 insertions(+), 6 deletions(-)

diffs (124 lines):

diff --git a/pidgin/gtkplugin.c b/pidgin/gtkplugin.c
--- a/pidgin/gtkplugin.c
+++ b/pidgin/gtkplugin.c
@@ -38,6 +38,7 @@
 #include <string.h>
 #include <json-glib/json-glib.h>
 #include <sys/utsname.h>
+#include <libsoup/soup.h>
 
 #include "gtk3compat.h"
 #define PIDGIN_RESPONSE_CONFIGURE 98121
@@ -51,10 +52,11 @@ typedef enum {
 	PLUGIN_FILTER_ENABLED_PLUGINS = 0,
 	PLUGIN_FILTER_DISABLED_PLUGINS = 1,
 	PLUGIN_FILTER_ALL_PLUGINS = 3,
+	PLUGIN_FILTER_ALL_DOWNLOADED = 4,
 } PluginFilter;
 
-static const gchar* DEFAULT_URI = "http://bhaskar-kandiyal.rhcloud.com";
-/*static const gchar* DEFAULT_URI = "http://127.0.0.1:8000"; /* For local debugging only */
+/*static const gchar* DEFAULT_URI = "http://bhaskar-kandiyal.rhcloud.com";*/
+static const gchar* DEFAULT_URI = "http://127.0.0.1:8000"; /* For local debugging only */
 static gint FIRST_LOAD = TRUE;
 
 static void plugin_toggled_stage_two(PurplePlugin *plug, GtkTreeModel *model,
@@ -804,7 +806,22 @@ static gboolean
 webview_download_requested_cb(WebKitWebView *webview, GObject *download, gpointer user_data)
 {
 	gchar *uri;
-	uri = g_build_filename(purple_user_dir(), "plugins", webkit_download_get_suggested_filename(WEBKIT_DOWNLOAD(download)), NULL);
+	const gchar *type;
+	SoupMessage *msg;
+	SoupMessageHeaders *headers;
+	GValue headers_value = G_VALUE_INIT;
+
+	msg = webkit_network_response_get_message(webkit_download_get_network_response(WEBKIT_DOWNLOAD(download)));
+
+	g_value_init(&headers_value, SOUP_TYPE_MESSAGE_HEADERS);
+	g_object_get_property(G_OBJECT(msg), SOUP_MESSAGE_RESPONSE_HEADERS, &headers_value);
+	headers = g_value_get_boxed(&headers_value);
+	g_value_unset(&headers_value);
+
+	type = soup_message_headers_get_one(headers, "Purple-Resource-Type");
+
+	/* Is it safe to use the resource type header as it is when building the filename? */
+	uri = g_build_filename(purple_user_dir(), type, webkit_download_get_suggested_filename(WEBKIT_DOWNLOAD(download)), NULL);
 
 	/* Create the plugins directory if it does not exist */
 	if(g_mkdir_with_parents(g_path_get_dirname(uri), 0755) == -1)
@@ -879,31 +896,63 @@ plugin_filter_function(GtkTreeModel *mod
 	gboolean enabled;
 	GtkTreeModel *cat_model;
 	GtkTreeIter cat_iter;
+	PurplePlugin *plug;
+	GValue val;
+	gchar *user_path, *plugin_path;
 
 	if(!gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(category_tree)),
-			&cat_model, &cat_iter)) {
+			&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);
 
+	val.g_type = 0;
+	gtk_tree_model_get_value(model, iter, 2, &val);
+	plug = g_value_get_pointer(&val);
+
 	switch(category)
 	{
 	case PLUGIN_FILTER_ALL_PLUGINS:
 		return TRUE;
 	break;
 	case PLUGIN_FILTER_ENABLED_PLUGINS:
-		if(enabled) {
+		if(enabled)
+		{
 			return TRUE;
 		}
 	break;
 	case PLUGIN_FILTER_DISABLED_PLUGINS:
-		if(!enabled) {
+		if(!enabled)
+		{
 			return TRUE;
 		}
 	break;
+	case PLUGIN_FILTER_ALL_DOWNLOADED:
+#ifdef _WIN32
+		user_path = g_build_path("\\", purple_user_dir(), "plugins", NULL);
+#else
+		user_path = g_build_path("/", purple_user_dir(), "plugins", NULL);
+#endif
+		plugin_path = g_path_get_dirname(plug->path);
+
+		if(g_strcmp0(user_path, plugin_path) == 0)
+		{
+			return TRUE;
+		}
+		else
+		{
+			return FALSE;
+		}
+
+		g_free(user_path);
+		g_free(plugin_path);
+
+	break;
 	}
 
+	g_value_unset(&val);
 	return FALSE;
 }
 
@@ -1101,6 +1150,7 @@ void pidgin_plugin_dialog_show()
 	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);
+	gtk_list_store_insert_with_values(category_store, NULL, -1, 0, PLUGIN_FILTER_ALL_DOWNLOADED, 1, _("Downloaded"), -1);
 
 	rendt = gtk_cell_renderer_text_new();
 		g_object_set(rendt,



More information about the Commits mailing list