From 70fa4a0868f12a18dbc9ba164ada94e6a0ebc799 Mon Sep 17 00:00:00 2001 From: Chenthill Palanisamy Date: Thu, 19 May 2005 17:32:41 +0000 Subject: Plugin file to add the Mark all Messages read menu item. Contains methods 2005-05-19 Chenthill Palanisamy * MakeFile.am: * org-gnome-send-options.eplug.in: Plugin file to add the Mark all Messages read menu item. * send-options.c: Contains methods to mark messages as read. svn path=/trunk/; revision=29391 --- plugins/mark-all-read/ChangeLog | 7 ++ plugins/mark-all-read/Makefile.am | 14 +++ plugins/mark-all-read/mark-all-read.c | 122 +++++++++++++++++++++ .../mark-all-read/org-gnome-mark-all-read.eplug.in | 15 +++ 4 files changed, 158 insertions(+) create mode 100644 plugins/mark-all-read/ChangeLog create mode 100644 plugins/mark-all-read/Makefile.am create mode 100644 plugins/mark-all-read/mark-all-read.c create mode 100644 plugins/mark-all-read/org-gnome-mark-all-read.eplug.in diff --git a/plugins/mark-all-read/ChangeLog b/plugins/mark-all-read/ChangeLog new file mode 100644 index 0000000000..72de624d25 --- /dev/null +++ b/plugins/mark-all-read/ChangeLog @@ -0,0 +1,7 @@ +2005-05-19 Chenthill Palanisamy + + * MakeFile.am: + * org-gnome-send-options.eplug.in: Plugin file to add + the Mark all Messages read menu item. + * send-options.c: Contains methods to mark messages as read. + diff --git a/plugins/mark-all-read/Makefile.am b/plugins/mark-all-read/Makefile.am new file mode 100644 index 0000000000..d560bdb015 --- /dev/null +++ b/plugins/mark-all-read/Makefile.am @@ -0,0 +1,14 @@ +INCLUDES = \ + -I$(top_srcdir)\ + -I$(top_srcdir)/camel \ + $(EVOLUTION_MAIL_CFLAGS) + +@EVO_PLUGIN_RULE@ + +plugin_DATA = org-gnome-mark-all-read.eplug +plugin_LTLIBRARIES = liborg-gnome-mark-all-read.la + +liborg_gnome_mark_all_read_la_SOURCES = mark-all-read.c +liborg_gnome_mark_all_read_la_LDFLAGS = -module -avoid-version + +EXTRA_DIST = org-gnome-mark-all-read.eplug.in diff --git a/plugins/mark-all-read/mark-all-read.c b/plugins/mark-all-read/mark-all-read.c new file mode 100644 index 0000000000..fc4c558b0e --- /dev/null +++ b/plugins/mark-all-read/mark-all-read.c @@ -0,0 +1,122 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Authors: Chenthill Palanisamy (pchenthill@novell.com) + * + * Copyright 2004 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "e-util/e-error.h" + +void org_gnome_mark_all_read (EPlugin *ep, EMPopupTargetFolder *target); +static void mar_got_folder (char *uri, CamelFolder *folder, void *data); +static void mar_all_sub_folders (CamelStore *store, CamelFolderInfo *fi, CamelException *ex); + +void +org_gnome_mark_all_read (EPlugin *ep, EMPopupTargetFolder *t) +{ + if (t->uri == NULL) { + return; + } + + mail_get_folder(t->uri, 0, mar_got_folder, NULL, mail_thread_new); +} + +static void +mark_all_as_read (CamelFolder *folder) +{ + GPtrArray *uids; + int i; + + uids = camel_folder_get_uids (folder); + camel_folder_freeze(folder); + for (i=0;ilen;i++) + camel_folder_set_message_flags(folder, uids->pdata[i], CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN); + camel_folder_thaw(folder); + camel_folder_free_uids (folder, uids); +} + +static void +mar_got_folder (char *uri, CamelFolder *folder, void *data) +{ + CamelFolderInfo *info; + CamelStore *store; + CamelException ex; + gint response; + guint32 flags = CAMEL_STORE_FOLDER_INFO_RECURSIVE | CAMEL_STORE_FOLDER_INFO_FAST; + + camel_exception_init (&ex); + store = folder->parent_store; + info = camel_store_get_folder_info (store, folder->full_name, flags, &ex); + + /* FIXME we have to disable the menu item */ + if (!folder) + return; + + if (camel_exception_is_set (&ex)) { + camel_exception_clear (&ex); + return; + } + + if (info && (info->child || info->next)) { + response = e_error_run (NULL, "mail:ask-mark-read", NULL); + } else { + mark_all_as_read (folder); + return; + } + + if (response == GTK_RESPONSE_NO) { + mark_all_as_read (folder); + } else if (response == GTK_RESPONSE_YES){ + mar_all_sub_folders (store, info, &ex); + } + +} + +static void +mar_all_sub_folders (CamelStore *store, CamelFolderInfo *fi, CamelException *ex) +{ + while (fi) { + CamelFolder *folder; + + if (fi->child) { + mar_all_sub_folders (store, fi->child, ex); + if (camel_exception_is_set (ex)) + return; + } + + if (!(folder = camel_store_get_folder (store, fi->full_name, 0, ex))) + return; + + if (!CAMEL_IS_VEE_FOLDER (folder)) { + mark_all_as_read (folder); + } + + fi = fi->next; + } +} diff --git a/plugins/mark-all-read/org-gnome-mark-all-read.eplug.in b/plugins/mark-all-read/org-gnome-mark-all-read.eplug.in new file mode 100644 index 0000000000..d749a3e3fe --- /dev/null +++ b/plugins/mark-all-read/org-gnome-mark-all-read.eplug.in @@ -0,0 +1,15 @@ + + + + Used for marking all the messages under a folder as read + + + + + + + + -- cgit v1.2.3