[annum] Specialize the 'today' view
- From: Gustavo Noronha Silva <gns src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [annum] Specialize the 'today' view
- Date: Tue, 26 Jan 2010 16:38:10 +0000 (UTC)
commit 8b4a92f02c064ef219d48fd8202a0c3a5a4e6f85
Author: Gustavo Noronha Silva <gustavo noronha collabora co uk>
Date: Tue Jan 26 14:36:14 2010 -0200
Specialize the 'today' view
src/annum-shell-view.c | 48 +++++++++++++++++++++++++++++++++++++++
src/annum-shell-view.h | 2 +
src/annum-shell-window.c | 56 +++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 105 insertions(+), 1 deletions(-)
---
diff --git a/src/annum-shell-view.c b/src/annum-shell-view.c
index 5b0f02e..1d3c12c 100644
--- a/src/annum-shell-view.c
+++ b/src/annum-shell-view.c
@@ -48,6 +48,13 @@ struct _AnnumShellViewPrivate {
#define GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), ANNUM_TYPE_SHELL_VIEW, AnnumShellViewPrivate))
+enum {
+ DATE_CHANGED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0, };
+
static void
annum_shell_view_date_navigator_selection_changed_cb (AnnumShellView * self,
ECalendarItem * calitem)
@@ -170,6 +177,8 @@ annum_shell_view_date_navigator_selection_changed_cb (AnnumShellView * self,
gnome_calendar_set_range_selected (calendar, TRUE);
gnome_calendar_notify_dates_shown_changed (calendar);
+
+ g_signal_emit (self, signals[DATE_CHANGED], 0, switch_to);
}
static struct tm
@@ -496,6 +505,17 @@ static void annum_shell_view_class_init (AnnumShellViewClass * klass)
shell_view_class->execute_search = NULL;
shell_view_class->update_actions = NULL;
+ signals[DATE_CHANGED] = g_signal_new ("date-changed",
+ ANNUM_TYPE_SHELL_VIEW,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__INT, /* FIXME: ENUM */
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_INT);
+
g_type_class_add_private (klass, sizeof (AnnumShellViewPrivate));
}
@@ -551,3 +571,31 @@ static void annum_shell_view_init (AnnumShellView * self G_GNUC_UNUSED)
*/
e_shell_view_set_view_id (E_SHELL_VIEW (self), "Day_View");
}
+
+
+/**
+ * annum_shell_view_goto_today
+ * @self: the #AnnumShellView
+ *
+ * This function handles the gory details of the special "today"
+ * view. It makes sure only one day is selected in the date navigator,
+ * and that said day is today.
+ */
+void annum_shell_view_goto_today (AnnumShellView *self)
+{
+ GDate *today;
+ GnomeCalendar *calendar;
+ ECalendar *date_navigator;
+
+ today = g_date_new ();
+ g_date_set_time_t (today, time NULL);
+
+ calendar = annum_shell_content_get_calendar (self->priv->prox_shell_content);
+ gnome_calendar_goto_today (calendar);
+
+ date_navigator = annum_shell_sidebar_get_date_navigator (self->priv->prox_shell_sidebar);
+ e_calendar_item_set_selection (date_navigator->calitem,
+ today, today);
+
+ g_date_free (today);
+}
diff --git a/src/annum-shell-view.h b/src/annum-shell-view.h
index 2998507..b6c1c47 100644
--- a/src/annum-shell-view.h
+++ b/src/annum-shell-view.h
@@ -48,4 +48,6 @@ GtkWidget *annum_shell_view_get_content_view (AnnumShellView * shell_view);
GtkWidget *annum_shell_view_get_sidebar (AnnumShellView * shell_view);
+void annum_shell_view_goto_today (AnnumShellView *self);
+
#endif
diff --git a/src/annum-shell-window.c b/src/annum-shell-window.c
index c9255a7..7affa4e 100644
--- a/src/annum-shell-window.c
+++ b/src/annum-shell-window.c
@@ -20,8 +20,10 @@
#include "config.h"
#include "annum-shell-window.h"
+#include "annum-shell-sidebar.h"
#include "annum-shell-view.h"
#include <glib/gi18n.h>
+#include <calendar/gui/gnome-cal.h>
#include <shell/e-shell-window.h>
G_DEFINE_TYPE (AnnumShellWindow, annum_shell_window, E_TYPE_SHELL_WINDOW)
@@ -55,6 +57,7 @@ enum {
ANNUM_VIEW_TODAY,
ANNUM_VIEW_WEEK,
ANNUM_VIEW_MONTH,
+ ANNUM_VIEW_DAY,
ANNUM_LAST_VIEW
};
@@ -65,8 +68,11 @@ static void annum_shell_window_change_view_cb (GtkAction *action, GtkRadioAction
switch (gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action))) {
case ANNUM_VIEW_TODAY:
+ annum_shell_view_goto_today (priv->shell_view);
+ return;
+ case ANNUM_VIEW_DAY:
view_id = "Day_View";
- break;
+ return;
case ANNUM_VIEW_WEEK:
view_id = "Week_View";
break;
@@ -85,6 +91,47 @@ static void annum_shell_window_change_view_cb (GtkAction *action, GtkRadioAction
g_object_set (priv->shell_view, "view-id", view_id, NULL);
}
+static void date_changed_cb (AnnumShellWindow *self,
+ GnomeCalendarViewType view,
+ AnnumShellView *shell_view)
+{
+ const char *view_id;
+ ECalendar *date_navigator;
+ GDate *today;
+ GDate start;
+ GDate end;
+
+ if (view != GNOME_CAL_DAY_VIEW)
+ return;
+
+ /* Week_View also uses GNOME_CAL_DAY_VIEW, so make sure */
+ view_id = e_shell_view_get_view_id (E_SHELL_VIEW (shell_view));
+ if (!g_strcmp0 (view_id, "Week_View"))
+ return;
+
+ /* DAY_VIEW is treated specially, because we only want to have
+ * the button toggled if we are showing today, not any other
+ * day
+ */
+
+ date_navigator = annum_shell_sidebar_get_date_navigator (ANNUM_SHELL_SIDEBAR (self->priv->sidebar));
+
+ today = g_date_new ();
+ g_date_set_time_t (today, time (NULL));
+
+ e_calendar_item_get_selection (date_navigator->calitem,
+ &start, &end);
+
+ if (g_date_compare (today, &start) || g_date_compare (&start, &end)) {
+ GtkAction *action = gtk_action_group_get_action (self->priv->action_group,
+ "ShowDay");
+ gtk_radio_action_set_current_value (GTK_RADIO_ACTION (action),
+ ANNUM_VIEW_DAY);
+ }
+
+ g_date_free (today);
+}
+
static void close_window_cb (GtkButton *button, AnnumShellWindow *self)
{
EShell *shell;
@@ -103,6 +150,9 @@ static GtkRadioActionEntry annum_view_actions[] = {
{ "ShowMonth", NULL, N_("Month"), "<Alt>3",
N_("Month's events"), ANNUM_VIEW_MONTH },
+
+ { "ShowDay", NULL, N_("Day"), NULL,
+ N_("Day's events"), ANNUM_VIEW_DAY },
};
static GObject *constructor (GType type,
@@ -146,6 +196,10 @@ static GObject *constructor (GType type,
"action", radio_action,
"shell-window", self, NULL);
+ g_signal_connect_swapped (priv->shell_view, "date-changed",
+ G_CALLBACK (date_changed_cb),
+ self);
+
/* Main layout */
priv->vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (self), priv->vbox);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]