Commit fbb4f13f authored by Rafaël Carré's avatar Rafaël Carré

ncurses: factor HandleBrowseKey() out of HandleKey()

parent 41420a4f
...@@ -1551,69 +1551,48 @@ static bool HandlePlaylistKey(intf_thread_t *p_intf, int key) ...@@ -1551,69 +1551,48 @@ static bool HandlePlaylistKey(intf_thread_t *p_intf, int key)
return true; return true;
} }
static int HandleKey(intf_thread_t *p_intf) static bool HandleBrowseKey(intf_thread_t *p_intf, int key)
{ {
struct dir_entry_t *dir_entry;
intf_sys_t *p_sys = p_intf->p_sys; intf_sys_t *p_sys = p_intf->p_sys;
playlist_t *p_playlist = pl_Get(p_intf);
int i_key = wgetch(p_sys->w);
if (i_key == -1)
return 0;
if (p_sys->i_box_type == BOX_PLAYLIST) switch(key)
{
if (HandlePlaylistKey(p_intf, i_key))
return 1;
}
else if (p_sys->i_box_type == BOX_BROWSE)
{
bool b_ret = true;
/* Browser navigation */
switch(i_key)
{ {
case KEY_HOME: case '.':
p_sys->i_box_bidx = 0;
break;
#ifdef __FreeBSD__
case KEY_SELECT:
#endif
case KEY_END:
p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
break;
case KEY_UP:
p_sys->i_box_bidx--;
break;
case KEY_DOWN:
p_sys->i_box_bidx++;
break;
case KEY_PPAGE:
p_sys->i_box_bidx -= p_sys->i_box_lines;
break;
case KEY_NPAGE:
p_sys->i_box_bidx += p_sys->i_box_lines;
break;
case '.': /* Toggle show hidden files */
p_sys->b_show_hidden_files = !p_sys->b_show_hidden_files; p_sys->b_show_hidden_files = !p_sys->b_show_hidden_files;
ReadDir(p_intf); ReadDir(p_intf);
break; return true;
case KEY_ENTER: case KEY_ENTER:
case '\r': case '\r':
case '\n': case '\n':
case ' ': case ' ':
if (p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file || i_key == ' ') dir_entry = p_sys->pp_dir_entries[p_sys->i_box_bidx];
if (!dir_entry->b_file && key != ' ')
{ {
char *current_dir = p_sys->psz_current_dir;
if (asprintf(&p_sys->psz_current_dir, "%s/%s",
p_sys->psz_current_dir, dir_entry->psz_path) != -1)
{
ReadDir(p_intf);
free(current_dir);
}
else
p_sys->psz_current_dir = current_dir;
return true;
}
char* psz_uri; char* psz_uri;
if (asprintf(&psz_uri, "%s://%s/%s", if (asprintf(&psz_uri, "%s://%s/%s",
p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file ? dir_entry->b_file ? "file" : "directory",
"file" : "directory", p_sys->psz_current_dir, dir_entry->psz_path) == -1)
p_sys->psz_current_dir,
p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path
) == -1)
{ {
psz_uri = NULL; return false;
} }
playlist_t *p_playlist = pl_Get(p_intf);
playlist_item_t *p_parent = p_sys->p_node; playlist_item_t *p_parent = p_sys->p_node;
if (!p_parent) if (!p_parent)
{ {
...@@ -1629,32 +1608,54 @@ static int HandleKey(intf_thread_t *p_intf) ...@@ -1629,32 +1608,54 @@ static int HandleKey(intf_thread_t *p_intf)
while (p_parent->p_parent && p_parent->p_parent->p_parent) while (p_parent->p_parent && p_parent->p_parent->p_parent)
p_parent = p_parent->p_parent; p_parent = p_parent->p_parent;
input_item_t *p_input = p_playlist->p_local_onelevel->p_input;
playlist_Add(p_playlist, psz_uri, NULL, PLAYLIST_APPEND, playlist_Add(p_playlist, psz_uri, NULL, PLAYLIST_APPEND,
PLAYLIST_END, PLAYLIST_END, p_parent->p_input == p_input, false);
p_parent->p_input ==
p_playlist->p_local_onelevel->p_input
, false);
p_sys->i_box_type = BOX_PLAYLIST; p_sys->i_box_type = BOX_PLAYLIST;
free(psz_uri); free(psz_uri);
} return true;
else
{ #ifdef __FreeBSD__
if (asprintf(&(p_sys->psz_current_dir), "%s/%s", p_sys->psz_current_dir, case KEY_SELECT:
p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path) != -1) #endif
ReadDir(p_intf); case KEY_END: p_sys->i_box_bidx = p_sys->i_dir_entries - 1; break;
} case KEY_HOME: p_sys->i_box_bidx = 0; break;
break; case KEY_UP: p_sys->i_box_bidx--; break;
case KEY_DOWN: p_sys->i_box_bidx++; break;
case KEY_PPAGE: p_sys->i_box_bidx -= p_sys->i_box_lines; break;
case KEY_NPAGE: p_sys->i_box_bidx += p_sys->i_box_lines; break;
default: default:
b_ret = false; return false;
break;
} }
if (b_ret)
if (p_sys->i_box_bidx >= p_sys->i_dir_entries)
p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
if (p_sys->i_box_bidx < 0)
p_sys->i_box_bidx = 0;
return true;
}
static int HandleKey(intf_thread_t *p_intf)
{
intf_sys_t *p_sys = p_intf->p_sys;
playlist_t *p_playlist = pl_Get(p_intf);
int i_key = wgetch(p_sys->w);
if (i_key == -1)
return 0;
if (p_sys->i_box_type == BOX_PLAYLIST)
{ {
if (p_sys->i_box_bidx >= p_sys->i_dir_entries) p_sys->i_box_bidx = p_sys->i_dir_entries - 1; if (HandlePlaylistKey(p_intf, i_key))
if (p_sys->i_box_bidx < 0) p_sys->i_box_bidx = 0;
return 1; return 1;
} }
else if (p_sys->i_box_type == BOX_BROWSE)
{
if (HandleBrowseKey(p_intf, i_key))
return 1;
} }
else if (p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO || else if (p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO ||
p_sys->i_box_type == BOX_META || p_sys->i_box_type == BOX_STATS || p_sys->i_box_type == BOX_META || p_sys->i_box_type == BOX_STATS ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment