No issues found
1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2 of the License, or (at your option) version 3.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with the program; if not, see <http://www.gnu.org/licenses/>
14 *
15 *
16 * Authors:
17 * Chris Lahey <clahey@ximian.com>
18 *
19 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
20 *
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <sys/time.h>
28 #include <time.h>
29 #include <unistd.h>
30 #include <string.h>
31
32 #include <glib/gi18n.h>
33 #include "e-util/e-util.h"
34 #include "e-util/e-unicode.h"
35 #include "e-util/e-datetime-format.h"
36
37 #include "e-cell-date.h"
38
39 G_DEFINE_TYPE (ECellDate, e_cell_date, E_TYPE_CELL_TEXT)
40
41 static gchar *
42 ecd_get_text (ECellText *cell,
43 ETableModel *model,
44 gint col,
45 gint row)
46 {
47 time_t date = GPOINTER_TO_INT (e_table_model_value_at (model, col, row));
48 const gchar *fmt_component, *fmt_part = NULL;
49
50 if (date == 0) {
51 return g_strdup (_("?"));
52 }
53
54 fmt_component = g_object_get_data ((GObject *) cell, "fmt-component");
55 if (!fmt_component || !*fmt_component)
56 fmt_component = "Default";
57 else
58 fmt_part = "table";
59
60 return e_datetime_format_format (
61 fmt_component, fmt_part, DTFormatKindDateTime, date);
62 }
63
64 static void
65 ecd_free_text (ECellText *cell,
66 gchar *text)
67 {
68 g_free (text);
69 }
70
71 static void
72 e_cell_date_class_init (ECellDateClass *class)
73 {
74 ECellTextClass *ectc = E_CELL_TEXT_CLASS (class);
75
76 ectc->get_text = ecd_get_text;
77 ectc->free_text = ecd_free_text;
78 }
79
80 static void
81 e_cell_date_init (ECellDate *ecd)
82 {
83 }
84
85 /**
86 * e_cell_date_new:
87 * @fontname: font to be used to render on the screen
88 * @justify: Justification of the string in the cell.
89 *
90 * Creates a new ECell renderer that can be used to render dates that
91 * that come from the model. The value returned from the model is
92 * interpreted as being a time_t.
93 *
94 * The ECellDate object support a large set of properties that can be
95 * configured through the Gtk argument system and allows the user to have
96 * a finer control of the way the string is displayed. The arguments supported
97 * allow the control of strikeout, bold, color and a date filter.
98 *
99 * The arguments "strikeout_column", "underline_column", "bold_column"
100 * and "color_column" set and return an integer that points to a
101 * column in the model that controls these settings. So controlling
102 * the way things are rendered is achieved by having special columns
103 * in the model that will be used to flag whether the date should be
104 * rendered with strikeout, underline, or bolded. In the case of the
105 * "color_column" argument, the column in the model is expected to
106 * have a string that can be parsed by gdk_color_parse().
107 *
108 * Returns: an ECell object that can be used to render dates.
109 */
110 ECell *
111 e_cell_date_new (const gchar *fontname,
112 GtkJustification justify)
113 {
114 ECellDate *ecd = g_object_new (E_TYPE_CELL_DATE, NULL);
115
116 e_cell_text_construct (E_CELL_TEXT (ecd), fontname, justify);
117
118 return (ECell *) ecd;
119 }
120
121 void
122 e_cell_date_set_format_component (ECellDate *ecd,
123 const gchar *fmt_component)
124 {
125 g_return_if_fail (ecd != NULL);
126
127 g_object_set_data_full (
128 G_OBJECT (ecd), "fmt-component",
129 g_strdup (fmt_component), g_free);
130 }