[gnome-calendar/wip/pandusonu/week-view: 20/21] week-header, week-grid: remove duplicate code



commit c1ab1c2d3b505eef7601ac2f2895ee6934c443b3
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Dec 8 18:41:36 2016 -0200

    week-header, week-grid: remove duplicate code

 src/gcal-utils.c             |   37 +++++++++++++++++++++++++++++++++++++
 src/gcal-utils.h             |    8 ++++++++
 src/views/gcal-week-grid.c   |   28 ----------------------------
 src/views/gcal-week-header.c |   38 --------------------------------------
 4 files changed, 45 insertions(+), 66 deletions(-)
---
diff --git a/src/gcal-utils.c b/src/gcal-utils.c
index ec91ee3..b6d1f4b 100644
--- a/src/gcal-utils.c
+++ b/src/gcal-utils.c
@@ -524,6 +524,43 @@ icaltime_compare_with_current (const icaltimetype *date1,
   return result;
 }
 
+GDateTime*
+get_start_of_week (icaltimetype *date)
+{
+  icaltimetype *new_date;
+  GDateTime *dt;
+
+  new_date = g_new0 (icaltimetype, 1);
+  *new_date = icaltime_from_day_of_year (icaltime_start_doy_week (*date, get_first_weekday () + 1),
+                                         date->year);
+  new_date->is_date = 0;
+  new_date->hour = 0;
+  new_date->minute = 0;
+  new_date->second = 0;
+
+  dt = g_date_time_new_local (new_date->year,
+                              new_date->month,
+                              new_date->day,
+                              0, 0, 0);
+
+  g_clear_pointer (&new_date, g_free);
+
+  return dt;
+}
+
+GDateTime*
+get_end_of_week (icaltimetype *date)
+{
+  GDateTime *week_start, *week_end;
+
+  week_start = get_start_of_week (date);
+  week_end = g_date_time_add_days (week_start, 7);
+
+  g_clear_pointer (&week_start, g_date_time_unref);
+
+  return week_end;
+}
+
 /* Function to do a last minute fixup of the AM/PM stuff if the locale
  * and gettext haven't done it right. Most English speaking countries
  * except the USA use the 24 hour clock (UK, Australia etc). However
diff --git a/src/gcal-utils.h b/src/gcal-utils.h
index 90992a9..07bbce1 100644
--- a/src/gcal-utils.h
+++ b/src/gcal-utils.h
@@ -27,6 +27,10 @@
 
 #define ICAL_TIME_TYPE (icaltime_get_type ())
 
+#define ALIGNED(x)      (round (x) + 0.5)
+#define MINUTES_PER_DAY 1440
+#define MAX_MINUTES     (7 * MINUTES_PER_DAY)
+
 typedef enum
 {
   GCAL_WINDOW_VIEW_DAY,
@@ -95,6 +99,10 @@ gint            icaltime_compare_with_current                   (const icaltimet
                                                                  const icaltimetype    *date2,
                                                                  time_t                *current_time_t);
 
+GDateTime*      get_start_of_week                               (icaltimetype          *date);
+
+GDateTime*      get_end_of_week                                 (icaltimetype          *date);
+
 /* code brought from evolution */
 gsize           e_strftime_fix_am_pm                            (gchar                 *str,
                                                                  gsize                  max,
diff --git a/src/views/gcal-week-grid.c b/src/views/gcal-week-grid.c
index 97bd3ff..27f54ce 100644
--- a/src/views/gcal-week-grid.c
+++ b/src/views/gcal-week-grid.c
@@ -28,10 +28,6 @@
 #include <string.h>
 #include <math.h>
 
-#define ALIGNED(x)      (round (x) + 0.5)
-#define MINUTES_PER_DAY 1440
-#define MAX_MINUTES     (7 * MINUTES_PER_DAY)
-
 static const double dashed [] =
 {
   5.0,
@@ -125,30 +121,6 @@ destroy_event_widget (GcalWeekGrid *self,
 }
 
 /* Auxiliary methods */
-static GDateTime*
-get_start_of_week (icaltimetype *date)
-{
-  icaltimetype *new_date;
-  GDateTime *dt;
-
-  new_date = g_new0 (icaltimetype, 1);
-  *new_date = icaltime_from_day_of_year (icaltime_start_doy_week (*date, get_first_weekday () + 1),
-                                         date->year);
-  new_date->is_date = 0;
-  new_date->hour = 0;
-  new_date->minute = 0;
-  new_date->second = 0;
-
-  dt = g_date_time_new_local (new_date->year,
-                              new_date->month,
-                              new_date->day,
-                              0, 0, 0);
-
-  g_clear_pointer (&new_date, g_free);
-
-  return dt;
-}
-
 static void
 get_event_range (GcalWeekGrid *self,
                  GcalEvent    *event,
diff --git a/src/views/gcal-week-header.c b/src/views/gcal-week-header.c
index ed7bf82..4a7f335 100644
--- a/src/views/gcal-week-header.c
+++ b/src/views/gcal-week-header.c
@@ -29,7 +29,6 @@
 #include <string.h>
 #include <math.h>
 
-#define ALIGNED(x)           (round (x) + 0.5)
 #define COLUMN_PADDING       6
 
 struct _GcalWeekHeader
@@ -161,43 +160,6 @@ get_event_by_uuid (GcalWeekHeader *self,
   return NULL;
 }
 
-static GDateTime*
-get_start_of_week (icaltimetype *date)
-{
-  icaltimetype *new_date;
-  GDateTime *dt;
-
-  new_date = g_new0 (icaltimetype, 1);
-  *new_date = icaltime_from_day_of_year (icaltime_start_doy_week (*date, get_first_weekday () + 1),
-                                         date->year);
-  new_date->is_date = 0;
-  new_date->hour = 0;
-  new_date->minute = 0;
-  new_date->second = 0;
-
-  dt = g_date_time_new_local (new_date->year,
-                              new_date->month,
-                              new_date->day,
-                              0, 0, 0);
-
-  g_clear_pointer (&new_date, g_free);
-
-  return dt;
-}
-
-static GDateTime*
-get_end_of_week (icaltimetype *date)
-{
-  GDateTime *week_start, *week_end;
-
-  week_start = get_start_of_week (date);
-  week_end = g_date_time_add_days (week_start, 7);
-
-  g_clear_pointer (&week_start, g_date_time_unref);
-
-  return week_end;
-}
-
 static inline gint
 get_today_column (GcalWeekHeader *self)
 {


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