2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
5 * Copyright (C) 2012, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program 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
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include <glib/gstdio.h>
35 const gchar *a_get_viking_dir()
37 static gchar *viking_dir = NULL;
39 // TODO: use g_get_user_config_dir ?
42 const gchar *home = g_getenv("HOME");
43 if (!home || g_access(home, W_OK))
44 home = g_get_home_dir ();
46 if (!home || g_access(home, W_OK))
48 static gchar temp[] = {"/tmp/vikXXXXXX"};
52 if (!home || g_access(home, W_OK))
54 g_critical("Unable to find a base directory");
56 /* Build the name of the directory */
58 viking_dir = g_build_filename(home, "/Library/Application Support/Viking", NULL);
60 viking_dir = g_build_filename(home, ".viking", NULL);
62 if (g_file_test(viking_dir, G_FILE_TEST_EXISTS) == FALSE)
63 g_mkdir(viking_dir, 0755);
70 * a_get_viking_data_home:
72 * Retrieves the XDG compliant user's data directory.
74 * Retuns: the directory (can be NULL). Should be freed with g_free.
77 a_get_viking_data_home()
79 const gchar *xdg_data_home = g_getenv("XDG_DATA_HOME");
82 return g_build_filename(xdg_data_home, PACKAGE, NULL);
91 * a_get_viking_data_path:
93 * Retrieves the configuration path.
95 * Returns: list of directories to scan for data. Should be freed with g_strfreev.
98 a_get_viking_data_path()
100 const gchar *xdg_data_dirs = g_getenv("XDG_DATA_DIRS");
101 if (xdg_data_dirs == NULL)
103 /* Default value specified in
104 http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
106 xdg_data_dirs = "/usr/local/share/:/usr/share/";
108 gchar **data_path = g_strsplit(xdg_data_dirs, ":", 0);
109 /* Append the viking dir */
111 for (path = data_path ; *path != NULL ; path++)
114 *path = g_build_filename(dir, PACKAGE, NULL);