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 <unistd.h>
29
30 #include "e-util/e-util.h"
31
32 #include "e-cell-size.h"
33
34 G_DEFINE_TYPE (ECellSize, e_cell_size, E_TYPE_CELL_TEXT)
35
36 static gchar *
37 ecd_get_text (ECellText *cell,
38 ETableModel *model,
39 gint col,
40 gint row)
41 {
42 gint size = GPOINTER_TO_INT (e_table_model_value_at (model, col, row));
43 gfloat fsize;
44
45 if (size < 1024) {
46 return g_strdup_printf ("%d bytes", size);
47 } else {
48 fsize = ((gfloat) size) / 1024.0;
49 if (fsize < 1024.0) {
50 return g_strdup_printf ("%d K", (gint) fsize);
51 } else {
52 fsize /= 1024.0;
53 return g_strdup_printf ("%.1f MB", fsize);
54 }
55 }
56 }
57
58 static void
59 ecd_free_text (ECellText *cell,
60 gchar *text)
61 {
62 g_free (text);
63 }
64
65 static void
66 e_cell_size_class_init (ECellSizeClass *class)
67 {
68 ECellTextClass *ectc = E_CELL_TEXT_CLASS (class);
69
70 ectc->get_text = ecd_get_text;
71 ectc->free_text = ecd_free_text;
72 }
73
74 static void
75 e_cell_size_init (ECellSize *e_cell_size)
76 {
77 }
78
79 /**
80 * e_cell_size_new:
81 * @fontname: font to be used to render on the screen
82 * @justify: Justification of the string in the cell.
83 *
84 * Creates a new ECell renderer that can be used to render file sizes
85 * that that come from the model. The value returned from the model
86 * is interpreted as being a time_t.
87 *
88 * The ECellSize object support a large set of properties that can be
89 * configured through the Gtk argument system and allows the user to
90 * have a finer control of the way the string is displayed. The
91 * arguments supported allow the control of strikeout, underline,
92 * bold, color and a size filter.
93 *
94 * The arguments "strikeout_column", "underline_column", "bold_column"
95 * and "color_column" set and return an integer that points to a
96 * column in the model that controls these settings. So controlling
97 * the way things are rendered is achieved by having special columns
98 * in the model that will be used to flag whether the size should be
99 * rendered with strikeout, underline, or bolded. In the case of the
100 * "color_column" argument, the column in the model is expected to
101 * have a string that can be parsed by gdk_color_parse().
102 *
103 * Returns: an ECell object that can be used to render file sizes. */
104 ECell *
105 e_cell_size_new (const gchar *fontname,
106 GtkJustification justify)
107 {
108 ECellSize *ecd = g_object_new (E_TYPE_CELL_SIZE, NULL);
109
110 e_cell_text_construct (E_CELL_TEXT (ecd), fontname, justify);
111
112 return (ECell *) ecd;
113 }