[gnome-calendar] Added GSettings to read/set the active view.



commit e09ce361b0aafb1fa30d2c00499199e8ed6e370b
Author: Erick PÃrez Castellanos <erick red gmail com>
Date:   Fri Jul 6 17:15:52 2012 -0400

    Added GSettings to read/set the active view.
    
    Placed code to generate G_TYPE_ENUM from my defined enums
    Semi-integrated GcalWeekView
    Updated TODO.

 .gitignore                             |    3 +
 TODO                                   |    1 +
 configure.ac                           |    6 +
 data/Makefile.am                       |    4 +
 data/gtk-styles.css                    |    2 +-
 data/org.gnome.calendar.gschema.xml.in |    5 +
 src/Makefile.am                        |  127 +++++++++------
 src/gcal-application.c                 |   23 +++-
 src/gcal-application.h                 |    8 +-
 src/gcal-enum-types.c.template         |   39 +++++
 src/gcal-enum-types.h.template         |   26 +++
 src/gcal-toolbar.c                     |   10 +-
 src/gcal-utils.h                       |   12 +-
 src/gcal-week-view.c                   |    4 +-
 src/gcal-window.c                      |  274 +++++++++++++++++++++++---------
 15 files changed, 394 insertions(+), 150 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 1fb470b..6e8309e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -71,3 +71,6 @@ gnome_calendar.anjuta
 /mkinstalldirs
 Debug*
 .gdb_history
+data/org.gnome.calendar.enums.xml
+src/gcal-enum-types.c
+src/gcal-enum-types.h
diff --git a/TODO b/TODO
index c33bac8..03901ea 100644
--- a/TODO
+++ b/TODO
@@ -9,6 +9,7 @@ TODO
  - Create GcalView interface or superclass of all views.
  - Connect all dconf options to the program
  - Remove body_actor if there's no need of it in the end.
+ - Clear/reorder #include in every header file.
 
 Design stuff
 
diff --git a/configure.ac b/configure.ac
index f449b7b..6268a55 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,6 +44,12 @@ AC_CACHE_SAVE
 
 GLIB_GSETTINGS
 
+dnl ================================================================
+dnl Misc
+dnl ================================================================
+AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
+AC_PATH_PROG(GLIB_MKENUMS, glib-mkenums)
+
 GNOME_COMPILE_WARNINGS(maximum)
 GNOME_MAINTAINER_MODE_DEFINES
 
diff --git a/data/Makefile.am b/data/Makefile.am
index f3b3225..c173b62 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -4,6 +4,10 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
 
 @INTLTOOL_DESKTOP_RULE@
 
+gsettings_ENUM_NAMESPACE = org.gnome.calendar
+gsettings_ENUM_FILES = \
+	$(top_srcdir)/src/gcal-utils.h
+
 gsettingsschema_in_files = org.gnome.calendar.gschema.xml.in
 gsettings_SCHEMAS = $(gsettingsschema_in_files:.xml.in=.xml)
 .PRECIOUS: $(gsettings_SCHEMAS)
diff --git a/data/gtk-styles.css b/data/gtk-styles.css
index 3fddd75..5f8697f 100644
--- a/data/gtk-styles.css
+++ b/data/gtk-styles.css
@@ -48,7 +48,7 @@
   padding-bottom: 2px;
   padding-left: 8px;
   padding-right: 8px;
