1/* gkeyfile.h - desktop entry file parser
2 *
3 * Copyright 2004 Red Hat, Inc.
4 *
5 * Ray Strode <halfline@hawaii.rr.com>
6 *
7 * SPDX-License-Identifier: LGPL-2.1-or-later
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library 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 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef __G_KEY_FILE_H__
24#define __G_KEY_FILE_H__
25
26#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
27#error "Only <glib.h> can be included directly."
28#endif
29
30#include <glib/gbytes.h>
31#include <glib/gerror.h>
32
33G_BEGIN_DECLS
34
35typedef enum
36{
37 G_KEY_FILE_ERROR_UNKNOWN_ENCODING,
38 G_KEY_FILE_ERROR_PARSE,
39 G_KEY_FILE_ERROR_NOT_FOUND,
40 G_KEY_FILE_ERROR_KEY_NOT_FOUND,
41 G_KEY_FILE_ERROR_GROUP_NOT_FOUND,
42 G_KEY_FILE_ERROR_INVALID_VALUE
43} GKeyFileError;
44
45#define G_KEY_FILE_ERROR g_key_file_error_quark()
46
47GLIB_AVAILABLE_IN_ALL
48GQuark g_key_file_error_quark (void);
49
50typedef struct _GKeyFile GKeyFile;
51
52typedef enum
53{
54 G_KEY_FILE_NONE = 0,
55 G_KEY_FILE_KEEP_COMMENTS = 1 << 0,
56 G_KEY_FILE_KEEP_TRANSLATIONS = 1 << 1
57} G_GNUC_FLAG_ENUM GKeyFileFlags;
58
59GLIB_AVAILABLE_IN_ALL
60GKeyFile *g_key_file_new (void);
61GLIB_AVAILABLE_IN_ALL
62GKeyFile *g_key_file_ref (GKeyFile *key_file);
63GLIB_AVAILABLE_IN_ALL
64void g_key_file_unref (GKeyFile *key_file);
65GLIB_AVAILABLE_IN_ALL
66void g_key_file_free (GKeyFile *key_file);
67GLIB_AVAILABLE_IN_ALL
68void g_key_file_set_list_separator (GKeyFile *key_file,
69 gchar separator);
70GLIB_AVAILABLE_IN_ALL
71gboolean g_key_file_load_from_file (GKeyFile *key_file,
72 const gchar *file,
73 GKeyFileFlags flags,
74 GError **error);
75GLIB_AVAILABLE_IN_ALL
76gboolean g_key_file_load_from_data (GKeyFile *key_file,
77 const gchar *data,
78 gsize length,
79 GKeyFileFlags flags,
80 GError **error);
81
82GLIB_AVAILABLE_IN_2_90
83gboolean g_key_file_load_unix_configurations (GKeyFile *key_file,
84 const gchar *project,
85 const gchar *etc_subdir,
86 const gchar *run_subdir,
87 const gchar *usr_subdir,
88 const gchar *config_name,
89 const gchar *config_suffix,
90 GKeyFileFlags flags,
91 GError **error);
92
93GLIB_AVAILABLE_IN_2_50
94gboolean g_key_file_load_from_bytes (GKeyFile *key_file,
95 GBytes *bytes,
96 GKeyFileFlags flags,
97 GError **error);
98GLIB_AVAILABLE_IN_ALL
99gboolean g_key_file_load_from_dirs (GKeyFile *key_file,
100 const gchar *file,
101 const gchar **search_dirs,
102 gchar **full_path,
103 GKeyFileFlags flags,
104 GError **error);
105GLIB_AVAILABLE_IN_ALL
106gboolean g_key_file_load_from_data_dirs (GKeyFile *key_file,
107 const gchar *file,
108 gchar **full_path,
109 GKeyFileFlags flags,
110 GError **error);
111GLIB_AVAILABLE_IN_ALL
112gchar *g_key_file_to_data (GKeyFile *key_file,
113 gsize *length,
114 GError **error) G_GNUC_MALLOC;
115GLIB_AVAILABLE_IN_2_40
116gboolean g_key_file_save_to_file (GKeyFile *key_file,
117 const gchar *filename,
118 GError **error);
119GLIB_AVAILABLE_IN_ALL
120gchar *g_key_file_get_start_group (GKeyFile *key_file) G_GNUC_MALLOC;
121GLIB_AVAILABLE_IN_ALL
122gchar **g_key_file_get_groups (GKeyFile *key_file,
123 gsize *length);
124GLIB_AVAILABLE_IN_ALL
125gchar **g_key_file_get_keys (GKeyFile *key_file,
126 const gchar *group_name,
127 gsize *length,
128 GError **error);
129GLIB_AVAILABLE_IN_ALL
130gboolean g_key_file_has_group (GKeyFile *key_file,
131 const gchar *group_name);
132GLIB_AVAILABLE_IN_ALL
133gboolean g_key_file_has_key (GKeyFile *key_file,
134 const gchar *group_name,
135 const gchar *key,
136 GError **error);
137GLIB_AVAILABLE_IN_ALL
138gchar *g_key_file_get_value (GKeyFile *key_file,
139 const gchar *group_name,
140 const gchar *key,
141 GError **error) G_GNUC_MALLOC;
142GLIB_AVAILABLE_IN_ALL
143void g_key_file_set_value (GKeyFile *key_file,
144 const gchar *group_name,
145 const gchar *key,
146 const gchar *value);
147GLIB_AVAILABLE_IN_ALL
148gchar *g_key_file_get_string (GKeyFile *key_file,
149 const gchar *group_name,
150 const gchar *key,
151 GError **error) G_GNUC_MALLOC;
152GLIB_AVAILABLE_IN_ALL
153void g_key_file_set_string (GKeyFile *key_file,
154 const gchar *group_name,
155 const gchar *key,
156 const gchar *string);
157GLIB_AVAILABLE_IN_ALL
158gchar *g_key_file_get_locale_string (GKeyFile *key_file,
159 const gchar *group_name,
160 const gchar *key,
161 const gchar *locale,
162 GError **error) G_GNUC_MALLOC;
163GLIB_AVAILABLE_IN_2_56
164gchar *g_key_file_get_locale_for_key (GKeyFile *key_file,
165 const gchar *group_name,
166 const gchar *key,
167 const gchar *locale) G_GNUC_MALLOC;
168GLIB_AVAILABLE_IN_ALL
169void g_key_file_set_locale_string (GKeyFile *key_file,
170 const gchar *group_name,
171 const gchar *key,
172 const gchar *locale,
173 const gchar *string);
174GLIB_AVAILABLE_IN_ALL
175gboolean g_key_file_get_boolean (GKeyFile *key_file,
176 const gchar *group_name,
177 const gchar *key,
178 GError **error);
179GLIB_AVAILABLE_IN_ALL
180void g_key_file_set_boolean (GKeyFile *key_file,
181 const gchar *group_name,
182 const gchar *key,
183 gboolean value);
184GLIB_AVAILABLE_IN_ALL
185gint g_key_file_get_integer (GKeyFile *key_file,
186 const gchar *group_name,
187 const gchar *key,
188 GError **error);
189GLIB_AVAILABLE_IN_ALL
190void g_key_file_set_integer (GKeyFile *key_file,
191 const gchar *group_name,
192 const gchar *key,
193 gint value);
194GLIB_AVAILABLE_IN_ALL
195gint64 g_key_file_get_int64 (GKeyFile *key_file,
196 const gchar *group_name,
197 const gchar *key,
198 GError **error);
199GLIB_AVAILABLE_IN_ALL
200void g_key_file_set_int64 (GKeyFile *key_file,
201 const gchar *group_name,
202 const gchar *key,
203 gint64 value);
204GLIB_AVAILABLE_IN_ALL
205guint64 g_key_file_get_uint64 (GKeyFile *key_file,
206 const gchar *group_name,
207 const gchar *key,
208 GError **error);
209GLIB_AVAILABLE_IN_ALL
210void g_key_file_set_uint64 (GKeyFile *key_file,
211 const gchar *group_name,
212 const gchar *key,
213 guint64 value);
214GLIB_AVAILABLE_IN_ALL
215gdouble g_key_file_get_double (GKeyFile *key_file,
216 const gchar *group_name,
217 const gchar *key,
218 GError **error);
219GLIB_AVAILABLE_IN_ALL
220void g_key_file_set_double (GKeyFile *key_file,
221 const gchar *group_name,
222 const gchar *key,
223 gdouble value);
224GLIB_AVAILABLE_IN_ALL
225gchar **g_key_file_get_string_list (GKeyFile *key_file,
226 const gchar *group_name,
227 const gchar *key,
228 gsize *length,
229 GError **error);
230GLIB_AVAILABLE_IN_ALL
231void g_key_file_set_string_list (GKeyFile *key_file,
232 const gchar *group_name,
233 const gchar *key,
234 const gchar * const list[],
235 gsize length);
236GLIB_AVAILABLE_IN_ALL
237gchar **g_key_file_get_locale_string_list (GKeyFile *key_file,
238 const gchar *group_name,
239 const gchar *key,
240 const gchar *locale,
241 gsize *length,
242 GError **error);
243GLIB_AVAILABLE_IN_ALL
244void g_key_file_set_locale_string_list (GKeyFile *key_file,
245 const gchar *group_name,
246 const gchar *key,
247 const gchar *locale,
248 const gchar * const list[],
249 gsize length);
250GLIB_AVAILABLE_IN_ALL
251gboolean *g_key_file_get_boolean_list (GKeyFile *key_file,
252 const gchar *group_name,
253 const gchar *key,
254 gsize *length,
255 GError **error) G_GNUC_MALLOC;
256GLIB_AVAILABLE_IN_ALL
257void g_key_file_set_boolean_list (GKeyFile *key_file,
258 const gchar *group_name,
259 const gchar *key,
260 gboolean list[],
261 gsize length);
262GLIB_AVAILABLE_IN_ALL
263gint *g_key_file_get_integer_list (GKeyFile *key_file,
264 const gchar *group_name,
265 const gchar *key,
266 gsize *length,
267 GError **error) G_GNUC_MALLOC;
268GLIB_AVAILABLE_IN_ALL
269void g_key_file_set_double_list (GKeyFile *key_file,
270 const gchar *group_name,
271 const gchar *key,
272 gdouble list[],
273 gsize length);
274GLIB_AVAILABLE_IN_ALL
275gdouble *g_key_file_get_double_list (GKeyFile *key_file,
276 const gchar *group_name,
277 const gchar *key,
278 gsize *length,
279 GError **error) G_GNUC_MALLOC;
280GLIB_AVAILABLE_IN_ALL
281void g_key_file_set_integer_list (GKeyFile *key_file,
282 const gchar *group_name,
283 const gchar *key,
284 gint list[],
285 gsize length);
286GLIB_AVAILABLE_IN_ALL
287gboolean g_key_file_set_comment (GKeyFile *key_file,
288 const gchar *group_name,
289 const gchar *key,
290 const gchar *comment,
291 GError **error);
292GLIB_AVAILABLE_IN_ALL
293gchar *g_key_file_get_comment (GKeyFile *key_file,
294 const gchar *group_name,
295 const gchar *key,
296 GError **error) G_GNUC_MALLOC;
297
298GLIB_AVAILABLE_IN_ALL
299gboolean g_key_file_remove_comment (GKeyFile *key_file,
300 const gchar *group_name,
301 const gchar *key,
302 GError **error);
303GLIB_AVAILABLE_IN_ALL
304gboolean g_key_file_remove_key (GKeyFile *key_file,
305 const gchar *group_name,
306 const gchar *key,
307 GError **error);
308GLIB_AVAILABLE_IN_ALL
309gboolean g_key_file_remove_group (GKeyFile *key_file,
310 const gchar *group_name,
311 GError **error);
312
313/* Defines for handling freedesktop.org Desktop files */
314#define G_KEY_FILE_DESKTOP_GROUP "Desktop Entry"
315
316#define G_KEY_FILE_DESKTOP_KEY_TYPE "Type"
317#define G_KEY_FILE_DESKTOP_KEY_VERSION "Version"
318#define G_KEY_FILE_DESKTOP_KEY_NAME "Name"
319#define G_KEY_FILE_DESKTOP_KEY_GENERIC_NAME "GenericName"
320#define G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY "NoDisplay"
321#define G_KEY_FILE_DESKTOP_KEY_COMMENT "Comment"
322#define G_KEY_FILE_DESKTOP_KEY_ICON "Icon"
323#define G_KEY_FILE_DESKTOP_KEY_HIDDEN "Hidden"
324#define G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN "OnlyShowIn"
325#define G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN "NotShowIn"
326#define G_KEY_FILE_DESKTOP_KEY_TRY_EXEC "TryExec"
327#define G_KEY_FILE_DESKTOP_KEY_EXEC "Exec"
328#define G_KEY_FILE_DESKTOP_KEY_PATH "Path"
329#define G_KEY_FILE_DESKTOP_KEY_TERMINAL "Terminal"
330#define G_KEY_FILE_DESKTOP_KEY_MIME_TYPE "MimeType"
331#define G_KEY_FILE_DESKTOP_KEY_CATEGORIES "Categories"
332#define G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY "StartupNotify"
333#define G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS "StartupWMClass"
334#define G_KEY_FILE_DESKTOP_KEY_URL "URL"
335#define G_KEY_FILE_DESKTOP_KEY_DBUS_ACTIVATABLE "DBusActivatable"
336#define G_KEY_FILE_DESKTOP_KEY_ACTIONS "Actions"
337
338#define G_KEY_FILE_DESKTOP_TYPE_APPLICATION "Application"
339#define G_KEY_FILE_DESKTOP_TYPE_LINK "Link"
340#define G_KEY_FILE_DESKTOP_TYPE_DIRECTORY "Directory"
341
342G_END_DECLS
343
344#endif /* __G_KEY_FILE_H__ */
345