[evolution] Bug 633172 - Folder->Subscriptions is always enabled



commit 43814fe77518e97c6b9c9ecb1d499dc3eb323296
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Oct 29 19:54:45 2010 -0400

    Bug 633172 - Folder->Subscriptions is always enabled

 doc/reference/shell/eshell-sections.txt       |    1 +
 doc/reference/shell/tmpl/e-account-utils.sgml |    9 ++++
 e-util/e-account-utils.c                      |   55 ++++++++++++++++++++++++-
 e-util/e-account-utils.h                      |    2 +
 mail/em-subscription-editor.c                 |   30 ++++++-------
 modules/mail/e-mail-shell-view.c              |   19 ++++++--
 6 files changed, 94 insertions(+), 22 deletions(-)
---
diff --git a/doc/reference/shell/eshell-sections.txt b/doc/reference/shell/eshell-sections.txt
index 63a8578..6e03f4d 100644
--- a/doc/reference/shell/eshell-sections.txt
+++ b/doc/reference/shell/eshell-sections.txt
@@ -439,6 +439,7 @@ e_get_account_by_source_url
 e_get_account_by_transport_url
 e_get_any_enabled_account
 e_get_default_transport
+e_get_subscribable_accounts
 </SECTION>
 
 <SECTION>
diff --git a/doc/reference/shell/tmpl/e-account-utils.sgml b/doc/reference/shell/tmpl/e-account-utils.sgml
index afce2e7..dae48fd 100644
--- a/doc/reference/shell/tmpl/e-account-utils.sgml
+++ b/doc/reference/shell/tmpl/e-account-utils.sgml
@@ -100,3 +100,12 @@ Mail Accounts
 @Returns: 
 
 
+<!-- ##### FUNCTION e_get_subscribable_accounts ##### -->
+<para>
+
+</para>
+
+ session: 
+ Returns: 
+
+
diff --git a/e-util/e-account-utils.c b/e-util/e-account-utils.c
index 1590c98..df93fa2 100644
--- a/e-util/e-account-utils.c
+++ b/e-util/e-account-utils.c
@@ -22,7 +22,6 @@
 
 #include "e-account-utils.h"
 
-#include <camel/camel.h>
 #include <gconf/gconf-client.h>
 
 static EAccountList *global_account_list;
@@ -355,3 +354,57 @@ e_get_default_transport (void)
 
 	return NULL;
 }
+
+/**
+ * e_get_subscribable_accounts:
+ * @session: a #CamelSession
+ *
+ * Returns a list of enabled accounts that support folder subscriptions.
+ * The #EAccount objects are not referenced, but the list itself should
+ * be should be freed with g_list_free().
+ *
+ * Returns: a list of #EAccount objects
+ **/
+GList *
+e_get_subscribable_accounts (CamelSession *session)
+{
+	EAccountList *account_list;
+	EAccount *account;
+	EIterator *iterator;
+	GList *subscribable = NULL;
+
+	g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
+
+	account_list = e_get_account_list ();
+	iterator = e_list_get_iterator (E_LIST (account_list));
+
+	while (e_iterator_is_valid (iterator)) {
+		CamelStore *store = NULL;
+
+		/* XXX EIterator misuses const. */
+		account = (EAccount *) e_iterator_get (iterator);
+
+		if (account->enabled) {
+			const gchar *url;
+
+			url = e_account_get_string (
+				account, E_ACCOUNT_SOURCE_URL);
+			store = (CamelStore *) camel_session_get_service (
+				session, url, CAMEL_PROVIDER_STORE, NULL);
+		}
+
+		e_iterator_next (iterator);
+
+		if (store == NULL)
+			continue;
+
+		if (!camel_store_supports_subscriptions (store))
+			continue;
+
+		subscribable = g_list_prepend (subscribable, account);
+	}
+
+	g_object_unref (iterator);
+
+	return g_list_reverse (subscribable);
+}
diff --git a/e-util/e-account-utils.h b/e-util/e-account-utils.h
index 0f3fbcb..57ca840 100644
--- a/e-util/e-account-utils.h
+++ b/e-util/e-account-utils.h
@@ -18,6 +18,7 @@
 #ifndef E_ACCOUNT_UTILS_H
 #define E_ACCOUNT_UTILS_H
 
+#include <camel/camel.h>
 #include <libedataserver/e-account.h>
 #include <libedataserver/e-account-list.h>
 
@@ -33,6 +34,7 @@ EAccount *	e_get_account_by_transport_url	(const gchar *transport_url);
 EAccount *	e_get_any_enabled_account	(void);
 EAccountService *
 		e_get_default_transport		(void);
+GList *		e_get_subscribable_accounts	(CamelSession *session);
 
 G_END_DECLS
 
