[gnome-calendar/search-improvements] search-view: coding style fixes



commit c9fb4ce9112de36fc630d5db415324e4d0338056
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Jan 7 18:57:32 2015 -0200

    search-view: coding style fixes
    
    This commit introduces no new code, as it only
    change function ordering and some minor style
    fixes.

 src/gcal-search-view.c |  383 ++++++++++++++++++++++++------------------------
 1 files changed, 193 insertions(+), 190 deletions(-)
---
diff --git a/src/gcal-search-view.c b/src/gcal-search-view.c
index 7b2d64d..cc5fbe4 100644
--- a/src/gcal-search-view.c
+++ b/src/gcal-search-view.c
@@ -73,25 +73,17 @@ static guint signals[NUM_SIGNALS] = { 0, };
 
 #define NO_RESULT_TIMEOUT 250 /* ms */
 
-static GtkWidget*     make_row_for_event_data                   (GcalSearchView       *view,
-                                                                 GcalEventData        *data);
-
-static gint           sort_by_event                             (GtkListBoxRow        *row1,
-                                                                 GtkListBoxRow        *row2,
+/* callbacks */
+static void           display_header_func                       (GtkListBoxRow        *row,
+                                                                 GtkListBoxRow        *before,
                                                                  gpointer              user_data);
 
 static void           open_event                                (GtkListBox           *list,
                                                                  GtkListBoxRow        *row,
                                                                  gpointer              user_data);
 
-static void           update_view                               (GcalSearchView       *view);
-
-static void           free_row_data                             (RowEventData          *data);
-
-static gboolean       show_no_results_page                      (GcalSearchView       *view);
-
-static void           display_header_func                       (GtkListBoxRow        *row,
-                                                                 GtkListBoxRow        *before,
+static gint           sort_by_event                             (GtkListBoxRow        *row1,
+                                                                 GtkListBoxRow        *row2,
                                                                  gpointer              user_data);
 
 static void           source_added                              (GcalManager          *manager,
@@ -103,6 +95,17 @@ static void           source_removed                            (GcalManager
                                                                  ESource              *source,
                                                                  gpointer              user_data);
 
+static gboolean       show_no_results_page                      (GcalSearchView       *view);
+
+/* private */
+static void           free_row_data                             (RowEventData          *data);
+
+static GtkWidget*     make_row_for_event_data                   (GcalSearchView       *view,
+                                                                 GcalEventData        *data);
+
+static void           update_view                               (GcalSearchView       *view);
+
+/* prefixed */
 static void           gcal_data_model_subscriber_interface_init (ECalDataModelSubscriberInterface *iface);
 
 static void           gcal_search_view_constructed              (GObject        *object);
@@ -144,116 +147,62 @@ G_DEFINE_TYPE_WITH_CODE (GcalSearchView,
                                                 gcal_data_model_subscriber_interface_init));
 
 /**
- * make_row_for_event_data:
- * @view: a #GcalSearchView
- * @data: a #GcalEventData pointer
+ * display_header_func:
  *
- * Creates a new #GtkListBoxRow with the event information
- * as input.
+ * Shows a separator before each row.
  *
- * Returns: the newly created #GtkListBoxRow with the event data
  */
-static GtkWidget*
-make_row_for_event_data (GcalSearchView  *view,
-                         GcalEventData   *data)
+static void
+display_header_func (GtkListBoxRow *row,
+                     GtkListBoxRow *before,
+                     gpointer       user_data)
 {
-  GcalSearchViewPrivate *priv;
-
-  GDateTime *datetime;
-  ECalComponentDateTime comp_dt;
-  ECalComponentText summary;
-  ESourceSelectable *extension;
-  GdkRGBA color;
-  GdkPixbuf *pixbuf;
-
-  GtkWidget *row;
-  GtkWidget *grid;
-  GtkWidget *box;
-
-  gchar *text;
-  GtkWidget *date_label;
-  GtkWidget *time_label;
-  GtkWidget *name_label;
-  GtkWidget *image;
-
-  priv = gcal_search_view_get_instance_private (view);
-
-  /* get event color */
-  extension = E_SOURCE_SELECTABLE (e_source_get_extension (data->source, E_SOURCE_EXTENSION_CALENDAR));
-  gdk_rgba_parse (&color, e_source_selectable_get_color (E_SOURCE_SELECTABLE (extension)));
-
-  pixbuf = gcal_get_pixbuf_from_color (&color, 16);
-
-  /* make an image of the color */
-  image = gtk_image_new_from_pixbuf (pixbuf);
-
-  /* date */
-  e_cal_component_get_dtstart (data->event_component, &comp_dt);
-  e_cal_component_get_summary (data->event_component, &summary);
-
-  /* grid & box*/
-  row = gtk_list_box_row_new ();
-  grid = gtk_grid_new ();
-  box = gtk_grid_new ();
-
-  g_object_set (grid,
-                "column-spacing", 12,
-                "border-width", 10,
-                "margin-start", 16,
-                "margin-end", 16,
-                "hexpand", TRUE, NULL);
-
-  gtk_grid_set_column_spacing (GTK_GRID (box), 12);
-  gtk_widget_set_valign (box, GTK_ALIGN_CENTER);
-  gtk_widget_set_margin_end (box, 6);
+  if (before != NULL)
+    {
+      GtkWidget *header;
 
-  /* start date & time */
-  datetime = g_date_time_new_local (comp_dt.value->year, comp_dt.value->month, comp_dt.value->day, 
comp_dt.value->hour,
-                                    comp_dt.value->minute, comp_dt.value->second);
-  text = g_date_time_format (datetime, "%x");
-  date_label = gtk_label_new (text);
-  gtk_label_set_width_chars (GTK_LABEL (date_label), 11);
-  g_free (text);
+      header = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+      gtk_widget_show (header);
 
-  /* show 'all day' instead of 00:00 */
-  if (comp_dt.value->is_date == 0)
-    {
-      if (priv->format_24h)
-        text = g_strdup_printf ("%.2d:%.2d", comp_dt.value->hour, comp_dt.value->minute);
-      else
-        text = g_strdup_printf (_("%.2d:%.2d %s"), comp_dt.value->hour % 12, comp_dt.value->minute,
-                                comp_dt.value->hour < 12 ? _("AM") : _("PM"));
-      time_label = gtk_label_new (text);
-      g_free (text);
-    }
-  else
-    {
-      time_label = gtk_label_new (_("All day"));
+      gtk_list_box_row_set_header (row, header);
     }
+}
 
-  gtk_label_set_width_chars (GTK_LABEL (time_label), 12);
-  gtk_style_context_add_class (gtk_widget_get_style_context (time_label), "dim-label");
+/**
+ * open_event:
+ * @list: the source #GtkListBox
+ * @row: the activated #GtkListBoxRow
+ * @user_data: a #GcalSearchView instance.
+ *
+ * Fire GcalSearchView::'event-activated' event
+ * when the @row is activated by the user.
+ *
+ * It is up to #GcalWindow to hear the signal,
+ * retrieve the #icaltimetype passed as parameter
+ * and select the day from the last view.
+ *
+ * Returns:
+ */
+static void
+open_event (GtkListBox    *list,
+            GtkListBoxRow *row,
+            gpointer       user_data)
+{
+  GcalSearchViewPrivate *priv;
+  GcalEventData *data;
+  ECalComponentDateTime dt;
+  icaltimetype *time;
 
-  /* name label */
-  name_label = gtk_label_new (summary.value);
-  gtk_widget_set_hexpand (name_label, TRUE);
-  gtk_widget_set_halign (name_label, GTK_ALIGN_START);
-  gtk_label_set_ellipsize (GTK_LABEL (name_label), PANGO_ELLIPSIZE_END);
 
-  /* attach things up */
-  gtk_grid_attach (GTK_GRID (box), time_label, 0, 0, 1, 1);
-  gtk_grid_attach (GTK_GRID (box), date_label, 1, 0, 1, 1);
-  gtk_grid_attach (GTK_GRID (grid), image, 0, 0, 1, 1);
-  gtk_grid_attach (GTK_GRID (grid), name_label, 1, 0, 1, 1);
-  gtk_grid_attach (GTK_GRID (grid), box, 2, 0, 1, 1);
-  gtk_container_add (GTK_CONTAINER (row), grid);
+  priv = gcal_search_view_get_instance_private (GCAL_SEARCH_VIEW (user_data));
+  data = g_hash_table_lookup (priv->row_to_event, row);
 
-  gtk_widget_show_all (row);
+  e_cal_component_get_dtstart (data->event_component, &dt);
+  time = gcal_dup_icaltime (dt.value);
 
-  g_date_time_unref (datetime);
-  e_cal_component_free_datetime (&comp_dt);
-  g_object_unref (pixbuf);
-  return row;
+  g_signal_emit_by_name (user_data, "event-activated", time);
+
+  e_cal_component_free_datetime (&dt);
 }
 
 /**
@@ -317,62 +266,46 @@ sort_by_event (GtkListBoxRow *row1,
   return -1 * result;
 }
 
-/**
- * open_event:
- * @list: the source #GtkListBox
- * @row: the activated #GtkListBoxRow
- * @user_data: a #GcalSearchView instance.
- *
- * Fire GcalSearchView::'event-activated' event
- * when the @row is activated by the user.
- *
- * It is up to #GcalWindow to hear the signal,
- * retrieve the #icaltimetype passed as parameter
- * and select the day from the last view.
- *
- * Returns:
- */
 static void
-open_event (GtkListBox    *list,
-            GtkListBoxRow *row,
-            gpointer       user_data)
+source_added (GcalManager *manager,
+              ESource     *source,
+              gboolean     enable,
+              gpointer     user_data)
 {
   GcalSearchViewPrivate *priv;
-  GcalEventData *data;
-  ECalComponentDateTime dt;
-  icaltimetype *time;
-
 
   priv = gcal_search_view_get_instance_private (GCAL_SEARCH_VIEW (user_data));
-  data = g_hash_table_lookup (priv->row_to_event, row);
-
-  e_cal_component_get_dtstart (data->event_component, &dt);
-  time = gcal_dup_icaltime (dt.value);
-
-  g_signal_emit_by_name (user_data, "event-activated", time);
+  gcal_search_view_search (GCAL_SEARCH_VIEW (user_data), priv->field, priv->query);
+}
 
-  e_cal_component_free_datetime (&dt);
+static void
+source_removed (GcalManager *manager,
+                ESource     *source,
+                gpointer     user_data)
+{
+  source_added (manager, source, FALSE, user_data);
 }
 
 /**
- * update_view:
+ * show_no_results_page:
  * @view: a #GcalSearchView instance.
  *
- * Updates the timeout for the 'No results found'
- * page.
+ * Callback to update the 'No results found' page.
  *
- * Returns:
+ * Returns: @G_SOURCE_REMOVE
  */
-static void
-update_view (GcalSearchView *view)
+static gboolean
+show_no_results_page (GcalSearchView *view)
 {
   GcalSearchViewPrivate *priv;
+
   priv = gcal_search_view_get_instance_private (view);
+  priv->no_results_timeout_id = 0;
 
-  if (priv->no_results_timeout_id != 0)
-    g_source_remove (priv->no_results_timeout_id);
+  gtk_widget_set_visible (priv->scrolled_window, priv->num_results != 0);
+  gtk_widget_set_visible (priv->no_results_grid, priv->num_results == 0);
 
-  priv->no_results_timeout_id = g_timeout_add (NO_RESULT_TIMEOUT, (GSourceFunc) show_no_results_page, view);
+  return G_SOURCE_REMOVE;
 }
 
 /**
@@ -398,67 +331,137 @@ free_row_data (RowEventData *data)
 }
 
 /**
- * show_no_results_page:
- * @view: a #GcalSearchView instance.
+ * make_row_for_event_data:
+ * @view: a #GcalSearchView
+ * @data: a #GcalEventData pointer
  *
- * Callback to update the 'No results found' page.
+ * Creates a new #GtkListBoxRow with the event information
+ * as input.
  *
- * Returns: @G_SOURCE_REMOVE
+ * Returns: the newly created #GtkListBoxRow with the event data
  */
-static gboolean
-show_no_results_page (GcalSearchView *view)
+static GtkWidget*
+make_row_for_event_data (GcalSearchView  *view,
+                         GcalEventData   *data)
 {
   GcalSearchViewPrivate *priv;
 
+  GDateTime *datetime;
+  ECalComponentDateTime comp_dt;
+  ECalComponentText summary;
+  ESourceSelectable *extension;
+  GdkRGBA color;
+  GdkPixbuf *pixbuf;
+
+  GtkWidget *row;
+  GtkWidget *grid;
+  GtkWidget *box;
+
+  gchar *text;
+  GtkWidget *date_label;
+  GtkWidget *time_label;
+  GtkWidget *name_label;
+  GtkWidget *image;
+
   priv = gcal_search_view_get_instance_private (view);
-  priv->no_results_timeout_id = 0;
 
-  gtk_widget_set_visible (priv->scrolled_window, priv->num_results != 0);
-  gtk_widget_set_visible (priv->no_results_grid, priv->num_results == 0);
+  /* get event color */
+  extension = E_SOURCE_SELECTABLE (e_source_get_extension (data->source, E_SOURCE_EXTENSION_CALENDAR));
+  gdk_rgba_parse (&color, e_source_selectable_get_color (E_SOURCE_SELECTABLE (extension)));
 
-  return G_SOURCE_REMOVE;
-}
+  pixbuf = gcal_get_pixbuf_from_color (&color, 16);
 
-/**
- * display_header_func:
- *
- * Shows a separator before each row.
- *
- */
-static void
-display_header_func (GtkListBoxRow *row,
-                     GtkListBoxRow *before,
-                     gpointer       user_data)
-{
-  if (before)
-    {
-      GtkWidget *header;
+  /* make an image of the color */
+  image = gtk_image_new_from_pixbuf (pixbuf);
 
-      header = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
-      gtk_widget_show (header);
+  /* date */
+  e_cal_component_get_dtstart (data->event_component, &comp_dt);
+  e_cal_component_get_summary (data->event_component, &summary);
 
-      gtk_list_box_row_set_header (row, header);
+  /* grid & box*/
+  row = gtk_list_box_row_new ();
+  grid = gtk_grid_new ();
+  box = gtk_grid_new ();
+
+  g_object_set (grid,
+                "column-spacing", 12,
+                "border-width", 10,
+                "margin-start", 16,
+                "margin-end", 16,
+                "hexpand", TRUE, NULL);
+
+  gtk_grid_set_column_spacing (GTK_GRID (box), 12);
+  gtk_widget_set_valign (box, GTK_ALIGN_CENTER);
+  gtk_widget_set_margin_end (box, 6);
+
+  /* start date & time */
+  datetime = g_date_time_new_local (comp_dt.value->year, comp_dt.value->month, comp_dt.value->day, 
comp_dt.value->hour,
+                                    comp_dt.value->minute, comp_dt.value->second);
+  text = g_date_time_format (datetime, "%x");
+  date_label = gtk_label_new (text);
+  gtk_label_set_width_chars (GTK_LABEL (date_label), 11);
+  g_free (text);
+
+  /* show 'all day' instead of 00:00 */
+  if (comp_dt.value->is_date == 0)
+    {
+      if (priv->format_24h)
+        text = g_strdup_printf ("%.2d:%.2d", comp_dt.value->hour, comp_dt.value->minute);
+      else
+        text = g_strdup_printf (_("%.2d:%.2d %s"), comp_dt.value->hour % 12, comp_dt.value->minute,
+                                comp_dt.value->hour < 12 ? _("AM") : _("PM"));
+      time_label = gtk_label_new (text);
+      g_free (text);
     }
+  else
+    {
+      time_label = gtk_label_new (_("All day"));
+    }
+
+  gtk_label_set_width_chars (GTK_LABEL (time_label), 12);
+  gtk_style_context_add_class (gtk_widget_get_style_context (time_label), "dim-label");
+
+  /* name label */
+  name_label = gtk_label_new (summary.value);
+  gtk_widget_set_hexpand (name_label, TRUE);
+  gtk_widget_set_halign (name_label, GTK_ALIGN_START);
+  gtk_label_set_ellipsize (GTK_LABEL (name_label), PANGO_ELLIPSIZE_END);
+
+  /* attach things up */
+  gtk_grid_attach (GTK_GRID (box), time_label, 0, 0, 1, 1);
+  gtk_grid_attach (GTK_GRID (box), date_label, 1, 0, 1, 1);
+  gtk_grid_attach (GTK_GRID (grid), image, 0, 0, 1, 1);
+  gtk_grid_attach (GTK_GRID (grid), name_label, 1, 0, 1, 1);
+  gtk_grid_attach (GTK_GRID (grid), box, 2, 0, 1, 1);
+  gtk_container_add (GTK_CONTAINER (row), grid);
+
+  gtk_widget_show_all (row);
+
+  g_date_time_unref (datetime);
+  e_cal_component_free_datetime (&comp_dt);
+  g_object_unref (pixbuf);
+  return row;
 }
 
+/**
+ * update_view:
+ * @view: a #GcalSearchView instance.
+ *
+ * Updates the timeout for the 'No results found'
+ * page.
+ *
+ * Returns:
+ */
 static void
-source_added (GcalManager *manager,
-              ESource     *source,
-              gboolean     enable,
-              gpointer     user_data)
+update_view (GcalSearchView *view)
 {
   GcalSearchViewPrivate *priv;
+  priv = gcal_search_view_get_instance_private (view);
 
-  priv = gcal_search_view_get_instance_private (GCAL_SEARCH_VIEW (user_data));
-  gcal_search_view_search (GCAL_SEARCH_VIEW (user_data), priv->field, priv->query);
-}
+  if (priv->no_results_timeout_id != 0)
+    g_source_remove (priv->no_results_timeout_id);
 
-static void
-source_removed (GcalManager *manager,
-                ESource     *source,
-                gpointer     user_data)
-{
-  source_added (manager, source, FALSE, user_data);
+  priv->no_results_timeout_id = g_timeout_add (NO_RESULT_TIMEOUT, (GSourceFunc) show_no_results_page, view);
 }
 
 static void


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