item.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #pragma once
  2. #include <m-array.h>
  3. // Max length of a filename, final path element only
  4. #define MAX_NAME_LEN (size_t)64
  5. #define MAX_EXT_LEN (size_t)6
  6. /** Defines an individual item action or item group. Each object contains
  7. * the relevant file and type information needed to both render correctly
  8. * on-screen as well as to perform that action.
  9. */
  10. typedef enum {
  11. Item_SubGhz,
  12. Item_RFID,
  13. Item_IR,
  14. Item_NFC,
  15. Item_iButton,
  16. Item_Playlist,
  17. Item_Group,
  18. Item_Settings,
  19. Item_Unknown,
  20. Item_count
  21. } ItemType;
  22. typedef struct Item {
  23. ItemType type;
  24. FuriString* name;
  25. FuriString* path;
  26. char ext[MAX_EXT_LEN];
  27. bool is_link;
  28. } Item;
  29. ARRAY_DEF(ItemArray, Item, M_POD_OPLIST);
  30. typedef struct ItemsView {
  31. FuriString* name;
  32. FuriString* path;
  33. ItemArray_t items;
  34. } ItemsView;
  35. /** Allocates and returns an ItemsView* which contains the list of
  36. * items to display for the given path. Contains everything needed
  37. * to render a scene_items.
  38. *
  39. * @param context App*
  40. * @param path FuriString*
  41. * @return ItemsView*
  42. */
  43. ItemsView* item_get_items_view_from_path(void* context, const FuriString* path);
  44. /** Free ItemsView
  45. * @param items_view
  46. */
  47. void item_items_view_free(ItemsView* items_view);
  48. /** Prettify the name by removing a leading XX_, only if both X are digits,
  49. * as well as replace all '_' with ' '.
  50. * @param name FuriString*
  51. */
  52. void item_prettify_name(FuriString* name);
  53. /** Return the ItemType enum for the given extension
  54. * @param ext File extension
  55. */
  56. ItemType item_get_item_type_from_extension(const char* ext);
  57. /** Extract filename and extension from path. Check if path is a link file
  58. */
  59. void item_path_extract_filename(
  60. FuriString* path,
  61. FuriString* name,
  62. char (*ext)[MAX_EXT_LEN],
  63. bool* is_link);