dialogs_api.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "dialogs_message.h"
  2. #include "dialogs_i.h"
  3. #include <toolbox/api_lock.h>
  4. #include <assets_icons.h>
  5. #include <storage/storage.h>
  6. /****************** File browser ******************/
  7. bool dialog_file_browser_show(
  8. DialogsApp* context,
  9. FuriString* result_path,
  10. FuriString* path,
  11. const DialogsFileBrowserOptions* options) {
  12. FuriApiLock lock = api_lock_alloc_locked();
  13. furi_check(lock != NULL);
  14. Storage* storage = furi_record_open(RECORD_STORAGE);
  15. FuriString* base_path = furi_string_alloc();
  16. if(options && options->base_path) {
  17. furi_string_set(base_path, options->base_path);
  18. storage_common_resolve_path_and_ensure_app_directory(storage, base_path);
  19. }
  20. if(result_path) {
  21. storage_common_resolve_path_and_ensure_app_directory(storage, result_path);
  22. }
  23. if(path) {
  24. storage_common_resolve_path_and_ensure_app_directory(storage, path);
  25. }
  26. DialogsAppData data = {
  27. .file_browser = {
  28. .extension = options ? options->extension : "",
  29. .result_path = result_path,
  30. .file_icon = options ? options->icon : NULL,
  31. .hide_ext = options ? options->hide_ext : true,
  32. .skip_assets = options ? options->skip_assets : true,
  33. .hide_dot_files = options ? options->hide_dot_files : true,
  34. .preselected_filename = path,
  35. .item_callback = options ? options->item_loader_callback : NULL,
  36. .item_callback_context = options ? options->item_loader_context : NULL,
  37. .base_path = furi_string_get_cstr(base_path),
  38. }};
  39. DialogsAppReturn return_data;
  40. DialogsAppMessage message = {
  41. .lock = lock,
  42. .command = DialogsAppCommandFileBrowser,
  43. .data = &data,
  44. .return_data = &return_data,
  45. };
  46. furi_check(
  47. furi_message_queue_put(context->message_queue, &message, FuriWaitForever) == FuriStatusOk);
  48. api_lock_wait_unlock_and_free(lock);
  49. furi_record_close(RECORD_STORAGE);
  50. furi_string_free(base_path);
  51. return return_data.bool_value;
  52. }
  53. /****************** Message ******************/
  54. DialogMessageButton dialog_message_show(DialogsApp* context, const DialogMessage* dialog_message) {
  55. FuriApiLock lock = api_lock_alloc_locked();
  56. furi_check(lock != NULL);
  57. DialogsAppData data = {
  58. .dialog = {
  59. .message = dialog_message,
  60. }};
  61. DialogsAppReturn return_data;
  62. DialogsAppMessage message = {
  63. .lock = lock,
  64. .command = DialogsAppCommandDialog,
  65. .data = &data,
  66. .return_data = &return_data,
  67. };
  68. furi_check(
  69. furi_message_queue_put(context->message_queue, &message, FuriWaitForever) == FuriStatusOk);
  70. api_lock_wait_unlock_and_free(lock);
  71. return return_data.dialog_value;
  72. }
  73. /****************** Storage error ******************/
  74. void dialog_message_show_storage_error(DialogsApp* context, const char* error_text) {
  75. DialogMessage* message = dialog_message_alloc();
  76. dialog_message_set_text(message, error_text, 88, 32, AlignCenter, AlignCenter);
  77. dialog_message_set_icon(message, &I_SDQuestion_35x43, 5, 6);
  78. dialog_message_set_buttons(message, "Back", NULL, NULL);
  79. dialog_message_show(context, message);
  80. dialog_message_free(message);
  81. }