aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2009-10-28 04:18:01 +0800
committerMilan Crha <mcrha@redhat.com>2009-10-28 04:18:01 +0800
commit9b4c2438652f02d045c58ec2f41b0592a6d26219 (patch)
tree0561364fe46b1798bc956e36b9839852093899a5
parentd8b3127abda28009b5c9e97b0e5df9699316f968 (diff)
downloadgsoc2013-evolution-9b4c2438652f02d045c58ec2f41b0592a6d26219.tar
gsoc2013-evolution-9b4c2438652f02d045c58ec2f41b0592a6d26219.tar.gz
gsoc2013-evolution-9b4c2438652f02d045c58ec2f41b0592a6d26219.tar.bz2
gsoc2013-evolution-9b4c2438652f02d045c58ec2f41b0592a6d26219.tar.lz
gsoc2013-evolution-9b4c2438652f02d045c58ec2f41b0592a6d26219.tar.xz
gsoc2013-evolution-9b4c2438652f02d045c58ec2f41b0592a6d26219.tar.zst
gsoc2013-evolution-9b4c2438652f02d045c58ec2f41b0592a6d26219.zip
Bug #550049 - Disable Mark messages as read actions when unusable
-rw-r--r--modules/mail/e-mail-shell-view-actions.h4
-rw-r--r--modules/mail/e-mail-shell-view.c68
-rw-r--r--plugins/mark-all-read/mark-all-read.c96
3 files changed, 165 insertions, 3 deletions
diff --git a/modules/mail/e-mail-shell-view-actions.h b/modules/mail/e-mail-shell-view-actions.h
index 99819f000e..6ae2e24a95 100644
--- a/modules/mail/e-mail-shell-view-actions.h
+++ b/modules/mail/e-mail-shell-view-actions.h
@@ -71,8 +71,8 @@
E_SHELL_WINDOW_ACTION ((window), "mail-folder-delete")
#define E_SHELL_WINDOW_ACTION_MAIL_FOLDER_EXPUNGE(window) \
E_SHELL_WINDOW_ACTION ((window), "mail-folder-expunge")
-#define E_SHELL_WINDOW_ACTION_MAIL_FOLDER_MARK_ALL_READ(window) \
- E_SHELL_WINDOW_ACTION ((window), "mail-folder-mark-all-read")
+#define E_SHELL_WINDOW_ACTION_MAIL_FOLDER_MARK_ALL_AS_READ(window) \
+ E_SHELL_WINDOW_ACTION ((window), "mail-folder-mark-all-as-read")
#define E_SHELL_WINDOW_ACTION_MAIL_FOLDER_MOVE(window) \
E_SHELL_WINDOW_ACTION ((window), "mail-folder-move")
#define E_SHELL_WINDOW_ACTION_MAIL_FOLDER_NEW(window) \
diff --git a/modules/mail/e-mail-shell-view.c b/modules/mail/e-mail-shell-view.c
index 3c82e516bc..d331c080ed 100644
--- a/modules/mail/e-mail-shell-view.c
+++ b/modules/mail/e-mail-shell-view.c
@@ -348,6 +348,54 @@ filter:
}
static void
+has_unread_mail (GtkTreeModel *model, GtkTreeIter *parent, gboolean is_root, gboolean *has_unread)
+{
+ guint unread = 0;
+ GtkTreeIter iter, child;
+
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (parent != NULL);
+ g_return_if_fail (has_unread != NULL);
+
+ if (is_root) {
+ gboolean is_store = FALSE, is_draft = FALSE;
+
+ gtk_tree_model_get (model, parent,
+ COL_UINT_UNREAD, &unread,
+ COL_BOOL_IS_STORE, &is_store,
+ COL_BOOL_IS_DRAFT, &is_draft,
+ -1);
+
+ if (is_draft || is_store) {
+ *has_unread = FALSE;
+ return;
+ }
+
+ *has_unread = *has_unread || (unread > 0 && unread != ~((guint)0));
+
+ if (*has_unread)
+ return;
+
+ if (!gtk_tree_model_iter_children (model, &iter, parent))
+ return;
+ } else {
+ iter = *parent;
+ }
+
+ do {
+ gtk_tree_model_get (model, &iter, COL_UINT_UNREAD, &unread, -1);
+
+ *has_unread = *has_unread || (unread > 0 && unread != ~((guint)0));
+ if (*has_unread)
+ break;
+
+ if (gtk_tree_model_iter_children (model, &child, &iter))
+ has_unread_mail (model, &child, FALSE, has_unread);
+
+ } while (gtk_tree_model_iter_next (model, &iter) && !*has_unread);
+}
+
+static void
mail_shell_view_update_actions (EShellView *shell_view)
{
EMailShellView *mail_shell_view;
@@ -371,6 +419,7 @@ mail_shell_view_update_actions (EShellView *shell_view)
gboolean folder_is_outbox;
gboolean folder_is_store;
gboolean folder_is_trash;
+ gboolean folder_has_unread_rec = FALSE;
mail_shell_view = E_MAIL_SHELL_VIEW (shell_view);
@@ -400,6 +449,8 @@ mail_shell_view_update_actions (EShellView *shell_view)
uri = em_folder_tree_get_selected_uri (folder_tree);
if (uri != NULL) {
+ EMFolderTreeModel *model;
+
account = mail_config_get_account_by_source_url (uri);
/* FIXME This belongs in a GroupWise plugin. */
@@ -407,6 +458,19 @@ mail_shell_view_update_actions (EShellView *shell_view)
(g_strrstr (uri, "groupwise://") != NULL) &&
account != NULL && account->parent_uid != NULL;
+ model = em_folder_tree_model_get_default ();
+ if (model) {
+ GtkTreeRowReference *reference = em_folder_tree_model_lookup_uri (model, uri);
+ if (reference != NULL) {
+ GtkTreePath *path = gtk_tree_row_reference_get_path (reference);
+ GtkTreeIter iter;
+
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path);
+ has_unread_mail (GTK_TREE_MODEL (model), &iter, TRUE, &folder_has_unread_rec);
+ gtk_tree_path_free (path);
+ }
+ }
+
g_free (uri);
}
@@ -459,6 +523,10 @@ mail_shell_view_update_actions (EShellView *shell_view)
sensitive = !folder_is_store && folder_can_be_deleted;
gtk_action_set_sensitive (action, sensitive);
+ action = ACTION (MAIL_FOLDER_MARK_ALL_AS_READ);
+ sensitive = folder_has_unread_rec && !folder_is_store;
+ gtk_action_set_sensitive (action, sensitive);
+
e_mail_shell_view_update_popup_labels (mail_shell_view);
}
diff --git a/plugins/mark-all-read/mark-all-read.c b/plugins/mark-all-read/mark-all-read.c
index dacb5e5685..008cc5a78d 100644
--- a/plugins/mark-all-read/mark-all-read.c
+++ b/plugins/mark-all-read/mark-all-read.c
@@ -272,12 +272,57 @@ mar_all_sub_folders (CamelStore *store, CamelFolderInfo *fi, CamelException *ex)
}
static void
+has_unread_mail (GtkTreeModel *model, GtkTreeIter *parent, gboolean is_root, gboolean *has_unread, gboolean *applicable)
+{
+ guint unread = 0;
+ GtkTreeIter iter, child;
+
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (parent != NULL);
+ g_return_if_fail (has_unread != NULL);
+ g_return_if_fail (applicable != NULL);
+
+ if (is_root) {
+ gboolean is_draft = FALSE, is_store = FALSE;
+
+ gtk_tree_model_get (model, parent,
+ COL_UINT_UNREAD, &unread,
+ COL_BOOL_IS_STORE, &is_store,
+ COL_BOOL_IS_DRAFT, &is_draft,
+ -1);
+
+ *has_unread = *has_unread || (unread > 0 && unread != ~((guint)0));
+ *applicable = !is_store && !is_draft;
+
+ if (*has_unread)
+ return;
+
+ if (!gtk_tree_model_iter_children (model, &iter, parent))
+ return;
+ } else {
+ iter = *parent;
+ }
+
+ do {
+ gtk_tree_model_get (model, &iter, COL_UINT_UNREAD, &unread, -1);
+
+ *has_unread = *has_unread || (unread > 0 && unread != ~((guint)0));
+ if (*has_unread)
+ break;
+
+ if (gtk_tree_model_iter_children (model, &child, &iter))
+ has_unread_mail (model, &child, FALSE, has_unread, applicable);
+
+ } while (gtk_tree_model_iter_next (model, &iter) && !*has_unread);
+}
+
+static void
action_mail_mark_read_recursive_cb (GtkAction *action,
EShellView *shell_view)
{
EShellSidebar *shell_sidebar;
EMFolderTree *folder_tree;
- const gchar *folder_uri;
+ gchar *folder_uri;
shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
g_object_get (shell_sidebar, "folder-tree", &folder_tree, NULL);
@@ -287,6 +332,7 @@ action_mail_mark_read_recursive_cb (GtkAction *action,
mail_get_folder (
folder_uri, 0, mar_got_folder, NULL, mail_msg_unordered_push);
+ g_free (folder_uri);
g_object_unref (folder_tree);
}
@@ -300,6 +346,52 @@ static GtkActionEntry entries[] = {
G_CALLBACK (action_mail_mark_read_recursive_cb) }
};
+static void
+update_actions_cb (EShellView *shell_view, gpointer user_data)
+{
+ GtkActionGroup *action_group;
+ EShellWindow *shell_window;
+ GtkAction *action;
+ EShellSidebar *shell_sidebar;
+ EMFolderTree *folder_tree;
+ gchar *folder_uri;
+ gboolean has_unread = FALSE, applicable = FALSE;
+
+ g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
+
+ shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
+ g_object_get (shell_sidebar, "folder-tree", &folder_tree, NULL);
+ folder_uri = em_folder_tree_get_selected_uri (folder_tree);
+
+ if (folder_uri != NULL) {
+ EMFolderTreeModel *model;
+
+ model = em_folder_tree_model_get_default ();
+ if (model) {
+ GtkTreeRowReference *reference = em_folder_tree_model_lookup_uri (model, folder_uri);
+ if (reference != NULL) {
+ GtkTreePath *path = gtk_tree_row_reference_get_path (reference);
+ GtkTreeIter iter;
+
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path);
+ has_unread_mail (GTK_TREE_MODEL (model), &iter, TRUE, &has_unread, &applicable);
+ gtk_tree_path_free (path);
+ }
+ }
+ }
+
+ shell_window = e_shell_view_get_shell_window (shell_view);
+ action_group = e_shell_window_get_action_group (shell_window, "mail");
+
+ action = gtk_action_group_get_action (action_group, entries[0].name);
+ g_return_if_fail (action != NULL);
+
+ gtk_action_set_sensitive (action, has_unread && applicable);
+
+ g_free (folder_uri);
+ g_object_unref (folder_tree);
+}
+
gboolean
e_plugin_ui_init (GtkUIManager *ui_manager,
EShellView *shell_view)
@@ -315,5 +407,7 @@ e_plugin_ui_init (GtkUIManager *ui_manager,
action_group, entries,
G_N_ELEMENTS (entries), shell_view);
+ g_signal_connect (shell_view, "update-actions", G_CALLBACK (update_actions_cb), NULL);
+
return TRUE;
}