[evolution-rss] allow to select feed location from properties menu



commit 7d264518c2c6741e81842e7c4e6ba62f9f9a240b
Author: Lucian Langa <lucilanga gnome org>
Date:   Fri Jan 28 18:57:36 2011 +0200

    allow to select feed location from properties menu

 src/Makefile.am          |    3 +
 src/network-soup.c       |    4 ++
 src/parser.c             |    1 +
 src/rss-config-factory.c |   88 +++++++++++++++++++++++++++++++++++-
 src/rss-evo-common.c     |  111 ++++++++++++++++++++++++++++++++++++++++++++++
 src/rss-evo-common.h     |   36 +++++++++++++++
 src/rss.c                |   50 +++++++++++++-------
 src/rss.h                |    5 ++-
 8 files changed, 277 insertions(+), 21 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index a2c3af3..261e0f8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -80,6 +80,7 @@ SOURCES =	dbus.c			\
 		rss-cache.c		\
 		rss-config.c		\
 		rss-config-factory.c	\
+		rss-evo-common.c	\
 		rss-image.c		\
 		rss-icon-factory.c	\
 		rss-status-icon.c
@@ -188,6 +189,8 @@ EXTRA_DIST =					\
 	rss-config.h				\
 	rss-config-factory.c			\
 	rss-config-factory.h			\
+	rss-evo-common.c			\
+	rss-evo-common.h			\
 	rss-icon-factory.c			\
 	rss-icon-factory.h			\
 	rss-status-icon.c			\
diff --git a/src/network-soup.c b/src/network-soup.c
index 07e476a..3958a16 100644
--- a/src/network-soup.c
+++ b/src/network-soup.c
@@ -638,6 +638,7 @@ net_get_unblocking(gchar *url,
 	/* Queue an async HTTP request */
 	msg = soup_message_new ("GET", url);
 	if (!msg) {
+		g_free(info);
 		g_set_error(err, NET_ERROR, NET_ERROR_GENERIC, "%s",
 				soup_status_get_phrase(2));			//invalid url
 		return FALSE;
@@ -677,6 +678,8 @@ net_get_unblocking(gchar *url,
 ////	g_object_add_weak_pointer (G_OBJECT(msg), (gpointer)info);
 	g_object_weak_ref (G_OBJECT(msg), unblock_free, soup_sess);
 //	g_object_weak_ref (G_OBJECT(soup_sess), unblock_free, soup_sess);
+	if (mainurl)
+		g_free(mainurl);
 	return TRUE;
 }
 
@@ -729,6 +732,7 @@ download_unblocking(
 	/* Queue an async HTTP request */
 	msg = soup_message_new ("GET", url);
 	if (!msg) {
+		g_free(info);
 		g_set_error(err, NET_ERROR, NET_ERROR_GENERIC, "%s",
 				soup_status_get_phrase(2));			//invalid url
 		return FALSE;
diff --git a/src/parser.c b/src/parser.c
index 587efb9..7df0614 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -81,6 +81,7 @@ rss_html_url_decode(const char *html, int len)
 				(xmlNodePtr)doc,
 				(xmlChar *)"src",
 				(xmlChar *)duri);
+			xmlFree(url);
 		}
 	}
 	return src;
diff --git a/src/rss-config-factory.c b/src/rss-config-factory.c
index 2cdf56d..8098b43 100644
--- a/src/rss-config-factory.c
+++ b/src/rss-config-factory.c
@@ -46,7 +46,11 @@
 #include <e-util/e-alert-dialog.h>
 #include <misc/e-preferences-window.h>
 #include <mail/e-mail-local.h>
+#include <mail/em-folder-selector.h>
+
+#include <mail/em-utils.h>
 #include <shell/e-shell.h>
+#include <shell/e-shell-view.h>
 #endif
 
 
@@ -56,12 +60,14 @@
 #endif
 
 extern int rss_verbose_debug;
+extern EShellView *rss_shell_view;
 
 #include "rss.h"
 #include "misc.h"
 #include "parser.h"
 #include "rss-config.h"
 #include "rss-config-factory.h"
+#include "rss-evo-common.h"
 #include "network-soup.h"
 #include "notification.h"
 
@@ -411,6 +417,78 @@ disable_widget_cb(GtkWidget *widget, GtkBuilder *data)
 	gtk_widget_set_sensitive(authpass, auth_enabled);
 }
 
