unleashed-firmware/applications/main/archive/scenes/archive_scene_info.c

98 lines
3.2 KiB
C
Raw Normal View History

#include "../archive_i.h"
#include "../helpers/archive_browser.h"
#define TAG "Archive"
void archive_scene_info_widget_callback(GuiButtonType result, InputType type, void* context) {
furi_assert(context);
ArchiveApp* app = (ArchiveApp*)context;
if(type == InputTypeShort) {
view_dispatcher_send_custom_event(app->view_dispatcher, result);
}
}
void archive_scene_info_on_enter(void* context) {
furi_assert(context);
2022-09-15 22:21:10 +00:00
ArchiveApp* instance = context;
widget_add_button_element(
2022-09-15 22:21:10 +00:00
instance->widget, GuiButtonTypeLeft, "Back", archive_scene_info_widget_callback, instance);
2022-10-05 18:27:13 +00:00
FuriString* filename;
FuriString* dirname;
FuriString* str_size;
filename = furi_string_alloc();
dirname = furi_string_alloc();
str_size = furi_string_alloc();
2022-09-15 22:21:10 +00:00
ArchiveFile_t* current = archive_get_current_file(instance->browser);
char file_info_message[128];
Storage* fs_api = furi_record_open(RECORD_STORAGE);
// Filename
path_extract_filename(current->path, filename, false);
2022-10-05 18:27:13 +00:00
snprintf(
file_info_message, sizeof(file_info_message), "\e#%s\e#", furi_string_get_cstr(filename));
widget_add_text_box_element(
2022-09-15 22:21:10 +00:00
instance->widget, 0, 0, 128, 25, AlignLeft, AlignCenter, file_info_message, false);
// Directory path
2022-10-05 18:27:13 +00:00
path_extract_dirname(furi_string_get_cstr(current->path), dirname);
if(strcmp(furi_string_get_cstr(dirname), "/any") == 0) {
furi_string_replace(dirname, STORAGE_ANY_PATH_PREFIX, "/");
} else {
2022-10-05 18:27:13 +00:00
furi_string_replace(dirname, STORAGE_ANY_PATH_PREFIX, "");
}
// File size
FileInfo fileinfo;
2022-10-05 18:27:13 +00:00
storage_common_stat(fs_api, furi_string_get_cstr(current->path), &fileinfo);
2022-09-15 22:21:10 +00:00
if(fileinfo.size <= 1024) {
2022-10-07 15:32:58 +00:00
furi_string_printf(str_size, "%lld", fileinfo.size);
2022-09-15 22:21:10 +00:00
snprintf(
file_info_message,
sizeof(file_info_message),
"Size: \e#%s\e# bytes\n%s",
2022-10-05 18:27:13 +00:00
furi_string_get_cstr(str_size),
furi_string_get_cstr(dirname));
2022-09-15 22:21:10 +00:00
} else {
2022-10-07 15:32:58 +00:00
furi_string_printf(str_size, "%lld", fileinfo.size / 1024);
2022-09-15 22:21:10 +00:00
snprintf(
file_info_message,
sizeof(file_info_message),
"Size: \e#%s\e# Kb.\n%s",
2022-10-05 18:27:13 +00:00
furi_string_get_cstr(str_size),
furi_string_get_cstr(dirname));
2022-09-15 22:21:10 +00:00
}
widget_add_text_box_element(
instance->widget, 0, 25, 128, 25, AlignLeft, AlignCenter, file_info_message, true);
2022-09-15 22:21:10 +00:00
// This one to return and cursor select this file
2022-10-05 18:27:13 +00:00
path_extract_filename_no_ext(furi_string_get_cstr(current->path), filename);
strlcpy(instance->text_store, furi_string_get_cstr(filename), MAX_NAME_LEN);
2022-10-05 18:27:13 +00:00
furi_string_free(filename);
furi_string_free(dirname);
furi_string_free(str_size);
2022-09-15 22:21:10 +00:00
view_dispatcher_switch_to_view(instance->view_dispatcher, ArchiveViewWidget);
}
bool archive_scene_info_on_event(void* context, SceneManagerEvent event) {
furi_assert(context);
ArchiveApp* app = (ArchiveApp*)context;
if(event.type == SceneManagerEventTypeCustom) {
scene_manager_next_scene(app->scene_manager, ArchiveAppSceneBrowser);
return true;
}
return false;
}
void archive_scene_info_on_exit(void* context) {
furi_assert(context);
ArchiveApp* app = (ArchiveApp*)context;
widget_reset(app->widget);
}