No issues found
1 /*
2 * nautilus-column.c - Info columns exported by NautilusColumnProvider
3 * objects.
4 *
5 * Copyright (C) 2003 Novell, Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 * Author: Dave Camp <dave@ximian.com>
22 *
23 */
24
25 #include <config.h>
26 #include <gtk/gtk.h>
27 #include "nautilus-column.h"
28 #include "nautilus-extension-i18n.h"
29
30 enum {
31 PROP_0,
32 PROP_NAME,
33 PROP_ATTRIBUTE,
34 PROP_ATTRIBUTE_Q,
35 PROP_LABEL,
36 PROP_DESCRIPTION,
37 PROP_XALIGN,
38 PROP_DEFAULT_SORT_ORDER,
39 LAST_PROP
40 };
41
42 struct _NautilusColumnDetails {
43 char *name;
44 GQuark attribute;
45 char *label;
46 char *description;
47 float xalign;
48 GtkSortType default_sort_order;
49 };
50
51 G_DEFINE_TYPE (NautilusColumn, nautilus_column, G_TYPE_OBJECT);
52
53 /**
54 * nautilus_column_new:
55 * @name: identifier of the column
56 * @attribute: the file attribute to be displayed in the column
57 * @label: the user-visible label for the column
58 * @description: a user-visible description of the column
59 *
60 * Creates a new column
61 *
62 * Returns: a newly created #NautilusColumn
63 */
64 NautilusColumn *
65 nautilus_column_new (const char *name,
66 const char *attribute,
67 const char *label,
68 const char *description)
69 {
70 NautilusColumn *column;
71
72 g_return_val_if_fail (name != NULL, NULL);
73 g_return_val_if_fail (attribute != NULL, NULL);
74 g_return_val_if_fail (label != NULL, NULL);
75 g_return_val_if_fail (description != NULL, NULL);
76
77 column = g_object_new (NAUTILUS_TYPE_COLUMN,
78 "name", name,
79 "attribute", attribute,
80 "label", label,
81 "description", description,
82 NULL);
83
84 return column;
85 }
86
87 static void
88 nautilus_column_get_property (GObject *object,
89 guint param_id,
90 GValue *value,
91 GParamSpec *pspec)
92 {
93 NautilusColumn *column;
94
95 column = NAUTILUS_COLUMN (object);
96
97 switch (param_id) {
98 case PROP_NAME :
99 g_value_set_string (value, column->details->name);
100 break;
101 case PROP_ATTRIBUTE :
102 g_value_set_string (value, g_quark_to_string (column->details->attribute));
103 break;
104 case PROP_ATTRIBUTE_Q :
105 g_value_set_uint (value, column->details->attribute);
106 break;
107 case PROP_LABEL :
108 g_value_set_string (value, column->details->label);
109 break;
110 case PROP_DESCRIPTION :
111 g_value_set_string (value, column->details->description);
112 break;
113 case PROP_XALIGN :
114 g_value_set_float (value, column->details->xalign);
115 break;
116 case PROP_DEFAULT_SORT_ORDER :
117 g_value_set_enum (value, column->details->default_sort_order);
118 break;
119 default :
120 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
121 break;
122 }
123 }
124
125 static void
126 nautilus_column_set_property (GObject *object,
127 guint param_id,
128 const GValue *value,
129 GParamSpec *pspec)
130 {
131 NautilusColumn *column;
132
133 column = NAUTILUS_COLUMN (object);
134
135 switch (param_id) {
136 case PROP_NAME :
137 g_free (column->details->name);
138 column->details->name = g_strdup (g_value_get_string (value));
139 g_object_notify (object, "name");
140 break;
141 case PROP_ATTRIBUTE :
142 column->details->attribute = g_quark_from_string (g_value_get_string (value));
143 g_object_notify (object, "attribute");
144 g_object_notify (object, "attribute_q");
145 break;
146 case PROP_LABEL :
147 g_free (column->details->label);
148 column->details->label = g_strdup (g_value_get_string (value));
149 g_object_notify (object, "label");
150 break;
151 case PROP_DESCRIPTION :
152 g_free (column->details->description);
153 column->details->description = g_strdup (g_value_get_string (value));
154 g_object_notify (object, "description");
155 break;
156 case PROP_XALIGN :
157 column->details->xalign = g_value_get_float (value);
158 g_object_notify (object, "xalign");
159 break;
160 case PROP_DEFAULT_SORT_ORDER :
161 column->details->default_sort_order = g_value_get_enum (value);
162 g_object_notify (object, "default-sort-order");
163 break;
164 default :
165 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
166 break;
167 }
168 }
169
170 static void
171 nautilus_column_finalize (GObject *object)
172 {
173 NautilusColumn *column;
174
175 column = NAUTILUS_COLUMN (object);
176
177 g_free (column->details->name);
178 g_free (column->details->label);
179 g_free (column->details->description);
180
181 g_free (column->details);
182
183 G_OBJECT_CLASS (nautilus_column_parent_class)->finalize (object);
184 }
185
186 static void
187 nautilus_column_init (NautilusColumn *column)
188 {
189 column->details = g_new0 (NautilusColumnDetails, 1);
190 column->details->xalign = 0.0;
191 }
192
193 static void
194 nautilus_column_class_init (NautilusColumnClass *class)
195 {
196 G_OBJECT_CLASS (class)->finalize = nautilus_column_finalize;
197 G_OBJECT_CLASS (class)->get_property = nautilus_column_get_property;
198 G_OBJECT_CLASS (class)->set_property = nautilus_column_set_property;
199
200 g_object_class_install_property (G_OBJECT_CLASS (class),
201 PROP_NAME,
202 g_param_spec_string ("name",
203 "Name",
204 "Name of the column",
205 NULL,
206 G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE));
207 g_object_class_install_property (G_OBJECT_CLASS (class),
208 PROP_ATTRIBUTE,
209 g_param_spec_string ("attribute",
210 "Attribute",
211 "The attribute name to display",
212 NULL,
213 G_PARAM_READWRITE));
214 g_object_class_install_property (G_OBJECT_CLASS (class),
215 PROP_ATTRIBUTE_Q,
216 g_param_spec_uint ("attribute_q",
217 "Attribute quark",
218 "The attribute name to display, in quark form",
219 0, G_MAXUINT, 0,
220 G_PARAM_READABLE));
221 g_object_class_install_property (G_OBJECT_CLASS (class),
222 PROP_LABEL,
223 g_param_spec_string ("label",
224 "Label",
225 "Label to display in the column",
226 NULL,
227 G_PARAM_READWRITE));
228 g_object_class_install_property (G_OBJECT_CLASS (class),
229 PROP_DESCRIPTION,
230 g_param_spec_string ("description",
231 "Description",
232 "A user-visible description of the column",
233 NULL,
234 G_PARAM_READWRITE));
235
236 g_object_class_install_property (G_OBJECT_CLASS (class),
237 PROP_XALIGN,
238 g_param_spec_float ("xalign",
239 "xalign",
240 "The x-alignment of the column",
241 0.0,
242 1.0,
243 0.0,
244 G_PARAM_READWRITE));
245 g_object_class_install_property (G_OBJECT_CLASS (class),
246 PROP_DEFAULT_SORT_ORDER,
247 g_param_spec_enum ("default-sort-order",
248 "Default sort order",
249 "Default sort order",
250 GTK_TYPE_SORT_TYPE,
251 GTK_SORT_ASCENDING,
252 G_PARAM_READWRITE));
253 }