File: sfdo-desktop.h

package info (click to toggle)
libsfdo 0.1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 740 kB
  • sloc: ansic: 6,491; python: 111; makefile: 4
file content (311 lines) | stat: -rw-r--r-- 11,249 bytes parent folder | download
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#ifndef SFDO_DESKTOP_H
#define SFDO_DESKTOP_H

#ifdef __cplusplus
extern "C" {
#endif

#include <sfdo-common.h>
#include <stdbool.h>

// libsfdo-desktop implements the desktop entry specification, version 1.5:
//
//  https://specifications.freedesktop.org/desktop-entry-spec/1.5/

struct sfdo_basedir_ctx;

enum sfdo_desktop_entry_type {
	SFDO_DESKTOP_ENTRY_APPLICATION,
	SFDO_DESKTOP_ENTRY_LINK,
	SFDO_DESKTOP_ENTRY_DIRECTORY,
};

enum sfdo_desktop_entry_startup_notify {
	// The application does not work with startup notification at all.
	SFDO_DESKTOP_ENTRY_STARTUP_NOTIFY_FALSE,

	// The application will send a "remove" message when started with the DESKTOP_STARTUP_ID
	// environment variable set.
	SFDO_DESKTOP_ENTRY_STARTUP_NOTIFY_TRUE,

	// The startup notification support status is unknown.
	SFDO_DESKTOP_ENTRY_STARTUP_NOTIFY_UNKNOWN,
};

struct sfdo_desktop_exec;

struct sfdo_desktop_exec_command;

struct sfdo_desktop_ctx;

struct sfdo_desktop_db;

struct sfdo_desktop_entry;

struct sfdo_desktop_entry_action;

// Create a context.
//
// basedir_ctx is used to create the default list of paths which are scanned for desktop entry
// files. Once the context is created, basedir_ctx is not referenced anymore and can be destroyed.
//
// basedir_ctx may be NULL, in which case the default list is empty.
//
// Returns NULL on memory allocation error.
struct sfdo_desktop_ctx *sfdo_desktop_ctx_create(struct sfdo_basedir_ctx *basedir_ctx);

// Destroy a context.
//
// ctx may be NULL, in which case the function is no-op.
void sfdo_desktop_ctx_destroy(struct sfdo_desktop_ctx *ctx);

// Set the context log handler.
//
// func will be called for each message with a level lower than or equal to level. func may be NULL.
void sfdo_desktop_ctx_set_log_handler(struct sfdo_desktop_ctx *ctx, enum sfdo_log_level level,
		sfdo_log_handler_func_t func, void *data);

// Load a desktop entry database from the default list of paths.
//
// locale is a string of form lang_COUNTRY.ENCODING@MODIFIER, where _COUNTRY, .ENCODING, and
// @MODIFIER may be omitted. It is used to select the best values for localized strings. May be
// NULL.
//
// Returns NULL on memory allocation error.
struct sfdo_desktop_db *sfdo_desktop_db_load(struct sfdo_desktop_ctx *ctx, const char *locale);

// Load a desktop entry database.
//
// locale is a string of form lang_COUNTRY.ENCODING@MODIFIER, where _COUNTRY, .ENCODING, and
// @MODIFIER may be omitted. It is used to select the best values for localized strings. May be
// NULL.
//
// Returns NULL on memory allocation error.
struct sfdo_desktop_db *sfdo_desktop_db_load_from(struct sfdo_desktop_ctx *ctx, const char *locale,
		const struct sfdo_string *basedirs, size_t n_basedirs);

// Destroy a desktop entry database.
//
// db may be NULL, in which case the function is no-op.
void sfdo_desktop_db_destroy(struct sfdo_desktop_db *db);

// Get a desktop entry by an ID.
//
// If id_len is equal to SFDO_NT, id is assumed to be null-terminated.
//
// Returns NULL if there is no matching desktop entry.
struct sfdo_desktop_entry *sfdo_desktop_db_get_entry_by_id(
		struct sfdo_desktop_db *db, const char *id, size_t id_len);

// Get the list of desktop entries in a database.
//
// The number of entries is saved to n_entries.
struct sfdo_desktop_entry **sfdo_desktop_db_get_entries(
		struct sfdo_desktop_db *db, size_t *n_entries);

// Get the desktop entry type.
enum sfdo_desktop_entry_type sfdo_desktop_entry_get_type(struct sfdo_desktop_entry *entry);

// Get the desktop entry ID.
//
// The length of the ID is saved to len. len may be NULL.
const char *sfdo_desktop_entry_get_id(struct sfdo_desktop_entry *entry, size_t *len);

// Get the desktop entry file path.
//
// The length of the path is saved to len. len may be NULL.
const char *sfdo_desktop_entry_get_file_path(struct sfdo_desktop_entry *entry, size_t *len);

// Get the desktop entry name.
//
// The length of the name is saved to len. len may be NULL.
const char *sfdo_desktop_entry_get_name(struct sfdo_desktop_entry *entry, size_t *len);

// Get the generic desktop entry name.
//
// The length of the name is saved to len. len may be NULL.
//
// Returns NULL if the corresponding key is absent.
const char *sfdo_desktop_entry_get_generic_name(struct sfdo_desktop_entry *entry, size_t *len);

// Get whether the desktop entry should *not* be displayed to the user.
bool sfdo_desktop_entry_get_no_display(struct sfdo_desktop_entry *entry);

// Get the desktop entry tooltip.
//
// The length of the tooltip is saved to len. len may be NULL.
//
// Returns NULL if the corresponding key is absent.
const char *sfdo_desktop_entry_get_comment(struct sfdo_desktop_entry *entry, size_t *len);

// Get the name of or the absolute path to the desktop entry icon.
//
// The length of the returned string is saved to len. len may be NULL.
//
// Returns NULL if the corresponding key is absent.
const char *sfdo_desktop_entry_get_icon(struct sfdo_desktop_entry *entry, size_t *len);

// Get whether the desktop entry should be shown in the given desktop environment.
//
// env is the desktop environment name. env may be NULL, in which case the default value is
// returned.
//
// If env_len is equal to SFDO_NT and env is not NULL, env is assumed to be null-terminated.
bool sfdo_desktop_entry_show_in(struct sfdo_desktop_entry *entry, const char *env, size_t env_len);

// Get whether D-Bus activation is supported for the application.
//
// The desktop entry type must be "Application".
bool sfdo_desktop_entry_get_dbus_activatable(struct sfdo_desktop_entry *entry);

// Get the path to an executable file used to determine if the program is installed.
//
// The desktop entry type must be "Application".
//
// Returns NULL if the corresponding key is absent.
const char *sfdo_desktop_entry_get_try_exec(struct sfdo_desktop_entry *entry, size_t *len);

// Get the application's command template.
//
// The desktop entry type must be "Application".
//
// Returns NULL if the corresponding key is absent.
struct sfdo_desktop_exec *sfdo_desktop_entry_get_exec(struct sfdo_desktop_entry *entry);

// Get the working directory to run the application in.
//
// The desktop entry type must be "Application".
//
// Returns NULL if the corresponding key is absent.
const char *sfdo_desktop_entry_get_path(struct sfdo_desktop_entry *entry, size_t *len);

// Get whether the application runs in a terminal window.
//
// The desktop entry type must be "Application".
bool sfdo_desktop_entry_get_terminal(struct sfdo_desktop_entry *entry);

// Get the list of application actions.
//
// The desktop entry type must be "Application".
struct sfdo_desktop_entry_action **sfdo_desktop_entry_get_actions(
		struct sfdo_desktop_entry *entry, size_t *n_actions);

// Get the list of MIME types supported by the application.
//
// The desktop entry type must be "Application".
const struct sfdo_string *sfdo_desktop_entry_get_mimetypes(
		struct sfdo_desktop_entry *entry, size_t *n_mimetypes);

// Get the list of categories in which the entry should be shown.
//
// The desktop entry type must be "Application".
const struct sfdo_string *sfdo_desktop_entry_get_categories(
		struct sfdo_desktop_entry *entry, size_t *n_categories);

// Get the list of interfaces the application implements.
//
// The desktop entry type must be "Application".
const struct sfdo_string *sfdo_desktop_entry_get_implements(
		struct sfdo_desktop_entry *entry, size_t *n_implements);

// Get the list of strings which may be used in addition to other metadata to describe the
// application.
//
// The desktop entry type must be "Application".
const struct sfdo_string *sfdo_desktop_entry_get_keywords(
		struct sfdo_desktop_entry *entry, size_t *n_keywords);

// Get the startup notification support status.
//
// The desktop entry type must be "Application".
enum sfdo_desktop_entry_startup_notify sfdo_desktop_entry_get_startup_notify(
		struct sfdo_desktop_entry *entry);

// Get the WM class or WM name hint that the application will map at least one window with.
//
// The desktop entry type must be "Application".
//
// Returns NULL if the corresponding key is absent.
const char *sfdo_desktop_entry_get_startup_wm_class(struct sfdo_desktop_entry *entry, size_t *len);

// Get the URL to access.
//
// The desktop entry type must be "Link".
const char *sfdo_desktop_entry_get_url(struct sfdo_desktop_entry *entry, size_t *len);

// Get whether the application prefers to be run on a more powerful discrete GPU if available.
//
// The desktop entry type must be "Application".
bool sfdo_desktop_entry_get_prefers_non_default_gpu(struct sfdo_desktop_entry *entry);

// Get whether the application has a single main window and does not support having an additional
// one opened.
//
// The desktop entry type must be "Application".
bool sfdo_desktop_entry_get_single_main_window(struct sfdo_desktop_entry *entry);

// Get the action ID.
//
// The length of the ID is saved to len. len may be NULL.
const char *sfdo_desktop_entry_action_get_id(struct sfdo_desktop_entry_action *action, size_t *len);

// Get the action name.
//
// The length of the name is saved to len. len may be NULL.
const char *sfdo_desktop_entry_action_get_name(
		struct sfdo_desktop_entry_action *action, size_t *len);

// Get the name of or the absolute path to the action icon.
//
// The length of the returned string is saved to len. len may be NULL.
//
// Returns NULL if the corresponding key is absent.
const char *sfdo_desktop_entry_action_get_icon(
		struct sfdo_desktop_entry_action *action, size_t *len);

// Get the action's command template.
//
// Returns NULL if the corresponding key is absent.
struct sfdo_desktop_exec *sfdo_desktop_entry_action_get_exec(
		struct sfdo_desktop_entry_action *action);

// Get whether the command template has a target.
bool sfdo_desktop_exec_get_has_target(struct sfdo_desktop_exec *exec);

// Get whether the command template supports using a list of paths as a target.
bool sfdo_desktop_exec_get_supports_list(struct sfdo_desktop_exec *exec);

// Get whether the command template supports using URI(s) as a target.
bool sfdo_desktop_exec_get_supports_uri(struct sfdo_desktop_exec *exec);

// Format a command template with a given path.
//
// Returns NULL on memory allocation error.
struct sfdo_desktop_exec_command *sfdo_desktop_exec_format(
		struct sfdo_desktop_exec *exec, const char *path);

// Format a command template with a given list of paths.
//
// If the command template doesn't support using a list of paths as a target, only the first path
// will be used.
//
// Returns NULL on memory allocation error.
struct sfdo_desktop_exec_command *sfdo_desktop_exec_format_list(
		struct sfdo_desktop_exec *exec, const char **paths, size_t n_paths);

// Get the NULL-terminated list of arguments of the formatted command.
//
// The number of arguments excluding the NULL terminator is saved to n_args. n_args may be NULL.
const char **sfdo_desktop_exec_command_get_args(
		struct sfdo_desktop_exec_command *command, size_t *n_args);

// Destroy a formatted command.
//
// command may be NULL, in which case the function is no-op.
void sfdo_desktop_exec_command_destroy(struct sfdo_desktop_exec_command *command);

#ifdef __cplusplus
}
#endif

#endif