658
populate_appointment_instances (ECalComponent * comp,
635
populate_appointment_instances (ECalClient * client,
663
g_debug("Appending item %p", comp);
665
ECalComponentVType vtype = e_cal_component_get_vtype (comp);
666
if (vtype != E_CAL_COMPONENT_EVENT && vtype != E_CAL_COMPONENT_TODO) return FALSE;
668
icalproperty_status status;
669
e_cal_component_get_status (comp, &status);
670
if (status == ICAL_STATUS_COMPLETED || status == ICAL_STATUS_CANCELLED) return FALSE;
672
struct comp_instance *ci = comp_instance_new (comp, start, end, E_SOURCE(data));
673
comp_instances = g_list_append (comp_instances, ci);
640
GSList *ecalcomps, *comp_item;
642
if (e_cal_client_get_object_list_as_comps_sync (client,
647
for (comp_item = ecalcomps; comp_item; comp_item = g_slist_next(comp_item)) {
648
ECalComponent *comp = comp_item->data;
650
g_debug("Appending item %p", e_cal_component_get_as_string(comp));
652
ECalComponentVType vtype = e_cal_component_get_vtype (comp);
653
if (vtype != E_CAL_COMPONENT_EVENT && vtype != E_CAL_COMPONENT_TODO) return FALSE;
655
icalproperty_status status;
656
e_cal_component_get_status (comp, &status);
657
if (status == ICAL_STATUS_COMPLETED || status == ICAL_STATUS_CANCELLED) return FALSE;
661
ECalComponentDateTime datetime;
662
icaltimezone *appointment_zone = NULL;
663
icaltimezone *current_zone = NULL;
665
if (vtype == E_CAL_COMPONENT_EVENT)
666
e_cal_component_get_dtstart (comp, &datetime);
668
e_cal_component_get_due (comp, &datetime);
670
appointment_zone = icaltimezone_get_builtin_timezone_from_tzid(datetime.tzid);
671
current_zone = icaltimezone_get_builtin_timezone_from_tzid(current_timezone);
672
if (!appointment_zone || datetime.value->is_date) { // If it's today put in the current timezone?
673
appointment_zone = current_zone;
676
struct comp_instance *ci = comp_instance_new (comp, start, end, E_SOURCE(data));
677
comp_instances = g_list_append (comp_instances, ci);
677
684
/* Populate the menu with todays, next 5 appointments.
736
743
highlightdays = highlightdays + 7; // Minimum of 7 days ahead
737
744
t2 = t1 + (time_t) (highlightdays * 24 * 60 * 60);
739
if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_EVENT, &gerror)) {
740
g_debug("Failed to get ecal sources\n");
741
g_clear_error (&gerror);
745
746
// clear any previous comp_instances
746
747
g_list_free_full (comp_instances, (GDestroyNotify)comp_instance_free);
747
748
comp_instances = NULL;
749
GSList *cal_list = gconf_client_get_list(gconf, "/apps/evolution/calendar/display/selected_calendars", GCONF_VALUE_STRING, &gerror);
751
g_debug("Failed to get evolution preference for enabled calendars");
752
g_clear_error (&gerror);
750
src_registry = e_source_registry_new_sync (NULL, &gerror);
752
g_debug("Failed to get access to source registry: %s\n", gerror->message);
756
sources = e_source_registry_list_sources(src_registry, E_SOURCE_EXTENSION_CALENDAR);
756
758
// Generate instances for all sources
757
for (g = e_source_list_peek_groups (sources); g; g = g->next) {
758
ESourceGroup *group = E_SOURCE_GROUP (g->data);
761
for (s = e_source_group_peek_sources (group); s; s = s->next) {
762
ESource *source = E_SOURCE (s->data);
763
g_signal_connect (G_OBJECT(source), "changed", G_CALLBACK (update_appointment_menu_items), NULL);
764
ECal *ecal = e_cal_new(source, E_CAL_SOURCE_TYPE_EVENT);
765
e_cal_set_auth_func (ecal, (ECalAuthFunc) auth_func, NULL);
767
icaltimezone* current_zone = icaltimezone_get_builtin_timezone(current_timezone);
769
// current_timezone may be a TZID?
770
current_zone = icaltimezone_get_builtin_timezone_from_tzid(current_timezone);
772
if (current_zone && !e_cal_set_default_timezone(ecal, current_zone, &gerror)) {
773
g_debug("Failed to set ecal default timezone %s", gerror->message);
774
g_clear_error (&gerror);
775
g_object_unref(ecal);
779
if (!e_cal_open(ecal, FALSE, &gerror)) {
780
g_debug("Failed to get ecal sources %s", gerror->message);
781
g_clear_error (&gerror);
782
g_object_unref(ecal);
786
const gchar *ecal_uid = e_source_peek_uid(source);
787
g_debug("Checking ecal_uid is enabled: %s", ecal_uid);
788
const gboolean in_list = g_slist_find_custom (cal_list, ecal_uid, (GCompareFunc)g_strcmp0) != NULL;
790
g_object_unref(ecal);
794
g_debug("ecal_uid is enabled, generating instances");
795
e_cal_generate_instances (ecal, t1, t2, (ECalRecurInstanceFn) populate_appointment_instances, source);
796
g_object_unref(ecal);
799
g_slist_free_full (cal_list, g_free);
759
for (s = g_list_first (sources); s; s = g_list_next (s)) {
761
ESource *source = E_SOURCE (s->data);
762
g_signal_connect (G_OBJECT(source), "changed", G_CALLBACK (update_appointment_menu_items), NULL);
763
ECalClient *ecal = e_cal_client_new(source, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, &gerror);
765
icaltimezone* current_zone = icaltimezone_get_builtin_timezone(current_timezone);
767
// current_timezone may be a TZID?
768
current_zone = icaltimezone_get_builtin_timezone_from_tzid(current_timezone);
771
e_cal_client_set_default_timezone (ecal, current_zone);
773
g_debug("Checking if source %s is enabled", e_source_get_uid(source));
774
if (e_source_get_enabled (source)) {
775
g_debug("source is enabled, generating instances");
777
if (!e_client_open_sync (E_CLIENT (ecal), TRUE, NULL, &gerror)) {
778
g_debug("Failed to open source: %s", gerror->message);
779
g_clear_error (&gerror);
780
g_object_unref(ecal);
784
e_cal_client_generate_instances (ecal, t1, t2, NULL,
785
(ECalRecurInstanceFn) populate_appointment_instances,
789
g_object_unref(ecal);
791
g_list_free_full (sources, g_object_unref);
801
793
g_debug("Number of ECalComponents returned: %d", g_list_length(comp_instances));
802
794
GList *sorted_comp_instances = g_list_sort(comp_instances, compare_comp_instances);