← Back to team overview

ayatana-commits team mailing list archive

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

 

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

Requested reviews:
  Ted Gould (ted)
  David Barth (dbarth)

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

Replaces about-to-show with a timer every 30 mins to update the appointments, adds gsettings reading but misses out on responding to location changes. Adds theoretical only signal handling for month-changes so we can then update the calendars. Various other small fixes.

Shortened timer, and added gerror freeing when not null
-- 
https://code.launchpad.net/~karl-qdh/indicator-datetime/configandcalsignals/+merge/51314
Your team ayatana-commits is subscribed to branch lp:indicator-datetime.
=== modified file 'data/com.canonical.indicator.datetime.gschema.xml'
--- data/com.canonical.indicator.datetime.gschema.xml	2011-02-15 14:54:00 +0000
+++ data/com.canonical.indicator.datetime.gschema.xml	2011-02-25 15:47:04 +0000
@@ -5,6 +5,11 @@
 		<value nick="24-hour" value="2" />
 		<value nick="custom" value="3" />
 	</enum>
+	<enum id="week-start-enum">
+		<value nick="locale-default" value="0" />
+		<value nick="sunday" value="1" />
+		<value nick="monday" value="2" />
+	</enum>
 	<schema id="com.canonical.indicator.datetime" path="/com/canonical/indicator/datetime/" gettext-domain="indicator-datetime">
 		<key name="time-format" enum="time-enum">
 			<default>'locale-default'</default>
@@ -57,13 +62,41 @@
 			  more information.
 			</description>
 		</key>
+		<key name="show-week-numbers" type="b">
+			<default>false</default>
+			<summary>Show week numbers in calendar</summary>
+			<description>
+			  Shows the week numbers in the monthly calendar in indicator-datetime's menu.
+			</description>
+		</key>
 		<key name="locations" type="as">
-			<default>[]</default>
+			<default>['UTC']</default>
 			<summary>A List of locations</summary>
 			<description>
 			  Adds the list of locations the user has configured to display in the 
 			  indicator-datetime menu.
 			</description>
 		</key>
+		<key name="show-calendar" type="b">
+			<default>true</default>
+			<summary>Show the monthly calendar in the indicator</summary>
+			<description>
+			  Puts the monthly calendar in indicator-datetime's menu.
+			</description>
+		</key>
+		<key name="show-events" type="b">
+			<default>true</default>
+			<summary>Show events in the indicator</summary>
+			<description>
+			  Shows events from Evolution in indicator-datetime's menu.
+			</description>
+		</key>
+		<key name="show-locations" type="b">
+			<default>false</default>
+			<summary>Show locations in the indicator</summary>
+			<description>
+			  Shows custom defined locations in indicator-datetime's menu.
+			</description>
+		</key>
 	</schema>
 </schemalist>

=== modified file 'src/datetime-service.c'
--- src/datetime-service.c	2011-02-17 18:58:54 +0000
+++ src/datetime-service.c	2011-02-25 15:47:04 +0000
@@ -54,8 +54,11 @@
 #include "dbus-shared.h"
 
 
-#define SETTINGS_INTERFACE "com.canonical.indicator.datetime"
-#define SETTINGS_LOCATIONS "locations"
+#define SETTINGS_INTERFACE      "com.canonical.indicator.datetime"
+#define SETTINGS_LOCATIONS      "locations"
+#define SETTINGS_SHOW_CALENDAR  "show-calendar"
+#define SETTINGS_SHOW_EVENTS    "show-events"
+#define SETTINGS_SHOW_LOCATIONS "show-locations"
 
 static void geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar * path, GError * error, gpointer user_data);
 static gboolean update_appointment_menu_items (gpointer user_data);
@@ -115,6 +118,13 @@
 	} else {
 		g_debug("Timezones are different");
 	}
+	
+	if (!g_settings_get_boolean(conf, SETTINGS_SHOW_LOCATIONS)) {
+		dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
+		dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
+		dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
+		return;
+	}
 
 	if (geo_location != NULL && current_location != NULL) {
 		g_debug("Got timezone %s", current_timezone);
@@ -208,6 +218,7 @@
 
 	check_timezone_sync();
 
+    if (error != NULL) g_error_free(error);
 	return;
 }
 
@@ -288,52 +299,35 @@
 	}
 }
 
