1 /*
2  * Nautilus-Actions
3  * A Nautilus extension which offers configurable context menu actions.
4  *
5  * Copyright (C) 2005 The GNOME Foundation
6  * Copyright (C) 2006-2008 Frederic Ruaudel and others (see AUTHORS)
7  * Copyright (C) 2009-2014 Pierre Wieser and others (see AUTHORS)
8  *
9  * Nautilus-Actions is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
13  *
14  * Nautilus-Actions is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with Nautilus-Actions; see the file COPYING. If not, see
21  * <http://www.gnu.org/licenses/>.
22  *
23  * Authors:
24  *   Frederic Ruaudel <grumz@grumz.net>
25  *   Rodrigo Moya <rodrigo@gnome-db.org>
26  *   Pierre Wieser <pwieser@trychlos.org>
27  *   ... and many others (see AUTHORS)
28  */
29 
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 
34 #include <api/na-core-utils.h>
35 
36 #include "nadp-xdg-dirs.h"
37 
38 /**
39  * nadp_xdg_dirs_get_data_dirs:
40  *
41  * Returns: the ordered list of data directories, most important first,
42  * as a GSList of newly allocated strings.
43  *
44  * The returned list, along with the pointed out strings, should be
45  * freed by the caller.
46  */
47 GSList *
nadp_xdg_dirs_get_data_dirs(void)48 nadp_xdg_dirs_get_data_dirs( void )
49 {
50 	GSList *listdirs;
51 	gchar *userdir;
52 	GSList *datadirs;
53 
54 	userdir = nadp_xdg_dirs_get_user_data_dir();
55 	listdirs = g_slist_prepend( NULL, userdir );
56 
57 	datadirs = nadp_xdg_dirs_get_system_data_dirs();
58 	listdirs = g_slist_concat( listdirs, datadirs );
59 
60 	return( listdirs );
61 }
62 
63 /**
64  * nadp_xdg_dirs_get_user_data_dir:
65  *
66  * Returns: the path to the single base directory relative to which
67  * user-specific data files should be written, as a newly allocated
68  * string.
69  *
70  * This directory is defined by the environment variable XDG_DATA_HOME.
71  * It defaults to ~/.local/share.
72  * cf. http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
73  *
74  * The returned string should be g_free() by the caller.
75  */
76 gchar *
nadp_xdg_dirs_get_user_data_dir(void)77 nadp_xdg_dirs_get_user_data_dir( void )
78 {
79 	gchar *dir;
80 
81 	dir = g_strdup( g_get_user_data_dir());
82 
83 	return( dir );
84 }
85 
86 /**
87  * nadp_xdg_dirs_get_system_data_dirs:
88  *
89  * Returns: the set of preference ordered base directories relative to
90  * which data files should be written, as a GSList of newly allocated
91  * strings.
92  *
93  * This set of directories is defined by the environment variable
94  * XDG_DATA_DIRS. It defaults to /usr/local/share:/usr/share.
95  *
96  * source: http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
97  *
98  * The returned list, along with the pointed out strings, should be freed
99  * by the caller.
100  */
101 GSList *
nadp_xdg_dirs_get_system_data_dirs(void)102 nadp_xdg_dirs_get_system_data_dirs( void )
103 {
104 	const gchar **dirs;
105 	GSList *paths;
106 
107 	dirs = ( const gchar ** ) g_get_system_data_dirs();
108 
109 	paths = na_core_utils_slist_from_array( dirs );
110 
111 	return( paths );
112 }
113