/soc/2013/bhaskar/plugins-window: a98e2005eb5a: Added notificati...

Bhaskar Kandiyal bkandiyal at gmail.com
Mon Sep 2 17:20:21 EDT 2013


Changeset: a98e2005eb5a5b125b854be960dfd1ec4d3c9123
Author:	 Bhaskar Kandiyal <bkandiyal at gmail.com>
Date:	 2013-09-03 00:29 +0530
Branch:	 soc.2013.plugins_window
URL: https://hg.pidgin.im/soc/2013/bhaskar/plugins-window/rev/a98e2005eb5a

Description:

Added notification dialog box for updates

diffstat:

 libpurple/Makefile.am      |    2 -
 libpurple/updater.c        |  283 -------------------------
 libpurple/updater.h        |   48 ----
 pidgin/Makefile.am         |    2 +
 pidgin/gtkmain.c           |   14 +-
 pidgin/gtkplugin-updater.c |  494 +++++++++++++++++++++++++++++++++++++++++++++
 pidgin/gtkplugin-updater.h |   57 +++++
 pidgin/gtkplugin.c         |   22 +-
 8 files changed, 569 insertions(+), 353 deletions(-)

diffs (truncated from 1078 to 300 lines):

diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am
--- a/libpurple/Makefile.am
+++ b/libpurple/Makefile.am
@@ -96,7 +96,6 @@ purple_coresources = \
 	theme-loader.c \
 	theme-manager.c \
 	upnp.c \
-	updater.c \
 	util.c \
 	value.c \
 	version.c \
@@ -162,7 +161,6 @@ purple_coreheaders = \
 	theme-loader.h \
 	theme-manager.h \
 	upnp.h \
-	updater.h \
 	util.h \
 	value.h \
 	xmlnode.h \
