[FL-2491] File browser GUI module (#1237)
* File browser module and test app * nfc: Add support for saved files in subdirectories * nfc: Use helper function to get shadow path when loading data * File browser dialog integration pt.1 * File browser dialog integration pt.2 * Gui,Dialogs: drop file select * Correct use of dynamic string_t(string_ptr) Co-authored-by: Yukai Li <yukaili.geek@gmail.com> Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "dialogs/dialogs_message.h"
|
||||
#include "dialogs_i.h"
|
||||
#include "dialogs_api_lock.h"
|
||||
#include "dialogs_module_file_select.h"
|
||||
#include "dialogs_module_file_browser.h"
|
||||
#include "dialogs_module_message.h"
|
||||
|
||||
static DialogsApp* dialogs_app_alloc() {
|
||||
@@ -13,9 +14,9 @@ static DialogsApp* dialogs_app_alloc() {
|
||||
static void dialogs_app_process_message(DialogsApp* app, DialogsAppMessage* message) {
|
||||
UNUSED(app);
|
||||
switch(message->command) {
|
||||
case DialogsAppCommandFileOpen:
|
||||
case DialogsAppCommandFileBrowser:
|
||||
message->return_data->bool_value =
|
||||
dialogs_app_process_module_file_select(&message->data->file_select);
|
||||
dialogs_app_process_module_file_browser(&message->data->file_browser);
|
||||
break;
|
||||
case DialogsAppCommandDialog:
|
||||
message->return_data->dialog_value =
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <furi.h>
|
||||
#include <gui/canvas.h>
|
||||
#include "m-string.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -10,25 +11,27 @@ extern "C" {
|
||||
|
||||
typedef struct DialogsApp DialogsApp;
|
||||
|
||||
/****************** FILE SELECT ******************/
|
||||
/****************** FILE BROWSER ******************/
|
||||
|
||||
/**
|
||||
* Shows and processes the file selection dialog
|
||||
* Shows and processes the file browser dialog
|
||||
* @param context api pointer
|
||||
* @param path path to directory
|
||||
* @param result_path selected file path string pointer
|
||||
* @param path preselected file path string pointer
|
||||
* @param extension file extension to be offered for selection
|
||||
* @param selected_filename buffer where the selected filename will be saved
|
||||
* @param selected_filename_size and the size of this buffer
|
||||
* @param preselected_filename filename to be preselected
|
||||
* @param skip_assets true - do not show assets folders
|
||||
* @param icon file icon pointer, NULL for default icon
|
||||
* @param hide_ext true - hide extensions for files
|
||||
* @return bool whether a file was selected
|
||||
*/
|
||||
bool dialog_file_select_show(
|
||||
bool dialog_file_browser_show(
|
||||
DialogsApp* context,
|
||||
const char* path,
|
||||
string_ptr result_path,
|
||||
string_ptr path,
|
||||
const char* extension,
|
||||
char* result,
|
||||
uint8_t result_size,
|
||||
const char* preselected_filename);
|
||||
bool skip_assets,
|
||||
const Icon* icon,
|
||||
bool hide_ext);
|
||||
|
||||
/****************** MESSAGE ******************/
|
||||
|
||||
|
@@ -1,31 +1,36 @@
|
||||
#include "dialogs/dialogs_message.h"
|
||||
#include "dialogs_i.h"
|
||||
#include "dialogs_api_lock.h"
|
||||
#include "m-string.h"
|
||||
|
||||
/****************** File select ******************/
|
||||
/****************** File browser ******************/
|
||||
|
||||
bool dialog_file_select_show(
|
||||
bool dialog_file_browser_show(
|
||||
DialogsApp* context,
|
||||
const char* path,
|
||||
string_ptr result_path,
|
||||
string_ptr path,
|
||||
const char* extension,
|
||||
char* result,
|
||||
uint8_t result_size,
|
||||
const char* preselected_filename) {
|
||||
bool skip_assets,
|
||||
const Icon* icon,
|
||||
bool hide_ext) {
|
||||
FuriApiLock lock = API_LOCK_INIT_LOCKED();
|
||||
furi_check(lock != NULL);
|
||||
|
||||
DialogsAppData data = {
|
||||
.file_select = {
|
||||
.path = path,
|
||||
.file_browser = {
|
||||
.extension = extension,
|
||||
.result = result,
|
||||
.result_size = result_size,
|
||||
.preselected_filename = preselected_filename,
|
||||
.result_path = result_path,
|
||||
.file_icon = icon,
|
||||
.hide_ext = hide_ext,
|
||||
.skip_assets = skip_assets,
|
||||
.preselected_filename = path,
|
||||
|
||||
}};
|
||||
|
||||
DialogsAppReturn return_data;
|
||||
DialogsAppMessage message = {
|
||||
.lock = lock,
|
||||
.command = DialogsAppCommandFileOpen,
|
||||
.command = DialogsAppCommandFileBrowser,
|
||||
.data = &data,
|
||||
.return_data = &return_data,
|
||||
};
|
||||
|
@@ -2,25 +2,27 @@
|
||||
#include <furi.h>
|
||||
#include "dialogs_i.h"
|
||||
#include "dialogs_api_lock.h"
|
||||
#include "m-string.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
const char* path;
|
||||
const char* extension;
|
||||
char* result;
|
||||
uint8_t result_size;
|
||||
const char* preselected_filename;
|
||||
} DialogsAppMessageDataFileSelect;
|
||||
bool skip_assets;
|
||||
bool hide_ext;
|
||||
const Icon* file_icon;
|
||||
string_ptr result_path;
|
||||
string_ptr preselected_filename;
|
||||
} DialogsAppMessageDataFileBrowser;
|
||||
|
||||
typedef struct {
|
||||
const DialogMessage* message;
|
||||
} DialogsAppMessageDataDialog;
|
||||
|
||||
typedef union {
|
||||
DialogsAppMessageDataFileSelect file_select;
|
||||
DialogsAppMessageDataFileBrowser file_browser;
|
||||
DialogsAppMessageDataDialog dialog;
|
||||
} DialogsAppData;
|
||||
|
||||
@@ -30,7 +32,7 @@ typedef union {
|
||||
} DialogsAppReturn;
|
||||
|
||||
typedef enum {
|
||||
DialogsAppCommandFileOpen,
|
||||
DialogsAppCommandFileBrowser,
|
||||
DialogsAppCommandDialog,
|
||||
} DialogsAppCommand;
|
||||
|
||||
|
59
applications/dialogs/dialogs_module_file_browser.c
Normal file
59
applications/dialogs/dialogs_module_file_browser.c
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "dialogs_i.h"
|
||||
#include "dialogs_api_lock.h"
|
||||
#include "gui/modules/file_browser.h"
|
||||
|
||||
typedef struct {
|
||||
FuriApiLock lock;
|
||||
bool result;
|
||||
} DialogsAppFileBrowserContext;
|
||||
|
||||
static void dialogs_app_file_browser_back_callback(void* context) {
|
||||
furi_assert(context);
|
||||
DialogsAppFileBrowserContext* file_browser_context = context;
|
||||
file_browser_context->result = false;
|
||||
API_LOCK_UNLOCK(file_browser_context->lock);
|
||||
}
|
||||
|
||||
static void dialogs_app_file_browser_callback(void* context) {
|
||||
furi_assert(context);
|
||||
DialogsAppFileBrowserContext* file_browser_context = context;
|
||||
file_browser_context->result = true;
|
||||
API_LOCK_UNLOCK(file_browser_context->lock);
|
||||
}
|
||||
|
||||
bool dialogs_app_process_module_file_browser(const DialogsAppMessageDataFileBrowser* data) {
|
||||
bool ret = false;
|
||||
Gui* gui = furi_record_open("gui");
|
||||
|
||||
DialogsAppFileBrowserContext* file_browser_context =
|
||||
malloc(sizeof(DialogsAppFileBrowserContext));
|
||||
file_browser_context->lock = 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_file_browser_back_callback, file_browser_context);
|
||||
|
||||
FileBrowser* file_browser = file_browser_alloc(data->result_path);
|
||||
file_browser_set_callback(
|
||||
file_browser, dialogs_app_file_browser_callback, file_browser_context);
|
||||
file_browser_configure(
|
||||
file_browser, data->extension, data->skip_assets, data->file_icon, data->hide_ext);
|
||||
file_browser_start(file_browser, data->preselected_filename);
|
||||
|
||||
view_holder_set_view(view_holder, file_browser_get_view(file_browser));
|
||||
view_holder_start(view_holder);
|
||||
API_LOCK_WAIT_UNTIL_UNLOCK(file_browser_context->lock);
|
||||
|
||||
ret = file_browser_context->result;
|
||||
|
||||
view_holder_stop(view_holder);
|
||||
view_holder_free(view_holder);
|
||||
file_browser_stop(file_browser);
|
||||
file_browser_free(file_browser);
|
||||
API_LOCK_FREE(file_browser_context->lock);
|
||||
free(file_browser_context);
|
||||
furi_record_close("gui");
|
||||
|
||||
return ret;
|
||||
}
|
@@ -5,7 +5,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
bool dialogs_app_process_module_file_select(const DialogsAppMessageDataFileSelect* data);
|
||||
bool dialogs_app_process_module_file_browser(const DialogsAppMessageDataFileBrowser* data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
@@ -1,59 +0,0 @@
|
||||
#include "dialogs_i.h"
|
||||
#include "dialogs_api_lock.h"
|
||||
#include <gui/modules/file_select.h>
|
||||
|
||||
typedef struct {
|
||||
FuriApiLock lock;
|
||||
bool result;
|
||||
} DialogsAppFileSelectContext;
|
||||
|
||||
static void dialogs_app_file_select_back_callback(void* context) {
|
||||
furi_assert(context);
|
||||
DialogsAppFileSelectContext* file_select_context = context;
|
||||
file_select_context->result = false;
|
||||
API_LOCK_UNLOCK(file_select_context->lock);
|
||||
}
|
||||
|
||||
static void dialogs_app_file_select_callback(bool result, void* context) {
|
||||
furi_assert(context);
|
||||
DialogsAppFileSelectContext* file_select_context = context;
|
||||
file_select_context->result = result;
|
||||
API_LOCK_UNLOCK(file_select_context->lock);
|
||||
}
|
||||
|
||||
bool dialogs_app_process_module_file_select(const DialogsAppMessageDataFileSelect* data) {
|
||||
bool ret = false;
|
||||
Gui* gui = furi_record_open("gui");
|
||||
|
||||
DialogsAppFileSelectContext* file_select_context = malloc(sizeof(DialogsAppFileSelectContext));
|
||||
file_select_context->lock = 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_file_select_back_callback, file_select_context);
|
||||
|
||||
FileSelect* file_select = file_select_alloc();
|
||||
file_select_set_callback(file_select, dialogs_app_file_select_callback, file_select_context);
|
||||
file_select_set_filter(file_select, data->path, data->extension);
|
||||
file_select_set_result_buffer(file_select, data->result, data->result_size);
|
||||
file_select_init(file_select);
|
||||
if(data->preselected_filename != NULL) {
|
||||
file_select_set_selected_file(file_select, data->preselected_filename);
|
||||
}
|
||||
|
||||
view_holder_set_view(view_holder, file_select_get_view(file_select));
|
||||
view_holder_start(view_holder);
|
||||
API_LOCK_WAIT_UNTIL_UNLOCK(file_select_context->lock);
|
||||
|
||||
ret = file_select_context->result;
|
||||
|
||||
view_holder_stop(view_holder);
|
||||
view_holder_free(view_holder);
|
||||
file_select_free(file_select);
|
||||
API_LOCK_FREE(file_select_context->lock);
|
||||
free(file_select_context);
|
||||
furi_record_close("gui");
|
||||
|
||||
return ret;
|
||||
}
|
Reference in New Issue
Block a user