1
2 #include "../../lv_examples.h"
3
4 #if LV_USE_TABLE && LV_USE_FILE_EXPLORER && (LV_USE_FS_STDIO || LV_USE_FS_POSIX || LV_USE_FS_WIN32 || LV_USE_FS_FATFS) && LV_BUILD_EXAMPLES
5
6 #include <stdlib.h>
7 #include <string.h>
8
file_explorer_event_handler(lv_event_t * e)9 static void file_explorer_event_handler(lv_event_t * e)
10 {
11 lv_event_code_t code = lv_event_get_code(e);
12 lv_obj_t * obj = lv_event_get_target(e);
13
14 if(code == LV_EVENT_VALUE_CHANGED) {
15 const char * cur_path = lv_file_explorer_get_current_path(obj);
16 const char * sel_fn = lv_file_explorer_get_selected_file_name(obj);
17 LV_LOG_USER("%s%s", cur_path, sel_fn);
18 }
19 }
20
lv_example_file_explorer_1(void)21 void lv_example_file_explorer_1(void)
22 {
23 lv_obj_t * file_explorer = lv_file_explorer_create(lv_screen_active());
24 lv_file_explorer_set_sort(file_explorer, LV_EXPLORER_SORT_KIND);
25
26 #if LV_USE_FS_WIN32
27 /* Note to Windows users: the initial "C:" on these paths corresponds to
28 * the value of `LV_FS_WIN32_LETTER` in `lv_conf.h`, and should not be
29 * confused with the Windows/DOS drive letter. It is an identifier that
30 * is used to enable LVGL to look up the appropriate driver from a list of
31 * registered file-system drivers. `lv_fs_win32_init()` happens to use the
32 * identifier letter 'C' so "C:" is the driver-identifier-prefix used here.
33 * The "C:" following that is indeed the Windows/DOS drive letter and is
34 * part of the actual path that gets passed to the OS-level functions.
35 *
36 * See https://docs.lvgl.io/master/details/main-components/fs.html for details.
37 * File Explorer uses `lv_fs` internally, thus the required prefix in path strings.
38 */
39 lv_file_explorer_open_dir(file_explorer, "C:C:/");
40 #if LV_FILE_EXPLORER_QUICK_ACCESS
41 lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_HOME_DIR, "C:C:/Users/Public/Desktop");
42 lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_VIDEO_DIR, "C:C:/Users/Public/Videos");
43 lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_PICTURES_DIR, "C:C:/Users/Public/Pictures");
44 lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_MUSIC_DIR, "C:C:/Users/Public/Music");
45 lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_DOCS_DIR, "C:C:/Users/Public/Documents");
46 lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_FS_DIR, "C:C:/");
47 #endif
48
49 #else
50 /* linux */
51 lv_file_explorer_open_dir(file_explorer, "A:/");
52
53 #if LV_FILE_EXPLORER_QUICK_ACCESS
54 char * envvar = "HOME";
55 char home_dir[LV_FS_MAX_PATH_LENGTH];
56 strcpy(home_dir, "A:");
57 /* get the user's home directory from the HOME environment variable*/
58 strcat(home_dir, getenv(envvar));
59 LV_LOG_USER("home_dir: %s\n", home_dir);
60 lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_HOME_DIR, home_dir);
61 char video_dir[LV_FS_MAX_PATH_LENGTH];
62 strcpy(video_dir, home_dir);
63 strcat(video_dir, "/Videos");
64 lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_VIDEO_DIR, video_dir);
65 char picture_dir[LV_FS_MAX_PATH_LENGTH];
66 strcpy(picture_dir, home_dir);
67 strcat(picture_dir, "/Pictures");
68 lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_PICTURES_DIR, picture_dir);
69 char music_dir[LV_FS_MAX_PATH_LENGTH];
70 strcpy(music_dir, home_dir);
71 strcat(music_dir, "/Music");
72 lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_MUSIC_DIR, music_dir);
73 char document_dir[LV_FS_MAX_PATH_LENGTH];
74 strcpy(document_dir, home_dir);
75 strcat(document_dir, "/Documents");
76 lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_DOCS_DIR, document_dir);
77
78 lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_FS_DIR, "A:/");
79 #endif
80 #endif
81
82 lv_obj_add_event_cb(file_explorer, file_explorer_event_handler, LV_EVENT_ALL, NULL);
83 }
84
85 #endif
86