[Planner Dev] UIDs for the e-d-s importer



Hi guys!

Here goes the patch to create a new custom property for resources for
Evolution Data Server (e-d-s) uid.

The property is defined as not created by the user so planner doesn't
show them in the GUI. The code already there work :)

Cheers

-- Alvaro
Index: src/planner-eds-plugin.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-eds-plugin.c,v
retrieving revision 1.2
diff -u -b -B -p -r1.2 planner-eds-plugin.c
--- src/planner-eds-plugin.c	10 Aug 2004 07:16:48 -0000	1.2
+++ src/planner-eds-plugin.c	11 Aug 2004 05:23:48 -0000
@@ -47,6 +47,8 @@
 #include "planner-window.h"
 #include "planner-plugin.h"
 #include "planner-resource-cmd.h"
+#include <libplanner/mrp-object.h>
+#include <libplanner/mrp-property.h>
 
 /* Evolution Data Server sources */
 #include <libedataserver/e-source-list.h>
@@ -132,7 +134,9 @@ static void eds_resource_selected      (
 					PlannerPlugin         *plugin);
 static void eds_import_resource        (gchar                 *name,
 					gchar                 *email,
+					 gchar                 *uid,
 					PlannerPlugin         *plugin);
+static gboolean eds_create_uid_property (PlannerPlugin         *plugin);
 static void eds_load_resources         (ESourceGroup          *group, 
 					PlannerPlugin         *plugin,
 					const gchar           *search);
@@ -618,11 +622,20 @@ eds_import_change_all (PlannerPlugin *pl
 static void
 eds_import_resource (gchar         *name,
 		     gchar         *email,
+		     gchar         *uid,
 		     PlannerPlugin *plugin) 
 {
 	MrpResource *resource = mrp_resource_new ();	
+	gchar       *note = _("Imported from Evolution Data Server");
 
 	planner_resource_cmd_insert (plugin->main_window, resource);
+	mrp_object_set (resource, 
+			"type", MRP_RESOURCE_TYPE_WORK, 
+			"units", 1,
+			"note", g_strdup_printf ("%s:\n%s", note, uid),
+			"eds-uid", g_strdup (uid),
+			NULL);
+
 	if (name) {
 		mrp_object_set (resource, "name", name, NULL);
 	}
@@ -698,6 +711,12 @@ eds_ok_button_clicked (GtkButton     *bu
 		return;
 	}
 
+	/* Custom property for e-d-s resource UID */
+	if (!mrp_project_has_property (plugin->priv->project, 
+				       MRP_TYPE_RESOURCE, "eds-uid")) {
+		eds_create_uid_property (plugin);
+	}
+
 	do {
 		EContact *contact;
 		gboolean  selected;
@@ -710,7 +729,11 @@ eds_ok_button_clicked (GtkButton     *bu
 		if (selected) {
 			gchar *name = e_contact_get (contact, E_CONTACT_GIVEN_NAME);
 			gchar *email = e_contact_get (contact, E_CONTACT_EMAIL_1);
-			eds_import_resource (name, email, plugin);
+			gchar *eds_uid = e_contact_get (contact, E_CONTACT_UID);
+			eds_import_resource (name, email, eds_uid, plugin);
+			g_free (name);
+			g_free (email);
+			g_free (eds_uid);
 		} 
 	} while (gtk_tree_model_iter_next (priv->resources_model, &iter));
 
@@ -824,6 +847,29 @@ eds_dialog_close (PlannerPlugin *plugin)
 	g_object_unref (priv->glade);
 	
 	gtk_widget_destroy (priv->dialog_get_resources);
+}
+
+/* FIXME: Undo support : planner-property-dialog.c */
+static gboolean
+eds_create_uid_property (PlannerPlugin *plugin)
+{	
+	MrpProperty *property;
+
+	property = mrp_property_new ("eds-uid", 
+				     MRP_PROPERTY_TYPE_STRING,
+				     _("Evolution Data Server UID"),
+				     _("Identifier used by Evolution Data Server for resources"),
+				     FALSE);
+			
+	mrp_project_add_property (plugin->priv->project, 
+				  MRP_TYPE_RESOURCE,
+				  property,
+				  FALSE);
+	if (!mrp_project_has_property (plugin->priv->project, 
+				       MRP_TYPE_RESOURCE, "eds-uid")) {
+		return FALSE;
+	}
+	return TRUE;
 }
 
 /* FIXME: Undo support */

Attachment: signature.asc
Description: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada digitalmente



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