2008-05-05 Paolo Borelli <pborelli@katamail.com>
[nautilus.git] / libnautilus-private / nautilus-column-utilities.c
blob4aeaf9a47fd4a4b3019d19ac74eff368f864267b
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
3 /* nautilus-column-utilities.h - Utilities related to column specifications
5 Copyright (C) 2004 Novell, Inc.
7 The Gnome Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 The Gnome 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.
17 You should have received a copy of the GNU Library General Public
18 License along with the Gnome Library; see the column COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 Authors: Dave Camp <dave@ximian.com>
25 #include <config.h>
26 #include "nautilus-column-utilities.h"
28 #include <string.h>
29 #include <eel/eel-glib-extensions.h>
30 #include <glib/gi18n.h>
31 #include <libnautilus-extension/nautilus-column-provider.h>
32 #include <libnautilus-private/nautilus-module.h>
34 static GList *
35 get_builtin_columns (void)
37 GList *columns;
39 columns = g_list_append (NULL,
40 g_object_new (NAUTILUS_TYPE_COLUMN,
41 "name", "name",
42 "attribute", "name",
43 "label", _("Name"),
44 "description", _("The name and icon of the file."),
45 NULL));
46 columns = g_list_append (columns,
47 g_object_new (NAUTILUS_TYPE_COLUMN,
48 "name", "size",
49 "attribute", "size",
50 "label", _("Size"),
51 "description", _("The size of the file."),
52 "xalign", 1.0,
53 NULL));
54 columns = g_list_append (columns,
55 g_object_new (NAUTILUS_TYPE_COLUMN,
56 "name", "type",
57 "attribute", "type",
58 "label", _("Type"),
59 "description", _("The type of the file."),
60 NULL));
61 columns = g_list_append (columns,
62 g_object_new (NAUTILUS_TYPE_COLUMN,
63 "name", "date_modified",
64 "attribute", "date_modified",
65 "label", _("Date Modified"),
66 "description", _("The date the file was modified."),
67 NULL));
69 columns = g_list_append (columns,
70 g_object_new (NAUTILUS_TYPE_COLUMN,
71 "name", "date_accessed",
72 "attribute", "date_accessed",
73 "label", _("Date Accessed"),
74 "description", _("The date the file was accessed."),
75 NULL));
77 columns = g_list_append (columns,
78 g_object_new (NAUTILUS_TYPE_COLUMN,
79 "name", "owner",
80 "attribute", "owner",
81 "label", _("Owner"),
82 "description", _("The owner of the file."),
83 NULL));
85 columns = g_list_append (columns,
86 g_object_new (NAUTILUS_TYPE_COLUMN,
87 "name", "group",
88 "attribute", "group",
89 "label", _("Group"),
90 "description", _("The group of the file."),
91 NULL));
93 columns = g_list_append (columns,
94 g_object_new (NAUTILUS_TYPE_COLUMN,
95 "name", "permissions",
96 "attribute", "permissions",
97 "label", _("Permissions"),
98 "description", _("The permissions of the file."),
99 NULL));
101 columns = g_list_append (columns,
102 g_object_new (NAUTILUS_TYPE_COLUMN,
103 "name", "octal_permissions",
104 "attribute", "octal_permissions",
105 "label", _("Octal Permissions"),
106 "description", _("The permissions of the file, in octal notation."),
107 NULL));
109 columns = g_list_append (columns,
110 g_object_new (NAUTILUS_TYPE_COLUMN,
111 "name", "mime_type",
112 "attribute", "mime_type",
113 "label", _("MIME Type"),
114 "description", _("The mime type of the file."),
115 NULL));
116 columns = g_list_append (columns,
117 g_object_new (NAUTILUS_TYPE_COLUMN,
118 "name", "selinux_context",
119 "attribute", "selinux_context",
120 "label", _("SELinux Context"),
121 "description", _("The SELinux security context of the file."),
122 NULL));
124 return columns;
127 static GList *
128 get_extension_columns (void)
130 GList *columns;
131 GList *providers;
132 GList *l;
134 providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_COLUMN_PROVIDER);
136 columns = NULL;
138 for (l = providers; l != NULL; l = l->next) {
139 NautilusColumnProvider *provider;
140 GList *provider_columns;
142 provider = NAUTILUS_COLUMN_PROVIDER (l->data);
143 provider_columns = nautilus_column_provider_get_columns (provider);
144 columns = g_list_concat (columns, provider_columns);
147 nautilus_module_extension_list_free (providers);
149 return columns;
152 GList *
153 nautilus_get_all_columns (void)
155 static GList *columns = NULL;
157 if (!columns) {
158 columns = g_list_concat (get_builtin_columns (),
159 get_extension_columns ());
162 return nautilus_column_list_copy (columns);
165 GList *
166 nautilus_column_list_copy (GList *columns)
168 GList *ret;
169 GList *l;
171 ret = g_list_copy (columns);
173 for (l = ret; l != NULL; l = l->next) {
174 g_object_ref (l->data);
177 return ret;
180 void
181 nautilus_column_list_free (GList *columns)
183 GList *l;
185 for (l = columns; l != NULL; l = l->next) {
186 g_object_unref (l->data);
189 g_list_free (columns);
192 static int
193 strv_index (char **strv, const char *str)
195 int i;
197 for (i = 0; strv[i] != NULL; ++i) {
198 if (strcmp (strv[i], str) == 0)
199 return i;
202 return -1;
205 static int
206 column_compare (NautilusColumn *a, NautilusColumn *b, char **column_order)
208 int index_a;
209 int index_b;
210 char *name;
212 g_object_get (G_OBJECT (a), "name", &name, NULL);
213 index_a = strv_index (column_order, name);
214 g_free (name);
216 g_object_get (G_OBJECT (b), "name", &name, NULL);
217 index_b = strv_index (column_order, name);
218 g_free (name);
220 if (index_a == index_b) {
221 int ret;
222 char *label_a;
223 char *label_b;
225 g_object_get (G_OBJECT (a), "label", &label_a, NULL);
226 g_object_get (G_OBJECT (b), "label", &label_b, NULL);
227 ret = strcmp (label_a, label_b);
228 g_free (label_a);
229 g_free (label_b);
231 return ret;
232 } else if (index_a == -1) {
233 return 1;
234 } else if (index_b == -1) {
235 return -1;
236 } else {
237 return index_a - index_b;
241 GList *
242 nautilus_sort_columns (GList *columns,
243 char **column_order)
245 return g_list_sort_with_data (columns,
246 (GCompareDataFunc)column_compare,
247 column_order);