[evolution-patches] Patch to allow a contact to be opened in the editor from command-line.
- From: Veerapuram Varadhan <vvaradhan novell com>
- To: evo-patches <evolution-patches lists ximian com>
- Subject: [evolution-patches] Patch to allow a contact to be opened in the editor from command-line.
- Date: Sat, 09 Jul 2005 20:43:58 +0530
Hi,
Attached patch enable handling for contacts:// uri's and also will allow
users to open a contact in the contact-editor from command-line.
It uses the "contacts://....." uri.
The added "query" options are:
1) "source-uid" -> specifies the source-uid corresponding to the
contact that we are trying to open in the editor.
2) "contact-uid" -> specifies the uid of the contact that we
want to open in the editor.
Kindly let me know your comments/suggestions.
Thanks,
V. Varadhan
Index: addressbook/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/ChangeLog,v
retrieving revision 1.1952
diff -u -p -r1.1952 ChangeLog
--- addressbook/ChangeLog 8 Jul 2005 08:06:48 -0000 1.1952
+++ addressbook/ChangeLog 9 Jul 2005 15:00:13 -0000
@@ -1,3 +1,9 @@
+2005-07-09 Veerapuram Varadhan <vvaradhan novell com>
+
+ * gui/component/addressbook-component.c: (impl_createControls):
+ * gui/component/addressbook-view.[c,h]: (addressbook_view_edit_contact):
+ (impl_handleURI): Handle contacts:// uris.
+
2005-07-08 Frederic Crozat <fcrozat mandriva com>
* gui/widgets/eab-gui-util.c (eab_load_error_dialog): Including the
Index: addressbook/gui/component/addressbook-component.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/component/addressbook-component.c,v
retrieving revision 1.137
diff -u -p -r1.137 addressbook-component.c
--- addressbook/gui/component/addressbook-component.c 7 Jul 2005 13:22:20 -0000 1.137
+++ addressbook/gui/component/addressbook-component.c 9 Jul 2005 15:00:47 -0000
@@ -44,6 +44,7 @@
#include <gtk/gtkimage.h>
#include <gconf/gconf-client.h>
#include <e-util/e-util.h>
+#include <libedataserver/e-url.h>
#ifdef ENABLE_SMIME
#include "smime/gui/component.h"
@@ -58,6 +59,7 @@ static BonoboObjectClass *parent_class =
struct _AddressbookComponentPrivate {
GConfClient *gconf_client;
char *base_directory;
+ GList *views;
};
static void
@@ -159,6 +161,24 @@ ensure_sources (AddressbookComponent *co
g_free (base_uri);
}
+static void
+view_destroyed_cb (gpointer data, GObject *where_the_object_was)
+{
+ AddressbookComponent *addressbook_component = data;
+ AddressbookComponentPrivate *priv;
+ GList *l;
+
+ priv = addressbook_component->priv;
+
+ for (l = priv->views; l; l = l->next) {
+ AddressbookView *view = l->data;
+ if (G_OBJECT (view) == where_the_object_was) {
+ priv->views = g_list_remove (priv->views, view);
+ break;
+ }
+ }
+}
+
/* Evolution::Component CORBA methods. */
static void
@@ -168,6 +188,8 @@ impl_createControls (PortableServer_Serv
Bonobo_Control *corba_statusbar_control,
CORBA_Environment *ev)
{
+ AddressbookComponent *addressbook_component = ADDRESSBOOK_COMPONENT (bonobo_object_from_servant (servant));
+ AddressbookComponentPrivate *priv = addressbook_component->priv;
AddressbookView *view = addressbook_view_new ();
BonoboControl *sidebar_control;
BonoboControl *view_control;
@@ -177,6 +199,9 @@ impl_createControls (PortableServer_Serv
view_control = addressbook_view_peek_folder_view (view);
statusbar_control = bonobo_control_new (addressbook_view_peek_statusbar (view));
+ g_object_weak_ref (G_OBJECT (view), view_destroyed_cb, addressbook_component);
+ priv->views = g_list_append (priv->views, view);
+
*corba_sidebar_control = CORBA_Object_duplicate (BONOBO_OBJREF (sidebar_control), ev);
*corba_view_control = CORBA_Object_duplicate (BONOBO_OBJREF (view_control), ev);
*corba_statusbar_control = CORBA_Object_duplicate (BONOBO_OBJREF (statusbar_control), ev);
@@ -278,6 +303,75 @@ impl_requestCreateItem (PortableServer_S
}
static void
+impl_handleURI (PortableServer_Servant servant,
+ const char* uri,
+ CORBA_Environment *ev)
+{
+ AddressbookComponent *addressbook_component = ADDRESSBOOK_COMPONENT (bonobo_object_from_servant (servant));
+ AddressbookComponentPrivate *priv;
+ AddressbookView *view = NULL;
+
+ GList *l;
+ char *src_uid = NULL;
+ char *contact_uid = NULL;
+
+ priv = addressbook_component->priv;
+ l = g_list_last (priv->views);
+ if (!l)
+ return;
+
+ view = l->data;
+
+ if (!strncmp (uri, "contacts:", 9)) {
+ EUri *euri = e_uri_new (uri);
+ const char *p;
+ char *header, *content;
+ size_t len, clen;
+
+ p = euri->query;
+ if (p) {
+ while (*p) {
+ len = strcspn (p, "=&");
+
+ /* If it's malformed, give up. */
+ if (p[len] != '=')
+ break;
+
+ header = (char *) p;
+ header[len] = '\0';
+ p += len + 1;
+
+ clen = strcspn (p, "&");
+
+ content = g_strndup (p, clen);
+
+ if (!g_ascii_strcasecmp (header, "source-uid")) {
+ src_uid = g_strdup (content);
+ } else if (!g_ascii_strcasecmp (header, "contact-uid")) {
+ contact_uid = g_strdup (content);
+ }
+
+ g_free (content);
+
+ p += clen;
+ if (*p == '&') {
+ p++;
+ if (!strcmp (p, "amp;"))
+ p += 4;
+ }
+ }
+
+ addressbook_view_edit_contact (view, src_uid, contact_uid);
+
+ g_free (src_uid);
+ g_free (contact_uid);
+ }
+ e_uri_free (euri);
+ }
+
+}
+
+static void
impl_upgradeFromVersion (PortableServer_Servant servant, short major, short minor, short revision, CORBA_Environment *ev)
{
GError *err = NULL;
@@ -307,6 +401,7 @@ static void
impl_dispose (GObject *object)
{
AddressbookComponentPrivate *priv = ADDRESSBOOK_COMPONENT (object)->priv;
+ GList *l;
if (priv->gconf_client != NULL) {
g_object_unref (priv->gconf_client);
@@ -314,6 +409,12 @@ impl_dispose (GObject *object)
}
(* G_OBJECT_CLASS (parent_class)->dispose) (object);
+ for (l = priv->views; l; l = l->next) {
+ AddressbookView *view = l->data;
+ g_object_weak_unref (G_OBJECT (view), view_destroyed_cb, ADDRESSBOOK_COMPONENT (object));
+ }
+ g_list_free (priv->views);
+ priv->views = NULL;
}
static void
@@ -340,6 +441,7 @@ addressbook_component_class_init (Addres
epv->requestCreateItem = impl_requestCreateItem;
epv->upgradeFromVersion = impl_upgradeFromVersion;
epv->requestQuit = impl_requestQuit;
+ epv->handleURI = impl_handleURI;
object_class->dispose = impl_dispose;
object_class->finalize = impl_finalize;
Index: addressbook/gui/component/addressbook-view.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/component/addressbook-view.c,v
retrieving revision 1.34
diff -u -p -r1.34 addressbook-view.c
--- addressbook/gui/component/addressbook-view.c 6 Jul 2005 13:29:57 -0000 1.34
+++ addressbook/gui/component/addressbook-view.c 9 Jul 2005 15:01:30 -0000
@@ -1405,3 +1405,42 @@ addressbook_view_peek_folder_view (Addre
return view->priv->folder_view_control;
}
+
+void
+addressbook_view_edit_contact (AddressbookView* view,
+ const char* source_uid,
+ const char* contact_uid)
+{
+ AddressbookViewPrivate *priv = view->priv;
+
+ GtkWidget *uid_view;
+ ESource* source = NULL;
+ EContact* contact = NULL;
+ EBook* book = NULL;
+ const char *uid;
+
+ if (!source_uid && !contact_uid)
+ return;
+
+ source = e_source_list_peek_source_by_uid (priv->source_list, source_uid);
+
+ if (source) {
+ /* FIXME: Can I unref this book? */
+ book = e_book_new (source, NULL);
+ if (book) {
+ if (e_book_open (book, TRUE, NULL))
+ e_book_get_contact (book, contact_uid, &contact, NULL);
+ else
+ g_warning (_("Error opening addressbook %s\n"), source_uid);
+ }
+ else
+ g_warning (_("Book != NULL failed\n"));
+
+ if (contact)
+ eab_show_contact_editor (book, contact, FALSE, FALSE);
+ else
+ g_warning (_("Contact != NULL failed\n"));
+
+ } else
+ g_warning (_("Addressbook source doesn't exist!\n"));
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]