-  font: 10;
+  font: 9;
 }
 
 .event-details .frame {
diff --git a/data/org.gnome.calendar.gschema.xml.in b/data/org.gnome.calendar.gschema.xml.in
index 65c363b..29aace8 100644
--- a/data/org.gnome.calendar.gschema.xml.in
+++ b/data/org.gnome.calendar.gschema.xml.in
@@ -5,5 +5,10 @@
             <_summary>Window maximized</_summary>
             <_description>Window maximized state</_description>
         </key>
+        <key name="active-view" enum="org.gnome.calendar.GcalWindowViewType">
+            <default>'month'</default>
+            <_summary>Type of the active view</_summary>
+            <_description>Type of the active window view, default value is: monthly view</_description>
+        </key>
     </schema>
 </schemalist>
diff --git a/src/Makefile.am b/src/Makefile.am
index 691c5ec..2df3e26 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,64 +1,85 @@
-AM_CPPFLAGS =                                           \
-	-DCLUTTER_VERSION_MIN_REQUIRED=CLUTTER_VERSION_1_10   \
-  -DPACKAGE_LOCALE_DIR=\""$(localedir)"\"               \
-  -DPACKAGE_SRC_DIR=\""$(srcdir)"\"                     \
-  -DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\"                \
-	-DUI_DATA_DIR=\""$(pkgdatadir)/style"\"               \
-	$(MAINTAINER_COMPILER_FLAGS)                          \
-	-Wall                                                 \
-  -g -O0                                                \
-  $(CALENDAR_CFLAGS)
+AM_CPPFLAGS =                                             \
+    -DCLUTTER_VERSION_MIN_REQUIRED=CLUTTER_VERSION_1_10   \
+    -DPACKAGE_LOCALE_DIR=\""$(localedir)"\"               \
+    -DPACKAGE_SRC_DIR=\""$(srcdir)"\"                     \
+    -DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\"                \
+    -DUI_DATA_DIR=\""$(pkgdatadir)/style"\"               \
+    $(MAINTAINER_COMPILER_FLAGS)                          \
+    -Wall                                                 \
+    -g -O0                                                \
+    $(CALENDAR_CFLAGS)
 
-AM_CFLAGS =                                             \
-	-Wall                                                 \
-  -g -O0
+AM_CFLAGS =                                               \
+    -Wall                                                 \
+    -g -O0
 
 bin_PROGRAMS = gnome-calendar
 
-gnome_calendar_SOURCES =                                \
-  main.c                                                \
-  gcal-application.h                                    \
-  gcal-application.c                                    \
-	gcal-floating-container.c                             \
-	gcal-floating-container.h                             \
-	gcal-toolbar.h  	                                    \
-	gcal-toolbar.c       			                            \
-	gcal-window.h                                         \
-	gcal-window.c                                         \
-	gcal-view.c                                           \
-	gcal-view.h                                           \
-	gcal-month-view.c                                     \
-	gcal-month-view.h                                     \
-	gcal-week-view.c                                      \
-	gcal-week-view.h                                     \
-	gcal-event-widget.c                                   \
-	gcal-event-widget.h                                   \
-	gcal-event-view.c                                     \
-	gcal-event-view.h                                     \
-	gcal-editable.c                                       \
-	gcal-editable.h                                       \
-	gcal-editable-entry.c                                 \
-	gcal-editable-entry.h                                 \
-	gcal-editable-text.c                                  \
-	gcal-editable-text.h                                  \
-	gcal-editable-date.c                                  \
-	gcal-editable-date.h                                  \
-	gcal-editable-combo.c                                 \
-	gcal-editable-combo.h                                 \
-	gcal-editable-reminder.c                              \
-	gcal-editable-reminder.h                              \
-	gcal-manager.c                                        \
-	gcal-manager.h                                        \
-	gcal-utils.c                                          \
-	gcal-utils.h                                          \
-	gtk-notification.c                                    \
-	gtk-notification.h
+BUILT_SOURCES =                                           \
+    gcal-enum-types.c                                     \
+    gcal-enum-types.h
 
+gnome_calendar_SOURCES =                                  \
+    $(BUILT_SOURCES)                                      \
+    main.c                                                \
+    gcal-application.h                                    \
+    gcal-application.c                                    \
+    gcal-floating-container.c                             \
+    gcal-floating-container.h                             \
+    gcal-toolbar.h                                        \
+    gcal-toolbar.c                                        \
+    gcal-window.h                                         \
+    gcal-window.c                                         \
+    gcal-view.c                                           \
+    gcal-view.h                                           \
+    gcal-month-view.c                                     \
+    gcal-month-view.h                                     \
+    gcal-week-view.c                                      \
+    gcal-week-view.h                                      \
+    gcal-event-widget.c                                   \
+    gcal-event-widget.h                                   \
+    gcal-event-view.c                                     \
+    gcal-event-view.h                                     \
+    gcal-editable.c                                       \
+    gcal-editable.h                                       \
+    gcal-editable-entry.c                                 \
+    gcal-editable-entry.h                                 \
+    gcal-editable-text.c                                  \
+    gcal-editable-text.h                                  \
+    gcal-editable-date.c                                  \
+    gcal-editable-date.h                                  \
+    gcal-editable-combo.c                                 \
+    gcal-editable-combo.h                                 \
+    gcal-editable-reminder.c                              \
+    gcal-editable-reminder.h                              \
+    gcal-manager.c                                        \
+    gcal-manager.h                                        \
+    gcal-utils.c                                          \
+    gcal-utils.h                                          \
+    gtk-notification.c                                    \
+    gtk-notification.h
 
-gnome_calendar_LDFLAGS =                                \
+
+gnome_calendar_LDFLAGS =                                  \
   -Wl,--export-dynamic
 
-gnome_calendar_LDADD =                                  \
+gnome_calendar_LDADD =                                    \
   $(CALENDAR_LIBS)
 
+ENUM_TYPES =                                              \
+    gcal-utils.h
+
+gcal-enum-types.h: gcal-enum-types.h.template $(ENUM_TYPES) $(GLIB_MKENUMS)
+	$(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template gcal-enum-types.h.template $(ENUM_TYPES)) > $@
+
+gcal-enum-types.c: gcal-enum-types.c.template $(ENUM_TYPES) $(GLIB_MKENUMS)
+	$(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template gcal-enum-types.c.template $(ENUM_TYPES)) > $@
+
+EXTRA_DIST =                                              \
+    gcal-enum-types.h.template                            \
+    gcal-enum-types.c.template
+
+CLEANFILES = $(BUILT_SOURCES)
 
+dist-hook:
+	cd $(distdir); rm -f $(BUILT_SOURCES)
diff --git a/src/gcal-application.c b/src/gcal-application.c
index b3fed3c..4993e52 100644
--- a/src/gcal-application.c
+++ b/src/gcal-application.c
@@ -31,6 +31,7 @@ struct _GcalApplicationPrivate
 {
   GtkWidget      *window;
 
+  GSettings      *settings;
   GcalManager    *manager;
 
   GtkCssProvider *provider;
@@ -59,6 +60,12 @@ gcal_application_activate (GApplication *application)
   else
     {
       priv->window = gcal_window_new (GCAL_APPLICATION (application));
+      g_settings_bind (priv->settings,
+                       "active-view",
+                       priv->window,
+                       "active-view",
+                       G_SETTINGS_BIND_SET | G_SETTINGS_BIND_GET
+                       | G_SETTINGS_BIND_GET_NO_CHANGES);
       gtk_window_set_title (GTK_WINDOW (priv->window), _("Calendar"));
       gtk_window_set_hide_titlebar_when_maximized (GTK_WINDOW (priv->window),
                                                    TRUE);
@@ -177,13 +184,16 @@ gcal_application_quit (GSimpleAction *simple,
 GcalApplication*
 gcal_application_new (void)
 {
+  GcalApplication *app;
   g_type_init ();
 
   g_set_application_name ("Calendar");
 
-  return g_object_new (gcal_application_get_type (),
-                       "application-id", "org.gnome.Calendar",
-                       NULL);
+  app = g_object_new (gcal_application_get_type (),
+                      "application-id", "org.gnome.Calendar",
+                      NULL);
+  app->priv->settings = g_settings_new ("org.gnome.calendar");
+  return app;
 }
 
 GcalManager*
@@ -192,3 +202,10 @@ gcal_application_get_manager (GcalApplication *app)
   g_return_val_if_fail (GCAL_IS_APPLICATION (app), NULL);
   return app->priv->manager;
 }
+
+GSettings*
+gcal_application_get_settings (GcalApplication *app)
+{
+  g_return_val_if_fail (GCAL_IS_APPLICATION (app), NULL);
+  return app->priv->settings;
+}
diff --git a/src/gcal-application.h b/src/gcal-application.h
index ddc0a26..c170d89 100644
--- a/src/gcal-application.h
+++ b/src/gcal-application.h
@@ -49,11 +49,13 @@ struct _GcalApplication
   GcalApplicationPrivate *priv;
 };
 
-GType            gcal_application_get_type    (void) G_GNUC_CONST;
+GType             gcal_application_get_type     (void) G_GNUC_CONST;
 
-GcalApplication* gcal_application_new         (void);
+GcalApplication*  gcal_application_new          (void);
 
-GcalManager*     gcal_application_get_manager (GcalApplication *app);
+GcalManager*      gcal_application_get_manager  (GcalApplication *app);
+
+GSettings*        gcal_application_get_settings (GcalApplication *app);
 
 /* Callbacks */
 
diff --git a/src/gcal-enum-types.c.template b/src/gcal-enum-types.c.template
new file mode 100644
index 0000000..dec6f81
--- /dev/null
+++ b/src/gcal-enum-types.c.template
@@ -0,0 +1,39 @@
+/*** BEGIN file-header ***/
+#include "gcal-enum-types.h"
+
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* enumerations from "@filename@" */
+#include "@filename@"
+
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType
+ enum_name@_get_type (void)
+{
+	static GType the_type = 0;
+
+	if (the_type == 0)
+	{
+		static const G Type@Value values[] = {
+/*** END value-header ***/
+
+/*** BEGIN value-production ***/
+			{ @VALUENAME@,
+			  "@VALUENAME@",
+			  "@valuenick@" },
+/*** END value-production ***/
+
+/*** BEGIN value-tail ***/
+			{ 0, NULL, NULL }
+		};
+		the_type = g_ type@_register_static (
+				g_intern_static_string ("@EnumName@"),
+				values);
+	}
+	return the_type;
+}
+
+/*** END value-tail ***/
diff --git a/src/gcal-enum-types.h.template b/src/gcal-enum-types.h.template
new file mode 100644
index 0000000..8c36d18
--- /dev/null
+++ b/src/gcal-enum-types.h.template
@@ -0,0 +1,26 @@
+/*** BEGIN file-header ***/
+#ifndef __GCAL_ENUM_TYPES_H__
+#define __GCAL_ENUM_TYPES_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* Enumerations from "@filename@" */
+
+/*** END file-production ***/
+
+/*** BEGIN enumeration-production ***/
+#define GCAL_ ENUMSHORT@	(@enum_name _get_type())
+GType @enum_name _get_type	(void) G_GNUC_CONST;
+
+/*** END enumeration-production ***/
+
+/*** BEGIN file-tail ***/
+G_END_DECLS
+
+#endif /* __GCAL_ENUM_TYPES_H__ */
+/*** END file-tail ***/
diff --git a/src/gcal-toolbar.c b/src/gcal-toolbar.c
index 4016203..e01ded7 100644
--- a/src/gcal-toolbar.c
+++ b/src/gcal-toolbar.c
@@ -309,7 +309,7 @@ gcal_toolbar_set_overview_mode (GcalToolbar *toolbar)
 
       g_object_set_data (G_OBJECT (button),
                         "view-type",
-                        GUINT_TO_POINTER (GCAL_VIEW_TYPE_DAILY));
+                        GUINT_TO_POINTER (GCAL_WINDOW_VIEW_DAY));
       g_signal_connect (button,
                         "clicked",
                         G_CALLBACK (gcal_toolbar_view_changed),
@@ -326,7 +326,7 @@ gcal_toolbar_set_overview_mode (GcalToolbar *toolbar)
 
       g_object_set_data (G_OBJECT (button),
                         "view-type",
-                        GUINT_TO_POINTER (GCAL_VIEW_TYPE_WEEKLY));
+                        GUINT_TO_POINTER (GCAL_WINDOW_VIEW_WEEK));
       g_signal_connect (button,
                         "clicked",
                         G_CALLBACK (gcal_toolbar_view_changed),
@@ -343,7 +343,7 @@ gcal_toolbar_set_overview_mode (GcalToolbar *toolbar)
 
       g_object_set_data (G_OBJECT (button),
                         "view-type",
-                        GUINT_TO_POINTER (GCAL_VIEW_TYPE_MONTHLY));
+                        GUINT_TO_POINTER (GCAL_WINDOW_VIEW_MONTH));
       g_signal_connect (button,
                         "clicked",
                         G_CALLBACK (gcal_toolbar_view_changed),
@@ -360,7 +360,7 @@ gcal_toolbar_set_overview_mode (GcalToolbar *toolbar)
 
       g_object_set_data (G_OBJECT (button),
                         "view-type",
-                        GUINT_TO_POINTER (GCAL_VIEW_TYPE_YEARLY));
+                        GUINT_TO_POINTER (GCAL_WINDOW_VIEW_YEAR));
       g_signal_connect (button,
                         "clicked",
                         G_CALLBACK (gcal_toolbar_view_changed),
@@ -377,7 +377,7 @@ gcal_toolbar_set_overview_mode (GcalToolbar *toolbar)
 
         g_object_set_data (G_OBJECT (button),
                         "view-type",
-                        GUINT_TO_POINTER (GCAL_VIEW_TYPE_LIST));
+                        GUINT_TO_POINTER (GCAL_WINDOW_VIEW_LIST));
       g_signal_connect (button,
                         "clicked",
                         G_CALLBACK (gcal_toolbar_view_changed),
diff --git a/src/gcal-utils.h b/src/gcal-utils.h
index 75fa006..a282211 100644
--- a/src/gcal-utils.h
+++ b/src/gcal-utils.h
@@ -27,12 +27,12 @@
 
 typedef enum
 {
-  GCAL_VIEW_TYPE_DAILY = 0,
-  GCAL_VIEW_TYPE_WEEKLY,
-  GCAL_VIEW_TYPE_MONTHLY,
-  GCAL_VIEW_TYPE_YEARLY,
-  GCAL_VIEW_TYPE_LIST,
-} GcalViewTypeEnum;
+  GCAL_WINDOW_VIEW_DAY,
+  GCAL_WINDOW_VIEW_WEEK,
+  GCAL_WINDOW_VIEW_MONTH,
+  GCAL_WINDOW_VIEW_YEAR,
+  GCAL_WINDOW_VIEW_LIST,
+} GcalWindowViewType;
 
 typedef enum
 {
diff --git a/src/gcal-week-view.c b/src/gcal-week-view.c
index 2ae8080..34b8c5b 100644
--- a/src/gcal-week-view.c
+++ b/src/gcal-week-view.c
@@ -621,8 +621,8 @@ gcal_week_view_draw_header (GcalWeekView  *view,
   context = gtk_widget_get_style_context (GTK_WIDGET (view));
   state = gtk_widget_get_state_flags (GTK_WIDGET (view));
 
-  gtk_style_context_add_region (context, "header", 0);
   gtk_style_context_save (context);
+  gtk_style_context_add_region (context, "header", 0);
 
   gtk_style_context_get_color (context, state, &color);
   cairo_set_source_rgba (cr, color.red, color.green, color.blue, color.alpha);
@@ -753,7 +753,7 @@ gcal_week_view_draw_grid (GcalWeekView  *view,
       pango_cairo_update_layout (cr, layout);
       pango_layout_get_pixel_size (layout, &font_width, &font_height);
       cairo_move_to (cr,
-                     alloc->x + padding->left + (( priv->grid_sidebar_size  - font_width) / 2),
+                     alloc->x + padding->left + priv->grid_sidebar_size - font_width - 4,
                      alloc->y + padding->top + priv->header_size + priv->grid_header_size + priv->vertical_step * (i + 1) + ((priv->vertical_step - font_height) / 2));
       pango_cairo_show_layout (cr, layout);
 
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 7e6cb48..36b3289 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -22,10 +22,11 @@
 #include "gcal-floating-container.h"
 #include "gcal-toolbar.h"
 #include "gcal-month-view.h"
+#include "gcal-week-view.h"
 #include "gcal-view.h"
 #include "gcal-event-widget.h"
 #include "gcal-event-view.h"
-#include "gcal-utils.h"
+#include "gcal-enum-types.h"
 #include "gtk-notification.h"
 
 #include <clutter/clutter.h>
@@ -49,72 +50,107 @@ struct _GcalWindowPrivate
   GtkWidget          *views [5];
   GtkWidget          *add_view;
 
-  GcalViewTypeEnum    active_view;
+  GcalWindowViewType        active_view;
 
   /* temp to keep the will_delete event uuid */
   gchar              *event_to_delete;
 };
 
-static void       gcal_window_constructed            (GObject           *object);
+enum
+{
+  PROP_0,
+  PROP_ACTIVE_VIEW
+};
+
+static void           gcal_window_constructed            (GObject             *object);
+
+static void           gcal_window_set_property           (GObject             *object,
+                                                          guint                property_id,
+                                                          const GValue        *value,
+                                                          GParamSpec          *pspec);
+
+static void           gcal_window_get_property           (GObject             *object,
+                                                          guint                property_id,
+                                                          GValue              *value,
+                                                          GParamSpec          *pspec);
+
+static GcalManager*   gcal_window_get_manager            (GcalWindow          *window);
 
-GcalManager*      gcal_window_get_manager            (GcalWindow        *window);
+static GSettings*     gcal_window_get_settings           (GcalWindow          *window);
 
-static void       gcal_window_set_sources_view       (GcalWindow        *window);
+static void           gcal_window_set_active_view        (GcalWindow          *window,
+                                                          GcalWindowViewType   view_type);
 
-static void       gcal_window_init_event_view        (GcalWindow        *window);
+static void           gcal_window_set_sources_view       (GcalWindow          *window);
 
-static void       gcal_window_view_changed           (GcalToolbar       *main_toolbar,
-                                                      GcalViewTypeEnum   view_type,
-                                                      gpointer           user_data);
+static void           gcal_window_init_event_view        (GcalWindow          *window);
 
-static void       gcal_window_sources_shown          (GcalToolbar       *main_toolbar,
-                                                      gboolean           visible,
-                                                      gpointer           user_data);
+static void           gcal_window_view_changed           (GcalToolbar         *main_toolbar,
+                                                          GcalWindowViewType   view_type,
+                                                          gpointer             user_data);
 
-static void       gcal_window_add_event              (GcalToolbar       *main_toolbar,
-                                                      gpointer           user_data);
+static void           gcal_window_sources_shown          (GcalToolbar         *main_toolbar,
+                                                          gboolean             visible,
+                                                          gpointer             user_data);
 
-static void       gcal_window_back_last_view         (GtkWidget         *widget,
-                                                      gpointer           user_data);
+static void           gcal_window_add_event              (GcalToolbar         *main_toolbar,
+                                                          gpointer             user_data);
 
-static void       gcal_window_edit_event             (GcalToolbar       *main_toolbar,
-                                                      gpointer           user_data);
+static void           gcal_window_back_last_view         (GtkWidget           *widget,
+                                                          gpointer             user_data);
 
-static void       gcal_window_done_edit_event        (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,
-                                                      gpointer           user_data);
+static void           gcal_window_done_edit_event        (GcalToolbar         *main_toolbar,
+                                                          gpointer             user_data);
 
-static void       gcal_window_events_added           (GcalManager       *manager,
-                                                      gpointer           events_list,
-                                                      gpointer           user_data);
+static void           gcal_window_sources_row_activated  (GtkTreeView         *tree_view,
+                                                          GtkTreePath         *path,
+                                                          GtkTreeViewColumn   *column,
+                                                          gpointer             user_data);
 
-static void       gcal_window_events_removed         (GcalManager       *manager,
-                                                      gpointer           events_list,
-                                                      gpointer           user_data);
+static void           gcal_window_events_added           (GcalManager         *manager,
+                                                          gpointer             events_list,
+                                                          gpointer             user_data);
 
-static void       gcal_window_event_activated        (GcalEventWidget   *event_widget,
-                                                      gpointer           user_data);
+static void           gcal_window_events_removed         (GcalManager         *manager,
+                                                          gpointer             events_list,
+                                                          gpointer             user_data);
 
-static void       gcal_window_will_remove_event      (GcalEventView     *view,
-                                                      gchar             *event_uuid,
-                                                      gpointer           user_data);
+static void           gcal_window_event_activated        (GcalEventWidget     *event_widget,
+                                                          gpointer             user_data);
 
-static void       gcal_window_remove_event           (GtkNotification   *notification,
-                                                      gpointer           user_data);
+static void           gcal_window_will_remove_event      (GcalEventView       *view,
+                                                          gchar               *event_uuid,
+                                                          gpointer             user_data);
 
-static void       gcal_window_undo_remove_event      (GtkButton         *button,
-                                                      gpointer           user_data);
+static void           gcal_window_remove_event           (GtkNotification     *notification,
+                                                          gpointer             user_data);
+
+static void           gcal_window_undo_remove_event      (GtkButton           *button,
+                                                          gpointer             user_data);
 
 G_DEFINE_TYPE(GcalWindow, gcal_window, GTK_TYPE_APPLICATION_WINDOW)
 
 static void
 gcal_window_class_init(GcalWindowClass *klass)
 {
-  G_OBJECT_CLASS (klass)->constructed = gcal_window_constructed;
+  GObjectClass *object_class;
+
+  object_class = G_OBJECT_CLASS (klass);
+  object_class->constructed = gcal_window_constructed;
+  object_class->set_property = gcal_window_set_property;
+  object_class->get_property = gcal_window_get_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_ACTIVE_VIEW,
+                                   g_param_spec_enum ("active-view",
+                                                      "Active View",
+                                                      "The active view, eg: month, week, etc.",
+                                                      GCAL_WINDOW_VIEW_TYPE,
+                                                      GCAL_WINDOW_VIEW_MONTH,
+                                                      G_PARAM_READWRITE));
 
   g_type_class_add_private((gpointer)klass, sizeof(GcalWindowPrivate));
 }
@@ -130,6 +166,7 @@ static void
 gcal_window_constructed (GObject *object)
 {
   GcalWindowPrivate *priv;
+
   GtkWidget *embed;
   ClutterActor *stage;
   ClutterActor *base;
@@ -219,17 +256,6 @@ gcal_window_constructed (GObject *object)
                           CLUTTER_BIN_ALIGNMENT_FILL,
                           CLUTTER_BIN_ALIGNMENT_FILL);
 
-  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);
-
-  gtk_widget_show (priv->views[GCAL_VIEW_TYPE_MONTHLY]);
-  gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
-                            priv->views[GCAL_VIEW_TYPE_MONTHLY],
-                            NULL);
-
   /* sources view */
   holder = gcal_floating_container_new ();
 