+void
+folder_cb (GtkWidget *widget, gpointer data);
+
+void
+folder_cb (GtkWidget *widget, gpointer data)
+{
+	CamelFolder *folder;
+	EMailBackend *backend;
+	EMailSession *session;
+	CamelFolderInfo *folderinfo;
+	GtkWidget *folder_tree;
+	GtkWidget *dialog;
+	GtkWindow *window;
+	const gchar *uri;
+	struct _copy_folder_data *cfd;
+
+	EMailReader *reader;
+	EShellContent *shell_content;
+
+	gchar *text = (gchar *)gtk_label_get_text(GTK_LABEL(data));
+
+	shell_content = e_shell_view_get_shell_content (rss_shell_view);
+	reader = E_MAIL_READER (shell_content);
+	backend = e_mail_reader_get_backend (reader);
+
+	session = e_mail_backend_get_session (backend);
+
+	folder = e_mail_reader_get_folder (reader);
+	window = e_mail_reader_get_window (reader);
+
+	folder_tree = em_folder_tree_new (session);
+	emu_restore_folder_tree_state (EM_FOLDER_TREE (folder_tree));
+
+	em_folder_tree_set_excluded (
+		EM_FOLDER_TREE (folder_tree),
+		EMFT_EXCLUDE_NOSELECT | EMFT_EXCLUDE_VIRTUAL |
+		EMFT_EXCLUDE_VTRASH);
+
+	dialog = em_folder_selector_new (
+			window, EM_FOLDER_TREE (folder_tree),
+			EM_FOLDER_SELECTOR_CAN_CREATE,
+			_("Move to Folder"), NULL, _("M_ove"));
+
+	if ((uri = lookup_uri_by_folder_name(text)))
+		em_folder_selector_set_selected (
+			EM_FOLDER_SELECTOR (dialog),
+			uri);
+
+	folderinfo = em_folder_tree_get_selected_folder_info ((EMFolderTree *)folder_tree);
+
+	cfd = g_malloc (sizeof (*cfd));
+	cfd->fi = folderinfo;
+	cfd->delete = 1;
+
+	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
+		gchar *tmp;
+		gchar *name = g_path_get_basename(text);
+		uri = em_folder_selector_get_selected_uri (
+			EM_FOLDER_SELECTOR (dialog));
+		rss_emfu_copy_folder_selected (backend, uri, cfd);
+		tmp = g_build_path(G_DIR_SEPARATOR_S,
+				em_utils_folder_name_from_uri(uri),
+				name, NULL);
+		g_free(name);
+		gtk_label_set_text(GTK_LABEL(data), tmp);
+		g_free(tmp);
+	}
+
+	gtk_widget_destroy (dialog);
+}
+
+
 add_feed *
 build_dialog_add(gchar *url, gchar *feed_text)
 {
@@ -520,6 +598,9 @@ build_dialog_add(gchar *url, gchar *feed_text)
 		location_button = GTK_WIDGET (gtk_builder_get_object(gui, "location_button"));
 
 		gtk_widget_show(location_button);
+		g_signal_connect (
+			GTK_BUTTON (location_button),
+			"clicked", G_CALLBACK (folder_cb), entry2);
 		location_label = GTK_WIDGET (
 			gtk_builder_get_object(gui,
 			"location_label"));
@@ -833,7 +914,8 @@ store_redraw(GtkTreeView *data)
 {
 	GtkTreeModel *model;
 
-	g_return_val_if_fail(data, FALSE);
+	if (!data)
+		return FALSE;
 
 	if (!store_redrawing) {
 		store_redrawing = 1;
@@ -1191,8 +1273,10 @@ delete_feed_folder_alloc(gchar *old_name)
 	feed_file = g_strdup_printf("%s/feed_folders", feed_dir);
 	g_free(feed_dir);
 	f = fopen(feed_file, "wb");
-	if (!f)
+	if (!f) {
+		g_free(feed_file);
 		return;
+	}
 
 	orig_name = g_hash_table_lookup(
 			rf->feed_folders,
diff --git a/src/rss-evo-common.c b/src/rss-evo-common.c
new file mode 100644
index 0000000..d6252d5
--- /dev/null
+++ b/src/rss-evo-common.c
@@ -0,0 +1,111 @@
+/* Evoution RSS Reader Plugin
+ * Copyright (C) 2011  Lucian Langa <lucilanga gnome org>
+ *
+ * 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  02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <mail/e-mail-local.h>
+#include <mail/e-mail-reader.h>
+#include <mail/em-folder-utils.h>
+
+#include "rss-evo-common.h"
+
+gboolean
+rss_emfu_is_special_local_folder (const gchar *name)
+{
+	return (!strcmp (name, "Drafts") || !strcmp (name, "Inbox") || !strcmp (name, "Outbox") || !strcmp (name, "Sent") || !strcmp (name, "Templates"));
+}
+
+void
+rss_emfu_copy_folder_selected (EMailBackend *backend,
+			const gchar *uri,
+			gpointer data)
+{
+	EMailSession *session;
+	struct _copy_folder_data *cfd = data;
+	CamelStore *fromstore = NULL, *tostore = NULL;
+	CamelStore *local_store;
+	const gchar *tobase = NULL;
+	CamelURL *url;
+	GError *local_error = NULL;
+
+	if (uri == NULL) {
+		g_free (cfd);
+		return;
+	}
+
+	local_store = e_mail_local_get_store ();
+	session = e_mail_backend_get_session (backend);
+
+	fromstore = camel_session_get_store (
+		CAMEL_SESSION (session), cfd->fi->uri, &local_error);
+	if (fromstore == NULL) {
+		e_mail_backend_submit_alert (
+			backend, cfd->delete ?
+				"mail:no-move-folder-notexist" :
+				"mail:no-copy-folder-notexist",
+			cfd->fi->full_name, uri,
+			local_error->message, NULL);
+		goto fail;
+	}
+
+	if (cfd->delete && fromstore == local_store && rss_emfu_is_special_local_folder (cfd->fi->full_name)) {
+		e_mail_backend_submit_alert (
+			backend, "mail:no-rename-special-folder",
+			cfd->fi->full_name, NULL);
+		goto fail;
+	}
+
+	tostore = camel_session_get_store (
+		CAMEL_SESSION (session), uri, &local_error);
+	if (tostore == NULL) {
+		e_mail_backend_submit_alert (
+			backend, cfd->delete ?
+				"mail:no-move-folder-to-notexist" :
+				"mail:no-copy-folder-to-notexist",
+			cfd->fi->full_name, uri,
+			local_error->message, NULL);
+		goto fail;
+	}
+
+	url = camel_url_new (uri, NULL);
+	if (((CamelService *)tostore)->provider->url_flags & CAMEL_URL_FRAGMENT_IS_PATH)
+		tobase = url->fragment;
+	else if (url->path && url->path[0])
+		tobase = url->path+1;
+	if (tobase == NULL)
+		tobase = "";
+
+	em_folder_utils_copy_folders (
+		fromstore, cfd->fi->full_name, tostore, tobase, cfd->delete);
+
+	camel_url_free (url);
+fail:
+	if (fromstore)
+		g_object_unref (fromstore);
+	if (tostore)
+		g_object_unref (tostore);
+
+	g_clear_error (&local_error);
+
+	g_free (cfd);
+}
+
diff --git a/src/rss-evo-common.h b/src/rss-evo-common.h
new file mode 100644
index 0000000..d55a720
--- /dev/null
+++ b/src/rss-evo-common.h
@@ -0,0 +1,36 @@
+/* Evoution RSS Reader Plugin
+ * Copyright (C) 2011  Lucian Langa <lucilanga gnome org>
+ *
+ * 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  02110-1301, USA.
+ */
+
+#ifndef __RSS_EVO_COMMON_H_
+#define __RSS_EVO_COMMON_H_
+
+struct _copy_folder_data {
+	CamelFolderInfo *fi;
+	gboolean delete;
+};
+
+gboolean
+rss_emfu_is_special_local_folder (const gchar *name);
+
+void
+rss_emfu_copy_folder_selected (EMailBackend *backend,
+		const gchar *uri,
+		gpointer data);
+
+#endif /*__RSS_EVO_COMMON_H_*/
+
diff --git a/src/rss.c b/src/rss.c
index e159b9a..41126a6 100644
--- a/src/rss.c
+++ b/src/rss.c
@@ -916,8 +916,6 @@ rss_select_folder(gchar *folder_name)
 	const
 #endif
 	gchar *uri;
-	CamelStore *store;
-	CamelFolder *fold = NULL;
 	EShellSidebar *shell_sidebar;
 
 	d("rss_select_folder() %s:%d\n", __FILE__, __LINE__);
@@ -926,22 +924,12 @@ rss_select_folder(gchar *folder_name)
 
 	shell_sidebar  = e_shell_view_get_shell_sidebar(rss_shell_view);
 	g_object_get (shell_sidebar, "folder-tree", &folder_tree, NULL);
-	store = rss_component_peek_local_store();
-#if (DATASERVER_VERSION >= 2033001)
-	fold = camel_store_get_folder_sync (store, folder_name, 0, NULL, NULL);
-#else
-	fold = camel_store_get_folder (store, folder_name, 0, NULL);
-#endif
-	if (!fold) return;
-#if EVOLUTION_VERSION >= 29101
-	uri = camel_folder_get_uri (fold);
-#else
-	uri = mail_tools_folder_to_url (fold);
-#endif
+
+	uri = lookup_uri_by_folder_name(folder_name);
 	em_folder_tree_set_selected(folder_tree, uri, 0);
 #endif
 #if EVOLUTION_VERSION < 29101
-	g_free(uri);
+	if (uri) g_free(uri);
 #endif
 #if 0 //kb//
 	CamelStore *store = rss_component_peek_local_store();
@@ -3794,6 +3782,7 @@ print_comments(gchar *url, gchar *stream, EMFormatHTML *format)
 
 			return display_comments (r, format);
 	}
+	g_free(r);
 	return NULL;
 }
 
@@ -3953,6 +3942,30 @@ lookup_chn_name_by_url(gchar *url)
 	return chn_name;
 }
 
+gchar *
+lookup_uri_by_folder_name(gchar *name)
+{
+	CamelFolder *folder;
+	gchar *uri;
+	CamelStore *store = rss_component_peek_local_store();
+
+	if (!name)
+		return NULL;
+
+#if (DATASERVER_VERSION >= 2033001)
+	folder = camel_store_get_folder_sync (store, name, 0, NULL, NULL);
+#else
+	folder = camel_store_get_folder (store, name, 0, NULL);
+#endif
+	if (!folder) return NULL;
+#if EVOLUTION_VERSION >= 29101
+	uri = (gchar *)camel_folder_get_uri (folder);
+#else
+	uri = mail_tools_folder_to_url (folder);
+#endif
+	return uri;
+}
+
 void
 update_main_folder(gchar *new_name)
 {
@@ -4016,6 +4029,7 @@ search_rebase(gpointer key, gpointer value, gchar *oname)
 	if (!strncmp(key, tmp, strlen(tmp))) {
 		rebase_keys = g_list_append(rebase_keys, key);
 	}
+	g_free(tmp);
 }
 
 void
@@ -4052,7 +4066,7 @@ sync_folders(void)
 	g_free(feed_dir);
 	f = fopen(feed_file, "wb");
 	if (!f)
-		return;
+		goto out;
 
 	if (!g_hash_table_size(rf->feed_folders))
 		goto exit;
@@ -4060,7 +4074,6 @@ sync_folders(void)
 	g_hash_table_foreach(rf->feed_folders,
 		(GHFunc)write_feeds_folder_line,
 		(gpointer *)f);
-	g_free(feed_file);
 	g_hash_table_destroy(rf->reversed_feed_folders);
 	rf->reversed_feed_folders = g_hash_table_new_full(g_str_hash,
 			g_str_equal,
@@ -4070,6 +4083,7 @@ sync_folders(void)
 			(GHFunc)populate_reversed,
 			rf->reversed_feed_folders);
 exit:	fclose(f);
+out:	g_free(feed_file);
 	return;
 }
 
