[evolution/wip/webkit2] Bug 751488 - Add Birthday and Anniversary columns into Contacts view



commit 17f35d210bc60de0049d95936a16e1ded65a3abd
Author: Milan Crha <mcrha redhat com>
Date:   Fri Jun 26 16:58:05 2015 +0200

    Bug 751488 - Add Birthday and Anniversary columns into Contacts view

 .../gui/widgets/e-addressbook-table-adapter.c      |   48 ++++++++-
 addressbook/gui/widgets/e-addressbook-view.etspec  |    2 +
 e-util/Makefile.am                                 |    2 +
 e-util/e-cell-date-int.c                           |  112 ++++++++++++++++++++
 e-util/e-cell-date-int.h                           |   72 +++++++++++++
 e-util/e-cell-date.c                               |   49 +++++++--
 e-util/e-cell-date.h                               |    7 +-
 e-util/e-table-extras.c                            |    5 +
 e-util/e-util.h                                    |    1 +
 9 files changed, 287 insertions(+), 11 deletions(-)
---
diff --git a/addressbook/gui/widgets/e-addressbook-table-adapter.c 
b/addressbook/gui/widgets/e-addressbook-table-adapter.c
index 87a0dee..36e71b3 100644
--- a/addressbook/gui/widgets/e-addressbook-table-adapter.c
+++ b/addressbook/gui/widgets/e-addressbook-table-adapter.c
@@ -164,6 +164,24 @@ addressbook_value_at (ETableModel *etc,
                return NULL;
 
        contact = e_addressbook_model_contact_at (priv->model, row);
+       if (col == E_CONTACT_BIRTH_DATE ||
+           col == E_CONTACT_ANNIVERSARY) {
+               EContactDate *date;
+
+               date = e_contact_get (contact, col);
+               if (date) {
+                       gint int_dt;
+
+                       int_dt = 10000 * date->year + 100 * date->month + date->day;
+
+                       e_contact_date_free (date);
+
+                       return GINT_TO_POINTER (int_dt);
+               } else {
+                       return GINT_TO_POINTER (-1);
+               }
+       }
+
        value = e_contact_get_const (contact, col);
 
        if (value && *value && (col == E_CONTACT_EMAIL_1 ||
@@ -218,7 +236,9 @@ addressbook_set_value_at (ETableModel *etc,
                EBookClient *book_client;
                EContact *contact;
 
-               if (col >= E_CONTACT_FIELD_LAST)
+               if (col >= E_CONTACT_FIELD_LAST ||
+                   col == E_CONTACT_BIRTH_DATE ||
+                   col == E_CONTACT_ANNIVERSARY)
                        return;
 
                if (row >= e_addressbook_model_contact_count (priv->model))
@@ -276,6 +296,10 @@ addressbook_duplicate_value (ETableModel *etc,
                              gint col,
                              gconstpointer value)
 {
+       if (col == E_CONTACT_BIRTH_DATE ||
+           col == E_CONTACT_ANNIVERSARY)
+               return GINT_TO_POINTER (GPOINTER_TO_INT (value));
+
        return g_strdup (value);
 }
 
@@ -285,13 +309,19 @@ addressbook_free_value (ETableModel *etc,
                         gint col,
                         gpointer value)
 {
-       g_free (value);
+       if (col != E_CONTACT_BIRTH_DATE &&
+           col != E_CONTACT_ANNIVERSARY)
+               g_free (value);
 }
 
 static gpointer
 addressbook_initialize_value (ETableModel *etc,
                               gint col)
 {
+       if (col == E_CONTACT_BIRTH_DATE ||
+           col == E_CONTACT_ANNIVERSARY)
+               return GINT_TO_POINTER (-1);
+
        return g_strdup ("");
 }
 
@@ -300,6 +330,10 @@ addressbook_value_is_empty (ETableModel *etc,
                             gint col,
                             gconstpointer value)
 {
+       if (col == E_CONTACT_BIRTH_DATE ||
+           col == E_CONTACT_ANNIVERSARY)
+               return GPOINTER_TO_INT (value) <= 0;
+
        return !(value && *(gchar *) value);
 }
 
@@ -308,6 +342,16 @@ addressbook_value_to_string (ETableModel *etc,
                              gint col,
                              gconstpointer value)
 {
+       if (col == E_CONTACT_BIRTH_DATE ||
+           col == E_CONTACT_ANNIVERSARY) {
+               gint int_dt = GPOINTER_TO_INT (value);
+
+               if (int_dt <= 0)
+                       return g_strdup ("");
+
+               return g_strdup_printf ("%04d-%02d-%02d", int_dt / 10000, (int_dt / 100) % 100, int_dt % 100);
+       }
+
        return g_strdup (value);
 }
 
diff --git a/addressbook/gui/widgets/e-addressbook-view.etspec 
b/addressbook/gui/widgets/e-addressbook-view.etspec
index 45eaea1..db1ad7a 100644
--- a/addressbook/gui/widgets/e-addressbook-view.etspec
+++ b/addressbook/gui/widgets/e-addressbook-view.etspec
@@ -51,6 +51,8 @@
 
   <ETableColumn model_col="49" _title="Spouse"            expansion="1.0" minimum_width="75" 
resizable="true" cell="string" compare="collate"/>
   <ETableColumn model_col="50" _title="Note"              expansion="1.0" minimum_width="75" 
resizable="true" cell="string" compare="collate"/>
+  <ETableColumn model_col="107" _title="Birthday"         expansion="1.0" minimum_width="75" 
resizable="true" cell="date-int" compare="integer"/>
+  <ETableColumn model_col="108" _title="Anniversary"      expansion="1.0" minimum_width="75" 
resizable="true" cell="date-int" compare="integer"/>
 
   <ETableState>
     <column source="0"/>
diff --git a/e-util/Makefile.am b/e-util/Makefile.am
index a3e84a3..010ca6a 100644
--- a/e-util/Makefile.am
+++ b/e-util/Makefile.am
@@ -151,6 +151,7 @@ evolution_util_include_HEADERS =  \
        e-cell-checkbox.h \
        e-cell-combo.h \
        e-cell-date-edit.h \
+       e-cell-date-int.h \
        e-cell-date.h \
        e-cell-hbox.h \
        e-cell-number.h \
@@ -419,6 +420,7 @@ libevolution_util_la_SOURCES = \
        e-cell-checkbox.c \
        e-cell-combo.c \
        e-cell-date-edit.c \
+       e-cell-date-int.c \
        e-cell-date.c \
        e-cell-hbox.c \
        e-cell-number.c \
diff --git a/e-util/e-cell-date-int.c b/e-util/e-cell-date-int.c
new file mode 100644
index 0000000..6f0dd75
--- /dev/null
+++ b/e-util/e-cell-date-int.c
@@ -0,0 +1,112 @@
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ * Authors:
+ *             Chris Lahey <clahey ximian com>
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "e-cell-date.h"
+#include "e-cell-date-int.h"
+
+struct _ECellDateIntPrivate {
+       gint dummy;
+};
+
+G_DEFINE_TYPE (ECellDateInt, e_cell_date_int, E_TYPE_CELL_DATE)
+
+static gchar *
+ecdi_get_text (ECellText *cell,
+               ETableModel *model,
+               gint col,
+               gint row)
+{
+       gint int_date = GPOINTER_TO_INT (e_table_model_value_at (model, col, row));
+       GDate *date;
+       struct tm tm;
+
+       if (int_date <= 0)
+               return g_strdup ("");
+
+       date = g_date_new_dmy (int_date % 100, (int_date / 100) % 100, int_date / 10000);
+       if (!date || !g_date_valid (date)) {
+               if (date)
+                       g_date_free (date);
+               return g_strdup ("");
+       }
+
+       g_date_to_struct_tm (date, &tm);
+
+       g_date_free (date);
+
+       return e_cell_date_tm_to_text (E_CELL_DATE (cell), &tm, TRUE);
+}
+
+static void
+e_cell_date_int_class_init (ECellDateIntClass *class)
+{
+       ECellTextClass *ectc = E_CELL_TEXT_CLASS (class);
+
+       g_type_class_add_private (class, sizeof (ECellDateIntPrivate));
+
+       ectc->get_text = ecdi_get_text;
+}
+
+static void
+e_cell_date_int_init (ECellDateInt *ecdi)
+{
+       ecdi->priv = G_TYPE_INSTANCE_GET_PRIVATE (ecdi, E_TYPE_CELL_DATE_INT, ECellDateIntPrivate);
+}
+
+/**
+ * e_cell_date_int_new:
+ * @fontname: font to be used to render on the screen
+ * @justify: Justification of the string in the cell.
+ *
+ * Creates a new ECell renderer that can be used to render dates that
+ * that come from the model. The value returned from the model is
+ * interpreted as being an integer with the format YYYYMMDD.
+ *
+ * The ECellDate object support a large set of properties that can be
+ * configured through the Gtk argument system and allows the user to have
+ * a finer control of the way the string is displayed.  The arguments supported
+ * allow the control of strikeout, bold, color and a date filter.
+ *
+ * The arguments "strikeout_column", "underline_column", "bold_column"
+ * and "color_column" set and return an integer that points to a
+ * column in the model that controls these settings.  So controlling
+ * the way things are rendered is achieved by having special columns
+ * in the model that will be used to flag whether the date should be
+ * rendered with strikeout, underline, or bolded.  In the case of the
+ * "color_column" argument, the column in the model is expected to
+ * have a string that can be parsed by gdk_color_parse().
+ *
+ * Returns: an ECell object that can be used to render dates encoded as integers.
+ */
+ECell *
+e_cell_date_int_new (const gchar *fontname,
+                    GtkJustification justify)
+{
+       ECellDateInt *ecdi = g_object_new (E_TYPE_CELL_DATE_INT, NULL);
+
+       e_cell_text_construct (E_CELL_TEXT (ecdi), fontname, justify);
+
+       return (ECell *) ecdi;
+}
diff --git a/e-util/e-cell-date-int.h b/e-util/e-cell-date-int.h
new file mode 100644
index 0000000..60a4ad8
--- /dev/null
+++ b/e-util/e-cell-date-int.h
@@ -0,0 +1,72 @@
+/*
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ * Authors:
+ *             Chris Lahey <clahey ximian com>
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+
+#if !defined (__E_UTIL_H_INSIDE__) && !defined (LIBEUTIL_COMPILATION)
+#error "Only <e-util/e-util.h> should be included directly."
+#endif
+
+#ifndef E_CELL_DATE_INT_H
+#define E_CELL_DATE_INT_H
+
+#include <e-util/e-cell-date.h>
+
+/* Standard GObject macros */
+#define E_TYPE_CELL_DATE_INT \
+       (e_cell_date_int_get_type ())
+#define E_CELL_DATE_INT(obj) \
+       (G_TYPE_CHECK_INSTANCE_CAST \
+       ((obj), E_TYPE_CELL_DATE_INT, ECellDateInt))
+#define E_CELL_DATE_INT_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_CAST \
+       ((cls), E_TYPE_CELL_DATE_INT, ECellDateIntClass))
+#define E_IS_CELL_DATE_INT(obj) \
+       (G_TYPE_CHECK_INSTANCE_TYPE \
+       ((obj), E_TYPE_CELL_DATE_INT))
+#define E_IS_CELL_DATE_INT_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_TYPE \
+       ((cls), E_TYPE_CELL_DATE_INT))
+#define E_CELL_DATE_INT_GET_CLASS(obj) \
+       (G_TYPE_INSTANCE_GET_CLASS \
+       ((obj), E_TYPE_CELL_DATE_INT, ECellDateIntClass))
+
+G_BEGIN_DECLS
+
+typedef struct _ECellDateInt ECellDateInt;
+typedef struct _ECellDateIntClass ECellDateIntClass;
+typedef struct _ECellDateIntPrivate ECellDateIntPrivate;
+
+struct _ECellDateInt {
+       ECellDate parent;
+
+       ECellDateIntPrivate *priv;
+};
+
+struct _ECellDateIntClass {
+       ECellDateClass parent_class;
+};
+
+GType          e_cell_date_int_get_type        (void) G_GNUC_CONST;
+ECell *                e_cell_date_int_new             (const gchar *fontname,
+                                                GtkJustification justify);
+G_END_DECLS
+
+#endif /* E_CELL_DATE_INT_H */
diff --git a/e-util/e-cell-date.c b/e-util/e-cell-date.c
index 610151a..7f0da8e 100644
--- a/e-util/e-cell-date.c
+++ b/e-util/e-cell-date.c
@@ -44,7 +44,6 @@ ecd_get_text (ECellText *cell,
               gint row)
 {
        gint64 *pdate = e_table_model_value_at (model, col, row);
-       const gchar *fmt_component, *fmt_part = NULL;
        gchar *res;
 
        if (!pdate || *pdate == 0) {
@@ -52,13 +51,7 @@ ecd_get_text (ECellText *cell,
                return g_strdup (_("?"));
        }
 
-       fmt_component = g_object_get_data ((GObject *) cell, "fmt-component");
-       if (!fmt_component || !*fmt_component)
-               fmt_component = "Default";
-       else
-               fmt_part = "table";
-
-       res = e_datetime_format_format (fmt_component, fmt_part, DTFormatKindDateTime, (time_t) *pdate);
+       res = e_cell_date_value_to_text (E_CELL_DATE (cell), *pdate, FALSE);
 
        e_table_model_free_value (model, col, pdate);
 
@@ -134,3 +127,43 @@ e_cell_date_set_format_component (ECellDate *ecd,
                G_OBJECT (ecd), "fmt-component",
                g_strdup (fmt_component), g_free);
 }
+
+gchar *
+e_cell_date_value_to_text (ECellDate *ecd,
+                          gint64 value,
+                          gboolean date_only)
+{
+       const gchar *fmt_component, *fmt_part = NULL;
+
+       if (value == 0)
+               return g_strdup (_("?"));
+
+       fmt_component = g_object_get_data ((GObject *) ecd, "fmt-component");
+       if (!fmt_component || !*fmt_component)
+               fmt_component = "Default";
+       else
+               fmt_part = "table";
+
+       return e_datetime_format_format (fmt_component, fmt_part,
+               date_only ? DTFormatKindDate : DTFormatKindDateTime, (time_t) value);
+}
+
+gchar *
+e_cell_date_tm_to_text (ECellDate *ecd,
+                       struct tm *tm_time,
+                       gboolean date_only)
+{
+       const gchar *fmt_component, *fmt_part = NULL;
+
+       if (!tm_time)
+               return g_strdup (_("?"));
+
+       fmt_component = g_object_get_data ((GObject *) ecd, "fmt-component");
+       if (!fmt_component || !*fmt_component)
+               fmt_component = "Default";
+       else
+               fmt_part = "table";
+
+       return e_datetime_format_format_tm (fmt_component, fmt_part,
+               date_only ? DTFormatKindDate : DTFormatKindDateTime, tm_time);
+}
diff --git a/e-util/e-cell-date.h b/e-util/e-cell-date.h
index adda2a2..3d4c6b0 100644
--- a/e-util/e-cell-date.h
+++ b/e-util/e-cell-date.h
@@ -67,7 +67,12 @@ ECell *              e_cell_date_new                 (const gchar *fontname,
 void           e_cell_date_set_format_component
                                                (ECellDate *ecd,
                                                 const gchar *fmt_component);
-
+gchar *                e_cell_date_value_to_text       (ECellDate *ecd,
+                                                gint64 value,
+                                                gboolean date_only);
+gchar *                e_cell_date_tm_to_text          (ECellDate *ecd,
+                                                struct tm *tm_time,
+                                                gboolean date_only);
 G_END_DECLS
 
 #endif /* E_CELL_DATE_H */
diff --git a/e-util/e-table-extras.c b/e-util/e-table-extras.c
index 43fca94..8f43a1f 100644
--- a/e-util/e-table-extras.c
+++ b/e-util/e-table-extras.c
@@ -32,6 +32,7 @@
 
 #include "e-cell-checkbox.h"
 #include "e-cell-date.h"
+#include "e-cell-date-int.h"
 #include "e-cell-number.h"
 #include "e-cell-pixbuf.h"
 #include "e-cell-size.h"
@@ -303,6 +304,10 @@ e_table_extras_init (ETableExtras *extras)
        e_table_extras_add_cell (extras, "date", cell);
        g_object_unref (cell);
 
+       cell = e_cell_date_int_new (NULL, GTK_JUSTIFY_LEFT);
+       e_table_extras_add_cell (extras, "date-int", cell);
+       g_object_unref (cell);
+
        cell = e_cell_number_new (NULL, GTK_JUSTIFY_RIGHT);
        e_table_extras_add_cell (extras, "number", cell);
        g_object_unref (cell);
diff --git a/e-util/e-util.h b/e-util/e-util.h
index eab44a7..e8597f1 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -63,6 +63,7 @@
 #include <e-util/e-cell-checkbox.h>
 #include <e-util/e-cell-combo.h>
 #include <e-util/e-cell-date-edit.h>
+#include <e-util/e-cell-date-int.h>
 #include <e-util/e-cell-date.h>
 #include <e-util/e-cell-hbox.h>
 #include <e-util/e-cell-number.h>


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