static gint
sort_event_data (gconstpointer a,
                 gconstpointer b,
                 gpointer user_data)
{
  ECalComponent *comp1, *comp2;
  ECalComponentDateTime date1, date2;
  gint result;


  comp1 = ((GcalEventData*) a)->event_component;
  comp2 = ((GcalEventData*) b)->event_component;

  e_cal_component_get_dtstart (comp1, &date1);
  e_cal_component_get_dtstart (comp2, &date2);

  if (date1.tzid != NULL)
    date1.value->zone = icaltimezone_get_builtin_timezone_from_tzid (date1.tzid);
  if (date2.tzid != NULL)
    date2.value->zone = icaltimezone_get_builtin_timezone_from_tzid (date2.tzid);
  result = icaltime_compare_with_current (date1.value, date2.value, user_data);

  e_cal_component_free_datetime (&date1);
  e_cal_component_free_datetime (&date2);

  return result;
}
Esempio n. 2
0
static void
add_timezone_cb (icalparameter *param,
                 gpointer data)
{
	icaltimezone *tz;
	const gchar *tzid;
	icalcomponent *vtz_comp;
	ForeachTzidData *f_data = (ForeachTzidData *) data;

	tzid = icalparameter_get_tzid (param);
	if (!tzid)
		return;

	tz = icalcomponent_get_timezone (f_data->vcal_comp, tzid);
	if (tz)
		return;

	tz = icalcomponent_get_timezone (f_data->icalcomp, tzid);
	if (!tz) {
		tz = icaltimezone_get_builtin_timezone_from_tzid (tzid);
		if (!tz)
			return;
	}

	vtz_comp = icaltimezone_get_component (tz);
	if (!vtz_comp)
		return;

	icalcomponent_add_component (
		f_data->vcal_comp,
		icalcomponent_new_clone (vtz_comp));
}
static time_t
get_time_from_property (icalcomponent         *ical,
                        icalproperty_kind      prop_kind,
                        struct icaltimetype (* get_prop_func) (const icalproperty *prop),
                        icaltimezone          *default_zone)
{
  icalproperty        *prop;
  struct icaltimetype  ical_time;
  icalparameter       *param;
  icaltimezone        *timezone = NULL;

  prop = icalcomponent_get_first_property (ical, prop_kind);
  if (!prop)
    return 0;

  ical_time = get_prop_func (prop);

  param = icalproperty_get_first_parameter (prop, ICAL_TZID_PARAMETER);
  if (param)
    timezone = icaltimezone_get_builtin_timezone_from_tzid (icalparameter_get_tzid (param));
  else if (icaltime_is_utc (ical_time))
    timezone = icaltimezone_get_utc_timezone ();
  else
    timezone = default_zone;

  return icaltime_as_timet_with_zone (ical_time, timezone);
}
static gboolean
activate_result_cb (GcalShellSearchProvider  *search_provider,
                    GDBusMethodInvocation    *invocation,
                    gchar                    *result,
                    gchar                   **terms,
                    guint32                   timestamp,
                    GcalShellSearchProvider2 *skel)
{
  GcalShellSearchProviderPrivate *priv;
  GApplication *application;
  GcalEventData *data;
  ECalComponentDateTime dtstart;

  priv = search_provider->priv;
  application = g_application_get_default ();

  data = gcal_manager_get_event_from_shell_search (priv->manager, result);
  e_cal_component_get_dtstart (data->event_component, &dtstart);
  if (dtstart.tzid != NULL)
    dtstart.value->zone = icaltimezone_get_builtin_timezone_from_tzid (dtstart.tzid);

  gcal_application_set_uuid (GCAL_APPLICATION (application), result);
  gcal_application_set_initial_date (GCAL_APPLICATION (application), dtstart.value);
  e_cal_component_free_datetime (&dtstart);

  g_application_activate (application);

  g_object_unref (data->event_component);
  g_free (data);
  return TRUE;
}
Esempio n. 5
0
static gchar *
format_dt (const ECalComponentDateTime *dt,
           GHashTable *timezones,
           icaltimezone *users_zone)
{
	struct tm tm;

	g_return_val_if_fail (dt != NULL, NULL);
	g_return_val_if_fail (timezones != NULL, NULL);

	if (!dt->value)
		return NULL;

	dt->value->zone = NULL;
	if (dt->tzid) {
		dt->value->zone = g_hash_table_lookup (timezones, dt->tzid);
		if (!dt->value->zone)
			dt->value->zone = icaltimezone_get_builtin_timezone_from_tzid (dt->tzid);

		if (!dt->value->zone && g_ascii_strcasecmp (dt->tzid, "UTC") == 0)
			dt->value->zone = icaltimezone_get_utc_timezone ();
	}

	if (dt->value->zone)
		tm = icaltimetype_to_tm_with_zone (dt->value, (icaltimezone *) dt->value->zone, users_zone);
	else
		tm = icaltimetype_to_tm (dt->value);

	return e_datetime_format_format_tm ("calendar", "table", dt->value->is_date ? DTFormatKindDate : DTFormatKindDateTime, &tm);
}
/* The default implementation is looking for timezone in the ical's builtin timezones,
 * and if that fails, then it tries to extract the location from the tzid and get the
 * timezone based on it. If even that fails, then it's returning UTC timezone.
 * That means, that any object deriving from ECalBackendSync is supposed to implement
 * this function for checking for a timezone in its own timezone cache, and if that
 * fails, then call parent's object internal_get_timezone, and that's all.
 */
