← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~karl-qdh/indicator-datetime/resetdate into lp:indicator-datetime

 

Karl Lattimer has proposed merging lp:~karl-qdh/indicator-datetime/resetdate into lp:indicator-datetime.

Requested reviews:
  tedgagnon (tedg)
Related bugs:
  Bug #649800 in Indicator Date and Time: "datetime indicator won't show today's date if you've ever clicked on any others"
  https://bugs.launchpad.net/indicator-datetime/+bug/649800
  Bug #740980 in indicator-datetime (Ubuntu): "Date with event isn't highlighted in the calendar"
  https://bugs.launchpad.net/ubuntu/+source/indicator-datetime/+bug/740980

For more details, see:
https://code.launchpad.net/~karl-qdh/indicator-datetime/resetdate/+merge/55336

Used the suggested arrays for marking/unmarking days but there's no change, the signal is still not received by the indicator, restarted everything in various ways and nothing seems to get it working. 
-- 
https://code.launchpad.net/~karl-qdh/indicator-datetime/resetdate/+merge/55336
Your team ayatana-commits is subscribed to branch lp:indicator-datetime.
=== modified file 'src/datetime-service.c'
--- src/datetime-service.c	2011-03-23 12:03:21 +0000
+++ src/datetime-service.c	2011-03-29 13:30:57 +0000
@@ -316,6 +316,28 @@
 	return TRUE;
 }
 
+static gboolean
+close_menu_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant) 
+{
+	if (calendar == NULL) return FALSE;
+	g_debug("Resetting date on menu close");
+	start_time_appointments = 0;
+	// TODO create a variant which will be an array of 3 ints {y,m,d}
+	GVariant *date_variant;
+	time_t curtime;
+	struct tm *t1;
+	time(&curtime);
+	t1 = localtime(&curtime);
+	GVariant *date[3];
+	date[0] = g_variant_new_uint32(t1->tm_year + 1900);
+	date[1] = g_variant_new_uint32(t1->tm_mon);
+	date[2] = g_variant_new_uint32(t1->tm_mday);
+	date_variant = g_variant_new_array(NULL, date, 3);
+	
+	dbusmenu_menuitem_property_set_variant (calendar, CALENDAR_MENUITEM_PROP_SET_DATE, date_variant);
+	return TRUE;
+}
+
 static guint ecaltimer = 0;
 
 static void
@@ -585,7 +607,7 @@
 	int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
 	if ((this_year % 400 == 0) || (this_year % 100 > 0 && this_year % 4 == 0)) days[1] = 29;
 	
-	int highlightdays = days[mon] - mday + 1;
+	int highlightdays = days[mon] - mday;
 	t1 = curtime; // By default the current time is the appointment start time. 
 	
 	if (start_time_appointments > 0) {
@@ -605,10 +627,7 @@
 	
 	g_debug("Will highlight %d days from %s", highlightdays, ctime(&t1));
 
-	t2 = t1 + (time_t) (highlightdays * 24 * 60 * 60); 
-	
-	// Remove all highlights from the calendar widget
-	dbusmenu_menuitem_property_set (calendar, CALENDAR_MENUITEM_PROP_CLEAR_MARKS, NULL);
+	t2 = t1 + (time_t) (highlightdays * 24 * 60 * 60);
 	
 	if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_EVENT, &gerror)) {
 		g_debug("Failed to get ecal sources\n");
@@ -680,6 +699,11 @@
 	} else {
 		apt_output = SETTINGS_TIME_LOCALE;
 	}
+	// Remove all highlights from the calendar widget
+	dbusmenu_menuitem_property_set (calendar, CALENDAR_MENUITEM_PROP_CLEAR_MARKS, NULL);
+	
+	GVariantBuilder markeddays;
+	g_variant_builder_init (&markeddays, G_VARIANT_TYPE_ARRAY);
 	
 	i = 0;
 	for (l = sorted_comp_instances; l; l = l->next) {
@@ -702,9 +726,8 @@
 		const int dyear = due->tm_year;
 		
 		// Mark day
-		g_debug("Marking date %s", ctime(&ci->start));
-		dbusmenu_menuitem_property_set_int (calendar, CALENDAR_MENUITEM_PROP_MARK, due->tm_mday);
-
+		g_debug("Adding marked date %s, %d", ctime(&ci->start), dmday);
+		g_variant_builder_add (&markeddays, "i", dmday);
 
 		// If the appointment time is less than the selected date, 
 		// don't create an appointment item for it.
@@ -832,6 +855,9 @@
 	}
 	g_list_free(sorted_comp_instances);
 	
