Remove browse_context_init()

Prefer to use designated initializers to avoid having to specify
unneeded parameters. Non-initialized members are zero-initialized
by the compiler.

Change-Id: Ia6a03c45cb3ef0b30f458d7d0ae1604a350c737c
This commit is contained in:
Aidan MacDonald 2022-11-30 15:17:54 +00:00
parent 701e262d3d
commit 6c52fa139c
17 changed files with 117 additions and 108 deletions

View file

@ -54,11 +54,14 @@ static void pm_handler(unsigned short id, void *data)
static int plugins_menu(void* param) static int plugins_menu(void* param)
{ {
intptr_t item = (intptr_t)param; intptr_t item = (intptr_t)param;
struct browse_context browse;
int ret; int ret;
browse_context_init(&browse, SHOW_PLUGINS, 0, str(items[item].id), struct browse_context browse = {
Icon_Plugin, items[item].path, NULL); .dirfilter = SHOW_PLUGINS,
.title = str(items[item].id),
.icon = Icon_Plugin,
.root = items[item].path,
};
ret = rockbox_browse(&browse); ret = rockbox_browse(&browse);

View file

@ -249,9 +249,12 @@ int browse_folder(void *param)
char selected[MAX_FILENAME+10]; char selected[MAX_FILENAME+10];
const struct browse_folder_info *info = const struct browse_folder_info *info =
(const struct browse_folder_info*)param; (const struct browse_folder_info*)param;
struct browse_context browse;
browse_context_init(&browse, info->show_options, 0, struct browse_context browse = {
NULL, NOICON, info->dir, NULL); .dirfilter = info->show_options,
.icon = Icon_NOICON,
.root = info->dir,
};
/* if we are in a special settings folder, center the current setting */ /* if we are in a special settings folder, center the current setting */
switch(info->show_options) switch(info->show_options)

View file

@ -352,7 +352,7 @@ retnhash:
void open_plugin_browse(const char *key) void open_plugin_browse(const char *key)
{ {
logf("%s", __func__); logf("%s", __func__);
struct browse_context browse;
char tmp_buf[OPEN_PLUGIN_BUFSZ+1]; char tmp_buf[OPEN_PLUGIN_BUFSZ+1];
open_plugin_load_entry(key); open_plugin_load_entry(key);
struct open_plugin_entry_t *op_entry = open_plugin_get_entry(); struct open_plugin_entry_t *op_entry = open_plugin_get_entry();
@ -364,11 +364,15 @@ void open_plugin_browse(const char *key)
if (op_entry->path[0] == '\0') if (op_entry->path[0] == '\0')
strcpy(op_entry->path, PLUGIN_DIR"/"); strcpy(op_entry->path, PLUGIN_DIR"/");
browse_context_init(&browse, SHOW_ALL, BROWSE_SELECTONLY, "", struct browse_context browse = {
Icon_Plugin, op_entry->path, NULL); .dirfilter = SHOW_ALL,
.flags = BROWSE_SELECTONLY,
browse.buf = tmp_buf; .title = str(LANG_OPEN_PLUGIN),
browse.bufsize = OPEN_PLUGIN_BUFSZ; .icon = Icon_Plugin,
.root = op_entry->path,
.buf = tmp_buf,
.bufsize = sizeof(tmp_buf),
};
if (rockbox_browse(&browse) == GO_TO_PREVIOUS) if (rockbox_browse(&browse) == GO_TO_PREVIOUS)
open_plugin_add_path(key, tmp_buf, NULL); open_plugin_add_path(key, tmp_buf, NULL);

View file

@ -150,7 +150,6 @@ static int display_playlists(char* playlist, enum catbrowse_status_flags status)
{ {
static bool reopen_last_playlist = false; static bool reopen_last_playlist = false;
static int most_recent_selection = 0; static int most_recent_selection = 0;
struct browse_context browse;
int result = -1; int result = -1;
char selected_playlist[MAX_PATH]; char selected_playlist[MAX_PATH];
selected_playlist[0] = '\0'; selected_playlist[0] = '\0';
@ -158,14 +157,16 @@ static int display_playlists(char* playlist, enum catbrowse_status_flags status)
browser_status |= status; browser_status |= status;
bool view = (status == CATBROWSE_CATVIEW); bool view = (status == CATBROWSE_CATVIEW);
browse_context_init(&browse, SHOW_M3U, struct browse_context browse = {
BROWSE_SELECTONLY|(view? 0: BROWSE_NO_CONTEXT_MENU), .dirfilter = SHOW_M3U,
str(LANG_CATALOG), NOICON, .flags = BROWSE_SELECTONLY | (view ? 0 : BROWSE_NO_CONTEXT_MENU),
selected_playlist, .title = str(LANG_CATALOG),
playlist_dir_length + 1 + most_recent_playlist); .icon = Icon_NOICON,
.root = selected_playlist,
browse.buf = selected_playlist; .selected = &most_recent_playlist[playlist_dir_length + 1],
browse.bufsize = sizeof(selected_playlist); .buf = selected_playlist,
.bufsize = sizeof(selected_playlist),
};
restart: restart:
/* set / restore the root directory for the browser */ /* set / restore the root directory for the browser */

View file

@ -429,7 +429,6 @@ static const struct plugin_api rockbox_api = {
dir_get_info, dir_get_info,
/* browsing */ /* browsing */
browse_context_init,
rockbox_browse, rockbox_browse,
tree_get_context, tree_get_context,
tree_get_entries, tree_get_entries,

View file

@ -157,12 +157,12 @@ int plugin_open(const char *plugin, const char *parameter);
#define PLUGIN_MAGIC 0x526F634B /* RocK */ #define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */ /* increase this every time the api struct changes */
#define PLUGIN_API_VERSION 257 #define PLUGIN_API_VERSION 258
/* update this to latest version if a change to the api struct breaks /* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */ new function which are "waiting" at the end of the function table) */
#define PLUGIN_MIN_API_VERSION 257 #define PLUGIN_MIN_API_VERSION 258
/* 239 Marks the removal of ARCHOS HWCODEC and CHARCELL */ /* 239 Marks the removal of ARCHOS HWCODEC and CHARCELL */
@ -479,10 +479,6 @@ struct plugin_api {
struct dirinfo (*dir_get_info)(DIR *dirp, struct dirent *entry); struct dirinfo (*dir_get_info)(DIR *dirp, struct dirent *entry);
/* browsing */ /* browsing */
void (*browse_context_init)(struct browse_context *browse,
int dirfilter, unsigned flags,
char *title, enum themable_icons icon,
const char *root, const char *selected);
int (*rockbox_browse)(struct browse_context *browse); int (*rockbox_browse)(struct browse_context *browse);
struct tree_context* (*tree_get_context)(void); struct tree_context* (*tree_get_context)(void);
struct entry* (*tree_get_entries)(struct tree_context* t); struct entry* (*tree_get_entries)(struct tree_context* t);

View file

@ -613,13 +613,14 @@ static void keyremap_export_user_keys(void)
static void keyremap_import_user_keys(void) static void keyremap_import_user_keys(void)
{ {
char buf[MAX_PATH]; char buf[MAX_PATH];
struct browse_context browse; struct browse_context browse = {
.dirfilter = SHOW_ALL,
rb->browse_context_init(&browse, SHOW_ALL, BROWSE_SELECTONLY, "Select Keymap", .flags = BROWSE_SELECTONLY,
Icon_Plugin, "/", NULL); .title = "Select Keymap",
.icon = Icon_Plugin,
browse.buf = buf; .buf = buf,
browse.bufsize = sizeof(buf); .bufsize = sizeof(buf),
};
if (rb->rockbox_browse(&browse) == GO_TO_PREVIOUS) if (rb->rockbox_browse(&browse) == GO_TO_PREVIOUS)
{ {

View file

@ -189,17 +189,20 @@ static void op_entry_set_name(void)
static int op_entry_set_path(void) static int op_entry_set_path(void)
{ {
int ret = 0; int ret = 0;
struct browse_context browse;
char tmp_buf[OPEN_PLUGIN_BUFSZ+1]; char tmp_buf[OPEN_PLUGIN_BUFSZ+1];
if (op_entry.path[0] == '\0') if (op_entry.path[0] == '\0')
rb->strcpy(op_entry.path, PLUGIN_DIR"/"); rb->strcpy(op_entry.path, PLUGIN_DIR"/");
rb->browse_context_init(&browse, SHOW_ALL, BROWSE_SELECTONLY, rb->str(LANG_ADD), struct browse_context browse = {
Icon_Plugin, op_entry.path, NULL); .dirfilter = SHOW_ALL,
.flags = BROWSE_SELECTONLY,
browse.buf = tmp_buf; .title = rb->str(LANG_ADD),
browse.bufsize = OPEN_PLUGIN_BUFSZ; .icon = Icon_Plugin,
.root = op_entry.path,
.buf = tmp_buf,
.bufsize = sizeof(tmp_buf),
};
if (rb->rockbox_browse(&browse) == GO_TO_PREVIOUS) if (rb->rockbox_browse(&browse) == GO_TO_PREVIOUS)
{ {
@ -213,7 +216,6 @@ static int op_entry_set_path(void)
static int op_entry_set_param_path(void) static int op_entry_set_param_path(void)
{ {
int ret = 0; int ret = 0;
struct browse_context browse;
char tmp_buf[OPEN_PLUGIN_BUFSZ+1]; char tmp_buf[OPEN_PLUGIN_BUFSZ+1];
if (op_entry.param[0] == '\0') if (op_entry.param[0] == '\0')
@ -221,11 +223,15 @@ static int op_entry_set_param_path(void)
else else
rb->strcpy(tmp_buf, op_entry.param); rb->strcpy(tmp_buf, op_entry.param);
rb->browse_context_init(&browse, SHOW_ALL, BROWSE_SELECTONLY, "", struct browse_context browse = {
Icon_Plugin, tmp_buf, NULL); .dirfilter = SHOW_ALL,
.flags = BROWSE_SELECTONLY,
browse.buf = tmp_buf; .title = rb->str(LANG_PARAMETER),
browse.bufsize = OPEN_PLUGIN_BUFSZ; .icon = Icon_Plugin,
.root = tmp_buf,
.buf = tmp_buf,
.bufsize = sizeof(tmp_buf),
};
if (rb->rockbox_browse(&browse) == GO_TO_PREVIOUS) if (rb->rockbox_browse(&browse) == GO_TO_PREVIOUS)
{ {

View file

@ -208,17 +208,16 @@ static int base32_encode(const uint8_t *data, int length, uint8_t *result,
static bool browse( char *dst, int dst_size, const char *start ) static bool browse( char *dst, int dst_size, const char *start )
{ {
struct browse_context browse; struct browse_context browse = {
.dirfilter = SHOW_ALL,
rb->browse_context_init(&browse, SHOW_ALL, .flags = BROWSE_SELECTONLY | BROWSE_NO_CONTEXT_MENU,
BROWSE_SELECTONLY|BROWSE_NO_CONTEXT_MENU, .icon = Icon_NOICON,
NULL, NOICON, start, NULL); .root = start,
.buf = dst,
browse.buf = dst; .bufsize = dst_size,
browse.bufsize = dst_size; };
rb->rockbox_browse(&browse); rb->rockbox_browse(&browse);
return (browse.flags & BROWSE_SELECTED); return (browse.flags & BROWSE_SELECTED);
} }

View file

@ -1084,15 +1084,15 @@ static bool callback_show_item(char *name, int attr, struct tree_context *tc)
static bool browse( char *dst, int dst_size, const char *start ) static bool browse( char *dst, int dst_size, const char *start )
{ {
struct browse_context browse; struct browse_context browse = {
.dirfilter = SHOW_ALL,
rb->browse_context_init(&browse, SHOW_ALL, .flags = BROWSE_SELECTONLY | BROWSE_NO_CONTEXT_MENU,
BROWSE_SELECTONLY|BROWSE_NO_CONTEXT_MENU, .icon = Icon_NOICON,
NULL, NOICON, start, NULL); .root = start,
.buf = dst,
browse.callback_show_item = callback_show_item; .bufsize = dst_size,
browse.buf = dst; .callback_show_item = callback_show_item,
browse.bufsize = dst_size; };
rb->rockbox_browse(&browse); rb->rockbox_browse(&browse);

View file

@ -482,16 +482,19 @@ static void load_font(void)
static void font_menu(void) static void font_menu(void)
{ {
/* taken from text_viewer */ /* taken from text_viewer */
struct browse_context browse;
char font[MAX_PATH], name[MAX_FILENAME+10]; char font[MAX_PATH], name[MAX_FILENAME+10];
rb->snprintf(name, sizeof(name), "%s.fnt", rb->global_settings->font_file); rb->snprintf(name, sizeof(name), "%s.fnt", rb->global_settings->font_file);
rb->browse_context_init(&browse, SHOW_FONT,
BROWSE_SELECTONLY|BROWSE_NO_CONTEXT_MENU,
"Font", Icon_Menu_setting, FONT_DIR, name);
browse.buf = font; struct browse_context browse = {
browse.bufsize = sizeof(font); .dirfilter = SHOW_FONT,
.flags = BROWSE_SELECTONLY | BROWSE_NO_CONTEXT_MENU,
.title = rb->str(LANG_CUSTOM_FONT),
.icon = Icon_Menu_setting,
.root = FONT_DIR,
.selected = name,
.buf = font,
.bufsize = sizeof(font),
};
rb->rockbox_browse(&browse); rb->rockbox_browse(&browse);

View file

@ -200,16 +200,19 @@ static bool tv_statusbar_setting(void)
static bool tv_font_setting(void) static bool tv_font_setting(void)
{ {
struct browse_context browse;
char font[MAX_PATH], name[MAX_FILENAME+10]; char font[MAX_PATH], name[MAX_FILENAME+10];
rb->snprintf(name, sizeof(name), "%s.fnt", new_prefs.font_name); rb->snprintf(name, sizeof(name), "%s.fnt", new_prefs.font_name);
rb->browse_context_init(&browse, SHOW_FONT,
BROWSE_SELECTONLY|BROWSE_NO_CONTEXT_MENU,
"Font", Icon_Menu_setting, FONT_DIR, name);
browse.buf = font; struct browse_context browse = {
browse.bufsize = sizeof(font); .dirfilter = SHOW_FONT,
.flags = BROWSE_SELECTONLY | BROWSE_NO_CONTEXT_MENU,
.title = "Font", /* XXX: Translate? */
.icon = Icon_Menu_setting,
.root = FONT_DIR,
.selected = name,
.buf = font,
.bufsize = sizeof(font),
};
rb->rockbox_browse(&browse); rb->rockbox_browse(&browse);

View file

@ -351,11 +351,16 @@ static int radio_delete_preset(void)
int preset_list_load(void) int preset_list_load(void)
{ {
char selected[MAX_PATH]; char selected[MAX_PATH];
struct browse_context browse;
snprintf(selected, sizeof(selected), "%s.%s", global_settings.fmr_file, "fmr"); snprintf(selected, sizeof(selected), "%s.%s", global_settings.fmr_file, "fmr");
browse_context_init(&browse, SHOW_FMR, 0,
str(LANG_FM_PRESET_LOAD), NOICON, struct browse_context browse = {
FMPRESET_PATH, selected); .dirfilter = SHOW_FMR,
.title = str(LANG_FM_PRESET_LOAD),
.icon = Icon_NOICON,
.root = FMPRESET_PATH,
.selected = selected,
};
return !rockbox_browse(&browse); return !rockbox_browse(&browse);
} }

View file

@ -115,7 +115,6 @@ static int browser(void* param)
#ifdef HAVE_TAGCACHE #ifdef HAVE_TAGCACHE
struct tree_context* tc = tree_get_context(); struct tree_context* tc = tree_get_context();
#endif #endif
struct browse_context browse;
int filter = SHOW_SUPPORTED; int filter = SHOW_SUPPORTED;
char folder[MAX_PATH] = "/"; char folder[MAX_PATH] = "/";
/* stuff needed to remember position in file browser */ /* stuff needed to remember position in file browser */
@ -274,7 +273,12 @@ static int browser(void* param)
#endif /*HAVE_TAGCACHE*/ #endif /*HAVE_TAGCACHE*/
} }
browse_context_init(&browse, filter, 0, NULL, NOICON, folder, NULL); struct browse_context browse = {
.dirfilter = filter,
.icon = Icon_NOICON,
.root = folder,
};
ret_val = rockbox_browse(&browse); ret_val = rockbox_browse(&browse);
if (ret_val == GO_TO_WPS if (ret_val == GO_TO_WPS

View file

@ -660,9 +660,11 @@ int do_shortcut_menu(void *ignored)
done = GO_TO_PLUGIN; done = GO_TO_PLUGIN;
break; break;
} }
struct browse_context browse; struct browse_context browse = {
browse_context_init(&browse, global_settings.dirfilter, 0, .dirfilter = global_settings.dirfilter,
NULL, NOICON, sc->u.path, NULL); .icon = Icon_NOICON,
.root = sc->u.path,
};
if (sc->type == SHORTCUT_FILE) if (sc->type == SHORTCUT_FILE)
browse.flags |= BROWSE_RUNFILE; browse.flags |= BROWSE_RUNFILE;
done = rockbox_browse(&browse); done = rockbox_browse(&browse);

View file

@ -962,22 +962,6 @@ int create_playlist(void)
return (ret) ? 1 : 0; return (ret) ? 1 : 0;
} }
void browse_context_init(struct browse_context *browse,
int dirfilter, unsigned flags,
char *title, enum themable_icons icon,
const char *root, const char *selected)
{
browse->dirfilter = dirfilter;
browse->flags = flags;
browse->callback_show_item = NULL;
browse->title = title;
browse->icon = icon;
browse->root = root;
browse->selected = selected;
browse->buf = NULL;
browse->bufsize = 0;
}
#define NUM_TC_BACKUP 3 #define NUM_TC_BACKUP 3
static struct tree_context backups[NUM_TC_BACKUP]; static struct tree_context backups[NUM_TC_BACKUP];
/* do not make backup if it is not recursive call */ /* do not make backup if it is not recursive call */

View file

@ -106,10 +106,6 @@ void tree_init(void) INIT_ATTR;
char* get_current_file(char* buffer, size_t buffer_len); char* get_current_file(char* buffer, size_t buffer_len);
void set_dirfilter(int l_dirfilter); void set_dirfilter(int l_dirfilter);
void set_current_file(const char *path); void set_current_file(const char *path);
void browse_context_init(struct browse_context *browse,
int dirfilter, unsigned flags,
char *title, enum themable_icons icon,
const char *root, const char *selected);
int rockbox_browse(struct browse_context *browse); int rockbox_browse(struct browse_context *browse);
int create_playlist(void); int create_playlist(void);
void resume_directory(const char *dir); void resume_directory(const char *dir);