void dates_calendar_combo_changed_cb (GtkComboBox *widget, DatesData *d) { ECal *c; ECalComponent *comp = d->comp; GtkTreeIter iter; if (!gtk_combo_box_get_active_iter (widget, &iter)) return; gtk_tree_model_get (gtk_combo_box_get_model (widget), &iter, COL_CALPTR, &c, -1); if (c != d->cal) { /* Move event between calendars */ const char *uid = NULL; g_object_ref (comp); if (!d->waiting) d->waiting = PENDING_CAL_CHANGE; e_cal_component_get_uid (comp, &uid); e_cal_remove_object (d->cal, uid, NULL); /* TODO: Error checking */ e_cal_create_object (c, e_cal_component_get_icalcomponent (comp), (char **)&uid, NULL); g_object_unref (comp); d->uri_uid = g_strconcat (e_cal_get_uri (c), uid, NULL); d->widgets = contacts_set_widgets_desensitive (d->details_dialog); g_idle_add (dates_select_event_idle_cb, d); } }
char * evo_cal_component_get_uid(ECalComponent *obj) { const char *uid = NULL; e_cal_component_get_uid(obj, &uid); if (uid) return g_strdup(uid); else return NULL; }
static gint set_status_cleared (GnomePilotConduitSyncAbs *conduit, EMemoLocalRecord *local, EMemoConduitContext *ctxt) { const char *uid; LOG (g_message ( "set_status_cleared: clearing status\n" )); e_cal_component_get_uid (local->comp, &uid); g_hash_table_remove (ctxt->changed_hash, uid); return 0; }
static gint set_pilot_id (GnomePilotConduitSyncAbs *conduit, EMemoLocalRecord *local, guint32 ID, EMemoConduitContext *ctxt) { const char *uid; LOG (g_message ( "set_pilot_id: setting to %d\n", ID )); e_cal_component_get_uid (local->comp, &uid); e_pilot_map_insert (ctxt->map, ID, uid, FALSE); return 0; }
static void print_ecomp (ECalComponent *ecalcomp) { const gchar *uid = NULL; ECalComponentText summary = { 0 }; g_return_if_fail (ecalcomp != NULL); e_cal_component_get_uid (ecalcomp, &uid); e_cal_component_get_summary (ecalcomp, &summary); g_print (" Component: %s\n", uid ? uid : "no-uid"); g_print (" Summary: %s\n", summary.value ? summary.value : "NULL"); g_print ("\n"); }
/* (uid? UID) * * UID - the uid of the component * * Returns a boolean indicating whether the component has the given UID */ static ESExpResult * func_uid (ESExp *esexp, gint argc, ESExpResult **argv, gpointer data) { SearchContext *ctx = data; const gchar *uid = NULL, *arg_uid; gboolean equal; ESExpResult *result; /* Check argument types */ if (argc != 1) { e_sexp_fatal_error ( esexp, _("\"%s\" expects one argument"), "uid"); return NULL; } if (argv[0]->type != ESEXP_RES_STRING) { e_sexp_fatal_error ( esexp, _("\"%s\" expects the first " "argument to be a string"), "uid"); return NULL; } arg_uid = argv[0]->value.string; e_cal_component_get_uid (ctx->comp, &uid); if (!arg_uid && !uid) equal = TRUE; else if ((!arg_uid || !uid) && arg_uid != uid) equal = FALSE; else if (e_util_utf8_strstrcase (arg_uid, uid) != NULL && strlen (arg_uid) == strlen (uid)) equal = TRUE; else equal = FALSE; result = e_sexp_result_new (esexp, ESEXP_RES_BOOL); result->value.boolean = equal; return result; }
static GList * next_changed_item (EMemoConduitContext *ctxt, GList *changes) { ECalChange *ccc; GList *l; for (l = changes; l != NULL; l = l->next) { const char *uid; ccc = l->data; e_cal_component_get_uid (ccc->comp, &uid); if (g_hash_table_lookup (ctxt->changed_hash, uid)) return l; } return NULL; }
static gint archive_record (GnomePilotConduitSyncAbs *conduit, EMemoLocalRecord *local, gboolean archive, EMemoConduitContext *ctxt) { const char *uid; int retval = 0; g_return_val_if_fail (local != NULL, -1); LOG (g_message ( "archive_record: %s\n", archive ? "yes" : "no" )); e_cal_component_get_uid (local->comp, &uid); e_pilot_map_insert (ctxt->map, local->local.ID, uid, archive); return retval; }
static void scalix_appointment_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { ScalixAppointment *app; char *str; const char *uid; ScalixAppointmentPrivate *priv; priv = SCALIX_APPOINTMENT_GET_PRIVATE (SCALIX_APPOINTMENT (object)); app = SCALIX_APPOINTMENT (object); switch (prop_id) { case PROP_ICAL: str = scalix_appointment_to_string (SCALIX_OBJECT (object)); g_value_take_string (value, str); break; case PROP_TIMEZONE: g_value_set_pointer (value, priv->timezone); break; case PROP_EXCEPTIONS: g_value_set_pointer (value, priv->exceptions); break; case PROP_UID: e_cal_component_get_uid (E_CAL_COMPONENT (app), &uid); g_value_set_string (value, uid); break; case PROP_IPM_TYPE: g_value_set_int (value, IPM_APPOINTMENT); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } }
void dates_details_cancel_cb (GtkWidget *source, DatesData *d) { if (d->event_type == NEW_EVENT) { if (d->waiting == NONE) { const char *uid = NULL; d->event_type = NORMAL; e_cal_component_get_uid (d->comp, &uid); e_cal_remove_object (d->cal, uid, NULL); } else { d->widgets = contacts_set_widgets_desensitive ( d->details_dialog); d->waiting = PENDING_DELETE; return; } } dates_platform_details_dlg (d, FALSE); }
static gint invitation_double_clicked_cb (ETable *et, int row, int col, GdkEvent *event, gpointer data) { SunOneInvitationList *list = SUNONE_INVITATION_LIST (data); SunOneInvitationListPrivate *priv = list->priv; ECalComponent *comp, *clone; GNOME_Evolution_Calendar_CompEditorFactory factory; const char *uid; CORBA_Environment ev; comp = sunone_invitation_list_model_get_comp (priv->model, row); if (!comp) return FALSE; clone = e_cal_component_clone (comp); sunone_util_mangle_uid (clone); e_cal_component_get_uid (clone, &uid); /* Get the factory */ CORBA_exception_init (&ev); factory = bonobo_activation_activate_from_id (COMPEDITORFACTORY, 0, NULL, &ev); if (BONOBO_EX (&ev)) { g_message ("%s: Could not activate the component editor factory (%s)", G_GNUC_FUNCTION, CORBA_exception_id (&ev)); CORBA_exception_free (&ev); return FALSE; } GNOME_Evolution_Calendar_CompEditorFactory_editExisting (factory, priv->model->uri, (char *)uid, GNOME_Evolution_Calendar_CompEditorFactory_EDITOR_MODE_EVENT, &ev); if (BONOBO_EX (&ev)) { g_message ("%s: Execption while editing the component (%s)", G_GNUC_FUNCTION, CORBA_exception_id (&ev)); } g_object_unref (G_OBJECT (clone)); CORBA_exception_free (&ev); bonobo_object_release_unref (factory, NULL); return FALSE; }
static gint delete_record (GnomePilotConduitSyncAbs *conduit, EMemoLocalRecord *local, EMemoConduitContext *ctxt) { const char *uid; g_return_val_if_fail (local != NULL, -1); g_return_val_if_fail (local->comp != NULL, -1); e_cal_component_get_uid (local->comp, &uid); LOG (g_message ( "delete_record: deleting %s", uid )); e_pilot_map_remove_by_uid (ctxt->map, uid); /* FIXME Error handling */ e_cal_remove_object (ctxt->client, uid, NULL); return 0; }
gboolean dates_select_event_idle_cb (gpointer data) { DatesData *d = data; gboolean selected = dates_view_set_selected_event (d->view, d->uri_uid, NULL); if (selected) { const char *uid = NULL; g_free (d->uri_uid); d->uri_uid = NULL; if (d->widgets) { contacts_set_widgets_sensitive (d->widgets); g_list_free (d->widgets); d->widgets = NULL; } switch (d->waiting) { case NONE : case PENDING_CREATE : break; case PENDING_DELETE : e_cal_component_get_uid (d->comp, &uid); e_cal_remove_object (d->cal, uid, NULL); dates_platform_details_dlg (d, FALSE); break; case PENDING_CHANGE : dates_save_changes (d); gtk_widget_hide (d->details_dialog); break; case PENDING_CAL_CHANGE : break; default: g_warning ("Unknown pending state"); } d->waiting = NONE; } return !selected; }
static void mem_test (void) { EIntervalTree *tree; time_t start = 10, end = 50; ECalComponent *comp = create_test_component (start, end), *clone_comp; const gchar *uid; gchar *rid; tree = e_intervaltree_new (); g_assert (((GObject *) comp)->ref_count == 1); e_intervaltree_insert (tree, start, end, comp); g_assert (((GObject *) comp)->ref_count == 2); e_cal_component_get_uid (comp, &uid); rid = e_cal_component_get_recurid_as_string (comp); e_intervaltree_remove (tree, uid, rid); g_free (rid); g_assert (((GObject *) comp)->ref_count == 1); e_intervaltree_insert (tree, start, end, comp); g_assert (((GObject *) comp)->ref_count == 2); clone_comp = e_cal_component_clone (comp); e_intervaltree_insert (tree, start, end, clone_comp); g_assert (((GObject *) comp)->ref_count == 1); g_assert (((GObject *) clone_comp)->ref_count == 2); e_intervaltree_destroy (tree); g_assert (((GObject *) comp)->ref_count == 1); g_assert (((GObject *) clone_comp)->ref_count == 1); g_object_unref (comp); g_object_unref (clone_comp); }
static void random_test (void) { /* * outline: * 1. create new tree and empty list of intervals * 2. insert some intervals into tree and list * 3. do various searches, compare results of both structures * 4. delete some intervals * 5. do various searches, compare results of both structures * 6. free memory */ gint i, start, end; EInterval *interval = NULL; EIntervalTree *tree; GList *l1, *l2, *next; gint num_deleted = 0; tree = e_intervaltree_new (); for (i = 0; i < NUM_INTERVALS_CLOSED; i++) { ECalComponent *comp; start = g_rand_int_range (myrand, 0, 1000); end = g_rand_int_range (myrand, start, 2000); comp = create_test_component (start, end); if (!comp) { g_message (G_STRLOC ": error"); exit (-1); } interval = g_new (EInterval, 1); interval->start = start; interval->end = end; interval->comp = comp; list = g_list_insert (list, interval, -1); e_intervaltree_insert (tree, start, end, comp); } /* insert open ended intervals */ for (i = 0; i < NUM_INTERVALS_OPEN; i++) { ECalComponent *comp; start = g_rand_int_range (myrand, 0, 1000); comp = create_test_component (start, end); if (!comp) { g_message (G_STRLOC ": error"); exit (-1); } interval = g_new (EInterval, 1); interval->start = start; interval->end = _TIME_MAX; interval->comp = comp; list = g_list_insert (list, interval, -1); e_intervaltree_insert (tree, start, interval->end, comp); /* g_print ("%d - %d\n", start, interval->end); */ } g_print ("Number of intervals inserted: %d\n", NUM_INTERVALS_CLOSED + NUM_INTERVALS_OPEN); for (i = 0; i < NUM_SEARCHES; i++) { start = g_rand_int_range (myrand, 0, 1000); end = g_rand_int_range (myrand, 2000, _TIME_MAX); /* g_print ("Search for : %d - %d\n", start, end); */ l1 = e_intervaltree_search (tree, start, end); l2 = search_in_list (list, start, end); if (!compare_interval_lists (l2, l1)) { e_intervaltree_dump (tree); g_message (G_STRLOC "Error"); exit (-1); } /* g_print ("OK\n"); */ g_list_foreach (l1, (GFunc)g_object_unref, NULL); g_list_foreach (l2, (GFunc)unref_comp, NULL); g_list_free (l1); g_list_free (l2); } /* open-ended intervals */ for (i = 0; i < 20; i++) { start = g_rand_int_range (myrand, 0, 1000); end = _TIME_MAX; /* g_print ("Search for : %d - %d\n", start, end); */ l1 = e_intervaltree_search (tree, start, end); l2 = search_in_list (list, start, end); if (!compare_interval_lists (l2, l1)) { e_intervaltree_dump (tree); g_message (G_STRLOC "Error"); exit (-1); } /* g_print ("OK\n"); */ g_list_foreach (l1, (GFunc)g_object_unref, NULL); g_list_foreach (l2, (GFunc)unref_comp, NULL); g_list_free (l1); g_list_free (l2); } l1 = list; while (l1) { /* perhaps we will delete l1 */ next = l1->next; if (g_rand_double (myrand) < pbality_delete) { ECalComponent *comp; const gchar *uid = NULL; gchar *rid; interval = (EInterval*) l1->data; comp = interval->comp; /* delete l1 */ /* g_print ("Deleting interval %d - %d\n", interval->start, interval->end); */ rid = e_cal_component_get_recurid_as_string (comp); e_cal_component_get_uid (comp, &uid); if (!e_intervaltree_remove (tree, uid, rid)) { g_free (rid); e_intervaltree_dump (tree); g_print ("Deleting interval %d - %d ERROR\n", interval->start, interval->end); exit (-1); } g_free (rid); g_object_unref (interval->comp); g_free (l1->data); list = g_list_delete_link (list, l1); num_deleted++; } l1 = next; } g_print ("Number of intervals deleted: %d\n", num_deleted); for (i = 0; i < NUM_SEARCHES; i++) { start = g_rand_int_range (myrand, 0, 1000); end = g_rand_int_range (myrand, start, 2000); /* g_print ("Search for : %d - %d\n", start, end); */ l1 = e_intervaltree_search (tree, start, end); /* g_print ("Results from tree:\n"); print_nodes_list (l1); */ l2 = search_in_list (list, start, end); if (!compare_interval_lists (l2, l1)) { g_print ("ERROR!\n\n"); return; } g_list_foreach (l1, (GFunc)g_object_unref, NULL); g_list_foreach (l2, (GFunc)unref_comp, NULL); g_list_free (l1); g_list_free (l2); /* g_print ("OK\n"); */ } e_intervaltree_destroy (tree); g_list_foreach (list, (GFunc)unref_comp, NULL); g_list_free (list); }
gboolean scalix_appointment_init_from_mime_message (ScalixObject * object, CamelMimeMessage * msg) { const char *msgid; const char *attachment_store; const char *mime_type, *alternative_mime_type; const char *content_disposition; const char *mime_filename; const char *cid; const char *cuid; const char *attachment_file_url; GSList *attachments = NULL; GSList *attachments_new = NULL; GSList *siter = NULL; CamelMimePart *part, *alternative; CamelMultipart *multipart, *nested_multipart; CamelDataWrapper *content, *alternative_content; int i, j, num_parts, num_alternatives; gboolean found_ical = FALSE; attachment_store = g_object_get_data (G_OBJECT (object), "attachment-store"); part = CAMEL_MIME_PART (msg); content = camel_medium_get_content_object (CAMEL_MEDIUM (part)); if (content == NULL) { return FALSE; } mime_type = camel_content_type_simple (content->mime_type); if (CAMEL_IS_MULTIPART (content)) { multipart = (CamelMultipart *) content; num_parts = (int) camel_multipart_get_number (multipart); for (i = 0; i < num_parts; i++) { part = camel_multipart_get_part (multipart, i); content = camel_medium_get_content_object (CAMEL_MEDIUM (part)); mime_type = camel_content_type_simple (content->mime_type); mime_filename = camel_mime_part_get_filename (part); content_disposition = camel_mime_part_get_disposition (part); if (CAMEL_IS_MULTIPART (content)) { nested_multipart = (CamelMultipart *) content; num_alternatives = (int) camel_multipart_get_number (nested_multipart); for (j = 0; j < num_alternatives; j++) { alternative = camel_multipart_get_part (nested_multipart, j); alternative_content = camel_medium_get_content_object (CAMEL_MEDIUM (alternative)); alternative_mime_type = camel_content_type_simple (alternative_content-> mime_type); if (g_str_equal (alternative_mime_type, "text/calendar") && found_ical == FALSE) { if (set_ical_from_mime_part (alternative, object) == TRUE) { e_cal_component_get_uid (E_CAL_COMPONENT (object), &cuid); e_cal_component_get_attachment_list (E_CAL_COMPONENT (object), &attachments); /* we are only interested in the first ical body part */ found_ical = TRUE; } } } } else if (g_str_equal (mime_type, "text/calendar") && found_ical == FALSE) { if (set_ical_from_mime_part (part, object) == TRUE) { e_cal_component_get_uid (E_CAL_COMPONENT (object), &cuid); e_cal_component_get_attachment_list (E_CAL_COMPONENT (object), &attachments); /* we are only interested in the first ical body part */ found_ical = TRUE; } } else if (content_disposition && strcmp (content_disposition, "attachment") == 0) { cid = camel_mime_part_get_content_id (part); if (cid != NULL) { for (siter = attachments; siter; siter = siter->next) { if (strstr (siter->data, cid) == (char *) (siter->data) + 4) { attachment_file_url = save_attachment (part, cuid, attachment_store); if (attachment_file_url != NULL) { attachments_new = g_slist_append (attachments_new, g_strdup (attachment_file_url)); } } } } } else { g_print ("XXXXX Unhandled mime part: %s\n", mime_type); } } } else { /* just a simple ical message */ if (g_str_equal (mime_type, "text/calendar")) { set_ical_from_mime_part (part, object); } } if (attachments_new != NULL) { e_cal_component_set_attachment_list (E_CAL_COMPONENT (object), attachments_new); } msgid = camel_mime_message_get_message_id (msg); scalix_appointment_unset (SCALIX_APPOINTMENT (object), X_SCALIX_MSG_ID); scalix_appointment_set (SCALIX_APPOINTMENT (object), X_SCALIX_MSG_ID, msgid); return TRUE; }
CamelMimeMessage * scalix_appointment_to_mime_message (ScalixObject * object) { CamelMimeMessage *message; CamelMultipart *multipart; CamelMimePart *part; CamelMedium *medium; CamelStream *stream; CamelDataWrapper *wrapper; ECalComponentDateTime dtstart, dtend; ECalComponent *comp; ECalComponentText text; icalcomponent_kind kind; icalcomponent *icalcomp, *toplevel_comp; icaltimezone *zone = NULL; GSList *attachment_list = NULL; GSList *attachment_list_new = NULL; GSList *siter = NULL; GList *part_list = NULL; GList *iter = NULL; char *msgid; char *str, *meeting_status; const char *ouid = NULL; char *file_contents = NULL; char *full_path, *filename, *mime_filename; char *cid; int size; g_object_get (SCALIX_APPOINTMENT (object), "timezone", &zone, NULL); comp = E_CAL_COMPONENT (scalix_object_clone (object)); message = camel_mime_message_new (); medium = CAMEL_MEDIUM (message); camel_medium_add_header (medium, "X-Scalix-Class", "IPM.Appointment"); /* Preserve msg id if there is already one */ if (scalix_appointment_get (SCALIX_APPOINTMENT (comp), X_SCALIX_MSG_ID, &msgid)) { scalix_appointment_unset (SCALIX_APPOINTMENT (comp), X_SCALIX_MSG_ID); } else { msgid = camel_header_msgid_generate (); } camel_mime_message_set_message_id (message, msgid); /* subject */ e_cal_component_get_summary (comp, &text); if (text.value != NULL) { camel_mime_message_set_subject (message, text.value); } /* start day */ e_cal_component_get_dtstart (comp, &dtstart); if (!icaltime_get_timezone (*dtstart.value)) icaltime_set_timezone (dtstart.value, icaltimezone_get_builtin_timezone_from_tzid (dtstart.tzid)); /* end day */ e_cal_component_get_dtend (comp, &dtend); if (!icaltime_get_timezone (*dtend.value)) icaltime_set_timezone (dtend.value, icaltimezone_get_builtin_timezone_from_tzid (dtend.tzid)); /* set From: and Sender: */ if (e_cal_component_has_organizer (comp)) { ECalComponentOrganizer organizer; e_cal_component_get_organizer (comp, &organizer); if (!strncasecmp (organizer.value, "MAILTO:", 7)) { camel_medium_add_header (medium, "Sender", organizer.value + 7); camel_medium_add_header (medium, "From", organizer.value + 7); } } /* set the appropriate recipient headers from the recipient table */ if (e_cal_component_has_attendees (comp) && e_cal_component_has_organizer (comp)) { GSList *iter, *attendees = NULL; CamelInternetAddress *recipients_to = NULL; CamelInternetAddress *recipients_cc = NULL; meeting_status = "1"; e_cal_component_get_attendee_list (comp, &attendees); for (iter = attendees; iter; iter = iter->next) { ECalComponentAttendee *attendee = iter->data; const char *mail = NULL; /* attendee entries must start with MAILTO: */ if (strncasecmp (attendee->value, "MAILTO:", 7)) { continue; } mail = attendee->value + 7; if (attendee->role == ICAL_ROLE_REQPARTICIPANT) { if (recipients_to == NULL) { recipients_to = camel_internet_address_new (); } camel_internet_address_add (recipients_to, attendee->cn, mail); } else if (attendee->role == ICAL_ROLE_OPTPARTICIPANT) { if (recipients_cc == NULL) { recipients_cc = camel_internet_address_new (); } camel_internet_address_add (recipients_cc, attendee->cn, mail); } else { continue; } } if (recipients_to != NULL) { camel_mime_message_set_recipients (message, "To", recipients_to); camel_object_unref (recipients_to); } if (recipients_cc != NULL) { camel_mime_message_set_recipients (message, "Cc", recipients_cc); camel_object_unref (recipients_cc); } } else { meeting_status = "0"; } /* Clear properties */ scalix_appointment_unset (SCALIX_APPOINTMENT (comp), X_SCALIX_IMAP_UID); /* Render the text/calendar */ e_cal_component_commit_sequence (comp); icalcomp = e_cal_component_get_icalcomponent (comp); kind = icalcomponent_isa (icalcomp); if (kind != ICAL_VCALENDAR_COMPONENT) { /* If its not a VCALENDAR, make it one to simplify below */ toplevel_comp = e_cal_util_new_top_level (); icalcomponent_add_component (toplevel_comp, icalcomp); icalcomp = toplevel_comp; } /* set METHOD to PUSBLISH */ icalcomponent_set_method (icalcomp, ICAL_METHOD_PUBLISH); /* Add the VTIMEZONE components for start- and/or end-times */ if (zone) { icalcomponent_add_component (icalcomp, icaltimezone_get_component (zone)); } else if (dtstart.tzid) { icalcomponent_add_component (icalcomp, icaltimezone_get_component (icaltimezone_get_builtin_timezone_from_tzid (dtstart.tzid))); } if (dtstart.tzid && dtend.tzid && strcmp (dtstart.tzid, dtend.tzid) != 0) { icalcomponent_add_component (icalcomp, icaltimezone_get_component (icaltimezone_get_builtin_timezone_from_tzid (dtend.tzid))); } /* FIXME: do we leek icalcomponents here? */ if (e_cal_component_has_attachments (comp)) { multipart = camel_multipart_new (); camel_multipart_set_boundary (multipart, NULL); e_cal_component_get_uid (comp, &ouid); e_cal_component_get_attachment_list (comp, &attachment_list); for (siter = attachment_list; siter; siter = siter->next) { if (siter->data == NULL) continue; if (strstr (siter->data, "file://") != siter->data) continue; full_path = ((char *) siter->data) + strlen ("file://"); filename = g_strrstr (full_path, "/") + 1; mime_filename = filename + strlen (ouid) + 1; size = 0; file_contents = get_file_contents (full_path, &size); if (file_contents == NULL) continue; stream = camel_stream_mem_new_with_buffer (file_contents, size); wrapper = camel_data_wrapper_new (); camel_data_wrapper_construct_from_stream (wrapper, stream); camel_object_unref (stream); part = camel_mime_part_new (); camel_medium_set_content_object (CAMEL_MEDIUM (part), wrapper); camel_mime_part_set_filename (part, mime_filename); camel_mime_part_set_encoding (part, CAMEL_TRANSFER_ENCODING_BASE64); cid = camel_header_msgid_generate (); camel_mime_part_set_content_id (part, cid); camel_mime_part_set_description (part, mime_filename); camel_mime_part_set_disposition (part, "attachment"); part_list = g_list_append (part_list, part); attachment_list_new = g_slist_append (attachment_list_new, g_strdup_printf ("CID:%s", cid)); g_free (cid); } e_cal_component_set_attachment_list (comp, attachment_list_new); str = icalcomponent_as_ical_string (icalcomp); part = camel_mime_part_new (); camel_mime_part_set_content (part, str, strlen (str), "text/calendar; method=PUBLISH; charset=UTF-8"); part_list = g_list_prepend (part_list, part); for (iter = part_list; iter; iter = iter->next) { part = (CamelMimePart *) iter->data; camel_multipart_add_part (multipart, part); camel_object_unref (part); } camel_medium_set_content_object (CAMEL_MEDIUM (message), CAMEL_DATA_WRAPPER (multipart)); camel_object_unref (multipart); g_slist_free (attachment_list); g_slist_free (attachment_list_new); g_list_free (part_list); } else { str = icalcomponent_as_ical_string (icalcomp); camel_mime_part_set_content (CAMEL_MIME_PART (message), str, strlen (str), "text/calendar; method=PUBLISH; charset=UTF-8"); } scalix_appointment_set (SCALIX_APPOINTMENT (object), X_SCALIX_MSG_ID, msgid); return message; }
static void do_save_calendar_rdf (FormatHandler *handler, ESourceSelector *selector, ECalClientSourceType type, gchar *dest_uri) { /* * According to some documentation about CSV, newlines 'are' allowed * in CSV-files. But you 'do' have to put the value between quotes. * The helper 'string_needsquotes' will check for that * * http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm * http://www.creativyst.com/cgi-bin/Prod/15/eg/csv2xml.pl */ ESource *primary_source; EClient *source_client; GError *error = NULL; GSList *objects = NULL; gchar *temp = NULL; GOutputStream *stream; if (!dest_uri) return; /* open source client */ primary_source = e_source_selector_ref_primary_selection (selector); source_client = e_cal_client_connect_sync ( primary_source, type, NULL, &error); g_object_unref (primary_source); /* Sanity check. */ g_return_if_fail ( ((source_client != NULL) && (error == NULL)) || ((source_client == NULL) && (error != NULL))); if (source_client == NULL) { display_error_message ( gtk_widget_get_toplevel (GTK_WIDGET (selector)), error->message); g_error_free (error); return; } stream = open_for_writing (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (selector))), dest_uri, &error); if (stream && e_cal_client_get_object_list_as_comps_sync (E_CAL_CLIENT (source_client), "#t", &objects, NULL, NULL)) { GSList *iter; xmlBufferPtr buffer = xmlBufferCreate (); xmlDocPtr doc = xmlNewDoc ((xmlChar *) "1.0"); xmlNodePtr fnode; doc->children = xmlNewDocNode (doc, NULL, (const guchar *)"rdf:RDF", NULL); xmlSetProp (doc->children, (const guchar *)"xmlns:rdf", (const guchar *)"http://www.w3.org/1999/02/22-rdf-syntax-ns#"); xmlSetProp (doc->children, (const guchar *)"xmlns", (const guchar *)"http://www.w3.org/2002/12/cal/ical#"); fnode = xmlNewChild (doc->children, NULL, (const guchar *)"Vcalendar", NULL); /* Should Evolution publicise these? */ xmlSetProp (fnode, (const guchar *)"xmlns:x-wr", (const guchar *)"http://www.w3.org/2002/12/cal/prod/Apple_Comp_628d9d8459c556fa#"); xmlSetProp (fnode, (const guchar *)"xmlns:x-lic", (const guchar *)"http://www.w3.org/2002/12/cal/prod/Apple_Comp_628d9d8459c556fa#"); /* Not sure if it's correct like this */ xmlNewChild (fnode, NULL, (const guchar *)"prodid", (const guchar *)"-//" PACKAGE_STRING "//iCal 1.0//EN"); /* Assuming GREGORIAN is the only supported calendar scale */ xmlNewChild (fnode, NULL, (const guchar *)"calscale", (const guchar *)"GREGORIAN"); temp = calendar_config_get_timezone (); xmlNewChild (fnode, NULL, (const guchar *)"x-wr:timezone", (guchar *) temp); g_free (temp); xmlNewChild (fnode, NULL, (const guchar *)"method", (const guchar *)"PUBLISH"); xmlNewChild (fnode, NULL, (const guchar *)"x-wr:relcalid", (guchar *) e_source_get_uid (primary_source)); xmlNewChild (fnode, NULL, (const guchar *)"x-wr:calname", (guchar *) e_source_get_display_name (primary_source)); /* Version of this RDF-format */ xmlNewChild (fnode, NULL, (const guchar *)"version", (const guchar *)"2.0"); for (iter = objects; iter; iter = iter->next) { ECalComponent *comp = iter->data; const gchar *temp_constchar; gchar *tmp_str = NULL; GSList *temp_list; ECalComponentDateTime temp_dt; struct icaltimetype *temp_time; gint *temp_int; ECalComponentText temp_comptext; xmlNodePtr c_node = xmlNewChild (fnode, NULL, (const guchar *)"component", NULL); xmlNodePtr node = xmlNewChild (c_node, NULL, (const guchar *)"Vevent", NULL); /* Getting the stuff */ e_cal_component_get_uid (comp, &temp_constchar); tmp_str = g_strdup_printf ("#%s", temp_constchar); xmlSetProp (node, (const guchar *)"about", (guchar *) tmp_str); g_free (tmp_str); add_string_to_rdf (node, "uid",temp_constchar); e_cal_component_get_summary (comp, &temp_comptext); add_string_to_rdf (node, "summary", temp_comptext.value); e_cal_component_get_description_list (comp, &temp_list); add_list_to_rdf (node, "description", temp_list, ECALCOMPONENTTEXT); if (temp_list) e_cal_component_free_text_list (temp_list); e_cal_component_get_categories_list (comp, &temp_list); add_list_to_rdf (node, "categories", temp_list, CONSTCHAR); if (temp_list) e_cal_component_free_categories_list (temp_list); e_cal_component_get_comment_list (comp, &temp_list); add_list_to_rdf (node, "comment", temp_list, ECALCOMPONENTTEXT); if (temp_list) e_cal_component_free_text_list (temp_list); e_cal_component_get_completed (comp, &temp_time); add_time_to_rdf (node, "completed", temp_time); if (temp_time) e_cal_component_free_icaltimetype (temp_time); e_cal_component_get_created (comp, &temp_time); add_time_to_rdf (node, "created", temp_time); if (temp_time) e_cal_component_free_icaltimetype (temp_time); e_cal_component_get_contact_list (comp, &temp_list); add_list_to_rdf (node, "contact", temp_list, ECALCOMPONENTTEXT); if (temp_list) e_cal_component_free_text_list (temp_list); e_cal_component_get_dtstart (comp, &temp_dt); add_time_to_rdf (node, "dtstart", temp_dt.value ? temp_dt.value : NULL); e_cal_component_free_datetime (&temp_dt); e_cal_component_get_dtend (comp, &temp_dt); add_time_to_rdf (node, "dtend", temp_dt.value ? temp_dt.value : NULL); e_cal_component_free_datetime (&temp_dt); e_cal_component_get_due (comp, &temp_dt); add_time_to_rdf (node, "due", temp_dt.value ? temp_dt.value : NULL); e_cal_component_free_datetime (&temp_dt); e_cal_component_get_percent (comp, &temp_int); add_nummeric_to_rdf (node, "percentComplete", temp_int); e_cal_component_get_priority (comp, &temp_int); add_nummeric_to_rdf (node, "priority", temp_int); e_cal_component_get_url (comp, &temp_constchar); add_string_to_rdf (node, "URL", temp_constchar); if (e_cal_component_has_attendees (comp)) { e_cal_component_get_attendee_list (comp, &temp_list); add_list_to_rdf (node, "attendee", temp_list, ECALCOMPONENTATTENDEE); if (temp_list) e_cal_component_free_attendee_list (temp_list); } e_cal_component_get_location (comp, &temp_constchar); add_string_to_rdf (node, "location", temp_constchar); e_cal_component_get_last_modified (comp, &temp_time); add_time_to_rdf (node, "lastModified",temp_time); /* Important note! * The documentation is not requiring this! * * if (temp_time) e_cal_component_free_icaltimetype (temp_time); * * Please uncomment and fix documentation if untrue * http://www.gnome.org/projects/evolution/developer-doc/libecal/ECalComponent.html * #e-cal-component-get-last-modified */ } /* I used a buffer rather than xmlDocDump: I want gio support */ xmlNodeDump (buffer, doc, doc->children, 2, 1); g_output_stream_write_all (stream, xmlBufferContent (buffer), xmlBufferLength (buffer), NULL, NULL, &error); g_output_stream_close (stream, NULL, NULL); e_cal_client_free_ecalcomp_slist (objects); xmlBufferFree (buffer); xmlFreeDoc (doc); } if (stream) g_object_unref (stream); g_object_unref (source_client); if (error != NULL) { display_error_message ( gtk_widget_get_toplevel (GTK_WIDGET (selector)), error->message); g_error_free (error); } }
static gboolean cal_backend_http_load (ECalBackendHttp *backend, const gchar *uri, gchar **out_certificate_pem, GTlsCertificateFlags *out_certificate_errors, GCancellable *cancellable, GError **error) { ECalBackendHttpPrivate *priv = backend->priv; ETimezoneCache *timezone_cache; SoupMessage *soup_message; SoupSession *soup_session; icalcomponent *icalcomp, *subcomp; icalcomponent_kind kind; const gchar *newuri; SoupURI *uri_parsed; GHashTable *old_cache; GSList *comps_in_cache; ESource *source; guint status_code; gulong cancel_id = 0; struct { SoupSession *soup_session; SoupMessage *soup_message; } cancel_data; timezone_cache = E_TIMEZONE_CACHE (backend); soup_session = backend->priv->soup_session; soup_message = cal_backend_http_new_message (backend, uri); if (soup_message == NULL) { g_set_error ( error, SOUP_HTTP_ERROR, SOUP_STATUS_MALFORMED, _("Malformed URI: %s"), uri); return FALSE; } if (G_IS_CANCELLABLE (cancellable)) { cancel_data.soup_session = soup_session; cancel_data.soup_message = soup_message; cancel_id = g_cancellable_connect ( cancellable, G_CALLBACK (cal_backend_http_cancelled), &cancel_data, (GDestroyNotify) NULL); } source = e_backend_get_source (E_BACKEND (backend)); e_soup_ssl_trust_connect (soup_message, source); e_source_set_connection_status (source, E_SOURCE_CONNECTION_STATUS_CONNECTING); status_code = soup_session_send_message (soup_session, soup_message); if (G_IS_CANCELLABLE (cancellable)) g_cancellable_disconnect (cancellable, cancel_id); if (status_code == SOUP_STATUS_NOT_MODIFIED) { e_source_set_connection_status (source, E_SOURCE_CONNECTION_STATUS_CONNECTED); /* attempts with ETag can result in 304 status code */ g_object_unref (soup_message); priv->opened = TRUE; return TRUE; } /* Handle redirection ourselves */ if (SOUP_STATUS_IS_REDIRECTION (status_code)) { gboolean success; newuri = soup_message_headers_get_list ( soup_message->response_headers, "Location"); d (g_message ("Redirected from %s to %s\n", async_context->uri, newuri)); if (newuri != NULL) { gchar *redirected_uri; if (newuri[0]=='/') { g_warning ("Hey! Relative URI returned! Working around...\n"); uri_parsed = soup_uri_new (uri); soup_uri_set_path (uri_parsed, newuri); soup_uri_set_query (uri_parsed, NULL); /* g_free (newuri); */ newuri = soup_uri_to_string (uri_parsed, FALSE); g_message ("Translated URI: %s\n", newuri); soup_uri_free (uri_parsed); } redirected_uri = webcal_to_http_method (newuri, FALSE); success = cal_backend_http_load ( backend, redirected_uri, out_certificate_pem, out_certificate_errors, cancellable, error); g_free (redirected_uri); } else { g_set_error ( error, SOUP_HTTP_ERROR, SOUP_STATUS_BAD_REQUEST, _("Redirected to Invalid URI")); success = FALSE; } if (success) { e_source_set_connection_status (source, E_SOURCE_CONNECTION_STATUS_CONNECTED); } else { e_source_set_connection_status (source, E_SOURCE_CONNECTION_STATUS_DISCONNECTED); } g_object_unref (soup_message); return success; } /* check status code */ if (!SOUP_STATUS_IS_SUCCESSFUL (status_code)) { /* because evolution knows only G_IO_ERROR_CANCELLED */ if (status_code == SOUP_STATUS_CANCELLED) g_set_error ( error, G_IO_ERROR, G_IO_ERROR_CANCELLED, "%s", soup_message->reason_phrase); else g_set_error ( error, SOUP_HTTP_ERROR, status_code, "%s", soup_message->reason_phrase); if (status_code == SOUP_STATUS_SSL_FAILED) { e_source_set_connection_status (source, E_SOURCE_CONNECTION_STATUS_SSL_FAILED); cal_backend_http_extract_ssl_failed_data (soup_message, out_certificate_pem, out_certificate_errors); } else { e_source_set_connection_status (source, E_SOURCE_CONNECTION_STATUS_DISCONNECTED); } g_object_unref (soup_message); empty_cache (backend); return FALSE; } e_source_set_connection_status (source, E_SOURCE_CONNECTION_STATUS_CONNECTED); if (priv->store) { const gchar *etag; etag = soup_message_headers_get_one ( soup_message->response_headers, "ETag"); if (etag != NULL && *etag == '\0') etag = NULL; e_cal_backend_store_put_key_value (priv->store, "ETag", etag); } /* get the calendar from the response */ icalcomp = icalparser_parse_string (soup_message->response_body->data); if (!icalcomp) { g_set_error ( error, SOUP_HTTP_ERROR, SOUP_STATUS_MALFORMED, _("Bad file format.")); g_object_unref (soup_message); empty_cache (backend); return FALSE; } if (icalcomponent_isa (icalcomp) != ICAL_VCALENDAR_COMPONENT) { g_set_error ( error, SOUP_HTTP_ERROR, SOUP_STATUS_MALFORMED, _("Not a calendar.")); icalcomponent_free (icalcomp); g_object_unref (soup_message); empty_cache (backend); return FALSE; } g_object_unref (soup_message); soup_message = NULL; /* Update cache */ old_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); comps_in_cache = e_cal_backend_store_get_components (priv->store); while (comps_in_cache != NULL) { const gchar *uid; ECalComponent *comp = comps_in_cache->data; e_cal_component_get_uid (comp, &uid); g_hash_table_insert (old_cache, g_strdup (uid), e_cal_component_get_as_string (comp)); comps_in_cache = g_slist_remove (comps_in_cache, comps_in_cache->data); g_object_unref (comp); } kind = e_cal_backend_get_kind (E_CAL_BACKEND (backend)); subcomp = icalcomponent_get_first_component (icalcomp, ICAL_ANY_COMPONENT); e_cal_backend_store_freeze_changes (priv->store); while (subcomp) { ECalComponent *comp; icalcomponent_kind subcomp_kind; icalproperty *prop = NULL; subcomp_kind = icalcomponent_isa (subcomp); prop = icalcomponent_get_first_property (subcomp, ICAL_UID_PROPERTY); if (!prop && subcomp_kind == kind) { gchar *new_uid = e_cal_component_gen_uid (); icalcomponent_set_uid (subcomp, new_uid); g_free (new_uid); } if (subcomp_kind == kind) { comp = e_cal_component_new (); if (e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (subcomp))) { const gchar *uid; gpointer orig_key, orig_value; e_cal_component_get_uid (comp, &uid); if (!put_component_to_store (backend, comp)) { g_hash_table_remove (old_cache, uid); } else if (g_hash_table_lookup_extended (old_cache, uid, &orig_key, &orig_value)) { ECalComponent *orig_comp = e_cal_component_new_from_string (orig_value); e_cal_backend_notify_component_modified (E_CAL_BACKEND (backend), orig_comp, comp); g_hash_table_remove (old_cache, uid); if (orig_comp) g_object_unref (orig_comp); } else { e_cal_backend_notify_component_created (E_CAL_BACKEND (backend), comp); } } g_object_unref (comp); } else if (subcomp_kind == ICAL_VTIMEZONE_COMPONENT) { icaltimezone *zone; zone = icaltimezone_new (); icaltimezone_set_component (zone, icalcomponent_new_clone (subcomp)); e_timezone_cache_add_timezone (timezone_cache, zone); icaltimezone_free (zone, 1); } subcomp = icalcomponent_get_next_component (icalcomp, ICAL_ANY_COMPONENT); } e_cal_backend_store_thaw_changes (priv->store); /* notify the removals */ g_hash_table_foreach_remove (old_cache, (GHRFunc) notify_and_remove_from_cache, backend); g_hash_table_destroy (old_cache); /* free memory */ icalcomponent_free (icalcomp); priv->opened = TRUE; return TRUE; }
static void do_save_calendar_csv (FormatHandler *handler, ESourceSelector *selector, ECalClientSourceType type, gchar *dest_uri) { /* * According to some documentation about CSV, newlines 'are' allowed * in CSV-files. But you 'do' have to put the value between quotes. * The helper 'string_needsquotes' will check for that * * http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm * http://www.creativyst.com/cgi-bin/Prod/15/eg/csv2xml.pl */ ESource *primary_source; EClient *source_client; GError *error = NULL; GSList *objects = NULL; GOutputStream *stream; GString *line = NULL; CsvConfig *config = NULL; CsvPluginData *d = handler->data; const gchar *tmp = NULL; if (!dest_uri) return; /* open source client */ primary_source = e_source_selector_ref_primary_selection (selector); source_client = e_cal_client_connect_sync ( primary_source, type, NULL, &error); g_object_unref (primary_source); /* Sanity check. */ g_return_if_fail ( ((source_client != NULL) && (error == NULL)) || ((source_client == NULL) && (error != NULL))); if (source_client == NULL) { display_error_message ( gtk_widget_get_toplevel (GTK_WIDGET (selector)), error); g_error_free (error); return; } config = g_new (CsvConfig, 1); tmp = gtk_entry_get_text (GTK_ENTRY (d->delimiter_entry)); config->delimiter = userstring_to_systemstring (tmp ? tmp:", "); tmp = gtk_entry_get_text (GTK_ENTRY (d->newline_entry)); config->newline = userstring_to_systemstring (tmp ? tmp:"\\n"); tmp = gtk_entry_get_text (GTK_ENTRY (d->quote_entry)); config->quote = userstring_to_systemstring (tmp ? tmp:"\""); config->header = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON (d->header_check)); stream = open_for_writing ( GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (selector))), dest_uri, &error); if (stream && e_cal_client_get_object_list_as_comps_sync (E_CAL_CLIENT (source_client), "#t", &objects, NULL, NULL)) { GSList *iter; if (config->header) { gint i = 0; static const gchar *labels[] = { N_("UID"), N_("Summary"), N_("Description List"), N_("Categories List"), N_("Comment List"), N_("Completed"), N_("Created"), N_("Contact List"), N_("Start"), N_("End"), N_("Due"), N_("percent Done"), N_("Priority"), N_("URL"), N_("Attendees List"), N_("Location"), N_("Modified"), }; line = g_string_new (""); for (i = 0; i < G_N_ELEMENTS (labels); i++) { if (i > 0) g_string_append (line, config->delimiter); g_string_append (line, _(labels[i])); } g_string_append (line, config->newline); g_output_stream_write_all ( stream, line->str, line->len, NULL, NULL, NULL); g_string_free (line, TRUE); } for (iter = objects; iter; iter = iter->next) { ECalComponent *comp = iter->data; gchar *delimiter_temp = NULL; const gchar *temp_constchar; GSList *temp_list; ECalComponentDateTime temp_dt; struct icaltimetype *temp_time; gint *temp_int; ECalComponentText temp_comptext; line = g_string_new (""); /* Getting the stuff */ e_cal_component_get_uid (comp, &temp_constchar); line = add_string_to_csv (line, temp_constchar, config); e_cal_component_get_summary (comp, &temp_comptext); line = add_string_to_csv ( line, temp_comptext.value, config); e_cal_component_get_description_list (comp, &temp_list); line = add_list_to_csv ( line, temp_list, config, ECALCOMPONENTTEXT); if (temp_list) e_cal_component_free_text_list (temp_list); e_cal_component_get_categories_list (comp, &temp_list); line = add_list_to_csv ( line, temp_list, config, CONSTCHAR); if (temp_list) e_cal_component_free_categories_list (temp_list); e_cal_component_get_comment_list (comp, &temp_list); line = add_list_to_csv ( line, temp_list, config, ECALCOMPONENTTEXT); if (temp_list) e_cal_component_free_text_list (temp_list); e_cal_component_get_completed (comp, &temp_time); line = add_time_to_csv (line, temp_time, config); if (temp_time) e_cal_component_free_icaltimetype (temp_time); e_cal_component_get_created (comp, &temp_time); line = add_time_to_csv (line, temp_time, config); if (temp_time) e_cal_component_free_icaltimetype (temp_time); e_cal_component_get_contact_list (comp, &temp_list); line = add_list_to_csv ( line, temp_list, config, ECALCOMPONENTTEXT); if (temp_list) e_cal_component_free_text_list (temp_list); e_cal_component_get_dtstart (comp, &temp_dt); line = add_time_to_csv ( line, temp_dt.value ? temp_dt.value : NULL, config); e_cal_component_free_datetime (&temp_dt); e_cal_component_get_dtend (comp, &temp_dt); line = add_time_to_csv ( line, temp_dt.value ? temp_dt.value : NULL, config); e_cal_component_free_datetime (&temp_dt); e_cal_component_get_due (comp, &temp_dt); line = add_time_to_csv ( line, temp_dt.value ? temp_dt.value : NULL, config); e_cal_component_free_datetime (&temp_dt); e_cal_component_get_percent (comp, &temp_int); line = add_nummeric_to_csv (line, temp_int, config); e_cal_component_get_priority (comp, &temp_int); line = add_nummeric_to_csv (line, temp_int, config); e_cal_component_get_url (comp, &temp_constchar); line = add_string_to_csv (line, temp_constchar, config); if (e_cal_component_has_attendees (comp)) { e_cal_component_get_attendee_list (comp, &temp_list); line = add_list_to_csv ( line, temp_list, config, ECALCOMPONENTATTENDEE); if (temp_list) e_cal_component_free_attendee_list (temp_list); } else { line = add_list_to_csv ( line, NULL, config, ECALCOMPONENTATTENDEE); } e_cal_component_get_location (comp, &temp_constchar); line = add_string_to_csv (line, temp_constchar, config); e_cal_component_get_last_modified (comp, &temp_time); /* Append a newline (record delimiter) */ delimiter_temp = config->delimiter; config->delimiter = config->newline; line = add_time_to_csv (line, temp_time, config); /* And restore for the next record */ config->delimiter = delimiter_temp; /* Important note! * The documentation is not requiring this! * * if (temp_time) * e_cal_component_free_icaltimetype (temp_time); * * Please uncomment and fix documentation if untrue * http://www.gnome.org/projects/evolution/ * developer-doc/libecal/ECalComponent.html * #e-cal-component-get-last-modified */ g_output_stream_write_all ( stream, line->str, line->len, NULL, NULL, &error); /* It's written, so we can free it */ g_string_free (line, TRUE); } g_output_stream_close (stream, NULL, NULL); e_cal_client_free_ecalcomp_slist (objects); } if (stream) g_object_unref (stream); g_object_unref (source_client); g_free (config->delimiter); g_free (config->quote); g_free (config->newline); g_free (config); if (error != NULL) { display_error_message ( gtk_widget_get_toplevel (GTK_WIDGET (selector)), error); g_error_free (error); } }
static void set_attachments (ECalClient *client, ECalComponent *comp, CamelMimeMessage *message) { /* XXX Much of this is copied from CompEditor::get_attachment_list(). * Perhaps it should be split off as a separate utility? */ EAttachmentStore *store; CamelDataWrapper *content; CamelMultipart *multipart; GFile *destination; GList *attachment_list = NULL; GSList *uri_list = NULL; const gchar *comp_uid = NULL; const gchar *local_store; gchar *filename_prefix, *tmp; gint ii, n_parts; struct _att_async_cb_data cb_data; cb_data.flag = e_flag_new (); cb_data.uris = NULL; content = camel_medium_get_content ((CamelMedium *) message); if (!content || !CAMEL_IS_MULTIPART (content)) return; n_parts = camel_multipart_get_number (CAMEL_MULTIPART (content)); if (n_parts < 1) return; e_cal_component_get_uid (comp, &comp_uid); g_return_if_fail (comp_uid != NULL); tmp = g_strdup (comp_uid); e_filename_make_safe (tmp); filename_prefix = g_strconcat (tmp, "-", NULL); g_free (tmp); local_store = e_cal_client_get_local_attachment_store (client); destination = g_file_new_for_path (local_store); /* Create EAttachments from the MIME parts and add them to the * attachment store. */ multipart = CAMEL_MULTIPART (content); store = E_ATTACHMENT_STORE (e_attachment_store_new ()); for (ii = 1; ii < n_parts; ii++) { EAttachment *attachment; CamelMimePart *mime_part; attachment = e_attachment_new (); mime_part = camel_multipart_get_part (multipart, ii); e_attachment_set_mime_part (attachment, mime_part); attachment_list = g_list_append (attachment_list, attachment); } e_flag_clear (cb_data.flag); e_attachment_store_load_async ( store, attachment_list, (GAsyncReadyCallback) attachment_load_finished, &cb_data); /* Loading should be instantaneous since we already have * the full content, but we need to wait for the callback. */ e_flag_wait (cb_data.flag); g_list_foreach (attachment_list, (GFunc) g_object_unref, NULL); g_list_free (attachment_list); cb_data.uris = NULL; e_flag_clear (cb_data.flag); e_attachment_store_save_async ( store, destination, filename_prefix, (GAsyncReadyCallback) attachment_save_finished, &cb_data); g_free (filename_prefix); /* We can't return until we have results. */ e_flag_wait (cb_data.flag); if (cb_data.uris == NULL) { e_flag_free (cb_data.flag); g_warning ("No attachment URIs retrieved."); return; } /* Transfer the URI strings to the GSList. */ for (ii = 0; cb_data.uris[ii] != NULL; ii++) { uri_list = g_slist_prepend (uri_list, cb_data.uris[ii]); cb_data.uris[ii] = NULL; } e_flag_free (cb_data.flag); g_free (cb_data.uris); /* XXX Does this take ownership of the list? */ e_cal_component_set_attachment_list (comp, uri_list); e_attachment_store_remove_all (store); g_object_unref (destination); g_object_unref (store); }
/** * e_intervaltree_insert: * @tree: interval tree * @start: start of the interval * @end: end of the interval * @comp: Component * * Since: 2.32 **/ gboolean e_intervaltree_insert (EIntervalTree *tree, time_t start, time_t end, ECalComponent *comp) { EIntervalTreePrivate *priv; EIntervalNode *y; EIntervalNode *x; EIntervalNode *newNode; const gchar *uid; gchar *rid; g_return_val_if_fail (tree != NULL, FALSE); g_return_val_if_fail (comp != NULL, FALSE); g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE); priv = tree->priv; g_static_rec_mutex_lock (&priv->mutex); e_cal_component_get_uid (comp, &uid); rid = e_cal_component_get_recurid_as_string (comp); e_intervaltree_remove (tree, uid, rid); x = g_new (EIntervalNode, 1); x->min = x->start = start; x->max = x->end = end; x->comp = g_object_ref (comp); binary_tree_insert (tree, x); newNode = x; x->red = TRUE; fixup_min_max_fields (tree, x->parent); while (x->parent->red) { /* use sentinel instead of checking for root */ if (x->parent == x->parent->parent->left) { y = x->parent->parent->right; if (y->red) { x->parent->red = FALSE; y->red = FALSE; x->parent->parent->red = TRUE; x = x->parent->parent; } else { if (x == x->parent->right) { x = x ->parent; left_rotate (tree, x); } x->parent->red = FALSE; x->parent->parent->red = TRUE; right_rotate (tree, x->parent->parent); } } else { /* case for x->parent == x->parent->parent->right */ y = x->parent->parent->left; if (y->red) { x->parent->red = FALSE; y->red = FALSE; x->parent->parent->red = TRUE; x = x->parent->parent; } else { if (x == x->parent->left) { x = x->parent; right_rotate (tree, x); } x->parent->red = FALSE; x->parent->parent->red = TRUE; left_rotate (tree, x->parent->parent); } } } priv->root->left->red = FALSE; g_hash_table_insert (priv->id_node_hash, component_key (uid, rid), newNode); g_free (rid); g_static_rec_mutex_unlock (&priv->mutex); return TRUE; }
/* Stores information about actually shown component and * returns whether component in the preview changed */ static gboolean update_comp_info (ECalComponentPreview *preview, ECalClient *client, ECalComponent *comp, icaltimezone *zone, gboolean use_24_hour_format) { ECalComponentPreviewPrivate *priv; gboolean changed; g_return_val_if_fail (preview != NULL, TRUE); g_return_val_if_fail (E_IS_CAL_COMPONENT_PREVIEW (preview), TRUE); priv = preview->priv; if (!E_IS_CAL_COMPONENT (comp) || !E_IS_CAL_CLIENT (client)) { changed = !priv->cal_uid; clear_comp_info (preview); } else { ESource *source; const gchar *uid; gchar *cal_uid; gchar *comp_uid; struct icaltimetype comp_last_modified, *itm = NULL; gint *sequence = NULL; gint comp_sequence; source = e_client_get_source (E_CLIENT (client)); cal_uid = g_strdup (e_source_get_uid (source)); e_cal_component_get_uid (comp, &uid); comp_uid = g_strdup (uid); e_cal_component_get_last_modified (comp, &itm); if (itm) { comp_last_modified = *itm; e_cal_component_free_icaltimetype (itm); } else comp_last_modified = icaltime_null_time (); e_cal_component_get_sequence (comp, &sequence); if (sequence) { comp_sequence = *sequence; e_cal_component_free_sequence (sequence); } else comp_sequence = 0; changed = !priv->cal_uid || !priv->comp_uid || !cal_uid || !comp_uid || !g_str_equal (priv->cal_uid, cal_uid) || !g_str_equal (priv->comp_uid, comp_uid) || priv->comp_sequence != comp_sequence || icaltime_compare (priv->comp_last_modified, comp_last_modified) != 0; clear_comp_info (preview); priv->cal_uid = cal_uid; priv->comp_uid = comp_uid; priv->comp_sequence = comp_sequence; priv->comp_last_modified = comp_last_modified; priv->comp = g_object_ref (comp); priv->client = g_object_ref (client); priv->timezone = icaltimezone_copy (zone); priv->use_24_hour_format = use_24_hour_format; } return changed; }
/* * converts a ECalComponent object to a EMemoLocalRecord */ static void local_record_from_comp (EMemoLocalRecord *local, ECalComponent *comp, EMemoConduitContext *ctxt) { const char *uid; GSList *d_list = NULL; ECalComponentText *description; ECalComponentClassification classif; LOG (g_message ( "local_record_from_comp\n" )); g_return_if_fail (local != NULL); g_return_if_fail (comp != NULL); local->comp = comp; g_object_ref (comp); LOG(fprintf(stderr, "local_record_from_comp: calling e_cal_component_get_uid\n")); e_cal_component_get_uid (local->comp, &uid); LOG(fprintf(stderr, "local_record_from_comp: got UID - %s, calling e_pilot_map_lookup_pid\n", uid)); local->local.ID = e_pilot_map_lookup_pid (ctxt->map, uid, TRUE); LOG(fprintf(stderr, "local_record_from_comp: local->local.ID == %lu\n", local->local.ID)); compute_status (ctxt, local, uid); LOG(fprintf(stderr, "local_record_from_comp: local->local.attr: %d\n", local->local.attr)); local->memo = g_new0 (struct Memo,1); /* Don't overwrite the category */ if (local->local.ID != 0) { #ifdef PILOT_LINK_0_12 struct Memo memo; pi_buffer_t * record; #else char record[0xffff]; #endif int cat = 0; #ifdef PILOT_LINK_0_12 record = pi_buffer_new(DLP_BUF_SIZE); if(record == NULL){ pi_set_error(ctxt->dbi->pilot_socket, PI_ERR_GENERIC_MEMORY); return; } #endif LOG(fprintf(stderr, "local_record_from_comp: calling dlp_ReadRecordById\n")); if (dlp_ReadRecordById (ctxt->dbi->pilot_socket, ctxt->dbi->db_handle, #ifdef PILOT_LINK_0_12 local->local.ID, record, NULL, NULL, &cat) > 0) { local->local.category = cat; memset (&memo, 0, sizeof (struct Memo)); unpack_Memo (&memo, record, memo_v1); local->memo->text = strdup (memo.text); free_Memo (&memo); } pi_buffer_free (record); #else local->local.ID, &record, NULL, NULL, NULL, &cat) > 0) { local->local.category = cat; } #endif LOG(fprintf(stderr, "local_record_from_comp: done calling dlp_ReadRecordById\n")); } /*Category support*/ e_pilot_local_category_to_remote(&(local->local.category), comp, &(ctxt->ai.category)); /* STOP: don't replace these with g_strdup, since free_Memo uses free to deallocate */ e_cal_component_get_description_list (comp, &d_list); if (d_list) { description = (ECalComponentText *) d_list->data; if (description && description->value){ local->memo->text = e_pilot_utf8_to_pchar (description->value); } else{ local->memo->text = NULL; } } else { local->memo->text = NULL; } e_cal_component_get_classification (comp, &classif); if (classif == E_CAL_COMPONENT_CLASS_PRIVATE) local->local.secret = 1; else local->local.secret = 0; local->local.archived = 0; }
/** * Get common fields from ECalComponentWithTZ and set them in I_common */ void conv_common_e_to_i (const ECalComponentWithTZ *ectz, I_common *i_common) { GSList *descr_list = NULL; const gchar *uid = NULL; const gchar *categories = NULL; struct icaltimetype *lastModifiedDate; struct icaltimetype *createdDate; icalcomponent *icomp = NULL; icalproperty *prop = NULL; i_common->vtimezone = get_vtimezone(ectz); sensitivity_e_to_i(ectz->maincomp, i_common); link_attachments_e_to_i(ectz->maincomp, i_common); /* handle description/body */ e_cal_component_get_description_list ((ECalComponent*) ectz->maincomp, &descr_list); if (descr_list != NULL) { ECalComponentText *text = (ECalComponentText*) descr_list->data; i_common->body = g_string_new (text->value); e_cal_component_free_text_list(descr_list); } /* ******************************************SET UID************************************ */ e_cal_component_get_uid (ectz->maincomp, &uid); if (uid) i_common->uid = g_string_new (uid); /* ******************************************SET CATEGORIES************************************ */ e_cal_component_get_categories (ectz->maincomp, &categories); if (categories) i_common->categories = g_string_new (categories); /* ******************************************SET DATES (CREATION, LASTMODIFICATION, START, END etc.)************************************ */ e_cal_component_get_last_modified (ectz->maincomp, &lastModifiedDate); i_common->last_modified_datetime = new_date_or_datetime(); if (lastModifiedDate) /* log_debug("ICalDate %d-%d-%d-%d-%d-%d", lastModifiedDate->year, lastModifiedDate->month, lastModifiedDate->day, lastModifiedDate->hour, lastModifiedDate->minute, lastModifiedDate->second); */ date_or_datetime_e_to_i (lastModifiedDate, i_common->last_modified_datetime); else { /* Set lastModifiedDate to current system time */ i_common->last_modified_datetime->date_time = g_new0(time_t, 1); *(i_common->last_modified_datetime->date_time) = time(NULL); } g_free(lastModifiedDate); i_common->creation_datetime = new_date_or_datetime(); e_cal_component_get_created (ectz->maincomp, &createdDate); if (createdDate) date_or_datetime_e_to_i (createdDate, i_common->creation_datetime); else { /* Set createdDate to current system time */ i_common->creation_datetime->date_time = g_new0(time_t, 1); *(i_common->creation_datetime->date_time) = time(NULL); } g_free(createdDate); /* ******************************************SET ATTACHMENT LIST******************************************************************************* */ /* iterate over all ical properties */ icomp = e_cal_component_get_icalcomponent (ectz->maincomp); prop = icalcomponent_get_first_property(icomp, ICAL_ANY_PROPERTY); while (prop != NULL) { icalproperty_kind kind = icalproperty_isa(prop); gchar *pname = (gchar*) icalproperty_get_x_name(prop); if (ICAL_ATTACH_PROPERTY == kind) /* found kolab inline or link attachment */ add_e_attachment_parameters(prop, i_common, TRUE); else if (pname && strcmp(pname, ICONTACT_KOLAB_STORE_ATTACHMENT) == 0) /* found hidden kolab attachment */ add_e_attachment_parameters(prop, i_common, FALSE); prop = icalcomponent_get_next_property(icomp, ICAL_ANY_PROPERTY); } i_common->is_html_richtext = FALSE; }
/* Pilot syncing callbacks */ static gint pre_sync (GnomePilotConduit *conduit, GnomePilotDBInfo *dbi, EMemoConduitContext *ctxt) { GnomePilotConduitSyncAbs *abs_conduit; GList *l; int len; unsigned char *buf; char *filename, *change_id; icalcomponent *icalcomp; gint num_records, add_records = 0, mod_records = 0, del_records = 0; #ifdef PILOT_LINK_0_12 pi_buffer_t * buffer; #endif abs_conduit = GNOME_PILOT_CONDUIT_SYNC_ABS (conduit); LOG (g_message ( "---------------------------------------------------------\n" )); LOG (g_message ( "pre_sync: Memo Conduit v.%s", CONDUIT_VERSION )); g_message ("Memo Conduit v.%s", CONDUIT_VERSION); ctxt->dbi = dbi; ctxt->client = NULL; if (start_calendar_server (ctxt) != 0) { WARN(_("Could not start evolution-data-server")); gnome_pilot_conduit_error (conduit, _("Could not start evolution-data-server")); return -1; } /* Get the timezone */ ctxt->timezone = get_default_timezone (); if (ctxt->timezone == NULL) return -1; LOG (g_message ( " Using timezone: %s", icaltimezone_get_tzid (ctxt->timezone) )); /* Set the default timezone on the backend. */ if (ctxt->timezone && !e_cal_set_default_timezone (ctxt->client, ctxt->timezone, NULL)) return -1; /* Get the default component */ if (!e_cal_get_default_object (ctxt->client, &icalcomp, NULL)) return -1; ctxt->default_comp = e_cal_component_new (); if (!e_cal_component_set_icalcomponent (ctxt->default_comp, icalcomp)) { g_object_unref (ctxt->default_comp); icalcomponent_free (icalcomp); return -1; } /* Load the uid <--> pilot id map */ filename = map_name (ctxt); e_pilot_map_read (filename, &ctxt->map); g_free (filename); /* Get the local database */ if (!e_cal_get_object_list_as_comp (ctxt->client, "#t", &ctxt->comps, NULL)) return -1; /* Count and hash the changes */ change_id = g_strdup_printf ("pilot-sync-evolution-memo-%d", ctxt->cfg->pilot_id); if (!e_cal_get_changes (ctxt->client, change_id, &ctxt->changed, NULL)) return -1; ctxt->changed_hash = g_hash_table_new (g_str_hash, g_str_equal); g_free (change_id); for (l = ctxt->changed; l != NULL; l = l->next) { ECalChange *ccc = l->data; const char *uid; e_cal_component_get_uid (ccc->comp, &uid); if (!e_pilot_map_uid_is_archived (ctxt->map, uid)) { g_hash_table_insert (ctxt->changed_hash, g_strdup (uid), ccc); switch (ccc->type) { case E_CAL_CHANGE_ADDED: add_records++; break; case E_CAL_CHANGE_MODIFIED: mod_records++; break; case E_CAL_CHANGE_DELETED: del_records++; break; } } else if (ccc->type == E_CAL_CHANGE_DELETED) { e_pilot_map_remove_by_uid (ctxt->map, uid); } } /* Set the count information */ num_records = g_list_length (ctxt->comps); gnome_pilot_conduit_sync_abs_set_num_local_records(abs_conduit, num_records); gnome_pilot_conduit_sync_abs_set_num_new_local_records (abs_conduit, add_records); gnome_pilot_conduit_sync_abs_set_num_updated_local_records (abs_conduit, mod_records); gnome_pilot_conduit_sync_abs_set_num_deleted_local_records(abs_conduit, del_records); g_message("num_records: %d\nadd_records: %d\nmod_records: %d\ndel_records: %d\n", num_records, add_records, mod_records, del_records); #ifdef PILOT_LINK_0_12 buffer = pi_buffer_new(DLP_BUF_SIZE); if(buffer == NULL){ pi_set_error(dbi->pilot_socket, PI_ERR_GENERIC_MEMORY); return -1; } len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0, DLP_BUF_SIZE, buffer); #else buf = (unsigned char*)g_malloc (0xffff); len = dlp_ReadAppBlock (dbi->pilot_socket, dbi->db_handle, 0, (unsigned char *)buf, 0xffff); #endif if (len < 0) { WARN (_("Could not read pilot's Memo application block")); WARN ("dlp_ReadAppBlock(...) = %d", len); gnome_pilot_conduit_error (conduit, _("Could not read pilot's Memo application block")); return -1; } #ifdef PILOT_LINK_0_12 buf = g_new0 (unsigned char,buffer->used); memcpy(buf, buffer->data, buffer->used); unpack_MemoAppInfo (&(ctxt->ai), buf, len); pi_buffer_free(buffer); #else unpack_MemoAppInfo (&(ctxt->ai), buf, len); #endif g_free (buf); lastDesktopUniqueID = 128; check_for_slow_setting (conduit, ctxt); if (ctxt->cfg->sync_type == GnomePilotConduitSyncTypeCopyToPilot || ctxt->cfg->sync_type == GnomePilotConduitSyncTypeCopyFromPilot) ctxt->map->write_touched_only = TRUE; return 0; }
static gboolean put_component_to_store (ECalBackendHttp *cb, ECalComponent *comp) { time_t time_start, time_end; ECalBackendHttpPrivate *priv; ECalComponent *cache_comp; const gchar *uid; gchar *rid; priv = cb->priv; e_cal_component_get_uid (comp, &uid); rid = e_cal_component_get_recurid_as_string (comp); cache_comp = e_cal_backend_store_get_component (priv->store, uid, rid); g_free (rid); if (cache_comp) { gboolean changed = TRUE; struct icaltimetype stamp1, stamp2; stamp1 = icaltime_null_time (); stamp2 = icaltime_null_time (); e_cal_component_get_dtstamp (comp, &stamp1); e_cal_component_get_dtstamp (cache_comp, &stamp2); changed = (icaltime_is_null_time (stamp1) && !icaltime_is_null_time (stamp2)) || (!icaltime_is_null_time (stamp1) && icaltime_is_null_time (stamp2)) || (icaltime_compare (stamp1, stamp2) != 0); if (!changed) { struct icaltimetype *last_modified1 = NULL, *last_modified2 = NULL; e_cal_component_get_last_modified (comp, &last_modified1); e_cal_component_get_last_modified (cache_comp, &last_modified2); changed = (last_modified1 != NULL && last_modified2 == NULL) || (last_modified1 == NULL && last_modified2 != NULL) || (last_modified1 != NULL && last_modified2 != NULL && icaltime_compare (*last_modified1, *last_modified2) != 0); if (last_modified1) e_cal_component_free_icaltimetype (last_modified1); if (last_modified2) e_cal_component_free_icaltimetype (last_modified2); if (!changed) { gint *sequence1 = NULL, *sequence2 = NULL; e_cal_component_get_sequence (comp, &sequence1); e_cal_component_get_sequence (cache_comp, &sequence2); changed = (sequence1 != NULL && sequence2 == NULL) || (sequence1 == NULL && sequence2 != NULL) || (sequence1 != NULL && sequence2 != NULL && *sequence1 != *sequence2); if (sequence1) e_cal_component_free_sequence (sequence1); if (sequence2) e_cal_component_free_sequence (sequence2); } } g_object_unref (cache_comp); if (!changed) return FALSE; } e_cal_util_get_component_occur_times ( comp, &time_start, &time_end, resolve_tzid, cb, icaltimezone_get_utc_timezone (), e_cal_backend_get_kind (E_CAL_BACKEND (cb))); e_cal_backend_store_put_component_with_time_range (priv->store, comp, time_start, time_end); return TRUE; }
void dates_delete_cb (GtkWidget *source, DatesData *d) { ECalComponentText summary; GtkWidget *widget; const char *orig_value; char *value; #ifdef WITH_HILDON gchar *tmp; #endif e_cal_component_get_summary (d->comp, &summary); widget = d->details_dialog; if (GTK_WIDGET_VISIBLE (widget)) orig_value = gtk_entry_get_text (GTK_ENTRY (d->details_summary_entry)); else if (summary.value) orig_value = summary.value; else if (summary.altrep) orig_value = summary.altrep; else { g_warning ("Deleting event with no summary"); orig_value = _("Unknown event"); } value = str_truncate (orig_value, 50); #ifdef WITH_HILDON tmp = g_strdup_printf(_("Are you sure you want to delete event '%s'?"), value); widget = hildon_note_new_confirmation_add_buttons( GTK_WINDOW (d->main_window), tmp, _("Keep event"), GTK_RESPONSE_NO, _("Delete event"), GTK_RESPONSE_YES, NULL); g_free(tmp); #else widget = gtk_message_dialog_new ( GTK_WINDOW (d->main_window), GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, _("Are you sure you want to delete event '%s'?"), value); gtk_dialog_add_buttons (GTK_DIALOG (widget), _("Keep event"), GTK_RESPONSE_NO, _("Delete event"), GTK_RESPONSE_YES, NULL); #endif if (gtk_dialog_run (GTK_DIALOG (widget)) == GTK_RESPONSE_YES) { /* Reset event type, in case this was a new event */ d->event_type = NORMAL; if (d->waiting == NONE) { const char *uid = NULL; e_cal_component_get_uid (d->comp, &uid); e_cal_remove_object (d->cal, uid, NULL); /* Hide the details dialog, in case we deleted * from there. */ dates_platform_details_dlg (d, FALSE); } else { d->widgets = contacts_set_widgets_desensitive ( d->details_dialog); d->waiting = PENDING_DELETE; } } gtk_widget_destroy (widget); g_free (value); }