diff options
Diffstat (limited to 'calendar')
-rw-r--r-- | calendar/ChangeLog | 42 | ||||
-rw-r--r-- | calendar/cal-util/cal-component.c | 163 | ||||
-rw-r--r-- | calendar/cal-util/cal-component.h | 10 | ||||
-rw-r--r-- | calendar/conduits/todo/Makefile.am | 21 | ||||
-rw-r--r-- | calendar/conduits/todo/todo-conduit-config.h | 79 | ||||
-rw-r--r-- | calendar/conduits/todo/todo-conduit-control-applet.c | 148 | ||||
-rw-r--r-- | calendar/conduits/todo/todo-conduit.c | 157 | ||||
-rw-r--r-- | calendar/conduits/todo/todo-conduit.h | 30 | ||||
-rw-r--r-- | calendar/pcs/cal-backend-file.c | 63 |
9 files changed, 419 insertions, 294 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 524d25cdfb..441fa5e815 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,45 @@ +2000-09-10 JP Rosevear <jpr@helixcode.com> + + * conduits/todo/todo-conduit.c (local_record_from_icalobject): Use + cal component pilot stuff properly + (find_record_in_repository): Remove cruft + (ical_from_remote_record): Remove cruft + (update_record): Set the vtype immediately after creation. Remove cruft + + * conduits/todo/todo-conduit.h: Remove iCalObject stuff + + * conduits/todo/todo-conduit-config.h: Move all the config stuff + here, I need to kill the warnings at some point + + * conduits/todo/todo-conduit-control-applet.c (doRevertSettings): + Set all the state variables correctly on a revert + (doSaveSettings): Update original state + (doHelp): Rename from about_cb + (main): Destroy configurations when done + + * conduits/todo/Makefile.am: Tidy + + * pcs/cal-backend-file.c (cbf_pilot_hash): Function for hashing + pilot ids + (cbf_pilot_equal): For hash table of pilot ids + (cal_backend_file_destroy): Destroy pilot id hash + (add_component): Insert the uid into the pilot hash + (remove_component): Remove the uid from the pilot hash + (cal_backend_file_load): Create the pilot hash + (cal_backend_file_create): ditto + (cal_backend_file_get_uid_by_pilot_id): Implement using the pilot hash + (cal_backend_file_update_pilot_id): ditto + + * cal-util/cal-component.h: Update prototypes + + * cal-util/cal-component.c (cal_component_get_pilot_id): Implement + using ical X properties + (cal_component_set_pilot_id): ditto + (cal_component_get_pilot_status): ditto + (cal_component_set_pilot_status): ditto + (cal_component_free_pilot_id): Free a pilot id + (cal_component_free_pilot_status): Free a pilot status + 2000-09-09 Ettore Perazzoli <ettore@helixcode.com> * gui/dialogs/Makefile.am (INCLUDES): Add diff --git a/calendar/cal-util/cal-component.c b/calendar/cal-util/cal-component.c index 60e0a1bbd5..ff3bcd6d96 100644 --- a/calendar/cal-util/cal-component.c +++ b/calendar/cal-util/cal-component.c @@ -95,6 +95,9 @@ struct _CalComponentPrivate { icalproperty *transparency; icalproperty *url; + icalproperty *pilot_id; + icalproperty *pilot_status; + /* Whether we should increment the sequence number when piping the * object over the wire. */ @@ -560,6 +563,13 @@ scan_property (CalComponent *comp, icalproperty *prop) priv->url = prop; break; + case ICAL_X_PROPERTY: + if (!strcmp (icalproperty_get_x_name (prop), "X-PILOT-ID")) + priv->pilot_id = prop; + if (!strcmp (icalproperty_get_x_name (prop), "X-PILOT-STATUS")) + priv->pilot_status = prop; + break; + default: break; } @@ -2882,11 +2892,29 @@ cal_component_set_url (CalComponent *comp, const char *url) * Queries the pilot id of a calendar component object, if any. **/ void -cal_component_get_pilot_id (CalComponent *comp, unsigned long *pilot_id) +cal_component_get_pilot_id (CalComponent *comp, unsigned long **pilot_id) { - /* pilot_id maybe should be recordid_t */ - /* FIX ME */ - *pilot_id = 0; + CalComponentPrivate *priv; + + g_return_if_fail (comp != NULL); + g_return_if_fail (IS_CAL_COMPONENT (comp)); + + priv = comp->priv; + g_return_if_fail (priv->icalcomp != NULL); + + /* Pilot id might want to be recordid_t */ + if (priv->pilot_id) { + icalvalue *value; + char *text; + + value = icalproperty_get_value (priv->pilot_id); + text = icalvalue_get_text (value); + + *pilot_id = g_new (unsigned long, 1); + **pilot_id = strtoul (text, NULL, 0); + } else { + *pilot_id = NULL; + } } /** @@ -2897,10 +2925,41 @@ cal_component_get_pilot_id (CalComponent *comp, unsigned long *pilot_id) * Sets the pilot id of a clanedar component object. **/ void -cal_component_set_pilot_id (CalComponent *comp, unsigned long pilot_id) +cal_component_set_pilot_id (CalComponent *comp, unsigned long *pilot_id) { + CalComponentPrivate *priv; + icalvalue *value; + char text[256]; + + g_return_if_fail (comp != NULL); + g_return_if_fail (IS_CAL_COMPONENT (comp)); + + priv = comp->priv; + g_return_if_fail (priv->icalcomp != NULL); + /* pilot_id maybe should be recordid_t */ - /* FIX ME */ + if (!pilot_id) { + if (priv->pilot_id) { + icalcomponent_remove_property (priv->icalcomp, + priv->pilot_id); + icalproperty_free (priv->pilot_id); + priv->pilot_id = NULL; + } + + return; + } + + /* iCalendar spec does not support unsigned longs directly */ + g_snprintf (text, 256, "%lu", *pilot_id); + value = icalvalue_new_text (text); + + if (!priv->pilot_id) { + priv->pilot_id = icalproperty_new (ICAL_X_PROPERTY); + icalproperty_set_x_name (priv->pilot_id, "X-PILOT-ID"); + icalcomponent_add_property (priv->icalcomp, priv->pilot_id); + } + + icalproperty_set_value (priv->pilot_id, value); } /** @@ -2911,11 +2970,30 @@ cal_component_set_pilot_id (CalComponent *comp, unsigned long pilot_id) * Queries the pilot status of a calendar component object, if any. **/ void -cal_component_get_pilot_status (CalComponent *comp, unsigned long *pilot_status) +cal_component_get_pilot_status (CalComponent *comp, + unsigned long **pilot_status) { - /* FIX ME */ - /* pilot_status should be iCalPilotState ? */ - *pilot_status = 0; + CalComponentPrivate *priv; + + g_return_if_fail (comp != NULL); + g_return_if_fail (IS_CAL_COMPONENT (comp)); + + priv = comp->priv; + g_return_if_fail (priv->icalcomp != NULL); + + /* Pilot id might want to be recordid_t */ + if (priv->pilot_status) { + icalvalue *value; + char *text; + + value = icalproperty_get_value (priv->pilot_status); + text = icalvalue_get_text (value); + + *pilot_status = g_new (unsigned long, 1); + **pilot_status = strtoul (text, NULL, 0); + } else { + *pilot_status = NULL; + } } /** @@ -2926,10 +3004,41 @@ cal_component_get_pilot_status (CalComponent *comp, unsigned long *pilot_status) * Sets the pilot id of a clanedar component object. **/ void -cal_component_set_pilot_status (CalComponent *comp, unsigned long pilot_status) +cal_component_set_pilot_status (CalComponent *comp, + unsigned long *pilot_status) { - /* pilot_id maybe should be recordid_t */ - /* FIX ME */ + CalComponentPrivate *priv; + icalvalue *value; + char text[256]; + + g_return_if_fail (comp != NULL); + g_return_if_fail (IS_CAL_COMPONENT (comp)); + + priv = comp->priv; + g_return_if_fail (priv->icalcomp != NULL); + + if (!pilot_status) { + if (priv->pilot_status) { + icalcomponent_remove_property (priv->icalcomp, + priv->pilot_status); + icalproperty_free (priv->pilot_status); + priv->pilot_status = NULL; + } + + return; + } + + /* iCalendar spec does not support unsigned longs directly */ + g_snprintf (text, 256, "%lu", *pilot_status); + value = icalvalue_new_text (text); + + if (!priv->pilot_status) { + priv->pilot_status = icalproperty_new (ICAL_X_PROPERTY); + icalproperty_set_x_name (priv->pilot_status, "X-PILOT-STATUS"); + icalcomponent_add_property (priv->icalcomp, priv->pilot_status); + } + + icalproperty_set_value (priv->pilot_status, value); } @@ -3112,6 +3221,34 @@ cal_component_free_sequence (int *sequence) } /** + * cal_component_free_pilot_id: + * @sequence: Sequence number value. + * + * Frees a sequence number value. + **/ +void +cal_component_free_pilot_id (unsigned long *pilot_id) +{ + g_return_if_fail (pilot_id != NULL); + + g_free (pilot_id); +} + +/** + * cal_component_free_pilot_status: + * @sequence: Sequence number value. + * + * Frees a sequence number value. + **/ +void +cal_component_free_pilot_status (unsigned long *pilot_status) +{ + g_return_if_fail (pilot_status != NULL); + + g_free (pilot_status); +} + +/** * cal_component_free_text_list: * @text_list: List of #CalComponentText structures. * diff --git a/calendar/cal-util/cal-component.h b/calendar/cal-util/cal-component.h index 2f9067896b..5fa759748f 100644 --- a/calendar/cal-util/cal-component.h +++ b/calendar/cal-util/cal-component.h @@ -239,11 +239,11 @@ void cal_component_set_transparency (CalComponent *comp, CalComponentTransparenc void cal_component_get_url (CalComponent *comp, const char **url); void cal_component_set_url (CalComponent *comp, const char *url); -void cal_component_get_pilot_id (CalComponent *comp, unsigned long *pilot_id); -void cal_component_set_pilot_id (CalComponent *comp, unsigned long pilot_id); +void cal_component_get_pilot_id (CalComponent *comp, unsigned long **pilot_id); +void cal_component_set_pilot_id (CalComponent *comp, unsigned long *pilot_id); -void cal_component_get_pilot_status (CalComponent *comp, unsigned long *pilot_status); -void cal_component_set_pilot_status (CalComponent *comp, unsigned long pilot_status); +void cal_component_get_pilot_status (CalComponent *comp, unsigned long **pilot_status); +void cal_component_set_pilot_status (CalComponent *comp, unsigned long *pilot_status); /* Functions to free returned values */ @@ -257,6 +257,8 @@ void cal_component_free_priority (int *priority); void cal_component_free_period_list (GSList *period_list); void cal_component_free_recur_list (GSList *recur_list); void cal_component_free_sequence (int *sequence); +void cal_component_free_pilot_id (unsigned long *pilot_status); +void cal_component_free_pilot_status (unsigned long *pilot_status); void cal_component_free_text_list (GSList *text_list); /* Alarms */ diff --git a/calendar/conduits/todo/Makefile.am b/calendar/conduits/todo/Makefile.am index 0dbc404d8e..5f93c81f72 100644 --- a/calendar/conduits/todo/Makefile.am +++ b/calendar/conduits/todo/Makefile.am @@ -6,6 +6,7 @@ INCLUDES = \ $(BONOBO_GNOME_CFLAGS) \ $(GNOME_PILOT_CFLAGS) +# ToDo Capplet bin_PROGRAMS = todo-conduit-control-applet todo_conduit_control_applet_SOURCES = todo-conduit-control-applet.c @@ -23,22 +24,11 @@ todo_conduit_control_applet_LDADD = \ -# todo_conduit +# ToDo Conduit todo_conduitsdir=$(libdir)/gnome-pilot/conduits todo_conduits_LTLIBRARIES = libtodo_conduit.la -libtodo_conduit_la_SOURCES = \ - todo-conduit.c - -# todo-conduit.c: my_gnomecal_idl - -todo.conduit: todo.conduit.in Makefile - sed -e 's^\@prefix\@^$(prefix)^g' < $(srcdir)/todo.conduit.in > todo.conduit.tmp \ - && mv todo.conduit.tmp todo.conduit - -# -# conduit -# +libtodo_conduit_la_SOURCES = todo-conduit.c libtodo_conduit_la_LDFLAGS = \ -rpath $(libdir) @@ -53,6 +43,11 @@ libtodo_conduit_la_LIBADD = \ $(GNOME_LIBDIR) \ $(GNOME_LIBS) +todo.conduit: todo.conduit.in Makefile + sed -e 's^\@prefix\@^$(prefix)^g' < $(srcdir)/todo.conduit.in > todo.conduit.tmp \ + && mv todo.conduit.tmp todo.conduit + + ccenterdir = $(datadir)/control-center ccenterPalmPilotdir = $(ccenterdir)/Peripherals ccenterConduitsdir = $(ccenterPalmPilotdir)/Conduits diff --git a/calendar/conduits/todo/todo-conduit-config.h b/calendar/conduits/todo/todo-conduit-config.h new file mode 100644 index 0000000000..fb4d35c7e8 --- /dev/null +++ b/calendar/conduits/todo/todo-conduit-config.h @@ -0,0 +1,79 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +#ifndef __TODO_CONDUIT_CONFIG_H__ +#define __TODO_CONDUIT_CONFIG_H__ + +#include <gnome.h> +#include <libgpilotdCM/gnome-pilot-conduit-management.h> +#include <libgpilotdCM/gnome-pilot-conduit-config.h> + +/* This is the configuration of the GnomeCal conduit. */ +typedef struct _ToDoConduitCfg ToDoConduitCfg; +struct _ToDoConduitCfg { + gboolean open_secret; + guint32 pilotId; + GnomePilotConduitSyncType sync_type; /* only used by capplet */ +}; + +static void +todoconduit_load_configuration (ToDoConduitCfg **c, guint32 pilotId) +{ + gchar prefix[256]; + g_snprintf (prefix,255,"/gnome-pilot.d/todo-conduit/Pilot_%u/",pilotId); + + *c = g_new0 (ToDoConduitCfg,1); + g_assert (*c != NULL); + gnome_config_push_prefix (prefix); + (*c)->open_secret = gnome_config_get_bool ("open_secret=FALSE"); + (*c)->sync_type = GnomePilotConduitSyncTypeCustom; /* set in capplets main */ + gnome_config_pop_prefix (); + + (*c)->pilotId = pilotId; +} + +/* Saves the configuration data. */ +static void +todoconduit_save_configuration (ToDoConduitCfg *c) +{ + gchar prefix[256]; + + g_snprintf(prefix,255,"/gnome-pilot.d/todo-conduit/Pilot_%u/",c->pilotId); + + gnome_config_push_prefix(prefix); + gnome_config_set_bool ("open_secret", c->open_secret); + gnome_config_pop_prefix(); + + gnome_config_sync(); + gnome_config_drop_all(); +} + +/* Creates a duplicate of the configuration data */ +static ToDoConduitCfg* +todoconduit_dupe_configuration (ToDoConduitCfg *c) +{ + ToDoConduitCfg *retval; + g_return_val_if_fail (c!=NULL,NULL); + retval = g_new0 (ToDoConduitCfg,1); + retval->sync_type = c->sync_type; + retval->open_secret = c->open_secret; + retval->pilotId = c->pilotId; + return retval; +} + +static void +todoconduit_destroy_configuration (ToDoConduitCfg **c) +{ + g_return_if_fail (c!=NULL); + g_return_if_fail (*c!=NULL); + g_free (*c); + *c = NULL; +} + +#endif __TODO_CONDUIT_CONFIG_H__ + + + + + + + diff --git a/calendar/conduits/todo/todo-conduit-control-applet.c b/calendar/conduits/todo/todo-conduit-control-applet.c index 811d7fe8e2..b8b0a36dc0 100644 --- a/calendar/conduits/todo/todo-conduit-control-applet.c +++ b/calendar/conduits/todo/todo-conduit-control-applet.c @@ -11,12 +11,9 @@ #include <config.h> #include <capplet-widget.h> -#include <libgpilotdCM/gnome-pilot-conduit-management.h> -#include <libgpilotdCM/gnome-pilot-conduit-config.h> #include <gpilotd/gnome-pilot-client.h> -#include "todo-conduit.h" - +#include "todo-conduit-config.h" /* tell changes callbacks to ignore changes or not */ static gboolean ignore_changes=FALSE; @@ -32,18 +29,17 @@ GtkWidget *dialogWindow=NULL; gboolean activated,org_activation_state; GnomePilotConduitManagement *conduit; GnomePilotConduitConfig *conduit_config; -GCalConduitCfg *origState = NULL; -GCalConduitCfg *curState = NULL; +ToDoConduitCfg *origState = NULL; +ToDoConduitCfg *curState = NULL; -static void doTrySettings(GtkWidget *widget, GCalConduitCfg *GCalConduitCfg); -static void doRevertSettings(GtkWidget *widget, GCalConduitCfg *GCalConduitCfg); -static void doSaveSettings(GtkWidget *widget, GCalConduitCfg *GCalConduitCfg); +static void doTrySettings(GtkWidget *widget, ToDoConduitCfg *c); +static void doRevertSettings(GtkWidget *widget, ToDoConduitCfg *c); +static void doSaveSettings(GtkWidget *widget, ToDoConduitCfg *c); -//static void readStateCfg (GtkWidget *w, GCalConduitCfg *c); -static void setStateCfg (GtkWidget *w, GCalConduitCfg *c); +static void readStateCfg (GtkWidget *w, ToDoConduitCfg *c); +static void setStateCfg (GtkWidget *w, ToDoConduitCfg *c); gint pilotId; -CORBA_Environment ev; static GnomePilotClient *gpc; @@ -60,50 +56,10 @@ static gchar* sync_options[] ={ N_("Disabled"), N_("Merge To Pilot")}; #define SYNC_OPTIONS_COUNT 6 - - - -/* Saves the configuration data. */ -static void -gcalconduit_save_configuration(GCalConduitCfg *c) -{ - gchar prefix[256]; - - g_snprintf(prefix,255,"/gnome-pilot.d/todo-conduit/Pilot_%u/",c->pilotId); - - gnome_config_push_prefix(prefix); - gnome_config_set_bool ("open_secret", c->open_secret); - gnome_config_pop_prefix(); - - gnome_config_sync(); - gnome_config_drop_all(); -} - -/* Creates a duplicate of the configuration data */ -static GCalConduitCfg* -gcalconduit_dupe_configuration(GCalConduitCfg *c) { - GCalConduitCfg *retval; - g_return_val_if_fail(c!=NULL,NULL); - retval = g_new0(GCalConduitCfg,1); - retval->sync_type = c->sync_type; - retval->open_secret = c->open_secret; - retval->pilotId = c->pilotId; - return retval; -} - - static void -doTrySettings(GtkWidget *widget, GCalConduitCfg *c) +doTrySettings (GtkWidget *widget, ToDoConduitCfg *c) { - /* - readStateCfg (cfgStateWindow, curState); - if (activated) - gnome_pilot_conduit_config_enable (conduit_config, GnomePilotConduitSyncTypeCustom); - else - gnome_pilot_conduit_config_disable (conduit_config); - */ - - if (c->sync_type!=GnomePilotConduitSyncTypeCustom) + if (c->sync_type != GnomePilotConduitSyncTypeCustom) gnome_pilot_conduit_config_enable_with_first_sync (conduit_config, c->sync_type, c->sync_type, @@ -111,34 +67,28 @@ doTrySettings(GtkWidget *widget, GCalConduitCfg *c) else gnome_pilot_conduit_config_disable (conduit_config); - gcalconduit_save_configuration (c); + todoconduit_save_configuration (c); } - static void -doSaveSettings(GtkWidget *widget, GCalConduitCfg *GCalConduitCfg) +doRevertSettings (GtkWidget *widget, ToDoConduitCfg *c) { - doTrySettings(widget, GCalConduitCfg); - gcalconduit_save_configuration(GCalConduitCfg); + activated = org_activation_state; + *c = *origState; + setStateCfg (cfgStateWindow, c); + doTrySettings (widget, c); } - static void -doCancelSettings(GtkWidget *widget, GCalConduitCfg *c) +doSaveSettings (GtkWidget *widget, ToDoConduitCfg *c) { - doSaveSettings (widget, c); + *origState = *c; + doTrySettings (widget, c); } -static void -doRevertSettings(GtkWidget *widget, GCalConduitCfg *GCalConduitCfg) -{ - activated = org_activation_state; - setStateCfg (cfgStateWindow, curState); -} - static void -about_cb (GtkWidget *widget, gpointer data) +doHelp (GtkWidget *widget, gpointer data) { GtkWidget *about; const gchar *authors[] = {_("Eskil Heyn Olsen <deity@eskil.dk>"),NULL}; @@ -156,16 +106,6 @@ about_cb (GtkWidget *widget, gpointer data) /* called by the sync_type GtkOptionMenu */ static void -sync_action_selection(GtkMenuShell *widget, gpointer unused) -{ - if (!ignore_changes) { - capplet_widget_state_changed(CAPPLET_WIDGET (capplet), TRUE); - } -} - - -/* called by the sync_type GtkOptionMenu */ -static void activate_sync_type(GtkMenuItem *widget, gpointer data) { curState->sync_type = GPOINTER_TO_INT(data); @@ -206,10 +146,6 @@ static GtkWidget } gtk_option_menu_set_menu(GTK_OPTION_MENU(optionMenu),GTK_WIDGET(menu)); - gtk_signal_connect(GTK_OBJECT(menu), "selection-done", - GTK_SIGNAL_FUNC(sync_action_selection), - NULL); - gtk_box_pack_start(GTK_BOX(table), optionMenu, FALSE, FALSE, 0); return vbox; @@ -217,7 +153,7 @@ static GtkWidget static void -setStateCfg (GtkWidget *w, GCalConduitCfg *c) +setStateCfg (GtkWidget *w, ToDoConduitCfg *c) { GtkOptionMenu *optionMenu; GtkMenu *menu; @@ -234,18 +170,10 @@ setStateCfg (GtkWidget *w, GCalConduitCfg *c) } -#if 0 static void -readStateCfg (GtkWidget *w, GCalConduitCfg *c) +readStateCfg (GtkWidget *w, ToDoConduitCfg *c) { - /* - GtkWidget *button; - button = gtk_object_get_data(GTK_OBJECT(cfg), "conduit_on_off"); - g_assert(button!=NULL); - activated = GTK_TOGGLE_BUTTON(button)->active; - */ } -#endif /* 0 */ static void @@ -271,10 +199,8 @@ pilot_capplet_setup(void) GTK_SIGNAL_FUNC(doRevertSettings), curState); gtk_signal_connect(GTK_OBJECT(capplet), "ok", GTK_SIGNAL_FUNC(doSaveSettings), curState); - gtk_signal_connect(GTK_OBJECT(capplet), "cancel", - GTK_SIGNAL_FUNC(doCancelSettings), curState); gtk_signal_connect(GTK_OBJECT(capplet), "help", - GTK_SIGNAL_FUNC(about_cb), NULL); + GTK_SIGNAL_FUNC(doHelp), NULL); setStateCfg (cfgStateWindow, curState); @@ -363,25 +289,29 @@ main (int argc, char *argv[]) if (!pilotId) return -1; - /* put all code to set things up in here */ - gcalconduit_load_configuration (&origState, pilotId); - + + /* Put all code to set things up in here */ conduit = gnome_pilot_conduit_management_new ("todo_conduit", GNOME_PILOT_CONDUIT_MGMT_ID); - if (conduit == NULL) return -1; + if (conduit == NULL) + return -1; + + todoconduit_load_configuration (&origState, pilotId); conduit_config = gnome_pilot_conduit_config_new (conduit, pilotId); - org_activation_state = gnome_pilot_conduit_config_is_enabled (conduit_config, - &origState->sync_type); - activated = org_activation_state; + org_activation_state = activated = + gnome_pilot_conduit_config_is_enabled (conduit_config, + &origState->sync_type); - curState = gcalconduit_dupe_configuration(origState); + curState = todoconduit_dupe_configuration (origState); pilot_capplet_setup (); - - /* done setting up, now run main loop */ + /* Done setting up, now run main loop */ capplet_gtk_main(); - - gnome_pilot_conduit_management_destroy(conduit); + /* Clean up */ + gnome_pilot_conduit_management_destroy (conduit); + todoconduit_destroy_configuration (&origState); + todoconduit_destroy_configuration (&curState); + return 0; } diff --git a/calendar/conduits/todo/todo-conduit.c b/calendar/conduits/todo/todo-conduit.c index 3ba9506854..2734f9cc79 100644 --- a/calendar/conduits/todo/todo-conduit.c +++ b/calendar/conduits/todo/todo-conduit.c @@ -9,7 +9,6 @@ #include <errno.h> #include <cal-client/cal-client.h> -// #include <cal-util/calobj.h> #include <cal-util/timeutil.h> #include <pi-source.h> #include <pi-socket.h> @@ -20,13 +19,12 @@ #include <pi-version.h> #include <gpilotd/gnome-pilot-conduit.h> #include <gpilotd/gnome-pilot-conduit-standard-abs.h> +#include <todo-conduit-config.h> #include <todo-conduit.h> #include <libical/src/libical/icaltypes.h> #include <bonobo.h> -//#include "GnomeCal.h" - GnomePilotConduit * conduit_get_gpilot_conduit (guint32); void conduit_destroy_gpilot_conduit (GnomePilotConduit*); void local_record_from_icalobject (GCalLocalRecord *local, CalComponent *obj); @@ -35,7 +33,10 @@ void local_record_from_icalobject (GCalLocalRecord *local, CalComponent *obj); #ifdef G_LOG_DOMAIN #undef G_LOG_DOMAIN #endif -#define G_LOG_DOMAIN "todoconduit" +#define G_LOG_DOMAIN "todoconduit" + +#define GET_TODOCONFIG(c) ((ToDoConduitCfg*)gtk_object_get_data(GTK_OBJECT(c),"todoconduit_cfg")) + #define DEBUG_CALCONDUIT 1 /* #undef DEBUG_CALCONDUIT */ @@ -59,49 +60,6 @@ void local_record_from_icalobject (GCalLocalRecord *local, CalComponent *obj); return ret; \ } - - -/* debug spew DELETE ME */ -static char *print_ical (CalComponent *obj - /*iCalObject *obj*/) -{ - static char buff[ 4096 ]; - - int indefinite; - CalComponentDateTime dtend; - int priority; - struct icaltimetype *complete; - CalComponentText summary; - GSList *comments; - CalComponentText *first_comment = NULL; - - if (obj == NULL) { - sprintf (buff, "[NULL]"); - return buff; - } - - indefinite = 0; /* FIX ME how do i get this */ - cal_component_get_dtend (obj, &dtend); - priority = 1; /* FIX ME how do i get this */ - cal_component_get_completed (obj, &complete); - - cal_component_get_summary (obj, &summary); - cal_component_get_comment_list (obj, &comments); - if (comments) - first_comment = (CalComponentText *) comments->data; - - sprintf (buff, "[%d %d-%d-%d %d %d-%d-%d '%s' '%s']", - indefinite, - dtend.value->year, dtend.value->month, dtend.value->day, - priority, - complete->year, complete->month, complete->day, - summary.value, /* description */ - first_comment ? first_comment->value : "" /* note */ - ); - return buff; -} - - /* debug spew DELETE ME */ static char *print_local (GCalLocalRecord *local) { @@ -123,7 +81,7 @@ static char *print_local (GCalLocalRecord *local) return buff; } - return print_ical (local->ical); + return cal_component_get_as_string (local->ical); } @@ -152,25 +110,10 @@ static char *print_remote (PilotRecord *remote) return buff; } - - - -/* Destroys any data allocated by gcalconduit_load_configuration - and deallocates the given configuration. */ -static void -gcalconduit_destroy_configuration(GCalConduitCfg **c) -{ - g_return_if_fail(c!=NULL); - g_return_if_fail(*c!=NULL); - g_free(*c); - *c = NULL; -} - - /* Given a GCalConduitContxt*, allocates the structure */ static void gcalconduit_new_context(GCalConduitContext **ctxt, - GCalConduitCfg *c) + ToDoConduitCfg *c) { *ctxt = g_new0(GCalConduitContext,1); g_assert(ctxt!=NULL); @@ -188,7 +131,7 @@ gcalconduit_destroy_context(GCalConduitContext **ctxt) g_return_if_fail(*ctxt!=NULL); /* if ((*ctxt)->cfg!=NULL) - gcalconduit_destroy_configuration(&((*ctxt)->cfg)); + todoconduit_destroy_configuration(&((*ctxt)->cfg)); */ g_free(*ctxt); *ctxt = NULL; @@ -256,13 +199,6 @@ start_calendar_server (GnomePilotConduitStandardAbs *conduit, } -#if 0 -/* Just a stub to link with */ -void calendar_notify (time_t time, CalendarAlarm *which, void *data); -void calendar_notify (time_t time, CalendarAlarm *which, void *data) { } -#endif /* 0 */ - - static GSList * get_calendar_objects(GnomePilotConduitStandardAbs *conduit, gboolean *status, @@ -276,7 +212,7 @@ get_calendar_objects(GnomePilotConduitStandardAbs *conduit, uids = cal_client_get_uids (ctxt->client, CALOBJ_TYPE_TODO); - // LOG ("got %d todo entries from cal server\n", g_list_length (uids)); + LOG ("got %d todo entries from cal server\n", g_list_length (uids)); if (status != NULL) (*status) = TRUE; @@ -338,8 +274,7 @@ void local_record_from_icalobject(GCalLocalRecord *local, CalComponent *obj) { - //iCalPilotState pilot_status; - unsigned long int pilot_status; + unsigned long *pilot_status; g_return_if_fail(local!=NULL); g_return_if_fail(obj!=NULL); @@ -349,7 +284,7 @@ local_record_from_icalobject(GCalLocalRecord *local, cal_component_get_pilot_id (obj, &local->local.ID); cal_component_get_pilot_status (obj, &pilot_status); - switch (pilot_status) { + switch (*pilot_status) { case ICAL_PILOT_SYNC_NONE: local->local.attr = GnomePilotRecordNothing; break; @@ -360,7 +295,7 @@ local_record_from_icalobject(GCalLocalRecord *local, local->local.attr = GnomePilotRecordDeleted; break; default: - g_warning ("unhandled pilot status: %ld\n", pilot_status); + g_warning ("unhandled pilot status: %lu\n", pilot_status); } /* Records without a pilot_id are new */ @@ -390,7 +325,6 @@ find_record_in_repository(GnomePilotConduitStandardAbs *conduit, char *uid = NULL; GCalLocalRecord *loc; CalClientGetStatus status; - //iCalObject *obj; CalComponent *obj; g_return_val_if_fail(conduit!=NULL,NULL); @@ -399,14 +333,14 @@ find_record_in_repository(GnomePilotConduitStandardAbs *conduit, LOG ("find_record_in_repository: remote=%s... ", print_remote (remote)); - // LOG ("requesting %ld", remote->ID); + LOG ("requesting %ld", remote->ID); status = cal_client_get_uid_by_pilot_id (ctxt->client, remote->ID, &uid); if (status == CAL_CLIENT_GET_SUCCESS) { status = cal_client_get_object (ctxt->client, uid, &obj); if (status == CAL_CLIENT_GET_SUCCESS) { - LOG ("found %s\n", print_ical (obj)); + LOG ("found %s\n", cal_component_get_as_string (obj)); loc = g_new0(GCalLocalRecord,1); /* memory allocated in new_from_string is freed in free_match */ local_record_from_icalobject (loc, obj); @@ -434,12 +368,11 @@ update_calendar_entry_in_repository(GnomePilotConduitStandardAbs *conduit, g_return_if_fail (obj!=NULL); LOG (" update_calendar_entry_in_repository " - "saving %s to desktop\n", - print_ical (obj)); + "saving %s to desktop\n", cal_component_get_as_string (obj)); success = cal_client_update_object (ctxt->client, obj); - if (! success) { + if (!success) { WARN (_("Error while communicating with calendar server")); } } @@ -464,7 +397,7 @@ ical_from_remote_record (GnomePilotConduitStandardAbs *conduit, LOG (" ical_from_remote_record: " "merging remote %s into local %s\n", - print_remote (remote), print_ical (in_obj)); + print_remote (remote), cal_component_get_as_string (in_obj)); if (in_obj == NULL) { obj = cal_component_new (); @@ -481,16 +414,10 @@ ical_from_remote_record (GnomePilotConduitStandardAbs *conduit, g_slist_free (comment_list); cal_component_set_new_vtype (obj, CAL_COMPONENT_TODO); - // obj->new = TRUE; - // obj->created = now; cal_component_set_created (obj, &now); - // obj->last_mod = now; cal_component_set_last_modified (obj, &now); /* obj->priority = 0; */ - // obj->transp = 0; - cal_component_set_transparency (obj, - /*CalComponentTransparency transp*/ - CAL_COMPONENT_TRANSP_NONE); + cal_component_set_transparency (obj, CAL_COMPONENT_TRANSP_NONE); /* obj->related = NULL; */ // cal_component_set_pilot_status (obj, ICAL_PILOT_SYNC_NONE); @@ -568,7 +495,6 @@ update_record (GnomePilotConduitStandardAbs *conduit, PilotRecord *remote, GCalConduitContext *ctxt) { - //iCalObject *obj; CalComponent *obj; struct ToDo todo; CalClientGetStatus status; @@ -599,7 +525,8 @@ update_record (GnomePilotConduitStandardAbs *conduit, LOG ("failed, making a new one.\n"); obj = cal_component_new (); - + cal_component_set_new_vtype (obj, CAL_COMPONENT_TODO); + summary.value = todo.description; cal_component_set_summary (obj, &summary); @@ -608,27 +535,17 @@ update_record (GnomePilotConduitStandardAbs *conduit, cal_component_set_comment_list (obj, comment_list); g_slist_free (comment_list); - // obj->type = ICAL_TODO; - cal_component_set_new_vtype (obj, CAL_COMPONENT_TODO); - // obj->new = TRUE; - // obj->created = now; cal_component_set_created (obj, &now); - // obj->last_mod = now; cal_component_set_last_modified (obj, &now); // obj->priority = 0; - // obj->transp = 0; - cal_component_set_transparency (obj, - /*CalComponentTransparency transp*/ - CAL_COMPONENT_TRANSP_NONE); + cal_component_set_transparency (obj, CAL_COMPONENT_TRANSP_NONE); // obj->related = NULL; - //obj->pilot_id = remote->ID; - //obj->pilot_status = ICAL_PILOT_SYNC_NONE; - cal_component_set_pilot_id (obj, remote->ID); - cal_component_set_pilot_status (obj, ICAL_PILOT_SYNC_NONE); + cal_component_set_pilot_id (obj, &remote->ID); +// cal_component_set_pilot_status (obj, ICAL_PILOT_SYNC_NONE); } else { CalComponent *new_obj; - LOG ("succeeded %s\n", print_ical (obj)); + LOG ("succeeded %s\n", cal_component_get_as_string (obj)); new_obj = ical_from_remote_record (conduit, remote, obj); obj = new_obj; @@ -637,20 +554,20 @@ update_record (GnomePilotConduitStandardAbs *conduit, /* update record on server */ { const char *uid; - unsigned long pilot_id; + unsigned long *pilot_id; cal_component_get_uid (obj, &uid); cal_component_get_pilot_id (obj, &pilot_id); update_calendar_entry_in_repository (conduit, obj, ctxt); - cal_client_update_pilot_id (ctxt->client, (char *) uid, pilot_id, - ICAL_PILOT_SYNC_NONE); + cal_client_update_pilot_id (ctxt->client, (char *) uid, + *pilot_id, ICAL_PILOT_SYNC_NONE); } /* * Shutdown */ - //ical_object_unref (obj); + gtk_object_unref (GTK_OBJECT (obj)); free_ToDo(&todo); return 0; @@ -1055,7 +972,7 @@ set_pilot_id (GnomePilotConduitStandardAbs *conduit, GCalConduitContext *ctxt) { const char *uid; - unsigned long int pilot_status; + unsigned long *pilot_status; LOG ("set_pilot_id: %s pilot ID is now '%d'\n", print_local (local), ID); @@ -1064,7 +981,7 @@ set_pilot_id (GnomePilotConduitStandardAbs *conduit, g_assert(local->ical!=NULL); local->local.ID = ID; - cal_component_set_pilot_id (local->ical, ID); + cal_component_set_pilot_id (local->ical, &ID); cal_component_get_uid (local->ical, &uid); cal_component_get_pilot_status (local->ical, &pilot_status); @@ -1072,7 +989,7 @@ set_pilot_id (GnomePilotConduitStandardAbs *conduit, cal_client_update_pilot_id (ctxt->client, (char *) uid, local->local.ID, - pilot_status); + *pilot_status); return 0; } @@ -1261,7 +1178,7 @@ delete_all (GnomePilotConduitStandardAbs *conduit, } g_slist_free (events); - return -1; + return 0; } @@ -1279,7 +1196,7 @@ GnomePilotConduit * conduit_get_gpilot_conduit (guint32 pilotId) { GtkObject *retval; - GCalConduitCfg *cfg; + ToDoConduitCfg *cfg; GCalConduitContext *ctxt; LOG ("in todo's conduit_get_gpilot_conduit\n"); @@ -1304,7 +1221,7 @@ conduit_get_gpilot_conduit (guint32 pilotId) g_assert (retval != NULL); gnome_pilot_conduit_construct(GNOME_PILOT_CONDUIT(retval),"ToDoConduit"); - gcalconduit_load_configuration(&cfg,pilotId); + todoconduit_load_configuration(&cfg,pilotId); gtk_object_set_data(retval,"todoconduit_cfg",cfg); gcalconduit_new_context(&ctxt,cfg); @@ -1335,10 +1252,10 @@ conduit_get_gpilot_conduit (guint32 pilotId) void conduit_destroy_gpilot_conduit (GnomePilotConduit *conduit) { - GCalConduitCfg *cc; + ToDoConduitCfg *cc; GCalConduitContext *ctxt; - cc = GET_GCALCONFIG(conduit); + cc = GET_TODOCONFIG (conduit); ctxt = GET_GCALCONTEXT(conduit); if (ctxt->client != NULL) { @@ -1347,7 +1264,7 @@ conduit_destroy_gpilot_conduit (GnomePilotConduit *conduit) //GNOME_Calendar_Repository_done (ctxt->calendar, &(ctxt->ev)); } - gcalconduit_destroy_configuration (&cc); + todoconduit_destroy_configuration (&cc); gcalconduit_destroy_context (&ctxt); diff --git a/calendar/conduits/todo/todo-conduit.h b/calendar/conduits/todo/todo-conduit.h index 31970ce356..89cc60e920 100644 --- a/calendar/conduits/todo/todo-conduit.h +++ b/calendar/conduits/todo/todo-conduit.h @@ -25,8 +25,8 @@ struct _GCalLocalRecord { structure cannot be used by gnome-pilot-conduit-standard-abs. */ LocalRecord local; - /* The corresponding iCal object, as found by GnomeCal. */ - //iCalObject *ical; + + /* The corresponding Comp object, as found by GnomeCal. */ CalComponent *ical; /* pilot-link todo structure, used for implementing Transmit. */ @@ -47,7 +47,7 @@ struct _GCalConduitCfg { typedef struct _GCalConduitContext GCalConduitContext; struct _GCalConduitContext { struct ToDoAppInfo ai; - GCalConduitCfg *cfg; + ToDoConduitCfg *cfg; CalClient *client; CORBA_Environment ev; CORBA_ORB orb; @@ -58,28 +58,6 @@ struct _GCalConduitContext { }; #define GET_GCALCONTEXT(c) ((GCalConduitContext*)gtk_object_get_data(GTK_OBJECT(c),"todoconduit_context")) - -/* Given a GCalConduitCfg*, allocates the structure and - loads the configuration data for the given pilot. - this is defined in the header file because it is used by - both todo-conduit and todo-conduit-control-applet, - and we don't want to export any symbols we don't have to. */ -static void -gcalconduit_load_configuration(GCalConduitCfg **c, - guint32 pilotId) -{ - gchar prefix[256]; - g_snprintf(prefix,255,"/gnome-pilot.d/todo-conduit/Pilot_%u/",pilotId); - - *c = g_new0(GCalConduitCfg,1); - g_assert(*c != NULL); - gnome_config_push_prefix(prefix); - (*c)->open_secret = gnome_config_get_bool("open_secret=FALSE"); - (*c)->sync_type = GnomePilotConduitSyncTypeCustom; /* set in capplets main */ - gnome_config_pop_prefix(); - - (*c)->pilotId = pilotId; -} +#endif __TODO_CONDUIT_H__ -#endif __TODO_CONDUIT_H__ diff --git a/calendar/pcs/cal-backend-file.c b/calendar/pcs/cal-backend-file.c index c60c0c118a..5b03150001 100644 --- a/calendar/pcs/cal-backend-file.c +++ b/calendar/pcs/cal-backend-file.c @@ -44,6 +44,13 @@ struct _CalBackendFilePrivate { */ GHashTable *comp_uid_hash; + /* All the uids in the calendar, hashed by pilot ID. The + * hash key *is* the pilot id returned by cal_component_get_pilot_id(); + * it is not copied, so don't free it when you remove an object from + * the hash table. + */ + GHashTable *comp_pilot_hash; + /* All event, to-do, and journal components in the calendar; they are * here just for easy access (i.e. so that you don't have to iterate * over the comp_uid_hash). If you need *all* the components in the @@ -173,6 +180,20 @@ free_cal_component (gpointer key, gpointer value, gpointer data) gtk_object_unref (GTK_OBJECT (comp)); } +/* For hashing pilot id's */ +/* FIX ME, these are not unique */ +static guint +cbf_pilot_hash (gconstpointer v) +{ + return *(const guint*) v; +} + +static gint +cbf_pilot_equal (gconstpointer v1, gconstpointer v2) +{ + return *((const unsigned long*) v1) == *((const unsigned long*) v2); +} + /* Saves the calendar data */ static void save (CalBackendFile *cbfile) @@ -250,11 +271,17 @@ cal_backend_file_destroy (GtkObject *object) } if (priv->comp_uid_hash) { - g_hash_table_foreach (priv->comp_uid_hash, free_cal_component, NULL); + g_hash_table_foreach (priv->comp_uid_hash, + free_cal_component, NULL); g_hash_table_destroy (priv->comp_uid_hash); priv->comp_uid_hash = NULL; } + if (priv->comp_pilot_hash) { + g_hash_table_destroy (priv->comp_pilot_hash); + priv->comp_pilot_hash = NULL; + } + g_list_free (priv->events); g_list_free (priv->todos); g_list_free (priv->journals); @@ -445,7 +472,8 @@ add_component (CalBackendFile *cbfile, CalComponent *comp, gboolean add_to_tople CalBackendFilePrivate *priv; GList **list; const char *uid; - + unsigned long *pilot_id; + priv = cbfile->priv; switch (cal_component_get_vtype (comp)) { @@ -471,8 +499,14 @@ add_component (CalBackendFile *cbfile, CalComponent *comp, gboolean add_to_tople */ check_dup_uid (cbfile, comp); cal_component_get_uid (comp, &uid); - g_hash_table_insert (priv->comp_uid_hash, (char *) uid, comp); + + /* Update the pilot list, if there is a pilot id */ + cal_component_get_pilot_id (comp, &pilot_id); + if (pilot_id) + g_hash_table_insert (priv->comp_pilot_hash, + pilot_id, (char *)uid); + *list = g_list_prepend (*list, comp); /* Put the object in the toplevel component if required */ @@ -497,6 +531,7 @@ remove_component (CalBackendFile *cbfile, CalComponent *comp) CalBackendFilePrivate *priv; icalcomponent *icalcomp; const char *uid; + unsigned long *pilot_id; GList **list, *l; priv = cbfile->priv; @@ -511,8 +546,10 @@ remove_component (CalBackendFile *cbfile, CalComponent *comp) /* Remove it from our mapping */ cal_component_get_uid (comp, &uid); + cal_component_get_pilot_id (comp, &pilot_id); g_hash_table_remove (priv->comp_uid_hash, uid); - + g_hash_table_remove (priv->comp_pilot_hash, pilot_id); + switch (cal_component_get_vtype (comp)) { case CAL_COMPONENT_EVENT: list = &priv->events; @@ -642,6 +679,7 @@ cal_backend_file_load (CalBackend *backend, GnomeVFSURI *uri) priv->icalcomp = icalcomp; priv->comp_uid_hash = g_hash_table_new (g_str_hash, g_str_equal); + priv->comp_pilot_hash = g_hash_table_new (cbf_pilot_hash, cbf_pilot_equal); scan_vcalendar (cbfile); /* Clean up */ @@ -687,6 +725,7 @@ cal_backend_file_create (CalBackend *backend, GnomeVFSURI *uri) g_assert (priv->comp_uid_hash == NULL); priv->comp_uid_hash = g_hash_table_new (g_str_hash, g_str_equal); + priv->comp_pilot_hash = g_hash_table_new (cbf_pilot_hash, cbf_pilot_equal); /* Done */ @@ -1074,14 +1113,14 @@ cal_backend_file_get_uid_by_pilot_id (CalBackend *backend, unsigned long int pil { CalBackendFile *cbfile; CalBackendFilePrivate *priv; + char *uid; cbfile = CAL_BACKEND_FILE (backend); priv = cbfile->priv; - g_return_val_if_fail (priv->icalcomp != NULL, FALSE); + uid = g_hash_table_lookup (priv->comp_pilot_hash, &pilot_id); - /* FIXME */ - return NULL; + return uid; } /* Update_pilot_id handler for the file backend */ @@ -1093,13 +1132,19 @@ cal_backend_file_update_pilot_id (CalBackend *backend, { CalBackendFile *cbfile; CalBackendFilePrivate *priv; + CalComponent *comp; cbfile = CAL_BACKEND_FILE (backend); priv = cbfile->priv; g_return_if_fail (priv->icalcomp != NULL); - g_return_if_fail (uid != NULL); - /* FIXME */ + comp = lookup_component (cbfile, uid); + if (!comp) + return; + + cal_component_set_pilot_id (comp, &pilot_id); + cal_component_set_pilot_status (comp, &pilot_status); } + |