aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Heyn Olsen <eskil@src.gnome.org>1999-09-15 16:38:05 +0800
committerEskil Heyn Olsen <eskil@src.gnome.org>1999-09-15 16:38:05 +0800
commit7251a2d2bc2274529e1ddd1d5a3c04771cc86113 (patch)
tree4025e73707c00c36ec022b56c989810d7e523dd2
parent0a765ba73162b2d162de1d1fc697c9586491ef00 (diff)
downloadgsoc2013-evolution-7251a2d2bc2274529e1ddd1d5a3c04771cc86113.tar
gsoc2013-evolution-7251a2d2bc2274529e1ddd1d5a3c04771cc86113.tar.gz
gsoc2013-evolution-7251a2d2bc2274529e1ddd1d5a3c04771cc86113.tar.bz2
gsoc2013-evolution-7251a2d2bc2274529e1ddd1d5a3c04771cc86113.tar.lz
gsoc2013-evolution-7251a2d2bc2274529e1ddd1d5a3c04771cc86113.tar.xz
gsoc2013-evolution-7251a2d2bc2274529e1ddd1d5a3c04771cc86113.tar.zst
gsoc2013-evolution-7251a2d2bc2274529e1ddd1d5a3c04771cc86113.zip
added sources to calendar-conduit
* gncal/Makefile.am: added sources to calendar-conduit * gncal/calendar-conduit.c: imported Miguels update_record function * gncal/corba-cal.c: fixed a grave bug in exception throwing, which cause ORBit to sigsegv. svn path=/trunk/; revision=1229
-rw-r--r--calendar/Makefile.am11
-rw-r--r--calendar/cal-util/calobj.h4
-rw-r--r--calendar/calendar-conduit.c267
-rw-r--r--calendar/calobj.h4
-rw-r--r--calendar/conduits/calendar/calendar-conduit.c267
-rw-r--r--calendar/corba-cal.c6
-rw-r--r--calendar/gui/Makefile.am11
-rw-r--r--calendar/gui/calendar-conduit.c267
-rw-r--r--calendar/gui/corba-cal.c6
-rw-r--r--calendar/pcs/calobj.h4
10 files changed, 746 insertions, 101 deletions
diff --git a/calendar/Makefile.am b/calendar/Makefile.am
index c7794b7e85..b4d349f936 100644
--- a/calendar/Makefile.am
+++ b/calendar/Makefile.am
@@ -120,7 +120,16 @@ calendar_conduitsdir=$(libdir)/gnome-pilot/conduits
calendar_conduits_LTLIBRARIES = libcalendar_conduit.la
libcalendar_conduit_la_SOURCES = \
- calendar-conduit.c
+ calendar-conduit.c \
+ calobj.c \
+ alarm.c \
+ GnomeCal-common.c \
+ GnomeCal-stubs.c \
+ calendar.c \
+ vcc.c \
+ vcaltmp.c \
+ vobject.c \
+ timeutil.c
libcalendar_conduit_la_LDFLAGS = \
-rpath $(libdir)
diff --git a/calendar/cal-util/calobj.h b/calendar/cal-util/calobj.h
index 07ba3f1cc7..8be38e5d26 100644
--- a/calendar/cal-util/calobj.h
+++ b/calendar/cal-util/calobj.h
@@ -180,8 +180,8 @@ typedef struct {
void *user_data; /* Generic data pointer */
/* Pilot */
- int pilot_status; /* Status information */
- int pilot_id; /* Pilot ID */
+ iCalPilotState pilot_status; /* Status information */
+ int pilot_id; /* Pilot ID */
} iCalObject;
/* The callback for the recurrence generator */
diff --git a/calendar/calendar-conduit.c b/calendar/calendar-conduit.c
index f7d1ebdd71..8f5835e4ef 100644
--- a/calendar/calendar-conduit.c
+++ b/calendar/calendar-conduit.c
@@ -26,9 +26,13 @@
#include "GnomeCal.h"
#include "calobj.h"
#include "calendar.h"
+#include "timeutil.h"
#include "calendar-conduit.h"
+GnomePilotConduit * conduit_get_gpilot_conduit (guint32);
+void conduit_destroy_gpilot_conduit (GnomePilotConduit*);
+
typedef struct _ConduitData ConduitData;
struct _ConduitData {
@@ -40,26 +44,231 @@ struct _ConduitData {
GNOME_Calendar_Repository calendar;
CORBA_Environment ev;
+CORBA_ORB orb;
static GNOME_Calendar_Repository
calendar_server (void)
{
- if(calendar!=CORBA_OBJECT_NIL) return calendar;
-
+ int n =0;
+
calendar = goad_server_activate_with_id (NULL, "IDL:GNOME:Calendar:Repository:1.0",
0, NULL);
-
if (calendar == CORBA_OBJECT_NIL)
g_error ("Can not communicate with GnomeCalendar server");
if (ev._major != CORBA_NO_EXCEPTION){
printf ("Exception: %s\n", CORBA_exception_id (&ev));
- abort ();
+ return CORBA_OBJECT_NIL;
}
return calendar;
}
+
+/* Just a stub to link with */
+void
+calendar_notify (time_t time, CalendarAlarm *which, void *data)
+{
+}
+
+/* Code blatantly stolen from
+ * calendar-pilot-sync.c:
+ *
+ * (C) 1999 International GNOME Support
+ *
+ * Author:
+ * Miguel de Icaza (miguel@gnome-support.com)
+ *
+ */
+static void
+update_record (PilotRecord *remote)
+{
+ char *vcal_string;
+ iCalObject *obj;
+ int i;
+ char *str;
+ struct Appointment a;
+
+ g_return_if_fail(remote!=NULL);
+
+ unpack_Appointment(&a,remote->record,remote->length);
+
+ obj = ical_new (a.note ? a.note : "",
+ g_get_user_name (),
+ a.description ? a.description : "");
+
+ printf ("requesting %d [%s]\n", remote->ID, a.description);
+ vcal_string = GNOME_Calendar_Repository_get_object_by_pilot_id (calendar, remote->ID, &ev);
+
+ if (ev._major == CORBA_USER_EXCEPTION){
+ time_t now = time (NULL);
+
+ obj->created = now;
+ obj->last_mod = now;
+ obj->priority = 0;
+ obj->transp = 0;
+ obj->related = NULL;
+ obj->pilot_id = remote->ID;
+ obj->pilot_status = ICAL_PILOT_SYNC_NONE;
+ printf (_("\tObject did not exist, creating a new one\n"));
+ } else if(ev._major != CORBA_NO_EXCEPTION) {
+ printf(_("\tError while communicating with calendar server\n"));
+ printf("\texception id = %s\n",CORBA_exception_id(&ev));
+ CORBA_exception_free(&ev);
+ ical_object_destroy (obj);
+ return;
+ } else {
+ printf ("\tFound\n");
+ ical_object_destroy (obj);
+ obj = ical_object_new_from_string (vcal_string);
+ }
+
+ if (obj->pilot_status == ICAL_PILOT_SYNC_MOD){
+ printf (_("\tObject has been modified on desktop and on the pilot, desktop takes precedence\n"));
+ ical_object_destroy (obj);
+ return;
+ }
+
+ /*
+ * Begin and end
+ */
+
+ if (a.event)
+ {
+ /* turn day-long events into a full day's appointment */
+ a.begin.tm_sec = 0;
+ a.begin.tm_min = 0;
+ a.begin.tm_hour = 6;
+
+ a.end.tm_sec = 0;
+ a.end.tm_min = 0;
+ a.end.tm_hour = 10;
+ }
+
+ obj->dtstart = mktime (&a.begin);
+ obj->dtend = mktime (&a.end);
+
+ /* Special case: daily repetitions are converted to a multi-day event */
+ if (a.repeatType == repeatDaily){
+ time_t newt = time_add_day (obj->dtend, a.repeatFrequency);
+
+ obj->dtend = newt;
+ }
+
+ /*
+ * Alarm
+ */
+ if (a.alarm){
+ obj->aalarm.type = ALARM_AUDIO;
+ obj->aalarm.enabled = 1;
+ obj->aalarm.count = a.advance;
+
+ switch (a.advanceUnits){
+ case advMinutes:
+ obj->aalarm.units = ALARM_MINUTES;
+ break;
+
+ case advHours:
+ obj->aalarm.units = ALARM_HOURS;
+ break;
+
+ case advDays:
+ obj->aalarm.units = ALARM_DAYS;
+ break;
+ default:
+ }
+ }
+
+ /*
+ * Recurrence
+ */
+ if (a.repeatFrequency && a.repeatType != repeatDaily){
+ obj->recur = g_new0 (Recurrence, 1);
+
+ switch (a.repeatType){
+ case repeatDaily:
+ /*
+ * In the Pilot daily repetitions are actually
+ * multi-day events
+ */
+ g_warning ("Should not have got here");
+ break;
+
+ case repeatMonthlyByDate:
+ obj->recur->type = RECUR_MONTHLY_BY_DAY;
+ obj->recur->u.month_day = a.repeatFrequency;
+ break;
+
+ case repeatWeekly:
+ {
+ int wd;
+
+ obj->recur->type = RECUR_WEEKLY;
+ for (wd = 0; wd < 7; wd++)
+ if (a.repeatDays [wd])
+ obj->recur->weekday |= 1 << wd;
+
+ if (obj->recur->weekday == 0){
+ struct tm *tm = localtime (&obj->dtstart);
+
+ obj->recur->weekday = 1 << tm->tm_wday;
+ }
+ break;
+ }
+
+ case repeatMonthlyByDay:
+ obj->recur->type = RECUR_MONTHLY_BY_POS;
+ obj->recur->u.month_pos = a.repeatFrequency;
+ obj->recur->weekday = (a.repeatDay / 7);
+ break;
+
+ case repeatYearly:
+ obj->recur->type = RECUR_YEARLY_BY_DAY;
+ break;
+
+ default:
+ g_warning ("Unhandled repeate case");
+ }
+
+ if (a.repeatForever)
+ obj->recur->duration = 0;
+ else
+ obj->recur->_enddate = mktime (&a.repeatEnd);
+ }
+
+ /*
+ * Load exception dates
+ */
+ obj->exdate = NULL;
+ for (i = 0; i < a.exceptions; i++){
+ time_t *t = g_new (time_t, 1);
+
+ *t = mktime (&(a.exception [i]));
+ obj->exdate = g_list_prepend (obj->exdate, t);
+ }
+
+ g_free (obj->class);
+
+ if (remote->attr & dlpRecAttrSecret)
+ obj->class = g_strdup ("PRIVATE");
+ else
+ obj->class = g_strdup ("PUBLIC");
+
+ /*
+ * Now, convert the in memory iCalObject to a full vCalendar we can send
+ */
+ str = calendar_string_from_object (obj);
+
+ GNOME_Calendar_Repository_update_object (calendar, obj->uid, str, &ev);
+
+ free (str);
+
+ /*
+ * Shutdown
+ */
+ ical_object_destroy (obj);
+}
+
static gint
load_records(GnomePilotConduit *c)
{
@@ -68,9 +277,10 @@ load_records(GnomePilotConduit *c)
ConduitData *cd;
vcalendar_string =
- GNOME_Calendar_Repository_get_updated_objects (calendar_server(), &ev);
+ GNOME_Calendar_Repository_get_updated_objects (calendar, &ev);
cd = GET_DATA(c);
+ g_assert(cd!=NULL);
cd->cal = calendar_new("Temporary");
error = calendar_load_from_memory(cd->cal,vcalendar_string);
@@ -83,25 +293,25 @@ pre_sync(GnomePilotConduit *c, GnomePilotDBInfo *dbi)
{
int l;
unsigned char *buf;
-
+
+ calendar = CORBA_OBJECT_NIL;
+ calendar = calendar_server();
+ if(calendar == CORBA_OBJECT_NIL) {
+ return 0;
+ }
+
gtk_object_set_data(GTK_OBJECT(c),"dbinfo",dbi);
load_records(c);
buf = (unsigned char*)g_malloc(0xffff);
if((l=dlp_ReadAppBlock(dbi->pilot_socket,dbi->db_handle,0,(unsigned char *)buf,0xffff))<0) {
- return -1;
+ return 0;
}
unpack_AppointmentAppInfo(&(GET_DATA(c)->ai),buf,l);
g_free(buf);
- return 0;
-}
-
-static gint
-post_sync(GnomePilotConduit *c)
-{
- return 0;
+ return 1;
}
static gint
@@ -110,8 +320,10 @@ match_record (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
PilotRecord *remote,
gpointer data)
{
+ g_return_val_if_fail(remote!=NULL,0);
g_print ("in match_record\n");
- return 0;
+ *local = NULL;
+ return 1;
}
static gint
free_match (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
@@ -120,7 +332,6 @@ free_match (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
{
g_print ("entering free_match\n");
*local = NULL;
-
return 0;
}
static gint
@@ -146,9 +357,12 @@ store_remote (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
PilotRecord *remote,
gpointer data)
{
- g_print ("entering store_remote\n");
- g_print ("Rec:%s:\nLength:%d\n", remote->record, remote->length);
- return 1;
+ g_print ("entering store_remote\n");
+ g_return_val_if_fail(remote!=NULL,0);
+
+ update_record(remote);
+
+ return 1;
}
static gint
clear_status_archive_local (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
@@ -190,7 +404,7 @@ set_status (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
gpointer data)
{
g_print ("entering set_status\n");
- return 1;
+ return 0;
}
static gint
set_archived (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
@@ -253,7 +467,7 @@ transmit (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
return NULL;
}
-static GnomePilotConduit *
+GnomePilotConduit *
conduit_get_gpilot_conduit (guint32 pilotId)
{
GtkObject *retval;
@@ -262,7 +476,6 @@ conduit_get_gpilot_conduit (guint32 pilotId)
CORBA_exception_init (&ev);
- g_print ("creating our new conduit\n");
retval = gnome_pilot_conduit_standard_abs_new ("DatebookDB", 0x64617465);
g_assert (retval != NULL);
gnome_pilot_conduit_construct(GNOME_PILOT_CONDUIT(retval),"calendar");
@@ -273,11 +486,8 @@ conduit_get_gpilot_conduit (guint32 pilotId)
cdata = g_new0(ConduitData,1);
g_assert(cdata != NULL);
- cdata = NULL;
gtk_object_set_data(retval,"conduit_data",cdata);
- calendar = CORBA_OBJECT_NIL;
-
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);
@@ -296,19 +506,20 @@ conduit_get_gpilot_conduit (guint32 pilotId)
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);
- gtk_signal_connect (retval, "post_sync", (GtkSignalFunc) post_sync, NULL);
load_configuration(&cfg,pilotId);
return GNOME_PILOT_CONDUIT (retval);
}
-static void
+void
conduit_destroy_gpilot_conduit (GnomePilotConduit *conduit)
{
ConduitCfg *cc;
ConduitData *cd;
+ GNOME_Calendar_Repository_done (calendar, &ev);
+
cc = GET_CONFIG(conduit);
destroy_configuration(&cc);
@@ -317,8 +528,6 @@ conduit_destroy_gpilot_conduit (GnomePilotConduit *conduit)
gtk_object_destroy (GTK_OBJECT (conduit));
- GNOME_Calendar_Repository_done (calendar_server(), &ev);
-
}
diff --git a/calendar/calobj.h b/calendar/calobj.h
index 07ba3f1cc7..8be38e5d26 100644
--- a/calendar/calobj.h
+++ b/calendar/calobj.h
@@ -180,8 +180,8 @@ typedef struct {
void *user_data; /* Generic data pointer */
/* Pilot */
- int pilot_status; /* Status information */
- int pilot_id; /* Pilot ID */
+ iCalPilotState pilot_status; /* Status information */
+ int pilot_id; /* Pilot ID */
} iCalObject;
/* The callback for the recurrence generator */
diff --git a/calendar/conduits/calendar/calendar-conduit.c b/calendar/conduits/calendar/calendar-conduit.c
index f7d1ebdd71..8f5835e4ef 100644
--- a/calendar/conduits/calendar/calendar-conduit.c
+++ b/calendar/conduits/calendar/calendar-conduit.c
@@ -26,9 +26,13 @@
#include "GnomeCal.h"
#include "calobj.h"
#include "calendar.h"
+#include "timeutil.h"
#include "calendar-conduit.h"
+GnomePilotConduit * conduit_get_gpilot_conduit (guint32);
+void conduit_destroy_gpilot_conduit (GnomePilotConduit*);
+
typedef struct _ConduitData ConduitData;
struct _ConduitData {
@@ -40,26 +44,231 @@ struct _ConduitData {
GNOME_Calendar_Repository calendar;
CORBA_Environment ev;
+CORBA_ORB orb;
static GNOME_Calendar_Repository
calendar_server (void)
{
- if(calendar!=CORBA_OBJECT_NIL) return calendar;
-
+ int n =0;
+
calendar = goad_server_activate_with_id (NULL, "IDL:GNOME:Calendar:Repository:1.0",
0, NULL);
-
if (calendar == CORBA_OBJECT_NIL)
g_error ("Can not communicate with GnomeCalendar server");
if (ev._major != CORBA_NO_EXCEPTION){
printf ("Exception: %s\n", CORBA_exception_id (&ev));
- abort ();
+ return CORBA_OBJECT_NIL;
}
return calendar;
}
+
+/* Just a stub to link with */
+void
+calendar_notify (time_t time, CalendarAlarm *which, void *data)
+{
+}
+
+/* Code blatantly stolen from
+ * calendar-pilot-sync.c:
+ *
+ * (C) 1999 International GNOME Support
+ *
+ * Author:
+ * Miguel de Icaza (miguel@gnome-support.com)
+ *
+ */
+static void
+update_record (PilotRecord *remote)
+{
+ char *vcal_string;
+ iCalObject *obj;
+ int i;
+ char *str;
+ struct Appointment a;
+
+ g_return_if_fail(remote!=NULL);
+
+ unpack_Appointment(&a,remote->record,remote->length);
+
+ obj = ical_new (a.note ? a.note : "",
+ g_get_user_name (),
+ a.description ? a.description : "");
+
+ printf ("requesting %d [%s]\n", remote->ID, a.description);
+ vcal_string = GNOME_Calendar_Repository_get_object_by_pilot_id (calendar, remote->ID, &ev);
+
+ if (ev._major == CORBA_USER_EXCEPTION){
+ time_t now = time (NULL);
+
+ obj->created = now;
+ obj->last_mod = now;
+ obj->priority = 0;
+ obj->transp = 0;
+ obj->related = NULL;
+ obj->pilot_id = remote->ID;
+ obj->pilot_status = ICAL_PILOT_SYNC_NONE;
+ printf (_("\tObject did not exist, creating a new one\n"));
+ } else if(ev._major != CORBA_NO_EXCEPTION) {
+ printf(_("\tError while communicating with calendar server\n"));
+ printf("\texception id = %s\n",CORBA_exception_id(&ev));
+ CORBA_exception_free(&ev);
+ ical_object_destroy (obj);
+ return;
+ } else {
+ printf ("\tFound\n");
+ ical_object_destroy (obj);
+ obj = ical_object_new_from_string (vcal_string);
+ }
+
+ if (obj->pilot_status == ICAL_PILOT_SYNC_MOD){
+ printf (_("\tObject has been modified on desktop and on the pilot, desktop takes precedence\n"));
+ ical_object_destroy (obj);
+ return;
+ }
+
+ /*
+ * Begin and end
+ */
+
+ if (a.event)
+ {
+ /* turn day-long events into a full day's appointment */
+ a.begin.tm_sec = 0;
+ a.begin.tm_min = 0;
+ a.begin.tm_hour = 6;
+
+ a.end.tm_sec = 0;
+ a.end.tm_min = 0;
+ a.end.tm_hour = 10;
+ }
+
+ obj->dtstart = mktime (&a.begin);
+ obj->dtend = mktime (&a.end);
+
+ /* Special case: daily repetitions are converted to a multi-day event */
+ if (a.repeatType == repeatDaily){
+ time_t newt = time_add_day (obj->dtend, a.repeatFrequency);
+
+ obj->dtend = newt;
+ }
+
+ /*
+ * Alarm
+ */
+ if (a.alarm){
+ obj->aalarm.type = ALARM_AUDIO;
+ obj->aalarm.enabled = 1;
+ obj->aalarm.count = a.advance;
+
+ switch (a.advanceUnits){
+ case advMinutes:
+ obj->aalarm.units = ALARM_MINUTES;
+ break;
+
+ case advHours:
+ obj->aalarm.units = ALARM_HOURS;
+ break;
+
+ case advDays:
+ obj->aalarm.units = ALARM_DAYS;
+ break;
+ default:
+ }
+ }
+
+ /*
+ * Recurrence
+ */
+ if (a.repeatFrequency && a.repeatType != repeatDaily){
+ obj->recur = g_new0 (Recurrence, 1);
+
+ switch (a.repeatType){
+ case repeatDaily:
+ /*
+ * In the Pilot daily repetitions are actually
+ * multi-day events
+ */
+ g_warning ("Should not have got here");
+ break;
+
+ case repeatMonthlyByDate:
+ obj->recur->type = RECUR_MONTHLY_BY_DAY;
+ obj->recur->u.month_day = a.repeatFrequency;
+ break;
+
+ case repeatWeekly:
+ {
+ int wd;
+
+ obj->recur->type = RECUR_WEEKLY;
+ for (wd = 0; wd < 7; wd++)
+ if (a.repeatDays [wd])
+ obj->recur->weekday |= 1 << wd;
+
+ if (obj->recur->weekday == 0){
+ struct tm *tm = localtime (&obj->dtstart);
+
+ obj->recur->weekday = 1 << tm->tm_wday;
+ }
+ break;
+ }
+
+ case repeatMonthlyByDay:
+ obj->recur->type = RECUR_MONTHLY_BY_POS;
+ obj->recur->u.month_pos = a.repeatFrequency;
+ obj->recur->weekday = (a.repeatDay / 7);
+ break;
+
+ case repeatYearly:
+ obj->recur->type = RECUR_YEARLY_BY_DAY;
+ break;
+
+ default:
+ g_warning ("Unhandled repeate case");
+ }
+
+ if (a.repeatForever)
+ obj->recur->duration = 0;
+ else
+ obj->recur->_enddate = mktime (&a.repeatEnd);
+ }
+
+ /*
+ * Load exception dates
+ */
+ obj->exdate = NULL;
+ for (i = 0; i < a.exceptions; i++){
+ time_t *t = g_new (time_t, 1);
+
+ *t = mktime (&(a.exception [i]));
+ obj->exdate = g_list_prepend (obj->exdate, t);
+ }
+
+ g_free (obj->class);
+
+ if (remote->attr & dlpRecAttrSecret)
+ obj->class = g_strdup ("PRIVATE");
+ else
+ obj->class = g_strdup ("PUBLIC");
+
+ /*
+ * Now, convert the in memory iCalObject to a full vCalendar we can send
+ */
+ str = calendar_string_from_object (obj);
+
+ GNOME_Calendar_Repository_update_object (calendar, obj->uid, str, &ev);
+
+ free (str);
+
+ /*
+ * Shutdown
+ */
+ ical_object_destroy (obj);
+}
+
static gint
load_records(GnomePilotConduit *c)
{
@@ -68,9 +277,10 @@ load_records(GnomePilotConduit *c)
ConduitData *cd;
vcalendar_string =
- GNOME_Calendar_Repository_get_updated_objects (calendar_server(), &ev);
+ GNOME_Calendar_Repository_get_updated_objects (calendar, &ev);
cd = GET_DATA(c);
+ g_assert(cd!=NULL);
cd->cal = calendar_new("Temporary");
error = calendar_load_from_memory(cd->cal,vcalendar_string);
@@ -83,25 +293,25 @@ pre_sync(GnomePilotConduit *c, GnomePilotDBInfo *dbi)
{
int l;
unsigned char *buf;
-
+
+ calendar = CORBA_OBJECT_NIL;
+ calendar = calendar_server();
+ if(calendar == CORBA_OBJECT_NIL) {
+ return 0;
+ }
+
gtk_object_set_data(GTK_OBJECT(c),"dbinfo",dbi);
load_records(c);
buf = (unsigned char*)g_malloc(0xffff);
if((l=dlp_ReadAppBlock(dbi->pilot_socket,dbi->db_handle,0,(unsigned char *)buf,0xffff))<0) {
- return -1;
+ return 0;
}
unpack_AppointmentAppInfo(&(GET_DATA(c)->ai),buf,l);
g_free(buf);
- return 0;
-}
-
-static gint
-post_sync(GnomePilotConduit *c)
-{
- return 0;
+ return 1;
}
static gint
@@ -110,8 +320,10 @@ match_record (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
PilotRecord *remote,
gpointer data)
{
+ g_return_val_if_fail(remote!=NULL,0);
g_print ("in match_record\n");
- return 0;
+ *local = NULL;
+ return 1;
}
static gint
free_match (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
@@ -120,7 +332,6 @@ free_match (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
{
g_print ("entering free_match\n");
*local = NULL;
-
return 0;
}
static gint
@@ -146,9 +357,12 @@ store_remote (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
PilotRecord *remote,
gpointer data)
{
- g_print ("entering store_remote\n");
- g_print ("Rec:%s:\nLength:%d\n", remote->record, remote->length);
- return 1;
+ g_print ("entering store_remote\n");
+ g_return_val_if_fail(remote!=NULL,0);
+
+ update_record(remote);
+
+ return 1;
}
static gint
clear_status_archive_local (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
@@ -190,7 +404,7 @@ set_status (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
gpointer data)
{
g_print ("entering set_status\n");
- return 1;
+ return 0;
}
static gint
set_archived (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
@@ -253,7 +467,7 @@ transmit (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
return NULL;
}
-static GnomePilotConduit *
+GnomePilotConduit *
conduit_get_gpilot_conduit (guint32 pilotId)
{
GtkObject *retval;
@@ -262,7 +476,6 @@ conduit_get_gpilot_conduit (guint32 pilotId)
CORBA_exception_init (&ev);
- g_print ("creating our new conduit\n");
retval = gnome_pilot_conduit_standard_abs_new ("DatebookDB", 0x64617465);
g_assert (retval != NULL);
gnome_pilot_conduit_construct(GNOME_PILOT_CONDUIT(retval),"calendar");
@@ -273,11 +486,8 @@ conduit_get_gpilot_conduit (guint32 pilotId)
cdata = g_new0(ConduitData,1);
g_assert(cdata != NULL);
- cdata = NULL;
gtk_object_set_data(retval,"conduit_data",cdata);
- calendar = CORBA_OBJECT_NIL;
-
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);
@@ -296,19 +506,20 @@ conduit_get_gpilot_conduit (guint32 pilotId)
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);
- gtk_signal_connect (retval, "post_sync", (GtkSignalFunc) post_sync, NULL);
load_configuration(&cfg,pilotId);
return GNOME_PILOT_CONDUIT (retval);
}
-static void
+void
conduit_destroy_gpilot_conduit (GnomePilotConduit *conduit)
{
ConduitCfg *cc;
ConduitData *cd;
+ GNOME_Calendar_Repository_done (calendar, &ev);
+
cc = GET_CONFIG(conduit);
destroy_configuration(&cc);
@@ -317,8 +528,6 @@ conduit_destroy_gpilot_conduit (GnomePilotConduit *conduit)
gtk_object_destroy (GTK_OBJECT (conduit));
- GNOME_Calendar_Repository_done (calendar_server(), &ev);
-
}
diff --git a/calendar/corba-cal.c b/calendar/corba-cal.c
index 3e95571f6c..6b4566dc06 100644
--- a/calendar/corba-cal.c
+++ b/calendar/corba-cal.c
@@ -79,12 +79,12 @@ cal_repo_get_object_by_pilot_id (PortableServer_Servant servant,
iCalObject *obj;
char *buffer;
CORBA_char *ret;
-
+
obj = calendar_object_find_by_pilot (gcal->cal, pilot_id);
if (obj == NULL){
CORBA_exception_set (ev,
CORBA_USER_EXCEPTION,
- ex_GNOME_Calendar_Repository_NotFound, "");
+ ex_GNOME_Calendar_Repository_NotFound, NULL);
return NULL;
}
@@ -108,7 +108,7 @@ cal_repo_get_id_from_pilot_id (PortableServer_Servant servant,
if (obj == NULL){
CORBA_exception_set (ev,
CORBA_USER_EXCEPTION,
- ex_GNOME_Calendar_Repository_NotFound, "");
+ ex_GNOME_Calendar_Repository_NotFound, NULL);
return NULL;
}
diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am
index c7794b7e85..b4d349f936 100644
--- a/calendar/gui/Makefile.am
+++ b/calendar/gui/Makefile.am
@@ -120,7 +120,16 @@ calendar_conduitsdir=$(libdir)/gnome-pilot/conduits
calendar_conduits_LTLIBRARIES = libcalendar_conduit.la
libcalendar_conduit_la_SOURCES = \
- calendar-conduit.c
+ calendar-conduit.c \
+ calobj.c \
+ alarm.c \
+ GnomeCal-common.c \
+ GnomeCal-stubs.c \
+ calendar.c \
+ vcc.c \
+ vcaltmp.c \
+ vobject.c \
+ timeutil.c
libcalendar_conduit_la_LDFLAGS = \
-rpath $(libdir)
diff --git a/calendar/gui/calendar-conduit.c b/calendar/gui/calendar-conduit.c
index f7d1ebdd71..8f5835e4ef 100644
--- a/calendar/gui/calendar-conduit.c
+++ b/calendar/gui/calendar-conduit.c
@@ -26,9 +26,13 @@
#include "GnomeCal.h"
#include "calobj.h"
#include "calendar.h"
+#include "timeutil.h"
#include "calendar-conduit.h"
+GnomePilotConduit * conduit_get_gpilot_conduit (guint32);
+void conduit_destroy_gpilot_conduit (GnomePilotConduit*);
+
typedef struct _ConduitData ConduitData;
struct _ConduitData {
@@ -40,26 +44,231 @@ struct _ConduitData {
GNOME_Calendar_Repository calendar;
CORBA_Environment ev;
+CORBA_ORB orb;
static GNOME_Calendar_Repository
calendar_server (void)
{
- if(calendar!=CORBA_OBJECT_NIL) return calendar;
-
+ int n =0;
+
calendar = goad_server_activate_with_id (NULL, "IDL:GNOME:Calendar:Repository:1.0",
0, NULL);
-
if (calendar == CORBA_OBJECT_NIL)
g_error ("Can not communicate with GnomeCalendar server");
if (ev._major != CORBA_NO_EXCEPTION){
printf ("Exception: %s\n", CORBA_exception_id (&ev));
- abort ();
+ return CORBA_OBJECT_NIL;
}
return calendar;
}
+
+/* Just a stub to link with */
+void
+calendar_notify (time_t time, CalendarAlarm *which, void *data)
+{
+}
+
+/* Code blatantly stolen from
+ * calendar-pilot-sync.c:
+ *
+ * (C) 1999 International GNOME Support
+ *
+ * Author:
+ * Miguel de Icaza (miguel@gnome-support.com)
+ *
+ */
+static void
+update_record (PilotRecord *remote)
+{
+ char *vcal_string;
+ iCalObject *obj;
+ int i;
+ char *str;
+ struct Appointment a;
+
+ g_return_if_fail(remote!=NULL);
+
+ unpack_Appointment(&a,remote->record,remote->length);
+
+ obj = ical_new (a.note ? a.note : "",
+ g_get_user_name (),
+ a.description ? a.description : "");
+
+ printf ("requesting %d [%s]\n", remote->ID, a.description);
+ vcal_string = GNOME_Calendar_Repository_get_object_by_pilot_id (calendar, remote->ID, &ev);
+
+ if (ev._major == CORBA_USER_EXCEPTION){
+ time_t now = time (NULL);
+
+ obj->created = now;
+ obj->last_mod = now;
+ obj->priority = 0;
+ obj->transp = 0;
+ obj->related = NULL;
+ obj->pilot_id = remote->ID;
+ obj->pilot_status = ICAL_PILOT_SYNC_NONE;
+ printf (_("\tObject did not exist, creating a new one\n"));
+ } else if(ev._major != CORBA_NO_EXCEPTION) {
+ printf(_("\tError while communicating with calendar server\n"));
+ printf("\texception id = %s\n",CORBA_exception_id(&ev));
+ CORBA_exception_free(&ev);
+ ical_object_destroy (obj);
+ return;
+ } else {
+ printf ("\tFound\n");
+ ical_object_destroy (obj);
+ obj = ical_object_new_from_string (vcal_string);
+ }
+
+ if (obj->pilot_status == ICAL_PILOT_SYNC_MOD){
+ printf (_("\tObject has been modified on desktop and on the pilot, desktop takes precedence\n"));
+ ical_object_destroy (obj);
+ return;
+ }
+
+ /*
+ * Begin and end
+ */
+
+ if (a.event)
+ {
+ /* turn day-long events into a full day's appointment */
+ a.begin.tm_sec = 0;
+ a.begin.tm_min = 0;
+ a.begin.tm_hour = 6;
+
+ a.end.tm_sec = 0;
+ a.end.tm_min = 0;
+ a.end.tm_hour = 10;
+ }
+
+ obj->dtstart = mktime (&a.begin);
+ obj->dtend = mktime (&a.end);
+
+ /* Special case: daily repetitions are converted to a multi-day event */
+ if (a.repeatType == repeatDaily){
+ time_t newt = time_add_day (obj->dtend, a.repeatFrequency);
+
+ obj->dtend = newt;
+ }
+
+ /*
+ * Alarm
+ */
+ if (a.alarm){
+ obj->aalarm.type = ALARM_AUDIO;
+ obj->aalarm.enabled = 1;
+ obj->aalarm.count = a.advance;
+
+ switch (a.advanceUnits){
+ case advMinutes:
+ obj->aalarm.units = ALARM_MINUTES;
+ break;
+
+ case advHours:
+ obj->aalarm.units = ALARM_HOURS;
+ break;
+
+ case advDays:
+ obj->aalarm.units = ALARM_DAYS;
+ break;
+ default:
+ }
+ }
+
+ /*
+ * Recurrence
+ */
+ if (a.repeatFrequency && a.repeatType != repeatDaily){
+ obj->recur = g_new0 (Recurrence, 1);
+
+ switch (a.repeatType){
+ case repeatDaily:
+ /*
+ * In the Pilot daily repetitions are actually
+ * multi-day events
+ */
+ g_warning ("Should not have got here");
+ break;
+
+ case repeatMonthlyByDate:
+ obj->recur->type = RECUR_MONTHLY_BY_DAY;
+ obj->recur->u.month_day = a.repeatFrequency;
+ break;
+
+ case repeatWeekly:
+ {
+ int wd;
+
+ obj->recur->type = RECUR_WEEKLY;
+ for (wd = 0; wd < 7; wd++)
+ if (a.repeatDays [wd])
+ obj->recur->weekday |= 1 << wd;
+
+ if (obj->recur->weekday == 0){
+ struct tm *tm = localtime (&obj->dtstart);
+
+ obj->recur->weekday = 1 << tm->tm_wday;
+ }
+ break;
+ }
+
+ case repeatMonthlyByDay:
+ obj->recur->type = RECUR_MONTHLY_BY_POS;
+ obj->recur->u.month_pos = a.repeatFrequency;
+ obj->recur->weekday = (a.repeatDay / 7);
+ break;
+
+ case repeatYearly:
+ obj->recur->type = RECUR_YEARLY_BY_DAY;
+ break;
+
+ default:
+ g_warning ("Unhandled repeate case");
+ }
+
+ if (a.repeatForever)
+ obj->recur->duration = 0;
+ else
+ obj->recur->_enddate = mktime (&a.repeatEnd);
+ }
+
+ /*
+ * Load exception dates
+ */
+ obj->exdate = NULL;
+ for (i = 0; i < a.exceptions; i++){
+ time_t *t = g_new (time_t, 1);
+
+ *t = mktime (&(a.exception [i]));
+ obj->exdate = g_list_prepend (obj->exdate, t);
+ }
+
+ g_free (obj->class);
+
+ if (remote->attr & dlpRecAttrSecret)
+ obj->class = g_strdup ("PRIVATE");
+ else
+ obj->class = g_strdup ("PUBLIC");
+
+ /*
+ * Now, convert the in memory iCalObject to a full vCalendar we can send
+ */
+ str = calendar_string_from_object (obj);
+
+ GNOME_Calendar_Repository_update_object (calendar, obj->uid, str, &ev);
+
+ free (str);
+
+ /*
+ * Shutdown
+ */
+ ical_object_destroy (obj);
+}
+
static gint
load_records(GnomePilotConduit *c)
{
@@ -68,9 +277,10 @@ load_records(GnomePilotConduit *c)
ConduitData *cd;
vcalendar_string =
- GNOME_Calendar_Repository_get_updated_objects (calendar_server(), &ev);
+ GNOME_Calendar_Repository_get_updated_objects (calendar, &ev);
cd = GET_DATA(c);
+ g_assert(cd!=NULL);
cd->cal = calendar_new("Temporary");
error = calendar_load_from_memory(cd->cal,vcalendar_string);
@@ -83,25 +293,25 @@ pre_sync(GnomePilotConduit *c, GnomePilotDBInfo *dbi)
{
int l;
unsigned char *buf;
-
+
+ calendar = CORBA_OBJECT_NIL;
+ calendar = calendar_server();
+ if(calendar == CORBA_OBJECT_NIL) {
+ return 0;
+ }
+
gtk_object_set_data(GTK_OBJECT(c),"dbinfo",dbi);
load_records(c);
buf = (unsigned char*)g_malloc(0xffff);
if((l=dlp_ReadAppBlock(dbi->pilot_socket,dbi->db_handle,0,(unsigned char *)buf,0xffff))<0) {
- return -1;
+ return 0;
}
unpack_AppointmentAppInfo(&(GET_DATA(c)->ai),buf,l);
g_free(buf);
- return 0;
-}
-
-static gint
-post_sync(GnomePilotConduit *c)
-{
- return 0;
+ return 1;
}
static gint
@@ -110,8 +320,10 @@ match_record (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
PilotRecord *remote,
gpointer data)
{
+ g_return_val_if_fail(remote!=NULL,0);
g_print ("in match_record\n");
- return 0;
+ *local = NULL;
+ return 1;
}
static gint
free_match (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
@@ -120,7 +332,6 @@ free_match (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
{
g_print ("entering free_match\n");
*local = NULL;
-
return 0;
}
static gint
@@ -146,9 +357,12 @@ store_remote (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
PilotRecord *remote,
gpointer data)
{
- g_print ("entering store_remote\n");
- g_print ("Rec:%s:\nLength:%d\n", remote->record, remote->length);
- return 1;
+ g_print ("entering store_remote\n");
+ g_return_val_if_fail(remote!=NULL,0);
+
+ update_record(remote);
+
+ return 1;
}
static gint
clear_status_archive_local (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
@@ -190,7 +404,7 @@ set_status (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
gpointer data)
{
g_print ("entering set_status\n");
- return 1;
+ return 0;
}
static gint
set_archived (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
@@ -253,7 +467,7 @@ transmit (GnomePilotConduitStandardAbs *pilot_conduit_standard_abs,
return NULL;
}
-static GnomePilotConduit *
+GnomePilotConduit *
conduit_get_gpilot_conduit (guint32 pilotId)
{
GtkObject *retval;
@@ -262,7 +476,6 @@ conduit_get_gpilot_conduit (guint32 pilotId)
CORBA_exception_init (&ev);
- g_print ("creating our new conduit\n");
retval = gnome_pilot_conduit_standard_abs_new ("DatebookDB", 0x64617465);
g_assert (retval != NULL);
gnome_pilot_conduit_construct(GNOME_PILOT_CONDUIT(retval),"calendar");
@@ -273,11 +486,8 @@ conduit_get_gpilot_conduit (guint32 pilotId)
cdata = g_new0(ConduitData,1);
g_assert(cdata != NULL);
- cdata = NULL;
gtk_object_set_data(retval,"conduit_data",cdata);
- calendar = CORBA_OBJECT_NIL;
-
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);
@@ -296,19 +506,20 @@ conduit_get_gpilot_conduit (guint32 pilotId)
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);
- gtk_signal_connect (retval, "post_sync", (GtkSignalFunc) post_sync, NULL);
load_configuration(&cfg,pilotId);
return GNOME_PILOT_CONDUIT (retval);
}
-static void
+void
conduit_destroy_gpilot_conduit (GnomePilotConduit *conduit)
{
ConduitCfg *cc;
ConduitData *cd;
+ GNOME_Calendar_Repository_done (calendar, &ev);
+
cc = GET_CONFIG(conduit);
destroy_configuration(&cc);
@@ -317,8 +528,6 @@ conduit_destroy_gpilot_conduit (GnomePilotConduit *conduit)
gtk_object_destroy (GTK_OBJECT (conduit));
- GNOME_Calendar_Repository_done (calendar_server(), &ev);
-
}
diff --git a/calendar/gui/corba-cal.c b/calendar/gui/corba-cal.c
index 3e95571f6c..6b4566dc06 100644
--- a/calendar/gui/corba-cal.c
+++ b/calendar/gui/corba-cal.c
@@ -79,12 +79,12 @@ cal_repo_get_object_by_pilot_id (PortableServer_Servant servant,
iCalObject *obj;
char *buffer;
CORBA_char *ret;
-
+
obj = calendar_object_find_by_pilot (gcal->cal, pilot_id);
if (obj == NULL){
CORBA_exception_set (ev,
CORBA_USER_EXCEPTION,
- ex_GNOME_Calendar_Repository_NotFound, "");
+ ex_GNOME_Calendar_Repository_NotFound, NULL);
return NULL;
}
@@ -108,7 +108,7 @@ cal_repo_get_id_from_pilot_id (PortableServer_Servant servant,
if (obj == NULL){
CORBA_exception_set (ev,
CORBA_USER_EXCEPTION,
- ex_GNOME_Calendar_Repository_NotFound, "");
+ ex_GNOME_Calendar_Repository_NotFound, NULL);
return NULL;
}
diff --git a/calendar/pcs/calobj.h b/calendar/pcs/calobj.h
index 07ba3f1cc7..8be38e5d26 100644
--- a/calendar/pcs/calobj.h
+++ b/calendar/pcs/calobj.h
@@ -180,8 +180,8 @@ typedef struct {
void *user_data; /* Generic data pointer */
/* Pilot */
- int pilot_status; /* Status information */
- int pilot_id; /* Pilot ID */
+ iCalPilotState pilot_status; /* Status information */
+ int pilot_id; /* Pilot ID */
} iCalObject;
/* The callback for the recurrence generator */