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} 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);
81GLIB_AVAILABLE_IN_2_50
82gboolean g_key_file_load_from_bytes (GKeyFile *key_file,
83 GBytes *bytes,
84 GKeyFileFlags flags,
85 GError **error);
86GLIB_AVAILABLE_IN_ALL
87gboolean g_key_file_load_from_dirs (GKeyFile *key_file,
88 const gchar *file,
89 const gchar **search_dirs,
90 gchar **full_path,
91 GKeyFileFlags flags,
92 GError **error);
93GLIB_AVAILABLE_IN_ALL
94gboolean g_key_file_load_from_data_dirs (GKeyFile *key_file,
95 const gchar *file,
96 gchar **full_path,
97 GKeyFileFlags flags,
98 GError **error);
99GLIB_AVAILABLE_IN_ALL
100gchar *g_key_file_to_data (GKeyFile *key_file,
101 gsize *length,
102 GError **error) G_GNUC_MALLOC;
103GLIB_AVAILABLE_IN_2_40
104gboolean g_key_file_save_to_file (GKeyFile *key_file,
105 const gchar *filename,
106 GError **error);
107GLIB_AVAILABLE_IN_ALL
108gchar *g_key_file_get_start_group (GKeyFile *key_file) G_GNUC_MALLOC;
109GLIB_AVAILABLE_IN_ALL
110gchar **g_key_file_get_groups (GKeyFile *key_file,
111 gsize *length);
112GLIB_AVAILABLE_IN_ALL
113gchar **g_key_file_get_keys (GKeyFile *key_file,
114 const gchar *group_name,
115 gsize *length,
116 GError **error);
117GLIB_AVAILABLE_IN_ALL
118gboolean g_key_file_has_group (GKeyFile *key_file,
119 const gchar *group_name);
120GLIB_AVAILABLE_IN_ALL
121gboolean g_key_file_has_key (GKeyFile *key_file,
122 const gchar *group_name,
123 const gchar *key,
124 GError **error);
125GLIB_AVAILABLE_IN_ALL
126gchar *g_key_file_get_value (GKeyFile *key_file,
127 const gchar *group_name,
128 const gchar *key,
129 GError **error) G_GNUC_MALLOC;
130GLIB_AVAILABLE_IN_ALL
131void g_key_file_set_value (GKeyFile *key_file,
132 const gchar *group_name,
133 const gchar *key,
134 const gchar *value);
135GLIB_AVAILABLE_IN_ALL
136gchar *g_key_file_get_string (GKeyFile *key_file,
137 const gchar *group_name,
138 const gchar *key,
139 GError **error) G_GNUC_MALLOC;
140GLIB_AVAILABLE_IN_ALL
141void g_key_file_set_string (GKeyFile *key_file,
142 const gchar *group_name,
143 const gchar *key,
144 const gchar *string);
145GLIB_AVAILABLE_IN_ALL
146gchar *g_key_file_get_locale_string (GKeyFile *key_file,
147 const gchar *group_name,
148 const gchar *key,
149 const gchar *locale,
150 GError **error) G_GNUC_MALLOC;
151GLIB_AVAILABLE_IN_2_56
152gchar *g_key_file_get_locale_for_key (GKeyFile *key_file,
153 const gchar *group_name,
154 const gchar *key,
155 const gchar *locale) G_GNUC_MALLOC;
156GLIB_AVAILABLE_IN_ALL
157void g_key_file_set_locale_string (GKeyFile *key_file,
158 const gchar *group_name,
159 const gchar *key,
160 const gchar *locale,
161 const gchar *string);
162GLIB_AVAILABLE_IN_ALL
163gboolean g_key_file_get_boolean (GKeyFile *key_file,
164 const gchar *group_name,
165 const gchar *key,
166 GError **error);
167GLIB_AVAILABLE_IN_ALL
168void g_key_file_set_boolean (GKeyFile *key_file,
169 const gchar *group_name,
170 const gchar *key,
171 gboolean value);
172GLIB_AVAILABLE_IN_ALL
173gint g_key_file_get_integer (GKeyFile *key_file,
174 const gchar *group_name,
175 const gchar *key,
176 GError **error);
177GLIB_AVAILABLE_IN_ALL
178void g_key_file_set_integer (GKeyFile *key_file,
179 const gchar *group_name,
180 const gchar *key,
181 gint value);
182GLIB_AVAILABLE_IN_ALL
183gint64 g_key_file_get_int64 (GKeyFile *key_file,
184 const gchar *group_name,
185 const gchar *key,
186 GError **error);
187GLIB_AVAILABLE_IN_ALL
188void g_key_file_set_int64 (GKeyFile *key_file,
189 const gchar *group_name,
190 const gchar *key,
191 gint64 value);
192GLIB_AVAILABLE_IN_ALL
193guint64 g_key_file_get_uint64 (GKeyFile *key_file,
194 const gchar *group_name,
195 const gchar *key,
196 GError **error);
197GLIB_AVAILABLE_IN_ALL
198void g_key_file_set_uint64 (GKeyFile *key_file,
199 const gchar *group_name,
200 const gchar *key,
201 guint64 value);
202GLIB_AVAILABLE_IN_ALL
203gdouble g_key_file_get_double (GKeyFile *key_file,
204 const gchar *group_name,
205 const gchar *key,
206 GError **error);
207GLIB_AVAILABLE_IN_ALL
208void g_key_file_set_double (GKeyFile *key_file,
209 const gchar *group_name,
210 const gchar *key,
211 gdouble value);
212GLIB_AVAILABLE_IN_ALL
213gchar **g_key_file_get_string_list (GKeyFile *key_file,
214 const gchar *group_name,
215 const gchar *key,
216 gsize *length,
217 GError **error);
218GLIB_AVAILABLE_IN_ALL
219void g_key_file_set_string_list (GKeyFile *key_file,
220 const gchar *group_name,
221 const gchar *key,
222 const gchar * const list[],
223 gsize length);
224GLIB_AVAILABLE_IN_ALL
225gchar **g_key_file_get_locale_string_list (GKeyFile *key_file,
226 const gchar *group_name,
227 const gchar *key,
228 const gchar *locale,
229 gsize *length,
230 GError **error);
231GLIB_AVAILABLE_IN_ALL
232void g_key_file_set_locale_string_list (GKeyFile *key_file,
233 const gchar *group_name,
234 const gchar *key,
235 const gchar *locale,
236 const gchar * const list[],
237 gsize length);
238GLIB_AVAILABLE_IN_ALL
239gboolean *g_key_file_get_boolean_list (GKeyFile *key_file,
240 const gchar *group_name,
241 const gchar *key,
242 gsize *length,
243 GError **error) G_GNUC_MALLOC;
244GLIB_AVAILABLE_IN_ALL
245void g_key_file_set_boolean_list (GKeyFile *key_file,
246 const gchar *group_name,
247 const gchar *key,
248 gboolean list[],
249 gsize length);
250GLIB_AVAILABLE_IN_ALL
251gint *g_key_file_get_integer_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_double_list (GKeyFile *key_file,
258 const gchar *group_name,
259 const gchar *key,
260 gdouble list[],
261 gsize length);
262GLIB_AVAILABLE_IN_ALL
263gdouble *g_key_file_get_double_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_integer_list (GKeyFile *key_file,
270 const gchar *group_name,
271 const gchar *key,
272 gint list[],
273 gsize length);
274GLIB_AVAILABLE_IN_ALL
275gboolean g_key_file_set_comment (GKeyFile *key_file,
276 const gchar *group_name,
277 const gchar *key,
278 const gchar *comment,
279 GError **error);
280GLIB_AVAILABLE_IN_ALL
281gchar *g_key_file_get_comment (GKeyFile *key_file,
282 const gchar *group_name,
283 const gchar *key,
284 GError **error) G_GNUC_MALLOC;
285
286GLIB_AVAILABLE_IN_ALL
287gboolean g_key_file_remove_comment (GKeyFile *key_file,
288 const gchar *group_name,
289 const gchar *key,
290 GError **error);
291GLIB_AVAILABLE_IN_ALL
292gboolean g_key_file_remove_key (GKeyFile *key_file,
293 const gchar *group_name,
294 const gchar *key,
295 GError **error);
296GLIB_AVAILABLE_IN_ALL
297gboolean g_key_file_remove_group (GKeyFile *key_file,
298 const gchar *group_name,
299 GError **error);
300
301/* Defines for handling freedesktop.org Desktop files */
302#define G_KEY_FILE_DESKTOP_GROUP "Desktop Entry"
303
304#define G_KEY_FILE_DESKTOP_KEY_TYPE "Type"
305#define G_KEY_FILE_DESKTOP_KEY_VERSION "Version"
306#define G_KEY_FILE_DESKTOP_KEY_NAME "Name"
307#define G_KEY_FILE_DESKTOP_KEY_GENERIC_NAME "GenericName"
308#define G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY "NoDisplay"
309#define G_KEY_FILE_DESKTOP_KEY_COMMENT "Comment"
310#define G_KEY_FILE_DESKTOP_KEY_ICON "Icon"
311#define G_KEY_FILE_DESKTOP_KEY_HIDDEN "Hidden"
312#define G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN "OnlyShowIn"
313#define G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN "NotShowIn"
314#define G_KEY_FILE_DESKTOP_KEY_TRY_EXEC "TryExec"
315#define G_KEY_FILE_DESKTOP_KEY_EXEC "Exec"
316#define G_KEY_FILE_DESKTOP_KEY_PATH "Path"
317#define G_KEY_FILE_DESKTOP_KEY_TERMINAL "Terminal"
318#define G_KEY_FILE_DESKTOP_KEY_MIME_TYPE "MimeType"
319#define G_KEY_FILE_DESKTOP_KEY_CATEGORIES "Categories"
320#define G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY "StartupNotify"
321#define G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS "StartupWMClass"
322#define G_KEY_FILE_DESKTOP_KEY_URL "URL"
323#define G_KEY_FILE_DESKTOP_KEY_DBUS_ACTIVATABLE "DBusActivatable"
324#define G_KEY_FILE_DESKTOP_KEY_ACTIONS "Actions"
325
326#define G_KEY_FILE_DESKTOP_TYPE_APPLICATION "Application"
327#define G_KEY_FILE_DESKTOP_TYPE_LINK "Link"
328#define G_KEY_FILE_DESKTOP_TYPE_DIRECTORY "Directory"
329
330G_END_DECLS
331
332#endif /* __G_KEY_FILE_H__ */
333