[anjal] BUGFIX: Moblin Bugzilla #4152 - Make auto-completion work.



commit fa2ca18a28827ca91c30844a72a8d2ed3ac238dd
Author: Srinivasa Ragavan <sragavan novell com>
Date:   Fri Jul 24 13:52:41 2009 +0530

    BUGFIX: Moblin Bugzilla #4152 - Make auto-completion work.

 src/mail-shell.c |   86 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 85 insertions(+), 1 deletions(-)
---
diff --git a/src/mail-shell.c b/src/mail-shell.c
index b5c7746..64e865f 100644
--- a/src/mail-shell.c
+++ b/src/mail-shell.c
@@ -34,6 +34,7 @@
 #include "mail-decoration.h"
 #include <mail/em-utils.h>
 #include <mail/em-composer-utils.h>
+#include <e-util/e-util.h>
 
 enum {
 	BACKSPACE_PRESSED,
@@ -90,6 +91,8 @@ struct  _MailShellPrivate {
 
 G_DEFINE_TYPE (MailShell, mail_shell, GTK_TYPE_WINDOW)
 
+static void setup_abooks (void);
+
 static void
 mail_shell_init (MailShell  *shell)
 {
@@ -530,6 +533,7 @@ mail_shell_construct (MailShell *shell)
 		gtk_widget_hide (((MailView *) shell->mail_component->mail_view)->folder_tree);
 		mc = mail_view_add_page ((MailView *)shell->mail_component->mail_view, MAIL_VIEW_ACCOUNT, NULL);
 		g_signal_connect (mc, "view-close", G_CALLBACK(ms_show_post_druid), shell);
+		setup_abooks ();
 	}
 }
 
@@ -550,6 +554,87 @@ mail_shell_set_cmdline_args (MailShell *shell, char **args)
 
 void e_msg_composer_set_lite (void);
 
+#define PERSONAL_RELATIVE_URI "system"
+
+static void
+setup_abooks()
+{
+	char *base_dir, *uri;
+	GSList *groups;
+	ESourceGroup *group;
+	ESourceList *list = NULL;
+	ESourceGroup *on_this_computer = NULL;
+	ESource *personal_source = NULL;
+
+	base_dir = g_build_filename (e_get_user_data_dir (), "addressbook", "local", NULL);
+	uri = g_filename_to_uri (base_dir, NULL, NULL);
+	
+	if (!e_book_get_addressbooks(&list, NULL)) {
+		g_warning ("Unable to get books\n");
+		return;
+	}
+
+	groups = e_source_list_peek_groups (list);
+	if (groups) {
+		/* groups are already there, we need to search for things... */
+		GSList *g;
+
+		for (g = groups; g; g = g->next) {
+
+			group = E_SOURCE_GROUP (g->data);
+
+			if (!on_this_computer && !strcmp (uri, e_source_group_peek_base_uri (group))) {
+				on_this_computer = g_object_ref (group);
+				break;
+			}
+		}
+	}
+	
+	if (on_this_computer) {
+		/* make sure "Personal" shows up as a source under
+		   this group */
+		GSList *sources = e_source_group_peek_sources (on_this_computer);
+		GSList *s;
+		for (s = sources; s; s = s->next) {
+			ESource *source = E_SOURCE (s->data);
+			const gchar *relative_uri;
+
+			relative_uri = e_source_peek_relative_uri (source);
+			if (relative_uri == NULL)
+				continue;
+			if (!strcmp (PERSONAL_RELATIVE_URI, relative_uri)) {
+				personal_source = g_object_ref (source);
+				break;
+			}
+		}
+	}
+	else {
+		/* create the local source group */
+		group = e_source_group_new (_("On This Computer"), uri);
+		e_source_list_add_group (list, group, -1);
+
+		on_this_computer = group;
+	}
+
+	if (!personal_source) {
+		/* Create the default Person addressbook */
+		ESource *source = e_source_new (_("Personal"), PERSONAL_RELATIVE_URI);
+		e_source_group_add_source (on_this_computer, source, -1);
+
+		e_source_set_property (source, "completion", "true");
+
+		personal_source = source;
+	}
+
+	if (on_this_computer)
+		g_object_unref (on_this_computer);
+	if (personal_source)
+		g_object_unref (personal_source);
+	
+	e_source_list_sync (list, NULL);
+	g_object_unref (list);
+}
+
 void
 mail_shell_handle_cmdline (MailShell *shell)
 {
@@ -567,7 +652,6 @@ mail_shell_handle_cmdline (MailShell *shell)
 				//MailViewChild *child = 
 				mail_view_add_page ((MailView *)shell->mail_component->mail_view, MAIL_VIEW_COMPOSER, (gpointer)composer);
 				//child->flags |= MAIL_VIEW_HOLD_FOCUS;
-			
 			} else {
 				g_message ("Please configure an account before anything else");
 			}



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