[evolution] Bug #613352 - Changed time range not propagated to calendar



commit 04bac0cf69e4dd26274cfe5fcb9d077a759c9fd6
Author: Milan Crha <mcrha redhat com>
Date:   Thu Apr 1 16:16:25 2010 +0200

    Bug #613352 - Changed time range not propagated to calendar

 calendar/gui/e-cal-list-view.c              |    9 ++
 calendar/gui/gnome-cal.c                    |  186 +++++++++++++++++++++++----
 calendar/gui/gnome-cal.h                    |    4 +
 modules/calendar/e-cal-shell-view-private.c |    6 +-
 shell/e-shell-view.c                        |   59 +++++++++-
 shell/e-shell-view.h                        |    4 +
 6 files changed, 238 insertions(+), 30 deletions(-)
---
diff --git a/calendar/gui/e-cal-list-view.c b/calendar/gui/e-cal-list-view.c
index 1d3e0e1..0a3c3de 100644
--- a/calendar/gui/e-cal-list-view.c
+++ b/calendar/gui/e-cal-list-view.c
@@ -528,6 +528,15 @@ e_cal_list_view_get_visible_time_range (ECalendarView *cal_view, time_t *start_t
 		return TRUE;
 	}
 
+	if (!n_rows) {
+		ECalModel *model = e_calendar_view_get_model (cal_view);
+
+		/* Use time range set in the model when nothing shown in the list view */
+		e_cal_model_get_time_range (model, start_time, end_time);
+
+		return TRUE;
+	}
+
 	return FALSE;
 }
 
diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c
index ea02e1c..b173bcc 100644
--- a/calendar/gui/gnome-cal.c
+++ b/calendar/gui/gnome-cal.c
@@ -66,6 +66,8 @@
 #include "misc.h"
 #include "ea-calendar.h"
 #include "common/authentication.h"
+#include "e-memo-table.h"
+#include "e-task-table.h"
 
 #define d(x)
 
@@ -88,6 +90,8 @@ struct _GnomeCalendarPrivate {
 	GtkWidget   *hpane;
 
 	ECalendar   *date_navigator;
+	GtkWidget   *memo_table; /* EMemoTable, but can be NULL */
+	GtkWidget   *task_table; /* ETaskTable, but can be NULL */
 
 	/* Calendar query for the date navigator */
 	GMutex      *dn_query_lock;
@@ -134,7 +138,9 @@ struct _GnomeCalendarPrivate {
 enum {
 	PROP_0,
 	PROP_DATE_NAVIGATOR,
-	PROP_VIEW
+	PROP_VIEW,
+	PROP_MEMO_TABLE,
+	PROP_TASK_TABLE
 };
 
 enum {
@@ -167,6 +173,7 @@ typedef void (*MessageFunc) (Message *msg);
 
 struct _Message {
 	MessageFunc func;
+	GSourceFunc done;
 };
 
 static void
@@ -175,6 +182,8 @@ message_proxy (Message *msg)
 	g_return_if_fail (msg->func != NULL);
 
 	msg->func (msg);
+	if (msg->done)
+		g_idle_add (msg->done, msg);
 }
 
 static gpointer
@@ -334,6 +343,18 @@ gnome_calendar_set_property (GObject *object,
 				GNOME_CALENDAR (object),
 				g_value_get_int (value));
 			return;
+
+		case PROP_MEMO_TABLE:
+			gnome_calendar_set_memo_table (
+				GNOME_CALENDAR (object),
+				g_value_get_object (value));
+			return;
+
+		case PROP_TASK_TABLE:
+			gnome_calendar_set_task_table (
+				GNOME_CALENDAR (object),
+				g_value_get_object (value));
+			return;
 	}
 
 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -357,6 +378,18 @@ gnome_calendar_get_property (GObject *object,
 				value, gnome_calendar_get_view (
 				GNOME_CALENDAR (object)));
 			return;
+
+		case PROP_MEMO_TABLE:
+			g_value_set_object (
+				value, gnome_calendar_get_memo_table (
+				GNOME_CALENDAR (object)));
+			return;
+
+		case PROP_TASK_TABLE:
+			g_value_set_object (
+				value, gnome_calendar_get_task_table (
+				GNOME_CALENDAR (object)));
+			return;
 	}
 
 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -494,6 +527,26 @@ gnome_calendar_class_init (GnomeCalendarClass *class)
 			GNOME_CAL_DAY_VIEW,
 			G_PARAM_READWRITE));
 
