279
update_appointment_menu_items_idle (gpointer user_data)
281
update_appointment_menu_items(user_data);
279
286
month_changed_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, guint timestamp)
281
288
start_time_appointments = (time_t)g_variant_get_uint32(variant);
283
290
g_debug("Received month changed with timestamp: %d -> %s",(int)start_time_appointments, ctime(&start_time_appointments));
284
update_appointment_menu_items(NULL);
291
/* By default one of the first things we do is
292
clear the marks as we don't know the correct
293
ones yet and we don't want to confuse the
295
dbusmenu_menuitem_property_remove(menuitem, CALENDAR_MENUITEM_PROP_MARKS);
298
for (appointment = appointments; appointment != NULL; appointment = g_list_next(appointment)) {
299
DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(appointment->data);
300
dbusmenu_menuitem_property_set_bool(mi, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE);
303
g_idle_add(update_appointment_menu_items_idle, NULL);
289
308
day_selected_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant, guint timestamp)
291
start_time_appointments = (time_t)g_variant_get_uint32(variant);
310
time_t new_time = (time_t)g_variant_get_uint32(variant);
311
g_warn_if_fail(new_time != 0);
313
if (start_time_appointments == 0 || new_time == 0) {
314
/* If we've got nothing, assume everyhting is going to
315
get repopulated, let's start with a clean slate */
316
dbusmenu_menuitem_property_remove(menuitem, CALENDAR_MENUITEM_PROP_MARKS);
318
/* No check to see if we changed months. If we did we'll
319
want to clear the marks. Otherwise we're cool keeping
324
localtime_r(&start_time_appointments, &start_tm);
325
localtime_r(&new_time, &new_tm);
327
if (start_tm.tm_mon != new_tm.tm_mon) {
328
dbusmenu_menuitem_property_remove(menuitem, CALENDAR_MENUITEM_PROP_MARKS);
333
for (appointment = appointments; appointment != NULL; appointment = g_list_next(appointment)) {
334
DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(appointment->data);
335
dbusmenu_menuitem_property_set_bool(mi, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE);
338
start_time_appointments = new_time;
293
340
g_debug("Received day-selected with timestamp: %d -> %s",(int)start_time_appointments, ctime(&start_time_appointments));
294
update_appointment_menu_items(NULL);
341
g_idle_add(update_appointment_menu_items_idle, NULL);
368
close_menu_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant)
370
if (calendar == NULL) return FALSE;
371
g_debug("Resetting date on menu close");
372
start_time_appointments = 0;
373
// TODO create a variant which will be an array of 3 ints {y,m,d}
374
GVariant *date_variant;
378
t1 = localtime(&curtime);
380
date[0] = g_variant_new_uint32(t1->tm_year + 1900);
381
date[1] = g_variant_new_uint32(t1->tm_mon);
382
date[2] = g_variant_new_uint32(t1->tm_mday);
383
date_variant = g_variant_new_array(NULL, date, 3);
385
dbusmenu_menuitem_property_set_variant (calendar, CALENDAR_MENUITEM_PROP_SET_DATE, date_variant);
319
389
static guint ecaltimer = 0;
344
420
dbusmenu_menuitem_property_set_bool(events_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
345
421
/* Remove all of the previous appointments */
346
422
if (appointments != NULL) {
347
g_debug("Freeing old appointments");
348
while (appointments != NULL) {
349
DbusmenuMenuitem * litem = DBUSMENU_MENUITEM(appointments->data);
350
g_debug("Freeing old appointment: %p", litem);
423
g_debug("Hiding old appointments");
425
for (appointment = appointments; appointment != NULL; appointment = g_list_next(appointment)) {
426
DbusmenuMenuitem * litem = DBUSMENU_MENUITEM(appointment->data);
427
g_debug("Hiding old appointment: %p", litem);
351
428
// Remove all the existing menu items which are in appointments.
352
appointments = g_list_remove(appointments, litem);
353
dbusmenu_menuitem_child_delete(root, DBUSMENU_MENUITEM(litem));
354
g_object_unref(G_OBJECT(litem));
429
dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(litem), DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
357
432
stop_ecal_timer();
389
464
if (g_settings_get_boolean(conf, SETTINGS_SHOW_EVENTS_S)) {
390
465
dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
391
466
dbusmenu_menuitem_property_set_bool(events_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
467
g_idle_add((GSourceFunc)idle_start_ecal_timer, NULL);
394
469
dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
395
470
dbusmenu_menuitem_property_set_bool(events_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
580
655
const int mday = today->tm_mday;
581
656
const int mon = today->tm_mon;
582
657
const int year = today->tm_year;
584
659
struct tm *start_tm = NULL;
585
660
int this_year = today->tm_year + 1900;
586
661
int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
600
675
month_start.tm_mon = start_tm->tm_mon;
601
676
month_start.tm_mday = 1;
602
677
t1 = mktime(&month_start);
603
highlightdays = days[mon];
678
highlightdays = days[start_month];
607
682
g_debug("Will highlight %d days from %s", highlightdays, ctime(&t1));
609
t2 = t1 + (time_t) (highlightdays * 24 * 60 * 60);
611
// Remove all highlights from the calendar widget
612
dbusmenu_menuitem_property_set (calendar, CALENDAR_MENUITEM_PROP_CLEAR_MARKS, NULL);
684
t2 = t1 + (time_t) (highlightdays * 24 * 60 * 60);
614
686
if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_EVENT, &gerror)) {
615
687
g_debug("Failed to get ecal sources\n");
653
725
comp_instances = NULL;
654
726
g_debug("Components sorted");
656
/* Remove all of the previous appointments */
728
/* Hiding all of the previous appointments */
657
729
if (appointments != NULL) {
658
g_debug("Freeing old appointments");
659
while (appointments != NULL) {
660
DbusmenuMenuitem * litem = DBUSMENU_MENUITEM(appointments->data);
661
g_debug("Freeing old appointment: %p", litem);
730
g_debug("Hiding old appointments");
732
for (appointment = appointments; appointment != NULL; appointment = g_list_next(appointment)) {
733
DbusmenuMenuitem * litem = DBUSMENU_MENUITEM(appointment->data);
734
g_debug("Hiding old appointment: %p", litem);
662
735
// Remove all the existing menu items which are in appointments.
663
appointments = g_list_remove(appointments, litem);
664
dbusmenu_menuitem_child_delete(root, DBUSMENU_MENUITEM(litem));
665
g_object_unref(G_OBJECT(litem));
736
dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(litem), DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
679
750
} else if (g_strcmp0(time_format_str, "24-hour") == 0) {
680
751
apt_output = SETTINGS_TIME_24_HOUR;
682
apt_output = SETTINGS_TIME_LOCALE;
753
if (is_locale_12h()) {
754
apt_output = SETTINGS_TIME_12_HOUR;
756
apt_output = SETTINGS_TIME_24_HOUR;
760
GVariantBuilder markeddays;
761
g_variant_builder_init (&markeddays, G_VARIANT_TYPE_ARRAY);
764
GList * cached_appointment = appointments;
686
765
for (l = sorted_comp_instances; l; l = l->next) {
687
766
struct comp_instance *ci = l->data;
688
767
ECalComponent *ecalcomp = ci->comp;
703
782
const int dyear = due->tm_year;
706
g_debug("Marking date %s", ctime(&ci->start));
707
dbusmenu_menuitem_property_set_int (calendar, CALENDAR_MENUITEM_PROP_MARK, due->tm_mday);
785
g_debug("Adding marked date %s, %d", ctime(&ci->start), dmday);
786
g_variant_builder_add (&markeddays, "i", dmday);
710
788
// If the appointment time is less than the selected date,
711
789
// don't create an appointment item for it.
718
796
if (i >= 5) continue;
721
g_debug("Create menu item");
723
item = dbusmenu_menuitem_new();
724
dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_TYPE, APPOINTMENT_MENUITEM_TYPE);
799
if (cached_appointment == NULL) {
800
g_debug("Create menu item");
802
item = dbusmenu_menuitem_new();
803
dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_TYPE, APPOINTMENT_MENUITEM_TYPE);
805
dbusmenu_menuitem_child_add_position (root, item, 2+i);
806
appointments = g_list_append (appointments, item); // Keep track of the items here to make them easy to remove
808
item = DBUSMENU_MENUITEM(cached_appointment->data);
809
cached_appointment = g_list_next(cached_appointment);
811
/* Remove the icon as we might not replace it on error */
812
dbusmenu_menuitem_property_remove(item, APPOINTMENT_MENUITEM_PROP_ICON);
814
/* Remove the activate handler */
815
g_signal_handlers_disconnect_matched(G_OBJECT(item), G_SIGNAL_MATCH_FUNC, 0, 0, NULL, G_CALLBACK(activate_cb), NULL);
725
818
dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
726
819
dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
729
823
e_cal_component_get_summary (ecalcomp, &valuetext);
744
838
strftime(right, 20, _(DEFAULT_TIME_24_FORMAT), due);
746
840
strftime(right, 20, _(DEFAULT_TIME_24_FORMAT_WITH_DAY), due);
748
if ((mday == dmday) && (mon == dmon) && (year == dyear))
749
strftime(right, 20, _(DEFAULT_TIME_FORMAT), due);
751
strftime(right, 20, _(DEFAULT_TIME_FORMAT_WITH_DAY), due);
753
842
g_debug("Appointment time: %s, for date %s", right, asctime(due));
754
843
dbusmenu_menuitem_property_set (item, APPOINTMENT_MENUITEM_PROP_RIGHT, right);