[gnome-calendar] Added EVENT_VIEW mode to GcalToolbar. Hooked signals to GcalWindow methods which connect with GcalEv
- From: Erick PÃrez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] Added EVENT_VIEW mode to GcalToolbar. Hooked signals to GcalWindow methods which connect with GcalEv
- Date: Tue, 3 Jul 2012 19:53:59 +0000 (UTC)
commit 325f0d8fa3a1aa4e827ab022b6fbca5a900c29dd
Author: Erick PÃrez Castellanos <erick red gmail com>
Date: Sun Jul 1 02:00:26 2012 -0400
Added EVENT_VIEW mode to GcalToolbar.
Hooked signals to GcalWindow methods which connect with GcalEventView.
src/gcal-toolbar.c | 164 +++++++++++++++++++++++++++++++++++++++++++++++++---
src/gcal-toolbar.h | 3 +
src/gcal-window.c | 76 ++++++++++++++++++++++--
3 files changed, 227 insertions(+), 16 deletions(-)
---
diff --git a/src/gcal-toolbar.c b/src/gcal-toolbar.c
index 30771c8..582d449 100644
--- a/src/gcal-toolbar.c
+++ b/src/gcal-toolbar.c
@@ -34,6 +34,10 @@ struct _GcalToolbarPrivate
GtkWidget *sources_button;
GtkWidget *views_box;
GtkWidget *add_button;
+
+ /* events widgets */
+ GtkWidget *back_button;
+ GtkWidget *edit_button;
};
enum
@@ -43,27 +47,38 @@ enum
SOURCES_SHOWN,
ADD_EVENT,
+ BACK,
+ EDIT_EVENT,
+
NUM_SIGNALS
};
static guint signals[NUM_SIGNALS] = { 0, };
-static void gcal_toolbar_constructed (GObject *object);
+static void gcal_toolbar_constructed (GObject *object);
+
+static void gcal_toolbar_finalize (GObject *object);
-static void gcal_toolbar_finalize (GObject *object);
+static void gcal_toolbar_clear (GcalToolbar *toolbar);
static void gcal_toolbar_set_overview_mode (GcalToolbar *toolbar);
static void gcal_toolbar_set_event_mode (GcalToolbar *toolbar);
-static void gcal_toolbar_view_changed (GtkWidget *button,
- gpointer user_data);
+static void gcal_toolbar_view_changed (GtkWidget *button,
+ gpointer user_data);
+
+static void gcal_toolbar_sources_shown (GtkWidget *button,
+ gpointer user_data);
+
+static void gcal_toolbar_add_event (GtkWidget *button,
+ gpointer user_data);
-static void gcal_toolbar_sources_shown (GtkWidget *button,
- gpointer user_data);
+static void gcal_toolbar_back_clicked (GtkWidget *button,
+ gpointer user_data);
-static void gcal_toolbar_add_event (GtkWidget *button,
- gpointer user_data);
+static void gcal_toolbar_event_edited (GtkWidget *button,
+ gpointer user_data);
G_DEFINE_TYPE (GcalToolbar, gcal_toolbar, GTK_CLUTTER_TYPE_ACTOR);
@@ -105,6 +120,25 @@ gcal_toolbar_class_init (GcalToolbarClass *klass)
G_TYPE_NONE,
0);
+ signals[BACK] = g_signal_new ("back",
+ GCAL_TYPE_TOOLBAR,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GcalToolbarClass, back),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ signals[EDIT_EVENT] = g_signal_new ("edit-event",
+ GCAL_TYPE_TOOLBAR,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GcalToolbarClass,
+ edit_event),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
g_type_class_add_private ((gpointer) klass, sizeof(GcalToolbarPrivate));
}
@@ -172,10 +206,46 @@ gcal_toolbar_constructed (GObject *object)
static void
gcal_toolbar_finalize (GObject *object)
{
+ GcalToolbarPrivate *priv;
+
+ g_return_if_fail (GCAL_IS_TOOLBAR (object));
+ priv = GCAL_TOOLBAR (object)->priv;
+
+ if (priv->sources_button)
+ g_clear_object (&(priv->sources_button));
+ if (priv->views_box)
+ g_clear_object (&(priv->views_box));
+ if (priv->add_button)
+ g_clear_object (&(priv->add_button));
+
+ if (priv->back_button)
+ g_clear_object (&(priv->back_button));
+ if (priv->edit_button)
+ g_clear_object (&(priv->edit_button));
+
G_OBJECT_CLASS (gcal_toolbar_parent_class)->finalize (object);
}
static void
+gcal_toolbar_clear (GcalToolbar *toolbar)
+{
+ GcalToolbarPrivate *priv;
+ GtkWidget *child;
+
+ g_return_if_fail (GCAL_IS_TOOLBAR (toolbar));
+ priv = toolbar->priv;
+
+ if ((child = gtk_bin_get_child (GTK_BIN (priv->left_item))) != NULL)
+ gtk_container_remove (GTK_CONTAINER (priv->left_item), child);
+
+ if ((child = gtk_bin_get_child (GTK_BIN (priv->central_item))) != NULL)
+ gtk_container_remove (GTK_CONTAINER (priv->central_item), child);
+
+ if ((child = gtk_bin_get_child (GTK_BIN (priv->right_item))) != NULL)
+ gtk_container_remove (GTK_CONTAINER (priv->right_item), child);
+}
+
+static void
gcal_toolbar_set_overview_mode (GcalToolbar *toolbar)
{
GcalToolbarPrivate *priv;
@@ -189,6 +259,7 @@ gcal_toolbar_set_overview_mode (GcalToolbar *toolbar)
if (priv->sources_button == NULL)
{
priv->sources_button = gtk_toggle_button_new ();
+ g_object_ref_sink (priv->sources_button);
gtk_container_add (
GTK_CONTAINER (priv->sources_button),
gtk_image_new_from_icon_name ("view-list-symbolic",
@@ -210,6 +281,7 @@ gcal_toolbar_set_overview_mode (GcalToolbar *toolbar)
if (priv->views_box == NULL)
{
priv->views_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ g_object_ref_sink (priv->views_box);
gtk_widget_set_hexpand (priv->views_box, TRUE);
context = gtk_widget_get_style_context (priv->views_box);
@@ -307,6 +379,7 @@ gcal_toolbar_set_overview_mode (GcalToolbar *toolbar)
if (priv->add_button == NULL)
{
priv->add_button = gtk_button_new ();
+ g_object_ref_sink (priv->add_button);
gtk_container_add (
GTK_CONTAINER (priv->add_button),
gtk_image_new_from_icon_name ("list-add-symbolic",
@@ -327,7 +400,52 @@ gcal_toolbar_set_overview_mode (GcalToolbar *toolbar)
static void
gcal_toolbar_set_event_mode (GcalToolbar *toolbar)
{
- ;
+ GcalToolbarPrivate *priv;
+ GtkStyleContext *context;
+
+ g_return_if_fail (GCAL_IS_TOOLBAR (toolbar));
+ priv = toolbar->priv;
+
+ /* back */
+ if (priv->back_button == NULL)
+ {
+ priv->back_button = gtk_button_new_with_label (_("Back"));
+ g_object_ref_sink (priv->back_button);
+ gtk_button_set_image (
+ GTK_BUTTON (priv->back_button),
+ gtk_image_new_from_icon_name ("go-previous-symbolic",
+ GTK_ICON_SIZE_MENU));
+
+ context = gtk_widget_get_style_context (priv->back_button);
+ gtk_style_context_add_class (context, "raised");
+
+ g_signal_connect (priv->back_button,
+ "clicked",
+ G_CALLBACK (gcal_toolbar_back_clicked),
+ toolbar);
+ }
+ gtk_container_add (GTK_CONTAINER (priv->left_item), priv->back_button);
+ gtk_widget_show_all (priv->back_button);
+
+ /* edit */
+ if (priv->edit_button == NULL)
+ {
+ priv->edit_button = gtk_button_new_with_label (_("Edit"));
+ g_object_ref_sink (priv->edit_button);
+
+ context = gtk_widget_get_style_context (priv->edit_button);
+ gtk_style_context_add_class (context, "raised");
+
+ g_signal_connect (priv->edit_button,
+ "clicked",
+ G_CALLBACK (gcal_toolbar_event_edited),
+ toolbar);
+ }
+ /* reset morphing edit_button */
+ gtk_button_set_label (GTK_BUTTON (priv->edit_button), _("Edit"));
+
+ gtk_container_add (GTK_CONTAINER (priv->right_item), priv->edit_button);
+ gtk_widget_show_all (priv->edit_button);
}
static void
@@ -367,6 +485,33 @@ gcal_toolbar_add_event (GtkWidget *button,
g_signal_emit (toolbar, signals[ADD_EVENT], 0);
}
+static void
+gcal_toolbar_back_clicked (GtkWidget *button,
+ gpointer user_data)
+{
+ GcalToolbar *toolbar;
+
+ toolbar = GCAL_TOOLBAR (user_data);
+ g_signal_emit (toolbar, signals[BACK], 0);
+}
+
+static void
+gcal_toolbar_event_edited (GtkWidget *button,
+ gpointer user_data)
+{
+ GcalToolbarPrivate *priv;
+ GcalToolbar *toolbar;
+
+ toolbar = GCAL_TOOLBAR (user_data);
+ priv = toolbar->priv;
+
+ /* morphing edit_button */
+ gtk_button_set_label (GTK_BUTTON (priv->edit_button), _("Done"));
+
+ g_signal_emit (toolbar, signals[EDIT_EVENT], 0);
+}
+
+/* Public API */
ClutterActor*
gcal_toolbar_new (void)
{
@@ -378,6 +523,7 @@ gcal_toolbar_set_mode (GcalToolbar *toolbar,
GcalToolbarMode mode)
{
g_return_if_fail (GCAL_IS_TOOLBAR (toolbar));
+ gcal_toolbar_clear (toolbar);
switch (mode)
{
case GCAL_TOOLBAR_OVERVIEW:
diff --git a/src/gcal-toolbar.h b/src/gcal-toolbar.h
index 9de55ca..6ceb55a 100644
--- a/src/gcal-toolbar.h
+++ b/src/gcal-toolbar.h
@@ -45,6 +45,9 @@ struct _GcalToolbarClass
void (*view_changed) (GcalToolbar *toolbar, guint view_type);
void (*sources_shown) (GcalToolbar *toolbar, gboolean visible);
void (*add_event) (GcalToolbar *toolbar);
+
+ void (*back) (GcalToolbar *toolbar);
+ void (*edit_event) (GcalToolbar *toolbar);
};
struct _GcalToolbar
diff --git a/src/gcal-window.c b/src/gcal-window.c
index a9d8413..662e37b 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -68,6 +68,12 @@ static void gcal_window_sources_shown (GcalToolbar *main_to
static void gcal_window_add_event (GcalToolbar *main_toolbar,
gpointer user_data);
+static void gcal_window_back_last_view (GcalToolbar *main_toolbar,
+ gpointer user_data);
+
+static void gcal_window_edit_event (GcalToolbar *main_toolbar,
+ gpointer user_data);
+
static void gcal_window_sources_row_activated (GtkTreeView *tree_view,
GtkTreePath *path,
GtkTreeViewColumn *column,
@@ -189,6 +195,7 @@ gcal_window_constructed (GObject *object)
icaltimetype *date = g_new (icaltimetype, 1);
*date = icaltime_from_timet (time (NULL), 0);
+ priv->active_view = GCAL_VIEW_TYPE_MONTHLY;
priv->views[GCAL_VIEW_TYPE_MONTHLY] = gcal_month_view_new (date);
g_free (date);
@@ -237,6 +244,16 @@ gcal_window_constructed (GObject *object)
G_CALLBACK (gcal_window_add_event),
object);
+ g_signal_connect (priv->main_toolbar,
+ "back",
+ G_CALLBACK (gcal_window_back_last_view),
+ object);
+
+ g_signal_connect (priv->main_toolbar,
+ "edit-event",
+ G_CALLBACK (gcal_window_edit_event),
+ object);
+
gtk_widget_show (embed);
}
@@ -338,7 +355,7 @@ gcal_window_init_event_view (GcalWindow *window)
}
static void
-gcal_window_view_changed (GcalToolbar *main_toolbar,
+gcal_window_view_changed (GcalToolbar *main_toolbar,
GcalViewTypeEnum view_type,
gpointer user_data)
{
@@ -364,8 +381,8 @@ gcal_window_view_changed (GcalToolbar *main_toolbar,
static void
gcal_window_sources_shown (GcalToolbar *main_toolbar,
- gboolean visible,
- gpointer user_data)
+ gboolean visible,
+ gpointer user_data)
{
GcalWindowPrivate *priv;
priv = ((GcalWindow*) user_data)->priv;
@@ -390,7 +407,7 @@ gcal_window_sources_shown (GcalToolbar *main_toolbar,
static void
gcal_window_add_event (GcalToolbar *main_toolbar,
- gpointer user_data)
+ gpointer user_data)
{
GcalWindowPrivate *priv;
@@ -405,7 +422,49 @@ gcal_window_add_event (GcalToolbar *main_toolbar,
}
static void
-gcal_window_sources_row_activated (GtkTreeView *tree_view,
+gcal_window_back_last_view (GcalToolbar *main_toolbar,
+ gpointer user_data)
+{
+ GcalWindowPrivate *priv;
+ gint activated_page;
+
+ priv = GCAL_WINDOW (user_data)->priv;
+
+ gcal_toolbar_set_mode (GCAL_TOOLBAR (priv->main_toolbar),
+ GCAL_TOOLBAR_OVERVIEW);
+
+ if ((activated_page = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
+ priv->views[priv->active_view]))
+ != -1)
+ {
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
+ activated_page);
+ }
+ else
+ {
+ //TODO create view
+ g_debug ("GcalViewTypeEnum in GcalWindow %d", priv->active_view);
+ }
+}
+
+static void
+gcal_window_edit_event (GcalToolbar *main_toolbar,
+ gpointer user_data)
+{
+ GcalWindowPrivate *priv;
+
+ priv = GCAL_WINDOW (user_data)->priv;
+ if (priv->add_view == NULL)
+ gcal_window_init_event_view (GCAL_WINDOW (user_data));
+
+ gtk_notebook_set_current_page (
+ GTK_NOTEBOOK (priv->notebook),
+ gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook), priv->add_view));
+ gcal_event_view_enter_edit_mode (GCAL_EVENT_VIEW (priv->add_view));
+}
+
+static void
+gcal_window_sources_row_activated (GtkTreeView *tree_view,
GtkTreePath *path,
GtkTreeViewColumn *column,
gpointer user_data)
@@ -436,8 +495,8 @@ gcal_window_sources_row_activated (GtkTreeView *tree_view,
static void
gcal_window_events_added (GcalManager *manager,
- gpointer events_list,
- gpointer user_data)
+ gpointer events_list,
+ gpointer user_data)
{
GcalWindowPrivate *priv;
GSList *l;
@@ -524,6 +583,9 @@ gcal_window_event_activated (GcalEventWidget *event_widget,
gcal_event_view_load_event (GCAL_EVENT_VIEW (priv->add_view),
gcal_event_widget_peek_uuid (event_widget));
+
+ gcal_toolbar_set_mode (GCAL_TOOLBAR (priv->main_toolbar),
+ GCAL_TOOLBAR_VIEW_EVENT);
}
/* Public API */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]