aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mail/ChangeLog13
-rw-r--r--mail/mail-summary.c218
2 files changed, 179 insertions, 52 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 8007565e7b..963e3e6cb3 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,16 @@
+2000-10-08 Iain Holmes <iain@helixcode.com>
+
+ * mail-summary.c (create_summary_view): Updated to use new icon code.
+
+2000-10-08 Iain Holmes <iain@helixcode.com>
+
+ * mail-summary.c (generate_html_summary): Generic function to
+ recreate the HTML of the summary. Checks all the folder summaries.
+ (generate_folder_summarys): Create a summary of all the vfolders
+ and the Inbox.
+ (create_summary_view): Generate the folder summarys before the
+ HTML.
+
2000-10-09 Ettore Perazzoli <ettore@helixcode.com>
* folder-browser.c: Don't #include "mail-search-dialogue.h" as
diff --git a/mail/mail-summary.c b/mail/mail-summary.c
index e670057ad8..9b9b941bf1 100644
--- a/mail/mail-summary.c
+++ b/mail/mail-summary.c
@@ -32,16 +32,31 @@
#include "mail.h" /* YUCK FIXME */
#include "mail-tools.h"
#include "mail-ops.h"
+#include "mail-vfolder.h"
+
+#include "Evolution.h"
+#include "evolution-storage.h"
#include "mail-local-storage.h"
+#include "filter/vfolder-context.h"
+
#include <executive-summary/evolution-services/executive-summary-component.h>
typedef struct {
- ExecutiveSummaryComponent *component;
CamelFolder *folder;
-
- int mail, unread;
+
+ char *name;
+ int total, unread;
+} FolderSummary;
+
+typedef struct {
+ ExecutiveSummaryComponent *component;
+
+ GHashTable *folder_to_summary;
+ FolderSummary **folders;
+ int numfolders;
+
char *html;
} MailSummary;
@@ -50,6 +65,8 @@ typedef struct {
static int queue_len = 0;
+extern char *evolution_dir;
+
#define MAIN_READER main_compipe[0]
#define MAIN_WRITER main_compipe[1]
#define DISPATCH_READER dispatch_compipe[0]
@@ -62,6 +79,7 @@ GIOChannel *summary_chan_reader = NULL;
static void do_changed (MailSummary *summary);
+/* Read a message from the pipe */
static gboolean
read_msg (GIOChannel *source,
GIOCondition condition,
@@ -107,23 +125,50 @@ check_compipes (void)
}
}
-/* Temporary functions to create the summary
- FIXME: Need TigerT's designs :) */
-static void
-do_changed (MailSummary *summary)
+static char *
+generate_html_summary (MailSummary *summary)
{
- char *ret_html, *str1;
- int mail = summary->mail;
+ char *ret_html = NULL, *tmp;
+ FolderSummary *fs;
+ int i;
+
+ /* Inbox first */
+ fs = summary->folders[0];
+
+ tmp = g_strdup_printf ("<table><tr><td><b>%s:</b>"
+ "<td align=\"right\">%d/%d</td></tr>",
+ fs->name, fs->unread, fs->total);
+
+ ret_html = g_strdup (tmp);
+ for (i = 1; i < summary->numfolders; i++) {
+ char *tmp2;
+
+ fs = summary->folders[i];
+ tmp2 = g_strdup_printf ("<tr><td><ul><li>%s:</li></ul></td>"
+ "<td align=\"right\">%d/%d</td></tr>",
+ fs->name, fs->unread, fs->total);
+
+ tmp = ret_html;
+ ret_html = g_strconcat (ret_html, tmp2, NULL);
+ g_free (tmp);
+ g_free (tmp2);
+ }
+
+ tmp = ret_html;
+ ret_html = g_strconcat (ret_html, "</table>", NULL);
+ g_free (tmp);
- str1 = g_strdup_printf (_("<b>Inbox:</b> %d/%d"),
- summary->unread, mail);
+ return ret_html;
+}
- ret_html = g_strdup_printf ("<table><tr><td><img src=\"evolution-inbox-mini.png\"></td><td>%s</td></tr></table>", str1);
- g_free (str1);
+static void
+do_changed (MailSummary *summary)
+{
+ char *ret_html;
+ ret_html = generate_html_summary (summary);
executive_summary_component_update (summary->component, ret_html);
g_free (ret_html);
-
}
/* These two callbacks are called from the Camel thread,
@@ -145,14 +190,17 @@ folder_changed_cb (CamelObject *folder,
gpointer user_data)
{
MailSummary *summary;
- int mail;
+ FolderSummary *fs;
summary = (MailSummary *) user_data;
- /* Put the summary data onto a pipe */
+ fs = g_hash_table_lookup (summary->folder_to_summary, folder);
+ if (fs == NULL) {
+ g_warning ("%s: Unknown folder", __FUNCTION__);
+ return;
+ }
- mail = camel_folder_get_message_count (folder);
- summary->unread = camel_folder_get_unread_message_count (folder);
- summary->mail = mail;
+ fs->total = camel_folder_get_message_count (fs->folder);
+ fs->unread = camel_folder_get_unread_message_count (fs->folder);
write (MAIN_WRITER, summary, sizeof (MailSummary));
queue_len++;
@@ -166,12 +214,17 @@ message_changed_cb (CamelObject *folder,
gpointer user_data)
{
MailSummary *summary;
- int mail;
+ FolderSummary *fs;
summary = (MailSummary *)user_data;
+ fs = g_hash_table_lookup (summary->folder_to_summary, folder);
+ if (fs == NULL) {
+ g_warning ("%s: Unknown folder.", __FUNCTION__);
+ return;
+ }
- summary->unread = camel_folder_get_unread_message_count (folder);
- summary->mail = camel_folder_get_message_count (folder);
+ fs->unread = camel_folder_get_unread_message_count (fs->folder);
+ fs->total = camel_folder_get_message_count (fs->folder);
write (MAIN_WRITER, summary, sizeof (MailSummary));
queue_len++;
@@ -179,50 +232,111 @@ message_changed_cb (CamelObject *folder,
return;
}
-char *
-create_summary_view (ExecutiveSummaryComponent *component,
- char **title,
- void *closure)
+static void
+generate_folder_summarys (MailSummary *summary)
{
- char *str1, *ret_html;
- int mailread, unread;
- CamelFolder *folder;
+ int numfolders = 1; /* Always at least the Inbox */
+ char *user, *system;
+ FilterRule *rule;
+ VfolderContext *context;
+ FolderSummary *fs;
CamelException *ex;
- MailSummary *summary;
+ int i;
+
+ user = g_strdup_printf ("%s/vfolders.xml", evolution_dir);
+ system = g_strdup_printf ("%s/evolution/vfoldertypes.xml", EVOLUTION_DATADIR);
+
+ context = vfolder_context_new ();
+ rule_context_load ((RuleContext *)context, system, user, NULL, NULL);
+ g_free (user);
+ g_free (system);
+
+ rule = NULL;
+ while ((rule = rule_context_next_rule ((RuleContext *)context, rule))){
+ g_print ("rule->name: %s\n", rule->name);
+ numfolders++;
+ }
- /* Strdup the title */
- *title = g_strdup ("Inbox:");
+ summary->folders = g_new (FolderSummary *, numfolders);
+ /* Inbox */
+ fs = summary->folders[0] = g_new (FolderSummary, 1);
+ fs->name = g_strdup ("Inbox");
mail_tool_camel_lock_up ();
ex = camel_exception_new ();
- folder = mail_tool_get_local_inbox (ex);
-
- mailread = camel_folder_get_message_count (folder);
- unread = camel_folder_get_unread_message_count (folder);
+ fs->folder = mail_tool_get_local_inbox (ex);
+ fs->total = camel_folder_get_message_count (fs->folder);
+ fs->unread = camel_folder_get_unread_message_count (fs->folder);
+ camel_exception_free (ex);
mail_tool_camel_lock_down ();
+ camel_object_hook_event (CAMEL_OBJECT (fs->folder), "folder_changed",
+ (CamelObjectEventHookFunc) folder_changed_cb,
+ summary);
+ camel_object_hook_event (CAMEL_OBJECT (fs->folder), "message_changed",
+ (CamelObjectEventHookFunc) message_changed_cb,
+ summary);
+ g_hash_table_insert (summary->folder_to_summary, fs->folder, fs);
+
- str1 = g_strdup_printf (_("<b>Inbox:</b>%d/%d"),
- unread, mailread);
+ summary->numfolders = 1;
+
+ for (i = 1, rule = NULL; i < numfolders; i++) {
+ char *uri;
+
+ ex = camel_exception_new ();
+ fs = summary->folders[i] = g_new (FolderSummary, 1);
+ rule = rule_context_next_rule ((RuleContext *)context, rule);
+ fs->name = g_strdup (rule->name);
+
+ uri = g_strconcat ("vfolder:", rule->name, NULL);
+ mail_tool_camel_lock_up ();
+ fs->folder = vfolder_uri_to_folder (uri, ex);
+ g_free (uri);
+
+ fs->total = camel_folder_get_message_count (fs->folder);
+ fs->unread = camel_folder_get_unread_message_count (fs->folder);
+
+ /* Connect to each folder */
+ camel_object_hook_event (CAMEL_OBJECT (fs->folder),
+ "folder_changed",
+ (CamelObjectEventHookFunc) folder_changed_cb,
+ summary);
+ camel_object_hook_event (CAMEL_OBJECT (fs->folder),
+ "message_changed",
+ (CamelObjectEventHookFunc) message_changed_cb,
+ summary);
+ g_hash_table_insert (summary->folder_to_summary, fs->folder, fs);
+ summary->numfolders++;
+
+ camel_exception_free (ex);
+ mail_tool_camel_lock_down ();
+ }
- ret_html = g_strdup_printf ("<table><tr><td><img src=\"evolution-inbox-mini.png\"></td><td>%s</td></tr></table>", str1);
- g_free (str1);
+ gtk_object_destroy (GTK_OBJECT (context));
+}
+
+char *
+create_summary_view (ExecutiveSummaryComponent *component,
+ char **title,
+ char **icon,
+ void *closure)
+{
+ char *ret_html;
+ MailSummary *summary;
+
+ /* Strdup the title and icon */
+ *title = g_strdup ("Mailbox summary");
+ *icon = g_strdup ("envelope.png");
summary = g_new (MailSummary, 1);
- summary->folder = folder;
- summary->html = ret_html;
- summary->mail = mailread;
- summary->unread = unread;
summary->component = component;
+ summary->folder_to_summary = g_hash_table_new (NULL, NULL);
+
+ generate_folder_summarys (summary);
+
+ ret_html = generate_html_summary (summary);
check_compipes ();
- mail_tool_camel_lock_up ();
- camel_object_hook_event (folder, "folder_changed",
- (CamelObjectEventHookFunc) folder_changed_cb,
- summary);
- camel_object_hook_event (folder, "message_changed",
- (CamelObjectEventHookFunc) message_changed_cb,
- summary);
- mail_tool_camel_lock_down ();
return ret_html;
}