aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/dialogs/comp-editor-util.c
diff options
context:
space:
mode:
authorDamon Chaplin <damon@ximian.com>2001-08-15 09:13:37 +0800
committerDamon Chaplin <damon@src.gnome.org>2001-08-15 09:13:37 +0800
commit6684b4627d4767f6ea5d2969d70ae6f2cf863a79 (patch)
tree89d7a6fba9713ff48fe44ed4bad3ee94471030e6 /calendar/gui/dialogs/comp-editor-util.c
parent84f12a913e4a46c198a951dd2b10512fb87ce0a3 (diff)
downloadgsoc2013-evolution-6684b4627d4767f6ea5d2969d70ae6f2cf863a79.tar
gsoc2013-evolution-6684b4627d4767f6ea5d2969d70ae6f2cf863a79.tar.gz
gsoc2013-evolution-6684b4627d4767f6ea5d2969d70ae6f2cf863a79.tar.bz2
gsoc2013-evolution-6684b4627d4767f6ea5d2969d70ae6f2cf863a79.tar.lz
gsoc2013-evolution-6684b4627d4767f6ea5d2969d70ae6f2cf863a79.tar.xz
gsoc2013-evolution-6684b4627d4767f6ea5d2969d70ae6f2cf863a79.tar.zst
gsoc2013-evolution-6684b4627d4767f6ea5d2969d70ae6f2cf863a79.zip
added support for the Contacts field. Note that I'm not sure what we
2001-08-14 Damon Chaplin <damon@ximian.com> * gui/dialogs/task-page.c: * gui/dialogs/event-page.c: added support for the Contacts field. Note that I'm not sure what we should put in the iCalendar CONTACT properties. Currently we put "name <email>", but it isn't recognized as a contact when we reopen the dialog, so we may need more info here. Also we currently use a simple parser to parse the above format, and we should maybe use some camel function. * gui/dialogs/task-page.glade: * gui/dialogs/event-page.glade: replaced the GtkEntry fields for the Contacts with a GtkEventBox which we put the BonoboControl in at runtime. * gui/dialogs/meeting-page.c (invite_entry_changed): added FIXMEs since it doesn't seem to be freeing the EDestination stuff. JP? * gui/dialogs/comp-editor-util.c: added bunch of utility functions to handle the Contacts field in the main Event and Task pages. * gui/gnome-cal.c: added visible_start and visible_end fields, so we only emit the 'dates-shown-changed' signal when really necessary. Currently changing the folder title bar label results in a complete redraw of the Evolution window (silly GtkLabel queueing a resize), so we want to avoid that as much as possible. (gnome_calendar_new_appointment_for): only move the event's end time to the end of the day if it is not already 00:00:00. * gui/e-week-view-event-item.c: * gui/e-week-view.c: * gui/e-day-view.c: added support for double-clicking on an event to open it, and for double-clicking on the background to create a new event. There is still a minor problem to sort out, but it basically works. * cal-util/cal-component.c: added support for CONTACT properties, mainly by copying the code for COMMENT properties which are exactly the same type. * gui/e-day-view.c (e_day_view_realize): use the same color for the top canvas background as the shortcut bar, to make it look a little nicer (I think). Although we still have the theme problem with hard-coded colors. svn path=/trunk/; revision=12039
Diffstat (limited to 'calendar/gui/dialogs/comp-editor-util.c')
-rw-r--r--calendar/gui/dialogs/comp-editor-util.c248
1 files changed, 248 insertions, 0 deletions
diff --git a/calendar/gui/dialogs/comp-editor-util.c b/calendar/gui/dialogs/comp-editor-util.c
index 0e4384dca4..8ef7aebbab 100644
--- a/calendar/gui/dialogs/comp-editor-util.c
+++ b/calendar/gui/dialogs/comp-editor-util.c
@@ -23,11 +23,16 @@
#include <config.h>
#endif
+#include <ctype.h>
#include <string.h>
#include <ical.h>
#include <glib.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
+#include <liboaf/liboaf.h>
+#include <bonobo/bonobo-control.h>
+#include <bonobo/bonobo-widget.h>
+#include <e-destination.h>
#include <e-util/e-time-utils.h>
#include <cal-util/timeutil.h>
#include "../calendar-config.h"
@@ -224,3 +229,246 @@ comp_editor_get_current_time (GtkObject *object, gpointer data)
return tmp_tm;
}
+
+
+
+/*
+ * These are utility functions to handle the SelectNames control we use
+ * for the contacts field, and its related dialog.
+ */
+
+#define SELECT_NAMES_OAFID "OAFIID:GNOME_Evolution_Addressbook_SelectNames"
+
+GNOME_Evolution_Addressbook_SelectNames
+comp_editor_create_contacts_component (void)
+{
+ GNOME_Evolution_Addressbook_SelectNames corba_select_names;
+ CORBA_Environment ev;
+
+ CORBA_exception_init (&ev);
+ corba_select_names = oaf_activate_from_id (SELECT_NAMES_OAFID, 0,
+ NULL, &ev);
+
+ /* OAF seems to be broken -- it can return a CORBA_OBJECT_NIL without
+ raising an exception in `ev'. */
+ if (ev._major != CORBA_NO_EXCEPTION
+ || corba_select_names == CORBA_OBJECT_NIL) {
+ g_warning ("Cannot activate -- %s", SELECT_NAMES_OAFID);
+ CORBA_exception_free (&ev);
+ return CORBA_OBJECT_NIL;
+ }
+
+ CORBA_exception_free (&ev);
+
+ return corba_select_names;
+}
+
+
+GtkWidget *
+comp_editor_create_contacts_control (GNOME_Evolution_Addressbook_SelectNames corba_select_names)
+{
+ Bonobo_Control corba_control;
+ GtkWidget *control_widget;
+ CORBA_Environment ev;
+ char *name = _("Contacts");
+
+ CORBA_exception_init (&ev);
+
+ GNOME_Evolution_Addressbook_SelectNames_addSection (
+ corba_select_names, name, name, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ CORBA_exception_free (&ev);
+ return NULL;
+ }
+
+ corba_control =
+ GNOME_Evolution_Addressbook_SelectNames_getEntryBySection (
+ corba_select_names, name, &ev);
+
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ CORBA_exception_free (&ev);
+ return NULL;
+ }
+
+ CORBA_exception_free (&ev);
+
+ control_widget = bonobo_widget_new_control_from_objref (
+ corba_control, CORBA_OBJECT_NIL);
+
+ gtk_widget_show (control_widget);
+
+ return control_widget;
+}
+
+
+Bonobo_EventSource_ListenerId
+comp_editor_connect_contacts_changed (GtkWidget *contacts_entry,
+ BonoboListenerCallbackFn changed_cb,
+ gpointer changed_cb_data)
+{
+ BonoboControlFrame *cf;
+ Bonobo_PropertyBag pb = CORBA_OBJECT_NIL;
+
+ cf = bonobo_widget_get_control_frame (BONOBO_WIDGET (contacts_entry));
+ pb = bonobo_control_frame_get_control_property_bag (cf, NULL);
+
+ return bonobo_event_source_client_add_listener (
+ pb, changed_cb,
+ "Bonobo/Property:change:entry_changed",
+ NULL, changed_cb_data);
+}
+
+
+void
+comp_editor_show_contacts_dialog (GNOME_Evolution_Addressbook_SelectNames corba_select_names)
+{
+ CORBA_Environment ev;
+
+ CORBA_exception_init (&ev);
+ GNOME_Evolution_Addressbook_SelectNames_activateDialog (
+ corba_select_names, _("Contacts"), &ev);
+ CORBA_exception_free (&ev);
+}
+
+
+/* A simple 'name <email>' parser.
+ FIXME: Should probably use camel functions or something. */
+static void
+parse_contact_string (const char *value, char **name, char **email)
+{
+ char *lbracket, *rbracket, *name_end, *tmp_name, *tmp_email;
+
+ if (!value) {
+ *name = g_strdup ("");
+ *email = g_strdup ("");
+ return;
+ }
+
+ lbracket = strchr (value, '<');
+ rbracket = strchr (value, '>');
+
+ if (!lbracket || !rbracket || rbracket < lbracket) {
+ *name = g_strdup (value);
+ *email = g_strdup ("");
+ return;
+ }
+
+ name_end = lbracket - 1;
+ while (name_end > value && isspace (*name_end))
+ name_end--;
+
+ tmp_name = g_malloc (name_end - value + 2);
+ strncpy (tmp_name, value, name_end - value + 1);
+ tmp_name[name_end - value + 1] = '\0';
+ *name = tmp_name;
+
+ tmp_email = g_malloc (rbracket - lbracket);
+ strncpy (tmp_email, lbracket + 1, rbracket - lbracket - 1);
+ tmp_email[rbracket - lbracket - 1] = '\0';
+ *email = tmp_email;
+
+ g_print ("Parsed: %s\n Name:'%s'\nEmail:'%s'\n",
+ value, *name, *email);
+}
+
+
+void
+comp_editor_contacts_to_widget (GtkWidget *contacts_entry,
+ CalComponent *comp)
+{
+ GPtrArray *dest_array;
+ EDestination *dest;
+ GSList *contact_list, *elem;
+ char *contacts_string;
+ int i;
+
+ cal_component_get_contact_list (comp, &contact_list);
+ dest_array = g_ptr_array_new ();
+ for (elem = contact_list; elem; elem = elem->next) {
+ CalComponentText *t = elem->data;
+ char *name, *email;
+
+ parse_contact_string (t->value, &name, &email);
+
+ dest = e_destination_new ();
+ e_destination_set_name (dest, name);
+ e_destination_set_email (dest, email);
+ g_ptr_array_add (dest_array, dest);
+ g_free (name);
+ g_free (email);
+ }
+ cal_component_free_text_list (contact_list);
+
+ /* we need destv to be NULL terminated */
+ g_ptr_array_add (dest_array, NULL);
+
+ contacts_string = e_destination_exportv ((EDestination**) dest_array->pdata);
+ g_print ("Destinations: %s\n", contacts_string);
+
+ bonobo_widget_set_property (BONOBO_WIDGET (contacts_entry),
+ "destinations", contacts_string, NULL);
+
+ g_free (contacts_string);
+
+ /* We free all dest_array except the last NULL we added. */
+ for (i = 0; i < dest_array->len - 1; i++) {
+ dest = g_ptr_array_index (dest_array, i);
+ gtk_object_unref (GTK_OBJECT (dest));
+ }
+ g_ptr_array_free (dest_array, TRUE);
+}
+
+
+void
+comp_editor_contacts_to_component (GtkWidget *contacts_entry,
+ CalComponent *comp)
+{
+ EDestination **contact_destv;
+ GSList *contact_list = NULL, *elem;
+ char *contacts_string = NULL;
+ CalComponentText *t;
+ const char *name, *email;
+ int i;
+
+ bonobo_widget_get_property (BONOBO_WIDGET (contacts_entry),
+ "destinations", &contacts_string, NULL);
+ g_print ("Contacts string: %s\n", contacts_string);
+
+ contact_destv = e_destination_importv (contacts_string);
+ if (contact_destv) {
+ for (i = 0; contact_destv[i] != NULL; i++) {
+ name = e_destination_get_name (contact_destv[i]);
+ email = e_destination_get_email (contact_destv[i]);
+
+ t = g_new0 (CalComponentText, 1);
+ t->altrep = NULL;
+
+ /* If both name and email are given, use the standard
+ 'name <email>' form, otherwise use just the name
+ or the email address.
+ FIXME: I'm not sure this is correct syntax etc. */
+ if (name && name[0] && email && email[0])
+ t->value = g_strdup_printf ("%s <%s>",
+ name, email);
+ else if (name && name[0])
+ t->value = g_strdup (name);
+ else
+ t->value = g_strdup (email);
+
+ contact_list = g_slist_prepend (contact_list, t);
+
+ gtk_object_unref (GTK_OBJECT (contact_destv[i]));
+ }
+ }
+ g_free (contact_destv);
+
+ contact_list = g_slist_reverse (contact_list);
+ cal_component_set_contact_list (comp, contact_list);
+
+ for (elem = contact_list; elem; elem = elem->next) {
+ t = elem->data;
+ g_free ((char*)t->value);
+ g_free (t);
+ }
+ g_slist_free (contact_list);
+}