[gnome-calendar/ui-rewrite] week-view: add subscriber range update



commit 61e56935d59d5f801736fdc2b0b51f1efb4954c9
Author: Erick Pérez Castellanos <erick red gmail com>
Date:   Wed Oct 22 01:02:37 2014 -0400

    week-view: add subscriber range update
    
    Remove unneeded GcalView deprecated method.
    Hook event widget activation

 src/gcal-week-view.c |  182 ++++++++++++++++++++++++++------------------------
 src/gcal-week-view.h |    6 +-
 2 files changed, 98 insertions(+), 90 deletions(-)
---
diff --git a/src/gcal-week-view.c b/src/gcal-week-view.c
index daf722d..006417a 100644
--- a/src/gcal-week-view.c
+++ b/src/gcal-week-view.c
@@ -77,6 +77,9 @@ typedef struct
   gint            clicked_cell;
 } GcalWeekViewPrivate;
 
+static void           event_opened                         (GcalEventWidget *event_widget,
+                                                            gpointer         user_data);
+
 static void           gcal_view_interface_init             (GcalViewIface  *iface);
 
 static void           gcal_week_view_constructed           (GObject        *object);
@@ -123,9 +126,6 @@ static void           gcal_week_view_forall                (GtkContainer   *cont
                                                             GtkCallback     callback,
                                                             gpointer        callback_data);
 
