dialogs_api.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "dialogs/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. }};
  25. DialogsAppReturn return_data;
  26. DialogsAppMessage message = {
  27. .lock = lock,
  28. .command = DialogsAppCommandFileBrowser,
  29. .data = &data,
  30. .return_data = &return_data,
  31. };
  32. furi_check(
  33. furi_message_queue_put(context->message_queue, &message, FuriWaitForever) == FuriStatusOk);
  34. api_lock_wait_unlock_and_free(lock);
  35. return return_data.bool_value;
  36. }
  37. /****************** Message ******************/
  38. DialogMessageButton dialog_message_show(DialogsApp* context, const DialogMessage* dialog_message) {
  39. FuriApiLock lock = api_lock_alloc_locked();
  40. furi_check(lock != NULL);
  41. DialogsAppData data = {
  42. .dialog = {
  43. .message = dialog_message,
  44. }};
  45. DialogsAppReturn return_data;
  46. DialogsAppMessage message = {
  47. .lock = lock,
  48. .command = DialogsAppCommandDialog,
  49. .data = &data,
  50. .return_data = &return_data,
  51. };
  52. furi_check(
  53. furi_message_queue_put(context->message_queue, &message, FuriWaitForever) == FuriStatusOk);
  54. api_lock_wait_unlock_and_free(lock);
  55. return return_data.dialog_value;
  56. }
  57. /****************** Storage error ******************/
  58. void dialog_message_show_storage_error(DialogsApp* context, const char* error_text) {
  59. DialogMessage* message = dialog_message_alloc();
  60. dialog_message_set_text(message, error_text, 88, 32, AlignCenter, AlignCenter);
  61. dialog_message_set_icon(message, &I_SDQuestion_35x43, 5, 6);
  62. dialog_message_set_buttons(message, "Back", NULL, NULL);
  63. dialog_message_show(context, message);
  64. dialog_message_free(message);
  65. }