[gnome-calendar] ui: Added GcalNavBar widget.
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] ui: Added GcalNavBar widget.
- Date: Thu, 4 Dec 2014 22:19:43 +0000 (UTC)
commit c8b155270be20c5e0ddfb082c6d97436a9ebc70c
Author: Erick Pérez Castellanos <erick red gmail com>
Date: Wed May 29 23:14:01 2013 -0400
ui: Added GcalNavBar widget.
GcalNavBar widget is composited using templates.
Great work of Tristan Van Berkom <tristanvb openismus com> on
using this.
data/theme/gtk-styles.css | 21 ++---
src/Makefile.am | 2 +
src/gcal-nav-bar.c | 210 +++++++++++++++++++++++++++++++++++++++++++++
src/gcal-nav-bar.h | 60 +++++++++++++
src/gcal-window.c | 88 ++++++++++++-------
5 files changed, 334 insertions(+), 47 deletions(-)
---
diff --git a/data/theme/gtk-styles.css b/data/theme/gtk-styles.css
index 677937f..b1421a8 100644
--- a/data/theme/gtk-styles.css
+++ b/data/theme/gtk-styles.css
@@ -4,7 +4,12 @@
background-image: none;
}
-.calendar-view header {
+.nav-button {
+ background-color: transparent;
+ background-image: none;
+}
+
+.nav-header {
font: bold 12;
padding: 12px;
}
@@ -51,20 +56,6 @@
border-radius: 0;
}
-GtkClutterOffscreen.overlay {
- background-color: transparent;
- background-image: none;
-}
-
-GtkClutterOffscreen.overlay .frame {
- padding: 12px;
- margin: 12px;
-}
-
-GtkClutterOffscreen.overlay .frame * {
- color: @theme_fg_color;
-}
-
GtkOverlay > GtkButton {
padding-top: 0px;
padding-right: 0px;
diff --git a/src/Makefile.am b/src/Makefile.am
index 00d707c..fe26f24 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -54,6 +54,8 @@ gnome_calendar_SOURCES = \
gcal-date-entry.h \
gcal-manager.c \
gcal-manager.h \
+ gcal-nav-bar.h \
+ gcal-nav-bar.c \
gcal-utils.c \
gcal-utils.h
diff --git a/src/gcal-nav-bar.c b/src/gcal-nav-bar.c
new file mode 100644
index 0000000..78fb026
--- /dev/null
+++ b/src/gcal-nav-bar.c
@@ -0,0 +1,210 @@
+/* -*- mode: c; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * gcal-nav-bar.c
+ *
+ * Copyright (C) 2012 - Erick Pérez Castellanos
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gcal-nav-bar.h"
+#include "gcal-utils.h"
+
+#include <glib/gi18n.h>
+
+struct _GcalNavBarPrivate
+{
+ GtkWidget *back_button;
+ GtkWidget *forward_button;
+
+ GtkWidget *left_label;
+ GtkWidget *right_label;
+};
+
+enum
+{
+ PROP_0,
+ PROP_LEFT_HEADER,
+ PROP_RIGHT_HEADER
+};
+
+/* Signal IDs */
+enum
+ {
+ MOVE,
+ LAST_SIGNAL
+ };
+
+static guint signals[LAST_SIGNAL];
+
+static void gcal_nav_bar_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+
+static void gcal_nav_bar_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+static void gcal_nav_bar_btn_clicked (GtkButton *button,
+ gpointer user_data);
+
+G_DEFINE_TYPE(GcalNavBar, gcal_nav_bar, GTK_TYPE_GRID)
+
+static void
+gcal_nav_bar_class_init (GcalNavBarClass *klass)
+{
+ GtkWidgetClass *widget_class;
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->set_property = gcal_nav_bar_set_property;
+ object_class->get_property = gcal_nav_bar_get_property;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_LEFT_HEADER,
+ g_param_spec_string ("left-header",
+ "Left Header",
+ "The text of the left header",
+ "",
+ G_PARAM_CONSTRUCT |
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_RIGHT_HEADER,
+ g_param_spec_string ("right-header",
+ "Right Header",
+ "The text of the right header",
+ "",
+ G_PARAM_CONSTRUCT |
+ G_PARAM_READWRITE));
+
+ signals[MOVE] = g_signal_new ("move",
+ GCAL_TYPE_NAV_BAR,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GcalNavBarClass,
+ move),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_BOOLEAN);
+
+ widget_class = GTK_WIDGET_CLASS (klass);
+
+ /* Setup the template GtkBuilder xml for this class */
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/nav_bar.ui");
+
+ /* Bind internals widgets */
+ gtk_widget_class_bind_child (widget_class, GcalNavBarPrivate, back_button);
+ gtk_widget_class_bind_child (widget_class, GcalNavBarPrivate, forward_button);
+ gtk_widget_class_bind_child (widget_class, GcalNavBarPrivate, left_label);
+ gtk_widget_class_bind_child (widget_class, GcalNavBarPrivate, right_label);
+
+ /* Bind callbacks */
+ gtk_widget_class_bind_callback (widget_class, gcal_nav_bar_btn_clicked);
+
+ g_type_class_add_private ((gpointer)klass, sizeof (GcalNavBarPrivate));
+}
+
+
+
+static void
+gcal_nav_bar_init (GcalNavBar *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ GCAL_TYPE_NAV_BAR,
+ GcalNavBarPrivate);
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+static void
+gcal_nav_bar_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GcalNavBarPrivate *priv;
+ priv = GCAL_NAV_BAR (object)->priv;
+
+ switch (property_id)
+ {
+ case PROP_LEFT_HEADER:
+ gtk_label_set_text (GTK_LABEL (priv->left_label),
+ g_value_get_string (value));
+ break;
+ case PROP_RIGHT_HEADER:
+ gtk_label_set_text (GTK_LABEL (priv->right_label),
+ g_value_get_string (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gcal_nav_bar_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GcalNavBarPrivate *priv;
+ priv = GCAL_NAV_BAR (object)->priv;
+
+ switch (property_id)
+ {
+ case PROP_LEFT_HEADER:
+ g_value_set_string (value,
+ gtk_label_get_text (GTK_LABEL (priv->left_label)));
+ break;
+ case PROP_RIGHT_HEADER:
+ g_value_set_string (value,
+ gtk_label_get_text (GTK_LABEL (priv->right_label)));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gcal_nav_bar_btn_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ GcalNavBarPrivate *priv;
+ priv = GCAL_NAV_BAR (user_data)->priv;
+
+ if (button == priv->back_button)
+ g_signal_emit (GCAL_NAV_BAR (user_data), signals[MOVE], 0, FALSE);
+ else
+ g_signal_emit (GCAL_NAV_BAR (user_data), signals[MOVE], 0, TRUE);
+}
+
+/* Public API */
+/**
+ * gcal_nav_bar_new:
+ *
+ * Since: 0.1
+ * Return value: A new #GcalNavBar
+ * Returns: (transfer full):
+ **/
+GtkWidget*
+gcal_nav_bar_new (void)
+{
+ return g_object_new (GCAL_TYPE_NAV_BAR, NULL);
+}
diff --git a/src/gcal-nav-bar.h b/src/gcal-nav-bar.h
new file mode 100644
index 0000000..cd573ee
--- /dev/null
+++ b/src/gcal-nav-bar.h
@@ -0,0 +1,60 @@
+/*
+ * gcal-nav-bar.h
+ *
+ * Copyright (C) 2012 - Erick Pérez Castellanos
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GCAL_NAV_BAR_H__
+#define __GCAL_NAV_BAR_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GCAL_TYPE_NAV_BAR (gcal_nav_bar_get_type ())
+#define GCAL_NAV_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_NAV_BAR,
GcalNavBar))
+#define GCAL_NAV_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GCAL_TYPE_NAV_BAR,
GcalNavBarClass))
+#define GCAL_IS_NAV_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCAL_TYPE_NAV_BAR))
+#define GCAL_IS_NAV_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GCAL_TYPE_NAV_BAR))
+#define GCAL_NAV_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCAL_TYPE_NAV_BAR,
GcalNavBarClass))
+
+typedef struct _GcalNavBar GcalNavBar;
+typedef struct _GcalNavBarClass GcalNavBarClass;
+typedef struct _GcalNavBarPrivate GcalNavBarPrivate;
+
+struct _GcalNavBar
+{
+ GtkGrid parent;
+
+ /* add your public declarations here */
+ GcalNavBarPrivate *priv;
+};
+
+struct _GcalNavBarClass
+{
+ GtkGridClass parent_class;
+
+ /* signals */
+ void (*move) (GcalNavBar *nav_bar, gboolean forward);
+};
+
+GType gcal_nav_bar_get_type (void);
+
+GtkWidget* gcal_nav_bar_new (void);
+
+G_END_DECLS
+
+#endif /* __GCAL_NAV_BAR_H__ */
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 734cf92..7fc6f06 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -17,8 +17,9 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "e-cell-renderer-color.h"
#include "gcal-window.h"
+
+#include "gcal-nav-bar.h"
#include "gcal-manager.h"
#include "gcal-floating-container.h"
#include "gcal-year-view.h"
@@ -30,6 +31,8 @@
#include "gcal-enum-types.h"
#include "gcal-event-overlay.h"
+#include "e-cell-renderer-color.h"
+
#include <libgd/gd.h>
#include <glib/gi18n.h>
@@ -43,6 +46,7 @@ struct _GcalWindowPrivate
GtkWidget *header_bar;
GtkWidget *search_bar;
+ GtkWidget *nav_bar;
GtkWidget *views_overlay;
GtkWidget *views_stack;
GtkWidget *noty; /* short-lived */
@@ -108,6 +112,10 @@ static void gcal_window_search_toggled (GObject *o
static void gcal_window_search_changed (GtkEditable *editable,
gpointer user_data);
+static void gcal_window_view_updated (GcalNavBar *nav_bar,
+ gboolean forward,
+ gpointer user_data);
+
static void gcal_window_set_active_view (GcalWindow *window,
GcalWindowViewType view_type);
@@ -148,10 +156,6 @@ static void gcal_window_remove_event (GdNotification *n
static void gcal_window_undo_remove_event (GtkButton *button,
gpointer user_data);
-static void gcal_window_view_updated (GcalView *view,
- gpointer date,
- gpointer user_data);
-
static void gcal_window_new_event_show (GcalView *view,
gpointer start_span,
gpointer end_span,
@@ -307,6 +311,12 @@ gcal_window_constructed (GObject *object)
gtk_container_add (GTK_CONTAINER (priv->search_bar), box);
gtk_container_add (GTK_CONTAINER (priv->main_box), priv->search_bar);
+ /* nav_bar */
+ priv->nav_bar = gcal_nav_bar_new ();
+ gtk_container_add (GTK_CONTAINER (priv->main_box), priv->nav_bar);
+ g_object_set (priv->nav_bar, "left-header", "May", NULL);
+ g_object_set (priv->nav_bar, "right-header", "2013", NULL);
+
/* overlay */
priv->views_overlay = gtk_overlay_new ();
gtk_widget_set_hexpand (priv->views_overlay, TRUE);
@@ -332,9 +342,15 @@ gcal_window_constructed (GObject *object)
G_CALLBACK (gcal_window_search_toggled), object);
g_signal_connect (priv->search_entry, "changed",
G_CALLBACK (gcal_window_search_changed), object);
+ g_signal_connect (priv->nav_bar, "move",
+ G_CALLBACK (gcal_window_view_updated), object);
gtk_container_add (GTK_CONTAINER (object), priv->main_box);
gtk_widget_show_all (priv->main_box);
+
+ gtk_style_context_add_class (
+ gtk_widget_get_style_context (GTK_WIDGET (object)),
+ "views");
}
static void
@@ -516,6 +532,41 @@ gcal_window_search_changed (GtkEditable *editable,
}
static void
+gcal_window_view_updated (GcalNavBar *nav_bar,
+ gboolean forward,
+ gpointer user_data)
+{
+ /* FIXME: reenable views updating */
+ /* GcalWindowPrivate *priv; */
+ /* icaltimetype *first_day; */
+ /* icaltimetype *last_day; */
+
+ if (! forward)
+ g_debug ("Moved back");
+ else
+ g_debug ("Moved forward");
+
+ /* FIXME: reenable views updating */
+ /* priv = GCAL_WINDOW (user_data)->priv; */
+
+ /* gcal_view_set_date (GCAL_VIEW (priv->views[priv->active_view]), */
+ /* date); */
+
+ /* first_day = gcal_view_get_initial_date ( */
+ /* GCAL_VIEW (priv->views[priv->active_view])); */
+ /* last_day = gcal_view_get_final_date ( */
+ /* GCAL_VIEW (priv->views[priv->active_view])); */
+
+ /* gcal_manager_set_new_range ( */
+ /* gcal_window_get_manager (GCAL_WINDOW (user_data)), */
+ /* first_day, */
+ /* last_day); */
+
+ /* g_free (first_day); */
+ /* g_free (last_day); */
+}
+
+static void
gcal_window_set_active_view (GcalWindow *window,
GcalWindowViewType view_type)
{
@@ -958,33 +1009,6 @@ gcal_window_undo_remove_event (GtkButton *button,
}
static void
-gcal_window_view_updated (GcalView *view,
- gpointer date,
- gpointer user_data)
-{
- GcalWindowPrivate *priv;
- icaltimetype *first_day;
- icaltimetype *last_day;
-
- priv = GCAL_WINDOW (user_data)->priv;
-
- gcal_view_set_date (GCAL_VIEW (priv->views[priv->active_view]),
- date);
-
- first_day = gcal_view_get_initial_date (
- GCAL_VIEW (priv->views[priv->active_view]));
- last_day = gcal_view_get_final_date (
- GCAL_VIEW (priv->views[priv->active_view]));
-
- gcal_manager_set_new_range (
- gcal_window_get_manager (GCAL_WINDOW (user_data)),
- first_day,
- last_day);
-
- g_free (first_day);
- g_free (last_day);
-}
-
gcal_window_new_event_show (GcalView *view,
gpointer start_span,
gpointer end_span,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]