/soc/2013/bhaskar/plugins-window: 226b4e33d616: Created an initi...

Bhaskar Kandiyal bkandiyal at gmail.com
Tue Jun 11 09:49:04 EDT 2013


Changeset: 226b4e33d616710e7c96153a881946142882823e
Author:	 Bhaskar Kandiyal <bkandiyal at gmail.com>
Date:	 2013-06-11 00:27 +0530
Branch:	 soc.2013.plugins_window
URL: https://hg.pidgin.im/soc/2013/bhaskar/plugins-window/rev/226b4e33d616

Description:

Created an initial implementation of the new plugins window

diffstat:

 configure.ac                  |    1 +
 pidgin/Makefile.am            |    2 +-
 pidgin/gtkplugin.c            |  513 +++++++++++++++++++++++------------------
 pidgin/ui/Makefile.am         |    7 +
 pidgin/ui/plugin_details.html |  177 ++++++++++++++
 5 files changed, 468 insertions(+), 232 deletions(-)

diffs (truncated from 891 to 300 lines):

diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -2858,6 +2858,7 @@ AC_CONFIG_FILES([Makefile
 		   pidgin/plugins/perl/common/Makefile.PL
 		   pidgin/plugins/ticker/Makefile
 		   pidgin/themes/Makefile
+       pidgin/ui/Makefile
 		   libpurple/ciphers/Makefile
 		   libpurple/example/Makefile
 		   libpurple/gconf/Makefile
diff --git a/pidgin/Makefile.am b/pidgin/Makefile.am
--- a/pidgin/Makefile.am
+++ b/pidgin/Makefile.am
@@ -36,7 +36,7 @@ if ENABLE_GTK
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = pidgin-3.pc
 
-SUBDIRS = pixmaps plugins themes
+SUBDIRS = pixmaps plugins themes ui
 
 bin_PROGRAMS = pidgin
 
diff --git a/pidgin/gtkplugin.c b/pidgin/gtkplugin.c
--- a/pidgin/gtkplugin.c
+++ b/pidgin/gtkplugin.c
@@ -32,6 +32,7 @@
 #include "prefs.h"
 #include "request.h"
 #include "pidgintooltip.h"
+#include "gtkwebview.h"
 
 #include <string.h>
 
@@ -39,21 +40,24 @@
 
 #define PIDGIN_RESPONSE_CONFIGURE 98121
 
+typedef enum {
+	PLUGINS_TAB_INSTALLED_PLUGINS = 0,
+	PLUGINS_TAB_DOWNLOAD_PLUGINS = 1,
+} PluginTabs;
+
+static const gchar* DEFAULT_URI = "http://bhaskar-kandiyal.rhcloud.com/";
+static gint FIRST_LOAD = TRUE;
+
 static void plugin_toggled_stage_two(PurplePlugin *plug, GtkTreeModel *model,
                                   GtkTreeIter *iter, gboolean unload);
+static gchar* convert_to_html_para(const gchar *input);
 
-static GtkWidget *expander = NULL;
+static GtkWidget *event_view = NULL;
 static GtkWidget *plugin_dialog = NULL;
+static GtkWidget *plugin_details = NULL;
+static GtkWidget *download_plugins = NULL;
 
-static GtkLabel *plugin_name = NULL;
-static GtkTextBuffer *plugin_desc = NULL;
-static GtkLabel *plugin_error = NULL;
-static GtkLabel *plugin_author = NULL;
-static GtkLabel *plugin_website = NULL;
-static gchar *plugin_website_uri = NULL;
-static GtkLabel *plugin_filename = NULL;
 
-static GtkWidget *pref_button = NULL;
 static GHashTable *plugin_pref_dialogs = NULL;
 
 GtkWidget *
@@ -168,6 +172,7 @@ static void plugin_loading_common(Purple
 {
 	GtkTreeIter iter;
 	GtkTreeModel *model = gtk_tree_view_get_model(view);
+	gchar *buf;
 
 	if (gtk_tree_model_get_iter_first(model, &iter)) {
 		do {
@@ -189,12 +194,14 @@ static void plugin_loading_common(Purple
 				gtk_tree_model_get(model, &iter, 2, &plug, -1);
 				if (plug == plugin)
 				{
-					gtk_widget_set_sensitive(pref_button,
-						loaded
-						&& ((PIDGIN_IS_PIDGIN_PLUGIN(plug) && plug->info->ui_info
-							&& PIDGIN_PLUGIN_UI_INFO(plug)->get_config_frame)
-						 || (plug->info->prefs_info
-							&& plug->info->prefs_info->get_plugin_pref_frame)));
+					buf = g_strdup_printf("enableConfigure(%d)", purple_plugin_is_loaded(plug)
+								&& ((PIDGIN_IS_PIDGIN_PLUGIN(plug) && plug->info->ui_info
+									&& PIDGIN_PLUGIN_UI_INFO(plug)->get_config_frame)
+								 || (plug->info->prefs_info
+									&& plug->info->prefs_info->get_plugin_pref_frame)));
+
+					gtk_webview_safe_execute_script(GTK_WEBVIEW(plugin_details), buf);
+					g_free(buf);
 				}
 			}
 
@@ -317,6 +324,8 @@ static void plugin_toggled(GtkCellRender
 
 static void plugin_toggled_stage_two(PurplePlugin *plug, GtkTreeModel *model, GtkTreeIter *iter, gboolean unload)
 {
+	gchar *buf, *error;
+
 	if (unload)
 	{
 		pidgin_set_cursor(plugin_dialog, GDK_WATCH);
@@ -343,36 +352,22 @@ static void plugin_toggled_stage_two(Pur
 		pidgin_clear_cursor(plugin_dialog);
 	}
 
-	gtk_widget_set_sensitive(pref_button,
-		purple_plugin_is_loaded(plug)
-		&& ((PIDGIN_IS_PIDGIN_PLUGIN(plug) && plug->info->ui_info
-			&& PIDGIN_PLUGIN_UI_INFO(plug)->get_config_frame)
-		 || (plug->info->prefs_info
-			&& plug->info->prefs_info->get_plugin_pref_frame)));
+	buf = g_strdup_printf("enableConfigure(%d)", purple_plugin_is_loaded(plug)
+			&& ((PIDGIN_IS_PIDGIN_PLUGIN(plug) && plug->info->ui_info
+				&& PIDGIN_PLUGIN_UI_INFO(plug)->get_config_frame)
+			 || (plug->info->prefs_info
+				&& plug->info->prefs_info->get_plugin_pref_frame)));
+
+	gtk_webview_safe_execute_script(GTK_WEBVIEW(plugin_details), buf);
+	g_free(buf);
 
 	if (plug->error != NULL)
 	{
-		gchar *name = g_markup_escape_text(purple_plugin_get_name(plug), -1);
-
-		gchar *error = g_markup_escape_text(plug->error, -1);
-		gchar *text;
-
-		text = g_strdup_printf(
-			"<b>%s</b> %s\n<span weight=\"bold\" color=\"red\"%s</span>",
-			purple_plugin_get_name(plug), purple_plugin_get_version(plug), error);
-		gtk_list_store_set(GTK_LIST_STORE (model), iter,
-				   1, text,
-				   -1);
-		g_free(text);
-
-		text = g_strdup_printf(
-			"<span weight=\"bold\" color=\"red\">%s</span>",
-			error);
-		gtk_label_set_markup(plugin_error, text);
-		g_free(text);
-
+		error = convert_to_html_para(plug->error);
+		buf = g_strdup_printf("showError('%s')", "Error: Kaboom!");
+		gtk_webview_safe_execute_script(GTK_WEBVIEW(plugin_details), buf);
 		g_free(error);
-		g_free(name);
+		g_free(buf);
 	}
 
 	gtk_list_store_set(GTK_LIST_STORE (model), iter,
@@ -398,93 +393,115 @@ static gboolean ensure_plugin_visible(vo
 	return FALSE;
 }
 
+/* Converts the string with newlines into separate paragraphs and escapes any quotations */
+static gchar*
+convert_to_html_para(const gchar *input)
+{
+	GString *str = g_string_new("<p>");
+
+	const gchar *cur = input;
+	while (cur && *cur) {
+		switch(*cur) {
+			case '\n':
+				g_string_append(str, "</p><p>");
+			break;
+			case '\'':
+				g_string_append(str, "\\\'");
+			break;
+			case '\"':
+				g_string_append(str, "\\\"");
+			break;
+			default:
+				g_string_append_c(str, *cur);
+			break;
+		}
+		cur++;
+	}
+
+	g_string_append(str, "</p>");
+	return g_string_free(str, FALSE);
+}
+
+/* Only strips the newline and escapes the quotes */
+static gchar*
+strip_newline_and_escape(const gchar *input)
+{
+	GString *str = g_string_new("");
+
+	const gchar *cur = input;
+	while (cur && *cur) {
+		switch (*cur) {
+			case '\n':
+				break;
+			break;
+			case '\'':
+				g_string_append(str, "\\\'");
+			break;
+			case '\"':
+				g_string_append(str, "\\\"");
+			break;
+			default:
+				g_string_append_c(str, *cur);
+			break;
+		}
+		cur++;
+	}
+
+	return g_string_free(str, FALSE);
+}
+
+
 static void prefs_plugin_sel (GtkTreeSelection *sel, GtkTreeModel *model)
 {
-	gchar *buf, *tmp, *name, *version;
+	gchar *buf, *name, *version, *description, *author;
 	GtkTreeIter  iter;
 	GValue val;
 	PurplePlugin *plug;
 
-	if (!gtk_tree_selection_get_selected (sel, &model, &iter))
-	{
-		gtk_widget_set_sensitive(pref_button, FALSE);
-
-		/* Collapse and disable the expander widget */
-		gtk_expander_set_expanded(GTK_EXPANDER(expander), FALSE);
-		gtk_widget_set_sensitive(expander, FALSE);
-
+	if (!gtk_tree_selection_get_selected (sel, &model, &iter)) {
+		gtk_webview_safe_execute_script(GTK_WEBVIEW(plugin_details), "showPluginIntro(false);");
 		return;
 	}
 
-	gtk_widget_set_sensitive(expander, TRUE);
-
 	val.g_type = 0;
 	gtk_tree_model_get_value (model, &iter, 2, &val);
 	plug = g_value_get_pointer(&val);
 
-	name = g_markup_escape_text(purple_plugin_get_name(plug), -1);
-	version = g_markup_escape_text(purple_plugin_get_version(plug), -1);
-	buf = g_strdup_printf(
-		"<span size=\"larger\" weight=\"bold\">%s</span> "
-		"<span size=\"smaller\">%s</span>",
-		name, version);
-	gtk_label_set_markup(plugin_name, buf);
-	g_free(name);
-	g_free(version);
+	name = strip_newline_and_escape(purple_plugin_get_name(plug));
+	version = strip_newline_and_escape(purple_plugin_get_version(plug));
+
+	description = convert_to_html_para(purple_plugin_get_description(plug));
+	author = strip_newline_and_escape(purple_plugin_get_author(plug));
+
+	buf = g_strdup_printf("updateDetails('%s', '%s', '%s', '%s', '%s', '%s', '%s')", name, version,
+			description, author,
+			purple_plugin_get_homepage(plug), plug->path, (plug->error != NULL) ? plug->error : "" );
+
+	gtk_webview_safe_execute_script(GTK_WEBVIEW(plugin_details), buf);
 	g_free(buf);
 
-	gtk_text_buffer_set_text(plugin_desc, purple_plugin_get_description(plug), -1);
-	gtk_label_set_text(plugin_author, purple_plugin_get_author(plug));
-	gtk_label_set_text(plugin_filename, plug->path);
-
-	g_free(plugin_website_uri);
-	plugin_website_uri = g_strdup(purple_plugin_get_homepage(plug));
-	if (plugin_website_uri)
-	{
-		tmp = g_markup_escape_text(plugin_website_uri, -1);
-		buf = g_strdup_printf("<span underline=\"single\" "
-			"foreground=\"blue\">%s</span>", tmp);
-		gtk_label_set_markup(plugin_website, buf);
-		g_free(tmp);
-		g_free(buf);
-	}
-	else
-	{
-		gtk_label_set_text(plugin_website, NULL);
-	}
-
-	if (plug->error == NULL)
-	{
-		gtk_label_set_text(plugin_error, NULL);
-	}
-	else
-	{
-		tmp = g_markup_escape_text(plug->error, -1);
-		buf = g_strdup_printf(
-			_("<span foreground=\"red\" weight=\"bold\">"
-			  "Error: %s\n"
-			  "Check the plugin website for an update."
-			  "</span>"),
-			tmp);
-		gtk_label_set_markup(plugin_error, buf);



More information about the Commits mailing list