[11662bd] | 1 | /*
|
---|
[7cf5ddb] | 2 | * Copyright (c) 2023 Jiri Svoboda
|
---|
[11662bd] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup libui
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file File list
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #ifndef _UI_PRIVATE_FILELIST_H
|
---|
| 37 | #define _UI_PRIVATE_FILELIST_H
|
---|
| 38 |
|
---|
| 39 | #include <gfx/color.h>
|
---|
| 40 | #include <ipc/loc.h>
|
---|
[7cf5ddb] | 41 | #include <ui/list.h>
|
---|
[11662bd] | 42 | #include <ui/window.h>
|
---|
| 43 | #include <stdint.h>
|
---|
| 44 | #include <types/ui/filelist.h>
|
---|
| 45 |
|
---|
| 46 | /** File list entry attributes */
|
---|
| 47 | struct ui_file_list_entry_attr {
|
---|
| 48 | /** File name */
|
---|
| 49 | const char *name;
|
---|
| 50 | /** File size */
|
---|
| 51 | uint64_t size;
|
---|
| 52 | /** @c true iff entry is a directory */
|
---|
| 53 | bool isdir;
|
---|
| 54 | /** Service number for service special entries */
|
---|
| 55 | service_id_t svc;
|
---|
| 56 | };
|
---|
| 57 |
|
---|
| 58 | /** File list entry */
|
---|
| 59 | struct ui_file_list_entry {
|
---|
| 60 | /** Containing file list */
|
---|
| 61 | struct ui_file_list *flist;
|
---|
[7cf5ddb] | 62 | /** List entry */
|
---|
| 63 | ui_list_entry_t *entry;
|
---|
[11662bd] | 64 | /** File name */
|
---|
| 65 | char *name;
|
---|
| 66 | /** File size */
|
---|
| 67 | uint64_t size;
|
---|
| 68 | /** @c true iff entry is a directory */
|
---|
| 69 | bool isdir;
|
---|
| 70 | /** Service number for service special entries */
|
---|
| 71 | service_id_t svc;
|
---|
| 72 | };
|
---|
| 73 |
|
---|
| 74 | /** File list.
|
---|
| 75 | *
|
---|
| 76 | * Allows browsing files and directories.
|
---|
| 77 | */
|
---|
| 78 | typedef struct ui_file_list {
|
---|
| 79 | /** Base control object */
|
---|
| 80 | struct ui_control *control;
|
---|
| 81 |
|
---|
| 82 | /** Containing window */
|
---|
[7cf5ddb] | 83 | struct ui_window *window;
|
---|
| 84 |
|
---|
| 85 | /** UI list */
|
---|
| 86 | ui_list_t *list;
|
---|
[11662bd] | 87 |
|
---|
| 88 | /** Callbacks */
|
---|
| 89 | struct ui_file_list_cb *cb;
|
---|
| 90 |
|
---|
| 91 | /** Callback argument */
|
---|
| 92 | void *cb_arg;
|
---|
| 93 |
|
---|
| 94 | /** Directory-type entry color */
|
---|
| 95 | gfx_color_t *dir_color;
|
---|
| 96 |
|
---|
| 97 | /** Service-type entry color */
|
---|
| 98 | gfx_color_t *svc_color;
|
---|
| 99 |
|
---|
| 100 | /** Directory */
|
---|
| 101 | char *dir;
|
---|
| 102 | } ui_file_list_t;
|
---|
| 103 |
|
---|
| 104 | extern bool ui_file_list_is_active(ui_file_list_t *);
|
---|
[c0757e1f] | 105 | extern void ui_file_list_entry_destroy(ui_file_list_entry_t *);
|
---|
[11662bd] | 106 | extern void ui_file_list_clear_entries(ui_file_list_t *);
|
---|
| 107 | extern errno_t ui_file_list_sort(ui_file_list_t *);
|
---|
| 108 | extern int ui_file_list_entry_ptr_cmp(const void *, const void *);
|
---|
[7cf5ddb] | 109 | extern void ui_file_list_entry_attr_init(ui_file_list_entry_attr_t *);
|
---|
| 110 | extern errno_t ui_file_list_entry_append(ui_file_list_t *,
|
---|
| 111 | ui_file_list_entry_attr_t *);
|
---|
[11662bd] | 112 | extern ui_file_list_entry_t *ui_file_list_first(ui_file_list_t *);
|
---|
| 113 | extern ui_file_list_entry_t *ui_file_list_last(ui_file_list_t *);
|
---|
| 114 | extern ui_file_list_entry_t *ui_file_list_next(ui_file_list_entry_t *);
|
---|
| 115 | extern ui_file_list_entry_t *ui_file_list_prev(ui_file_list_entry_t *);
|
---|
| 116 | extern errno_t ui_file_list_open_dir(ui_file_list_t *, ui_file_list_entry_t *);
|
---|
| 117 | extern errno_t ui_file_list_open_file(ui_file_list_t *, ui_file_list_entry_t *);
|
---|
| 118 | extern void ui_file_list_activate_req(ui_file_list_t *);
|
---|
| 119 | extern void ui_file_list_selected(ui_file_list_t *, const char *);
|
---|
[7cf5ddb] | 120 | extern errno_t ui_file_list_paint(ui_file_list_t *);
|
---|
| 121 | extern int ui_file_list_list_compare(ui_list_entry_t *, ui_list_entry_t *);
|
---|
[11662bd] | 122 |
|
---|
| 123 | #endif
|
---|
| 124 |
|
---|
| 125 | /** @}
|
---|
| 126 | */
|
---|