452
// Compare function for g_list_sort of ECalComponent objects
453
// Generate instances sorts them by time anyway
455
compare_appointment_items (ECalComponent *a,
458
g_debug("Comparing two items from list %d %d", (int)a, (int)b);
459
ECalComponentDateTime datetime_a, datetime_b;
460
struct tm tm_a, tm_b;
464
if (a == NULL || b == NULL) return 0;
466
ECalComponentVType vtype = e_cal_component_get_vtype (a);
468
if (vtype != E_CAL_COMPONENT_EVENT && vtype != E_CAL_COMPONENT_TODO) {
469
g_debug("A is Not a todo or event");
473
if (vtype == E_CAL_COMPONENT_EVENT)
474
e_cal_component_get_dtstart (a, &datetime_a);
476
e_cal_component_get_due (a, &datetime_a);
477
tm_a = icaltimetype_to_tm(datetime_a.value);
480
vtype = e_cal_component_get_vtype (b);
481
if (vtype != E_CAL_COMPONENT_EVENT && vtype != E_CAL_COMPONENT_TODO) {
482
g_debug("B is Not a todo or event");
486
if (vtype == E_CAL_COMPONENT_EVENT)
487
e_cal_component_get_dtstart (b, &datetime_b);
489
e_cal_component_get_due (b, &datetime_b);
490
tm_b = icaltimetype_to_tm(datetime_b.value);
493
// Compare datetime_a and datetime_b, newest first in this sort.
495
g_debug("A > B: %d > %d", (int)t_a, (int)t_b);
497
} else if (t_a < t_b) {
498
g_debug("B > A: %d > %d", (int)t_b, (int)t_a);
501
g_debug("A == B: %d == %d", (int)t_a, (int)t_b);
506
452
populate_appointment_instances (ECalComponent *comp,
507
453
time_t instance_start,
511
457
g_debug("Appending item %d", (int)comp);
512
458
ECalComponentVType vtype = e_cal_component_get_vtype (comp);
513
459
if (vtype != E_CAL_COMPONENT_EVENT && vtype != E_CAL_COMPONENT_TODO) return FALSE;
461
icalproperty_status status;
462
e_cal_component_get_status (comp, &status);
463
if (status == ICAL_STATUS_COMPLETED || status == ICAL_STATUS_CANCELLED) return FALSE;
514
465
g_object_ref(comp);
515
466
tmpobjects = g_list_append(tmpobjects, comp);
517
// TODO We also may as well use this opportunity to "mark days" in the calendar
518
// as we're iterating everything of interest here anyway.
578
526
for (s = e_source_group_peek_sources (group); s; s = s->next) {
579
527
ESource *source = E_SOURCE (s->data);
580
g_signal_connect (G_OBJECT(source), "changed", G_CALLBACK (update_appointment_menu_items), NULL);
528
//g_signal_connect (G_OBJECT(source), "changed", G_CALLBACK (update_appointment_menu_items), NULL);
581
529
ECal *ecal = e_cal_new(source, E_CAL_SOURCE_TYPE_EVENT);
582
530
e_cal_set_auth_func (ecal, (ECalAuthFunc) auth_func, NULL);
603
551
ECalComponentDateTime datetime;
604
552
icaltimezone *appointment_zone = NULL;
605
553
icaltimezone *current_zone = NULL;
606
icalproperty_status status;
607
554
gchar *summary, *cmd;
609
556
//const gchar *uri;
610
557
struct tm tmp_tm;
611
558
DbusmenuMenuitem * item;
613
g_debug("Start Object");
560
g_debug("Start Object %p", ecalcomp);
614
561
ECalComponentVType vtype = e_cal_component_get_vtype (ecalcomp);
616
// See above FIXME regarding query result
617
// If it's not an event or todo, continue no-increment
618
if (vtype != E_CAL_COMPONENT_EVENT && vtype != E_CAL_COMPONENT_TODO)
621
// See above FIXME regarding query result
622
// if the status is completed, continue no-increment
623
e_cal_component_get_status (ecalcomp, &status);
624
if (status == ICAL_STATUS_COMPLETED || status == ICAL_STATUS_CANCELLED)
563
if (vtype == E_CAL_COMPONENT_EVENT)
564
e_cal_component_get_dtstart (ecalcomp, &datetime);
566
e_cal_component_get_due (ecalcomp, &datetime);
568
if (!datetime.value) continue;
570
// TODO Mark days with appointments in the current month
572
if (i >= 5) continue;
627
575
item = dbusmenu_menuitem_new();
628
576
dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_TYPE, APPOINTMENT_MENUITEM_TYPE);
629
577
dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
638
586
g_free (summary);
641
if (vtype == E_CAL_COMPONENT_EVENT)
642
e_cal_component_get_dtstart (ecalcomp, &datetime);
644
e_cal_component_get_due (ecalcomp, &datetime);
646
// FIXME need to get the timezone of the above datetime,
647
// and get the icaltimezone of the geoclue timezone/selected timezone (whichever is preferred)
648
if (!datetime.value) {
653
589
appointment_zone = icaltimezone_get_builtin_timezone_from_tzid(datetime.tzid);
654
590
current_zone = icaltimezone_get_builtin_timezone_from_tzid(current_timezone);
655
591
if (!appointment_zone || datetime.value->is_date) { // If it's today put in the current timezone?
656
592
appointment_zone = current_zone;
594
// FIXME need to get the timezone of the above datetime,
595
// and get the icaltimezone of the geoclue timezone/selected timezone (whichever is preferred)
658
596
// TODO: Convert the timezone into a 3 letter abbreviation if it's different to current_timezone
659
597
// TODO: Add the appointment timezone to the list if it's not already there.
681
619
e_cal_component_free_datetime (&datetime);
683
ad = isodate_from_time_t(mktime(&tmp_tm));
685
622
// Now we pull out the URI for the calendar event and try to create a URI that'll work when we execute evolution
686
623
// FIXME Because the URI stuff is really broken, we're going to open the calendar at todays date instead
688
624
//e_cal_component_get_uid(ecalcomp, &uri);
625
ad = isodate_from_time_t(mktime(&tmp_tm));
689
626
cmd = g_strconcat("evolution calendar:///?startdate=", ad, NULL);
690
627
g_signal_connect (G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
691
628
G_CALLBACK (activate_cb), cmd);
719
656
dbusmenu_menuitem_property_set_image (item, APPOINTMENT_MENUITEM_PROP_ICON, pixbuf);
721
dbusmenu_menuitem_child_add_position (root, item, 3+i);
658
dbusmenu_menuitem_child_add_position (root, item, 2+i);
722
659
appointments = g_list_append (appointments, item); // Keep track of the items here to make them east to remove
723
660
g_debug("Adding appointment: %p", item);
729
663
if (gerror != NULL) g_error_free(gerror);
730
664
for (l = allobjects; l; l = l->next) g_object_unref(l->data);
731
g_object_unref(allobjects);
732
665
g_debug("End of objects");
810
743
check_timezone_sync();
812
745
g_signal_connect (conf, "changed::" SETTINGS_SHOW_LOCATIONS_S, G_CALLBACK (show_locations_changed), NULL);
746
g_signal_connect (conf, "changed::" SETTINGS_LOCATIONS_S, G_CALLBACK (show_locations_changed), NULL);
813
747
g_signal_connect (conf, "changed::" SETTINGS_SHOW_EVENTS_S, G_CALLBACK (show_events_changed), NULL);
815
749
DbusmenuMenuitem * separator = dbusmenu_menuitem_new();