static icaltimezone *
cal_backend_internal_get_timezone (ECalBackend *backend,
                                   const gchar *tzid)
{
	icaltimezone *zone = NULL;

	if (!tzid || !*tzid)
		return NULL;

	zone = icaltimezone_get_builtin_timezone_from_tzid (tzid);

	if (!zone) {
		const gchar *s, *slash1 = NULL, *slash2 = NULL;

		/* get builtin by a location, if any */
		for (s = tzid; *s; s++) {
			if (*s == '/') {
				slash1 = slash2;
				slash2 = s;
			}
		}

		if (slash1)
			zone = icaltimezone_get_builtin_timezone (slash1 + 1);
		else if (slash2)
			zone = icaltimezone_get_builtin_timezone (tzid);
	}

	if (!zone)
		zone = icaltimezone_get_utc_timezone ();

	return zone;
}
static icaltimezone *
resolve_timezone_id (const char *tzid,
                     ECalClient *source)
{
  icaltimezone *retval;

  retval = icaltimezone_get_builtin_timezone_from_tzid (tzid);
  if (!retval)
    {
      e_cal_client_get_timezone_sync (source, tzid, &retval, NULL, NULL);
    }

  return retval;
}
static void addsystemtz(gpointer key,
                        gpointer value,
                        gpointer user_data)
{
    const char *tzid = key;
    icalcomponent *comp = user_data;
    icaltimezone *zone;

    zone = icaltimezone_get_builtin_timezone_from_tzid(tzid);
    if (zone) {
        icalcomponent_add_component(comp,
                                    icalcomponent_new_clone(icaltimezone_get_component(zone)));
    }
}
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;
}
Esempio n. 10
0
static void
dates_fill_details_dialog (DatesView *view, DatesData *d)
{
    const gchar *location = NULL;
    gchar *string = NULL;
    GSList *text_list;
    ECalComponentDateTime time;
    struct tm timem;
    gchar time_text[256];
    GtkTextBuffer *buffer;
    ECalComponentText summary;
    GtkWidget *widget;
    icaltimezone* from_zone; 

    /* Set summary entry */
    e_cal_component_get_summary (d->comp, &summary);
    widget = d->details_summary_entry;
    if (summary.value)
	gtk_entry_set_text (GTK_ENTRY (widget), summary.value);
    else if (summary.altrep)
	gtk_entry_set_text (GTK_ENTRY (widget), summary.altrep);
    else
	gtk_entry_set_text (GTK_ENTRY (widget), "");
	
    /* Set event description textview */
    /* NOTE: Docs say that only journal entries can have more than one
     * description, so just use text_list->data
     */
    e_cal_component_get_location (d->comp, &location);
    e_cal_component_get_description_list (d->comp, &text_list);
    buffer = gtk_text_view_get_buffer (
	GTK_TEXT_VIEW (d->details_textview));
    /* NOTE: If there's a location property, we move it to the description
     */
    if (location)
	string = g_strconcat (location, "\n", NULL);
    gtk_text_buffer_set_text (buffer, string ? string : "", -1);
    g_free (string);
    if (text_list) {
	ECalComponentText *desc = text_list->data;
	if (desc->value) {
	    GtkTextIter iter;
	    gtk_text_buffer_get_end_iter (buffer, &iter);
	    gtk_text_buffer_insert (buffer, &iter, desc->value, -1);
	}
	e_cal_component_free_text_list (text_list);
    }
	
    /* Set time buttons and dialog */
    e_cal_component_get_dtstart (d->comp, &time);
    from_zone = icaltimezone_get_builtin_timezone_from_tzid (time.tzid);
    timem = icaltimetype_to_tm_with_zone (time.value, from_zone, dates_view_get_zone(view));
    strftime (time_text, 256, TIME_MARKUP, &timem);
    gtk_label_set_markup (GTK_LABEL (d->details_start_label), time_text);
    e_cal_component_free_datetime (&time);

    e_cal_component_get_dtend (d->comp, &time);
    from_zone = icaltimezone_get_builtin_timezone_from_tzid (time.tzid);
    timem = icaltimetype_to_tm_with_zone (time.value, from_zone, dates_view_get_zone(view));
    strftime (time_text, 256, TIME_MARKUP, &timem);
    gtk_label_set_markup (GTK_LABEL (d->details_end_label),
			  time_text);
    e_cal_component_free_datetime (&time);
}