dialogs_api.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "dialogs/dialogs_message.h"
  2. #include "dialogs_i.h"
  3. #include "dialogs_api_lock.h"
  4. /****************** File browser ******************/
  5. bool dialog_file_browser_show(
  6. DialogsApp* context,
  7. FuriString* result_path,
  8. FuriString* path,
  9. const DialogsFileBrowserOptions* options) {
  10. FuriApiLock lock = API_LOCK_INIT_LOCKED();
  11. furi_check(lock != NULL);
  12. DialogsAppData data = {
  13. .file_browser = {
  14. .extension = options ? options->extension : "",
  15. .result_path = result_path,
  16. .file_icon = options ? options->icon : NULL,
  17. .hide_ext = options ? options->hide_ext : true,
  18. .skip_assets = options ? options->skip_assets : true,
  19. .preselected_filename = path,
  20. .item_callback = options ? options->item_loader_callback : NULL,
  21. .item_callback_context = options ? options->item_loader_context : NULL,
  22. }};
  23. DialogsAppReturn return_data;
  24. DialogsAppMessage message = {
  25. .lock = lock,
  26. .command = DialogsAppCommandFileBrowser,
  27. .data = &data,
  28. .return_data = &return_data,
  29. };
  30. furi_check(
  31. furi_message_queue_put(context->message_queue, &message, FuriWaitForever) == FuriStatusOk);
  32. API_LOCK_WAIT_UNTIL_UNLOCK_AND_FREE(lock);
  33. return return_data.bool_value;
  34. }
  35. /****************** Message ******************/
  36. DialogMessageButton dialog_message_show(DialogsApp* context, const DialogMessage* dialog_message) {
  37. FuriApiLock lock = API_LOCK_INIT_LOCKED();
  38. furi_check(lock != NULL);
  39. DialogsAppData data = {
  40. .dialog = {
  41. .message = dialog_message,
  42. }};
  43. DialogsAppReturn return_data;
  44. DialogsAppMessage message = {
  45. .lock = lock,
  46. .command = DialogsAppCommandDialog,
  47. .data = &data,
  48. .return_data = &return_data,
  49. };
  50. furi_check(
  51. furi_message_queue_put(context->message_queue, &message, FuriWaitForever) == FuriStatusOk);
  52. API_LOCK_WAIT_UNTIL_UNLOCK_AND_FREE(lock);
  53. return return_data.dialog_value;
  54. }
  55. /****************** Storage error ******************/
  56. void dialog_message_show_storage_error(DialogsApp* context, const char* error_text) {
  57. DialogMessage* message = dialog_message_alloc();
  58. dialog_message_set_text(message, error_text, 88, 32, AlignCenter, AlignCenter);
  59. dialog_message_set_icon(message, &I_SDQuestion_35x43, 5, 6);
  60. dialog_message_set_buttons(message, "Back", NULL, NULL);
  61. dialog_message_show(context, message);
  62. dialog_message_free(message);
  63. }