[anjal] Make way to do Anjal as default mailer.



commit 9df159e207c17cb8fbbf06c6ac359654b6379d3c
Author: Srinivasa Ragavan <sragavan novell com>
Date:   Sat May 30 00:29:41 2009 +0530

    Make way to do Anjal as default mailer.
---
 src/mail-shell.c |    3 +++
 src/main.c       |   35 ++++++++++++++++++++++++++++++++---
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/src/mail-shell.c b/src/mail-shell.c
index 8c5d3fe..e0aa4b1 100644
--- a/src/mail-shell.c
+++ b/src/mail-shell.c
@@ -472,6 +472,9 @@ void
 mail_shell_handle_cmdline (MailShell *shell)
 {
 	int i;
+	
+	if (!shell->priv->args)
+		return;
 
 	e_msg_composer_set_lite ();
 	for (i=0; shell->priv->args[i]; i++) {
diff --git a/src/main.c b/src/main.c
index 3a5cf67..70f2f10 100644
--- a/src/main.c
+++ b/src/main.c
@@ -37,17 +37,42 @@
 #include <mail/mail-mt.h>
 #include "mail-shell.h"
 #include <libgnome/gnome-sound.h>
+#include <gconf/gconf-client.h>
 
 gboolean windowed = FALSE;
+gboolean default_app =  FALSE;
 static gchar **remaining_args;
 
 /* For testing propose use the local (not installed) glade file */
 /* #define GLADE_FILE PACKAGE_DATA_DIR"/anjal/glade/anjal.glade" */
 #define GLADE_FILE "anjal.glade"
 
+#define GCONF_KEY_MAILTO_ENABLED "/desktop/gnome/url-handlers/mailto/enabled"
+#define GCONF_KEY_MAILTO_COMMAND "/desktop/gnome/url-handlers/mailto/command"
+#define ANJAL_MAILTO_COMMAND "anjal %s"
+
+static void
+check_and_set_default_mail (void)
+{
+	GConfClient *client = gconf_client_get_default ();
+	gchar *mailer;
+	printf("coming here\n");
+	mailer  = gconf_client_get_string(client, GCONF_KEY_MAILTO_COMMAND, NULL);
+	if (mailer && *mailer && (strcmp (mailer, ANJAL_MAILTO_COMMAND) == 0))
+		return; /* Anjal is the default mailer */
+	
+	gconf_client_set_bool(client, GCONF_KEY_MAILTO_ENABLED, TRUE, NULL);
+	gconf_client_set_string(client, GCONF_KEY_MAILTO_COMMAND, ANJAL_MAILTO_COMMAND, NULL);
+	g_object_unref (client);
+	printf("Set %s\n", GCONF_KEY_MAILTO_COMMAND);
+}
+
 static gboolean
 idle_cb (MailShell *shell)
 {
+	if (default_app) {
+		check_and_set_default_mail ();
+	}
 	mail_shell_handle_cmdline (shell);
 	return FALSE;
 }
@@ -56,9 +81,10 @@ int
 main (int argc, char *argv[])
 {
  	GtkWidget *window;
+	GError *error = NULL;
 	static GOptionEntry entries[] = {
-    		{ "windowed", 'w', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_NONE, &windowed,
-		N_("Run Anjal in a window"), NULL },
+    		{ "windowed", 'w', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_NONE, &windowed,N_("Run Anjal in a window"), NULL },
+		{ "default-mailer", 'd', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_NONE, &default_app,N_("Make Anjal the default email client"), NULL },
 		{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining_args, NULL, NULL },
 		{ NULL }
  	 	};
@@ -71,7 +97,10 @@ main (int argc, char *argv[])
 
 	
 	gtk_set_locale ();
-	gtk_init_with_args (&argc, &argv, _("Anjal email client"), entries, NULL, NULL);
+	if (!gtk_init_with_args (&argc, &argv, _("Anjal email client"), entries, NULL, &error)) {
+		g_error ("Unable to start Anjal: %s\n", error->message);
+		g_error_free(error);
+	}
 	glade_init ();
 	e_cursors_init ();
 	e_icon_factory_init ();



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