[anjal] Commit libunique support for Anjal and make it possible to send mail to



commit 0449ddd6644f7b5077f765ffbdd5509da9e42aa3
Author: Srinivasa Ragavan <sragavan novell com>
Date:   Mon Jun 8 17:55:07 2009 +0530

    Commit libunique support for Anjal and make it possible to send mail to
    handle mailto: uris through unique created app.
---
 configure.ac     |    8 ++++
 src/Makefile.am  |    4 ++-
 src/mail-shell.c |    3 ++
 src/main.c       |   94 +++++++++++++++++++++++++++++++++++++++++++++++-------
 4 files changed, 96 insertions(+), 13 deletions(-)

diff --git a/configure.ac b/configure.ac
index aa5ab5a..d956ce8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -81,6 +81,14 @@ else
    AM_CONDITIONAL(ENABLE_MOZILLA, false)
 fi
 
+PKG_CHECK_MODULES(UNIQUE, [unique-1.0],HAVE_UNIQUE="yes", HAVE_UNIQUE="no")
+if test "x$HAVE_UNIQUE" = "xyes"; then
+   AC_DEFINE(HAVE_UNIQUE, 1, [unique available])
+   AM_CONDITIONAL(ENABLE_UNIQUE, true)
+else
+   AC_DEFINE(HAVE_UNIQUE, 0, [unique not available])
+   AM_CONDITIONAL(ENABLE_UNIQUE, false)
+fi
 
 
 AC_OUTPUT([
diff --git a/src/Makefile.am b/src/Makefile.am
index 3272527..8af5000 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,7 +10,8 @@ AM_CPPFLAGS = \
 	-DANJAL_IMAGEDIR=\""$(datadir)/anjal/images/"\" \
 	$(ANJAL_CFLAGS)	-I. \
 	$(MOZILLA_CFLAGS) \
-	$(WEBKIT_CFLAGS)
+	$(WEBKIT_CFLAGS) \
+	$(UNIQUE_CFLAGS)
 
 AM_CFLAGS =\
 	 -Wall\
@@ -82,6 +83,7 @@ anjal_LDFLAGS = \
 anjal_LDADD = $(ANJAL_LIBS) \
 	$(MOZILLA_LIBS) \
 	$(WEBKIT_LIBS) \
+	$(UNIQUE_LIBS) \
 	-lemiscwidgets \
 	-lfilter \
 	-lefilterbar \
diff --git a/src/mail-shell.c b/src/mail-shell.c
index 28a150f..9d79f78 100644
--- a/src/mail-shell.c
+++ b/src/mail-shell.c
@@ -493,4 +493,7 @@ mail_shell_handle_cmdline (MailShell *shell)
 			}
 		}
 	}
+	
+	/* FIXME: Check who own the memory? GOptionContext or me ? */
+	shell->priv->args = NULL;
 }
diff --git a/src/main.c b/src/main.c
index f3ec6a9..8fb076e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -39,19 +39,18 @@
 #include <gconf/gconf-client.h>
 #include <e-util/e-icon-factory.h>
 
-#include <bonobo/bonobo-main.h>
-#include <bonobo/bonobo-moniker-util.h>
-#include <bonobo/bonobo-exception.h>
-
-#include <bonobo-activation/bonobo-activation.h>
-
 #ifdef G_OS_WIN32
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #endif
 
+#if HAVE_UNIQUE
+#include <unique/unique.h>
+#endif
+
 gboolean windowed = FALSE;
 gboolean default_app =  FALSE;
+GtkWidget *main_window;
 static gchar **remaining_args;
 
 /* For testing propose use the local (not installed) glade file */
@@ -62,6 +61,48 @@ static gchar **remaining_args;
 #define GCONF_KEY_MAILTO_COMMAND "/desktop/gnome/url-handlers/mailto/command"
 #define ANJAL_MAILTO_COMMAND "anjal %s"
 
+#if HAVE_UNIQUE
+static UniqueResponse
+mail_message_received_cb (UniqueApp         *app,
+                         gint               command,
+                         UniqueMessageData *message_data,
+                         guint              time_,
+                         gpointer           user_data)
+{
+	 gchar *url;
+	 GtkWindow *window = (GtkWindow *) user_data;
+	 char *args[2];
+	 
+	 switch (command) {
+	 case UNIQUE_ACTIVATE :
+		  gtk_window_deiconify (window);
+		  gtk_window_present (window);
+		  return UNIQUE_RESPONSE_OK;
+
+	 case UNIQUE_NEW :
+		  return UNIQUE_RESPONSE_OK;
+
+	 case UNIQUE_OPEN :
+		  url = unique_message_data_get_text (message_data);
+		  if (url && (url[0] != '\0')) printf("%s\n", url);
+			  // mwb_dbus_new_tab (mwb_dbus, url, FALSE, TRUE, NULL);
+		  args[0] = url;
+		  args[1] = NULL;
+		  mail_shell_set_cmdline_args ((MailShell *)window, args);
+		  mail_shell_handle_cmdline ((MailShell *)window);
+		  g_free (url);
+		  gdk_window_raise (((GtkWidget *)window)->window);
+		  gtk_window_deiconify (window);
+		  gtk_window_present (window);
+
+		  return UNIQUE_RESPONSE_OK;
+	 }
+
+	 return UNIQUE_RESPONSE_PASSTHROUGH;
+}
+
+#endif
+
 static void
 check_and_set_default_mail (void)
 {
@@ -149,14 +190,20 @@ set_paths (void)
 int
 main (int argc, char *argv[])
 {
+	GtkWidget *window;
+	GError *error = NULL;
+#if HAVE_UNIQUE	
+	UniqueApp *app;
+#endif
+
 	if (!g_thread_supported ()) 
 		g_thread_init (NULL);
 #ifdef G_OS_WIN32
 	extern void link_shutdown (void);
 	set_paths ();
 #endif
- 	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 },
 		{ "default-mailer", 'd', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_NONE, &default_app,N_("Make Anjal the default email client"), NULL },
@@ -185,10 +232,33 @@ main (int argc, char *argv[])
 	mail_msg_init ();
 	gnome_sound_init ("localhost");
 
-	window = (GtkWidget *)mail_shell_new ();
-	gtk_widget_show (window);
-	mail_shell_set_cmdline_args ((MailShell *)window, remaining_args);
-	g_idle_add ((GSourceFunc) idle_cb, window);
+#if HAVE_UNIQUE	
+	app = unique_app_new ("org.gnome.Anjal", NULL);
+	  if (unique_app_is_running (app))  {
+		   gboolean cmd_line =  (remaining_args && remaining_args[0] != NULL);
+		   
+		  if (!cmd_line)
+			unique_app_send_message (app, UNIQUE_ACTIVATE, NULL);
+		  else {
+			  UniqueMessageData *data = unique_message_data_new ();
+			  unique_message_data_set_text (data, remaining_args[0], -1);
+			  unique_app_send_message (app, UNIQUE_OPEN, data);
+			  unique_message_data_free (data);
+		  }
+
+		  return 0;
+	  }
+#endif
+	  
+	main_window = (GtkWidget *)mail_shell_new ();
+	gtk_widget_show (main_window);
+	mail_shell_set_cmdline_args ((MailShell *)main_window, remaining_args);
+#if HAVE_UNIQUE
+	g_signal_connect (app, "message-received",
+                    G_CALLBACK (mail_message_received_cb),  main_window);
+#endif
+	
+	g_idle_add ((GSourceFunc) idle_cb, main_window);
 
 	gtk_main ();
 	e_icon_factory_shutdown ();



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