* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
-/*
- * Note that when we use wide characters (and link with libncursesw),
- * we assume that an UTF8 locale is used (or compatible, such as ASCII).
- * Other characters encodings are not supported.
- */
+/* UTF8 locale is required */
/*****************************************************************************
* Preamble
input_thread_t *p_input;
bool b_color;
- bool b_color_started;
-
- float f_slider;
- float f_slider_old;
WINDOW *w;
static void start_color_and_pairs(intf_thread_t *p_intf)
{
- if (p_intf->p_sys->b_color_started)
- return;
-
- p_intf->p_sys->b_color_started = true;
-
if (!has_colors())
{
p_intf->p_sys->b_color = false;
/* untested, in all my terminals, !can_change_color() --funman */
if (can_change_color())
init_color(COLOR_YELLOW, 960, 500, 0); /* YELLOW -> ORANGE */
-
- p_intf->p_sys->b_color_started = true;
}
static void DrawBox(WINDOW *win, int y, int x, int h, int w, const char *title, bool b_color)
var_Get(p_input, "length", &val);
secstotimestr(buf2, val.i_time / CLOCK_FREQ);
- mvnprintw(y++, 0, COLS, _(" Position : %s/%s (%.2f%%)"), buf1, buf2, p_sys->f_slider);
+ mvnprintw(y++, 0, COLS, _(" Position : %s/%s"), buf1, buf2);
/* Volume */
aout_VolumeGet(p_playlist, &i_volume);
DrawBox(p_sys->w, y, 0, 3, COLS, "", p_sys->b_color);
DrawEmptyLine(p_sys->w, y+1, 1, COLS-2);
- DrawLine(p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)));
+
+ if (p_input && var_GetInteger(p_input, "state") == PLAYING_S)
+ {
+ float pos = var_GetFloat(p_input, "position");
+ DrawLine(p_sys->w, y+1, 1, (int)(pos * (COLS-2)));
+ }
+
y += 3;
p_sys->i_box_y = y + 1;
MainBoxWrite(p_intf, l++, 1, _(" B Show/Hide filebrowser"));
MainBoxWrite(p_intf, l++, 1, _(" x Show/Hide objects box"));
MainBoxWrite(p_intf, l++, 1, _(" S Show/Hide statistics box"));
- MainBoxWrite(p_intf, l++, 1, _(" c Switch color on/off"));
MainBoxWrite(p_intf, l++, 1, _(" Esc Close Add/Search entry"));
MainBoxWrite(p_intf, l++, 1, "");
if (p_sys->i_box_type == BOX_SEARCH)
{
DrawEmptyLine(p_sys->w, 7, 1, COLS-2);
- mvnprintw(7, 1, COLS-2, _("Find: %s"), *p_sys->psz_search_chain ?
- p_sys->psz_search_chain : p_sys->psz_old_search);
+ mvnprintw(7, 1, COLS-2, _("Find: %s"), p_sys->psz_old_search ?
+ p_sys->psz_old_search : p_sys->psz_search_chain);
}
if (p_sys->i_box_type == BOX_OPEN)
{
*t_last_refresh = time(0);
}
-static void ManageSlider(intf_thread_t *p_intf)
+static void ChangePosition(intf_thread_t *p_intf, float increment)
{
intf_sys_t *p_sys = p_intf->p_sys;
input_thread_t *p_input = p_sys->p_input;
if (!p_input || var_GetInteger(p_input, "state") != PLAYING_S)
return;
- pos = var_GetFloat(p_input, "position");
- if (p_sys->f_slider == p_sys->f_slider_old)
- p_sys->f_slider = p_sys->f_slider_old = 100. * pos;
- else
- {
- p_sys->f_slider_old = p_sys->f_slider;
+ pos = var_GetFloat(p_input, "position") + increment;
- pos = p_sys->f_slider / 100.;
- var_SetFloat(p_input, "position", pos);
- }
+ if (pos > 0.99) pos = 0.99;
+ if (pos < 0.0) pos = 0.0;
+
+ var_SetFloat(p_input, "position", pos);
}
static inline int RemoveLastUTF8Entity(char *psz, int len)
}
psz_name = playlist_CurrentPlayingItem(p_playlist)->p_input->psz_name;
-
- if (psz_name)
- psz_device = GetDiscDevice(p_intf, psz_name);
+ psz_device = psz_name ? GetDiscDevice(p_intf, psz_name) : NULL;
PL_UNLOCK;
p_sys->i_box_type = (p_sys->i_box_type == box) ? BOX_NONE : box;
}
-static int HandleKey(intf_thread_t *p_intf)
+static bool HandlePlaylistKey(intf_thread_t *p_intf, int key)
{
+ bool b_box_plidx_follow = false;
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;
+ struct pl_item_t *p_pl_item;
- if (p_sys->i_box_type == BOX_PLAYLIST)
+ switch(key)
{
- int b_ret = true;
- bool b_box_plidx_follow = false;
-
- switch(i_key)
- {
- /* Playlist Settings */
- case 'r':
- var_ToggleBool(p_playlist, "random");
- return 1;
- case 'l':
- var_ToggleBool(p_playlist, "loop");
- return 1;
- case 'R':
- var_ToggleBool(p_playlist, "repeat");
- return 1;
-
- /* Playlist sort */
- case 'o':
- 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),
- SORT_TITLE_NODES_FIRST, ORDER_REVERSE);
- p_sys->b_need_update = true;
- return 1;
-
- /* Playlist view */
- case 'v':
- p_sys->category_view = !p_sys->category_view;
- PlaylistRebuild(p_intf);
- return 1;
-
- /* Playlist navigation */
- case 'g':
- FindIndex(p_sys, p_playlist, false);
- break;
- case KEY_HOME:
- p_sys->i_box_plidx = 0;
- break;
+ /* Playlist Settings */
+ case 'r': var_ToggleBool(p_playlist, "random"); return true;
+ case 'l': var_ToggleBool(p_playlist, "loop"); return true;
+ case 'R': var_ToggleBool(p_playlist, "repeat"); return true;
+
+ /* Playlist sort */
+ case 'o':
+ case 'O':
+ playlist_RecursiveNodeSort(p_playlist, PlaylistGetRoot(p_intf),
+ SORT_TITLE_NODES_FIRST,
+ (key == 'o')? ORDER_NORMAL : ORDER_REVERSE);
+ p_sys->b_need_update = true;
+ return true;
+
+ /* Playlist view */
+ case 'v':
+ p_sys->category_view = !p_sys->category_view;
+ p_sys->b_need_update = true;
+ return true;
+
+ /* Playlist navigation */
#ifdef __FreeBSD__
/* workaround for FreeBSD + xterm:
* see http://www.nabble.com/curses-vs.-xterm-key-mismatch-t3574377.html */
- case KEY_SELECT:
+ case KEY_SELECT:
#endif
- case KEY_END:
- p_sys->i_box_plidx = p_playlist->items.i_size - 1;
- break;
- case KEY_UP:
- p_sys->i_box_plidx--;
- break;
- case KEY_DOWN:
- p_sys->i_box_plidx++;
- break;
- case KEY_PPAGE:
- p_sys->i_box_plidx -= p_sys->i_box_lines;
- break;
- case KEY_NPAGE:
- p_sys->i_box_plidx += p_sys->i_box_lines;
- break;
- case 'D':
- case KEY_BACKSPACE:
- case 0x7f:
- case KEY_DC:
- {
- playlist_item_t *p_item;
+ case KEY_END: p_sys->i_box_plidx = p_playlist->items.i_size - 1; break;
+ case KEY_HOME: p_sys->i_box_plidx = 0; break;
+ case KEY_UP: p_sys->i_box_plidx--; break;
+ case KEY_DOWN: p_sys->i_box_plidx++; break;
+ case KEY_PPAGE: p_sys->i_box_plidx -= p_sys->i_box_lines; break;
+ case KEY_NPAGE: p_sys->i_box_plidx += p_sys->i_box_lines; break;
+ case 'g': FindIndex(p_sys, p_playlist, false); break;
+
+ /* Deletion */
+ case 'D':
+ case KEY_BACKSPACE:
+ case 0x7f:
+ case KEY_DC:
+ {
+ playlist_item_t *p_item;
- 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);
- else
- playlist_NodeDelete(p_playlist, p_item, true , false);
- PL_UNLOCK;
- PlaylistRebuild(p_intf);
- break;
- }
+ 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);
+ else
+ playlist_NodeDelete(p_playlist, p_item, true , false);
+ PL_UNLOCK;
+ p_sys->b_need_update = true;
+ break;
+ }
- case KEY_ENTER:
- case '\r':
- case '\n':
- if (!p_sys->pp_plist[p_sys->i_box_plidx])
- {
- b_ret = false;
- break;
- }
- if (p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children == -1)
+ case KEY_ENTER:
+ case '\r':
+ case '\n':
+ if (!(p_pl_item = p_sys->pp_plist[p_sys->i_box_plidx]))
+ return false;
+
+ if (p_pl_item->p_item->i_children)
+ {
+ playlist_item_t *p_item, *p_parent = p_pl_item->p_item;
+ if (p_parent->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;
- 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);
- }
- 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;
}
else
{
- p_sys->p_node = p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
- playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked,
- p_sys->pp_plist[p_sys->i_box_plidx]->p_item, NULL);
+ p_sys->p_node = p_parent;
+ p_item = NULL;
}
- b_box_plidx_follow = true;
- break;
- default:
- b_ret = false;
- break;
+
+ playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked,
+ p_parent, p_item);
}
+ else
+ { /* We only want to set the current node */
+ playlist_Stop(p_playlist);
+ p_sys->p_node = p_pl_item->p_item;
+ }
+
+ b_box_plidx_follow = true;
+ break;
+
+ default:
+ return false;
+ }
+
+ if (p_sys->i_box_plidx > p_sys->i_plist_entries - 1)
+ p_sys->i_box_plidx = p_sys->i_plist_entries - 1;
+ if (p_sys->i_box_plidx < 0)
+ p_sys->i_box_plidx = 0;
+
+ p_pl_item = p_sys->pp_plist[p_sys->i_box_plidx];
+
+ PL_LOCK;
+ if (PlaylistIsPlaying(p_playlist, p_pl_item->p_item))
+ b_box_plidx_follow = true;
+ PL_UNLOCK;
+ p_sys->b_box_plidx_follow = b_box_plidx_follow;
+ return true;
+}
- if (b_ret)
+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;
+
+ switch(key)
+ {
+ case '.':
+ p_sys->b_show_hidden_files = !p_sys->b_show_hidden_files;
+ ReadDir(p_intf);
+ return true;
+
+ case KEY_ENTER:
+ case '\r':
+ case '\n':
+ case ' ':
+ dir_entry = p_sys->pp_dir_entries[p_sys->i_box_bidx];
+
+ if (!dir_entry->b_file && key != ' ')
{
- int i_max = p_sys->i_plist_entries;
- if (p_sys->i_box_plidx >= i_max) p_sys->i_box_plidx = i_max - 1;
- if (p_sys->i_box_plidx < 0) p_sys->i_box_plidx = 0;
+ 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;
+ if (asprintf(&psz_uri, "%s://%s/%s",
+ dir_entry->b_file ? "file" : "directory",
+ p_sys->psz_current_dir, dir_entry->psz_path) == -1)
+ {
+ return false;
+ }
+
+ playlist_t *p_playlist = pl_Get(p_intf);
+ playlist_item_t *p_parent = p_sys->p_node;
+ if (!p_parent)
+ {
+ playlist_item_t *p_item;
PL_LOCK;
- if (PlaylistIsPlaying(p_playlist,
- p_sys->pp_plist[p_sys->i_box_plidx]->p_item))
- b_box_plidx_follow = true;
+ p_item = playlist_CurrentPlayingItem(p_playlist);
+ p_parent = p_item ? p_item->p_parent : NULL;
PL_UNLOCK;
- p_sys->b_box_plidx_follow = b_box_plidx_follow;
- return 1;
+ if (!p_parent)
+ p_parent = p_playlist->p_local_onelevel;
}
- }
- else if (p_sys->i_box_type == BOX_BROWSE)
- {
- bool b_ret = true;
- /* Browser navigation */
- switch(i_key)
- {
- case KEY_HOME:
- p_sys->i_box_bidx = 0;
- break;
+
+ while (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_END, p_parent->p_input == p_input, false);
+
+ p_sys->i_box_type = BOX_PLAYLIST;
+ free(psz_uri);
+ return true;
+
#ifdef __FreeBSD__
- case KEY_SELECT:
+ 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;
- ReadDir(p_intf);
- break;
+ 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;
+ 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 KEY_ENTER:
- case '\r':
- case '\n':
- case ' ':
- if (p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file || i_key == ' ')
- {
- char* psz_uri;
- if (asprintf(&psz_uri, "%s://%s/%s",
- p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file ?
- "file" : "directory",
- p_sys->psz_current_dir,
- p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path
- ) == -1)
- {
- psz_uri = NULL;
- }
+ default:
+ return false;
+ }
- playlist_item_t *p_parent = p_sys->p_node;
- if (!p_parent)
- {
- playlist_item_t *p_item;
- PL_LOCK;
- p_item = playlist_CurrentPlayingItem(p_playlist);
- p_parent = p_item ? p_item->p_parent : NULL;
- PL_UNLOCK;
- if (!p_parent)
- p_parent = p_playlist->p_local_onelevel;
- }
+ 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;
- while (p_parent->p_parent && p_parent->p_parent->p_parent)
- p_parent = p_parent->p_parent;
+ return true;
+}
- playlist_Add(p_playlist, psz_uri, NULL, PLAYLIST_APPEND,
- PLAYLIST_END,
- p_parent->p_input ==
- p_playlist->p_local_onelevel->p_input
- , false);
+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);
- p_sys->i_box_type = BOX_PLAYLIST;
- free(psz_uri);
- }
- else
- {
- if (asprintf(&(p_sys->psz_current_dir), "%s/%s", p_sys->psz_current_dir,
- p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path) != -1)
- ReadDir(p_intf);
- }
- break;
- default:
- b_ret = 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;
+ if (i_key == -1)
+ return 0;
+
+ if (p_sys->i_box_type == BOX_PLAYLIST)
+ {
+ if (HandlePlaylistKey(p_intf, i_key))
+ 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 ||
p_sys->i_box_type == BOX_META || p_sys->i_box_type == BOX_STATS ||
if (p_sys->i_box_start >= p_sys->i_box_lines_total)
p_sys->i_box_start = p_sys->i_box_lines_total - 1;
return 1;
- default:
- break;
}
}
else if (p_sys->i_box_type == BOX_NONE)
switch(i_key)
{
case KEY_HOME:
- p_sys->f_slider = 0;
- ManageSlider(p_intf);
+ ChangePosition(p_intf, -1.0);
return 1;
#ifdef __FreeBSD__
case KEY_SELECT:
#endif
case KEY_END:
- p_sys->f_slider = 99.9;
- ManageSlider(p_intf);
+ ChangePosition(p_intf, .99);
return 1;
case KEY_UP:
- p_sys->f_slider += 5.0;
- if (p_sys->f_slider >= 99.0) p_sys->f_slider = 99.0;
- ManageSlider(p_intf);
+ ChangePosition(p_intf, 0.05);
return 1;
case KEY_DOWN:
- p_sys->f_slider -= 5.0;
- if (p_sys->f_slider < 0.0) p_sys->f_slider = 0.0;
- ManageSlider(p_intf);
+ ChangePosition(p_intf, -0.05);
return 1;
-
- default:
- break;
}
}
else if (p_sys->i_box_type == BOX_SEARCH)
case 'S':
BoxSwitch(p_sys, BOX_STATS);
break;
- case 'c':
- if ((p_sys->b_color = !p_sys->b_color))
- start_color_and_pairs(p_intf);
- break;
case 'h':
case 'H':
BoxSwitch(p_sys, BOX_HELP);
/* Navigation */
case KEY_RIGHT:
- p_sys->f_slider += 1.0;
- if (p_sys->f_slider > 99.9) p_sys->f_slider = 99.9;
- ManageSlider(p_intf);
+ ChangePosition(p_intf, 0.01);
break;
case KEY_LEFT:
- p_sys->f_slider -= 1.0;
- if (p_sys->f_slider < 0.0) p_sys->f_slider = 0.0;
- ManageSlider(p_intf);
+ ChangePosition(p_intf, -0.01);
break;
/* Common control */
{
vlc_object_release(p_sys->p_input);
p_sys->p_input = NULL;
- p_sys->f_slider = p_sys->f_slider_old = 0.0;
}
PL_LOCK;
}
if ((time(0) - t_last_refresh) >= 1)
- {
- ManageSlider(p_intf);
Redraw(p_intf, &t_last_refresh);
- }
}
var_DelCallback(p_playlist, "intf-change", PlaylistChanged, p_intf);
var_DelCallback(p_playlist, "playlist-item-append", PlaylistChanged, p_intf);