static ECalComponent * comp_from_remote_record (GnomePilotConduitSyncAbs *conduit, GnomePilotRecord *remote, ECalComponent *in_comp, icaltimezone *timezone, struct MemoAppInfo *ai) { ECalComponent *comp; struct Memo memo; struct icaltimetype now; icaltimezone *utc_zone; char *txt, *txt2, *txt3; int i; #ifdef PILOT_LINK_0_12 pi_buffer_t * buffer; #endif g_return_val_if_fail (remote != NULL, NULL); #ifdef PILOT_LINK_0_12 buffer = pi_buffer_new(DLP_BUF_SIZE); if(buffer == NULL){ return NULL; } if(pi_buffer_append(buffer, remote->record, remote->length)==NULL){ return NULL; } unpack_Memo (&memo, buffer, memo_v1); pi_buffer_free(buffer); #else memset (&memo, 0, sizeof (struct Memo)); unpack_Memo (&memo, remote->record, remote->length); #endif utc_zone = icaltimezone_get_utc_timezone (); now = icaltime_from_timet_with_zone (time (NULL), FALSE, utc_zone); if (in_comp == NULL) { comp = e_cal_component_new (); e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_JOURNAL); e_cal_component_set_created (comp, &now); } else { comp = e_cal_component_clone (in_comp); } e_cal_component_set_last_modified (comp, &now); /*Category support*/ e_pilot_remote_category_to_local(remote->category, comp, &(ai->category)); /* The iCal description field */ if (!memo.text) { e_cal_component_set_comment_list (comp, NULL); e_cal_component_set_summary(comp, NULL); } else { int idxToUse = -1, ntext = strlen(memo.text); gboolean foundNL = FALSE; GSList l; ECalComponentText text, sumText; for(i = 0; i<ntext && i<50; i++){ if(memo.text[i] == '\n'){ idxToUse = i; foundNL = TRUE; break; } } if(foundNL == FALSE){ if(ntext > 50){ txt2 = g_strndup(memo.text, 50); } else{ txt2 = g_strdup(memo.text); } } else{ txt2 = g_strndup(memo.text, idxToUse); /* cuts off '\n' */ } sumText.value = txt3 = e_pilot_utf8_from_pchar(txt2); sumText.altrep = NULL; text.value = txt = e_pilot_utf8_from_pchar (memo.text); text.altrep = NULL; l.data = &text; l.next = NULL; e_cal_component_set_summary(comp, &sumText); e_cal_component_set_description_list (comp, &l); free (txt); g_free(txt2); free(txt3); } e_cal_component_set_transparency (comp, E_CAL_COMPONENT_TRANSP_NONE); if (remote->secret) e_cal_component_set_classification (comp, E_CAL_COMPONENT_CLASS_PRIVATE); else e_cal_component_set_classification (comp, E_CAL_COMPONENT_CLASS_PUBLIC); e_cal_component_commit_sequence (comp); free_Memo(&memo); return comp; }
static const gchar * test_object_creation (ECal *client, gchar **uid) { ECalComponent *comp, *comp_retrieved; icalcomponent *icalcomp, *icalcomp_retrieved; struct icaltimetype tt; ECalComponentText text; ECalComponentDateTime dt; ECalComponentTransparency transp; gboolean compare; GError *error = NULL; comp = e_cal_component_new (); /* set fields */ e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT); text.value = "Creation of new test event"; text.altrep = NULL; e_cal_component_set_summary (comp, &text); tt = icaltime_from_string ("20040109T090000Z"); dt.value = &tt; dt.tzid ="UTC"; e_cal_component_set_dtstart (comp, &dt); tt = icaltime_from_string ("20040109T103000"); dt.value = &tt; dt.tzid ="UTC"; e_cal_component_set_dtend (comp, &dt); e_cal_component_set_transparency (comp, E_CAL_COMPONENT_TRANSP_OPAQUE); e_cal_component_commit_sequence (comp); icalcomp = e_cal_component_get_icalcomponent (comp); if (!e_cal_create_object (client, icalcomp, uid, &error)) { cl_printf (client, "Object creation: %s\n", error->message); g_free (comp); g_free (icalcomp); return "Test Object Creation failed"; } e_cal_component_commit_sequence (comp); if (!e_cal_get_object (client, *uid, NULL, &icalcomp_retrieved, &error)) { cl_printf (client, "Object retrieval: %s\n", error->message); g_free (uid); g_free (comp); g_free (icalcomp); return "Test Object Creation failed"; } comp_retrieved = e_cal_component_new (); if (!e_cal_component_set_icalcomponent (comp_retrieved, icalcomp_retrieved)) { cl_printf (client, "Could not set icalcomponent\n"); g_free (uid); g_free (comp); g_free (icalcomp); g_free (icalcomp_retrieved); return "Test Object Creation failed"; } /* Dumping icalcomp into a string is not useful as the retrieved object * has some generated information like timestamps. We compare * member values we set during creation*/ compare = e_cal_component_event_dates_match (comp, comp_retrieved); if (compare) { e_cal_component_get_transparency (comp_retrieved, &transp); compare = (transp == E_CAL_COMPONENT_TRANSP_OPAQUE); } g_free (comp_retrieved); g_free (comp); g_free (icalcomp); g_free (icalcomp_retrieved); mu_assert ("Test Object creation : Created object does not match retrieved data\n", compare); return NULL; }