+static gboolean
+month_changed_cb (DbusmenuMenuitem * menuitem, GVariant *variant, guint timestamp)
+{
+	// TODO: * Decode the month/year from the string we received
+	//       * Check what our current month/year are
+	//		 * Set some globals so when we-re-run update appointment menu items it gets the right start date
+	//		 * update appointment menu items
+	g_debug("Received month changed : %s", g_variant_get_string(variant, NULL));
+	return TRUE;
+}
+
 /* Looks for the calendar application and enables the item if
    we have one */
 static gboolean
 check_for_calendar (gpointer user_data)
 {
 	g_return_val_if_fail (calendar != NULL, FALSE);
+	
+	if (!g_settings_get_boolean(conf, SETTINGS_SHOW_CALENDAR)) return FALSE;
 
 	gchar *evo = g_find_program_in_path("evolution");
 	if (evo != NULL) {
 		g_debug("Found the calendar application: %s", evo);
 		dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
 		dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
-/*
-		GError *gerror = NULL;
-		// TODO: In reality we should iterate sources of calendar, but getting the local one doens't lag for > a minute
-		g_debug("Setting up ecal.");
-		if (!ecal)
-			ecal = e_cal_new_system_calendar();
-	
-		if (!ecal) {
-			g_debug("e_cal_new_system_calendar failed");
-			ecal = NULL;
-		}
-		g_debug("Open calendar.");
-		if (!e_cal_open(ecal, FALSE, &gerror) ) {
-			g_debug("e_cal_open: %s\n", gerror->message);
-			g_free(ecal);
-			ecal = NULL;
-		}
-		g_debug("Get calendar timezone.");
-		if (!e_cal_get_timezone(ecal, "UTC", &tzone, &gerror)) {
-			g_debug("failed to get time zone\n");
-			g_free(ecal);
-			ecal = NULL;
-		}
-	
-		 This timezone represents the timezone of the calendar, this might be different to the current UTC offset.
-		 * this means we'll have some geoclue interaction going on, and possibly the user will be involved in setting
-		 * their location manually, case in point: trains have satellite links which often geoclue to sweden,
-		 * this shouldn't automatically set the location and mess up all the appointments for the user.
-		 
-		if (ecal) ecal_timezone = icaltimezone_get_tzid(tzone);
-		*/
+
 		DbusmenuMenuitem * separator = dbusmenu_menuitem_new();
 		dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR);
-		dbusmenu_menuitem_child_add_position(root, separator, 3);
+		dbusmenu_menuitem_child_add_position(root, separator, 2);
 
 		add_appointment = dbusmenu_menuitem_new();
 		dbusmenu_menuitem_property_set     (add_appointment, DBUSMENU_MENUITEM_PROP_LABEL, _("Add Appointment"));
@@ -342,9 +336,12 @@
 		g_signal_connect(G_OBJECT(add_appointment), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), "evolution -c calendar");
 		dbusmenu_menuitem_child_add_position (root, add_appointment, 3);
 
