Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1.  
  2. // Reads a .desktop file and returns the app name, the command to launch and the icon name.
  3. // Returns 0 if it didn't work.
  4. // Free the strings after usage.
  5. static int
  6. _parse_desktop_file(const char *desktop_file_path, char **app_name, char **app_command, char **app_icon_name)
  7. {
  8. EINA_RW_SLICE_DECLARE(slice, 1024);
  9. Efl_Io_File *desktop_file;
  10. int ret = 0;
  11.  
  12. desktop_file = efl_new(EFL_IO_FILE_CLASS,
  13. efl_file_set(efl_added, desktop_file_path),
  14. efl_io_closer_close_on_invalidate_set(efl_added, EINA_TRUE));
  15.  
  16. if (!desktop_file)
  17. return 0;
  18.  
  19. char *name = NULL, *command = NULL, *icon = NULL, *tmp = NULL, *nodisplay = NULL;
  20. while (!efl_io_reader_eos_get(desktop_file) &&
  21. efl_io_reader_read(desktop_file, &slice) == EINA_ERROR_NO_ERROR)
  22. {
  23. char *content = eina_rw_slice_strdup(slice);
  24. char *ptr = content;
  25. while ((ptr = strchr(ptr, '\n')))
  26. {
  27. ptr++;
  28. _parse_token(ptr, "Name=", &name);
  29. _parse_token(ptr, "Exec=", &command);
  30. _parse_token(ptr, "Icon=", &icon);
  31. _parse_token(ptr, "OnlyShowIn=", &tmp);
  32. _parse_token(ptr, "NoDisplay", &nodisplay);
  33. }
  34. free(content);
  35. }
  36. if (name && command && icon && !tmp && (!nodisplay || eina_streq(nodisplay, "false")))
  37. {
  38. *app_name = name;
  39. *app_command = command;
  40. *app_icon_name = icon;
  41. ret = 1;
  42. }
  43. else
  44. {
  45. if (name)
  46. free(name);
  47. if (command)
  48. free(command);
  49. if (icon)
  50. free(icon);
  51. }
  52.  
  53. efl_unref(desktop_file);
  54.  
  55. return ret;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement