summaryrefslogtreecommitdiffstats
path: root/gedit/gedit-dirs.c
blob: 81f32c287c55bf6ba66a601a85132cb3f6981961 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
 * gedit-dirs.c
 * This file is part of gedit
 *
 * Copyright (C) 2008 Ignacio Casal Quinteiro
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */

#include "config.h"

#include "gedit-dirs.h"

#ifdef OS_OSX
#include <gtkosxapplication.h>
#endif

static gchar *user_config_dir        = NULL;
static gchar *user_data_dir          = NULL;
static gchar *user_styles_dir        = NULL;
static gchar *user_plugins_dir       = NULL;
static gchar *gedit_locale_dir       = NULL;
static gchar *gedit_lib_dir          = NULL;
static gchar *gedit_plugins_dir      = NULL;
static gchar *gedit_plugins_data_dir = NULL;

void
gedit_dirs_init ()
{
#ifdef G_OS_WIN32
	gchar *win32_dir;

	win32_dir = g_win32_get_package_installation_directory_of_module (NULL);

	gedit_locale_dir = g_build_filename (win32_dir,
					     "share",
					     "locale",
					     NULL);
	gedit_lib_dir = g_build_filename (win32_dir,
					  "lib",
					  "gedit",
					  NULL);
	gedit_plugins_data_dir = g_build_filename (win32_dir,
						   "share",
						   "gedit",
						   "plugins",
						   NULL);

	g_free (win32_dir);
#endif /* G_OS_WIN32 */

#ifdef OS_OSX
	if (gtkosx_application_get_bundle_id () != NULL)
	{
		const gchar *bundle_resource_dir = gtkosx_application_get_resource_path ();

		gedit_locale_dir = g_build_filename (bundle_resource_dir,
						     "share",
						     "locale",
						     NULL);
		gedit_lib_dir = g_build_filename (bundle_resource_dir,
						  "lib",
						  "gedit",
						  NULL);
		gedit_plugins_data_dir = g_build_filename (bundle_resource_dir,
							   "share",
							   "gedit",
							   "plugins",
							   NULL);
	}
#endif /* OS_OSX */

	if (gedit_locale_dir == NULL)
	{
		gedit_locale_dir = g_build_filename (DATADIR,
						     "locale",
						     NULL);
		gedit_lib_dir = g_build_filename (LIBDIR,
						  "gedit",
						  NULL);
		gedit_plugins_data_dir = g_build_filename (DATADIR,
							   "gedit",
							   "plugins",
							   NULL);
	}

	user_config_dir = g_build_filename (g_get_user_config_dir (),
					    "gedit",
					    NULL);
	user_data_dir = g_build_filename (g_get_user_data_dir (),
					  "gedit",
					  NULL);
	user_styles_dir = g_build_filename (user_data_dir,
					    "styles",
					    NULL);
	user_plugins_dir = g_build_filename (user_data_dir,
					     "plugins",
					     NULL);
	gedit_plugins_dir = g_build_filename (gedit_lib_dir,
					      "plugins",
					      NULL);
}

void
gedit_dirs_shutdown ()
{
	g_clear_pointer (&user_config_dir, g_free);
	g_clear_pointer (&user_data_dir, g_free);
	g_clear_pointer (&user_styles_dir, g_free);
	g_clear_pointer (&user_plugins_dir, g_free);
	g_clear_pointer (&gedit_locale_dir, g_free);
	g_clear_pointer (&gedit_lib_dir, g_free);
	g_clear_pointer (&gedit_plugins_dir, g_free);
	g_clear_pointer (&gedit_plugins_data_dir, g_free);
}

const gchar *
gedit_dirs_get_user_config_dir (void)
{
	return user_config_dir;
}

const gchar *
gedit_dirs_get_user_data_dir (void)
{
	return user_data_dir;
}

const gchar *
gedit_dirs_get_user_styles_dir (void)
{
	return user_styles_dir;
}

const gchar *
gedit_dirs_get_user_plugins_dir (void)
{
	return user_plugins_dir;
}

const gchar *
gedit_dirs_get_gedit_locale_dir (void)
{
	return gedit_locale_dir;
}

const gchar *
gedit_dirs_get_gedit_lib_dir (void)
{
	return gedit_lib_dir;
}

const gchar *
gedit_dirs_get_gedit_plugins_dir (void)
{
	return gedit_plugins_dir;
}

const gchar *
gedit_dirs_get_gedit_plugins_data_dir (void)
{
	return gedit_plugins_data_dir;
}

/* ex:set ts=8 noet: */