+	GVariant * marks = g_variant_builder_end (&markeddays);
+	dbusmenu_menuitem_property_set_variant (calendar, CALENDAR_MENUITEM_PROP_MARK, marks);
+	
 	updating_appointments = FALSE;
 	g_debug("End of objects");
 	return TRUE;
@@ -1218,6 +1244,9 @@
 	
 	build_menus(root);
 	
+	// Connect to the close signal to reset the calendar date 
+	g_signal_connect(root, "event::closed", G_CALLBACK(close_menu_cb), NULL);
+	
 	/* Cache the timezone */
 	update_current_timezone();
 

=== modified file 'src/indicator-datetime.c'
--- src/indicator-datetime.c	2011-03-15 15:47:25 +0000
+++ src/indicator-datetime.c	2011-03-29 13:30:57 +0000
@@ -1144,18 +1144,43 @@
 		timezone_update_labels(mi_data);
 	} else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_RADIO)) {
 		gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi_data->gmi), g_variant_get_boolean(value));
-		
-	// Properties for marking and unmarking the calendar
-	
-	} else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARK)) {
-		ido_calendar_menu_item_mark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int16(value));
+	} else {
+		g_warning("Indicator Item property '%s' unknown", prop);
+	}
+	return;
+}
+// Properties for marking and unmarking the calendar
+static void
+calendar_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, IdoCalendarMenuItem * mi_data)
+{
+	g_debug("Changing calendar property");
+	if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARK)) {
+		GVariantIter iter;
+		GVariant *day;
+		gchar *key;
+
+		g_variant_iter_init (&iter, value);
+	  	while (g_variant_iter_loop (&iter, "{i}", &key, &day)) {
+			ido_calendar_menu_item_mark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int32(day));
+			g_debug("Marked day: %d", g_variant_get_int32(day));
+		}
 	} else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_UNMARK)) {
-		ido_calendar_menu_item_unmark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int16(value));
+		GVariantIter iter;
+		GVariant *day;
+		gchar *key;
+
+		g_variant_iter_init (&iter, value);
+	  	while (g_variant_iter_loop (&iter, "{i}", &key, &day)) {
+			ido_calendar_menu_item_unmark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int32(day));
+			g_debug("Unmarked day: %d", g_variant_get_int32(day));
+		}
 	} else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_CLEAR_MARKS)) {
 		ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data));
+		g_debug("Cleared Marks");
 	} else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_SET_DATE)) {
 		gsize size = 3;
 		const gint * array = g_variant_get_fixed_array(value, &size, sizeof(gint));
+		g_debug("Setting date y-m-d: %d-%d-%d", array[0], array[1], array[2]);
 		ido_calendar_menu_item_set_date (IDO_CALENDAR_MENU_ITEM (mi_data), array[0], array[1], array[2]);
 	} else {
 		g_warning("Indicator Item property '%s' unknown", prop);
@@ -1235,8 +1260,6 @@
 	dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(mi_data->gmi), parent);
 
 	g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(indicator_prop_change_cb), mi_data);
-	g_signal_connect_swapped(G_OBJECT(newitem), "destroyed", G_CALLBACK(g_free), mi_data);
-
 	return TRUE;
 }
 
@@ -1330,6 +1353,7 @@
 	g_signal_connect_after(ido, "day-selected", G_CALLBACK(day_selected_cb), (gpointer)newitem);
 	g_signal_connect_after(ido, "day-selected-double-click", G_CALLBACK(day_selected_double_click_cb), (gpointer)newitem);
 
+	g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(calendar_prop_change_cb), ido);
 	return TRUE;
 }