[annum] Implement top bar with buttons to change the view, and close the window



commit fedad522c40349b0248ba8a916a9a2b27e5667f0
Author: Gustavo Noronha Silva <gustavo noronha collabora co uk>
Date:   Mon Jan 25 18:22:48 2010 -0200

    Implement top bar with buttons to change the view, and close the window

 src/annum-shell-window.c |  132 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 128 insertions(+), 4 deletions(-)
---
diff --git a/src/annum-shell-window.c b/src/annum-shell-window.c
index aa914b8..c9255a7 100644
--- a/src/annum-shell-window.c
+++ b/src/annum-shell-window.c
@@ -29,8 +29,20 @@ G_DEFINE_TYPE (AnnumShellWindow, annum_shell_window, E_TYPE_SHELL_WINDOW)
 struct _AnnumShellWindowPrivate {
 	AnnumShellView *shell_view;
 
+	GtkWidget *vbox;
+	GtkWidget *toolbox;
 	GtkWidget *hpaned;
 
+	GtkActionGroup *action_group;
+
+	GtkWidget *today_button;
+	GtkWidget *week_button;
+	GtkWidget *month_button;
+
+	GtkWidget *quickadd_entry;
+
+	GtkWidget *quit_button;
+
 	EShellSidebar *sidebar;
 	EShellContent *content_view;
 };
@@ -38,6 +50,61 @@ struct _AnnumShellWindowPrivate {
 #define GET_PRIVATE(o)                                                  \
   (G_TYPE_INSTANCE_GET_PRIVATE ((o), ANNUM_TYPE_SHELL_WINDOW, AnnumShellWindowPrivate))
 
+/* Action callbacks */
+enum {
+	ANNUM_VIEW_TODAY,
+	ANNUM_VIEW_WEEK,
+	ANNUM_VIEW_MONTH,
+	ANNUM_LAST_VIEW
+};
+
+static void annum_shell_window_change_view_cb (GtkAction *action, GtkRadioAction *current, AnnumShellWindow *self)
+{
+	AnnumShellWindowPrivate *priv = self->priv;
+	const char *view_id = NULL;
+
+	switch (gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action))) {
+	case ANNUM_VIEW_TODAY:
+		view_id = "Day_View";
+		break;
+	case ANNUM_VIEW_WEEK:
+		view_id = "Week_View";
+		break;
+	case ANNUM_VIEW_MONTH:
+		view_id = "Month_View";
+		break;
+	default:
+		g_warning ("Unknown view asked for!");
+		break;
+	}
+
+	if (view_id == NULL)
+		return;
+
+	/* See annum-shell-backend.c's class init for the view name */
+	g_object_set (priv->shell_view, "view-id", view_id, NULL);
+}
+
+static void close_window_cb (GtkButton *button, AnnumShellWindow *self)
+{
+	EShell *shell;
+
+	shell = e_shell_window_get_shell (E_SHELL_WINDOW (self));
+	e_shell_quit (shell);
+}
+
+/* Action definitions */
+static GtkRadioActionEntry annum_view_actions[] = {
+	{ "ShowToday", NULL, N_("Today"), "<Alt>1",
+	  N_("Today's events"), ANNUM_VIEW_TODAY },
+
+	{ "ShowWeek", NULL, N_("Week"), "<Alt>2",
+	  N_("Week's events"), ANNUM_VIEW_WEEK },
+
+	{ "ShowMonth", NULL, N_("Month"), "<Alt>3",
+	  N_("Month's events"), ANNUM_VIEW_MONTH },
+};
+
 static GObject *constructor (GType type,
 			     guint n_properties,
 			     GObjectConstructParam * properties)
