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