flipperzero-firmware/applications/dialogs/dialogs-module-message.c
SG ad421a81bc
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.

Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 15:20:19 +03:00

152 lines
4.6 KiB
C

#include "dialogs-i.h"
#include "dialogs-api-lock.h"
#include <gui/modules/dialog_ex.h>
typedef struct {
osSemaphoreId_t semaphore;
DialogMessageButton result;
} DialogsAppMessageContext;
struct DialogMessage {
const char* header_text;
uint8_t header_text_x;
uint8_t header_text_y;
Align header_horizontal;
Align header_vertical;
const char* dialog_text;
uint8_t dialog_text_x;
uint8_t dialog_text_y;
Align dialog_text_horizontal;
Align dialog_text_vertical;
const Icon* icon;
uint8_t icon_x;
uint8_t icon_y;
const char* left_button_text;
const char* center_button_text;
const char* right_button_text;
};
static void dialogs_app_message_back_callback(void* context) {
furi_assert(context);
DialogsAppMessageContext* message_context = context;
message_context->result = DialogMessageButtonBack;
API_LOCK_UNLOCK(message_context->semaphore);
}
static void dialogs_app_message_callback(DialogExResult result, void* context) {
furi_assert(context);
DialogsAppMessageContext* message_context = context;
switch(result) {
case DialogExResultLeft:
message_context->result = DialogMessageButtonLeft;
break;
case DialogExResultRight:
message_context->result = DialogMessageButtonRight;
break;
case DialogExResultCenter:
message_context->result = DialogMessageButtonCenter;
break;
}
API_LOCK_UNLOCK(message_context->semaphore);
}
DialogMessageButton dialogs_app_process_module_message(const DialogsAppMessageDataDialog* data) {
DialogMessageButton ret = DialogMessageButtonBack;
Gui* gui = furi_record_open("gui");
const DialogMessage* message = data->message;
DialogsAppMessageContext* message_context = furi_alloc(sizeof(DialogsAppMessageContext));
message_context->semaphore = API_LOCK_INIT_LOCKED();
ViewHolder* view_holder = view_holder_alloc();
view_holder_attach_to_gui(view_holder, gui);
view_holder_set_back_callback(view_holder, dialogs_app_message_back_callback, message_context);
DialogEx* dialog_ex = dialog_ex_alloc();
dialog_ex_set_result_callback(dialog_ex, dialogs_app_message_callback);
dialog_ex_set_context(dialog_ex, message_context);
dialog_ex_set_header(
dialog_ex,
message->header_text,
message->header_text_x,
message->header_text_y,
message->header_horizontal,
message->header_vertical);
dialog_ex_set_text(
dialog_ex,
message->dialog_text,
message->dialog_text_x,
message->dialog_text_y,
message->dialog_text_horizontal,
message->dialog_text_vertical);
dialog_ex_set_icon(dialog_ex, message->icon_x, message->icon_y, message->icon);
dialog_ex_set_left_button_text(dialog_ex, message->left_button_text);
dialog_ex_set_center_button_text(dialog_ex, message->center_button_text);
dialog_ex_set_right_button_text(dialog_ex, message->right_button_text);
view_holder_set_view(view_holder, dialog_ex_get_view(dialog_ex));
view_holder_start(view_holder);
API_LOCK_WAIT_UNTIL_UNLOCK_AND_FREE(message_context->semaphore);
ret = message_context->result;
free(message_context);
view_holder_stop(view_holder);
view_holder_free(view_holder);
dialog_ex_free(dialog_ex);
furi_record_close("gui");
return ret;
}
DialogMessage* dialog_message_alloc() {
DialogMessage* message = furi_alloc(sizeof(DialogMessage));
return message;
}
void dialog_message_free(DialogMessage* message) {
free(message);
}
void dialog_message_set_text(
DialogMessage* message,
const char* text,
uint8_t x,
uint8_t y,
Align horizontal,
Align vertical) {
message->dialog_text = text;
message->dialog_text_x = x;
message->dialog_text_y = y;
message->dialog_text_horizontal = horizontal;
message->dialog_text_vertical = vertical;
}
void dialog_message_set_header(
DialogMessage* message,
const char* text,
uint8_t x,
uint8_t y,
Align horizontal,
Align vertical) {
message->header_text = text;
message->header_text_x = x;
message->header_text_y = y;
message->header_horizontal = horizontal;
message->header_vertical = vertical;
}
void dialog_message_set_icon(DialogMessage* message, const Icon* icon, uint8_t x, uint8_t y) {
message->icon = icon;
message->icon_x = x;
message->icon_y = y;
}
void dialog_message_set_buttons(
DialogMessage* message,
const char* left,
const char* center,
const char* right) {
message->left_button_text = left;
message->center_button_text = center;
message->right_button_text = right;
}