diff options
author | Eskil Heyn Olsen <eskil@src.gnome.org> | 1999-10-22 09:16:15 +0800 |
---|---|---|
committer | Eskil Heyn Olsen <eskil@src.gnome.org> | 1999-10-22 09:16:15 +0800 |
commit | 47f01927e15b6eb279d2cbf046b2707467096666 (patch) | |
tree | 9a61c996094c07640cad5f1d77b0956e4f361b48 /calendar | |
parent | 0a505aa40e7504dec10119c0bb4c84087e3d06d4 (diff) | |
download | gsoc2013-evolution-47f01927e15b6eb279d2cbf046b2707467096666.tar gsoc2013-evolution-47f01927e15b6eb279d2cbf046b2707467096666.tar.gz gsoc2013-evolution-47f01927e15b6eb279d2cbf046b2707467096666.tar.bz2 gsoc2013-evolution-47f01927e15b6eb279d2cbf046b2707467096666.tar.lz gsoc2013-evolution-47f01927e15b6eb279d2cbf046b2707467096666.tar.xz gsoc2013-evolution-47f01927e15b6eb279d2cbf046b2707467096666.tar.zst gsoc2013-evolution-47f01927e15b6eb279d2cbf046b2707467096666.zip |
now it doesn't build todo conduit anymore. Since the conduit is just a
* Makefile.am: now it doesn't build todo conduit
anymore. Since the conduit is just a skeleton, no need to
build and install it.
* calendar-conduit-control-applet.c: revamped for all the
changes in calendar-conduit.h. Also fixed the pilotId bug that
all conduit capplets had.
* calendar-conduit-control-applet.desktop: renamed to
GnomeCalendar.
* calendar-conduit.h: Fixed namespace pollution, appended GCal
to structures, gcalconduit to methods. Introduced the
GCalConduitContext.
* calendar-conduit.c: No more global variables, all is contained
in a GCalConduitContext variable, that all the signals are
passed as user data.
svn path=/trunk/; revision=1338
Diffstat (limited to 'calendar')
-rw-r--r-- | calendar/Makefile.am | 43 | ||||
-rw-r--r-- | calendar/calendar-conduit-control-applet.c | 70 | ||||
-rw-r--r-- | calendar/calendar-conduit-control-applet.desktop | 4 | ||||
-rw-r--r-- | calendar/calendar-conduit.c | 389 | ||||
-rw-r--r-- | calendar/calendar-conduit.h | 132 | ||||
-rw-r--r-- | calendar/conduits/calendar/calendar-conduit-control-applet.c | 70 | ||||
-rw-r--r-- | calendar/conduits/calendar/calendar-conduit-control-applet.desktop | 4 | ||||
-rw-r--r-- | calendar/conduits/calendar/calendar-conduit.c | 389 | ||||
-rw-r--r-- | calendar/conduits/calendar/calendar-conduit.h | 132 | ||||
-rw-r--r-- | calendar/conduits/todo/todo-conduit-control-applet.c | 46 | ||||
-rw-r--r-- | calendar/gui/Makefile.am | 43 | ||||
-rw-r--r-- | calendar/gui/calendar-conduit-control-applet.c | 70 | ||||
-rw-r--r-- | calendar/gui/calendar-conduit-control-applet.desktop | 4 | ||||
-rw-r--r-- | calendar/gui/calendar-conduit.c | 389 | ||||
-rw-r--r-- | calendar/gui/calendar-conduit.h | 132 | ||||
-rw-r--r-- | calendar/gui/todo-conduit-control-applet.c | 46 | ||||
-rw-r--r-- | calendar/todo-conduit-control-applet.c | 46 |
17 files changed, 1116 insertions, 893 deletions
diff --git a/calendar/Makefile.am b/calendar/Makefile.am index cb03a4eacb..4042368bff 100644 --- a/calendar/Makefile.am +++ b/calendar/Makefile.am @@ -11,7 +11,6 @@ help_base = $(datadir)/gnome/help/cal if HAVE_GNOME_PILOT bin_PROGRAMS = \ gnomecal \ - todo-conduit-control-applet \ calendar-conduit-control-applet \ calendar-pilot-sync else @@ -158,34 +157,34 @@ calendar_conduit_control_applet_LDADD = \ $(INTLLIBS) #todo_conduit -todo_conduitsdir=$(libdir)/gnome-pilot/conduits +#todo_conduitsdir=$(libdir)/gnome-pilot/conduits -todo_conduits_LTLIBRARIES = libtodo_conduit.la +#todo_conduits_LTLIBRARIES = libtodo_conduit.la -libtodo_conduit_la_LDFLAGS = \ - -rpath $(libdir) +#libtodo_conduit_la_LDFLAGS = \ +# -rpath $(libdir) -libtodo_conduit_la_LIBADD = \ - $(GNOME_LIBDIR) \ - $(GNOME_LIBS) +#libtodo_conduit_la_LIBADD = \ +# $(GNOME_LIBDIR) \ +# $(GNOME_LIBS) -libtodo_conduit_la_SOURCES = \ - todo-conduit.c +#libtodo_conduit_la_SOURCES = \ +# todo-conduit.c -todo-conduit.c: GnomeCal.h +#todo-conduit.c: GnomeCal.h -todo_conduit_control_applet_SOURCES = \ - todo-conduit-control-applet.c +#todo_conduit_control_applet_SOURCES = \ +# todo-conduit-control-applet.c -todo_conduit_control_applet_LDADD = \ - $(CAPPLET_LIBS) \ - $(GNOME_LIBDIR) \ - $(GNOME_CAPPLET_LIBS) \ - $(PISOCK_LIBS) \ - $(GNOMEUI_LIBS) \ - $(PISOCK_LIBS) \ - $(GNOME_PILOT_LIBS) \ - $(INTLLIBS) +#todo_conduit_control_applet_LDADD = \ +# $(CAPPLET_LIBS) \ +# $(GNOME_LIBDIR) \ +# $(GNOME_CAPPLET_LIBS) \ +# $(PISOCK_LIBS) \ +# $(GNOMEUI_LIBS) \ +# $(PISOCK_LIBS) \ +# $(GNOME_PILOT_LIBS) \ +# $(INTLLIBS) endif gnomecal_LDADD = $(LINK_FLAGS) diff --git a/calendar/calendar-conduit-control-applet.c b/calendar/calendar-conduit-control-applet.c index 4b18ae920f..57f4a07cc8 100644 --- a/calendar/calendar-conduit-control-applet.c +++ b/calendar/calendar-conduit-control-applet.c @@ -32,18 +32,21 @@ GtkWidget *dialogWindow=NULL; gboolean activated,org_activation_state; GnomePilotConduitMgmt *conduit; -static void doTrySettings(GtkWidget *widget, ConduitCfg *conduitCfg); -static void doRevertSettings(GtkWidget *widget, ConduitCfg *conduitCfg); -static void doSaveSettings(GtkWidget *widget, ConduitCfg *conduitCfg); +static void doTrySettings(GtkWidget *widget, GCalConduitCfg *conduitCfg); +static void doRevertSettings(GtkWidget *widget, GCalConduitCfg *conduitCfg); +static void doSaveSettings(GtkWidget *widget, GCalConduitCfg *conduitCfg); static void readStateCfg(GtkWidget *w); static void setStateCfg(GtkWidget *w); -gchar *pilotId; +GCalConduitCfg *origState = NULL; +GCalConduitCfg *curState = NULL; + +gint pilotId; CORBA_Environment ev; static void -doTrySettings(GtkWidget *widget, ConduitCfg *conduitCfg) +doTrySettings(GtkWidget *widget, GCalConduitCfg *conduitCfg) { readStateCfg(cfgStateWindow); if(activated) @@ -53,15 +56,15 @@ doTrySettings(GtkWidget *widget, ConduitCfg *conduitCfg) } static void -doSaveSettings(GtkWidget *widget, ConduitCfg *conduitCfg) +doSaveSettings(GtkWidget *widget, GCalConduitCfg *conduitCfg) { doTrySettings(widget, conduitCfg); - save_configuration(NULL); + gcalconduit_save_configuration(conduitCfg); } static void -doRevertSettings(GtkWidget *widget, ConduitCfg *conduitCfg) +doRevertSettings(GtkWidget *widget, GCalConduitCfg *conduitCfg) { activated = org_activation_state; setStateCfg(cfgStateWindow); @@ -203,7 +206,7 @@ pilot_capplet_setup(void) gtk_signal_connect(GTK_OBJECT(capplet), "revert", GTK_SIGNAL_FUNC(doRevertSettings), NULL); gtk_signal_connect(GTK_OBJECT(capplet), "ok", - GTK_SIGNAL_FUNC(doSaveSettings), NULL); + GTK_SIGNAL_FUNC(doSaveSettings), curState); gtk_signal_connect(GTK_OBJECT(capplet), "help", GTK_SIGNAL_FUNC(about_cb), NULL); @@ -224,28 +227,29 @@ void run_error_dialog(gchar *mesg,...) { va_end(ap); } -gchar *get_pilot_id_from_gpilotd() { - gchar **pilots; - int i; +gint get_pilot_id_from_gpilotd() { + gint *pilots; + int i; - i=0; - gpilotd_get_pilots(&pilots); - if(pilots) { - while(pilots[i]) { g_message("pilot %d = \"%s\"",i,pilots[i]); i++; } - if(i==0) { - run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); - return NULL; - } else - if(i==1) - return pilots[0]; - else { - g_message("too many pilots..."); - return pilots[0]; - } - } else { - run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); - return NULL; - } + i=0; + gpilotd_get_pilot_ids(&pilots); + if(pilots) { + while(pilots[i]!=-1) { g_message("pilot %d = \"%d\"",i,pilots[i]); i++; } + if(i==0) { + run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); + return -1; + } else { + if(i==1) + return pilots[0]; + else { + g_message("too many pilots..."); + return pilots[0]; + } + } + } else { + run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); + return -1; + } } int @@ -276,6 +280,11 @@ main( int argc, char *argv[] ) pilotId = get_pilot_id_from_gpilotd(); if(!pilotId) return -1; + + /* put all code to set things up in here */ + gcalconduit_load_configuration(&origState,pilotId); + curState = gcalconduit_dupe_configuration(origState); + org_activation_state = activated = gpilotd_conduit_mgmt_is_enabled(conduit,pilotId); pilot_capplet_setup(); @@ -283,6 +292,5 @@ main( int argc, char *argv[] ) /* done setting up, now run main loop */ capplet_gtk_main(); - g_free(pilotId); return 0; } diff --git a/calendar/calendar-conduit-control-applet.desktop b/calendar/calendar-conduit-control-applet.desktop index 869bba1476..aaaa7bd2c8 100644 --- a/calendar/calendar-conduit-control-applet.desktop +++ b/calendar/calendar-conduit-control-applet.desktop @@ -1,6 +1,6 @@ [Desktop Entry] -Name=Calendar conduit -Comment=Configure the calendar conduit +Name=GnomeCalendar +Comment=Configure the GnomeCal conduit Exec=calendar-conduit-control-applet --cap-id=1 Terminal=0 Type=Application diff --git a/calendar/calendar-conduit.c b/calendar/calendar-conduit.c index 193cc52e04..400824186a 100644 --- a/calendar/calendar-conduit.c +++ b/calendar/calendar-conduit.c @@ -32,16 +32,10 @@ GnomePilotConduit * conduit_get_gpilot_conduit (guint32); void conduit_destroy_gpilot_conduit (GnomePilotConduit*); -void local_record_from_icalobject(CalLocalRecord *local,iCalObject *obj); - -typedef struct _ConduitData ConduitData; - -struct _ConduitData { - struct AppointmentAppInfo ai; -}; +void local_record_from_icalobject(GCalLocalRecord *local,iCalObject *obj); #define CONDUIT_VERSION "0.8.0" -#define DEBUG_CALCONDUIT +/* #define DEBUG_CALCONDUIT */ #ifdef DEBUG_CALCONDUIT #define show_exception(e) g_warning ("Exception: %s\n", CORBA_exception_id (e)) @@ -54,30 +48,28 @@ struct _ConduitData { #define WARN(e...) g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING, e) #define INFO(e...) g_log(G_LOG_DOMAIN,G_LOG_LEVEL_MESSAGE, "calconduit: "##e) -#define GET_DATA(c) ((ConduitData*)gtk_object_get_data(GTK_OBJECT(c),"conduit_data")) - -GNOME_Calendar_Repository calendar; -CORBA_Environment ev; -CORBA_ORB orb; - -static GNOME_Calendar_Repository -start_calendar_server (GnomePilotConduitStandardAbs *conduit) +static int +start_calendar_server (GnomePilotConduitStandardAbs *conduit, + GCalConduitContext *ctxt) { - g_return_val_if_fail(conduit!=NULL,CORBA_OBJECT_NIL); - - calendar = goad_server_activate_with_id (NULL, - "IDL:GNOME:Calendar:Repository:1.0", - 0, NULL); - if (calendar == CORBA_OBJECT_NIL) + + g_return_val_if_fail(conduit!=NULL,-2); + g_return_val_if_fail(ctxt!=NULL,-2); + + ctxt->calendar = goad_server_activate_with_id (NULL, + "IDL:GNOME:Calendar:Repository:1.0", + 0, NULL); + if (ctxt->calendar == CORBA_OBJECT_NIL) { g_error ("Can not communicate with GnomeCalendar server"); - - if (ev._major != CORBA_NO_EXCEPTION){ - show_exception(&ev); - CORBA_exception_free(&ev); - return CORBA_OBJECT_NIL; + return -1; } - return calendar; + if (ctxt->ev._major != CORBA_NO_EXCEPTION){ + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); + return -1; + } + return 0; } @@ -88,25 +80,27 @@ calendar_notify (time_t time, CalendarAlarm *which, void *data) } static GList * -get_calendar_objects(GnomePilotConduitStandardAbs *conduit) +get_calendar_objects(GnomePilotConduitStandardAbs *conduit, + GCalConduitContext *ctxt) { GList *result; GNOME_Calendar_Repository_String_Sequence *uids; g_return_val_if_fail(conduit!=NULL,NULL); + g_return_val_if_fail(ctxt!=NULL,NULL); result = NULL; - uids = GNOME_Calendar_Repository_get_object_id_list (calendar, &ev); + uids = GNOME_Calendar_Repository_get_object_id_list (ctxt->calendar, &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ INFO ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return NULL; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return NULL; } @@ -174,25 +168,26 @@ get_calendar_objects(GnomePilotConduitStandardAbs *conduit) #endif static void -local_record_from_ical_uid(CalLocalRecord *local, - char *uid) +local_record_from_ical_uid(GCalLocalRecord *local, + char *uid, + GCalConduitContext *ctxt) { iCalObject *obj; char *vcalendar_string; g_assert(local!=NULL); - vcalendar_string = GNOME_Calendar_Repository_get_object(calendar, uid, &ev); + vcalendar_string = GNOME_Calendar_Repository_get_object(ctxt->calendar, uid, &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ INFO ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return; } g_return_if_fail(vcalendar_string!=NULL); @@ -206,11 +201,11 @@ local_record_from_ical_uid(CalLocalRecord *local, /* - * converts a iCalObject to a CalLocalRecord + * converts a iCalObject to a GCalLocalRecord */ void -local_record_from_icalobject(CalLocalRecord *local, +local_record_from_icalobject(GCalLocalRecord *local, iCalObject *obj) { g_return_if_fail(local!=NULL); @@ -250,33 +245,34 @@ local_record_from_icalobject(CalLocalRecord *local, * Given a PilotRecord, find the matching record in * the calendar repository. If no match, return NULL */ -static CalLocalRecord * +static GCalLocalRecord * find_record_in_repository(GnomePilotConduitStandardAbs *conduit, - PilotRecord *remote) + PilotRecord *remote, + GCalConduitContext *ctxt) { char *vcal_string; - CalLocalRecord *loc; + GCalLocalRecord *loc; g_return_val_if_fail(conduit!=NULL,NULL); g_return_val_if_fail(remote!=NULL,NULL); vcal_string = - GNOME_Calendar_Repository_get_object_by_pilot_id (calendar, remote->ID, &ev); + GNOME_Calendar_Repository_get_object_by_pilot_id (ctxt->calendar, remote->ID, &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ INFO ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return NULL; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return NULL; } else { LOG ("Found"); - loc = g_new0(CalLocalRecord,1); + loc = g_new0(GCalLocalRecord,1); /* memory allocated in new_from_string is freed in free_match */ local_record_from_icalobject(loc, ical_object_new_from_string (vcal_string)); @@ -292,7 +288,8 @@ find_record_in_repository(GnomePilotConduitStandardAbs *conduit, */ static void update_calendar_entry_in_repository(GnomePilotConduitStandardAbs *conduit, - iCalObject *obj) + iCalObject *obj, + GCalConduitContext *ctxt) { char *str; @@ -301,17 +298,17 @@ update_calendar_entry_in_repository(GnomePilotConduitStandardAbs *conduit, str = calendar_string_from_object (obj); - GNOME_Calendar_Repository_update_object (calendar, obj->uid, str, &ev); + GNOME_Calendar_Repository_update_object (ctxt->calendar, obj->uid, str, &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ INFO ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return; } @@ -506,7 +503,8 @@ ical_from_remote_record(GnomePilotConduitStandardAbs *conduit, */ static gint update_record (GnomePilotConduitStandardAbs *conduit, - PilotRecord *remote) + PilotRecord *remote, + GCalConduitContext *ctxt) { char *vcal_string; iCalObject *obj; @@ -522,17 +520,17 @@ update_record (GnomePilotConduitStandardAbs *conduit, a.description ? a.description : ""); LOG ("requesting %ld [%s]", remote->ID, a.description); - vcal_string = GNOME_Calendar_Repository_get_object_by_pilot_id (calendar, remote->ID, &ev); + vcal_string = GNOME_Calendar_Repository_get_object_by_pilot_id (ctxt->calendar, remote->ID, &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ - WARN (_("Object did not exist, creating a new one")); - show_exception(&ev); - CORBA_exception_free(&ev); + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ + LOG (_("Object did not exist, creating a new one")); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); ical_from_remote_record(conduit,remote,obj); - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); ical_object_destroy (obj); free_Appointment(&a); return -1; @@ -546,7 +544,7 @@ update_record (GnomePilotConduitStandardAbs *conduit, /* update record on server */ - update_calendar_entry_in_repository(conduit,obj); + update_calendar_entry_in_repository(conduit,obj,ctxt); /* * Shutdown @@ -559,16 +557,18 @@ update_record (GnomePilotConduitStandardAbs *conduit, static gint -pre_sync(GnomePilotConduit *c, GnomePilotDBInfo *dbi) +pre_sync(GnomePilotConduit *c, + GnomePilotDBInfo *dbi, + GCalConduitContext *ctxt) { int l; unsigned char *buf; - INFO (CONDUIT_VERSION); + g_message ("GnomeCal Conduit v.%s",CONDUIT_VERSION); - calendar = CORBA_OBJECT_NIL; - calendar = start_calendar_server(GNOME_PILOT_CONDUIT_STANDARD_ABS(c)); - if(calendar == CORBA_OBJECT_NIL) { + ctxt->calendar = CORBA_OBJECT_NIL; + + if (start_calendar_server(GNOME_PILOT_CONDUIT_STANDARD_ABS(c),GET_GCALCONTEXT(c)) != 0) { return -1; } @@ -580,7 +580,7 @@ pre_sync(GnomePilotConduit *c, GnomePilotDBInfo *dbi) if((l=dlp_ReadAppBlock(dbi->pilot_socket,dbi->db_handle,0,(unsigned char *)buf,0xffff))<0) { return -1; } - unpack_AppointmentAppInfo(&(GET_DATA(c)->ai),buf,l); + unpack_AppointmentAppInfo(&(ctxt->ai),buf,l); g_free(buf); return 0; @@ -596,16 +596,16 @@ pre_sync(GnomePilotConduit *c, GnomePilotDBInfo *dbi) static gint match_record (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord **local, + GCalLocalRecord **local, PilotRecord *remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("in match_record"); g_return_val_if_fail(local!=NULL,-1); g_return_val_if_fail(remote!=NULL,-1); - *local = find_record_in_repository(conduit,remote); + *local = find_record_in_repository(conduit,remote,ctxt); if (*local==NULL) return -1; return 0; @@ -618,15 +618,15 @@ match_record (GnomePilotConduitStandardAbs *conduit, */ static gint free_match (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord **local, - gpointer data) + GCalLocalRecord **local, + GCalConduitContext *ctxt) { LOG ("entering free_match"); g_return_val_if_fail(local!=NULL,-1); g_return_val_if_fail(*local!=NULL,-1); - ical_object_destroy (CALLOCALRECORD(*local)->ical); + ical_object_destroy (GCAL_LOCALRECORD(*local)->ical); g_free(*local); *local = NULL; @@ -638,8 +638,8 @@ free_match (GnomePilotConduitStandardAbs *conduit, */ static gint archive_local (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, - gpointer data) + GCalLocalRecord *local, + GCalConduitContext *ctxt) { LOG ("entering archive_local"); @@ -653,9 +653,9 @@ archive_local (GnomePilotConduitStandardAbs *conduit, */ static gint archive_remote (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, PilotRecord *remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering archive_remote"); @@ -671,19 +671,19 @@ archive_remote (GnomePilotConduitStandardAbs *conduit, static gint store_remote (GnomePilotConduitStandardAbs *conduit, PilotRecord *remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering store_remote"); g_return_val_if_fail(remote!=NULL,-1); - return update_record(conduit,remote); + return update_record(conduit,remote,ctxt); } static gint clear_status_archive_local (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, - gpointer data) + GCalLocalRecord *local, + GCalConduitContext *ctxt) { LOG ("entering clear_status_archive_local"); @@ -694,8 +694,8 @@ clear_status_archive_local (GnomePilotConduitStandardAbs *conduit, static gint iterate (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord **local, - gpointer data) + GCalLocalRecord **local, + GCalConduitContext *ctxt) { static GList *events,*iterator; static int hest; @@ -705,14 +705,14 @@ iterate (GnomePilotConduitStandardAbs *conduit, if(*local==NULL) { LOG ("beginning iteration"); - events = get_calendar_objects(conduit); + events = get_calendar_objects(conduit,ctxt); hest = 0; if(events!=NULL) { LOG ("iterating over %d records",g_list_length(events)); - *local = g_new0(CalLocalRecord,1); + *local = g_new0(GCalLocalRecord,1); - local_record_from_ical_uid(*local,(gchar*)events->data); + local_record_from_ical_uid(*local,(gchar*)events->data,ctxt); iterator = events; } else { LOG ("no events"); @@ -739,7 +739,7 @@ iterate (GnomePilotConduitStandardAbs *conduit, return 0; } else { iterator = g_list_next(iterator); - local_record_from_ical_uid(*local,(gchar*)(iterator->data)); + local_record_from_ical_uid(*local,(gchar*)(iterator->data),ctxt); } } return 1; @@ -747,10 +747,10 @@ iterate (GnomePilotConduitStandardAbs *conduit, static gint iterate_specific (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord **local, + GCalLocalRecord **local, gint flag, gint archived, - gpointer data) + GCalConduitContext *ctxt) { #ifdef DEBUG_CALCONDUIT { @@ -769,7 +769,6 @@ iterate_specific (GnomePilotConduitStandardAbs *conduit, /* iterate until a record meets the criteria */ while(gnome_pilot_conduit_standard_abs_iterate(conduit,(LocalRecord**)local)) { if((*local)==NULL) break; - /* g_print("calconduit: local->attr = %d, flag = %d, & %d\n",(*local)->local.attr,flag,((*local)->local.attr & flag)); */ if(archived && ((*local)->local.archived==archived)) break; if(((*local)->local.attr == flag)) break; } @@ -779,7 +778,7 @@ iterate_specific (GnomePilotConduitStandardAbs *conduit, static gint purge (GnomePilotConduitStandardAbs *conduit, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering purge"); @@ -791,9 +790,9 @@ purge (GnomePilotConduitStandardAbs *conduit, static gint set_status (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, gint status, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering set_status"); @@ -816,23 +815,23 @@ set_status (GnomePilotConduitStandardAbs *conduit, } if ( status != GnomePilotRecordDeleted) - GNOME_Calendar_Repository_update_pilot_id(calendar, + GNOME_Calendar_Repository_update_pilot_id(ctxt->calendar, local->ical->uid, local->local.ID, local->ical->pilot_status, - &ev); + &(ctxt->ev)); else - GNOME_Calendar_Repository_delete_object(calendar,local->ical->uid,&ev); + GNOME_Calendar_Repository_delete_object(ctxt->calendar,local->ical->uid,&(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ LOG ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return -1; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return -1; } return 0; @@ -840,9 +839,9 @@ set_status (GnomePilotConduitStandardAbs *conduit, static gint set_archived (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, gint archived, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering set_archived"); @@ -850,7 +849,7 @@ set_archived (GnomePilotConduitStandardAbs *conduit, g_assert(local->ical!=NULL); local->local.archived = archived; - update_calendar_entry_in_repository(conduit,local->ical); + update_calendar_entry_in_repository(conduit,local->ical,ctxt); /* FIXME: This should move the entry into a speciel calendar file, eg. Archive, or (by config option), simply delete it */ @@ -859,9 +858,9 @@ set_archived (GnomePilotConduitStandardAbs *conduit, static gint set_pilot_id (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, guint32 ID, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering set_pilot_id"); @@ -870,21 +869,21 @@ set_pilot_id (GnomePilotConduitStandardAbs *conduit, local->local.ID = ID; local->ical->pilot_id = ID; - GNOME_Calendar_Repository_update_pilot_id(calendar, + GNOME_Calendar_Repository_update_pilot_id(ctxt->calendar, local->ical->uid, local->local.ID, local->ical->pilot_status, - &ev); + &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ LOG ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return -1; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return -1; } return 0; @@ -892,9 +891,9 @@ set_pilot_id (GnomePilotConduitStandardAbs *conduit, static gint compare (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, PilotRecord *remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering compare"); @@ -906,9 +905,9 @@ compare (GnomePilotConduitStandardAbs *conduit, static gint compare_backup (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, PilotRecord *remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering compare_backup"); @@ -920,9 +919,9 @@ compare_backup (GnomePilotConduitStandardAbs *conduit, static gint free_transmit (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, PilotRecord **remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering free_transmit"); @@ -937,7 +936,7 @@ free_transmit (GnomePilotConduitStandardAbs *conduit, static gint delete_all (GnomePilotConduitStandardAbs *conduit, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering delete_all"); @@ -946,13 +945,12 @@ delete_all (GnomePilotConduitStandardAbs *conduit, static gint transmit (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, PilotRecord **remote, - gpointer data) + GCalConduitContext *ctxt) { PilotRecord *p; int daycount; - int x,y; LOG ("entering transmit"); @@ -1059,18 +1057,23 @@ transmit (GnomePilotConduitStandardAbs *conduit, p->length = pack_Appointment(local->a,p->record,0xffff); #if 0 - g_message("calconduit: new item from %s to %s",asctime(&(local->a->begin)),asctime(&(local->a->end))); - - g_message("local->a->note = %s",local->a->note); - g_message("local->a->description = %s",local->a->description); - g_message("sizeof(p->record) = %d, length is %d",sizeof(p->record),p->length); - for(x=0;x<p->length;x+=32) { - for(y=x;y<x+32;y++) - if(p->record[y]<33 || p->record[y]>128) - printf("%02X",p->record[y]); - else - printf(" %c",p->record[y]); - printf("\n"); + /* This is some debug code that hexdumps the calendar entry... + You won't need this. */ + { + int x,y; + g_message("calconduit: new item from %s to %s",asctime(&(local->a->begin)),asctime(&(local->a->end))); + + g_message("local->a->note = %s",local->a->note); + g_message("local->a->description = %s",local->a->description); + g_message("sizeof(p->record) = %d, length is %d",sizeof(p->record),p->length); + for(x=0;x<p->length;x+=32) { + for(y=x;y<x+32;y++) + if(p->record[y]<33 || p->record[y]>128) + printf("%02X",p->record[y]); + else + printf(" %c",p->record[y]); + printf("\n"); + } } #endif @@ -1083,43 +1086,42 @@ GnomePilotConduit * conduit_get_gpilot_conduit (guint32 pilotId) { GtkObject *retval; - ConduitCfg *cfg; - ConduitData *cdata; + GCalConduitCfg *cfg; + GCalConduitContext *ctxt; - CORBA_exception_init (&ev); retval = gnome_pilot_conduit_standard_abs_new ("DatebookDB", 0x64617465); g_assert (retval != NULL); - gnome_pilot_conduit_construct(GNOME_PILOT_CONDUIT(retval),"calendar"); - - cfg = g_new0(ConduitCfg,1); - g_assert(cfg != NULL); - gtk_object_set_data(retval,"conduit_cfg",cfg); - - cdata = g_new0(ConduitData,1); - g_assert(cdata != NULL); - gtk_object_set_data(retval,"conduit_data",cdata); - - gtk_signal_connect (retval, "match_record", (GtkSignalFunc) match_record, NULL); - gtk_signal_connect (retval, "free_match", (GtkSignalFunc) free_match, NULL); - gtk_signal_connect (retval, "archive_local", (GtkSignalFunc) archive_local, NULL); - gtk_signal_connect (retval, "archive_remote", (GtkSignalFunc) archive_remote, NULL); - gtk_signal_connect (retval, "store_remote", (GtkSignalFunc) store_remote, NULL); - gtk_signal_connect (retval, "clear_status_archive_local", (GtkSignalFunc) clear_status_archive_local, NULL); - gtk_signal_connect (retval, "iterate", (GtkSignalFunc) iterate, NULL); - gtk_signal_connect (retval, "iterate_specific", (GtkSignalFunc) iterate_specific, NULL); - gtk_signal_connect (retval, "purge", (GtkSignalFunc) purge, NULL); - gtk_signal_connect (retval, "set_status", (GtkSignalFunc) set_status, NULL); - gtk_signal_connect (retval, "set_archived", (GtkSignalFunc) set_archived, NULL); - gtk_signal_connect (retval, "set_pilot_id", (GtkSignalFunc) set_pilot_id, NULL); - gtk_signal_connect (retval, "compare", (GtkSignalFunc) compare, NULL); - gtk_signal_connect (retval, "compare_backup", (GtkSignalFunc) compare_backup, NULL); - gtk_signal_connect (retval, "free_transmit", (GtkSignalFunc) free_transmit, NULL); - gtk_signal_connect (retval, "delete_all", (GtkSignalFunc) delete_all, NULL); - gtk_signal_connect (retval, "transmit", (GtkSignalFunc) transmit, NULL); - gtk_signal_connect (retval, "pre_sync", (GtkSignalFunc) pre_sync, NULL); - - load_configuration(&cfg,pilotId); + gnome_pilot_conduit_construct(GNOME_PILOT_CONDUIT(retval),"GnomeCalConduit"); + + gcalconduit_load_configuration(&cfg,pilotId); + gtk_object_set_data(retval,"gcalconduit_cfg",cfg); + + gcalconduit_new_context(&ctxt,cfg); + /* No real need to set it, since all signal are given this + as their user data */ + gtk_object_set_data(retval,"gcalconduit_context",ctxt); + + gtk_signal_connect (retval, "match_record", (GtkSignalFunc) match_record, ctxt); + gtk_signal_connect (retval, "free_match", (GtkSignalFunc) free_match, ctxt); + gtk_signal_connect (retval, "archive_local", (GtkSignalFunc) archive_local, ctxt); + gtk_signal_connect (retval, "archive_remote", (GtkSignalFunc) archive_remote, ctxt); + gtk_signal_connect (retval, "store_remote", (GtkSignalFunc) store_remote, ctxt); + gtk_signal_connect (retval, "clear_status_archive_local", (GtkSignalFunc) clear_status_archive_local, ctxt); + gtk_signal_connect (retval, "iterate", (GtkSignalFunc) iterate, ctxt); + gtk_signal_connect (retval, "iterate_specific", (GtkSignalFunc) iterate_specific, ctxt); + gtk_signal_connect (retval, "purge", (GtkSignalFunc) purge, ctxt); + gtk_signal_connect (retval, "set_status", (GtkSignalFunc) set_status, ctxt); + gtk_signal_connect (retval, "set_archived", (GtkSignalFunc) set_archived, ctxt); + gtk_signal_connect (retval, "set_pilot_id", (GtkSignalFunc) set_pilot_id, ctxt); + gtk_signal_connect (retval, "compare", (GtkSignalFunc) compare, ctxt); + gtk_signal_connect (retval, "compare_backup", (GtkSignalFunc) compare_backup, ctxt); + gtk_signal_connect (retval, "free_transmit", (GtkSignalFunc) free_transmit, ctxt); + gtk_signal_connect (retval, "delete_all", (GtkSignalFunc) delete_all, ctxt); + gtk_signal_connect (retval, "transmit", (GtkSignalFunc) transmit, ctxt); + gtk_signal_connect (retval, "pre_sync", (GtkSignalFunc) pre_sync, ctxt); + + return GNOME_PILOT_CONDUIT (retval); } @@ -1127,17 +1129,18 @@ conduit_get_gpilot_conduit (guint32 pilotId) void conduit_destroy_gpilot_conduit (GnomePilotConduit *conduit) { - ConduitCfg *cc; - ConduitData *cd; + GCalConduitCfg *cc; + GCalConduitContext *ctxt; + + cc = GET_GCALCONFIG(conduit); + ctxt = GET_GCALCONTEXT(conduit); - if(calendar!=CORBA_OBJECT_NIL) - GNOME_Calendar_Repository_done (calendar, &ev); + if(ctxt->calendar!=CORBA_OBJECT_NIL) + GNOME_Calendar_Repository_done (ctxt->calendar, &(ctxt->ev)); - cc = GET_CONFIG(conduit); - destroy_configuration(&cc); + gcalconduit_destroy_configuration(&cc); - cd = GET_DATA(conduit); - g_free(cd); + gcalconduit_destroy_context(&ctxt); gtk_object_destroy (GTK_OBJECT (conduit)); diff --git a/calendar/calendar-conduit.h b/calendar/calendar-conduit.h index d8b320c1ce..cee7d3386e 100644 --- a/calendar/calendar-conduit.h +++ b/calendar/calendar-conduit.h @@ -17,55 +17,119 @@ #include <gpilotd/gnome-pilot-conduit.h> #include <gpilotd/gnome-pilot-conduit-standard-abs.h> -#define CALLOCALRECORD(s) ((CalLocalRecord*)(s)) -typedef struct _CalLocalRecord CalLocalRecord; - -struct _CalLocalRecord { - /* The stuff from gnome-pilot-conduit-standard-abs.h */ +/* This is the local record structure for the GnomeCal conduit. */ +typedef struct _GCalLocalRecord GCalLocalRecord; +struct _GCalLocalRecord { + /* The stuff from gnome-pilot-conduit-standard-abs.h + Must be first in the structure, or instances of this + structure cannot be used by gnome-pilot-conduit-standard-abs. + */ LocalRecord local; - /* The corresponding iCal object */ + /* The corresponding iCal object, as found by GnomeCal. */ iCalObject *ical; - /* pilot-link appointment structure, used for implementing Transmit */ + /* pilot-link appointment structure, used for implementing Transmit. */ struct Appointment *a; }; +#define GCAL_LOCALRECORD(s) ((GCalLocalRecord*)(s)) -typedef struct _ConduitCfg ConduitCfg; - -struct _ConduitCfg { - gboolean open_secret; - guint32 pilotId; +/* This is the configuration of the GnomeCal conduit. */ +typedef struct _GCalConduitCfg GCalConduitCfg; +struct _GCalConduitCfg { + gboolean open_secret; + guint32 pilotId; }; +#define GET_GCALCONFIG(c) ((GCalConduitCfg*)gtk_object_get_data(GTK_OBJECT(c),"gcalconduit_cfg")) + +/* This is the context for all the GnomeCal conduit methods. */ +typedef struct _GCalConduitContext GCalConduitContext; +struct _GCalConduitContext { + struct AppointmentAppInfo ai; + GCalConduitCfg *cfg; + GNOME_Calendar_Repository calendar; + CORBA_Environment ev; + CORBA_ORB orb; +}; +#define GET_GCALCONTEXT(c) ((GCalConduitContext*)gtk_object_get_data(GTK_OBJECT(c),"gcalconduit_context")) + +/* Given a GCalConduitCfg*, allocates the structure and + loads the configuration data for the given pilot. */ +static void +gcalconduit_load_configuration(GCalConduitCfg **c, + guint32 pilotId) +{ + gchar prefix[256]; + g_snprintf(prefix,255,"/gnome-pilot.d/calendard-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"); + gnome_config_pop_prefix(); + + (*c)->pilotId = pilotId; +} -#define GET_CONFIG(c) ((ConduitCfg*)gtk_object_get_data(GTK_OBJECT(c),"conduit_cfg")) +/* Saves the configuration data. */ +static void +gcalconduit_save_configuration(GCalConduitCfg *c) +{ + gchar prefix[256]; -static void load_configuration(ConduitCfg **c,guint32 pilotId) { - gchar prefix[256]; - g_snprintf(prefix,255,"/gnome-pilot.d/calendard-conduit/Pilot_%u/",pilotId); + g_snprintf(prefix,255,"/gnome-pilot.d/calendar-conduit/Pilot_%u/",c->pilotId); - *c = g_new0(ConduitCfg,1); - gnome_config_push_prefix(prefix); - (*c)->open_secret = gnome_config_get_bool("open secret=FALSE"); - gnome_config_pop_prefix(); + gnome_config_push_prefix(prefix); + gnome_config_set_bool("open_secret",c->open_secret); + gnome_config_pop_prefix(); - (*c)->pilotId = pilotId; + gnome_config_sync(); + gnome_config_drop_all(); } -static void save_configuration(ConduitCfg *c) { - gchar prefix[256]; - - g_snprintf(prefix,255,"/gnome-pilot.d/calendar-conduit/Pilot_%u/",c->pilotId); - - gnome_config_push_prefix(prefix); - gnome_config_set_bool("open secret",c->open_secret); - gnome_config_pop_prefix(); +/* 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->open_secret = c->open_secret; + retval->pilotId = c->pilotId; + return retval; +} - gnome_config_sync(); - gnome_config_drop_all(); +/* 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; } -static void destroy_configuration(ConduitCfg **c) { - g_free(*c); - *c = NULL; +/* Given a GCalConduitContxt*, allocates the structure */ +static void +gcalconduit_new_context(GCalConduitContext **ctxt, + GCalConduitCfg *c) +{ + *ctxt = g_new0(GCalConduitContext,1); + g_assert(ctxt!=NULL); + (*ctxt)->cfg = c; + CORBA_exception_init (&((*ctxt)->ev)); } +/* Destroys any data allocated by gcalconduit_new_context + and deallocates its data. */ +static void +gcalconduit_destroy_context(GCalConduitContext **ctxt) +{ + g_return_if_fail(ctxt!=NULL); + g_return_if_fail(*ctxt!=NULL); +/* + if ((*ctxt)->cfg!=NULL) + gcalconduit_destroy_configuration(&((*ctxt)->cfg)); +*/ + g_free(*ctxt); + *ctxt = NULL; +} #endif __CALENDAR_CONDUIT_H__ diff --git a/calendar/conduits/calendar/calendar-conduit-control-applet.c b/calendar/conduits/calendar/calendar-conduit-control-applet.c index 4b18ae920f..57f4a07cc8 100644 --- a/calendar/conduits/calendar/calendar-conduit-control-applet.c +++ b/calendar/conduits/calendar/calendar-conduit-control-applet.c @@ -32,18 +32,21 @@ GtkWidget *dialogWindow=NULL; gboolean activated,org_activation_state; GnomePilotConduitMgmt *conduit; -static void doTrySettings(GtkWidget *widget, ConduitCfg *conduitCfg); -static void doRevertSettings(GtkWidget *widget, ConduitCfg *conduitCfg); -static void doSaveSettings(GtkWidget *widget, ConduitCfg *conduitCfg); +static void doTrySettings(GtkWidget *widget, GCalConduitCfg *conduitCfg); +static void doRevertSettings(GtkWidget *widget, GCalConduitCfg *conduitCfg); +static void doSaveSettings(GtkWidget *widget, GCalConduitCfg *conduitCfg); static void readStateCfg(GtkWidget *w); static void setStateCfg(GtkWidget *w); -gchar *pilotId; +GCalConduitCfg *origState = NULL; +GCalConduitCfg *curState = NULL; + +gint pilotId; CORBA_Environment ev; static void -doTrySettings(GtkWidget *widget, ConduitCfg *conduitCfg) +doTrySettings(GtkWidget *widget, GCalConduitCfg *conduitCfg) { readStateCfg(cfgStateWindow); if(activated) @@ -53,15 +56,15 @@ doTrySettings(GtkWidget *widget, ConduitCfg *conduitCfg) } static void -doSaveSettings(GtkWidget *widget, ConduitCfg *conduitCfg) +doSaveSettings(GtkWidget *widget, GCalConduitCfg *conduitCfg) { doTrySettings(widget, conduitCfg); - save_configuration(NULL); + gcalconduit_save_configuration(conduitCfg); } static void -doRevertSettings(GtkWidget *widget, ConduitCfg *conduitCfg) +doRevertSettings(GtkWidget *widget, GCalConduitCfg *conduitCfg) { activated = org_activation_state; setStateCfg(cfgStateWindow); @@ -203,7 +206,7 @@ pilot_capplet_setup(void) gtk_signal_connect(GTK_OBJECT(capplet), "revert", GTK_SIGNAL_FUNC(doRevertSettings), NULL); gtk_signal_connect(GTK_OBJECT(capplet), "ok", - GTK_SIGNAL_FUNC(doSaveSettings), NULL); + GTK_SIGNAL_FUNC(doSaveSettings), curState); gtk_signal_connect(GTK_OBJECT(capplet), "help", GTK_SIGNAL_FUNC(about_cb), NULL); @@ -224,28 +227,29 @@ void run_error_dialog(gchar *mesg,...) { va_end(ap); } -gchar *get_pilot_id_from_gpilotd() { - gchar **pilots; - int i; +gint get_pilot_id_from_gpilotd() { + gint *pilots; + int i; - i=0; - gpilotd_get_pilots(&pilots); - if(pilots) { - while(pilots[i]) { g_message("pilot %d = \"%s\"",i,pilots[i]); i++; } - if(i==0) { - run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); - return NULL; - } else - if(i==1) - return pilots[0]; - else { - g_message("too many pilots..."); - return pilots[0]; - } - } else { - run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); - return NULL; - } + i=0; + gpilotd_get_pilot_ids(&pilots); + if(pilots) { + while(pilots[i]!=-1) { g_message("pilot %d = \"%d\"",i,pilots[i]); i++; } + if(i==0) { + run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); + return -1; + } else { + if(i==1) + return pilots[0]; + else { + g_message("too many pilots..."); + return pilots[0]; + } + } + } else { + run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); + return -1; + } } int @@ -276,6 +280,11 @@ main( int argc, char *argv[] ) pilotId = get_pilot_id_from_gpilotd(); if(!pilotId) return -1; + + /* put all code to set things up in here */ + gcalconduit_load_configuration(&origState,pilotId); + curState = gcalconduit_dupe_configuration(origState); + org_activation_state = activated = gpilotd_conduit_mgmt_is_enabled(conduit,pilotId); pilot_capplet_setup(); @@ -283,6 +292,5 @@ main( int argc, char *argv[] ) /* done setting up, now run main loop */ capplet_gtk_main(); - g_free(pilotId); return 0; } diff --git a/calendar/conduits/calendar/calendar-conduit-control-applet.desktop b/calendar/conduits/calendar/calendar-conduit-control-applet.desktop index 869bba1476..aaaa7bd2c8 100644 --- a/calendar/conduits/calendar/calendar-conduit-control-applet.desktop +++ b/calendar/conduits/calendar/calendar-conduit-control-applet.desktop @@ -1,6 +1,6 @@ [Desktop Entry] -Name=Calendar conduit -Comment=Configure the calendar conduit +Name=GnomeCalendar +Comment=Configure the GnomeCal conduit Exec=calendar-conduit-control-applet --cap-id=1 Terminal=0 Type=Application diff --git a/calendar/conduits/calendar/calendar-conduit.c b/calendar/conduits/calendar/calendar-conduit.c index 193cc52e04..400824186a 100644 --- a/calendar/conduits/calendar/calendar-conduit.c +++ b/calendar/conduits/calendar/calendar-conduit.c @@ -32,16 +32,10 @@ GnomePilotConduit * conduit_get_gpilot_conduit (guint32); void conduit_destroy_gpilot_conduit (GnomePilotConduit*); -void local_record_from_icalobject(CalLocalRecord *local,iCalObject *obj); - -typedef struct _ConduitData ConduitData; - -struct _ConduitData { - struct AppointmentAppInfo ai; -}; +void local_record_from_icalobject(GCalLocalRecord *local,iCalObject *obj); #define CONDUIT_VERSION "0.8.0" -#define DEBUG_CALCONDUIT +/* #define DEBUG_CALCONDUIT */ #ifdef DEBUG_CALCONDUIT #define show_exception(e) g_warning ("Exception: %s\n", CORBA_exception_id (e)) @@ -54,30 +48,28 @@ struct _ConduitData { #define WARN(e...) g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING, e) #define INFO(e...) g_log(G_LOG_DOMAIN,G_LOG_LEVEL_MESSAGE, "calconduit: "##e) -#define GET_DATA(c) ((ConduitData*)gtk_object_get_data(GTK_OBJECT(c),"conduit_data")) - -GNOME_Calendar_Repository calendar; -CORBA_Environment ev; -CORBA_ORB orb; - -static GNOME_Calendar_Repository -start_calendar_server (GnomePilotConduitStandardAbs *conduit) +static int +start_calendar_server (GnomePilotConduitStandardAbs *conduit, + GCalConduitContext *ctxt) { - g_return_val_if_fail(conduit!=NULL,CORBA_OBJECT_NIL); - - calendar = goad_server_activate_with_id (NULL, - "IDL:GNOME:Calendar:Repository:1.0", - 0, NULL); - if (calendar == CORBA_OBJECT_NIL) + + g_return_val_if_fail(conduit!=NULL,-2); + g_return_val_if_fail(ctxt!=NULL,-2); + + ctxt->calendar = goad_server_activate_with_id (NULL, + "IDL:GNOME:Calendar:Repository:1.0", + 0, NULL); + if (ctxt->calendar == CORBA_OBJECT_NIL) { g_error ("Can not communicate with GnomeCalendar server"); - - if (ev._major != CORBA_NO_EXCEPTION){ - show_exception(&ev); - CORBA_exception_free(&ev); - return CORBA_OBJECT_NIL; + return -1; } - return calendar; + if (ctxt->ev._major != CORBA_NO_EXCEPTION){ + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); + return -1; + } + return 0; } @@ -88,25 +80,27 @@ calendar_notify (time_t time, CalendarAlarm *which, void *data) } static GList * -get_calendar_objects(GnomePilotConduitStandardAbs *conduit) +get_calendar_objects(GnomePilotConduitStandardAbs *conduit, + GCalConduitContext *ctxt) { GList *result; GNOME_Calendar_Repository_String_Sequence *uids; g_return_val_if_fail(conduit!=NULL,NULL); + g_return_val_if_fail(ctxt!=NULL,NULL); result = NULL; - uids = GNOME_Calendar_Repository_get_object_id_list (calendar, &ev); + uids = GNOME_Calendar_Repository_get_object_id_list (ctxt->calendar, &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ INFO ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return NULL; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return NULL; } @@ -174,25 +168,26 @@ get_calendar_objects(GnomePilotConduitStandardAbs *conduit) #endif static void -local_record_from_ical_uid(CalLocalRecord *local, - char *uid) +local_record_from_ical_uid(GCalLocalRecord *local, + char *uid, + GCalConduitContext *ctxt) { iCalObject *obj; char *vcalendar_string; g_assert(local!=NULL); - vcalendar_string = GNOME_Calendar_Repository_get_object(calendar, uid, &ev); + vcalendar_string = GNOME_Calendar_Repository_get_object(ctxt->calendar, uid, &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ INFO ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return; } g_return_if_fail(vcalendar_string!=NULL); @@ -206,11 +201,11 @@ local_record_from_ical_uid(CalLocalRecord *local, /* - * converts a iCalObject to a CalLocalRecord + * converts a iCalObject to a GCalLocalRecord */ void -local_record_from_icalobject(CalLocalRecord *local, +local_record_from_icalobject(GCalLocalRecord *local, iCalObject *obj) { g_return_if_fail(local!=NULL); @@ -250,33 +245,34 @@ local_record_from_icalobject(CalLocalRecord *local, * Given a PilotRecord, find the matching record in * the calendar repository. If no match, return NULL */ -static CalLocalRecord * +static GCalLocalRecord * find_record_in_repository(GnomePilotConduitStandardAbs *conduit, - PilotRecord *remote) + PilotRecord *remote, + GCalConduitContext *ctxt) { char *vcal_string; - CalLocalRecord *loc; + GCalLocalRecord *loc; g_return_val_if_fail(conduit!=NULL,NULL); g_return_val_if_fail(remote!=NULL,NULL); vcal_string = - GNOME_Calendar_Repository_get_object_by_pilot_id (calendar, remote->ID, &ev); + GNOME_Calendar_Repository_get_object_by_pilot_id (ctxt->calendar, remote->ID, &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ INFO ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return NULL; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return NULL; } else { LOG ("Found"); - loc = g_new0(CalLocalRecord,1); + loc = g_new0(GCalLocalRecord,1); /* memory allocated in new_from_string is freed in free_match */ local_record_from_icalobject(loc, ical_object_new_from_string (vcal_string)); @@ -292,7 +288,8 @@ find_record_in_repository(GnomePilotConduitStandardAbs *conduit, */ static void update_calendar_entry_in_repository(GnomePilotConduitStandardAbs *conduit, - iCalObject *obj) + iCalObject *obj, + GCalConduitContext *ctxt) { char *str; @@ -301,17 +298,17 @@ update_calendar_entry_in_repository(GnomePilotConduitStandardAbs *conduit, str = calendar_string_from_object (obj); - GNOME_Calendar_Repository_update_object (calendar, obj->uid, str, &ev); + GNOME_Calendar_Repository_update_object (ctxt->calendar, obj->uid, str, &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ INFO ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return; } @@ -506,7 +503,8 @@ ical_from_remote_record(GnomePilotConduitStandardAbs *conduit, */ static gint update_record (GnomePilotConduitStandardAbs *conduit, - PilotRecord *remote) + PilotRecord *remote, + GCalConduitContext *ctxt) { char *vcal_string; iCalObject *obj; @@ -522,17 +520,17 @@ update_record (GnomePilotConduitStandardAbs *conduit, a.description ? a.description : ""); LOG ("requesting %ld [%s]", remote->ID, a.description); - vcal_string = GNOME_Calendar_Repository_get_object_by_pilot_id (calendar, remote->ID, &ev); + vcal_string = GNOME_Calendar_Repository_get_object_by_pilot_id (ctxt->calendar, remote->ID, &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ - WARN (_("Object did not exist, creating a new one")); - show_exception(&ev); - CORBA_exception_free(&ev); + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ + LOG (_("Object did not exist, creating a new one")); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); ical_from_remote_record(conduit,remote,obj); - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); ical_object_destroy (obj); free_Appointment(&a); return -1; @@ -546,7 +544,7 @@ update_record (GnomePilotConduitStandardAbs *conduit, /* update record on server */ - update_calendar_entry_in_repository(conduit,obj); + update_calendar_entry_in_repository(conduit,obj,ctxt); /* * Shutdown @@ -559,16 +557,18 @@ update_record (GnomePilotConduitStandardAbs *conduit, static gint -pre_sync(GnomePilotConduit *c, GnomePilotDBInfo *dbi) +pre_sync(GnomePilotConduit *c, + GnomePilotDBInfo *dbi, + GCalConduitContext *ctxt) { int l; unsigned char *buf; - INFO (CONDUIT_VERSION); + g_message ("GnomeCal Conduit v.%s",CONDUIT_VERSION); - calendar = CORBA_OBJECT_NIL; - calendar = start_calendar_server(GNOME_PILOT_CONDUIT_STANDARD_ABS(c)); - if(calendar == CORBA_OBJECT_NIL) { + ctxt->calendar = CORBA_OBJECT_NIL; + + if (start_calendar_server(GNOME_PILOT_CONDUIT_STANDARD_ABS(c),GET_GCALCONTEXT(c)) != 0) { return -1; } @@ -580,7 +580,7 @@ pre_sync(GnomePilotConduit *c, GnomePilotDBInfo *dbi) if((l=dlp_ReadAppBlock(dbi->pilot_socket,dbi->db_handle,0,(unsigned char *)buf,0xffff))<0) { return -1; } - unpack_AppointmentAppInfo(&(GET_DATA(c)->ai),buf,l); + unpack_AppointmentAppInfo(&(ctxt->ai),buf,l); g_free(buf); return 0; @@ -596,16 +596,16 @@ pre_sync(GnomePilotConduit *c, GnomePilotDBInfo *dbi) static gint match_record (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord **local, + GCalLocalRecord **local, PilotRecord *remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("in match_record"); g_return_val_if_fail(local!=NULL,-1); g_return_val_if_fail(remote!=NULL,-1); - *local = find_record_in_repository(conduit,remote); + *local = find_record_in_repository(conduit,remote,ctxt); if (*local==NULL) return -1; return 0; @@ -618,15 +618,15 @@ match_record (GnomePilotConduitStandardAbs *conduit, */ static gint free_match (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord **local, - gpointer data) + GCalLocalRecord **local, + GCalConduitContext *ctxt) { LOG ("entering free_match"); g_return_val_if_fail(local!=NULL,-1); g_return_val_if_fail(*local!=NULL,-1); - ical_object_destroy (CALLOCALRECORD(*local)->ical); + ical_object_destroy (GCAL_LOCALRECORD(*local)->ical); g_free(*local); *local = NULL; @@ -638,8 +638,8 @@ free_match (GnomePilotConduitStandardAbs *conduit, */ static gint archive_local (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, - gpointer data) + GCalLocalRecord *local, + GCalConduitContext *ctxt) { LOG ("entering archive_local"); @@ -653,9 +653,9 @@ archive_local (GnomePilotConduitStandardAbs *conduit, */ static gint archive_remote (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, PilotRecord *remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering archive_remote"); @@ -671,19 +671,19 @@ archive_remote (GnomePilotConduitStandardAbs *conduit, static gint store_remote (GnomePilotConduitStandardAbs *conduit, PilotRecord *remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering store_remote"); g_return_val_if_fail(remote!=NULL,-1); - return update_record(conduit,remote); + return update_record(conduit,remote,ctxt); } static gint clear_status_archive_local (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, - gpointer data) + GCalLocalRecord *local, + GCalConduitContext *ctxt) { LOG ("entering clear_status_archive_local"); @@ -694,8 +694,8 @@ clear_status_archive_local (GnomePilotConduitStandardAbs *conduit, static gint iterate (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord **local, - gpointer data) + GCalLocalRecord **local, + GCalConduitContext *ctxt) { static GList *events,*iterator; static int hest; @@ -705,14 +705,14 @@ iterate (GnomePilotConduitStandardAbs *conduit, if(*local==NULL) { LOG ("beginning iteration"); - events = get_calendar_objects(conduit); + events = get_calendar_objects(conduit,ctxt); hest = 0; if(events!=NULL) { LOG ("iterating over %d records",g_list_length(events)); - *local = g_new0(CalLocalRecord,1); + *local = g_new0(GCalLocalRecord,1); - local_record_from_ical_uid(*local,(gchar*)events->data); + local_record_from_ical_uid(*local,(gchar*)events->data,ctxt); iterator = events; } else { LOG ("no events"); @@ -739,7 +739,7 @@ iterate (GnomePilotConduitStandardAbs *conduit, return 0; } else { iterator = g_list_next(iterator); - local_record_from_ical_uid(*local,(gchar*)(iterator->data)); + local_record_from_ical_uid(*local,(gchar*)(iterator->data),ctxt); } } return 1; @@ -747,10 +747,10 @@ iterate (GnomePilotConduitStandardAbs *conduit, static gint iterate_specific (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord **local, + GCalLocalRecord **local, gint flag, gint archived, - gpointer data) + GCalConduitContext *ctxt) { #ifdef DEBUG_CALCONDUIT { @@ -769,7 +769,6 @@ iterate_specific (GnomePilotConduitStandardAbs *conduit, /* iterate until a record meets the criteria */ while(gnome_pilot_conduit_standard_abs_iterate(conduit,(LocalRecord**)local)) { if((*local)==NULL) break; - /* g_print("calconduit: local->attr = %d, flag = %d, & %d\n",(*local)->local.attr,flag,((*local)->local.attr & flag)); */ if(archived && ((*local)->local.archived==archived)) break; if(((*local)->local.attr == flag)) break; } @@ -779,7 +778,7 @@ iterate_specific (GnomePilotConduitStandardAbs *conduit, static gint purge (GnomePilotConduitStandardAbs *conduit, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering purge"); @@ -791,9 +790,9 @@ purge (GnomePilotConduitStandardAbs *conduit, static gint set_status (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, gint status, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering set_status"); @@ -816,23 +815,23 @@ set_status (GnomePilotConduitStandardAbs *conduit, } if ( status != GnomePilotRecordDeleted) - GNOME_Calendar_Repository_update_pilot_id(calendar, + GNOME_Calendar_Repository_update_pilot_id(ctxt->calendar, local->ical->uid, local->local.ID, local->ical->pilot_status, - &ev); + &(ctxt->ev)); else - GNOME_Calendar_Repository_delete_object(calendar,local->ical->uid,&ev); + GNOME_Calendar_Repository_delete_object(ctxt->calendar,local->ical->uid,&(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ LOG ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return -1; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return -1; } return 0; @@ -840,9 +839,9 @@ set_status (GnomePilotConduitStandardAbs *conduit, static gint set_archived (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, gint archived, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering set_archived"); @@ -850,7 +849,7 @@ set_archived (GnomePilotConduitStandardAbs *conduit, g_assert(local->ical!=NULL); local->local.archived = archived; - update_calendar_entry_in_repository(conduit,local->ical); + update_calendar_entry_in_repository(conduit,local->ical,ctxt); /* FIXME: This should move the entry into a speciel calendar file, eg. Archive, or (by config option), simply delete it */ @@ -859,9 +858,9 @@ set_archived (GnomePilotConduitStandardAbs *conduit, static gint set_pilot_id (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, guint32 ID, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering set_pilot_id"); @@ -870,21 +869,21 @@ set_pilot_id (GnomePilotConduitStandardAbs *conduit, local->local.ID = ID; local->ical->pilot_id = ID; - GNOME_Calendar_Repository_update_pilot_id(calendar, + GNOME_Calendar_Repository_update_pilot_id(ctxt->calendar, local->ical->uid, local->local.ID, local->ical->pilot_status, - &ev); + &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ LOG ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return -1; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return -1; } return 0; @@ -892,9 +891,9 @@ set_pilot_id (GnomePilotConduitStandardAbs *conduit, static gint compare (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, PilotRecord *remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering compare"); @@ -906,9 +905,9 @@ compare (GnomePilotConduitStandardAbs *conduit, static gint compare_backup (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, PilotRecord *remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering compare_backup"); @@ -920,9 +919,9 @@ compare_backup (GnomePilotConduitStandardAbs *conduit, static gint free_transmit (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, PilotRecord **remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering free_transmit"); @@ -937,7 +936,7 @@ free_transmit (GnomePilotConduitStandardAbs *conduit, static gint delete_all (GnomePilotConduitStandardAbs *conduit, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering delete_all"); @@ -946,13 +945,12 @@ delete_all (GnomePilotConduitStandardAbs *conduit, static gint transmit (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, PilotRecord **remote, - gpointer data) + GCalConduitContext *ctxt) { PilotRecord *p; int daycount; - int x,y; LOG ("entering transmit"); @@ -1059,18 +1057,23 @@ transmit (GnomePilotConduitStandardAbs *conduit, p->length = pack_Appointment(local->a,p->record,0xffff); #if 0 - g_message("calconduit: new item from %s to %s",asctime(&(local->a->begin)),asctime(&(local->a->end))); - - g_message("local->a->note = %s",local->a->note); - g_message("local->a->description = %s",local->a->description); - g_message("sizeof(p->record) = %d, length is %d",sizeof(p->record),p->length); - for(x=0;x<p->length;x+=32) { - for(y=x;y<x+32;y++) - if(p->record[y]<33 || p->record[y]>128) - printf("%02X",p->record[y]); - else - printf(" %c",p->record[y]); - printf("\n"); + /* This is some debug code that hexdumps the calendar entry... + You won't need this. */ + { + int x,y; + g_message("calconduit: new item from %s to %s",asctime(&(local->a->begin)),asctime(&(local->a->end))); + + g_message("local->a->note = %s",local->a->note); + g_message("local->a->description = %s",local->a->description); + g_message("sizeof(p->record) = %d, length is %d",sizeof(p->record),p->length); + for(x=0;x<p->length;x+=32) { + for(y=x;y<x+32;y++) + if(p->record[y]<33 || p->record[y]>128) + printf("%02X",p->record[y]); + else + printf(" %c",p->record[y]); + printf("\n"); + } } #endif @@ -1083,43 +1086,42 @@ GnomePilotConduit * conduit_get_gpilot_conduit (guint32 pilotId) { GtkObject *retval; - ConduitCfg *cfg; - ConduitData *cdata; + GCalConduitCfg *cfg; + GCalConduitContext *ctxt; - CORBA_exception_init (&ev); retval = gnome_pilot_conduit_standard_abs_new ("DatebookDB", 0x64617465); g_assert (retval != NULL); - gnome_pilot_conduit_construct(GNOME_PILOT_CONDUIT(retval),"calendar"); - - cfg = g_new0(ConduitCfg,1); - g_assert(cfg != NULL); - gtk_object_set_data(retval,"conduit_cfg",cfg); - - cdata = g_new0(ConduitData,1); - g_assert(cdata != NULL); - gtk_object_set_data(retval,"conduit_data",cdata); - - gtk_signal_connect (retval, "match_record", (GtkSignalFunc) match_record, NULL); - gtk_signal_connect (retval, "free_match", (GtkSignalFunc) free_match, NULL); - gtk_signal_connect (retval, "archive_local", (GtkSignalFunc) archive_local, NULL); - gtk_signal_connect (retval, "archive_remote", (GtkSignalFunc) archive_remote, NULL); - gtk_signal_connect (retval, "store_remote", (GtkSignalFunc) store_remote, NULL); - gtk_signal_connect (retval, "clear_status_archive_local", (GtkSignalFunc) clear_status_archive_local, NULL); - gtk_signal_connect (retval, "iterate", (GtkSignalFunc) iterate, NULL); - gtk_signal_connect (retval, "iterate_specific", (GtkSignalFunc) iterate_specific, NULL); - gtk_signal_connect (retval, "purge", (GtkSignalFunc) purge, NULL); - gtk_signal_connect (retval, "set_status", (GtkSignalFunc) set_status, NULL); - gtk_signal_connect (retval, "set_archived", (GtkSignalFunc) set_archived, NULL); - gtk_signal_connect (retval, "set_pilot_id", (GtkSignalFunc) set_pilot_id, NULL); - gtk_signal_connect (retval, "compare", (GtkSignalFunc) compare, NULL); - gtk_signal_connect (retval, "compare_backup", (GtkSignalFunc) compare_backup, NULL); - gtk_signal_connect (retval, "free_transmit", (GtkSignalFunc) free_transmit, NULL); - gtk_signal_connect (retval, "delete_all", (GtkSignalFunc) delete_all, NULL); - gtk_signal_connect (retval, "transmit", (GtkSignalFunc) transmit, NULL); - gtk_signal_connect (retval, "pre_sync", (GtkSignalFunc) pre_sync, NULL); - - load_configuration(&cfg,pilotId); + gnome_pilot_conduit_construct(GNOME_PILOT_CONDUIT(retval),"GnomeCalConduit"); + + gcalconduit_load_configuration(&cfg,pilotId); + gtk_object_set_data(retval,"gcalconduit_cfg",cfg); + + gcalconduit_new_context(&ctxt,cfg); + /* No real need to set it, since all signal are given this + as their user data */ + gtk_object_set_data(retval,"gcalconduit_context",ctxt); + + gtk_signal_connect (retval, "match_record", (GtkSignalFunc) match_record, ctxt); + gtk_signal_connect (retval, "free_match", (GtkSignalFunc) free_match, ctxt); + gtk_signal_connect (retval, "archive_local", (GtkSignalFunc) archive_local, ctxt); + gtk_signal_connect (retval, "archive_remote", (GtkSignalFunc) archive_remote, ctxt); + gtk_signal_connect (retval, "store_remote", (GtkSignalFunc) store_remote, ctxt); + gtk_signal_connect (retval, "clear_status_archive_local", (GtkSignalFunc) clear_status_archive_local, ctxt); + gtk_signal_connect (retval, "iterate", (GtkSignalFunc) iterate, ctxt); + gtk_signal_connect (retval, "iterate_specific", (GtkSignalFunc) iterate_specific, ctxt); + gtk_signal_connect (retval, "purge", (GtkSignalFunc) purge, ctxt); + gtk_signal_connect (retval, "set_status", (GtkSignalFunc) set_status, ctxt); + gtk_signal_connect (retval, "set_archived", (GtkSignalFunc) set_archived, ctxt); + gtk_signal_connect (retval, "set_pilot_id", (GtkSignalFunc) set_pilot_id, ctxt); + gtk_signal_connect (retval, "compare", (GtkSignalFunc) compare, ctxt); + gtk_signal_connect (retval, "compare_backup", (GtkSignalFunc) compare_backup, ctxt); + gtk_signal_connect (retval, "free_transmit", (GtkSignalFunc) free_transmit, ctxt); + gtk_signal_connect (retval, "delete_all", (GtkSignalFunc) delete_all, ctxt); + gtk_signal_connect (retval, "transmit", (GtkSignalFunc) transmit, ctxt); + gtk_signal_connect (retval, "pre_sync", (GtkSignalFunc) pre_sync, ctxt); + + return GNOME_PILOT_CONDUIT (retval); } @@ -1127,17 +1129,18 @@ conduit_get_gpilot_conduit (guint32 pilotId) void conduit_destroy_gpilot_conduit (GnomePilotConduit *conduit) { - ConduitCfg *cc; - ConduitData *cd; + GCalConduitCfg *cc; + GCalConduitContext *ctxt; + + cc = GET_GCALCONFIG(conduit); + ctxt = GET_GCALCONTEXT(conduit); - if(calendar!=CORBA_OBJECT_NIL) - GNOME_Calendar_Repository_done (calendar, &ev); + if(ctxt->calendar!=CORBA_OBJECT_NIL) + GNOME_Calendar_Repository_done (ctxt->calendar, &(ctxt->ev)); - cc = GET_CONFIG(conduit); - destroy_configuration(&cc); + gcalconduit_destroy_configuration(&cc); - cd = GET_DATA(conduit); - g_free(cd); + gcalconduit_destroy_context(&ctxt); gtk_object_destroy (GTK_OBJECT (conduit)); diff --git a/calendar/conduits/calendar/calendar-conduit.h b/calendar/conduits/calendar/calendar-conduit.h index d8b320c1ce..cee7d3386e 100644 --- a/calendar/conduits/calendar/calendar-conduit.h +++ b/calendar/conduits/calendar/calendar-conduit.h @@ -17,55 +17,119 @@ #include <gpilotd/gnome-pilot-conduit.h> #include <gpilotd/gnome-pilot-conduit-standard-abs.h> -#define CALLOCALRECORD(s) ((CalLocalRecord*)(s)) -typedef struct _CalLocalRecord CalLocalRecord; - -struct _CalLocalRecord { - /* The stuff from gnome-pilot-conduit-standard-abs.h */ +/* This is the local record structure for the GnomeCal conduit. */ +typedef struct _GCalLocalRecord GCalLocalRecord; +struct _GCalLocalRecord { + /* The stuff from gnome-pilot-conduit-standard-abs.h + Must be first in the structure, or instances of this + structure cannot be used by gnome-pilot-conduit-standard-abs. + */ LocalRecord local; - /* The corresponding iCal object */ + /* The corresponding iCal object, as found by GnomeCal. */ iCalObject *ical; - /* pilot-link appointment structure, used for implementing Transmit */ + /* pilot-link appointment structure, used for implementing Transmit. */ struct Appointment *a; }; +#define GCAL_LOCALRECORD(s) ((GCalLocalRecord*)(s)) -typedef struct _ConduitCfg ConduitCfg; - -struct _ConduitCfg { - gboolean open_secret; - guint32 pilotId; +/* This is the configuration of the GnomeCal conduit. */ +typedef struct _GCalConduitCfg GCalConduitCfg; +struct _GCalConduitCfg { + gboolean open_secret; + guint32 pilotId; }; +#define GET_GCALCONFIG(c) ((GCalConduitCfg*)gtk_object_get_data(GTK_OBJECT(c),"gcalconduit_cfg")) + +/* This is the context for all the GnomeCal conduit methods. */ +typedef struct _GCalConduitContext GCalConduitContext; +struct _GCalConduitContext { + struct AppointmentAppInfo ai; + GCalConduitCfg *cfg; + GNOME_Calendar_Repository calendar; + CORBA_Environment ev; + CORBA_ORB orb; +}; +#define GET_GCALCONTEXT(c) ((GCalConduitContext*)gtk_object_get_data(GTK_OBJECT(c),"gcalconduit_context")) + +/* Given a GCalConduitCfg*, allocates the structure and + loads the configuration data for the given pilot. */ +static void +gcalconduit_load_configuration(GCalConduitCfg **c, + guint32 pilotId) +{ + gchar prefix[256]; + g_snprintf(prefix,255,"/gnome-pilot.d/calendard-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"); + gnome_config_pop_prefix(); + + (*c)->pilotId = pilotId; +} -#define GET_CONFIG(c) ((ConduitCfg*)gtk_object_get_data(GTK_OBJECT(c),"conduit_cfg")) +/* Saves the configuration data. */ +static void +gcalconduit_save_configuration(GCalConduitCfg *c) +{ + gchar prefix[256]; -static void load_configuration(ConduitCfg **c,guint32 pilotId) { - gchar prefix[256]; - g_snprintf(prefix,255,"/gnome-pilot.d/calendard-conduit/Pilot_%u/",pilotId); + g_snprintf(prefix,255,"/gnome-pilot.d/calendar-conduit/Pilot_%u/",c->pilotId); - *c = g_new0(ConduitCfg,1); - gnome_config_push_prefix(prefix); - (*c)->open_secret = gnome_config_get_bool("open secret=FALSE"); - gnome_config_pop_prefix(); + gnome_config_push_prefix(prefix); + gnome_config_set_bool("open_secret",c->open_secret); + gnome_config_pop_prefix(); - (*c)->pilotId = pilotId; + gnome_config_sync(); + gnome_config_drop_all(); } -static void save_configuration(ConduitCfg *c) { - gchar prefix[256]; - - g_snprintf(prefix,255,"/gnome-pilot.d/calendar-conduit/Pilot_%u/",c->pilotId); - - gnome_config_push_prefix(prefix); - gnome_config_set_bool("open secret",c->open_secret); - gnome_config_pop_prefix(); +/* 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->open_secret = c->open_secret; + retval->pilotId = c->pilotId; + return retval; +} - gnome_config_sync(); - gnome_config_drop_all(); +/* 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; } -static void destroy_configuration(ConduitCfg **c) { - g_free(*c); - *c = NULL; +/* Given a GCalConduitContxt*, allocates the structure */ +static void +gcalconduit_new_context(GCalConduitContext **ctxt, + GCalConduitCfg *c) +{ + *ctxt = g_new0(GCalConduitContext,1); + g_assert(ctxt!=NULL); + (*ctxt)->cfg = c; + CORBA_exception_init (&((*ctxt)->ev)); } +/* Destroys any data allocated by gcalconduit_new_context + and deallocates its data. */ +static void +gcalconduit_destroy_context(GCalConduitContext **ctxt) +{ + g_return_if_fail(ctxt!=NULL); + g_return_if_fail(*ctxt!=NULL); +/* + if ((*ctxt)->cfg!=NULL) + gcalconduit_destroy_configuration(&((*ctxt)->cfg)); +*/ + g_free(*ctxt); + *ctxt = NULL; +} #endif __CALENDAR_CONDUIT_H__ diff --git a/calendar/conduits/todo/todo-conduit-control-applet.c b/calendar/conduits/todo/todo-conduit-control-applet.c index 973a6192c8..54a26715ef 100644 --- a/calendar/conduits/todo/todo-conduit-control-applet.c +++ b/calendar/conduits/todo/todo-conduit-control-applet.c @@ -38,7 +38,7 @@ static void doSaveSettings(GtkWidget *widget, ConduitCfg *conduitCfg); static void readStateCfg(GtkWidget *w); static void setStateCfg(GtkWidget *w); -gchar *pilotId; +gint pilotId; CORBA_Environment ev; static void @@ -223,28 +223,29 @@ void run_error_dialog(gchar *mesg,...) { va_end(ap); } -gchar *get_pilot_id_from_gpilotd() { - gchar **pilots; - int i; +gint get_pilot_id_from_gpilotd() { + gint *pilots; + int i; - i=0; - gpilotd_get_pilots(&pilots); - if(pilots) { - while(pilots[i]) { g_message("pilot %d = \"%s\"",i,pilots[i]); i++; } - if(i==0) { - run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); - return NULL; - } else - if(i==1) - return pilots[0]; - else { - g_message("too many pilots..."); - return pilots[0]; - } - } else { - run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); - return NULL; - } + i=0; + gpilotd_get_pilot_ids(&pilots); + if(pilots) { + while(pilots[i]!=-1) { g_message("pilot %d = \"%d\"",i,pilots[i]); i++; } + if(i==0) { + run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); + return -1; + } else { + if(i==1) + return pilots[0]; + else { + g_message("too many pilots..."); + return pilots[0]; + } + } + } else { + run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); + return -1; + } } int @@ -282,6 +283,5 @@ main( int argc, char *argv[] ) /* done setting up, now run main loop */ capplet_gtk_main(); - g_free(pilotId); return 0; } diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am index cb03a4eacb..4042368bff 100644 --- a/calendar/gui/Makefile.am +++ b/calendar/gui/Makefile.am @@ -11,7 +11,6 @@ help_base = $(datadir)/gnome/help/cal if HAVE_GNOME_PILOT bin_PROGRAMS = \ gnomecal \ - todo-conduit-control-applet \ calendar-conduit-control-applet \ calendar-pilot-sync else @@ -158,34 +157,34 @@ calendar_conduit_control_applet_LDADD = \ $(INTLLIBS) #todo_conduit -todo_conduitsdir=$(libdir)/gnome-pilot/conduits +#todo_conduitsdir=$(libdir)/gnome-pilot/conduits -todo_conduits_LTLIBRARIES = libtodo_conduit.la +#todo_conduits_LTLIBRARIES = libtodo_conduit.la -libtodo_conduit_la_LDFLAGS = \ - -rpath $(libdir) +#libtodo_conduit_la_LDFLAGS = \ +# -rpath $(libdir) -libtodo_conduit_la_LIBADD = \ - $(GNOME_LIBDIR) \ - $(GNOME_LIBS) +#libtodo_conduit_la_LIBADD = \ +# $(GNOME_LIBDIR) \ +# $(GNOME_LIBS) -libtodo_conduit_la_SOURCES = \ - todo-conduit.c +#libtodo_conduit_la_SOURCES = \ +# todo-conduit.c -todo-conduit.c: GnomeCal.h +#todo-conduit.c: GnomeCal.h -todo_conduit_control_applet_SOURCES = \ - todo-conduit-control-applet.c +#todo_conduit_control_applet_SOURCES = \ +# todo-conduit-control-applet.c -todo_conduit_control_applet_LDADD = \ - $(CAPPLET_LIBS) \ - $(GNOME_LIBDIR) \ - $(GNOME_CAPPLET_LIBS) \ - $(PISOCK_LIBS) \ - $(GNOMEUI_LIBS) \ - $(PISOCK_LIBS) \ - $(GNOME_PILOT_LIBS) \ - $(INTLLIBS) +#todo_conduit_control_applet_LDADD = \ +# $(CAPPLET_LIBS) \ +# $(GNOME_LIBDIR) \ +# $(GNOME_CAPPLET_LIBS) \ +# $(PISOCK_LIBS) \ +# $(GNOMEUI_LIBS) \ +# $(PISOCK_LIBS) \ +# $(GNOME_PILOT_LIBS) \ +# $(INTLLIBS) endif gnomecal_LDADD = $(LINK_FLAGS) diff --git a/calendar/gui/calendar-conduit-control-applet.c b/calendar/gui/calendar-conduit-control-applet.c index 4b18ae920f..57f4a07cc8 100644 --- a/calendar/gui/calendar-conduit-control-applet.c +++ b/calendar/gui/calendar-conduit-control-applet.c @@ -32,18 +32,21 @@ GtkWidget *dialogWindow=NULL; gboolean activated,org_activation_state; GnomePilotConduitMgmt *conduit; -static void doTrySettings(GtkWidget *widget, ConduitCfg *conduitCfg); -static void doRevertSettings(GtkWidget *widget, ConduitCfg *conduitCfg); -static void doSaveSettings(GtkWidget *widget, ConduitCfg *conduitCfg); +static void doTrySettings(GtkWidget *widget, GCalConduitCfg *conduitCfg); +static void doRevertSettings(GtkWidget *widget, GCalConduitCfg *conduitCfg); +static void doSaveSettings(GtkWidget *widget, GCalConduitCfg *conduitCfg); static void readStateCfg(GtkWidget *w); static void setStateCfg(GtkWidget *w); -gchar *pilotId; +GCalConduitCfg *origState = NULL; +GCalConduitCfg *curState = NULL; + +gint pilotId; CORBA_Environment ev; static void -doTrySettings(GtkWidget *widget, ConduitCfg *conduitCfg) +doTrySettings(GtkWidget *widget, GCalConduitCfg *conduitCfg) { readStateCfg(cfgStateWindow); if(activated) @@ -53,15 +56,15 @@ doTrySettings(GtkWidget *widget, ConduitCfg *conduitCfg) } static void -doSaveSettings(GtkWidget *widget, ConduitCfg *conduitCfg) +doSaveSettings(GtkWidget *widget, GCalConduitCfg *conduitCfg) { doTrySettings(widget, conduitCfg); - save_configuration(NULL); + gcalconduit_save_configuration(conduitCfg); } static void -doRevertSettings(GtkWidget *widget, ConduitCfg *conduitCfg) +doRevertSettings(GtkWidget *widget, GCalConduitCfg *conduitCfg) { activated = org_activation_state; setStateCfg(cfgStateWindow); @@ -203,7 +206,7 @@ pilot_capplet_setup(void) gtk_signal_connect(GTK_OBJECT(capplet), "revert", GTK_SIGNAL_FUNC(doRevertSettings), NULL); gtk_signal_connect(GTK_OBJECT(capplet), "ok", - GTK_SIGNAL_FUNC(doSaveSettings), NULL); + GTK_SIGNAL_FUNC(doSaveSettings), curState); gtk_signal_connect(GTK_OBJECT(capplet), "help", GTK_SIGNAL_FUNC(about_cb), NULL); @@ -224,28 +227,29 @@ void run_error_dialog(gchar *mesg,...) { va_end(ap); } -gchar *get_pilot_id_from_gpilotd() { - gchar **pilots; - int i; +gint get_pilot_id_from_gpilotd() { + gint *pilots; + int i; - i=0; - gpilotd_get_pilots(&pilots); - if(pilots) { - while(pilots[i]) { g_message("pilot %d = \"%s\"",i,pilots[i]); i++; } - if(i==0) { - run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); - return NULL; - } else - if(i==1) - return pilots[0]; - else { - g_message("too many pilots..."); - return pilots[0]; - } - } else { - run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); - return NULL; - } + i=0; + gpilotd_get_pilot_ids(&pilots); + if(pilots) { + while(pilots[i]!=-1) { g_message("pilot %d = \"%d\"",i,pilots[i]); i++; } + if(i==0) { + run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); + return -1; + } else { + if(i==1) + return pilots[0]; + else { + g_message("too many pilots..."); + return pilots[0]; + } + } + } else { + run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); + return -1; + } } int @@ -276,6 +280,11 @@ main( int argc, char *argv[] ) pilotId = get_pilot_id_from_gpilotd(); if(!pilotId) return -1; + + /* put all code to set things up in here */ + gcalconduit_load_configuration(&origState,pilotId); + curState = gcalconduit_dupe_configuration(origState); + org_activation_state = activated = gpilotd_conduit_mgmt_is_enabled(conduit,pilotId); pilot_capplet_setup(); @@ -283,6 +292,5 @@ main( int argc, char *argv[] ) /* done setting up, now run main loop */ capplet_gtk_main(); - g_free(pilotId); return 0; } diff --git a/calendar/gui/calendar-conduit-control-applet.desktop b/calendar/gui/calendar-conduit-control-applet.desktop index 869bba1476..aaaa7bd2c8 100644 --- a/calendar/gui/calendar-conduit-control-applet.desktop +++ b/calendar/gui/calendar-conduit-control-applet.desktop @@ -1,6 +1,6 @@ [Desktop Entry] -Name=Calendar conduit -Comment=Configure the calendar conduit +Name=GnomeCalendar +Comment=Configure the GnomeCal conduit Exec=calendar-conduit-control-applet --cap-id=1 Terminal=0 Type=Application diff --git a/calendar/gui/calendar-conduit.c b/calendar/gui/calendar-conduit.c index 193cc52e04..400824186a 100644 --- a/calendar/gui/calendar-conduit.c +++ b/calendar/gui/calendar-conduit.c @@ -32,16 +32,10 @@ GnomePilotConduit * conduit_get_gpilot_conduit (guint32); void conduit_destroy_gpilot_conduit (GnomePilotConduit*); -void local_record_from_icalobject(CalLocalRecord *local,iCalObject *obj); - -typedef struct _ConduitData ConduitData; - -struct _ConduitData { - struct AppointmentAppInfo ai; -}; +void local_record_from_icalobject(GCalLocalRecord *local,iCalObject *obj); #define CONDUIT_VERSION "0.8.0" -#define DEBUG_CALCONDUIT +/* #define DEBUG_CALCONDUIT */ #ifdef DEBUG_CALCONDUIT #define show_exception(e) g_warning ("Exception: %s\n", CORBA_exception_id (e)) @@ -54,30 +48,28 @@ struct _ConduitData { #define WARN(e...) g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING, e) #define INFO(e...) g_log(G_LOG_DOMAIN,G_LOG_LEVEL_MESSAGE, "calconduit: "##e) -#define GET_DATA(c) ((ConduitData*)gtk_object_get_data(GTK_OBJECT(c),"conduit_data")) - -GNOME_Calendar_Repository calendar; -CORBA_Environment ev; -CORBA_ORB orb; - -static GNOME_Calendar_Repository -start_calendar_server (GnomePilotConduitStandardAbs *conduit) +static int +start_calendar_server (GnomePilotConduitStandardAbs *conduit, + GCalConduitContext *ctxt) { - g_return_val_if_fail(conduit!=NULL,CORBA_OBJECT_NIL); - - calendar = goad_server_activate_with_id (NULL, - "IDL:GNOME:Calendar:Repository:1.0", - 0, NULL); - if (calendar == CORBA_OBJECT_NIL) + + g_return_val_if_fail(conduit!=NULL,-2); + g_return_val_if_fail(ctxt!=NULL,-2); + + ctxt->calendar = goad_server_activate_with_id (NULL, + "IDL:GNOME:Calendar:Repository:1.0", + 0, NULL); + if (ctxt->calendar == CORBA_OBJECT_NIL) { g_error ("Can not communicate with GnomeCalendar server"); - - if (ev._major != CORBA_NO_EXCEPTION){ - show_exception(&ev); - CORBA_exception_free(&ev); - return CORBA_OBJECT_NIL; + return -1; } - return calendar; + if (ctxt->ev._major != CORBA_NO_EXCEPTION){ + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); + return -1; + } + return 0; } @@ -88,25 +80,27 @@ calendar_notify (time_t time, CalendarAlarm *which, void *data) } static GList * -get_calendar_objects(GnomePilotConduitStandardAbs *conduit) +get_calendar_objects(GnomePilotConduitStandardAbs *conduit, + GCalConduitContext *ctxt) { GList *result; GNOME_Calendar_Repository_String_Sequence *uids; g_return_val_if_fail(conduit!=NULL,NULL); + g_return_val_if_fail(ctxt!=NULL,NULL); result = NULL; - uids = GNOME_Calendar_Repository_get_object_id_list (calendar, &ev); + uids = GNOME_Calendar_Repository_get_object_id_list (ctxt->calendar, &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ INFO ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return NULL; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return NULL; } @@ -174,25 +168,26 @@ get_calendar_objects(GnomePilotConduitStandardAbs *conduit) #endif static void -local_record_from_ical_uid(CalLocalRecord *local, - char *uid) +local_record_from_ical_uid(GCalLocalRecord *local, + char *uid, + GCalConduitContext *ctxt) { iCalObject *obj; char *vcalendar_string; g_assert(local!=NULL); - vcalendar_string = GNOME_Calendar_Repository_get_object(calendar, uid, &ev); + vcalendar_string = GNOME_Calendar_Repository_get_object(ctxt->calendar, uid, &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ INFO ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return; } g_return_if_fail(vcalendar_string!=NULL); @@ -206,11 +201,11 @@ local_record_from_ical_uid(CalLocalRecord *local, /* - * converts a iCalObject to a CalLocalRecord + * converts a iCalObject to a GCalLocalRecord */ void -local_record_from_icalobject(CalLocalRecord *local, +local_record_from_icalobject(GCalLocalRecord *local, iCalObject *obj) { g_return_if_fail(local!=NULL); @@ -250,33 +245,34 @@ local_record_from_icalobject(CalLocalRecord *local, * Given a PilotRecord, find the matching record in * the calendar repository. If no match, return NULL */ -static CalLocalRecord * +static GCalLocalRecord * find_record_in_repository(GnomePilotConduitStandardAbs *conduit, - PilotRecord *remote) + PilotRecord *remote, + GCalConduitContext *ctxt) { char *vcal_string; - CalLocalRecord *loc; + GCalLocalRecord *loc; g_return_val_if_fail(conduit!=NULL,NULL); g_return_val_if_fail(remote!=NULL,NULL); vcal_string = - GNOME_Calendar_Repository_get_object_by_pilot_id (calendar, remote->ID, &ev); + GNOME_Calendar_Repository_get_object_by_pilot_id (ctxt->calendar, remote->ID, &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ INFO ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return NULL; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return NULL; } else { LOG ("Found"); - loc = g_new0(CalLocalRecord,1); + loc = g_new0(GCalLocalRecord,1); /* memory allocated in new_from_string is freed in free_match */ local_record_from_icalobject(loc, ical_object_new_from_string (vcal_string)); @@ -292,7 +288,8 @@ find_record_in_repository(GnomePilotConduitStandardAbs *conduit, */ static void update_calendar_entry_in_repository(GnomePilotConduitStandardAbs *conduit, - iCalObject *obj) + iCalObject *obj, + GCalConduitContext *ctxt) { char *str; @@ -301,17 +298,17 @@ update_calendar_entry_in_repository(GnomePilotConduitStandardAbs *conduit, str = calendar_string_from_object (obj); - GNOME_Calendar_Repository_update_object (calendar, obj->uid, str, &ev); + GNOME_Calendar_Repository_update_object (ctxt->calendar, obj->uid, str, &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ INFO ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return; } @@ -506,7 +503,8 @@ ical_from_remote_record(GnomePilotConduitStandardAbs *conduit, */ static gint update_record (GnomePilotConduitStandardAbs *conduit, - PilotRecord *remote) + PilotRecord *remote, + GCalConduitContext *ctxt) { char *vcal_string; iCalObject *obj; @@ -522,17 +520,17 @@ update_record (GnomePilotConduitStandardAbs *conduit, a.description ? a.description : ""); LOG ("requesting %ld [%s]", remote->ID, a.description); - vcal_string = GNOME_Calendar_Repository_get_object_by_pilot_id (calendar, remote->ID, &ev); + vcal_string = GNOME_Calendar_Repository_get_object_by_pilot_id (ctxt->calendar, remote->ID, &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ - WARN (_("Object did not exist, creating a new one")); - show_exception(&ev); - CORBA_exception_free(&ev); + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ + LOG (_("Object did not exist, creating a new one")); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); ical_from_remote_record(conduit,remote,obj); - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); ical_object_destroy (obj); free_Appointment(&a); return -1; @@ -546,7 +544,7 @@ update_record (GnomePilotConduitStandardAbs *conduit, /* update record on server */ - update_calendar_entry_in_repository(conduit,obj); + update_calendar_entry_in_repository(conduit,obj,ctxt); /* * Shutdown @@ -559,16 +557,18 @@ update_record (GnomePilotConduitStandardAbs *conduit, static gint -pre_sync(GnomePilotConduit *c, GnomePilotDBInfo *dbi) +pre_sync(GnomePilotConduit *c, + GnomePilotDBInfo *dbi, + GCalConduitContext *ctxt) { int l; unsigned char *buf; - INFO (CONDUIT_VERSION); + g_message ("GnomeCal Conduit v.%s",CONDUIT_VERSION); - calendar = CORBA_OBJECT_NIL; - calendar = start_calendar_server(GNOME_PILOT_CONDUIT_STANDARD_ABS(c)); - if(calendar == CORBA_OBJECT_NIL) { + ctxt->calendar = CORBA_OBJECT_NIL; + + if (start_calendar_server(GNOME_PILOT_CONDUIT_STANDARD_ABS(c),GET_GCALCONTEXT(c)) != 0) { return -1; } @@ -580,7 +580,7 @@ pre_sync(GnomePilotConduit *c, GnomePilotDBInfo *dbi) if((l=dlp_ReadAppBlock(dbi->pilot_socket,dbi->db_handle,0,(unsigned char *)buf,0xffff))<0) { return -1; } - unpack_AppointmentAppInfo(&(GET_DATA(c)->ai),buf,l); + unpack_AppointmentAppInfo(&(ctxt->ai),buf,l); g_free(buf); return 0; @@ -596,16 +596,16 @@ pre_sync(GnomePilotConduit *c, GnomePilotDBInfo *dbi) static gint match_record (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord **local, + GCalLocalRecord **local, PilotRecord *remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("in match_record"); g_return_val_if_fail(local!=NULL,-1); g_return_val_if_fail(remote!=NULL,-1); - *local = find_record_in_repository(conduit,remote); + *local = find_record_in_repository(conduit,remote,ctxt); if (*local==NULL) return -1; return 0; @@ -618,15 +618,15 @@ match_record (GnomePilotConduitStandardAbs *conduit, */ static gint free_match (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord **local, - gpointer data) + GCalLocalRecord **local, + GCalConduitContext *ctxt) { LOG ("entering free_match"); g_return_val_if_fail(local!=NULL,-1); g_return_val_if_fail(*local!=NULL,-1); - ical_object_destroy (CALLOCALRECORD(*local)->ical); + ical_object_destroy (GCAL_LOCALRECORD(*local)->ical); g_free(*local); *local = NULL; @@ -638,8 +638,8 @@ free_match (GnomePilotConduitStandardAbs *conduit, */ static gint archive_local (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, - gpointer data) + GCalLocalRecord *local, + GCalConduitContext *ctxt) { LOG ("entering archive_local"); @@ -653,9 +653,9 @@ archive_local (GnomePilotConduitStandardAbs *conduit, */ static gint archive_remote (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, PilotRecord *remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering archive_remote"); @@ -671,19 +671,19 @@ archive_remote (GnomePilotConduitStandardAbs *conduit, static gint store_remote (GnomePilotConduitStandardAbs *conduit, PilotRecord *remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering store_remote"); g_return_val_if_fail(remote!=NULL,-1); - return update_record(conduit,remote); + return update_record(conduit,remote,ctxt); } static gint clear_status_archive_local (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, - gpointer data) + GCalLocalRecord *local, + GCalConduitContext *ctxt) { LOG ("entering clear_status_archive_local"); @@ -694,8 +694,8 @@ clear_status_archive_local (GnomePilotConduitStandardAbs *conduit, static gint iterate (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord **local, - gpointer data) + GCalLocalRecord **local, + GCalConduitContext *ctxt) { static GList *events,*iterator; static int hest; @@ -705,14 +705,14 @@ iterate (GnomePilotConduitStandardAbs *conduit, if(*local==NULL) { LOG ("beginning iteration"); - events = get_calendar_objects(conduit); + events = get_calendar_objects(conduit,ctxt); hest = 0; if(events!=NULL) { LOG ("iterating over %d records",g_list_length(events)); - *local = g_new0(CalLocalRecord,1); + *local = g_new0(GCalLocalRecord,1); - local_record_from_ical_uid(*local,(gchar*)events->data); + local_record_from_ical_uid(*local,(gchar*)events->data,ctxt); iterator = events; } else { LOG ("no events"); @@ -739,7 +739,7 @@ iterate (GnomePilotConduitStandardAbs *conduit, return 0; } else { iterator = g_list_next(iterator); - local_record_from_ical_uid(*local,(gchar*)(iterator->data)); + local_record_from_ical_uid(*local,(gchar*)(iterator->data),ctxt); } } return 1; @@ -747,10 +747,10 @@ iterate (GnomePilotConduitStandardAbs *conduit, static gint iterate_specific (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord **local, + GCalLocalRecord **local, gint flag, gint archived, - gpointer data) + GCalConduitContext *ctxt) { #ifdef DEBUG_CALCONDUIT { @@ -769,7 +769,6 @@ iterate_specific (GnomePilotConduitStandardAbs *conduit, /* iterate until a record meets the criteria */ while(gnome_pilot_conduit_standard_abs_iterate(conduit,(LocalRecord**)local)) { if((*local)==NULL) break; - /* g_print("calconduit: local->attr = %d, flag = %d, & %d\n",(*local)->local.attr,flag,((*local)->local.attr & flag)); */ if(archived && ((*local)->local.archived==archived)) break; if(((*local)->local.attr == flag)) break; } @@ -779,7 +778,7 @@ iterate_specific (GnomePilotConduitStandardAbs *conduit, static gint purge (GnomePilotConduitStandardAbs *conduit, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering purge"); @@ -791,9 +790,9 @@ purge (GnomePilotConduitStandardAbs *conduit, static gint set_status (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, gint status, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering set_status"); @@ -816,23 +815,23 @@ set_status (GnomePilotConduitStandardAbs *conduit, } if ( status != GnomePilotRecordDeleted) - GNOME_Calendar_Repository_update_pilot_id(calendar, + GNOME_Calendar_Repository_update_pilot_id(ctxt->calendar, local->ical->uid, local->local.ID, local->ical->pilot_status, - &ev); + &(ctxt->ev)); else - GNOME_Calendar_Repository_delete_object(calendar,local->ical->uid,&ev); + GNOME_Calendar_Repository_delete_object(ctxt->calendar,local->ical->uid,&(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ LOG ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return -1; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return -1; } return 0; @@ -840,9 +839,9 @@ set_status (GnomePilotConduitStandardAbs *conduit, static gint set_archived (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, gint archived, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering set_archived"); @@ -850,7 +849,7 @@ set_archived (GnomePilotConduitStandardAbs *conduit, g_assert(local->ical!=NULL); local->local.archived = archived; - update_calendar_entry_in_repository(conduit,local->ical); + update_calendar_entry_in_repository(conduit,local->ical,ctxt); /* FIXME: This should move the entry into a speciel calendar file, eg. Archive, or (by config option), simply delete it */ @@ -859,9 +858,9 @@ set_archived (GnomePilotConduitStandardAbs *conduit, static gint set_pilot_id (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, guint32 ID, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering set_pilot_id"); @@ -870,21 +869,21 @@ set_pilot_id (GnomePilotConduitStandardAbs *conduit, local->local.ID = ID; local->ical->pilot_id = ID; - GNOME_Calendar_Repository_update_pilot_id(calendar, + GNOME_Calendar_Repository_update_pilot_id(ctxt->calendar, local->ical->uid, local->local.ID, local->ical->pilot_status, - &ev); + &(ctxt->ev)); - if (ev._major == CORBA_USER_EXCEPTION){ + if (ctxt->ev._major == CORBA_USER_EXCEPTION){ LOG ("Object did not exist"); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return -1; - } else if(ev._major != CORBA_NO_EXCEPTION) { + } else if(ctxt->ev._major != CORBA_NO_EXCEPTION) { WARN (_("Error while communicating with calendar server")); - show_exception(&ev); - CORBA_exception_free(&ev); + show_exception(&(ctxt->ev)); + CORBA_exception_free(&(ctxt->ev)); return -1; } return 0; @@ -892,9 +891,9 @@ set_pilot_id (GnomePilotConduitStandardAbs *conduit, static gint compare (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, PilotRecord *remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering compare"); @@ -906,9 +905,9 @@ compare (GnomePilotConduitStandardAbs *conduit, static gint compare_backup (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, PilotRecord *remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering compare_backup"); @@ -920,9 +919,9 @@ compare_backup (GnomePilotConduitStandardAbs *conduit, static gint free_transmit (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, PilotRecord **remote, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering free_transmit"); @@ -937,7 +936,7 @@ free_transmit (GnomePilotConduitStandardAbs *conduit, static gint delete_all (GnomePilotConduitStandardAbs *conduit, - gpointer data) + GCalConduitContext *ctxt) { LOG ("entering delete_all"); @@ -946,13 +945,12 @@ delete_all (GnomePilotConduitStandardAbs *conduit, static gint transmit (GnomePilotConduitStandardAbs *conduit, - CalLocalRecord *local, + GCalLocalRecord *local, PilotRecord **remote, - gpointer data) + GCalConduitContext *ctxt) { PilotRecord *p; int daycount; - int x,y; LOG ("entering transmit"); @@ -1059,18 +1057,23 @@ transmit (GnomePilotConduitStandardAbs *conduit, p->length = pack_Appointment(local->a,p->record,0xffff); #if 0 - g_message("calconduit: new item from %s to %s",asctime(&(local->a->begin)),asctime(&(local->a->end))); - - g_message("local->a->note = %s",local->a->note); - g_message("local->a->description = %s",local->a->description); - g_message("sizeof(p->record) = %d, length is %d",sizeof(p->record),p->length); - for(x=0;x<p->length;x+=32) { - for(y=x;y<x+32;y++) - if(p->record[y]<33 || p->record[y]>128) - printf("%02X",p->record[y]); - else - printf(" %c",p->record[y]); - printf("\n"); + /* This is some debug code that hexdumps the calendar entry... + You won't need this. */ + { + int x,y; + g_message("calconduit: new item from %s to %s",asctime(&(local->a->begin)),asctime(&(local->a->end))); + + g_message("local->a->note = %s",local->a->note); + g_message("local->a->description = %s",local->a->description); + g_message("sizeof(p->record) = %d, length is %d",sizeof(p->record),p->length); + for(x=0;x<p->length;x+=32) { + for(y=x;y<x+32;y++) + if(p->record[y]<33 || p->record[y]>128) + printf("%02X",p->record[y]); + else + printf(" %c",p->record[y]); + printf("\n"); + } } #endif @@ -1083,43 +1086,42 @@ GnomePilotConduit * conduit_get_gpilot_conduit (guint32 pilotId) { GtkObject *retval; - ConduitCfg *cfg; - ConduitData *cdata; + GCalConduitCfg *cfg; + GCalConduitContext *ctxt; - CORBA_exception_init (&ev); retval = gnome_pilot_conduit_standard_abs_new ("DatebookDB", 0x64617465); g_assert (retval != NULL); - gnome_pilot_conduit_construct(GNOME_PILOT_CONDUIT(retval),"calendar"); - - cfg = g_new0(ConduitCfg,1); - g_assert(cfg != NULL); - gtk_object_set_data(retval,"conduit_cfg",cfg); - - cdata = g_new0(ConduitData,1); - g_assert(cdata != NULL); - gtk_object_set_data(retval,"conduit_data",cdata); - - gtk_signal_connect (retval, "match_record", (GtkSignalFunc) match_record, NULL); - gtk_signal_connect (retval, "free_match", (GtkSignalFunc) free_match, NULL); - gtk_signal_connect (retval, "archive_local", (GtkSignalFunc) archive_local, NULL); - gtk_signal_connect (retval, "archive_remote", (GtkSignalFunc) archive_remote, NULL); - gtk_signal_connect (retval, "store_remote", (GtkSignalFunc) store_remote, NULL); - gtk_signal_connect (retval, "clear_status_archive_local", (GtkSignalFunc) clear_status_archive_local, NULL); - gtk_signal_connect (retval, "iterate", (GtkSignalFunc) iterate, NULL); - gtk_signal_connect (retval, "iterate_specific", (GtkSignalFunc) iterate_specific, NULL); - gtk_signal_connect (retval, "purge", (GtkSignalFunc) purge, NULL); - gtk_signal_connect (retval, "set_status", (GtkSignalFunc) set_status, NULL); - gtk_signal_connect (retval, "set_archived", (GtkSignalFunc) set_archived, NULL); - gtk_signal_connect (retval, "set_pilot_id", (GtkSignalFunc) set_pilot_id, NULL); - gtk_signal_connect (retval, "compare", (GtkSignalFunc) compare, NULL); - gtk_signal_connect (retval, "compare_backup", (GtkSignalFunc) compare_backup, NULL); - gtk_signal_connect (retval, "free_transmit", (GtkSignalFunc) free_transmit, NULL); - gtk_signal_connect (retval, "delete_all", (GtkSignalFunc) delete_all, NULL); - gtk_signal_connect (retval, "transmit", (GtkSignalFunc) transmit, NULL); - gtk_signal_connect (retval, "pre_sync", (GtkSignalFunc) pre_sync, NULL); - - load_configuration(&cfg,pilotId); + gnome_pilot_conduit_construct(GNOME_PILOT_CONDUIT(retval),"GnomeCalConduit"); + + gcalconduit_load_configuration(&cfg,pilotId); + gtk_object_set_data(retval,"gcalconduit_cfg",cfg); + + gcalconduit_new_context(&ctxt,cfg); + /* No real need to set it, since all signal are given this + as their user data */ + gtk_object_set_data(retval,"gcalconduit_context",ctxt); + + gtk_signal_connect (retval, "match_record", (GtkSignalFunc) match_record, ctxt); + gtk_signal_connect (retval, "free_match", (GtkSignalFunc) free_match, ctxt); + gtk_signal_connect (retval, "archive_local", (GtkSignalFunc) archive_local, ctxt); + gtk_signal_connect (retval, "archive_remote", (GtkSignalFunc) archive_remote, ctxt); + gtk_signal_connect (retval, "store_remote", (GtkSignalFunc) store_remote, ctxt); + gtk_signal_connect (retval, "clear_status_archive_local", (GtkSignalFunc) clear_status_archive_local, ctxt); + gtk_signal_connect (retval, "iterate", (GtkSignalFunc) iterate, ctxt); + gtk_signal_connect (retval, "iterate_specific", (GtkSignalFunc) iterate_specific, ctxt); + gtk_signal_connect (retval, "purge", (GtkSignalFunc) purge, ctxt); + gtk_signal_connect (retval, "set_status", (GtkSignalFunc) set_status, ctxt); + gtk_signal_connect (retval, "set_archived", (GtkSignalFunc) set_archived, ctxt); + gtk_signal_connect (retval, "set_pilot_id", (GtkSignalFunc) set_pilot_id, ctxt); + gtk_signal_connect (retval, "compare", (GtkSignalFunc) compare, ctxt); + gtk_signal_connect (retval, "compare_backup", (GtkSignalFunc) compare_backup, ctxt); + gtk_signal_connect (retval, "free_transmit", (GtkSignalFunc) free_transmit, ctxt); + gtk_signal_connect (retval, "delete_all", (GtkSignalFunc) delete_all, ctxt); + gtk_signal_connect (retval, "transmit", (GtkSignalFunc) transmit, ctxt); + gtk_signal_connect (retval, "pre_sync", (GtkSignalFunc) pre_sync, ctxt); + + return GNOME_PILOT_CONDUIT (retval); } @@ -1127,17 +1129,18 @@ conduit_get_gpilot_conduit (guint32 pilotId) void conduit_destroy_gpilot_conduit (GnomePilotConduit *conduit) { - ConduitCfg *cc; - ConduitData *cd; + GCalConduitCfg *cc; + GCalConduitContext *ctxt; + + cc = GET_GCALCONFIG(conduit); + ctxt = GET_GCALCONTEXT(conduit); - if(calendar!=CORBA_OBJECT_NIL) - GNOME_Calendar_Repository_done (calendar, &ev); + if(ctxt->calendar!=CORBA_OBJECT_NIL) + GNOME_Calendar_Repository_done (ctxt->calendar, &(ctxt->ev)); - cc = GET_CONFIG(conduit); - destroy_configuration(&cc); + gcalconduit_destroy_configuration(&cc); - cd = GET_DATA(conduit); - g_free(cd); + gcalconduit_destroy_context(&ctxt); gtk_object_destroy (GTK_OBJECT (conduit)); diff --git a/calendar/gui/calendar-conduit.h b/calendar/gui/calendar-conduit.h index d8b320c1ce..cee7d3386e 100644 --- a/calendar/gui/calendar-conduit.h +++ b/calendar/gui/calendar-conduit.h @@ -17,55 +17,119 @@ #include <gpilotd/gnome-pilot-conduit.h> #include <gpilotd/gnome-pilot-conduit-standard-abs.h> -#define CALLOCALRECORD(s) ((CalLocalRecord*)(s)) -typedef struct _CalLocalRecord CalLocalRecord; - -struct _CalLocalRecord { - /* The stuff from gnome-pilot-conduit-standard-abs.h */ +/* This is the local record structure for the GnomeCal conduit. */ +typedef struct _GCalLocalRecord GCalLocalRecord; +struct _GCalLocalRecord { + /* The stuff from gnome-pilot-conduit-standard-abs.h + Must be first in the structure, or instances of this + structure cannot be used by gnome-pilot-conduit-standard-abs. + */ LocalRecord local; - /* The corresponding iCal object */ + /* The corresponding iCal object, as found by GnomeCal. */ iCalObject *ical; - /* pilot-link appointment structure, used for implementing Transmit */ + /* pilot-link appointment structure, used for implementing Transmit. */ struct Appointment *a; }; +#define GCAL_LOCALRECORD(s) ((GCalLocalRecord*)(s)) -typedef struct _ConduitCfg ConduitCfg; - -struct _ConduitCfg { - gboolean open_secret; - guint32 pilotId; +/* This is the configuration of the GnomeCal conduit. */ +typedef struct _GCalConduitCfg GCalConduitCfg; +struct _GCalConduitCfg { + gboolean open_secret; + guint32 pilotId; }; +#define GET_GCALCONFIG(c) ((GCalConduitCfg*)gtk_object_get_data(GTK_OBJECT(c),"gcalconduit_cfg")) + +/* This is the context for all the GnomeCal conduit methods. */ +typedef struct _GCalConduitContext GCalConduitContext; +struct _GCalConduitContext { + struct AppointmentAppInfo ai; + GCalConduitCfg *cfg; + GNOME_Calendar_Repository calendar; + CORBA_Environment ev; + CORBA_ORB orb; +}; +#define GET_GCALCONTEXT(c) ((GCalConduitContext*)gtk_object_get_data(GTK_OBJECT(c),"gcalconduit_context")) + +/* Given a GCalConduitCfg*, allocates the structure and + loads the configuration data for the given pilot. */ +static void +gcalconduit_load_configuration(GCalConduitCfg **c, + guint32 pilotId) +{ + gchar prefix[256]; + g_snprintf(prefix,255,"/gnome-pilot.d/calendard-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"); + gnome_config_pop_prefix(); + + (*c)->pilotId = pilotId; +} -#define GET_CONFIG(c) ((ConduitCfg*)gtk_object_get_data(GTK_OBJECT(c),"conduit_cfg")) +/* Saves the configuration data. */ +static void +gcalconduit_save_configuration(GCalConduitCfg *c) +{ + gchar prefix[256]; -static void load_configuration(ConduitCfg **c,guint32 pilotId) { - gchar prefix[256]; - g_snprintf(prefix,255,"/gnome-pilot.d/calendard-conduit/Pilot_%u/",pilotId); + g_snprintf(prefix,255,"/gnome-pilot.d/calendar-conduit/Pilot_%u/",c->pilotId); - *c = g_new0(ConduitCfg,1); - gnome_config_push_prefix(prefix); - (*c)->open_secret = gnome_config_get_bool("open secret=FALSE"); - gnome_config_pop_prefix(); + gnome_config_push_prefix(prefix); + gnome_config_set_bool("open_secret",c->open_secret); + gnome_config_pop_prefix(); - (*c)->pilotId = pilotId; + gnome_config_sync(); + gnome_config_drop_all(); } -static void save_configuration(ConduitCfg *c) { - gchar prefix[256]; - - g_snprintf(prefix,255,"/gnome-pilot.d/calendar-conduit/Pilot_%u/",c->pilotId); - - gnome_config_push_prefix(prefix); - gnome_config_set_bool("open secret",c->open_secret); - gnome_config_pop_prefix(); +/* 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->open_secret = c->open_secret; + retval->pilotId = c->pilotId; + return retval; +} - gnome_config_sync(); - gnome_config_drop_all(); +/* 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; } -static void destroy_configuration(ConduitCfg **c) { - g_free(*c); - *c = NULL; +/* Given a GCalConduitContxt*, allocates the structure */ +static void +gcalconduit_new_context(GCalConduitContext **ctxt, + GCalConduitCfg *c) +{ + *ctxt = g_new0(GCalConduitContext,1); + g_assert(ctxt!=NULL); + (*ctxt)->cfg = c; + CORBA_exception_init (&((*ctxt)->ev)); } +/* Destroys any data allocated by gcalconduit_new_context + and deallocates its data. */ +static void +gcalconduit_destroy_context(GCalConduitContext **ctxt) +{ + g_return_if_fail(ctxt!=NULL); + g_return_if_fail(*ctxt!=NULL); +/* + if ((*ctxt)->cfg!=NULL) + gcalconduit_destroy_configuration(&((*ctxt)->cfg)); +*/ + g_free(*ctxt); + *ctxt = NULL; +} #endif __CALENDAR_CONDUIT_H__ diff --git a/calendar/gui/todo-conduit-control-applet.c b/calendar/gui/todo-conduit-control-applet.c index 973a6192c8..54a26715ef 100644 --- a/calendar/gui/todo-conduit-control-applet.c +++ b/calendar/gui/todo-conduit-control-applet.c @@ -38,7 +38,7 @@ static void doSaveSettings(GtkWidget *widget, ConduitCfg *conduitCfg); static void readStateCfg(GtkWidget *w); static void setStateCfg(GtkWidget *w); -gchar *pilotId; +gint pilotId; CORBA_Environment ev; static void @@ -223,28 +223,29 @@ void run_error_dialog(gchar *mesg,...) { va_end(ap); } -gchar *get_pilot_id_from_gpilotd() { - gchar **pilots; - int i; +gint get_pilot_id_from_gpilotd() { + gint *pilots; + int i; - i=0; - gpilotd_get_pilots(&pilots); - if(pilots) { - while(pilots[i]) { g_message("pilot %d = \"%s\"",i,pilots[i]); i++; } - if(i==0) { - run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); - return NULL; - } else - if(i==1) - return pilots[0]; - else { - g_message("too many pilots..."); - return pilots[0]; - } - } else { - run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); - return NULL; - } + i=0; + gpilotd_get_pilot_ids(&pilots); + if(pilots) { + while(pilots[i]!=-1) { g_message("pilot %d = \"%d\"",i,pilots[i]); i++; } + if(i==0) { + run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); + return -1; + } else { + if(i==1) + return pilots[0]; + else { + g_message("too many pilots..."); + return pilots[0]; + } + } + } else { + run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); + return -1; + } } int @@ -282,6 +283,5 @@ main( int argc, char *argv[] ) /* done setting up, now run main loop */ capplet_gtk_main(); - g_free(pilotId); return 0; } diff --git a/calendar/todo-conduit-control-applet.c b/calendar/todo-conduit-control-applet.c index 973a6192c8..54a26715ef 100644 --- a/calendar/todo-conduit-control-applet.c +++ b/calendar/todo-conduit-control-applet.c @@ -38,7 +38,7 @@ static void doSaveSettings(GtkWidget *widget, ConduitCfg *conduitCfg); static void readStateCfg(GtkWidget *w); static void setStateCfg(GtkWidget *w); -gchar *pilotId; +gint pilotId; CORBA_Environment ev; static void @@ -223,28 +223,29 @@ void run_error_dialog(gchar *mesg,...) { va_end(ap); } -gchar *get_pilot_id_from_gpilotd() { - gchar **pilots; - int i; +gint get_pilot_id_from_gpilotd() { + gint *pilots; + int i; - i=0; - gpilotd_get_pilots(&pilots); - if(pilots) { - while(pilots[i]) { g_message("pilot %d = \"%s\"",i,pilots[i]); i++; } - if(i==0) { - run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); - return NULL; - } else - if(i==1) - return pilots[0]; - else { - g_message("too many pilots..."); - return pilots[0]; - } - } else { - run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); - return NULL; - } + i=0; + gpilotd_get_pilot_ids(&pilots); + if(pilots) { + while(pilots[i]!=-1) { g_message("pilot %d = \"%d\"",i,pilots[i]); i++; } + if(i==0) { + run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); + return -1; + } else { + if(i==1) + return pilots[0]; + else { + g_message("too many pilots..."); + return pilots[0]; + } + } + } else { + run_error_dialog(_("No pilot configured, please choose the\n'Pilot Link Properties' capplet first.")); + return -1; + } } int @@ -282,6 +283,5 @@ main( int argc, char *argv[] ) /* done setting up, now run main loop */ capplet_gtk_main(); - g_free(pilotId); return 0; } |