aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui
diff options
context:
space:
mode:
Diffstat (limited to 'addressbook/gui')
-rw-r--r--addressbook/gui/component/addressbook-component.c102
-rw-r--r--addressbook/gui/component/addressbook-view.c39
-rw-r--r--addressbook/gui/component/addressbook-view.h4
3 files changed, 145 insertions, 0 deletions
diff --git a/addressbook/gui/component/addressbook-component.c b/addressbook/gui/component/addressbook-component.c
index a5eadf6c96..670e5de8ef 100644
--- a/addressbook/gui/component/addressbook-component.c
+++ b/addressbook/gui/component/addressbook-component.c
@@ -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 = NULL;
struct _AddressbookComponentPrivate {
GConfClient *gconf_client;
char *base_directory;
+ GList *views;
};
static void
@@ -159,6 +161,24 @@ ensure_sources (AddressbookComponent *component)
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_Servant servant,
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_Servant servant,
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_Servant servant,
}
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,12 +401,19 @@ 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);
priv->gconf_client = NULL;
}
+ 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;
(* G_OBJECT_CLASS (parent_class)->dispose) (object);
}
@@ -340,6 +441,7 @@ addressbook_component_class_init (AddressbookComponentClass *class)
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;
diff --git a/addressbook/gui/component/addressbook-view.c b/addressbook/gui/component/addressbook-view.c
index 87d25df125..78d44d83c9 100644
--- a/addressbook/gui/component/addressbook-view.c
+++ b/addressbook/gui/component/addressbook-view.c
@@ -1405,3 +1405,42 @@ addressbook_view_peek_folder_view (AddressbookView *view)
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;
+
+ ESource* source = NULL;
+ EContact* contact = NULL;
+ EBook* book = NULL;
+
+ if (!source_uid || !contact_uid)
+ return;
+
+ source = e_source_list_peek_source_by_uid (priv->source_list, source_uid);
+ if (!source)
+ return;
+
+ /* FIXME: Can I unref this book? */
+ book = e_book_new (source, NULL);
+ if (!book)
+ return;
+
+ if (!e_book_open (book, TRUE, NULL)) {
+ g_object_unref (book);
+ return;
+ }
+
+ e_book_get_contact (book, contact_uid, &contact, NULL);
+
+ if (!contact) {
+ g_object_unref (book);
+ return;
+ }
+ eab_show_contact_editor (book, contact, FALSE, FALSE);
+ g_object_unref (contact);
+ g_object_unref (book);
+}
diff --git a/addressbook/gui/component/addressbook-view.h b/addressbook/gui/component/addressbook-view.h
index e2292c4527..37119abd65 100644
--- a/addressbook/gui/component/addressbook-view.h
+++ b/addressbook/gui/component/addressbook-view.h
@@ -57,4 +57,8 @@ GtkWidget *addressbook_view_peek_sidebar (AddressbookView *view
GtkWidget *addressbook_view_peek_statusbar (AddressbookView *view);
BonoboControl *addressbook_view_peek_folder_view (AddressbookView *view);
+void addressbook_view_edit_contact (AddressbookView* view,
+ const char* source_id,
+ const char* contact_id);
+
#endif /* _ADDRESSBOOK_VIEW_H_ */