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>
26 #include "nautilus-column-utilities.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>
35 get_builtin_columns (void)
39 columns
= g_list_append (NULL
,
40 g_object_new (NAUTILUS_TYPE_COLUMN
,
44 "description", _("The name and icon of the file."),
46 columns
= g_list_append (columns
,
47 g_object_new (NAUTILUS_TYPE_COLUMN
,
51 "description", _("The size of the file."),
54 columns
= g_list_append (columns
,
55 g_object_new (NAUTILUS_TYPE_COLUMN
,
59 "description", _("The type of the file."),
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."),
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."),
77 columns
= g_list_append (columns
,
78 g_object_new (NAUTILUS_TYPE_COLUMN
,
82 "description", _("The owner of the file."),
85 columns
= g_list_append (columns
,
86 g_object_new (NAUTILUS_TYPE_COLUMN
,
90 "description", _("The group of the file."),
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."),
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."),
109 columns
= g_list_append (columns
,
110 g_object_new (NAUTILUS_TYPE_COLUMN
,
112 "attribute", "mime_type",
113 "label", _("MIME Type"),
114 "description", _("The mime type of the file."),
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."),
128 get_extension_columns (void)
134 providers
= nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_COLUMN_PROVIDER
);
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
);
153 nautilus_get_all_columns (void)
155 static GList
*columns
= NULL
;
158 columns
= g_list_concat (get_builtin_columns (),
159 get_extension_columns ());
162 return nautilus_column_list_copy (columns
);
166 nautilus_column_list_copy (GList
*columns
)
171 ret
= g_list_copy (columns
);
173 for (l
= ret
; l
!= NULL
; l
= l
->next
) {
174 g_object_ref (l
->data
);
181 nautilus_column_list_free (GList
*columns
)
185 for (l
= columns
; l
!= NULL
; l
= l
->next
) {
186 g_object_unref (l
->data
);
189 g_list_free (columns
);
193 strv_index (char **strv
, const char *str
)
197 for (i
= 0; strv
[i
] != NULL
; ++i
) {
198 if (strcmp (strv
[i
], str
) == 0)
206 column_compare (NautilusColumn
*a
, NautilusColumn
*b
, char **column_order
)
212 g_object_get (G_OBJECT (a
), "name", &name
, NULL
);
213 index_a
= strv_index (column_order
, name
);
216 g_object_get (G_OBJECT (b
), "name", &name
, NULL
);
217 index_b
= strv_index (column_order
, name
);
220 if (index_a
== index_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
);
232 } else if (index_a
== -1) {
234 } else if (index_b
== -1) {
237 return index_a
- index_b
;
242 nautilus_sort_columns (GList
*columns
,
245 return g_list_sort_with_data (columns
,
246 (GCompareDataFunc
)column_compare
,