~karl-qdh/indicator-datetime/fixed-appointment-icon-colours

« back to all changes in this revision

Viewing changes to src/datetime-service.c

  • Committer: karl-qdh
  • Date: 2011-03-02 13:31:45 UTC
  • Revision ID: karl@qdh.org.uk-20110302133145-x3k73jz063nk4pap
* Fixed adding/removing locations not triggering update
* Improved update appointment menu items code
* Improved populate_appointment_instances
* Opened up objects generation to include marking days

Show diffs side-by-side

added added

removed removed

Lines of Context:
448
448
        return password;
449
449
}
450
450
 
451
 
 
452
 
// Compare function for g_list_sort of ECalComponent objects
453
 
// Generate instances sorts them by time anyway
454
 
/*static gint 
455
 
compare_appointment_items (ECalComponent *a,
456
 
                           ECalComponent *b) 
457
 
{
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;
461
 
        time_t t_a, t_b;
462
 
        gint retval = 0;
463
 
 
464
 
        if (a == NULL || b == NULL) return 0;
465
 
 
466
 
        ECalComponentVType vtype = e_cal_component_get_vtype (a);
467
 
        
468
 
        if (vtype != E_CAL_COMPONENT_EVENT && vtype != E_CAL_COMPONENT_TODO) {
469
 
                g_debug("A is Not a todo or event");
470
 
                return 1;
471
 
        }
472
 
        
473
 
        if (vtype == E_CAL_COMPONENT_EVENT)
474
 
                e_cal_component_get_dtstart (a, &datetime_a);
475
 
        else
476
 
            e_cal_component_get_due (a, &datetime_a);
477
 
        tm_a = icaltimetype_to_tm(datetime_a.value);
478
 
        t_a = mktime(&tm_a);
479
 
        
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");
483
 
                return -1;
484
 
        }
485
 
        
486
 
        if (vtype == E_CAL_COMPONENT_EVENT)
487
 
                e_cal_component_get_dtstart (b, &datetime_b);
488
 
        else
489
 
            e_cal_component_get_due (b, &datetime_b);
490
 
        tm_b = icaltimetype_to_tm(datetime_b.value);
491
 
        t_b = mktime(&tm_b);
492
 
 
493
 
        // Compare datetime_a and datetime_b, newest first in this sort.
494
 
        if (t_a > t_b) {
495
 
                g_debug("A > B: %d > %d", (int)t_a, (int)t_b);
496
 
                retval = 1;
497
 
        } else if (t_a < t_b) {
498
 
                g_debug("B > A: %d > %d", (int)t_b, (int)t_a);
499
 
                retval = -1;
500
 
        }
501
 
        g_debug("A == B: %d == %d", (int)t_a, (int)t_b);
502
 
        return 0;
503
 
}*/
504
 
 
505
451
static gboolean
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;
 
460
        
 
461
        icalproperty_status status;
 
462
        e_cal_component_get_status (comp, &status);
 
463
        if (status == ICAL_STATUS_COMPLETED || status == ICAL_STATUS_CANCELLED) return FALSE;
 
464
        
514
465
        g_object_ref(comp);
515
466
        tmpobjects = g_list_append(tmpobjects, comp);
516
 
 
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.
519
467
        return TRUE;
520
468
}
521
469
 
577
525
                
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);
583
531
                        
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;
608
555
                char right[20];
609
556
                //const gchar *uri;
610
557
                struct tm tmp_tm;
611
558
                DbusmenuMenuitem * item;
612
559
 
613
 
                g_debug("Start Object");
 
560
                g_debug("Start Object %p", ecalcomp);
614
561
                ECalComponentVType vtype = e_cal_component_get_vtype (ecalcomp);
615
562
 
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)
619
 
                        continue;
620
 
 
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)
625
 
                        continue;
626
 
 
 
563
                if (vtype == E_CAL_COMPONENT_EVENT)
 
564
                        e_cal_component_get_dtstart (ecalcomp, &datetime);
 
565
                else
 
566
                    e_cal_component_get_due (ecalcomp, &datetime);
 
567
                    
 
568
                if (!datetime.value) continue;
 
569
                
 
570
                // TODO Mark days with appointments in the current month
 
571
                
 
572
                if (i >= 5) continue;
 
573
                i++;
 
574
                
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);
639
587
                
640
588
                // Due text
641
 
                if (vtype == E_CAL_COMPONENT_EVENT)
642
 
                        e_cal_component_get_dtstart (ecalcomp, &datetime);
643
 
                else
644
 
                    e_cal_component_get_due (ecalcomp, &datetime);
645
 
                
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) {
649
 
                        g_free(item);
650
 
                        continue;
651
 
                }
652
 
                
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;
657
593
                }
 
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. 
660
598
                
680
618
                
681
619
                e_cal_component_free_datetime (&datetime);
682
620
                
683
 
                ad = isodate_from_time_t(mktime(&tmp_tm));
684
621
                
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
687
 
                
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);
718
655
                        
719
656
                        dbusmenu_menuitem_property_set_image (item, APPOINTMENT_MENUITEM_PROP_ICON, pixbuf);
720
657
                }
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);
724
 
 
725
 
                if (i == 4) break;
726
 
                i++;
727
661
        }
728
662
        
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");
733
666
        return TRUE;
734
667
}
810
743
        check_timezone_sync();
811
744
        
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);
814
748
 
815
749
        DbusmenuMenuitem * separator = dbusmenu_menuitem_new();