-		update_appointment_menu_items(NULL);
-		g_signal_connect(root, DBUSMENU_MENUITEM_SIGNAL_ABOUT_TO_SHOW, G_CALLBACK(update_appointment_menu_items), NULL);	
-
+		// Update the calendar items every 5 minutes if it updates the first time
+		if (update_appointment_menu_items(NULL))
+			g_timeout_add_seconds(60*5, update_appointment_menu_items, NULL); 
+			
+		// Connect to event::month-changed 
+		g_signal_connect(calendar, "event::month-changed", G_CALLBACK(month_changed_cb), NULL);
 		g_free(evo);
 	} else {
 		g_debug("Unable to find calendar app.");
@@ -358,7 +355,14 @@
 
 static gboolean
 update_timezone_menu_items(gpointer user_data) {
+	if (!g_settings_get_boolean(conf, SETTINGS_SHOW_LOCATIONS)) {
+		dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
+		dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
+		dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
+		return FALSE;
+	} 
 	g_debug("Updating timezone menu items");
+
 	gchar ** locations = g_settings_get_strv(conf, SETTINGS_LOCATIONS);
 	if (locations == NULL) { 
 		g_debug("No locations configured (NULL)");
@@ -426,7 +430,8 @@
 	else component_name = "Calendar";
 	
 	gchar *password = e_passwords_get_password (component_name, key);
-
+	gboolean remember;
+	
 	if (password == NULL) {
 		password = e_passwords_ask_password (
 			_("Enter password"),
@@ -494,6 +499,9 @@
 update_appointment_menu_items (gpointer user_data) {
 	// FFR: we should take into account short term timers, for instance
 	// tea timers, pomodoro timers etc... that people may add, this is hinted to in the spec.
+	if (calendar == NULL) return FALSE;
+	if (!g_settings_get_boolean(conf, SETTINGS_SHOW_EVENTS)) return FALSE;
+	
 	time_t t1, t2;
 	gchar *query, *is, *ie, *ad;
 	GList *objects = NULL, *l;
@@ -546,7 +554,6 @@
 			g_signal_connect (G_OBJECT(source), "changed", G_CALLBACK (update_appointment_menu_items), NULL);
 			ECal *ecal = e_cal_new(source, E_CAL_SOURCE_TYPE_EVENT);
 			e_cal_set_auth_func (ecal, (ECalAuthFunc) auth_func, NULL);
-			//icaltimezone * tzone;
 			
 			if (!e_cal_open(ecal, FALSE, &gerror)) {
 				g_debug("Failed to get ecal sources %s", gerror->message);
@@ -559,7 +566,8 @@
 			if (!e_cal_get_object_list_as_comp(ecal, query, &objects, &gerror)) {
 				g_debug("Failed to get objects\n");
 				g_free(ecal);
-				return FALSE;
+				gerror = NULL;
+				continue;
 			}
 			g_debug("Number of objects returned: %d", g_list_length(objects));
 			
@@ -704,6 +712,8 @@
 		if (i == 4) break; // See above FIXME regarding query result limit
 		i++;
 	}
+	
+    if (gerror != NULL) g_error_free(gerror);
 	g_object_unref(allobjects);
 	g_debug("End of objects");
 	return TRUE;

=== modified file 'src/dbus-shared.h'
--- src/dbus-shared.h	2011-02-16 21:22:12 +0000
+++ src/dbus-shared.h	2011-02-25 15:47:04 +0000
@@ -27,7 +27,14 @@
 
 #define  MENU_OBJ      "/com/canonical/indicator/datetime/menu"
 
-#define  DBUSMENU_CALENDAR_MENUITEM_TYPE "x-canonical-calendar-item"
+#define DBUSMENU_CALENDAR_MENUITEM_TYPE    "x-canonical-calendar-item"
+
+// The following properties are not *really* properties, but are just
+// a way of accessing the calendar from the service
+#define CALENDAR_MENUITEM_PROP_MARK        "calendar-mark"
+#define CALENDAR_MENUITEM_PROP_UNMARK      "calendar-unmark"
+#define CALENDAR_MENUITEM_PROP_CLEAR_MARKS "calendar-clear-marks"
+
 
 #define APPOINTMENT_MENUITEM_TYPE          "appointment-item"	
 #define APPOINTMENT_MENUITEM_PROP_LABEL    "appointment-label"

=== modified file 'src/indicator-datetime.c'
--- src/indicator-datetime.c	2011-02-17 19:03:01 +0000
+++ src/indicator-datetime.c	2011-02-25 15:47:04 +0000
@@ -26,9 +26,11 @@
 #include <locale.h>
 #include <langinfo.h>
 #include <string.h>
+#include <time.h>
 
 /* GStuff */
 #include <glib.h>
+#include <glib/gprintf.h>
 #include <glib-object.h>
 #include <glib/gi18n-lib.h>
 #include <gio/gio.h>
@@ -79,6 +81,9 @@
 	gchar * custom_string;
 	gboolean custom_show_seconds;
 
+	gboolean show_week_numbers;
+	gint week_start;
+	
 	guint idle_measure;
 	gint  max_width;
 
@@ -102,7 +107,8 @@
 	PROP_SHOW_SECONDS,
 	PROP_SHOW_DAY,
 	PROP_SHOW_DATE,
-	PROP_CUSTOM_TIME_FORMAT
+	PROP_CUSTOM_TIME_FORMAT,
+	PROP_SHOW_WEEK_NUMBERS
 };
 
 typedef struct _indicator_item_t indicator_item_t;
@@ -120,6 +126,7 @@
 #define PROP_SHOW_DAY_S                 "show-day"
 #define PROP_SHOW_DATE_S                "show-date"
 #define PROP_CUSTOM_TIME_FORMAT_S       "custom-time-format"
+#define PROP_SHOW_WEEK_NUMBERS_S        "show-week-numbers"
 
 #define SETTINGS_INTERFACE              "com.canonical.indicator.datetime"
 #define SETTINGS_TIME_FORMAT_S          "time-format"
@@ -127,6 +134,7 @@
 #define SETTINGS_SHOW_DAY_S             "show-day"
 #define SETTINGS_SHOW_DATE_S            "show-date"
 #define SETTINGS_CUSTOM_TIME_FORMAT_S   "custom-time-format"
+#define SETTINGS_SHOW_WEEK_NUMBERS_S    "show-week-numbers"
 
 enum {
 	SETTINGS_TIME_LOCALE = 0,
@@ -249,6 +257,13 @@
 	                                                     DEFAULT_TIME_FORMAT,
 	                                                     G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+	g_object_class_install_property (object_class,
+	                                 PROP_SHOW_WEEK_NUMBERS,
+	                                 g_param_spec_boolean(PROP_SHOW_WEEK_NUMBERS_S,
+	                                                      "Whether to show the week numbers in the calendar.",
+	                                                      "Shows the week numbers in the monthly calendar in indicator-datetime's menu.",
+	                                                      FALSE, /* default */
+	                                                      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 	return;
 }
 
@@ -307,6 +322,11 @@
 		                self,
 		                PROP_CUSTOM_TIME_FORMAT_S,
 		                G_SETTINGS_BIND_DEFAULT);
+		g_settings_bind(self->priv->settings,
+		                SETTINGS_SHOW_WEEK_NUMBERS_S,
+		                self,
+		                PROP_SHOW_WEEK_NUMBERS_S,
+		                G_SETTINGS_BIND_DEFAULT);
 	} else {
 		g_warning("Unable to get settings for '" SETTINGS_INTERFACE "'");
 	}
@@ -533,6 +553,18 @@
 		}
 		break;
 	}
+	case PROP_SHOW_WEEK_NUMBERS: {
+		if (g_value_get_boolean(value) != self->priv->show_week_numbers) {
+			GtkCalendarDisplayOptions flags = ido_calendar_menu_item_get_display_options (self->priv->ido_calendar);
+			if (g_value_get_boolean(value) == TRUE)
+				flags |= GTK_CALENDAR_SHOW_WEEK_NUMBERS;
+			else
+				flags &= ~GTK_CALENDAR_SHOW_WEEK_NUMBERS;
+			ido_calendar_menu_item_set_display_options (self->priv->ido_calendar, flags);
+			self->priv->show_week_numbers = g_value_get_boolean(value);
+		}
+		break;
+	}
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 		return;
@@ -588,6 +620,9 @@
 	case PROP_CUSTOM_TIME_FORMAT:
 		g_value_set_string(value, self->priv->custom_string);
 		break;
+	case PROP_SHOW_WEEK_NUMBERS:
+		g_value_set_boolean(value, self->priv->show_week_numbers);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 		return;
@@ -1249,6 +1284,15 @@
 		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 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));
+	} else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_CLEAR_MARKS)) {
+		ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data));
 	} else {
 		g_warning("Indicator Item property '%s' unknown", prop);
 	}
@@ -1332,6 +1376,20 @@
 	return TRUE;
 }
 
+static void
+month_changed_cb (IdoCalendarMenuItem *ido, 
+                  gpointer        user_data) 
+{
+	gchar datestring[20];
+	guint d,m,y;
+	DbusmenuMenuitem * item = DBUSMENU_MENUITEM (user_data);
+	ido_calendar_menu_item_get_date(ido, &y, &m, &d);
+	g_sprintf(datestring, "%d-%d-%d", y, m, d);
+	GVariant *variant = g_variant_new_string(datestring);
+	guint timestamp = (guint)time(NULL);
+	dbusmenu_menuitem_handle_event(DBUSMENU_MENUITEM(item), "event::month-changed", variant, timestamp);
+	g_debug("Got month changed signal: %s", datestring);
+}
 
 static gboolean
 new_calendar_item (DbusmenuMenuitem * newitem,
@@ -1356,7 +1414,7 @@
 	self->priv->ido_calendar = ido;
 
 	dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(ido), parent);
-
+	g_signal_connect_after(ido, "month-changed", G_CALLBACK(month_changed_cb), (gpointer)newitem);
 	return TRUE;
 }
 


Follow ups