Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Reads a .desktop file and returns the app name, the command to launch and the icon name.
- // Returns 0 if it didn't work.
- // Free the strings after usage.
- static int
- _parse_desktop_file(const char *desktop_file_path, char **app_name, char **app_command, char **app_icon_name)
- {
- EINA_RW_SLICE_DECLARE(slice, 1024);
- Efl_Io_File *desktop_file;
- int ret = 0;
- desktop_file = efl_new(EFL_IO_FILE_CLASS,
- efl_file_set(efl_added, desktop_file_path),
- efl_io_closer_close_on_invalidate_set(efl_added, EINA_TRUE));
- if (!desktop_file)
- return 0;
- char *name = NULL, *command = NULL, *icon = NULL, *tmp = NULL, *nodisplay = NULL;
- while (!efl_io_reader_eos_get(desktop_file) &&
- efl_io_reader_read(desktop_file, &slice) == EINA_ERROR_NO_ERROR)
- {
- char *content = eina_rw_slice_strdup(slice);
- char *ptr = content;
- while ((ptr = strchr(ptr, '\n')))
- {
- ptr++;
- _parse_token(ptr, "Name=", &name);
- _parse_token(ptr, "Exec=", &command);
- _parse_token(ptr, "Icon=", &icon);
- _parse_token(ptr, "OnlyShowIn=", &tmp);
- _parse_token(ptr, "NoDisplay", &nodisplay);
- }
- free(content);
- }
- if (name && command && icon && !tmp && (!nodisplay || eina_streq(nodisplay, "false")))
- {
- *app_name = name;
- *app_command = command;
- *app_icon_name = icon;
- ret = 1;
- }
- else
- {
- if (name)
- free(name);
- if (command)
- free(command);
- if (icon)
- free(icon);
- }
- efl_unref(desktop_file);
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement