xed/pluma/pluma-dirs.c

268 lines
5.4 KiB
C
Raw Normal View History

2011-11-07 13:46:58 -06:00
/*
2011-11-07 16:52:18 -06:00
* pluma-dirs.c
* This file is part of pluma
2011-11-07 13:46:58 -06:00
*
* Copyright (C) 2008 Ignacio Casal Quinteiro
2011-11-07 18:10:16 -06:00
* Copyright (C) 2011 Perberos
2011-11-07 13:46:58 -06:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2011-11-07 18:10:16 -06:00
* Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
2011-11-07 13:46:58 -06:00
*/
#ifdef HAVE_CONFIG_H
2011-11-07 18:10:16 -06:00
#include <config.h>
2011-11-07 13:46:58 -06:00
#endif
2011-11-07 16:52:18 -06:00
#include "pluma-dirs.h"
2011-11-07 13:46:58 -06:00
#ifdef OS_OSX
2011-11-07 18:10:16 -06:00
#include <ige-mac-bundle.h>
2011-11-07 13:46:58 -06:00
#endif
2011-11-07 18:10:16 -06:00
gchar* pluma_dirs_get_user_config_dir(void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 18:10:16 -06:00
gchar* config_dir = NULL;
#ifndef G_OS_WIN32
const gchar* envvar;
const gchar* home;
/* Support old libmate env var */
envvar = g_getenv("MATE22_USER_DIR");
if (envvar != NULL)
2011-11-07 13:46:58 -06:00
{
2011-11-07 18:10:16 -06:00
config_dir = g_build_filename(envvar, "pluma", NULL);
2011-11-07 13:46:58 -06:00
}
2011-11-07 18:10:16 -06:00
else
{
home = g_get_home_dir();
if (home != NULL)
{
config_dir = g_build_filename(home, ".config", "pluma", NULL);
}
}
#else
config_dir = g_build_filename(g_get_user_config_dir(), "pluma", NULL);
#endif
2011-11-07 13:46:58 -06:00
return config_dir;
}
2011-11-07 18:10:16 -06:00
gchar* pluma_dirs_get_user_cache_dir(void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 18:10:16 -06:00
const gchar* cache_dir;
2011-11-07 13:46:58 -06:00
2011-11-07 18:10:16 -06:00
cache_dir = g_get_user_cache_dir();
2011-11-07 13:46:58 -06:00
2011-11-07 18:10:16 -06:00
return g_build_filename(cache_dir, "pluma", NULL);
2011-11-07 13:46:58 -06:00
}
2011-11-07 18:10:16 -06:00
gchar* pluma_dirs_get_user_plugins_dir(void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 18:10:16 -06:00
gchar* config_dir;
gchar* plugin_dir;
2011-11-07 13:46:58 -06:00
2011-11-07 18:10:16 -06:00
config_dir = pluma_dirs_get_user_config_dir();
plugin_dir = g_build_filename(config_dir, "plugins", NULL);
g_free(config_dir);
2011-11-07 13:46:58 -06:00
return plugin_dir;
}
2011-11-07 18:10:16 -06:00
gchar* pluma_dirs_get_user_accels_file(void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 18:10:16 -06:00
gchar* accels = NULL;
#ifndef G_OS_WIN32
const gchar* envvar;
const gchar* home;
/* on linux accels are stored in .config/accels
* for historic reasons (backward compat with the
* old libmate that took care of saving them */
/* Support old libmate env var */
envvar = g_getenv("MATE22_USER_DIR");
if (envvar != NULL)
{
accels = g_build_filename(envvar, "accels", "pluma", NULL);
}
else
2011-11-07 13:46:58 -06:00
{
2011-11-07 18:10:16 -06:00
home = g_get_home_dir();
if (home != NULL)
{
accels = g_build_filename(home, ".config", "accels", "pluma", NULL);
}
2011-11-07 13:46:58 -06:00
}
2011-11-07 18:10:16 -06:00
#else
2011-11-07 13:46:58 -06:00
gchar *config_dir = NULL;
2011-11-07 18:10:16 -06:00
config_dir = pluma_dirs_get_user_config_dir();
accels = g_build_filename(config_dir, "accels", "pluma", NULL);
2011-11-07 13:46:58 -06:00
2011-11-07 18:10:16 -06:00
g_free(config_dir);
#endif
2011-11-07 13:46:58 -06:00
return accels;
}
2011-11-07 18:10:16 -06:00
gchar* pluma_dirs_get_pluma_data_dir(void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 18:10:16 -06:00
gchar* data_dir;
#ifdef G_OS_WIN32
gchar* win32_dir;
win32_dir = g_win32_get_package_installation_directory_of_module(NULL);
data_dir = g_build_filename(win32_dir, "share", "pluma", NULL);
g_free(win32_dir);
#elif defined(OS_OSX)
IgeMacBundle* bundle = ige_mac_bundle_get_default();
if (ige_mac_bundle_get_is_app_bundle(bundle))
{
const gchar* bundle_data_dir = ige_mac_bundle_get_datadir(bundle);
data_dir = g_build_filename(bundle_data_dir, "pluma", NULL);
}
else
{
data_dir = g_build_filename(DATADIR, "pluma", NULL);
}
#else
data_dir = g_build_filename(DATADIR, "pluma", NULL);
#endif
2011-11-07 13:46:58 -06:00
return data_dir;
}
2011-11-07 18:10:16 -06:00
gchar* pluma_dirs_get_pluma_locale_dir(void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 18:10:16 -06:00
gchar* locale_dir;
#ifdef G_OS_WIN32
gchar* win32_dir;
win32_dir = g_win32_get_package_installation_directory_of_module(NULL);
locale_dir = g_build_filename(win32_dir, "share", "locale", NULL);
g_free(win32_dir);
#elif defined(OS_OSX)
IgeMacBundle *bundle = ige_mac_bundle_get_default();
if (ige_mac_bundle_get_is_app_bundle(bundle))
{
locale_dir = g_strdup(ige_mac_bundle_get_localedir(bundle));
}
else
{
locale_dir = g_build_filename(DATADIR, "locale", NULL);
}
#else
locale_dir = g_build_filename(DATADIR, "locale", NULL);
#endif
2011-11-07 13:46:58 -06:00
return locale_dir;
}
2011-11-07 18:10:16 -06:00
gchar* pluma_dirs_get_pluma_lib_dir(void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 18:10:16 -06:00
gchar* lib_dir;
#ifdef G_OS_WIN32
gchar* win32_dir;
win32_dir = g_win32_get_package_installation_directory_of_module(NULL);
lib_dir = g_build_filename(win32_dir, "lib", "pluma", NULL);
g_free(win32_dir);
#elif defined(OS_OSX)
IgeMacBundle* bundle = ige_mac_bundle_get_default();
if (ige_mac_bundle_get_is_app_bundle(bundle))
{
const gchar* path = ige_mac_bundle_get_resourcesdir(bundle);
lib_dir = g_build_filename(path, "lib", "pluma", NULL);
}
else
{
lib_dir = g_build_filename(LIBDIR, "pluma", NULL);
}
#else
lib_dir = g_build_filename(LIBDIR, "pluma", NULL);
#endif
2011-11-07 13:46:58 -06:00
return lib_dir;
}
2011-11-07 18:10:16 -06:00
gchar* pluma_dirs_get_pluma_plugins_dir(void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 18:10:16 -06:00
gchar* lib_dir;
gchar* plugin_dir;
lib_dir = pluma_dirs_get_pluma_lib_dir();
plugin_dir = g_build_filename(lib_dir, "plugins", NULL);
g_free(lib_dir);
2011-11-07 13:46:58 -06:00
return plugin_dir;
}
2011-11-07 18:10:16 -06:00
gchar* pluma_dirs_get_pluma_plugin_loaders_dir(void)
2011-11-07 13:46:58 -06:00
{
2011-11-07 18:10:16 -06:00
gchar* lib_dir;
gchar* loader_dir;
lib_dir = pluma_dirs_get_pluma_lib_dir();
loader_dir = g_build_filename(lib_dir, "plugin-loaders", NULL);
g_free(lib_dir);
2011-11-07 13:46:58 -06:00
return loader_dir;
}
2011-11-07 18:10:16 -06:00
gchar* pluma_dirs_get_ui_file(const gchar* file)
2011-11-07 13:46:58 -06:00
{
2011-11-07 18:10:16 -06:00
gchar* datadir;
gchar* ui_file;
g_return_val_if_fail(file != NULL, NULL);
datadir = pluma_dirs_get_pluma_data_dir();
ui_file = g_build_filename(datadir, "ui", file, NULL);
g_free(datadir);
2011-11-07 13:46:58 -06:00
return ui_file;
}