+	g_object_class_install_property (
+		object_class,
+		PROP_MEMO_TABLE,
+		g_param_spec_object (
+			"memo-table",
+			"Memo table",
+			NULL,
+			E_TYPE_MEMO_TABLE,
+			G_PARAM_READWRITE));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_TASK_TABLE,
+		g_param_spec_object (
+			"task-table",
+			"Task table",
+			NULL,
+			E_TYPE_TASK_TABLE,
+			G_PARAM_READWRITE));
+
 	signals[DATES_SHOWN_CHANGED] =
 		g_signal_new ("dates_shown_changed",
 				G_TYPE_FROM_CLASS (object_class),
@@ -981,7 +1034,7 @@ update_query_async (struct _date_query_msg *msg)
 {
 	GnomeCalendar *gcal = msg->gcal;
 	GnomeCalendarPrivate *priv;
-	ECalView *old_query;
+	ECalView *new_query;
 	gchar *real_sexp;
 	GList *list, *iter;
 
@@ -1013,8 +1066,8 @@ update_query_async (struct _date_query_msg *msg)
 			continue;
 
 try_again:
-		old_query = NULL;
-		if (!e_cal_get_query (client, real_sexp, &old_query, &error)) {
+		new_query = NULL;
+		if (!e_cal_get_query (client, real_sexp, &new_query, &error)) {
 			/* If calendar is busy try again for 3 times. */
 			if (error->code == E_CALENDAR_STATUS_BUSY && tries != 10) {
 				tries++;
@@ -1031,18 +1084,19 @@ try_again:
 			continue;
 		}
 
-		g_signal_connect (old_query, "objects_added",
+		g_signal_connect (new_query, "objects_added",
 				  G_CALLBACK (dn_e_cal_view_objects_added_cb), gcal);
-		g_signal_connect (old_query, "objects_modified",
+		g_signal_connect (new_query, "objects_modified",
 				  G_CALLBACK (dn_e_cal_view_objects_modified_cb), gcal);
-		g_signal_connect (old_query, "objects_removed",
+		g_signal_connect (new_query, "objects_removed",
 				  G_CALLBACK (dn_e_cal_view_objects_removed_cb), gcal);
-		g_signal_connect (old_query, "view_done",
+		g_signal_connect (new_query, "view_done",
 				  G_CALLBACK (dn_e_cal_view_done_cb), gcal);
 
-		priv->dn_queries = g_list_append (priv->dn_queries, old_query);
-
-		e_cal_view_start (old_query);
+		g_mutex_lock (priv->dn_query_lock);
+		priv->dn_queries = g_list_append (priv->dn_queries, new_query);
+		e_cal_view_start (new_query);
+		g_mutex_unlock (priv->dn_query_lock);
 	}
 
 	g_list_foreach (list, (GFunc) g_object_unref, NULL);
@@ -1068,6 +1122,7 @@ gnome_calendar_update_query (GnomeCalendar *gcal)
 
 	msg = g_slice_new0 (struct _date_query_msg);
 	msg->header.func = (MessageFunc) update_query_async;
+	msg->header.done = NULL;
 	msg->gcal = g_object_ref (gcal);
 
 	message_push ((Message *) msg);
@@ -1119,9 +1174,6 @@ gnome_calendar_set_search_query (GnomeCalendar *gcal,
 			gnome_calendar_update_date_navigator (gcal);
 	} else
 		e_cal_model_set_search_query (model, sexp);
-
-	/* Set the query on the task pad */
-	update_todo_view (gcal);
 }
 
 static void
@@ -1151,7 +1203,6 @@ struct _mupdate_todo_msg {
 	GnomeCalendar *gcal;
 };
 
-#if 0 /* KILL-BONOBO */
 static void
 update_todo_view_async (struct _mupdate_todo_msg *msg)
 {
@@ -1165,6 +1216,8 @@ update_todo_view_async (struct _mupdate_todo_msg *msg)
 	gcal = msg->gcal;
 	priv = gcal->priv;
 
+	g_return_if_fail (priv->task_table != NULL);
+
 	g_mutex_lock (priv->todo_update_lock);
 
 	/* Set the query on the task pad */
@@ -1173,7 +1226,7 @@ update_todo_view_async (struct _mupdate_todo_msg *msg)
 		priv->todo_sexp = NULL;
 	}
 
-	model = e_calendar_table_get_model (E_CALENDAR_TABLE (priv->todo));
+	model = e_task_table_get_model (E_TASK_TABLE (priv->task_table));
 
 	if ((sexp = calendar_config_get_hide_completed_tasks_sexp (FALSE)) != NULL) {
 		priv->todo_sexp = g_strdup_printf ("(and %s %s)", sexp,
@@ -1185,40 +1238,68 @@ update_todo_view_async (struct _mupdate_todo_msg *msg)
 		e_cal_model_set_search_query (model, priv->todo_sexp);
 	}
 
+	update_memo_view (msg->gcal);
+
 	g_mutex_unlock (priv->todo_update_lock);
+}
+
+static gboolean
+update_todo_view_done (struct _mupdate_todo_msg *msg)
+{
+	GnomeCalendar *gcal;
+	GnomeCalendarPrivate *priv;
+
+	g_return_val_if_fail (msg != NULL, FALSE);
+
+	gcal = msg->gcal;
+	priv = gcal->priv;
+
+	g_return_val_if_fail (priv->task_table != NULL, FALSE);
+	g_return_val_if_fail (priv->memo_table != NULL, FALSE);
+
+	e_shell_view_unblock_update_actions (e_task_table_get_shell_view (E_TASK_TABLE (priv->task_table)));
+	e_shell_view_unblock_update_actions (e_memo_table_get_shell_view (E_MEMO_TABLE (priv->memo_table)));
 
 	g_object_unref (msg->gcal);
 	g_slice_free (struct _mupdate_todo_msg, msg);
+
+	return FALSE;
 }
-#endif
 
 static void
 update_todo_view (GnomeCalendar *gcal)
 {
-#if 0 /* KILL-BONOBO */
 	struct _mupdate_todo_msg *msg;
 
+	/* they are both or none anyway */
+	if (!gcal->priv->task_table || !gcal->priv->memo_table)
+		return;
+
 	msg = g_slice_new0 (struct _mupdate_todo_msg);
 	msg->header.func = (MessageFunc) update_todo_view_async;
+	msg->header.done = (GSourceFunc) update_todo_view_done;
 	msg->gcal = g_object_ref (gcal);
 
+	e_shell_view_block_update_actions (e_task_table_get_shell_view (E_TASK_TABLE (gcal->priv->task_table)));
+	e_shell_view_block_update_actions (e_memo_table_get_shell_view (E_MEMO_TABLE (gcal->priv->memo_table)));
+
 	message_push ((Message *) msg);
-#endif
 }
 
 static void
 update_memo_view (GnomeCalendar *gcal)
 {
-#if 0 /* KILL-BONOBO */
 	GnomeCalendarPrivate *priv;
 	ECalModel *model, *view_model;
-	time_t start, end;
+	time_t start = -1, end = -1;
 	gchar *iso_start, *iso_end;
 
 	priv = gcal->priv;
+	if (!priv->memo_table)
+		return;
 
 	/* Set the query on the memo pad*/
-	model = e_memo_table_get_model (E_MEMO_TABLE (priv->memo));
+	model = e_memo_table_get_model (E_MEMO_TABLE (priv->memo_table));
 	view_model = gnome_calendar_get_model (gcal);
 	e_cal_model_get_time_range (view_model, &start, &end);
 
@@ -1230,9 +1311,9 @@ update_memo_view (GnomeCalendar *gcal)
 			g_free (priv->memo_sexp);
 		}
 
-		priv->memo_sexp = g_strdup_printf ("(or (not (has-start?)) (and (occur-in-time-range? (make-time \"%s\")"
+		priv->memo_sexp = g_strdup_printf ("(and (or (not (has-start?)) (occur-in-time-range? (make-time \"%s\")"
 				" (make-time \"%s\"))"
-				"  %s))",
+				"  ) %s)",
 				iso_start, iso_end,
 				priv->sexp ? priv->sexp : "");
 
@@ -1241,7 +1322,6 @@ update_memo_view (GnomeCalendar *gcal)
 		g_free (iso_start);
 		g_free (iso_end);
 	}
-#endif
 }
 
 static void
@@ -1322,7 +1402,7 @@ setup_widgets (GnomeCalendar *gcal)
 	/* The Marcus Bains line */
 	priv->update_marcus_bains_line_timeout = g_timeout_add_full (G_PRIORITY_LOW, 60000, (GSourceFunc) update_marcus_bains_line_cb, gcal, NULL);
 
-	update_memo_view (gcal);
+	/* update_memo_view (gcal); */
 }
 
 /* Object initialization function for the gnome calendar */
@@ -1817,6 +1897,58 @@ gnome_calendar_set_date_navigator (GnomeCalendar *gcal,
 	g_object_notify (G_OBJECT (gcal), "date-navigator");
 }
 
+GtkWidget *
+gnome_calendar_get_memo_table (GnomeCalendar *gcal)
+{
+	g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL);
+
+	return gcal->priv->memo_table;
+}
+
+void
+gnome_calendar_set_memo_table (GnomeCalendar *gcal, GtkWidget *memo_table)
+{
+	g_return_if_fail (GNOME_IS_CALENDAR (gcal));
+
+	if (memo_table != NULL) {
+		g_return_if_fail (E_IS_MEMO_TABLE (memo_table));
+		g_object_ref (memo_table);
+	}
+
+	if (gcal->priv->memo_table != NULL)
+		g_object_unref (gcal->priv->memo_table);
+
+	gcal->priv->memo_table = memo_table;
+
+	g_object_notify (G_OBJECT (gcal), "memo-table");
+}
+
+GtkWidget *
+gnome_calendar_get_task_table (GnomeCalendar *gcal)
+{
+	g_return_val_if_fail (GNOME_IS_CALENDAR (gcal), NULL);
+
+	return gcal->priv->task_table;
+}
+
+void
+gnome_calendar_set_task_table (GnomeCalendar *gcal, GtkWidget *task_table)
+{
+	g_return_if_fail (GNOME_IS_CALENDAR (gcal));
+
+	if (task_table != NULL) {
+		g_return_if_fail (E_IS_TASK_TABLE (task_table));
+		g_object_ref (task_table);
+	}
+
+	if (gcal->priv->task_table != NULL)
+		g_object_unref (gcal->priv->task_table);
+
+	gcal->priv->task_table = task_table;
+
+	g_object_notify (G_OBJECT (gcal), "task-table");
+}
+
 /**
  * gnome_calendar_get_model:
  * @gcal: A calendar view.
@@ -2051,7 +2183,7 @@ gnome_calendar_notify_dates_shown_changed (GnomeCalendar *gcal)
 		gtk_widget_queue_draw (GTK_WIDGET (calendar_view));
 		g_signal_emit (gcal, signals[DATES_SHOWN_CHANGED], 0);
 	}
-	update_memo_view (gcal);
+	update_todo_view (gcal);
 }
 
 /* Returns the number of selected events (0 or 1 at present). */
diff --git a/calendar/gui/gnome-cal.h b/calendar/gui/gnome-cal.h
index 8511f0f..52047a0 100644
--- a/calendar/gui/gnome-cal.h
+++ b/calendar/gui/gnome-cal.h
@@ -119,6 +119,10 @@ ECalendar *	gnome_calendar_get_date_navigator
 void		gnome_calendar_set_date_navigator
 						(GnomeCalendar *gcal,
 						 ECalendar *date_navigator);
+GtkWidget *	gnome_calendar_get_memo_table	(GnomeCalendar *gcal);
+void		gnome_calendar_set_memo_table	(GnomeCalendar *gcal, GtkWidget *memo_table);
+GtkWidget *	gnome_calendar_get_task_table	(GnomeCalendar *gcal);
+void		gnome_calendar_set_task_table	(GnomeCalendar *gcal, GtkWidget *task_table);
 ECalModel *	gnome_calendar_get_model	(GnomeCalendar *gcal);
 void		gnome_calendar_update_query	(GnomeCalendar *gcal);
 void		gnome_calendar_set_search_query	(GnomeCalendar *gcal,
diff --git a/modules/calendar/e-cal-shell-view-private.c b/modules/calendar/e-cal-shell-view-private.c
index 5576224..1c9c268 100644
--- a/modules/calendar/e-cal-shell-view-private.c
+++ b/modules/calendar/e-cal-shell-view-private.c
@@ -219,7 +219,7 @@ cal_shell_view_date_navigator_scroll_event_cb (ECalShellView *cal_shell_view,
 	 *     we could move this handler into ECalShellSidebar. */
 	e_calendar_item_set_selection (calitem, &start_date, &end_date);
 
-	cal_shell_view_date_navigator_date_range_changed_cb (
+	cal_shell_view_date_navigator_selection_changed_cb (
 		cal_shell_view, calitem);
 }
 
@@ -459,8 +459,10 @@ e_cal_shell_view_private_constructed (ECalShellView *cal_shell_view)
 	selector = e_cal_shell_sidebar_get_selector (cal_shell_sidebar);
 	date_navigator = e_cal_shell_sidebar_get_date_navigator (cal_shell_sidebar);
 
-	/* Give GnomeCalendar a handle to the date navigator. */
+	/* Give GnomeCalendar a handle to the date navigator, memo and task table. */
 	gnome_calendar_set_date_navigator (calendar, date_navigator);
+	gnome_calendar_set_memo_table (calendar, memo_table ? GTK_WIDGET (memo_table) : NULL);
+	gnome_calendar_set_task_table (calendar, task_table ? GTK_WIDGET (task_table) : NULL);
 
 	e_calendar_item_set_get_time_callback (
 		date_navigator->calitem, (ECalendarItemGetTimeCallback)
diff --git a/shell/e-shell-view.c b/shell/e-shell-view.c
index 51ad7dd..6cae11c 100644
--- a/shell/e-shell-view.c
+++ b/shell/e-shell-view.c
@@ -71,6 +71,9 @@ struct _EShellViewPrivate {
 
 	EFilterRule *search_rule;
 	guint execute_search_blocked;
+
+	guint update_actions_blocked;
+	gboolean update_actions_called;
 };
 
 enum {
@@ -730,6 +733,9 @@ shell_view_update_actions (EShellView *shell_view)
 	EShellWindow *shell_window;
 	EFocusTracker *focus_tracker;
 
+	g_return_if_fail (!shell_view->priv->update_actions_blocked);
+	g_return_if_fail (e_shell_view_is_active (shell_view));
+
 	shell_window = e_shell_view_get_shell_window (shell_view);
 	focus_tracker = e_shell_window_get_focus_tracker (shell_window);
 
@@ -1664,13 +1670,64 @@ e_shell_view_unblock_execute_search (EShellView *shell_view)
  * #EShellView::update-actions signal is typically emitted just before
  * showing a popup menu or just after the user selects an item in the
  * shell view.
+ *
+ * Emission can be blocked by e_shell_view_block_update_actions().
  **/
 void
 e_shell_view_update_actions (EShellView *shell_view)
 {
 	g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
 
-	g_signal_emit (shell_view, signals[UPDATE_ACTIONS], 0);
+	if (!e_shell_view_is_active (shell_view))
+		return;
+
+	if (shell_view->priv->update_actions_blocked > 0) {
+		shell_view->priv->update_actions_called = TRUE;
+	} else {
+		shell_view->priv->update_actions_called = FALSE;
+		g_signal_emit (shell_view, signals[UPDATE_ACTIONS], 0);
+	}
+}
+
+/**
+ * e_shell_view_block_update_actions:
+ * @shell_view: an #EShellView
+ *
+ * Block emission of #EShellView::update-actions signal through
+ * e_shell_view_update_actions(). The emission si blocked until
+ * e_shell_view_unblock_update_actions() is called same times as
+ * this function.
+ **/
+void
+e_shell_view_block_update_actions (EShellView *shell_view)
+{
+	g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
+	g_return_if_fail (shell_view->priv->update_actions_blocked + 1 != 0);
+
+	shell_view->priv->update_actions_blocked++;
+	if (shell_view->priv->update_actions_blocked == 1)
+		shell_view->priv->update_actions_called = FALSE;
+}
+
+/**
+ * e_shell_view_unblock_update_actions:
+ * @shell_view: an #EShellView
+ *
+ * Unblock emission of #EShellView::update-actions signal through
+ * e_shell_view_update_actions(), previously blocked by function
+ * e_shell_view_block_update_actions().
+ **/
+void
+e_shell_view_unblock_update_actions (EShellView *shell_view)
+{
+	g_return_if_fail (E_IS_SHELL_VIEW (shell_view));
+	g_return_if_fail (shell_view->priv->update_actions_blocked > 0);
+
+	shell_view->priv->update_actions_blocked--;
+	if (!shell_view->priv->update_actions_blocked && shell_view->priv->update_actions_called) {
+		shell_view->priv->update_actions_called = FALSE;
+		e_shell_view_update_actions (shell_view);
+	}
 }
 
 /**
diff --git a/shell/e-shell-view.h b/shell/e-shell-view.h
index 2cf2136..4387082 100644
--- a/shell/e-shell-view.h
+++ b/shell/e-shell-view.h
@@ -215,6 +215,10 @@ void		e_shell_view_block_execute_search
 void		e_shell_view_unblock_execute_search
 						(EShellView *shell_view);
 void		e_shell_view_update_actions	(EShellView *shell_view);
+void		e_shell_view_block_update_actions
+						(EShellView *shell_view);
+void		e_shell_view_unblock_update_actions
+						(EShellView *shell_view);
 GtkWidget *	e_shell_view_show_popup_menu	(EShellView *shell_view,
 						 const gchar *widget_path,
 						 GdkEventButton *event);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]