@@ -46,10 +113,12 @@ static GObject *constructor (GType type,
 	AnnumShellWindowPrivate *priv;
 	GObject *object;
 	GObjectClass *parent_class;
+	GtkAction *action;
 	GdkScreen *screen;
 	gint monitor;
 	GdkRectangle rect;
-	GtkRadioAction *action;
+	GtkRadioAction *radio_action;
+	GtkWidget *button_image;
 
 	parent_class = G_OBJECT_CLASS (annum_shell_window_parent_class);
 	object = parent_class->constructor (type, n_properties, properties);
@@ -71,16 +140,50 @@ static GObject *constructor (GType type,
 	/* This is a fake action, just because EShellView needs one, but we
 	 * have only one view, so an action to switch views is needless.
 	 */
-	action = gtk_radio_action_new ("Calendar", NULL, NULL, NULL, 0);
+	radio_action = gtk_radio_action_new ("Calendar", NULL, NULL, NULL, 0);
 
 	priv->shell_view = g_object_new (ANNUM_TYPE_SHELL_VIEW,
-					 "action", action,
+					 "action", radio_action,
 					 "shell-window", self, NULL);
 
+	/* Main layout */
+	priv->vbox = gtk_vbox_new (FALSE, 0);
+	gtk_container_add (GTK_CONTAINER (self), priv->vbox);
+
+	priv->toolbox = gtk_hbox_new (FALSE, 0);
+	gtk_container_set_border_width (GTK_CONTAINER (priv->toolbox), 6);
+	gtk_box_pack_start (GTK_BOX (priv->vbox), priv->toolbox,
+			    FALSE, FALSE, 0);
+
+	/* Top toolbox */
+	priv->today_button = gtk_toggle_button_new ();
+	gtk_box_pack_start (GTK_BOX (priv->toolbox), priv->today_button, FALSE, FALSE, 0);
+
+	priv->week_button = gtk_toggle_button_new ();
+	gtk_box_pack_start (GTK_BOX (priv->toolbox), priv->week_button, FALSE, FALSE, 0);
+
+	priv->month_button = gtk_toggle_button_new ();
+	gtk_box_pack_start (GTK_BOX (priv->toolbox), priv->month_button, FALSE, FALSE, 0);
+
+	priv->quickadd_entry = gtk_entry_new ();
+	gtk_entry_set_text (GTK_ENTRY (priv->quickadd_entry), "This space intentionally left blank.");
+	gtk_widget_set_sensitive (priv->quickadd_entry, FALSE);
+	gtk_box_pack_start (GTK_BOX (priv->toolbox), priv->quickadd_entry, TRUE, TRUE, 0);
+
+	priv->quit_button = gtk_button_new ();
+	g_signal_connect (priv->quit_button, "clicked",
+			  G_CALLBACK (close_window_cb), self);
+	gtk_box_pack_start (GTK_BOX (priv->toolbox), priv->quit_button, FALSE, FALSE, 0);
+
+	button_image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_LARGE_TOOLBAR);
+	gtk_container_add (GTK_CONTAINER (priv->quit_button), button_image);
+
+        /* Sidebar, and main content view */
 	priv->hpaned = gtk_hpaned_new ();
 	/* FIXME: store the position somehow? */
 	gtk_paned_set_position (GTK_PANED (priv->hpaned), 250);
-	gtk_container_add (GTK_CONTAINER (self), priv->hpaned);
+	gtk_box_pack_start (GTK_BOX (priv->vbox), priv->hpaned,
+			    TRUE, TRUE, 0);
 
 	priv->sidebar =
 	    e_shell_view_get_shell_sidebar (E_SHELL_VIEW (priv->shell_view));
@@ -91,6 +194,27 @@ static GObject *constructor (GType type,
 	gtk_paned_add2 (GTK_PANED (priv->hpaned),
 			GTK_WIDGET (priv->content_view));
 
+	/* Set up actions */
+	priv->action_group = gtk_action_group_new ("AnnumActions");
+	gtk_action_group_add_radio_actions (priv->action_group,
+					    annum_view_actions,
+					    G_N_ELEMENTS (annum_view_actions),
+					    ANNUM_VIEW_TODAY,
+					    G_CALLBACK (annum_shell_window_change_view_cb),
+					    self);
+
+	/* Today */
+	action = gtk_action_group_get_action (priv->action_group, "ShowToday");
+	gtk_activatable_set_related_action (GTK_ACTIVATABLE (priv->today_button), action);
+
+	/* Week */
+	action = gtk_action_group_get_action (priv->action_group, "ShowWeek");
+	gtk_activatable_set_related_action (GTK_ACTIVATABLE (priv->week_button), action);
+
+	/* Month */
+	action = gtk_action_group_get_action (priv->action_group, "ShowMonth");
+	gtk_activatable_set_related_action (GTK_ACTIVATABLE (priv->month_button), action);
+
 	return object;
 }
 



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