static icalcomponent_kind get_menu_type (void *data) { CamelMimePart *part; char *path; icalcomponent *icalcomp, *subcomp; icalcomponent_kind kind; EPopupTarget *target = (EPopupTarget *) data; if (target->type == EM_POPUP_TARGET_ATTACHMENTS) part = ((EAttachment *) ((EMPopupTargetAttachments *) target)->attachments->data)->body; else part = ((EMPopupTargetPart *) target)->part; path = em_utils_temp_save_part (NULL, part, FALSE); icalcomp = get_icalcomponent_from_file (path); subcomp = icalcomponent_get_inner(icalcomp); kind = icalcomponent_isa (subcomp); if (kind == ICAL_VTODO_COMPONENT ) { return ICAL_VTODO_COMPONENT; } else if ( kind == ICAL_VEVENT_COMPONENT) { return ICAL_VEVENT_COMPONENT; } return ICAL_NO_COMPONENT; }
icalspanlist *icalspanlist_from_vfreebusy(icalcomponent *comp) { icalcomponent *inner; icalproperty *prop; icalspanlist *sl; icalerror_check_arg_rz((comp != NULL), "comp"); inner = icalcomponent_get_inner(comp); if (!inner) return NULL; if ((sl = (icalspanlist *) malloc(sizeof(icalspanlist))) == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } sl->spans = pvl_newlist(); /* cycle through each FREEBUSY property, adding to the spanlist */ for (prop = icalcomponent_get_first_property(inner, ICAL_FREEBUSY_PROPERTY); prop != NULL; prop = icalcomponent_get_next_property(inner, ICAL_FREEBUSY_PROPERTY)) { icaltime_span *s = (icaltime_span *) malloc(sizeof(icaltime_span)); icalparameter *param; struct icalperiodtype period; icalparameter_fbtype fbtype; if (s == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); icalspanlist_free(sl); return 0; } param = icalproperty_get_first_parameter(prop, ICAL_FBTYPE_PARAMETER); fbtype = (param) ? icalparameter_get_fbtype(param) : ICAL_FBTYPE_BUSY; switch (fbtype) { case ICAL_FBTYPE_FREE: case ICAL_FBTYPE_NONE: case ICAL_FBTYPE_X: s->is_busy = 1; break; default: s->is_busy = 0; } period = icalproperty_get_freebusy(prop); s->start = icaltime_as_timet_with_zone(period.start, icaltimezone_get_utc_timezone()); s->end = icaltime_as_timet_with_zone(period.end, icaltimezone_get_utc_timezone()); ; pvl_insert_ordered(sl->spans, compare_span, (void *)s); } /** @todo calculate start/end limits.. fill in holes? **/ return sl; }
static struct icaltimetype get_last_modified (icalcomponent *component) { icalcomponent *inner = icalcomponent_get_inner (component); icalproperty *prop; prop = icalcomponent_get_first_property (inner, ICAL_LASTMODIFIED_PROPERTY); if (prop == 0) { return icaltime_null_time (); } return icalproperty_get_lastmodified (prop); }
icalspanlist* icalspanlist_new(icalset *set, struct icaltimetype start, struct icaltimetype end) { struct icaltime_span range; pvl_elem itr; icalcomponent *c,*inner; icalcomponent_kind kind, inner_kind; icalspanlist *sl; struct icaltime_span *freetime; if ( ( sl = (struct icalspanlist_impl*) malloc(sizeof(struct icalspanlist_impl))) == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } sl->spans = pvl_newlist(); sl->start = start; sl->end = end; range.start = icaltime_as_timet(start); range.end = icaltime_as_timet(end); /* Get a list of spans of busy time from the events in the set and order the spans based on the start time */ for(c = icalset_get_first_component(set); c != 0; c = icalset_get_next_component(set)){ kind = icalcomponent_isa(c); inner = icalcomponent_get_inner(c); if(!inner){ continue; } inner_kind = icalcomponent_isa(inner); if( kind != ICAL_VEVENT_COMPONENT && inner_kind != ICAL_VEVENT_COMPONENT){ continue; } icalerror_clear_errno(); icalcomponent_foreach_recurrence(c, start, end, icalspanlist_new_callback, (void*)sl); } /* Now Fill in the free time spans. loop through the spans. if the start of the range is not within the span, create a free entry that runs from the start of the range to the start of the span. */ for( itr = pvl_head(sl->spans); itr != 0; itr = pvl_next(itr)) { struct icaltime_span *s = (struct icaltime_span*)pvl_data(itr); if ((freetime=(struct icaltime_span *) malloc(sizeof(struct icaltime_span))) == 0){ icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } if(range.start < s->start){ freetime->start = range.start; freetime->end = s->start; freetime->is_busy = 0; pvl_insert_ordered(sl->spans,compare_span,(void*)freetime); } else { free(freetime); } range.start = s->end; } /* If the end of the range is null, then assume that everything after the last item in the calendar is open and add a span that indicates this */ if( icaltime_is_null_time(end)){ struct icaltime_span* last_span; last_span = (struct icaltime_span*)pvl_data(pvl_tail(sl->spans)); if (last_span != 0){ if ((freetime=(struct icaltime_span *) malloc(sizeof(struct icaltime_span))) == 0){ icalerror_set_errno(ICAL_NEWFAILED_ERROR); return 0; } freetime->is_busy = 0; freetime->start = last_span->end; freetime->end = freetime->start; pvl_insert_ordered(sl->spans,compare_span,(void*)freetime); } } return sl; }
static void init_widgets(char *path) { GtkWidget *vbox, *hbox, *dialog; icalcomponent_kind kind; icalcomponent *subcomp; GtkWidget *selector, *label; ESourceList *source_list; ESource *primary; GtkWidget *scrolled; ICalImporterData *icidata = g_malloc0(sizeof(*icidata)); GtkWidget *icon, *button; char *label_str = NULL; char *markup; g_return_if_fail ( path != NULL); dialog = gtk_dialog_new_with_buttons (_("Import ICS"), NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); icidata->window = dialog; g_signal_connect (dialog, "response", G_CALLBACK (dialog_response_cb), icidata); vbox = GTK_DIALOG(dialog)->vbox; hbox = gtk_hbox_new (FALSE, FALSE); label = gtk_label_new(NULL); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 6); icidata->icalcomp = get_icalcomponent_from_file (path); subcomp = icalcomponent_get_inner(icidata->icalcomp); kind = icalcomponent_isa (subcomp); if (kind == ICAL_VTODO_COMPONENT ) { e_cal_get_sources (&source_list, E_CAL_SOURCE_TYPE_TODO, NULL); label_str = _("Select Task List"); icidata->source_type = E_CAL_SOURCE_TYPE_TODO; } else if ( kind == ICAL_VEVENT_COMPONENT) { e_cal_get_sources (&source_list, E_CAL_SOURCE_TYPE_EVENT, NULL); label_str = _("Select Calendar"); icidata->source_type = E_CAL_SOURCE_TYPE_EVENT; } markup = g_markup_printf_escaped ("<b>%s</b>", label_str); gtk_label_set_markup (GTK_LABEL (label), markup); g_free (markup); hbox = gtk_hbox_new (FALSE, FALSE); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 6); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 6); selector = e_source_selector_new (source_list); e_source_selector_show_selection (E_SOURCE_SELECTOR (selector), FALSE); scrolled = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add((GtkContainer *)scrolled, selector); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); hbox = gtk_hbox_new (FALSE, FALSE); gtk_box_pack_start (GTK_BOX (hbox), scrolled, TRUE, TRUE, 6); gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 6); icidata->selector = selector; /* FIXME What if no sources? */ primary = e_source_list_peek_source_any (source_list); e_source_selector_set_primary_selection (E_SOURCE_SELECTOR (selector), primary); g_object_unref (source_list); hbox = gtk_hbox_new (FALSE, FALSE); icon = e_icon_factory_get_image ("stock_mail-import", E_ICON_SIZE_MENU); gtk_box_pack_start (GTK_BOX(hbox), icon, FALSE, FALSE, 6); label = gtk_label_new_with_mnemonic (_("_Import")); gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6); gtk_widget_show(label); button = gtk_button_new (); gtk_container_add (GTK_CONTAINER (button), hbox); gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, GTK_RESPONSE_OK); gtk_widget_grab_focus (button); gtk_window_set_default_size (GTK_WINDOW (dialog), 210,340); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); }