@@ -4850,7 +4864,7 @@ e_plugin_ui_init (GtkUIManager *ui_manager,
 
 	rss_shell_view = shell_view;
 	shell_window = e_shell_view_get_shell_window (rss_shell_view);
-	evo_window = shell_window;
+	evo_window = (GtkWidget *)shell_window;
 	g_signal_connect (
 		e_shell_window_get_action (
 			E_SHELL_WINDOW (shell_window),
diff --git a/src/rss.h b/src/rss.h
index 64c62f2..2c77a53 100644
--- a/src/rss.h
+++ b/src/rss.h
@@ -404,13 +404,16 @@ void rss_error(
 	gchar *emsg);
 void rss_hooks_init(void);
 void rss_select_folder(gchar *folder_name);
-gchar *lookup_chn_name_by_url(gchar *url);
 gboolean update_articles(gboolean disabler);
+
+gchar *lookup_chn_name_by_url(gchar *url);
 gchar *lookup_main_folder(void);
 gchar *lookup_feed_folder(gchar *folder);
 gchar *lookup_original_folder(
 	gchar *folder,
 	gboolean *found);
+gchar *lookup_uri_by_folder_name(gchar *name);
+
 gchar *decode_utf8_entities(gchar *str);
 gchar *decode_html_entities(gchar *str);
 gchar *get_real_channel_name(gchar *uri, gchar *failed);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]