-static void           gcal_week_view_set_date              (GcalWeekView   *view,
-                                                            icaltimetype   *date);
-
 static void           gcal_week_view_draw_header           (GcalWeekView   *view,
                                                             cairo_t        *cr,
                                                             GtkAllocation  *alloc,
@@ -136,8 +136,6 @@ static void           gcal_week_view_draw_grid_window      (GcalWeekView   *view
 
 static gint           gcal_week_view_get_sidebar_width     (GtkWidget      *widget);
 
-static gint           gcal_week_view_get_start_grid_y      (GtkWidget      *widget);
-
 static void           gcal_week_view_scroll_value_changed  (GtkAdjustment  *adjusment,
                                                             gpointer        user_data);
 
@@ -149,20 +147,73 @@ static gchar*         gcal_week_view_get_left_header       (GcalView       *view
 
 static gchar*         gcal_week_view_get_right_header      (GcalView       *view);
 
-static gboolean       gcal_week_view_draw_event            (GcalView       *view,
-                                                            icaltimetype   *start_date,
-                                                            icaltimetype   *end_date);
-
 static GtkWidget*     gcal_week_view_get_by_uuid           (GcalView       *view,
                                                             const gchar    *uuid);
 
 G_DEFINE_TYPE_WITH_CODE (GcalWeekView,
                          gcal_week_view,
-                         GTK_TYPE_CONTAINER,
+                         GCAL_TYPE_SUBSCRIBER,
                          G_ADD_PRIVATE (GcalWeekView)
                          G_IMPLEMENT_INTERFACE (GCAL_TYPE_VIEW,
                                                 gcal_view_interface_init));
 
+/**
+ * get_start_grid_y:
+ *
+ * In GcalMonthView this method returns the height of the headers of the view
+ * and the grid. Here this points just the place where the grid_window hides
+ * behind the header
+ * Here this height includes:
+ *  - The big header of the view
+ *  - The grid header dislaying weekdays
+ *  - The cell containing all-day events.
+ */
+static gint
+get_start_grid_y (GtkWidget *widget)
+{
+  GtkStyleContext *context;
+  GtkStateFlags flags;
+  GtkBorder padding;
+
+  PangoLayout *layout;
+  PangoFontDescription *font_desc;
+  gint font_height;
+  gdouble start_grid_y;
+
+  context = gtk_widget_get_style_context (widget);
+  flags = gtk_widget_get_state_flags (widget);
+
+  layout = gtk_widget_create_pango_layout (widget, NULL);
+
+  /* init header values */
+  gtk_style_context_get_padding (context, flags, &padding);
+
+  gtk_style_context_get (context, flags, "font", &font_desc, NULL);
+
+  pango_font_description_set_weight (font_desc, PANGO_WEIGHT_SEMIBOLD);
+  pango_layout_set_font_description (layout, font_desc);
+  pango_layout_get_pixel_size (layout, NULL, &font_height);
+  pango_font_description_free (font_desc);
+
+  /* 6: is padding around the header */
+  start_grid_y = font_height + padding.bottom;
+
+  /* for including the all-day cells */
+  start_grid_y += ALL_DAY_CELLS_HEIGHT;
+
+  g_object_unref (layout);
+  return start_grid_y;
+}
+
+static void
+event_opened (GcalEventWidget *event_widget,
+              gpointer         user_data)
+{
+  g_signal_emit_by_name (GCAL_VIEW (user_data),
+                         "event-activated",
+                         event_widget);
+}
+
 static void
 gcal_week_view_class_init (GcalWeekViewClass *klass)
 {
@@ -292,13 +343,37 @@ gcal_week_view_set_property (GObject       *object,
   switch (property_id)
     {
     case PROP_DATE:
-      gcal_week_view_set_date (
-          GCAL_WEEK_VIEW (object),
-          g_value_dup_boxed (value));
-      break;
+      {
+        time_t range_start, range_end;
+        icaltimetype *date;
+        icaltimezone* default_zone;
+
+        if (priv->date != NULL)
+          g_free (priv->date);
+
+        priv->date = g_value_dup_boxed (value);
+
+        default_zone =
+          gcal_manager_get_system_timezone (priv->manager);
+        date = gcal_view_get_initial_date (GCAL_VIEW (object));
+        range_start = icaltime_as_timet_with_zone (*date,
+                                                   default_zone);
+        g_free (date);
+        date = gcal_view_get_final_date (GCAL_VIEW (object));
+        range_end = icaltime_as_timet_with_zone (*date,
+                                                 default_zone);
+        g_free (date);
+        gcal_manager_set_subscriber (priv->manager,
+                                     E_CAL_DATA_MODEL_SUBSCRIBER (object),
+                                     range_start,
+                                     range_end);
+        break;
+      }
     case PROP_MANAGER:
-      priv->manager = g_value_get_pointer (value);
-      break;
+      {
+        priv->manager = g_value_get_pointer (value);
+        break;
+      }
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -837,6 +912,10 @@ gcal_week_view_add (GtkContainer *container,
   priv->days[day - 1] = g_list_append (priv->days[day - 1], new_child);
   gtk_widget_set_parent (widget, GTK_WIDGET (container));
 
+  g_signal_connect (widget,
+                    "activate",
+                    G_CALLBACK (event_opened),
+                    container);
   g_free (date);
 }
 
@@ -912,52 +991,6 @@ gcal_week_view_forall (GtkContainer *container,
 }
 
 static void
-gcal_week_view_set_date (GcalWeekView *view,
-                         icaltimetype *date)
-{
-  GcalWeekViewPrivate *priv;
-  gboolean will_resize;
-
-  gint i;
-  GList *l;
-  GList *to_remove;
-
-  priv = gcal_week_view_get_instance_private (view);
-  will_resize = FALSE;
-
-  /* FIXME: draw_event don't exist anymore */
-  /* if span_updated: queue_resize */
-  will_resize = ! gcal_week_view_draw_event (GCAL_VIEW (view), date, NULL);
-
-  if (priv->date != NULL)
-    g_free (priv->date);
-
-  priv->date = date;
-
-  if (will_resize)
-    {
-      to_remove = NULL;
-
-      for (i = 0; i < 7; i++)
-        {
-          for (l = priv->days[i]; l != NULL; l = l->next)
-            {
-              GcalWeekViewChild *child;
-              icaltimetype *child_date;
-
-              child = (GcalWeekViewChild*) l->data;
-              child_date = gcal_event_widget_get_date (GCAL_EVENT_WIDGET (child->widget));
-              if (! gcal_week_view_draw_event (GCAL_VIEW (view), child_date, NULL))
-                to_remove = g_list_append (to_remove, child->widget);
-            }
-        }
-      g_list_foreach (to_remove, (GFunc) gtk_widget_destroy, NULL);
-
-      gtk_widget_queue_resize (GTK_WIDGET (view));
-    }
-}
-
-static void
 gcal_week_view_draw_header (GcalWeekView  *view,
                             cairo_t       *cr,
                             GtkAllocation *alloc,
@@ -1378,31 +1411,6 @@ gcal_week_view_get_right_header (GcalView *view)
   return header;
 }
 
-/* FIXME: replace cause it doesn't exist anymore */
-static gboolean
-gcal_week_view_draw_event (GcalView     *view,
-                           icaltimetype *start_date,
-                           icaltimetype *end_date)
-{
-  GcalWeekViewPrivate *priv;
-
-  g_return_val_if_fail (GCAL_IS_WEEK_VIEW (view), FALSE);
-  priv = gcal_week_view_get_instance_private (GCAL_WEEK_VIEW(view));
-
-  if (priv->date == NULL)
-    return FALSE;
-
-  if (icaltime_week_number (*(priv->date)) == icaltime_week_number (*start_date)
-      && priv->date->year == start_date->year)
-    {
-      return TRUE;
-    }
-  else
-    {
-      return FALSE;
-    }
-}
-
 static GtkWidget*
 gcal_week_view_get_by_uuid (GcalView    *view,
                             const gchar *uuid)
diff --git a/src/gcal-week-view.h b/src/gcal-week-view.h
index 7972a87..ef57773 100644
--- a/src/gcal-week-view.h
+++ b/src/gcal-week-view.h
@@ -22,7 +22,7 @@
 
 #include "gcal-manager.h"
 
-#include <gtk/gtk.h>
+#include "gcal-subscriber.h"
 
 G_BEGIN_DECLS
 
@@ -38,12 +38,12 @@ typedef struct _GcalWeekViewClass                  GcalWeekViewClass;
 
 struct _GcalWeekView
 {
-  GtkContainer parent;
+  GcalSubscriber parent;
 };
 
 struct _GcalWeekViewClass
 {
-  GtkContainerClass parent_class;
+  GcalSubscriberClass parent_class;
 };
 
 GType          gcal_week_view_get_type         (void);


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