@@ -297,9 +323,49 @@ gcal_window_constructed (GObject *object)
                     object);
 
   gtk_widget_show (embed);
+
+  /* settings the view */
+
+}
+
+static void
+gcal_window_set_property (GObject      *object,
+                          guint         property_id,
+                          const GValue *value,
+                          GParamSpec   *pspec)
+{
+  switch (property_id)
+    {
+    case PROP_ACTIVE_VIEW:
+      gcal_window_set_active_view (GCAL_WINDOW (object),
+                                   g_value_get_enum (value));
+      return;
+    }
+
+  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 }
 
-GcalManager*
+static void
+gcal_window_get_property (GObject    *object,
+                          guint       property_id,
+                          GValue     *value,
+                          GParamSpec *pspec)
+{
+  GcalWindowPrivate *priv;
+
+  priv = GCAL_WINDOW (object)->priv;
+
+  switch (property_id)
+    {
+    case PROP_ACTIVE_VIEW:
+      g_value_set_enum (value, priv->active_view);
+      return;
+    }
+
+  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static GcalManager*
 gcal_window_get_manager (GcalWindow *window)
 {
   GcalApplication *app;
@@ -308,6 +374,80 @@ gcal_window_get_manager (GcalWindow *window)
   return gcal_application_get_manager (app);
 }
 
+static GSettings*
+gcal_window_get_settings (GcalWindow *window)
+{
+  GcalApplication *app;
+  app = GCAL_APPLICATION (gtk_window_get_application (GTK_WINDOW (window)));
+
+  return gcal_application_get_settings (app);
+}
+
+static void
+gcal_window_set_active_view (GcalWindow         *window,
+                             GcalWindowViewType  view_type)
+{
+  GcalWindowPrivate *priv;
+  gint activated_page;
+
+  g_return_if_fail (GCAL_IS_WINDOW (window));
+  priv = window->priv;
+
+  if ((activated_page = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
+                                               priv->views[view_type]))
+      != -1)
+    {
+      gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
+                                     activated_page);
+      priv->active_view = view_type;
+    }
+  else
+    {
+      //TODO create view
+      g_debug ("GcalWindowViewType in GcalWindow %d", priv->active_view);
+      icaltimetype *date = g_new (icaltimetype, 1);
+      *date = icaltime_from_timet (time (NULL), 0);
+
+      switch (view_type)
+        {
+          case GCAL_WINDOW_VIEW_WEEK:
+            priv->views[GCAL_WINDOW_VIEW_WEEK] = gcal_week_view_new (date);
+            break;
+          case GCAL_WINDOW_VIEW_MONTH:
+            priv->views[GCAL_WINDOW_VIEW_MONTH] = gcal_month_view_new (date);
+            break;
+          default:
+            g_debug ("Unimplemented view yet");
+            return;
+        }
+
+      priv->active_view = view_type;
+      g_free (date);
+
+      gtk_widget_show (priv->views[priv->active_view]);
+      gtk_notebook_set_current_page (
+          GTK_NOTEBOOK (priv->notebook),
+          gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
+                                    priv->views[priv->active_view],
+                                    NULL));
+    }
+
+  //FIXME: thi isn't yet the final destination of this code.
+  icaltimetype *first_day;
+  icaltimetype *last_day;
+  first_day = gcal_month_view_get_initial_date (
+                GCAL_MONTH_VIEW (priv->views[GCAL_WINDOW_VIEW_MONTH]));
+  last_day = gcal_month_view_get_final_date (
+                GCAL_MONTH_VIEW (priv->views[GCAL_WINDOW_VIEW_MONTH]));
+
+  gcal_manager_set_new_range (
+      gcal_window_get_manager (window),
+      first_day,
+      last_day);
+  g_free (first_day);
+  g_free (last_day);
+}
+
 static void
 gcal_window_set_sources_view (GcalWindow *window)
 {
@@ -404,9 +544,9 @@ gcal_window_init_event_view (GcalWindow *window)
 }
 
 static void