diff --git a/libpurple/updater.c b/libpurple/updater.c
deleted file mode 100644
--- a/libpurple/updater.c
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * purple
- *
- * Purple is the legal property of its developers, whose names are too numerous
- * to list here.  Please refer to the COPYRIGHT file distributed with this
- * source distribution.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
- */
-
-#define _PURPLE_UPDATER_C
-
-#include "http.h"
-#include "debug.h"
-#include "updater.h"
-#include "prefs.h"
-
-#include <sys/utsname.h>
-#include <json-glib/json-glib.h>
-
-static void
-download_plugin_cb(PurpleHttpConnection *con, PurpleHttpResponse *response, gpointer user_data)
-{
-	gchar *id = (gchar*) user_data;
-	gssize size;
-	const gchar *data, *header;
-	gchar *path, *filename, *tmp_dir, *tmp_file;
-	GRegex *regex;
-	GMatchInfo *minfo;
-
-	if(purple_http_response_is_successfull(response))
-	{
-		data = purple_http_response_get_data(response, &size);
-		header = purple_http_response_get_header(response, "Content-Disposition");
-		regex = g_regex_new("attachment; filename=\"(?<filename>.*)\"", G_REGEX_OPTIMIZE, 0, NULL);
-		if(g_regex_match(regex, header, 0, &minfo))
-		{
-			filename = g_match_info_fetch_named(minfo, "filename");
-			if(filename == NULL)
-			{
-				purple_debug_info("updater", "Error: Cannot parse filename from header!");
-				return;
-			}
-			else
-			{
-				header = purple_http_response_get_header(response, "Purple-Resource-Type");
-				purple_debug_info("updater", "Plugin Type: %s", header);
-
-				/* If we have a zip file then extract it to the appropriate directory */
-				if(g_str_has_suffix(filename, ".zip"))
-				{
-					tmp_dir = g_dir_make_tmp(NULL, NULL);
-					if(tmp_dir == NULL)
-					{
-						purple_debug_info("updater", "Error: Cannot create a temp directory for zip file extraction\n");
-					}
-					else
-					{
-						/*
-						 * Save the zip file to a temporary directory and extract the contents to the purple_user_dir()
-						 * in the appropriate directory
-						 */
-						tmp_file = g_build_filename(tmp_dir, filename, NULL);
-						if(!g_file_set_contents(tmp_file, data, size, NULL))
-						{
-							purple_debug_info("updater", "Error saving downloaded plugin %s\n", id);
-						}
-
-						path = g_build_filename(purple_user_dir(), header, id, NULL);
-						g_mkdir_with_parents(path, 0755);
-
-						purple_debug_info("updater", "Extracting file %s for %s....", tmp_file, id);
-						if(!purple_util_extract_zip_file(tmp_file, path))
-						{
-							purple_debug_error("updater", "Error: Cannot extract zip file for plugin %s", id);
-						}
-						g_free(tmp_file);
-						g_free(path);
-					}
-					g_free(tmp_dir);
-				}
-				else
-				{
-					path = g_build_filename(purple_user_dir(), header, filename, NULL);
-					g_mkdir_with_parents(g_path_get_dirname(path), 0755);
-					purple_debug_info("updater", "Downloading finished, saving to: %s\n", path);
-					if(!g_file_set_contents(path, data, size, NULL))
-					{
-						purple_debug_info("updater", "Error saving downloaded plugin %s\n", id);
-					}
-				}
-			}
-		}
-		g_match_info_free(minfo);
-		g_regex_unref(regex);
-	}
-	else {
-		purple_debug_info("updater", "Error cannot download plugin %s\n", id);
-	}
-}
-
-static gpointer
-execute_update_queue(gpointer data)
-{
-	struct utsname u_name;
-	gchar *url, *id;
-	PurpleHttpConnection *con;
-	GQueue *queue = (GQueue*) data;
-
-	uname(&u_name);
-	while(!g_queue_is_empty(queue))
-	{
-		id = (gchar*) g_queue_pop_head(queue);
-		url = g_strdup_printf("%s/plugin/download?id=%s&platform=%s&arch=%s", PURPLE_UPDATE_URI,
-			id, u_name.sysname, u_name.machine);
-
-		purple_debug_info("updater", "Starting download of: %s\n", url);
-
-		con = purple_http_get(NULL, url, download_plugin_cb, id);
-
-		while(purple_http_conn_is_running(con)) {
-			/* We wait for the connection to close */
-		}
-
-		g_free(url);
-	}
-
-	g_queue_free(queue);
-	return NULL;
-}
-
-static void
-check_updates_request_cb(PurpleHttpConnection *con, PurpleHttpResponse *response, gpointer user_data)
-{
-	JsonParser *parser;
-	JsonReader *reader;
-	const gchar *data;
-	gchar **list, **ptr;
-	const gchar *ver;
-	PurplePlugin *plug;
-	GQueue *queue;
-
-	if(!purple_http_response_is_successfull(response))
-	{
-		purple_debug_info("updater", "Error: Cannot check for updates\n");
-		return;
-	}
-
-	parser = json_parser_new();
-	data = purple_http_response_get_data(response, NULL);
-
-	json_parser_load_from_data(parser, data, -1, NULL);
-	reader = json_reader_new(json_parser_get_root(parser));
-
-	json_reader_read_member(reader, "plugins");
-
-	list = json_reader_list_members(reader);
-	queue = g_queue_new();
-	for(ptr = list; *ptr != NULL; ptr++)
-	{
-		purple_debug_info("updater", "At: %s", *ptr);
-		if(json_reader_read_member(reader, *ptr))
-		{
-			plug = purple_plugins_find_with_id(*ptr);
-			ver = json_reader_get_string_value(reader);
-			/*
-			 * If plug and ver are not NULL and current version is not equal to the version
-			 * on the server, we can update the plugin
-			 */
-			if(plug != NULL && ver != NULL && g_strcmp0(purple_plugin_get_version(plug), ver) != 0) {
-				purple_debug_info("updater", "%s: %s\n", *ptr, ver);
-				/* Add the plugin ID to the queue */
-				g_queue_push_tail(queue, *ptr);
-			}
-			else {
-				purple_debug_info("updater", "Not updating %s\n", *ptr);
-			}
-		}
-		json_reader_end_member(reader);
-	}
-	json_reader_end_member(reader);
-
-	if(!g_queue_is_empty(queue))
-	{
-		g_thread_new("execute_update_queue", execute_update_queue, queue);
-	}
-	else
-	{
-		purple_debug_info("updater", "Plugins seem to be up-to-date");
-	}
-
-	g_strfreev(list);
-	g_object_unref(reader);
-	g_object_unref(parser);
-}
-
-void
-purple_updater_check_for_updates()
-{
-	gchar *url, *json, *data;
-	PurpleHttpRequest *request;
-	JsonBuilder *builder;
-	JsonGenerator *generator;
-	JsonNode *root;
-	GList *plugin_list;
-	PurplePlugin *plug;
-	gsize len;
-
-	url = g_strdup_printf("%s/%s", PURPLE_UPDATE_URI, "api/get_version");
-	purple_debug_info("updater", "Checking for plugin updates....\n");
-
-	request = purple_http_request_new(url);
-	purple_http_request_set_method(request, "POST");
-
-	builder = json_builder_new();
-	json_builder_begin_object(builder);
-	json_builder_set_member_name(builder, "plugins");
-	json_builder_begin_array(builder);
-
-	for(plugin_list = purple_plugins_get_all(); plugin_list != NULL; plugin_list = plugin_list->next)
-	{
-		plug = plugin_list->data;
-		json_builder_add_string_value(builder, plug->info->id);
-	}
-
-	json_builder_end_array(builder);
-	json_builder_end_object(builder);
-
-	generator = json_generator_new();
-	root = json_builder_get_root(builder);
-	json_generator_set_root(generator, root);
-	json = json_generator_to_data(generator, &len);
-
-	data = g_strdup_printf("plugin_ids=%s", json);
-
-	purple_http_request_header_set(request, "Content-Type", "application/x-www-form-urlencoded");
-	purple_http_request_set_contents(request, data, g_utf8_strlen(data, -1));
-
-	purple_http_request(NULL, request, check_updates_request_cb, NULL);
-
-	purple_http_request_unref(request);
-
-	json_node_free(root);
-	g_object_unref(generator);
-	g_object_unref(builder);
-	g_free(url);
-	g_free(json);
-	g_free(data);
-}
-
-gboolean
-purple_updater_check_for_updates_timeout_cb(gpointer data)
-{
-	GDateTime *gdt_cur, *gdt_future;
-	GTimeVal cur_time, future_time;
-
-	purple_updater_check_for_updates();
-
-	gdt_cur = g_date_time_new_now_local();
-
-	g_date_time_to_timeval(gdt_cur, &cur_time);
-	purple_prefs_set_string("/purple/updater/last_updated", g_time_val_to_iso8601(&cur_time));
-
-	gdt_future = g_date_time_add_weeks(gdt_cur, 1);



More information about the Commits mailing list