static ECalComponent* create_test_component (time_t start, time_t end) { ECalComponent *comp = e_cal_component_new (); ECalComponentText summary; struct icaltimetype current; e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT); /* ECalComponentDateTime dtstart, dtend; struct icaltimetype time_start, time_end; time_start = icaltime_from_timet (start, 0); dtstart.value = icaltime_from_timet (start, 0); dtstart.zone = icaltimezone_get_utc_timezone (); dtend.value = icaltime_from_timet (end, 0); dtend.value = icaltimezone_get_utc_timezone (); e_cal_component_set_dtstart (comp, &dtstart); e_cal_component_set_dtend (comp, &dtend); */ summary.value = g_strdup_printf ("%ld - %ld", start, end); summary.altrep = NULL; e_cal_component_set_summary (comp, &summary); g_free ((gchar *) summary.value); current = icaltime_from_timet (time (NULL), 0); e_cal_component_set_created (comp, ¤t); e_cal_component_set_last_modified (comp, ¤t); return comp; }
void evo_cal_component_set_summary(ECalComponent *obj, const char *summary) { ECalComponentText *txt = NULL; txt = g_malloc0(sizeof (ECalComponentText)); txt->value = g_strdup(summary); e_cal_component_set_summary(obj, txt); }
static void dates_save_changes (DatesData *d) { ECalComponentText text; const gchar *old_location = NULL; gchar *desc; GSList *desc_list; GtkTextIter start, middle, end; GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW ( d->details_textview)); GtkWidget *widget; ECalComponentText summary, new_summary; gtk_text_buffer_get_start_iter (buffer, &start); e_cal_component_get_location (d->comp, &old_location); /* If there was a location field set, try not to overwrite it */ if (old_location) { gtk_text_buffer_get_iter_at_line (buffer, &middle, 1); desc = gtk_text_buffer_get_text ( buffer, &start, &middle, FALSE); if (desc) { /* Strip the trailing new-line, if necessary */ gchar *strip; if ((strip = g_utf8_strchr (desc, -1, '\n'))) *strip = '\0'; e_cal_component_set_location (d->comp, desc); g_free (desc); } start = middle; } /* Set the rest of the description */ gtk_text_buffer_get_end_iter (buffer, &end); desc = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); text.value = desc ? desc : ""; text.altrep = NULL; desc_list = g_slist_prepend (NULL, &text); e_cal_component_set_description_list (d->comp, desc_list); g_free (desc); g_slist_free (desc_list); widget = d->details_summary_entry; e_cal_component_get_summary (d->comp, &summary); new_summary.altrep = summary.altrep; new_summary.value = g_strdup (gtk_entry_get_text (GTK_ENTRY (widget))); e_cal_component_set_summary (d->comp, &new_summary); dates_commit_event_cb (NULL, d, CALOBJ_MOD_ALL); }
static gboolean do_mail_to_event (AsyncData *data) { EClient *client; CamelFolder *folder = data->folder; GPtrArray *uids = data->uids; GError *error = NULL; client = e_client_cache_get_client_sync (data->client_cache, data->source, data->extension_name, 30, NULL, &error); /* Sanity check. */ g_return_val_if_fail ( ((client != NULL) && (error == NULL)) || ((client == NULL) && (error != NULL)), TRUE); if (error != NULL) { report_error_idle (_("Cannot open calendar. %s"), error->message); } else if (e_client_is_readonly (E_CLIENT (client))) { switch (data->source_type) { case E_CAL_CLIENT_SOURCE_TYPE_EVENTS: report_error_idle (_("Selected calendar is read only, thus cannot create event there. Select other calendar, please."), NULL); break; case E_CAL_CLIENT_SOURCE_TYPE_TASKS: report_error_idle (_("Selected task list is read only, thus cannot create task there. Select other task list, please."), NULL); break; case E_CAL_CLIENT_SOURCE_TYPE_MEMOS: report_error_idle (_("Selected memo list is read only, thus cannot create memo there. Select other memo list, please."), NULL); break; default: g_warn_if_reached (); break; } } else { gint i; ECalComponentDateTime dt, dt2; struct icaltimetype tt, tt2; struct _manage_comp *oldmc = NULL; #define cache_backend_prop(prop) { \ gchar *val = NULL; \ e_client_get_backend_property_sync (E_CLIENT (client), prop, &val, NULL, NULL); \ g_free (val); \ } /* precache backend properties, thus editor have them ready when needed */ cache_backend_prop (CAL_BACKEND_PROPERTY_CAL_EMAIL_ADDRESS); cache_backend_prop (CAL_BACKEND_PROPERTY_ALARM_EMAIL_ADDRESS); cache_backend_prop (CAL_BACKEND_PROPERTY_DEFAULT_OBJECT); e_client_get_capabilities (E_CLIENT (client)); #undef cache_backend_prop /* set start day of the event as today, without time - easier than looking for a calendar's time zone */ tt = icaltime_today (); dt.value = &tt; dt.tzid = NULL; tt2 = tt; icaltime_adjust (&tt2, 1, 0, 0, 0); dt2.value = &tt2; dt2.tzid = NULL; for (i = 0; i < (uids ? uids->len : 0); i++) { CamelMimeMessage *message; ECalComponent *comp; ECalComponentText text; icalproperty *icalprop; icalcomponent *icalcomp; struct _manage_comp *mc; /* retrieve the message from the CamelFolder */ /* FIXME Not passing a GCancellable or GError. */ message = camel_folder_get_message_sync ( folder, g_ptr_array_index (uids, i), NULL, NULL); if (!message) { continue; } comp = e_cal_component_new (); switch (data->source_type) { case E_CAL_CLIENT_SOURCE_TYPE_EVENTS: e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT); break; case E_CAL_CLIENT_SOURCE_TYPE_TASKS: e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_TODO); break; case E_CAL_CLIENT_SOURCE_TYPE_MEMOS: e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_JOURNAL); break; default: g_warn_if_reached (); break; } e_cal_component_set_uid (comp, camel_mime_message_get_message_id (message)); e_cal_component_set_dtstart (comp, &dt); if (data->source_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS) { /* make it an all-day event */ e_cal_component_set_dtend (comp, &dt2); } /* set the summary */ text.value = camel_mime_message_get_subject (message); text.altrep = NULL; e_cal_component_set_summary (comp, &text); /* set all fields */ if (data->selected_text) { GSList sl; text.value = data->selected_text; text.altrep = NULL; sl.next = NULL; sl.data = &text; e_cal_component_set_description_list (comp, &sl); } else set_description (comp, message); if (data->with_attendees) { gchar *organizer; /* set actual user as organizer, to be able to change event's properties */ organizer = set_organizer (comp, data->folder); set_attendees (comp, message, organizer); g_free (organizer); } /* set attachment files */ set_attachments (E_CAL_CLIENT (client), comp, message); /* priority */ set_priority (comp, CAMEL_MIME_PART (message)); /* no need to increment a sequence number, this is a new component */ e_cal_component_abort_sequence (comp); icalcomp = e_cal_component_get_icalcomponent (comp); icalprop = icalproperty_new_x ("1"); icalproperty_set_x_name (icalprop, "X-EVOLUTION-MOVE-CALENDAR"); icalcomponent_add_property (icalcomp, icalprop); mc = g_new0 (struct _manage_comp, 1); mc->client = g_object_ref (client); mc->comp = g_object_ref (comp); g_mutex_init (&mc->mutex); g_cond_init (&mc->cond); mc->mails_count = uids->len; mc->mails_done = i + 1; /* Current task */ mc->editor_title = NULL; mc->can_continue = TRUE; if (oldmc) { /* Wait for user to quit the editor created in previous iteration * before displaying next one */ gboolean can_continue; g_mutex_lock (&oldmc->mutex); g_cond_wait (&oldmc->cond, &oldmc->mutex); g_mutex_unlock (&oldmc->mutex); can_continue = oldmc->can_continue; free_manage_comp_struct (oldmc); oldmc = NULL; if (!can_continue) break; } e_cal_client_get_object_sync ( E_CAL_CLIENT (client), icalcomponent_get_uid (icalcomp), NULL, &mc->stored_comp, NULL, NULL); /* Prioritize ahead of GTK+ redraws. */ g_idle_add_full ( G_PRIORITY_HIGH_IDLE, (GSourceFunc) do_manage_comp_idle, mc, NULL); oldmc = mc; g_object_unref (comp); g_object_unref (message); } /* Wait for the last editor and then clean up */ if (oldmc) { g_mutex_lock (&oldmc->mutex); g_cond_wait (&oldmc->cond, &oldmc->mutex); g_mutex_unlock (&oldmc->mutex); free_manage_comp_struct (oldmc); } } /* free memory */ if (client != NULL) g_object_unref (client); g_ptr_array_unref (uids); g_object_unref (folder); g_object_unref (data->client_cache); g_object_unref (data->source); g_free (data->selected_text); g_free (data); data = NULL; if (error != NULL) g_error_free (error); return TRUE; }
/** * build_component_from_details: * @summary: * @initial_date: * @final_date: * * Create a component with the provided details * * Returns: (Transfer full): an {@link ECalComponent} object **/ ECalComponent* build_component_from_details (const gchar *summary, GDateTime *initial_date, GDateTime *final_date) { ECalComponent *event; ECalComponentDateTime dt; ECalComponentText summ; icaltimezone *zone; gboolean all_day; event = e_cal_component_new (); e_cal_component_set_new_vtype (event, E_CAL_COMPONENT_EVENT); /* * Check if the event is all day. Notice that it can be all day even * without the final date. */ all_day = datetime_is_date (initial_date) && (final_date ? datetime_is_date (final_date) : TRUE); /* * When the event is all day, we consider UTC timezone by default. Otherwise, * we always use the system timezone to create new events */ if (all_day) { zone = icaltimezone_get_utc_timezone (); } else { gchar *system_tz = e_cal_system_timezone_get_location (); zone = icaltimezone_get_builtin_timezone (system_tz); g_free (system_tz); } /* Start date */ dt.value = datetime_to_icaltime (initial_date); icaltime_set_timezone (dt.value, zone); dt.value->is_date = all_day; dt.tzid = icaltimezone_get_tzid (zone); e_cal_component_set_dtstart (event, &dt); g_free (dt.value); /* End date */ if (!final_date) final_date = g_date_time_add_days (initial_date, 1); dt.value = datetime_to_icaltime (final_date); icaltime_set_timezone (dt.value, zone); dt.value->is_date = all_day; dt.tzid = icaltimezone_get_tzid (zone); e_cal_component_set_dtend (event, &dt); g_free (dt.value); /* Summary */ summ.altrep = NULL; summ.value = summary; e_cal_component_set_summary (event, &summ); e_cal_component_commit_sequence (event); return event; }
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; }