diff --git a/mail/em-subscription-editor.c b/mail/em-subscription-editor.c
index e34a924..c040daf 100644
--- a/mail/em-subscription-editor.c
+++ b/mail/em-subscription-editor.c
@@ -1044,32 +1044,30 @@ static void
 subscription_editor_realize (GtkWidget *widget)
 {
 	EMSubscriptionEditor *editor;
-	EAccountList *account_list;
-	EIterator *account_iter;
 	GtkComboBox *combo_box;
+	CamelSession *session;
+	GList *list, *iter;
 	gint initial_index = 0;
 
 	editor = EM_SUBSCRIPTION_EDITOR (widget);
+	session = em_subscription_editor_get_session (editor);
 
 	/* Chain up to parent's realize() method. */
 	GTK_WIDGET_CLASS (em_subscription_editor_parent_class)->realize (widget);
 
 	/* Find accounts to display, and watch for the default account. */
-	account_list = e_get_account_list ();
-	account_iter = e_list_get_iterator (E_LIST (account_list));
-	while (e_iterator_is_valid (account_iter)) {
-		EAccount *account;
-
-		/* XXX EIterator misuses const. */
-		account = (EAccount *) e_iterator_get (account_iter);
-		if (subscription_editor_test_account (editor, account)) {
-			if (account == editor->priv->initial_account)
-				initial_index = editor->priv->stores->len;
-			subscription_editor_add_account (editor, account);
-		}
-		e_iterator_next (account_iter);
+	list = e_get_subscribable_accounts (session);
+	for (iter = list; iter != NULL; iter = g_list_next (iter)) {
+		EAccount *account = E_ACCOUNT (iter->data);
+		if (account == editor->priv->initial_account)
+			initial_index = editor->priv->stores->len;
+		subscription_editor_add_account (editor, account);
 	}
-	g_object_unref (account_iter);
+	g_list_free (list);
+
+	/* The subscription editor should only be accessible if
+	 * at least one enabled account supports subscriptions. */
+	g_return_if_fail (editor->priv->stores->len > 0);
 
 	combo_box = GTK_COMBO_BOX (editor->priv->combo_box);
 	gtk_combo_box_set_active (combo_box, initial_index);
diff --git a/modules/mail/e-mail-shell-view.c b/modules/mail/e-mail-shell-view.c
index 8d5a568..0484a56 100644
--- a/modules/mail/e-mail-shell-view.c
+++ b/modules/mail/e-mail-shell-view.c
@@ -834,13 +834,17 @@ mail_shell_view_update_actions (EShellView *shell_view)
 	EMailShellView *mail_shell_view;
 	EMailShellContent *mail_shell_content;
 	EMailShellSidebar *mail_shell_sidebar;
+	EShellBackend *shell_backend;
 	EShellSidebar *shell_sidebar;
 	EShellWindow *shell_window;
 	EMFolderTree *folder_tree;
 	EMailReader *reader;
+	EMailBackend *backend;
+	EMailSession *session;
 	EMailView *mail_view;
 	EAccount *account = NULL;
 	GtkAction *action;
+	GList *list;
 	const gchar *label;
 	gchar *uri;
 	gboolean sensitive;
@@ -856,7 +860,7 @@ mail_shell_view_update_actions (EShellView *shell_view)
 	gboolean folder_has_unread_rec = FALSE;
 	gboolean folder_tree_and_message_list_agree = TRUE;
 	gboolean store_supports_subscriptions;
-	gboolean have_enabled_account;
+	gboolean any_account_supports_subscriptions;
 
 	/* Chain up to parent's update_actions() method. */
 	E_SHELL_VIEW_CLASS (parent_class)->update_actions (shell_view);
@@ -864,17 +868,18 @@ mail_shell_view_update_actions (EShellView *shell_view)
 	mail_shell_view = E_MAIL_SHELL_VIEW (shell_view);
 
 	shell_window = e_shell_view_get_shell_window (shell_view);
+	shell_backend = e_shell_view_get_shell_backend (shell_view);
 
 	mail_shell_content = mail_shell_view->priv->mail_shell_content;
 	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
 
+	backend = E_MAIL_BACKEND (shell_backend);
+	session = e_mail_backend_get_session (backend);
+
 	reader = E_MAIL_READER (mail_view);
 	state = e_mail_reader_check_state (reader);
 	e_mail_reader_update_actions (reader, state);
 
-	have_enabled_account =
-		(state & E_MAIL_READER_HAVE_ENABLED_ACCOUNT);
-
 	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
 	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
 
@@ -937,6 +942,10 @@ mail_shell_view_update_actions (EShellView *shell_view)
 		g_free (uri);
 	}
 
+	list = e_get_subscribable_accounts (CAMEL_SESSION (session));
+	any_account_supports_subscriptions = (g_list_length (list) > 0);
+	g_list_free (list);
+
 	action = ACTION (MAIL_ACCOUNT_DISABLE);
 	sensitive = (account != NULL) && folder_is_store;
 	if (account_is_groupwise)
@@ -1007,7 +1016,7 @@ mail_shell_view_update_actions (EShellView *shell_view)
 	gtk_action_set_sensitive (action, sensitive);
 
 	action = ACTION (MAIL_TOOLS_SUBSCRIPTIONS);
-	sensitive = have_enabled_account;
+	sensitive = any_account_supports_subscriptions;
 	gtk_action_set_sensitive (action, sensitive);
 
 	e_mail_shell_view_update_popup_labels (mail_shell_view);



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