/soc/2013/bhaskar/plugins-window: 9f0c4f7abe2a: Added functional...

Bhaskar Kandiyal bkandiyal at gmail.com
Sun Jul 28 15:41:18 EDT 2013


Changeset: 9f0c4f7abe2a469bf16556c029f9ab1ddcf6f2c6
Author:	 Bhaskar Kandiyal <bkandiyal at gmail.com>
Date:	 2013-07-29 01:10 +0530
Branch:	 soc.2013.plugins_window
URL: https://hg.pidgin.im/soc/2013/bhaskar/plugins-window/rev/9f0c4f7abe2a

Description:

Added functionality to install plugins from the website

diffstat:

 pidgin/gtkplugin.c |  68 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 66 insertions(+), 2 deletions(-)

diffs (93 lines):

diff --git a/pidgin/gtkplugin.c b/pidgin/gtkplugin.c
--- a/pidgin/gtkplugin.c
+++ b/pidgin/gtkplugin.c
@@ -45,7 +45,7 @@ typedef enum {
 	PLUGINS_TAB_DOWNLOAD_PLUGINS = 1,
 } PluginTabs;
 
-static const gchar* DEFAULT_URI = "http://bhaskar-kandiyal.rhcloud.com/";
+static const gchar* DEFAULT_URI = "http://localhost:8000/";
 static gint FIRST_LOAD = TRUE;
 
 static void plugin_toggled_stage_two(PurplePlugin *plug, GtkTreeModel *model,
@@ -731,8 +731,70 @@ plugin_details_button_click_cb(WebKitDOM
 	}
 }
 
+
+static gboolean
+webview_download_status(gpointer data)
+{
+	GtkWidget *dialog;
+	WebKitDownloadStatus status = webkit_download_get_status(WEBKIT_DOWNLOAD(data));
+	switch(status)
+	{
+	case WEBKIT_DOWNLOAD_STATUS_FINISHED:
+		purple_debug_info("plugins", "Download Finished\n");
+		dialog = gtk_message_dialog_new(GTK_WINDOW(plugin_dialog), GTK_DIALOG_MODAL,
+				GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
+				_("Plugin installed. You can now enable the plugin from the \'Installed Plugins\' tab"));
+		gtk_dialog_run(GTK_DIALOG(dialog));
+		gtk_widget_destroy(dialog);
+		return FALSE;
+	break;
+
+	case WEBKIT_DOWNLOAD_STATUS_ERROR:
+		purple_debug_info("plugins", "Error downloading file\n");
+		dialog = gtk_message_dialog_new(GTK_WINDOW(plugin_dialog), GTK_DIALOG_MODAL,
+				GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
+				_("An error occurred when trying to download the plugin. Please try again."));
+		gtk_dialog_run(GTK_DIALOG(dialog));
+		gtk_widget_destroy(dialog);
+		return FALSE;
+	break;
+
+	case WEBKIT_DOWNLOAD_STATUS_CANCELLED:
+		purple_debug_info("plugins", "Download Cancelled");
+		return FALSE;
+	break;
+
+	default:
+		return TRUE;
+	}
+}
+
+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);
+
+	/* Create the plugins directory if it does not exist */
+	if(g_mkdir_with_parents(g_path_get_dirname(uri), 0755) == -1)
+	{
+		purple_debug_info("plugins", "Error creating directory: %s\n", uri);
+	}
+
+	uri = g_filename_to_uri(uri, NULL, NULL);
+	purple_debug_info("plugins", "SAVING DOWNLOAD TO: %s with suggested filename: %s\n", uri, webkit_download_get_suggested_filename(WEBKIT_DOWNLOAD(download)));
+
+	webkit_download_set_destination_uri(WEBKIT_DOWNLOAD(download), uri);
+	g_timeout_add_seconds(1, webview_download_status, download);
+
+	g_free(uri);
+
+	return TRUE;
+}
+
 static void
-setup_webview_input_event_handlers(WebKitWebView *webview) {
+setup_webview_input_event_handlers(WebKitWebView *webview)
+{
 	WebKitDOMDocument *document;
 	WebKitDOMNodeList *elements;
 	gulong element_count;
@@ -871,6 +933,8 @@ void pidgin_plugin_dialog_show()
 	/* Create the download plugins webview */
 
 	download_plugins = webkit_web_view_new();
+	g_signal_connect (G_OBJECT(download_plugins), "download-requested", G_CALLBACK (webview_download_requested_cb), NULL);
+	/*g_signal_connect (G_OBJECT(download_plugins), "mime-type-policy-decision-requested", G_CALLBACK (webview_download_mime_type_cb), NULL);*/
 
 	/* -- Create the download plugins webview -- */
 



More information about the Commits mailing list