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

ncurses: cosmetics

align 'case' on the same level than 'switch'
use an inline function to switch boxes
parent 8a72c657
......@@ -1534,6 +1534,11 @@ static void PlayPause(intf_thread_t *p_intf)
playlist_Play(pl_Get(p_intf));
}
static inline void BoxSwitch(intf_sys_t *p_sys, int box)
{
p_sys->i_box_type = (p_sys->i_box_type == box) ? BOX_NONE : box;
}
static int HandleKey(intf_thread_t *p_intf)
{
intf_sys_t *p_sys = p_intf->p_sys;
......@@ -1563,14 +1568,12 @@ static int HandleKey(intf_thread_t *p_intf)
/* Playlist sort */
case 'o':
playlist_RecursiveNodeSort(p_playlist,
PlaylistGetRoot(p_intf),
playlist_RecursiveNodeSort(p_playlist, PlaylistGetRoot(p_intf),
SORT_TITLE_NODES_FIRST, ORDER_NORMAL);
p_sys->b_need_update = true;
return 1;
case 'O':
playlist_RecursiveNodeSort(p_playlist,
PlaylistGetRoot(p_intf),
playlist_RecursiveNodeSort(p_playlist, PlaylistGetRoot(p_intf),
SORT_TITLE_NODES_FIRST, ORDER_REVERSE);
p_sys->b_need_update = true;
return 1;
......@@ -1590,7 +1593,7 @@ static int HandleKey(intf_thread_t *p_intf)
break;
#ifdef __FreeBSD__
/* workaround for FreeBSD + xterm:
* see http://www.nabble.com/curses-vs.-xterm-key-mismatch-t3574377.html */
* see http://www.nabble.com/curses-vs.-xterm-key-mismatch-t3574377.html */
case KEY_SELECT:
#endif
case KEY_END:
......@@ -1618,8 +1621,7 @@ static int HandleKey(intf_thread_t *p_intf)
PL_LOCK;
p_item = p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
if (p_item->i_children == -1)
playlist_DeleteFromInput(p_playlist,
p_item->p_input, pl_Locked);
playlist_DeleteFromInput(p_playlist, p_item->p_input, pl_Locked);
else
playlist_NodeDelete(p_playlist, p_item, true , false);
PL_UNLOCK;
......@@ -1635,22 +1637,19 @@ static int HandleKey(intf_thread_t *p_intf)
b_ret = false;
break;
}
if (p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children
== -1)
if (p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children == -1)
{
playlist_item_t *p_item, *p_parent;
p_item = p_parent =
p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
p_item = p_parent = p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
if (!p_parent)
p_parent = p_playlist->p_root_onelevel;
while (p_parent->p_parent)
p_parent = p_parent->p_parent;
playlist_Control(p_playlist, PLAYLIST_VIEWPLAY,
pl_Unlocked, p_parent, p_item);
playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked,
p_parent, p_item);
}
else if (p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children
== 0)
else if (!p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children)
{ /* We only want to set the current node */
playlist_Stop(p_playlist);
p_sys->p_node = p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
......@@ -1711,8 +1710,7 @@ static int HandleKey(intf_thread_t *p_intf)
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 ==
true ? false : true);
p_sys->b_show_hidden_files = !p_sys->b_show_hidden_files;
ReadDir(p_intf);
break;
......@@ -1736,8 +1734,11 @@ static int HandleKey(intf_thread_t *p_intf)
playlist_item_t *p_parent = p_sys->p_node;
if (!p_parent)
{
playlist_item_t *p_item;
p_item = playlist_CurrentPlayingItem(p_playlist);
PL_LOCK;
p_parent = playlist_CurrentPlayingItem(p_playlist) ? playlist_CurrentPlayingItem(p_playlist)->p_parent : NULL;
p_parent = p_item ? p_item->p_parent : NULL;
PL_UNLOCK;
if (!p_parent)
p_parent = p_playlist->p_local_onelevel;
......@@ -1953,14 +1954,8 @@ static int HandleKey(intf_thread_t *p_intf)
RemoveLastUTF8Entity(p_sys->psz_open_chain, i_chain_len);
return 1;
default:
#ifndef HAVE_NCURSESW
{
#ifdef HAVE_NCURSESW
if (i_chain_len + 1 < OPEN_CHAIN_SIZE)
{
p_sys->psz_open_chain[i_chain_len] = (char) i_key;
p_sys->psz_open_chain[i_chain_len + 1] = '\0';
}
#else
char *psz_utf8 = KeyToUTF8(i_key, p_sys->psz_partial_keys);
if (psz_utf8)
......@@ -1969,8 +1964,14 @@ static int HandleKey(intf_thread_t *p_intf)
strcpy(p_sys->psz_open_chain + i_chain_len, psz_utf8);
free(psz_utf8);
}
#endif
}
#else
if (i_chain_len + 1 < OPEN_CHAIN_SIZE)
{
p_sys->psz_open_chain[i_chain_len] = (char) i_key;
p_sys->psz_open_chain[i_chain_len + 1] = '\0';
}
#endif
}
return 1;
}
......@@ -1982,6 +1983,7 @@ static int HandleKey(intf_thread_t *p_intf)
case 0x1b: /* ESC */
if (wgetch(p_sys->w) != ERR)
return 0;
case 'q':
case 'Q':
case KEY_EXIT:
......@@ -1990,50 +1992,29 @@ static int HandleKey(intf_thread_t *p_intf)
/* Box switching */
case 'i':
if (p_sys->i_box_type == BOX_INFO)
p_sys->i_box_type = BOX_NONE;
else
p_sys->i_box_type = BOX_INFO;
BoxSwitch(p_sys, BOX_INFO);
p_sys->i_box_lines_total = 0;
break;
case 'm':
if (p_sys->i_box_type == BOX_META)
p_sys->i_box_type = BOX_NONE;
else
p_sys->i_box_type = BOX_META;
BoxSwitch(p_sys, BOX_META);
p_sys->i_box_lines_total = 0;
break;
#if 0
case 'L':
if (p_sys->i_box_type == BOX_LOG)
p_sys->i_box_type = BOX_NONE;
else
p_sys->i_box_type = BOX_LOG;
BoxSwitch(p_sys, BOX_LOG)
break;
#endif
case 'P':
if (p_sys->i_box_type == BOX_PLAYLIST)
p_sys->i_box_type = BOX_NONE;
else
p_sys->i_box_type = BOX_PLAYLIST;
BoxSwitch(p_sys, BOX_PLAYLIST);
break;
case 'B':
if (p_sys->i_box_type == BOX_BROWSE)
p_sys->i_box_type = BOX_NONE;
else
p_sys->i_box_type = BOX_BROWSE;
BoxSwitch(p_sys, BOX_BROWSE);
break;
case 'x':
if (p_sys->i_box_type == BOX_OBJECTS)
p_sys->i_box_type = BOX_NONE;
else
p_sys->i_box_type = BOX_OBJECTS;
BoxSwitch(p_sys, BOX_OBJECTS);
break;
case 'S':
if (p_sys->i_box_type == BOX_STATS)
p_sys->i_box_type = BOX_NONE;
else
p_sys->i_box_type = BOX_STATS;
BoxSwitch(p_sys, BOX_STATS);
break;
case 'c':
p_sys->b_color = !p_sys->b_color;
......@@ -2042,10 +2023,7 @@ static int HandleKey(intf_thread_t *p_intf)
break;
case 'h':
case 'H':
if (p_sys->i_box_type == BOX_HELP)
p_sys->i_box_type = BOX_NONE;
else
p_sys->i_box_type = BOX_HELP;
BoxSwitch(p_sys, BOX_HELP);
p_sys->i_box_lines_total = 0;
break;
case '/':
......
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