-gcal_window_view_changed (GcalToolbar       *main_toolbar,
-                           GcalViewTypeEnum  view_type,
-                           gpointer          user_data)
+gcal_window_view_changed (GcalToolbar         *main_toolbar,
+                           GcalWindowViewType  view_type,
+                           gpointer            user_data)
 {
   GcalWindowPrivate *priv;
   gint activated_page;
@@ -423,11 +563,7 @@ gcal_window_view_changed (GcalToolbar       *main_toolbar,
     }
   else
     {
-      //TODO create view
-      g_debug ("GcalViewTypeEnum in GcalWindow %d", priv->active_view);
-      if (priv->active_view == GCAL_VIEW_TYPE_LIST)
-        {
-        }
+      gcal_window_set_active_view (GCAL_WINDOW (user_data), view_type);
     }
 }
 
@@ -593,10 +729,8 @@ gcal_window_events_added (GcalManager *manager,
       starting_date = gcal_manager_get_event_start_date (manager,
                                                          source_uid,
                                                          event_uid);
-      /* FIXME: here priv->views[priv->active_view] instead of hardcoding
-       * GCAL_VIEW_TYPE_MONTHLY */
       if (gcal_view_is_in_range (
-            GCAL_VIEW (priv->views[GCAL_VIEW_TYPE_MONTHLY]),
+            GCAL_VIEW (priv->views[priv->active_view]),
             starting_date))
         {
           summary = gcal_manager_get_event_summary (manager,
@@ -819,20 +953,6 @@ gcal_window_new (GcalApplication *app)
                     G_CALLBACK (gcal_window_events_removed),
                     win);
 
-  /* FIXME: demo code */
-  GcalWindowPrivate *priv;
-  icaltimetype *first_day;
-  icaltimetype *last_day;
-  priv = win->priv;
-  first_day = gcal_month_view_get_initial_date (
-                GCAL_MONTH_VIEW (priv->views[GCAL_VIEW_TYPE_MONTHLY]));
-  last_day = gcal_month_view_get_final_date (
-                GCAL_MONTH_VIEW (priv->views[GCAL_VIEW_TYPE_MONTHLY]));
-
-  gcal_manager_set_new_range (manager, first_day, last_day);
-  g_free (first_day);
-  g_free (last_day);
-
   return GTK_WIDGET (win);
 }
 



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