/soc/2013/bhaskar/plugins-window: 9c1ccbdfb0f2: Improved update ...

Bhaskar Kandiyal bkandiyal at gmail.com
Sat Sep 14 07:14:07 EDT 2013


Changeset: 9c1ccbdfb0f204adbfac645ee547caf85b20ab55
Author:	 Bhaskar Kandiyal <bkandiyal at gmail.com>
Date:	 2013-09-14 16:43 +0530
Branch:	 soc.2013.plugins_window
URL: https://hg.pidgin.im/soc/2013/bhaskar/plugins-window/rev/9c1ccbdfb0f2

Description:

Improved update installation and bug fixes

diffstat:

 libpurple/plugin.c         |    1 -
 libpurple/util.c           |   15 ++++-
 pidgin/gtkmain.c           |    7 ++
 pidgin/gtkplugin-updater.c |   99 ++++++++++++++++++++++++++++++++++--
 pidgin/gtkplugin-updater.h |   10 ++-
 pidgin/gtkplugin.c         |  123 ++++++++++++++++++++++++++++++--------------
 pidgin/gtkprefs.c          |    1 +
 7 files changed, 206 insertions(+), 50 deletions(-)

diffs (truncated from 468 to 300 lines):

diff --git a/libpurple/plugin.c b/libpurple/plugin.c
--- a/libpurple/plugin.c
+++ b/libpurple/plugin.c
@@ -488,7 +488,6 @@ purple_plugin_probe(const char *filename
 	{
 		plugin->removeable = g_file_info_get_attribute_boolean(gfile_info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE);
 		g_object_unref(gfile_info);
-		purple_debug_info("plugins", "Removeable: %s\n", (plugin->removeable)?"TRUE":"FALSE");
 	}
 	else {
 		plugin->removeable = FALSE;
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -4860,7 +4860,7 @@ purple_util_extract_zip_file(const gchar
 	mz_bool status;
 	mz_zip_archive zip_archive;
 	mz_zip_archive_file_stat file_stat;
-	gchar *file;
+	gchar *file, *base;
 
 	memset(&zip_archive, 0, sizeof(zip_archive));
 	status = mz_zip_reader_init_file(&zip_archive, zip_file, 0);
@@ -4899,9 +4899,20 @@ purple_util_extract_zip_file(const gchar
 		}
 		else
 		{
+			base = g_path_get_dirname(file);
+			if(g_mkdir_with_parents(base, 0755) == -1)
+			{
+				purple_debug_error("util", "g_mkdir_with_parents failed on directory %s\n", base);
+				g_free(base);
+				mz_zip_reader_end(&zip_archive);
+				return FALSE;
+			}
+
+			g_free(base);
+
 			if(!mz_zip_reader_extract_to_file(&zip_archive, i, file, MZ_ZIP_FLAG_CASE_SENSITIVE))
 			{
-				purple_debug_error("util", "Error: Cannot extract %s from %s", file_stat.m_filename, zip_file);
+				purple_debug_error("util", "Error: Cannot extract %s from %s\n", file_stat.m_filename, zip_file);
 				g_free(file);
 				mz_zip_reader_end(&zip_archive);
 				return FALSE;
diff --git a/pidgin/gtkmain.c b/pidgin/gtkmain.c
--- a/pidgin/gtkmain.c
+++ b/pidgin/gtkmain.c
@@ -850,6 +850,13 @@ int main(int argc, char *argv[])
 		}
 	}
 
+
+	if(purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/updater/install_pending_updates"))
+	{
+		purple_debug_info("gtkmain", "Installing pending updates....");
+		pidgin_plugin_updater_install_pending_updates();
+	}
+
 	/* load plugins we had when we quit */
 	purple_plugins_load_saved(PIDGIN_PREFS_ROOT "/plugins/loaded");
 
diff --git a/pidgin/gtkplugin-updater.c b/pidgin/gtkplugin-updater.c
--- a/pidgin/gtkplugin-updater.c
+++ b/pidgin/gtkplugin-updater.c
@@ -113,7 +113,7 @@ download_plugin_cb(PurpleHttpConnection 
 				}
 				else
 				{
-					path = g_build_filename(purple_user_dir(), header, filename, NULL);
+					path = g_build_filename(purple_user_dir(), "updates", 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))
@@ -322,7 +322,7 @@ static gboolean handle_updates (gpointer
 	}
 	else
 	{
-		purple_debug_info("updater", "Plugins seem to be up-to-date");
+		purple_debug_info("updater", "Plugins are up-to-date");
 		if(INTERACTIVE)
 		{
 			msgd = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
@@ -362,8 +362,6 @@ check_updates_request_cb(PurpleHttpConne
 		return;
 	}
 
-	purple_debug_info("updater", "%s\n", data);
-
 	parser = json_parser_new();
 	data = purple_http_response_get_data(response, NULL);
 
@@ -379,7 +377,6 @@ check_updates_request_cb(PurpleHttpConne
 
 	for(ptr = list; *ptr != NULL; ptr++)
 	{
-		purple_debug_info("updater", "At: %s\n", *ptr);
 		if(json_reader_read_member(reader, *ptr) && json_reader_count_members(reader) >= 0)
 		{
 			plug = purple_plugins_find_with_id(*ptr);
@@ -397,7 +394,6 @@ check_updates_request_cb(PurpleHttpConne
 			 * 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);
 				gtk_list_store_insert_with_values(plugin_store, NULL, -1, PLUGIN_COL_SELECTED, TRUE, PLUGIN_COL_ID, *ptr,
@@ -493,3 +489,94 @@ pidgin_plugin_updater_check_for_updates_
 	g_date_time_unref(gdt_future);
 	return FALSE;
 }
+
+void
+pidgin_plugin_updater_install_pending_updates()
+{
+	gchar *update_path, *tmp_path, *dest_path;
+	GFile *update_dir, *tmp_dir, *dest_dir;
+	GFileEnumerator *file_enum, *tmp_enum;
+	GFileInfo *file_info, *tmp_info;
+	gboolean success = TRUE;
+
+	update_path = g_build_filename(purple_user_dir(), "updates", NULL);
+	update_dir = g_file_new_for_path(update_path);
+	g_free(update_path);
+
+	if(update_dir == NULL)
+		return;
+
+	file_enum = g_file_enumerate_children(update_dir, "*", G_FILE_QUERY_INFO_NONE, NULL, NULL);
+
+	if(file_enum == NULL)
+	{
+		g_object_unref(update_dir);
+		return;
+	}
+
+	while((file_info = g_file_enumerator_next_file(file_enum, NULL, NULL)) != NULL)
+	{
+		if(g_file_info_get_file_type(file_info) == G_FILE_TYPE_DIRECTORY)
+		{
+			update_path = g_build_filename(g_file_get_path(update_dir), g_file_info_get_name(file_info), NULL);
+			tmp_dir = g_file_new_for_path(update_path);
+			tmp_enum = g_file_enumerate_children(tmp_dir, "*", G_FILE_QUERY_INFO_NONE, NULL, NULL);
+
+			g_free(update_path);
+			g_object_unref(tmp_dir);
+
+			while((tmp_info = g_file_enumerator_next_file(tmp_enum, NULL, NULL)) != NULL)
+			{
+				update_path = g_build_filename(g_file_get_path(tmp_dir), g_file_info_get_name(tmp_info), NULL);
+				tmp_dir = g_file_new_for_path(update_path);
+
+				if(g_str_has_suffix(g_file_info_get_name(tmp_info), ".zip"))
+				{
+					dest_path = g_build_filename(purple_user_dir(), g_file_info_get_name(file_info),  NULL);
+					if(!purple_util_extract_zip_file(update_path, dest_path))
+					{
+						purple_debug_error("updater", "Cannot extract %s to %s", update_path, dest_path);
+						success = FALSE;
+					}
+					else
+					{
+						g_file_delete(tmp_dir, NULL, NULL);
+					}
+				}
+				else
+				{
+
+					dest_path = g_build_filename(purple_user_dir(), g_file_info_get_name(file_info), g_file_info_get_name(tmp_info), NULL);
+					dest_dir = g_file_new_for_path(dest_path);
+
+					if(!g_file_copy(tmp_dir, dest_dir, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL))
+					{
+						purple_debug_error("updater", "Cannot copy %s to %s\n", update_path, dest_path);
+						success = FALSE;
+					}
+					else
+					{
+						g_file_delete(tmp_dir, NULL, NULL);
+					}
+
+					g_object_unref(dest_dir);
+				}
+
+				g_free(update_path);
+				g_free(dest_path);
+				g_object_unref(tmp_dir);
+				g_object_unref(tmp_info);
+			}
+
+			g_file_enumerator_close(tmp_enum, NULL, NULL);
+			g_object_unref(tmp_enum);
+		}
+		g_object_unref(file_info);
+	}
+
+	purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/updater/install_pending_updates", !success);
+
+	g_file_enumerator_close(file_enum, NULL, NULL);
+	g_object_unref(file_enum);
+	g_object_unref(update_dir);
+}
diff --git a/pidgin/gtkplugin-updater.h b/pidgin/gtkplugin-updater.h
--- a/pidgin/gtkplugin-updater.h
+++ b/pidgin/gtkplugin-updater.h
@@ -29,8 +29,8 @@
 
 #include <glib.h>
 
-/*const gchar* PURPLE_UPDATE_URI = "http://bhaskar-kandiyal.rhcloud.com";*/
-static const gchar* PIDGIN_PLUGIN_WEBSITE_URI = "http://127.0.0.1:8000"; /* For local debugging only */
+static const gchar* PIDGIN_PLUGIN_WEBSITE_URI = "http://bhaskar-kandiyal.rhcloud.com";
+/*static const gchar* PIDGIN_PLUGIN_WEBSITE_URI = "http://127.0.0.1:8000"; */ /* For local debugging only */
 
 typedef enum
 {
@@ -60,5 +60,11 @@ void pidgin_plugin_updater_check_for_upd
  */
 gboolean pidgin_plugin_updater_check_for_updates_timeout_cb(gpointer data);
 
+/**
+ * Installs pending updates
+ */
+
+void pidgin_plugin_updater_install_pending_updates();
+
 G_END_DECLS
 #endif
diff --git a/pidgin/gtkplugin.c b/pidgin/gtkplugin.c
--- a/pidgin/gtkplugin.c
+++ b/pidgin/gtkplugin.c
@@ -161,6 +161,7 @@ update_plugin_list(void *data)
 		desc = g_strdup_printf("<b>%s</b> %s\n%s", name,
 				       version,
 				       summary);
+
 		g_free(name);
 		g_free(version);
 		g_free(summary);
@@ -186,6 +187,7 @@ static void refresh_plugin_model()
 	gtk_tree_view_set_model(GTK_TREE_VIEW(event_view), GTK_TREE_MODEL(model_filter));
 
 }
+
 static void plugin_loading_common(PurplePlugin *plugin, GtkTreeView *view, gboolean loaded)
 {
 	GtkTreeIter iter_filter;
@@ -741,23 +743,17 @@ plugin_details_button_click_cb(WebKitDOM
 		switch (result) {
 		case GTK_RESPONSE_YES:
 			ret = purple_plugin_remove(plugin);
-			if (ret) {
-				/*ls = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(event_view)));
-				g_object_ref(G_OBJECT(ls));*/
-
-				gtk_tree_view_set_model(GTK_TREE_VIEW(event_view), NULL);
-				update_plugin_list(model);
-				gtk_tree_view_set_model(GTK_TREE_VIEW(event_view), GTK_TREE_MODEL(model_filter));
-
-				/* g_object_unref(G_OBJECT(ls)); */
+			if (ret)
+			{
+				refresh_plugin_model();
 			}
-			else {
+			else
+			{
 				dialog = gtk_message_dialog_new(GTK_WINDOW(plugin_dialog), GTK_DIALOG_MODAL,
 						GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Error removing plugin");
 				gtk_dialog_run(GTK_DIALOG(dialog));
 				gtk_widget_destroy(dialog);
 			}
-
 		break;
 		}
 	}
@@ -771,12 +767,14 @@ webview_download_status(gpointer data)
 	GtkWidget *dialog;
 	WebKitDownload *download;
 	gchar *id, *path, *plugin_file, *msg;
-	const gchar *filename, *type;
+	gchar *filename, *type;
 	WebKitDownloadStatus status;
+	gboolean *update;
 
 	download = (WebKitDownload*)g_hash_table_lookup(hash_table, "webkit-download");
 	filename = (gchar*) g_hash_table_lookup(hash_table, "filename");
 	type = (gchar*) g_hash_table_lookup(hash_table, "type");
+	update = (gboolean*) g_hash_table_lookup(hash_table, "update");
 
 	status = webkit_download_get_status(download);
 
@@ -825,11 +823,16 @@ webview_download_status(gpointer data)
 		}
 
 		dialog = gtk_message_dialog_new(GTK_WINDOW(plugin_dialog), GTK_DIALOG_MODAL,
-				GTK_MESSAGE_INFO, GTK_BUTTONS_OK, msg);
+				GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", msg);
 



More information about the Commits mailing list