dialogs_api.c 2.6 KB

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