1 /*****************************************************************************
2 * ncurses.c : NCurses interface for vlc
3 *****************************************************************************
4 * Copyright © 2001-2010 the VideoLAN team
7 * Authors: Sam Hocevar <sam@zoy.org>
8 * Laurent Aimar <fenrir@via.ecp.fr>
9 * Yoann Peronneau <yoann@videolan.org>
10 * Derk-Jan Hartman <hartman at videolan dot org>
11 * Rafaël Carré <funman@videolanorg>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
29 * Note that when we use wide characters (and link with libncursesw),
30 * we assume that an UTF8 locale is used (or compatible, such as ASCII).
31 * Other characters encodings are not supported.
34 /*****************************************************************************
36 *****************************************************************************/
41 #include <vlc_common.h>
42 #include <vlc_plugin.h>
45 # define _XOPEN_SOURCE_EXTENDED 1
51 #include <vlc_interface.h>
54 #include <vlc_charset.h>
55 #include <vlc_input.h>
57 #include <vlc_playlist.h>
63 #ifdef HAVE_SYS_STAT_H
64 # include <sys/stat.h>
67 #define SEARCH_CHAIN_SIZE 20
68 #define OPEN_CHAIN_SIZE 50
70 /*****************************************************************************
72 *****************************************************************************/
73 static int Open (vlc_object_t *);
74 static void Close (vlc_object_t *);
76 /*****************************************************************************
78 *****************************************************************************/
80 #define BROWSE_TEXT N_("Filebrowser starting point")
81 #define BROWSE_LONGTEXT N_(\
82 "This option allows you to specify the directory the ncurses filebrowser " \
83 "will show you initially.")
86 set_shortname("Ncurses")
87 set_description(N_("Ncurses interface"))
88 set_capability("interface", 10)
89 set_category(CAT_INTERFACE)
90 set_subcategory(SUBCAT_INTERFACE_MAIN)
91 set_callbacks(Open, Close)
92 add_shortcut("curses")
93 add_directory("browse-dir", NULL, BROWSE_TEXT, BROWSE_LONGTEXT, false)
96 /*****************************************************************************
97 * intf_sys_t: description and status of ncurses interface
98 *****************************************************************************/
131 /* XXX: new elements here ! */
136 /* Available colors: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE */
137 static const struct { short f; short b; } color_pairs[] =
139 /* element */ /* foreground*/ /* background*/
140 [C_TITLE] = { COLOR_YELLOW, COLOR_BLACK },
142 /* jamaican playlist */
143 [C_PLAYLIST_1] = { COLOR_GREEN, COLOR_BLACK },
144 [C_PLAYLIST_2] = { COLOR_YELLOW, COLOR_BLACK },
145 [C_PLAYLIST_3] = { COLOR_RED, COLOR_BLACK },
147 /* used in DrawBox() */
148 [C_BOX] = { COLOR_CYAN, COLOR_BLACK },
149 /* Source: State, Position, Volume, Chapters, etc...*/
150 [C_STATUS] = { COLOR_BLUE, COLOR_BLACK },
153 /* VLC messages, keep the order from highest priority to lowest */
154 [C_INFO] = { COLOR_BLACK, COLOR_WHITE },
155 [C_ERROR] = { COLOR_RED, COLOR_BLACK },
156 [C_WARNING] = { COLOR_YELLOW, COLOR_BLACK },
157 [C_DEBUG] = { COLOR_WHITE, COLOR_BLACK },
159 /* Category title: help, info, metadata */
160 [C_CATEGORY] = { COLOR_MAGENTA, COLOR_BLACK },
161 /* Folder (BOX_BROWSE) */
162 [C_FOLDER] = { COLOR_RED, COLOR_BLACK },
173 playlist_item_t *p_item;
179 input_thread_t *p_input;
180 playlist_t *p_playlist;
183 bool b_color_started;
193 int i_box_lines_total;
196 int i_box_plidx; /* Playlist index */
197 int b_box_plidx_follow;
198 int i_box_bidx; /* browser index */
200 playlist_item_t *p_node; /* current node */
204 msg_subscription_t* p_sub; /* message bank subscription */
206 char *psz_search_chain; /* for playlist searching */
207 char *psz_old_search; /* for searching next */
210 char *psz_open_chain;
211 #ifndef HAVE_NCURSESW
212 char psz_partial_keys[7];
215 char *psz_current_dir;
217 struct dir_entry_t **pp_dir_entries;
218 bool b_show_hidden_files;
221 struct pl_item_t **pp_plist;
223 bool b_need_update; /* for playlist view */
226 /*****************************************************************************
228 *****************************************************************************/
230 static void DirsDestroy(intf_sys_t *p_sys)
232 while (p_sys->i_dir_entries)
234 struct dir_entry_t *p_dir_entry;
235 p_dir_entry = p_sys->pp_dir_entries[--p_sys->i_dir_entries];
236 free(p_dir_entry->psz_path);
239 free(p_sys->pp_dir_entries);
240 p_sys->pp_dir_entries = NULL;
243 static int comp_dir_entries(const void *pp_dir_entry1, const void *pp_dir_entry2)
245 struct dir_entry_t *p_dir_entry1 = *(struct dir_entry_t**)pp_dir_entry1;
246 struct dir_entry_t *p_dir_entry2 = *(struct dir_entry_t**)pp_dir_entry2;
248 if (p_dir_entry1->b_file == p_dir_entry2->b_file)
249 return strcasecmp(p_dir_entry1->psz_path, p_dir_entry2->psz_path);
251 return p_dir_entry1->b_file ? 1 : -1;
254 static void ReadDir(intf_thread_t *p_intf)
256 intf_sys_t *p_sys = p_intf->p_sys;
259 if (!p_sys->psz_current_dir || !*p_sys->psz_current_dir)
261 msg_Dbg(p_intf, "no current dir set");
268 p_current_dir = vlc_opendir(p_sys->psz_current_dir);
272 /* something went bad, get out of here ! */
273 msg_Warn(p_intf, "cannot open directory `%s' (%m)",
274 p_sys->psz_current_dir);
278 /* Clean the old shit */
281 /* while we still have entries in the directory */
282 while ((psz_entry = vlc_readdir(p_current_dir)))
285 struct stat stat_data;
287 struct dir_entry_t *p_dir_entry;
288 char *psz_uri = NULL;
290 if (!p_sys->b_show_hidden_files)
291 if (*psz_entry == '.' && strcmp(psz_entry, ".."))
294 if (asprintf(&psz_uri, "%s/%s", p_sys->psz_current_dir, psz_entry) == -1)
300 if (!(p_dir_entry = malloc(sizeof *p_dir_entry)))
303 p_dir_entry->b_file =
305 vlc_stat(psz_uri, &stat_data) || !S_ISDIR(stat_data.st_mode)
306 /*#elif defined(DT_DIR)
307 !(p_dir_content->d_type & DT_DIR)*/
313 p_dir_entry->psz_path = strdup(psz_entry);
314 INSERT_ELEM(p_sys->pp_dir_entries, p_sys->i_dir_entries,
315 p_sys->i_dir_entries, p_dir_entry);
323 qsort(p_sys->pp_dir_entries, p_sys->i_dir_entries,
324 sizeof(struct dir_entry_t*), &comp_dir_entries);
326 closedir(p_current_dir);
329 /*****************************************************************************
331 *****************************************************************************/
333 static void PlaylistDestroy(intf_sys_t *p_sys)
335 while (p_sys->i_plist_entries)
337 struct pl_item_t *p_pl_item = p_sys->pp_plist[--p_sys->i_plist_entries];
338 free(p_pl_item->psz_display);
341 free(p_sys->pp_plist);
342 p_sys->pp_plist = NULL;
345 static inline playlist_item_t *PlaylistGetRoot(intf_thread_t *p_intf)
347 playlist_t *p_playlist = pl_Get(p_intf);
348 return p_intf->p_sys->category_view ?
349 p_playlist->p_root_category :
350 p_playlist->p_root_onelevel;
353 static bool PlaylistAddChild(intf_sys_t *p_sys, playlist_item_t *p_child,
354 const char *c, const char d)
357 char *psz_name = input_item_GetTitleFbName(p_child->p_input);
358 struct pl_item_t *p_pl_item = malloc(sizeof *p_pl_item);
360 if (!psz_name || !p_pl_item)
363 p_pl_item->p_item = p_child;
366 ret = asprintf(&p_pl_item->psz_display, "%s%c-%s", c, d, psz_name);
368 ret = asprintf(&p_pl_item->psz_display, " %s", psz_name);
376 INSERT_ELEM(p_sys->pp_plist, p_sys->i_plist_entries,
377 p_sys->i_plist_entries, p_pl_item);
387 static void PlaylistAddNode(intf_sys_t *p_sys, playlist_item_t *p_node,
390 for(int k = 0; k < p_node->i_children; k++)
392 playlist_item_t *p_child = p_node->pp_children[k];
393 char d = k == p_node->i_children - 1 ? '`' : '|';
394 if(!PlaylistAddChild(p_sys, p_child, c, d))
397 if (p_child->i_children <= 0)
403 if (asprintf(&psz_tmp, "%s%c ", c,
404 k == p_node->i_children - 1 ? ' ' : '|') == -1)
406 PlaylistAddNode(p_sys, p_child, psz_tmp);
410 PlaylistAddNode(p_sys, p_child, " ");
414 static void PlaylistRebuild(intf_thread_t *p_intf)
416 intf_sys_t *p_sys = p_intf->p_sys;
417 playlist_t *p_playlist = pl_Get(p_intf);
421 PlaylistDestroy(p_sys);
422 PlaylistAddNode(p_sys, PlaylistGetRoot(p_intf), "");
423 p_sys->b_need_update = false;
428 static int PlaylistChanged(vlc_object_t *p_this, const char *psz_variable,
429 vlc_value_t oval, vlc_value_t nval, void *param)
431 VLC_UNUSED(p_this); VLC_UNUSED(psz_variable);
432 VLC_UNUSED(oval); VLC_UNUSED(nval);
434 intf_thread_t *p_intf = (intf_thread_t *)param;
435 intf_sys_t *p_sys = p_intf->p_sys;
436 playlist_item_t *p_node = playlist_CurrentPlayingItem(pl_Get(p_intf));
438 p_sys->b_need_update = true;
439 p_sys->p_node = p_node ? p_node->p_parent : NULL;
445 /* This function have to be called with the playlist locked */
446 static inline bool PlaylistIsPlaying(playlist_t *p_playlist,
447 playlist_item_t *p_item)
449 playlist_item_t *p_played_item = playlist_CurrentPlayingItem(p_playlist);
450 return p_item && p_played_item
451 && p_item->p_input && p_played_item->p_input
452 && p_item->p_input->i_id == p_played_item->p_input->i_id;
455 static int SubSearchPlaylist(intf_sys_t *p_sys, char *psz_searchstring,
456 int i_start, int i_stop)
458 for(int i = i_start + 1; i < i_stop; i++)
459 if (strcasestr(p_sys->pp_plist[i]->psz_display, psz_searchstring))
465 static void SearchPlaylist(intf_sys_t *p_sys, char *psz_searchstring)
467 int i_item, i_first = p_sys->i_before_search;
472 if (!psz_searchstring || !*psz_searchstring)
474 p_sys->i_box_plidx = p_sys->i_before_search;
478 i_item = SubSearchPlaylist(p_sys, psz_searchstring, i_first + 1,
479 p_sys->i_plist_entries);
481 i_item = SubSearchPlaylist(p_sys, psz_searchstring, 0, i_first);
484 p_sys->i_box_plidx = i_item;
487 static inline bool IsIndex(intf_sys_t *p_sys, playlist_t *p_playlist, int i)
489 playlist_item_t *p_item = p_sys->pp_plist[i]->p_item;
490 return (p_item->i_children == 0 && p_item == p_sys->p_node) ||
491 PlaylistIsPlaying(p_playlist, p_item);
494 static void FindIndex(intf_sys_t *p_sys, playlist_t *p_playlist)
496 int plidx = p_sys->i_box_plidx;
499 if (plidx < 0 || plidx >= p_sys->i_plist_entries ||
500 !IsIndex(p_sys, p_playlist, plidx))
502 for(int i = 0; i < p_sys->i_plist_entries; i++)
503 if (IsIndex(p_sys, p_playlist, i))
505 p_sys->i_box_plidx = i;
513 /****************************************************************************
515 ****************************************************************************/
517 static void start_color_and_pairs(intf_thread_t *p_intf)
519 assert(p_intf->p_sys->b_color && !p_intf->p_sys->b_color_started);
523 p_intf->p_sys->b_color = false;
524 msg_Warn(p_intf, "Terminal doesn't support colors");
529 for(int i = C_DEFAULT + 1; i < C_MAX; i++)
530 init_pair(i, color_pairs[i].f, color_pairs[i].b);
532 /* untested, in all my terminals, !can_change_color() --funman */
533 if (can_change_color())
534 init_color(COLOR_YELLOW, 960, 500, 0); /* YELLOW -> ORANGE */
536 p_intf->p_sys->b_color_started = true;
539 static void DrawBox(WINDOW *win, int y, int x, int h, int w, const char *title, bool b_color)
547 wcolor_set(win, C_BOX, NULL);
548 if (!title) title = "";
549 i_len = strlen(title);
551 if (i_len > w - 2) i_len = w - 2;
553 mvwaddch(win, y, x, ACS_ULCORNER);
554 mvwhline(win, y, x+1, ACS_HLINE, (w-i_len-2)/2);
555 mvwprintw(win,y, x+1+(w-i_len-2)/2, "%s", title);
556 mvwhline(win, y, x+(w-i_len)/2+i_len, ACS_HLINE, w - 1 - ((w-i_len)/2+i_len));
557 mvwaddch(win, y, x+w-1,ACS_URCORNER);
559 for(i = 0; i < h-2; i++)
561 mvwaddch(win, y+i+1, x, ACS_VLINE);
562 mvwaddch(win, y+i+1, x+w-1, ACS_VLINE);
565 mvwaddch(win, y+h-1, x, ACS_LLCORNER);
566 mvwhline(win, y+h-1, x+1, ACS_HLINE, w - 2);
567 mvwaddch(win, y+h-1, x+w-1, ACS_LRCORNER);
569 wcolor_set(win, C_DEFAULT, NULL);
573 static void DrawEmptyLine(WINDOW *win, int y, int x, int w)
577 mvwhline(win, y, x, ' ', w);
580 static void DrawLine(WINDOW *win, int y, int x, int w)
585 mvwhline(win, y, x, ' ', w);
589 static void mvnprintw(int y, int x, int w, const char *p_fmt, ...)
598 va_start(vl_args, p_fmt);
599 if (vasprintf(&p_buf, p_fmt, vl_args) == -1)
603 i_len = strlen(p_buf);
606 wchar_t psz_wide[i_len + 1];
609 size_t i_char_len = mbstowcs(psz_wide, p_buf, i_len);
611 size_t i_width; /* number of columns */
613 if (i_char_len == (size_t)-1)
614 /* an invalid character was encountered */
621 i_width = wcswidth(psz_wide, i_char_len);
622 if (i_width == (size_t)-1)
624 /* a non printable character was encountered */
628 for(i = 0 ; i < i_char_len ; i++)
630 i_cwidth = wcwidth(psz_wide[i]);
636 if (i_width > (size_t)w)
638 int i_total_width = 0;
640 while (i_total_width < w)
642 i_total_width += wcwidth(psz_wide[i]);
643 if (w > 7 && i_total_width >= w/2)
647 i_total_width -= wcwidth(psz_wide[i]) - 2;
650 /* we require this check only if at least one character
651 * 4 or more columns wide exists (which i doubt) */
653 i_total_width -= wcwidth(psz_wide[i-1]) - 1;
656 /* find the widest string */
657 int j, i_2nd_width = 0;
658 for(j = i_char_len - 1; i_2nd_width < w - i_total_width; j--)
659 i_2nd_width += wcwidth(psz_wide[j]);
661 /* we already have i_total_width columns filled, and we can't
662 * have more than w columns */
663 if (i_2nd_width > w - i_total_width)
666 wmemmove(&psz_wide[i+2], &psz_wide[j+1], i_char_len - j - 1);
667 psz_wide[i + 2 + i_char_len - j - 1] = '\0';
672 if (w <= 7) /* we don't add the '...' else we lose too much chars */
675 size_t i_wlen = wcslen(psz_wide) * 6 + 1; /* worst case */
676 char psz_ellipsized[i_wlen];
677 wcstombs(psz_ellipsized, psz_wide, i_wlen);
678 mvprintw(y, x, "%s", psz_ellipsized);
682 mvprintw(y, x, "%s", p_buf);
683 mvhline(y, x + i_width, ' ', w - i_width);
689 int i_cut = i_len - w;
690 int x1 = i_len/2 - i_cut/2;
694 memmove(&p_buf[x1], &p_buf[x2], i_len - x2);
703 char *psz_local = ToLocale(p_buf);
704 mvprintw(y, x, "%s", psz_local);
709 char *psz_local = ToLocale(p_buf);
710 mvprintw(y, x, "%s", psz_local);
712 mvhline(y, x + i_len, ' ', w - i_len);
718 static void MainBoxWrite(intf_thread_t *p_intf, int l, int x, const char *p_fmt, ...)
720 intf_sys_t *p_sys = p_intf->p_sys;
725 if (l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines)
728 va_start(vl_args, p_fmt);
729 if (vasprintf(&p_buf, p_fmt, vl_args) == -1)
733 mvnprintw(p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf);
737 static void DumpObject(intf_thread_t *p_intf, int *l, vlc_object_t *p_obj, int i_level)
739 char *psz_name = vlc_object_get_name(p_obj);
742 MainBoxWrite(p_intf, (*l)++, 1 + 2 * i_level, "%s \"%s\" (%p)",
743 p_obj->psz_object_type, psz_name, p_obj);
747 MainBoxWrite(p_intf, (*l)++, 1 + 2 * i_level, "%s (%o)",
748 p_obj->psz_object_type, p_obj);
750 vlc_list_t *list = vlc_list_children(p_obj);
751 for(int i = 0; i < list->i_count ; i++)
753 MainBoxWrite(p_intf, *l, 1 + 2 * i_level,
754 i == list->i_count - 1 ? "`-" : "|-");
755 DumpObject(p_intf, l, list->p_values[i].p_object, i_level + 1);
757 vlc_list_release(list);
760 static void Redraw(intf_thread_t *p_intf, time_t *t_last_refresh)
762 intf_sys_t *p_sys = p_intf->p_sys;
763 input_thread_t *p_input = p_sys->p_input;
764 playlist_t *p_playlist = pl_Get(p_intf);
771 int i_len = strlen("VLC media player "PACKAGE_VERSION);
772 int mid = (COLS - i_len) / 2;
775 int i_size = (COLS > i_len + 1) ? COLS : i_len + 1;
776 char psz_title[i_size];
777 memset(psz_title, ' ', mid);
779 wcolor_set(p_sys->w, C_TITLE, NULL);
780 strlcpy(&psz_title[mid], "VLC media player "PACKAGE_VERSION, i_size);
781 mvnprintw(y, 0, COLS, "%s", psz_title);
786 wcolor_set(p_sys->w, C_STATUS, NULL);
790 if (asprintf(&psz_state, "%s%s%s",
791 var_GetBool(p_playlist, "repeat") ? _("[Repeat] ") : "",
792 var_GetBool(p_playlist, "random") ? _("[Random] ") : "",
793 var_GetBool(p_playlist, "loop") ? _("[Loop]") : "") == -1)
796 if (p_input && !p_input->b_dead)
798 char buf1[MSTRTIME_MAX_SIZE];
799 char buf2[MSTRTIME_MAX_SIZE];
803 char *psz_uri = input_item_GetURI(input_GetItem(p_input));
804 mvnprintw(y++, 0, COLS, _(" Source : %s"), psz_uri);
808 var_Get(p_input, "state", &val);
809 if (val.i_int == PLAYING_S)
810 mvnprintw(y++, 0, COLS, _(" State : Playing %s"), psz_state);
811 else if (val.i_int == OPENING_S)
812 mvnprintw(y++, 0, COLS, _(" State : Opening/Connecting %s"), psz_state);
813 else if (val.i_int == PAUSE_S)
814 mvnprintw(y++, 0, COLS, _(" State : Paused %s"), psz_state);
816 if (val.i_int != INIT_S && val.i_int != END_S)
818 audio_volume_t i_volume;
821 var_Get(p_input, "time", &val);
822 secstotimestr(buf1, val.i_time / CLOCK_FREQ);
824 var_Get(p_input, "length", &val);
825 secstotimestr(buf2, val.i_time / CLOCK_FREQ);
827 mvnprintw(y++, 0, COLS, _(" Position : %s/%s (%.2f%%)"), buf1, buf2, p_sys->f_slider);
830 aout_VolumeGet(p_playlist, &i_volume);
831 mvnprintw(y++, 0, COLS, _(" Volume : %i%%"), i_volume*200/AOUT_VOLUME_MAX);
834 if (!var_Get(p_input, "title", &val))
836 int i_title_count = var_CountChoices(p_input, "title");
837 if (i_title_count > 0)
838 mvnprintw(y++, 0, COLS, _(" Title : %"PRId64"/%d"),
839 val.i_int, i_title_count);
843 if (!var_Get(p_input, "chapter", &val))
845 int i_chapter_count = var_CountChoices(p_input, "chapter");
846 if (i_chapter_count > 0)
847 mvnprintw(y++, 0, COLS, _(" Chapter : %"PRId64"/%d"),
848 val.i_int, i_chapter_count);
858 mvnprintw(y++, 0, COLS, _(" Source: <no current item> %s"), psz_state);
859 DrawEmptyLine(p_sys->w, y++, 0, COLS);
860 mvnprintw(y++, 0, COLS, _(" [ h for help ]"));
861 DrawEmptyLine(p_sys->w, y++, 0, COLS);
865 wcolor_set(p_sys->w, C_DEFAULT, NULL);
867 DrawBox(p_sys->w, y, 0, 3, COLS, "", p_sys->b_color);
868 DrawEmptyLine(p_sys->w, y+1, 1, COLS-2);
869 DrawLine(p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)));
872 p_sys->i_box_y = y + 1;
873 p_sys->i_box_lines = LINES - y - 2;
878 if (p_sys->i_box_type == BOX_HELP)
882 DrawBox(p_sys->w, y++, 0, h, COLS, _(" Help "), p_sys->b_color);
885 wcolor_set(p_sys->w, C_CATEGORY, NULL);
886 MainBoxWrite(p_intf, l++, 1, _("[Display]"));
888 wcolor_set(p_sys->w, C_DEFAULT, NULL);
889 MainBoxWrite(p_intf, l++, 1, _(" h,H Show/Hide help box"));
890 MainBoxWrite(p_intf, l++, 1, _(" i Show/Hide info box"));
891 MainBoxWrite(p_intf, l++, 1, _(" m Show/Hide metadata box"));
892 MainBoxWrite(p_intf, l++, 1, _(" L Show/Hide messages box"));
893 MainBoxWrite(p_intf, l++, 1, _(" P Show/Hide playlist box"));
894 MainBoxWrite(p_intf, l++, 1, _(" B Show/Hide filebrowser"));
895 MainBoxWrite(p_intf, l++, 1, _(" x Show/Hide objects box"));
896 MainBoxWrite(p_intf, l++, 1, _(" S Show/Hide statistics box"));
897 MainBoxWrite(p_intf, l++, 1, _(" c Switch color on/off"));
898 MainBoxWrite(p_intf, l++, 1, _(" Esc Close Add/Search entry"));
899 MainBoxWrite(p_intf, l++, 1, "");
902 wcolor_set(p_sys->w, C_CATEGORY, NULL);
903 MainBoxWrite(p_intf, l++, 1, _("[Global]"));
905 wcolor_set(p_sys->w, C_DEFAULT, NULL);
906 MainBoxWrite(p_intf, l++, 1, _(" q, Q, Esc Quit"));
907 MainBoxWrite(p_intf, l++, 1, _(" s Stop"));
908 MainBoxWrite(p_intf, l++, 1, _(" <space> Pause/Play"));
909 MainBoxWrite(p_intf, l++, 1, _(" f Toggle Fullscreen"));
910 MainBoxWrite(p_intf, l++, 1, _(" n, p Next/Previous playlist item"));
911 MainBoxWrite(p_intf, l++, 1, _(" [, ] Next/Previous title"));
912 MainBoxWrite(p_intf, l++, 1, _(" <, > Next/Previous chapter"));
913 MainBoxWrite(p_intf, l++, 1, _(" <right> Seek +1%%"));
914 MainBoxWrite(p_intf, l++, 1, _(" <left> Seek -1%%"));
915 MainBoxWrite(p_intf, l++, 1, _(" a Volume Up"));
916 MainBoxWrite(p_intf, l++, 1, _(" z Volume Down"));
917 MainBoxWrite(p_intf, l++, 1, "");
920 wcolor_set(p_sys->w, C_CATEGORY, NULL);
921 MainBoxWrite(p_intf, l++, 1, _("[Playlist]"));
923 wcolor_set(p_sys->w, C_DEFAULT, NULL);
924 MainBoxWrite(p_intf, l++, 1, _(" r Toggle Random playing"));
925 MainBoxWrite(p_intf, l++, 1, _(" l Toggle Loop Playlist"));
926 MainBoxWrite(p_intf, l++, 1, _(" R Toggle Repeat item"));
927 MainBoxWrite(p_intf, l++, 1, _(" o Order Playlist by title"));
928 MainBoxWrite(p_intf, l++, 1, _(" O Reverse order Playlist by title"));
929 MainBoxWrite(p_intf, l++, 1, _(" g Go to the current playing item"));
930 MainBoxWrite(p_intf, l++, 1, _(" / Look for an item"));
931 MainBoxWrite(p_intf, l++, 1, _(" A Add an entry"));
932 MainBoxWrite(p_intf, l++, 1, _(" D, <del> Delete an entry"));
933 MainBoxWrite(p_intf, l++, 1, _(" <backspace> Delete an entry"));
934 MainBoxWrite(p_intf, l++, 1, _(" e Eject (if stopped)"));
935 MainBoxWrite(p_intf, l++, 1, "");
938 wcolor_set(p_sys->w, C_CATEGORY, NULL);
939 MainBoxWrite(p_intf, l++, 1, _("[Filebrowser]"));
941 wcolor_set(p_sys->w, C_DEFAULT, NULL);
942 MainBoxWrite(p_intf, l++, 1, _(" <enter> Add the selected file to the playlist"));
943 MainBoxWrite(p_intf, l++, 1, _(" <space> Add the selected directory to the playlist"));
944 MainBoxWrite(p_intf, l++, 1, _(" . Show/Hide hidden files"));
945 MainBoxWrite(p_intf, l++, 1, "");
948 wcolor_set(p_sys->w, C_CATEGORY, NULL);
949 MainBoxWrite(p_intf, l++, 1, _("[Boxes]"));
951 wcolor_set(p_sys->w, C_DEFAULT, NULL);
952 MainBoxWrite(p_intf, l++, 1, _(" <up>,<down> Navigate through the box line by line"));
953 MainBoxWrite(p_intf, l++, 1, _(" <pgup>,<pgdown> Navigate through the box page by page"));
954 MainBoxWrite(p_intf, l++, 1, "");
957 wcolor_set(p_sys->w, C_CATEGORY, NULL);
958 MainBoxWrite(p_intf, l++, 1, _("[Player]"));
960 wcolor_set(p_sys->w, C_DEFAULT, NULL);
961 MainBoxWrite(p_intf, l++, 1, _(" <up>,<down> Seek +/-5%%"));
962 MainBoxWrite(p_intf, l++, 1, "");
965 wcolor_set(p_sys->w, C_CATEGORY, NULL);
966 MainBoxWrite(p_intf, l++, 1, _("[Miscellaneous]"));
968 wcolor_set(p_sys->w, C_DEFAULT, NULL);
969 MainBoxWrite(p_intf, l++, 1, _(" Ctrl-l Refresh the screen"));
971 p_sys->i_box_lines_total = l;
972 if (p_sys->i_box_start >= p_sys->i_box_lines_total)
973 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
975 if (l - p_sys->i_box_start < p_sys->i_box_lines)
976 y += l - p_sys->i_box_start;
978 y += p_sys->i_box_lines;
980 else if (p_sys->i_box_type == BOX_INFO)
984 DrawBox(p_sys->w, y++, 0, h, COLS, _(" Information "), p_sys->b_color);
989 vlc_mutex_lock(&input_GetItem(p_input)->lock);
990 for(i = 0; i < input_GetItem(p_input)->i_categories; i++)
992 info_category_t *p_category = input_GetItem(p_input)->pp_categories[i];
993 if (y >= y_end) break;
995 wcolor_set(p_sys->w, C_CATEGORY, NULL);
996 MainBoxWrite(p_intf, l++, 1, _(" [%s]"), p_category->psz_name);
998 wcolor_set(p_sys->w, C_DEFAULT, NULL);
999 for(j = 0; j < p_category->i_infos; j++)
1001 info_t *p_info = p_category->pp_infos[j];
1002 if (y >= y_end) break;
1003 MainBoxWrite(p_intf, l++, 1, _(" %s: %s"), p_info->psz_name, p_info->psz_value);
1006 vlc_mutex_unlock(&input_GetItem(p_input)->lock);
1009 MainBoxWrite(p_intf, l++, 1, _("No item currently playing"));
1011 p_sys->i_box_lines_total = l;
1012 if (p_sys->i_box_start >= p_sys->i_box_lines_total)
1013 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1015 if (l - p_sys->i_box_start < p_sys->i_box_lines)
1016 y += l - p_sys->i_box_start;
1018 y += p_sys->i_box_lines;
1020 else if (p_sys->i_box_type == BOX_META)
1025 DrawBox(p_sys->w, y++, 0, h, COLS, _("Meta-information"),
1031 input_item_t *p_item = input_GetItem(p_input);
1032 vlc_mutex_lock(&p_item->lock);
1033 for(i=0; i<VLC_META_TYPE_COUNT; i++)
1035 if (y >= y_end) break;
1036 const char *psz_meta = vlc_meta_Get(p_item->p_meta, i);
1037 if (psz_meta && *psz_meta)
1039 const char *psz_meta_title;
1043 psz_meta_title = VLC_META_TITLE; break;
1045 psz_meta_title = VLC_META_ARTIST; break;
1047 psz_meta_title = VLC_META_GENRE ; break;
1049 psz_meta_title = VLC_META_COPYRIGHT; break;
1051 psz_meta_title = VLC_META_ALBUM; break;
1053 psz_meta_title = VLC_META_TRACK_NUMBER; break;
1055 psz_meta_title = VLC_META_DESCRIPTION; break;
1057 psz_meta_title = VLC_META_RATING; break;
1059 psz_meta_title = VLC_META_DATE; break;
1061 psz_meta_title = VLC_META_SETTING; break;
1063 psz_meta_title = VLC_META_URL; break;
1065 psz_meta_title = VLC_META_LANGUAGE; break;
1067 psz_meta_title = VLC_META_NOW_PLAYING; break;
1069 psz_meta_title = VLC_META_PUBLISHER; break;
1071 psz_meta_title = VLC_META_ENCODED_BY; break;
1073 psz_meta_title = VLC_META_ART_URL; break;
1075 psz_meta_title = VLC_META_TRACKID; break;
1077 psz_meta_title = ""; break;
1080 wcolor_set(p_sys->w, C_CATEGORY, NULL);
1081 MainBoxWrite(p_intf, l++, 1, " [%s]", psz_meta_title);
1083 wcolor_set(p_sys->w, C_DEFAULT, NULL);
1084 MainBoxWrite(p_intf, l++, 1, " %s", psz_meta);
1087 vlc_mutex_unlock(&p_item->lock);
1090 MainBoxWrite(p_intf, l++, 1, _("No item currently playing"));
1092 p_sys->i_box_lines_total = l;
1093 if (p_sys->i_box_start >= p_sys->i_box_lines_total)
1094 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1096 if (l - p_sys->i_box_start < p_sys->i_box_lines)
1097 y += l - p_sys->i_box_start;
1099 y += p_sys->i_box_lines;
1101 else if (p_sys->i_box_type == BOX_LOG)
1103 #warning Deprecated API
1109 DrawBox(p_sys->w, y++, 0, h, COLS, _(" Logs "), p_sys->b_color);
1112 i_start = p_intf->p_sys->p_sub->i_start;
1114 vlc_mutex_lock(p_intf->p_sys->p_sub->p_lock);
1115 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1116 vlc_mutex_unlock(p_intf->p_sys->p_sub->p_lock);
1120 static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
1121 if (i_line >= h - 2)
1127 if (i_stop < 0) i_stop += VLC_MSG_QSIZE;
1128 if (i_stop == i_start)
1133 wcolor_set(p_sys->w,
1134 p_sys->p_sub->p_msg[i_stop].i_type + C_INFO,
1136 mvnprintw(y + h-2-i_line, 1, COLS - 2, " [%s] %s",
1137 ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
1138 p_sys->p_sub->p_msg[i_stop].psz_msg);
1140 wcolor_set(p_sys->w, C_DEFAULT, NULL);
1143 vlc_mutex_lock(p_intf->p_sys->p_sub->p_lock);
1144 p_intf->p_sys->p_sub->i_start = i_stop;
1145 vlc_mutex_unlock(p_intf->p_sys->p_sub->p_lock);
1149 else if (p_sys->i_box_type == BOX_BROWSE)
1151 /* Filebrowser box */
1152 int i_start, i_stop;
1154 DrawBox(p_sys->w, y++, 0, h, COLS, _(" Browse "), p_sys->b_color);
1156 if (p_sys->i_box_bidx >= p_sys->i_dir_entries) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
1157 if (p_sys->i_box_bidx < 0) p_sys->i_box_bidx = 0;
1159 if (p_sys->i_box_bidx < (h - 2)/2)
1164 else if (p_sys->i_dir_entries - p_sys->i_box_bidx > (h - 2)/2)
1166 i_start = p_sys->i_box_bidx - (h - 2)/2;
1167 i_stop = i_start + h - 2;
1171 i_stop = p_sys->i_dir_entries;
1172 i_start = p_sys->i_dir_entries - (h - 2);
1176 if (i_stop > p_sys->i_dir_entries)
1177 i_stop = p_sys->i_dir_entries;
1179 for(i_item = i_start; i_item < i_stop; i_item++)
1181 bool b_selected = (p_sys->i_box_bidx == i_item);
1183 if (y >= y_end) break;
1186 if (p_sys->b_color && !p_sys->pp_dir_entries[i_item]->b_file)
1187 wcolor_set(p_sys->w, C_FOLDER, NULL);
1188 mvnprintw(y++, 1, COLS - 2, " %c %s", p_sys->pp_dir_entries[i_item]->b_file == true ? ' ' : '+',
1189 p_sys->pp_dir_entries[i_item]->psz_path);
1190 if (p_sys->b_color && !p_sys->pp_dir_entries[i_item]->b_file)
1191 wcolor_set(p_sys->w, C_DEFAULT, NULL);
1198 else if (p_sys->i_box_type == BOX_OBJECTS)
1201 DrawBox(p_sys->w, y++, 0, h, COLS, _(" Objects "), p_sys->b_color);
1202 DumpObject(p_intf, &l, VLC_OBJECT(p_intf->p_libvlc), 0);
1204 p_sys->i_box_lines_total = l;
1205 if (p_sys->i_box_start >= p_sys->i_box_lines_total)
1206 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1208 if (l - p_sys->i_box_start < p_sys->i_box_lines)
1209 y += l - p_sys->i_box_start;
1211 y += p_sys->i_box_lines;
1213 else if (p_sys->i_box_type == BOX_STATS)
1215 DrawBox(p_sys->w, y++, 0, h, COLS, _(" Stats "), p_sys->b_color);
1219 input_item_t *p_item = input_GetItem(p_input);
1221 vlc_mutex_lock(&p_item->lock);
1222 vlc_mutex_lock(&p_item->p_stats->lock);
1229 i_video = i_audio = 1;
1231 for(i = 0; i < p_item->i_es ; i++)
1233 i_audio += (p_item->es[i]->i_cat == AUDIO_ES);
1234 i_video += (p_item->es[i]->i_cat == VIDEO_ES);
1239 #define SHOW_ACS(x,c) \
1240 if (l >= p_sys->i_box_start && l - p_sys->i_box_start < p_sys->i_box_lines) \
1241 mvaddch(p_sys->i_box_y - p_sys->i_box_start + l, x, c)
1244 if (p_sys->b_color) wcolor_set(p_sys->w, C_CATEGORY, NULL);
1245 MainBoxWrite(p_intf, l, 1, _("+-[Incoming]"));
1246 SHOW_ACS(1, ACS_ULCORNER); SHOW_ACS(2, ACS_HLINE); l++;
1247 if (p_sys->b_color) wcolor_set(p_sys->w, C_DEFAULT, NULL);
1248 MainBoxWrite(p_intf, l, 1, _("| input bytes read : %8.0f KiB"),
1249 (float)(p_item->p_stats->i_read_bytes)/1024);
1250 SHOW_ACS(1, ACS_VLINE); l++;
1251 MainBoxWrite(p_intf, l, 1, _("| input bitrate : %6.0f kb/s"),
1252 (float)(p_item->p_stats->f_input_bitrate)*8000);
1253 MainBoxWrite(p_intf, l, 1, _("| demux bytes read : %8.0f KiB"),
1254 (float)(p_item->p_stats->i_demux_read_bytes)/1024);
1255 SHOW_ACS(1, ACS_VLINE); l++;
1256 MainBoxWrite(p_intf, l, 1, _("| demux bitrate : %6.0f kb/s"),
1257 (float)(p_item->p_stats->f_demux_bitrate)*8000);
1258 SHOW_ACS(1, ACS_VLINE); l++;
1259 DrawEmptyLine(p_sys->w, p_sys->i_box_y + l - p_sys->i_box_start, 1, COLS - 2);
1260 SHOW_ACS(1, ACS_VLINE); l++;
1265 if (p_sys->b_color) wcolor_set(p_sys->w, C_CATEGORY, NULL);
1266 MainBoxWrite(p_intf, l, 1, _("+-[Video Decoding]"));
1267 SHOW_ACS(1, ACS_LTEE); SHOW_ACS(2, ACS_HLINE); l++;
1268 if (p_sys->b_color) wcolor_set(p_sys->w, C_DEFAULT, NULL);
1269 MainBoxWrite(p_intf, l, 1, _("| video decoded : %"PRId64),
1270 p_item->p_stats->i_decoded_video);
1271 SHOW_ACS(1, ACS_VLINE); l++;
1272 MainBoxWrite(p_intf, l, 1, _("| frames displayed : %"PRId64),
1273 p_item->p_stats->i_displayed_pictures);
1274 SHOW_ACS(1, ACS_VLINE); l++;
1275 MainBoxWrite(p_intf, l, 1, _("| frames lost : %"PRId64),
1276 p_item->p_stats->i_lost_pictures);
1277 SHOW_ACS(1, ACS_VLINE); l++;
1278 DrawEmptyLine(p_sys->w, p_sys->i_box_y + l - p_sys->i_box_start, 1, COLS - 2);
1279 SHOW_ACS(1, ACS_VLINE); l++;
1284 if (p_sys->b_color) wcolor_set(p_sys->w, C_CATEGORY, NULL);
1285 MainBoxWrite(p_intf, l, 1, _("+-[Audio Decoding]"));
1286 SHOW_ACS(1, ACS_LTEE); SHOW_ACS(2, ACS_HLINE); l++;
1287 if (p_sys->b_color) wcolor_set(p_sys->w, C_DEFAULT, NULL);
1288 MainBoxWrite(p_intf, l, 1, _("| audio decoded : %"PRId64),
1289 p_item->p_stats->i_decoded_audio);
1290 SHOW_ACS(1, ACS_VLINE); l++;
1291 MainBoxWrite(p_intf, l, 1, _("| buffers played : %"PRId64),
1292 p_item->p_stats->i_played_abuffers);
1293 SHOW_ACS(1, ACS_VLINE); l++;
1294 MainBoxWrite(p_intf, l, 1, _("| buffers lost : %"PRId64),
1295 p_item->p_stats->i_lost_abuffers);
1296 SHOW_ACS(1, ACS_VLINE); l++;
1297 DrawEmptyLine(p_sys->w, p_sys->i_box_y + l - p_sys->i_box_start, 1, COLS - 2);
1298 SHOW_ACS(1, ACS_VLINE); l++;
1301 if (p_sys->b_color) wcolor_set(p_sys->w, C_CATEGORY, NULL);
1302 MainBoxWrite(p_intf, l, 1, _("+-[Streaming]"));
1303 SHOW_ACS(1, ACS_LTEE); SHOW_ACS(2, ACS_HLINE); l++;
1304 if (p_sys->b_color) wcolor_set(p_sys->w, C_DEFAULT, NULL);
1305 MainBoxWrite(p_intf, l, 1, _("| packets sent : %5i"), p_item->p_stats->i_sent_packets);
1306 SHOW_ACS(1, ACS_VLINE); l++;
1307 MainBoxWrite(p_intf, l, 1, _("| bytes sent : %8.0f KiB"),
1308 (float)(p_item->p_stats->i_sent_bytes)/1024);
1309 SHOW_ACS(1, ACS_VLINE); l++;
1310 MainBoxWrite(p_intf, l, 1, _("\\ sending bitrate : %6.0f kb/s"),
1311 (float)(p_item->p_stats->f_send_bitrate*8)*1000);
1312 SHOW_ACS(1, ACS_LLCORNER); l++;
1313 if (p_sys->b_color) wcolor_set(p_sys->w, C_DEFAULT, NULL);
1317 p_sys->i_box_lines_total = l;
1318 if (p_sys->i_box_start >= p_sys->i_box_lines_total)
1319 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1321 if (l - p_sys->i_box_start < p_sys->i_box_lines)
1322 y += l - p_sys->i_box_start;
1324 y += p_sys->i_box_lines;
1326 vlc_mutex_unlock(&p_item->p_stats->lock);
1327 vlc_mutex_unlock(&p_item->lock);
1331 else if (p_sys->i_box_type == BOX_PLAYLIST ||
1332 p_sys->i_box_type == BOX_SEARCH ||
1333 p_sys->i_box_type == BOX_OPEN )
1336 int i_start, i_stop, i_max = p_sys->i_plist_entries;
1340 if (p_sys->category_view)
1341 psz_title = strdup(_(" Playlist (By category) "));
1343 psz_title = strdup(_(" Playlist (All, one level) "));
1345 DrawBox(p_sys->w, y++, 0, h, COLS, psz_title, p_sys->b_color);
1348 if (p_sys->b_need_update || !p_sys->pp_plist)
1349 PlaylistRebuild(p_intf);
1350 if (p_sys->b_box_plidx_follow)
1351 FindIndex(p_sys, p_playlist);
1353 if (p_sys->i_box_plidx < 0) p_sys->i_box_plidx = 0;
1354 if (p_sys->i_box_plidx < 0) p_sys->i_box_plidx = 0;
1355 if (p_sys->i_box_plidx >= i_max) p_sys->i_box_plidx = i_max - 1;
1357 if (p_sys->i_box_plidx < (h - 2)/2)
1362 else if (i_max - p_sys->i_box_plidx > (h - 2)/2)
1364 i_start = p_sys->i_box_plidx - (h - 2)/2;
1365 i_stop = i_start + h - 2;
1370 i_start = i_max - (h - 2);
1377 for(i_item = i_start; i_item < i_stop; i_item++)
1379 bool b_selected = (p_sys->i_box_plidx == i_item);
1380 playlist_item_t *p_item = p_sys->pp_plist[i_item]->p_item;
1381 playlist_item_t *p_node = p_sys->p_node;
1383 input_thread_t *p_input2 = playlist_CurrentInput(p_playlist);
1387 playlist_item_t *p_current_playing_item = playlist_CurrentPlayingItem(p_playlist);
1388 if ((p_node && p_item->p_input == p_node->p_input) ||
1389 (!p_node && p_input2 && p_current_playing_item &&
1390 p_item->p_input == p_current_playing_item->p_input))
1392 else if (p_item == p_node || (p_item != p_node &&
1393 PlaylistIsPlaying(p_playlist, p_item)))
1398 vlc_object_release(p_input2);
1400 if (y >= y_end) break;
1404 wcolor_set(p_sys->w, i_item % 3 + C_PLAYLIST_1, NULL);
1405 mvnprintw(y++, 1, COLS - 2, "%c%s", c,
1406 p_sys->pp_plist[i_item]->psz_display);
1408 wcolor_set(p_sys->w, C_DEFAULT, NULL);
1417 if (p_sys->i_box_type == BOX_SEARCH)
1419 DrawEmptyLine(p_sys->w, 7, 1, COLS-2);
1420 if (p_sys->psz_search_chain)
1422 if (*p_sys->psz_search_chain == '\0' && p_sys->psz_old_search)
1423 /* Searching next entry */
1424 mvnprintw(7, 1, COLS-2, _("Find: %s"), p_sys->psz_old_search);
1426 mvnprintw(7, 1, COLS-2, _("Find: %s"), p_sys->psz_search_chain);
1429 if (p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain)
1431 DrawEmptyLine(p_sys->w, 7, 1, COLS-2);
1432 mvnprintw(7, 1, COLS-2, _("Open: %s"), p_sys->psz_open_chain);
1436 DrawEmptyLine(p_sys->w, y++, 1, COLS - 2);
1440 *t_last_refresh = time(0);
1443 static void ManageSlider(intf_thread_t *p_intf)
1445 intf_sys_t *p_sys = p_intf->p_sys;
1446 input_thread_t *p_input = p_sys->p_input;
1451 var_Get(p_input, "state", &val);
1452 if (val.i_int != PLAYING_S)
1455 var_Get(p_input, "position", &val);
1456 if (p_sys->f_slider == p_sys->f_slider_old)
1457 p_sys->f_slider = p_sys->f_slider_old = 100 * val.f_float;
1460 p_sys->f_slider_old = p_sys->f_slider;
1462 val.f_float = p_sys->f_slider / 100.0;
1463 var_Set(p_input, "position", val);
1468 /* following functions are local */
1469 #ifndef HAVE_NCURSESW
1470 static char *KeyToUTF8(int i_key, char *psz_part)
1473 int len = strlen(psz_part);
1476 /* overflow error - should not happen */
1477 memset(psz_part, 0, 6);
1481 psz_part[len] = (char)i_key;
1483 psz_utf8 = FromLocaleDup(psz_part);
1485 /* Ugly check for incomplete bytes sequences
1486 * (in case of non-UTF8 multibyte local encoding) */
1488 for(psz = psz_utf8; *psz; psz++)
1489 if ((*psz == '?') && (*psz_utf8 != '?'))
1491 /* incomplete bytes sequence detected
1492 * (VLC core inserted dummy question marks) */
1497 /* Check for incomplete UTF8 bytes sequence */
1498 if (!EnsureUTF8(psz_utf8))
1504 memset(psz_part, 0, 6);
1509 static inline int RemoveLastUTF8Entity(char *psz, int len)
1511 while (len && ((psz[--len] & 0xc0) == 0x80));
1512 /* UTF8 continuation byte */
1518 static void Eject(intf_thread_t *p_intf)
1520 char *psz_device = NULL, *psz_parser, *psz_name;
1523 * Get the active input
1524 * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
1525 * If it's neither of these, then return
1528 playlist_t * p_playlist = pl_Get(p_intf);
1531 if (!playlist_CurrentPlayingItem(p_playlist))
1537 psz_name = playlist_CurrentPlayingItem(p_playlist)->p_input->psz_name;
1541 if (!strncmp(psz_name, "dvd://", 6))
1547 psz_device = config_GetPsz(p_intf, "dvd");
1550 /* Omit the first MRL-selector characters */
1551 psz_device = strdup(psz_name + strlen("dvd://"));
1555 else if (!strncmp(psz_name, "vcd://", 6))
1561 psz_device = config_GetPsz(p_intf, "vcd");
1564 /* Omit the beginning MRL-selector characters */
1565 psz_device = strdup(psz_name + 6);
1569 else if (!strncmp(psz_name, "cdda://", 7))
1575 psz_device = config_GetPsz(p_intf, "cd-audio");
1578 /* Omit the beginning MRL-selector characters */
1579 psz_device = strdup(psz_name + 7);
1584 psz_device = strdup(psz_name);
1592 /* Remove what we have after @ */
1593 for(psz_parser = psz_device ; *psz_parser ; psz_parser++)
1594 if (*psz_parser == '@')
1600 /* If there's a stream playing, we aren't allowed to eject ! */
1601 if (!p_intf->p_sys->p_input)
1603 msg_Dbg(p_intf, "ejecting %s", psz_device);
1605 intf_Eject(p_intf, psz_device);
1611 static void PlayPause(intf_thread_t *p_intf)
1613 input_thread_t *p_input = p_intf->p_sys->p_input;
1614 playlist_t *p_playlist = pl_Get(p_intf);
1619 var_Get(p_input, "state", &val);
1620 if (val.i_int != PAUSE_S)
1621 val.i_int = PAUSE_S;
1623 val.i_int = PLAYING_S;
1624 var_Set(p_input, "state", val);
1627 playlist_Play(p_playlist);
1630 static int HandleKey(intf_thread_t *p_intf, int i_key)
1632 intf_sys_t *p_sys = p_intf->p_sys;
1635 playlist_t *p_playlist = pl_Get(p_intf);
1637 if (p_sys->i_box_type == BOX_PLAYLIST)
1640 bool b_box_plidx_follow = false;
1644 /* Playlist Settings */
1646 var_ToggleBool(p_playlist, "random");
1649 var_ToggleBool(p_playlist, "loop");
1652 var_ToggleBool(p_playlist, "repeat");
1657 playlist_RecursiveNodeSort(p_playlist,
1658 PlaylistGetRoot(p_intf),
1659 SORT_TITLE_NODES_FIRST, ORDER_NORMAL);
1660 p_sys->b_need_update = true;
1663 playlist_RecursiveNodeSort(p_playlist,
1664 PlaylistGetRoot(p_intf),
1665 SORT_TITLE_NODES_FIRST, ORDER_REVERSE);
1666 p_sys->b_need_update = true;
1671 p_sys->category_view = !p_sys->category_view;
1672 PlaylistRebuild(p_intf);
1675 /* Playlist navigation */
1677 FindIndex(p_sys, p_playlist);
1680 p_sys->i_box_plidx = 0;
1683 /* workaround for FreeBSD + xterm:
1684 * see http://www.nabble.com/curses-vs.-xterm-key-mismatch-t3574377.html */
1688 p_sys->i_box_plidx = p_playlist->items.i_size - 1;
1691 p_sys->i_box_plidx--;
1694 p_sys->i_box_plidx++;
1697 p_sys->i_box_plidx -= p_sys->i_box_lines;
1700 p_sys->i_box_plidx += p_sys->i_box_lines;
1707 playlist_item_t *p_item;
1710 p_item = p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
1711 if (p_item->i_children == -1)
1712 playlist_DeleteFromInput(p_playlist,
1713 p_item->p_input, pl_Locked);
1715 playlist_NodeDelete(p_playlist, p_item, true , false);
1717 PlaylistRebuild(p_intf);
1724 if (!p_sys->pp_plist[p_sys->i_box_plidx])
1729 if (p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children
1732 playlist_item_t *p_item, *p_parent;
1734 p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
1737 p_parent = p_playlist->p_root_onelevel;
1738 while (p_parent->p_parent)
1739 p_parent = p_parent->p_parent;
1740 playlist_Control(p_playlist, PLAYLIST_VIEWPLAY,
1741 pl_Unlocked, p_parent, p_item);
1743 else if (p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children
1745 { /* We only want to set the current node */
1746 playlist_Stop(p_playlist);
1747 p_sys->p_node = p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
1751 p_sys->p_node = p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
1752 playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked,
1753 p_sys->pp_plist[p_sys->i_box_plidx]->p_item, NULL);
1755 b_box_plidx_follow = true;
1764 int i_max = p_sys->i_plist_entries;
1765 if (p_sys->i_box_plidx >= i_max) p_sys->i_box_plidx = i_max - 1;
1766 if (p_sys->i_box_plidx < 0) p_sys->i_box_plidx = 0;
1769 if (PlaylistIsPlaying(p_playlist,
1770 p_sys->pp_plist[p_sys->i_box_plidx]->p_item))
1771 b_box_plidx_follow = true;
1773 p_sys->b_box_plidx_follow = b_box_plidx_follow;
1777 if (p_sys->i_box_type == BOX_BROWSE)
1780 /* Browser navigation */
1784 p_sys->i_box_bidx = 0;
1790 p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
1793 p_sys->i_box_bidx--;
1796 p_sys->i_box_bidx++;
1799 p_sys->i_box_bidx -= p_sys->i_box_lines;
1802 p_sys->i_box_bidx += p_sys->i_box_lines;
1804 case '.': /* Toggle show hidden files */
1805 p_sys->b_show_hidden_files = (p_sys->b_show_hidden_files ==
1806 true ? false : true);
1814 if (p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file || i_key == ' ')
1817 if (asprintf(&psz_uri, "%s://%s/%s",
1818 p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file ?
1819 "file" : "directory",
1820 p_sys->psz_current_dir,
1821 p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path
1827 playlist_item_t *p_parent = p_sys->p_node;
1831 p_parent = playlist_CurrentPlayingItem(p_playlist) ? playlist_CurrentPlayingItem(p_playlist)->p_parent : NULL;
1834 p_parent = p_playlist->p_local_onelevel;
1837 while (p_parent->p_parent && p_parent->p_parent->p_parent)
1838 p_parent = p_parent->p_parent;
1840 playlist_Add(p_playlist, psz_uri, NULL, PLAYLIST_APPEND,
1842 p_parent->p_input ==
1843 p_playlist->p_local_onelevel->p_input
1846 p_sys->i_box_type = BOX_PLAYLIST;
1851 if (asprintf(&(p_sys->psz_current_dir), "%s/%s", p_sys->psz_current_dir,
1852 p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path) != -1)
1862 if (p_sys->i_box_bidx >= p_sys->i_dir_entries) p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
1863 if (p_sys->i_box_bidx < 0) p_sys->i_box_bidx = 0;
1867 else if (p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO ||
1868 p_sys->i_box_type == BOX_META || p_sys->i_box_type == BOX_STATS ||
1869 p_sys->i_box_type == BOX_OBJECTS)
1874 p_sys->i_box_start = 0;
1880 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1883 if (p_sys->i_box_start > 0) p_sys->i_box_start--;
1886 if (p_sys->i_box_start < p_sys->i_box_lines_total - 1)
1887 p_sys->i_box_start++;
1890 p_sys->i_box_start -= p_sys->i_box_lines;
1891 if (p_sys->i_box_start < 0) p_sys->i_box_start = 0;
1894 p_sys->i_box_start += p_sys->i_box_lines;
1895 if (p_sys->i_box_start >= p_sys->i_box_lines_total)
1896 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
1902 else if (p_sys->i_box_type == BOX_NONE)
1907 p_sys->f_slider = 0;
1908 ManageSlider(p_intf);
1914 p_sys->f_slider = 99.9;
1915 ManageSlider(p_intf);
1918 p_sys->f_slider += 5.0;
1919 if (p_sys->f_slider >= 99.0) p_sys->f_slider = 99.0;
1920 ManageSlider(p_intf);
1923 p_sys->f_slider -= 5.0;
1924 if (p_sys->f_slider < 0.0) p_sys->f_slider = 0.0;
1925 ManageSlider(p_intf);
1932 else if (p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain)
1934 int i_chain_len = strlen(p_sys->psz_search_chain);
1944 if (i_chain_len > 0)
1945 p_sys->psz_old_search = strdup(p_sys->psz_search_chain);
1946 else if (p_sys->psz_old_search)
1947 SearchPlaylist(p_sys, p_sys->psz_old_search);
1948 p_sys->i_box_type = BOX_PLAYLIST;
1950 case 0x1b: /* ESC */
1951 /* Alt+key combinations return 2 keys in the terminal keyboard:
1952 * ESC, and the 2nd key.
1953 * If some other key is available immediately (where immediately
1954 * means after wgetch() 1 second delay), that means that the
1955 * ESC key was not pressed.
1957 * man 3X curs_getch says:
1959 * Use of the escape key by a programmer for a single
1960 * character function is discouraged, as it will cause a delay
1961 * of up to one second while the keypad code looks for a
1962 * following function-key sequence.
1965 if (wgetch(p_sys->w) != ERR)
1970 p_sys->i_box_plidx = p_sys->i_before_search;
1971 p_sys->i_box_type = BOX_PLAYLIST;
1975 RemoveLastUTF8Entity(p_sys->psz_search_chain, i_chain_len);
1979 #ifdef HAVE_NCURSESW
1980 if (i_chain_len + 1 < SEARCH_CHAIN_SIZE)
1982 p_sys->psz_search_chain[i_chain_len] = (char) i_key;
1983 p_sys->psz_search_chain[i_chain_len + 1] = '\0';
1986 char *psz_utf8 = KeyToUTF8(i_key, p_sys->psz_partial_keys);
1990 if (i_chain_len + strlen(psz_utf8) < SEARCH_CHAIN_SIZE)
1991 strcpy(p_sys->psz_search_chain + i_chain_len, psz_utf8);
1998 free(p_sys->psz_old_search);
1999 p_sys->psz_old_search = NULL;
2000 SearchPlaylist(p_sys, p_sys->psz_search_chain);
2003 else if (p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain)
2005 int i_chain_len = strlen(p_sys->psz_open_chain);
2016 if (i_chain_len > 0)
2018 playlist_item_t *p_parent = p_sys->p_node;
2022 p_parent = playlist_CurrentPlayingItem(p_playlist) ? playlist_CurrentPlayingItem(p_playlist)->p_parent : NULL;
2024 p_parent = p_playlist->p_local_onelevel;
2026 while (p_parent->p_parent && p_parent->p_parent->p_parent)
2027 p_parent = p_parent->p_parent;
2030 playlist_Add(p_playlist, p_sys->psz_open_chain, NULL,
2031 PLAYLIST_APPEND|PLAYLIST_GO, PLAYLIST_END,
2032 p_parent->p_input ==
2033 p_playlist->p_local_onelevel->p_input
2036 p_sys->b_box_plidx_follow = true;
2038 p_sys->i_box_type = BOX_PLAYLIST;
2040 case 0x1b: /* ESC */
2041 if (wgetch(p_sys->w) != ERR)
2046 p_sys->i_box_type = BOX_PLAYLIST;
2050 RemoveLastUTF8Entity(p_sys->psz_open_chain, i_chain_len);
2054 #ifdef HAVE_NCURSESW
2055 if (i_chain_len + 1 < OPEN_CHAIN_SIZE)
2057 p_sys->psz_open_chain[i_chain_len] = (char) i_key;
2058 p_sys->psz_open_chain[i_chain_len + 1] = '\0';
2061 char *psz_utf8 = KeyToUTF8(i_key, p_sys->psz_partial_keys);
2065 if (i_chain_len + strlen(psz_utf8) < OPEN_CHAIN_SIZE)
2066 strcpy(p_sys->psz_open_chain + i_chain_len, psz_utf8);
2079 case 0x1b: /* ESC */
2080 if (wgetch(p_sys->w) != ERR)
2088 libvlc_Quit(p_intf->p_libvlc);
2094 if (p_sys->i_box_type == BOX_INFO)
2095 p_sys->i_box_type = BOX_NONE;
2097 p_sys->i_box_type = BOX_INFO;
2098 p_sys->i_box_lines_total = 0;
2101 if (p_sys->i_box_type == BOX_META)
2102 p_sys->i_box_type = BOX_NONE;
2104 p_sys->i_box_type = BOX_META;
2105 p_sys->i_box_lines_total = 0;
2108 if (p_sys->i_box_type == BOX_LOG)
2109 p_sys->i_box_type = BOX_NONE;
2111 p_sys->i_box_type = BOX_LOG;
2114 if (p_sys->i_box_type == BOX_PLAYLIST)
2115 p_sys->i_box_type = BOX_NONE;
2117 p_sys->i_box_type = BOX_PLAYLIST;
2120 if (p_sys->i_box_type == BOX_BROWSE)
2121 p_sys->i_box_type = BOX_NONE;
2123 p_sys->i_box_type = BOX_BROWSE;
2126 if (p_sys->i_box_type == BOX_OBJECTS)
2127 p_sys->i_box_type = BOX_NONE;
2129 p_sys->i_box_type = BOX_OBJECTS;
2132 if (p_sys->i_box_type == BOX_STATS)
2133 p_sys->i_box_type = BOX_NONE;
2135 p_sys->i_box_type = BOX_STATS;
2138 p_sys->b_color = !p_sys->b_color;
2139 if (p_sys->b_color && !p_sys->b_color_started)
2140 start_color_and_pairs(p_intf);
2144 if (p_sys->i_box_type == BOX_HELP)
2145 p_sys->i_box_type = BOX_NONE;
2147 p_sys->i_box_type = BOX_HELP;
2148 p_sys->i_box_lines_total = 0;
2151 if (p_sys->i_box_type != BOX_SEARCH && p_sys->psz_search_chain)
2153 p_sys->psz_search_chain[0] = '\0';
2154 p_sys->b_box_plidx_follow = false;
2155 p_sys->i_before_search = p_sys->i_box_plidx;
2156 p_sys->i_box_type = BOX_SEARCH;
2159 case 'A': /* Open */
2160 if (p_sys->i_box_type != BOX_OPEN && p_sys->psz_open_chain)
2162 p_sys->psz_open_chain[0] = '\0';
2163 p_sys->i_box_type = BOX_OPEN;
2169 p_sys->f_slider += 1.0;
2170 if (p_sys->f_slider > 99.9) p_sys->f_slider = 99.9;
2171 ManageSlider(p_intf);
2175 p_sys->f_slider -= 1.0;
2176 if (p_sys->f_slider < 0.0) p_sys->f_slider = 0.0;
2177 ManageSlider(p_intf);
2180 /* Common control */
2183 bool fs = var_ToggleBool(p_playlist, "fullscreen");
2184 if (p_intf->p_sys->p_input)
2186 vout_thread_t *p_vout = input_GetVout(p_intf->p_sys->p_input);
2189 var_SetBool(p_vout, "fullscreen", fs);
2190 vlc_object_release(p_vout);
2202 playlist_Stop(p_playlist);
2211 var_TriggerCallback(p_sys->p_input, "prev-title");
2216 var_TriggerCallback(p_sys->p_input, "next-title");
2221 var_TriggerCallback(p_sys->p_input, "prev-chapter");
2226 var_TriggerCallback(p_sys->p_input, "next-chapter");
2230 playlist_Prev(p_playlist);
2235 playlist_Next(p_playlist);
2240 aout_VolumeUp(p_playlist, 1, NULL);
2245 aout_VolumeDown(p_playlist, 1, NULL);
2250 * ^l should clear and redraw the screen
2265 /*****************************************************************************
2266 * Run: ncurses thread
2267 *****************************************************************************/
2268 static void Run(intf_thread_t *p_intf)
2270 intf_sys_t *p_sys = p_intf->p_sys;
2271 playlist_t *p_playlist = pl_Get(p_intf);
2272 p_sys->p_playlist = p_playlist;
2275 time_t t_last_refresh;
2276 int canc = vlc_savecancel();
2279 * force drawing the interface for the first time
2281 t_last_refresh = (time(0) - 1);
2283 * force building of the playlist array
2285 PlaylistRebuild(p_intf);
2286 var_AddCallback(p_playlist, "intf-change", PlaylistChanged, p_intf);
2287 var_AddCallback(p_playlist, "playlist-item-append", PlaylistChanged, p_intf);
2289 while (vlc_object_alive(p_intf))
2291 msleep(INTF_IDLE_SLEEP);
2293 /* Update the input */
2294 if (!p_sys->p_input)
2295 p_sys->p_input = playlist_CurrentInput(p_playlist);
2296 else if (p_sys->p_input->b_dead)
2298 vlc_object_release(p_sys->p_input);
2299 p_sys->p_input = NULL;
2300 p_sys->f_slider = p_sys->f_slider_old = 0.0;
2301 p_sys->b_box_cleared = false;
2305 if (p_sys->b_box_plidx_follow && playlist_CurrentPlayingItem(p_playlist))
2308 FindIndex(p_sys, p_playlist);
2313 while ((i_key = wgetch(p_sys->w)) != -1)
2314 if (HandleKey(p_intf, i_key))
2315 Redraw(p_intf, &t_last_refresh);
2318 if (p_sys->f_slider > 0.0001 && !p_sys->b_box_cleared)
2321 Redraw(p_intf, &t_last_refresh);
2322 p_sys->b_box_cleared = true;
2326 * redraw the screen every second
2328 if ((time(0) - t_last_refresh) >= 1)
2330 ManageSlider(p_intf);
2331 Redraw(p_intf, &t_last_refresh);
2334 var_DelCallback(p_playlist, "intf-change", PlaylistChanged, p_intf);
2335 var_DelCallback(p_playlist, "playlist-item-append", PlaylistChanged, p_intf);
2336 vlc_restorecancel(canc);
2339 /*****************************************************************************
2340 * Open: initialize and create window
2341 *****************************************************************************/
2342 static int Open(vlc_object_t *p_this)
2344 intf_thread_t *p_intf = (intf_thread_t *)p_this;
2347 /* Allocate instance and initialize some members */
2348 p_sys = p_intf->p_sys = malloc(sizeof(intf_sys_t));
2351 p_sys->p_node = NULL;
2352 p_sys->p_input = NULL;
2353 p_sys->f_slider = 0.0;
2354 p_sys->f_slider_old = 0.0;
2355 p_sys->i_box_type = BOX_PLAYLIST;
2356 p_sys->i_box_lines = 0;
2357 p_sys->i_box_start= 0;
2358 p_sys->i_box_lines_total = 0;
2359 p_sys->b_box_plidx_follow = true;
2360 p_sys->b_box_cleared = false;
2361 p_sys->i_box_plidx = 0;
2362 p_sys->i_box_bidx = 0;
2363 // FIXME p_sys->p_sub = msg_Subscribe(p_intf);
2364 p_sys->b_color = var_CreateGetBool(p_intf, "color");
2365 p_sys->b_color_started = false;
2367 #ifndef HAVE_NCURSESW
2368 memset(p_sys->psz_partial_keys, 0, sizeof(p_sys->psz_partial_keys));
2371 /* Initialize the curses library */
2372 p_sys->w = initscr();
2375 start_color_and_pairs(p_intf);
2377 keypad(p_sys->w, TRUE);
2378 /* Don't do NL -> CR/NL */
2380 /* Take input chars one at a time */
2384 /* Invisible cursor */
2386 /* Non blocking wgetch() */
2387 wtimeout(p_sys->w, 0);
2391 /* exported function */
2392 p_intf->pf_run = Run;
2394 /* Stop printing errors to the console */
2395 freopen("/dev/null", "wb", stderr);
2397 /* Set defaul playlist view */
2398 p_sys->category_view = true; //FIXME
2399 p_sys->pp_plist = NULL;
2400 p_sys->i_plist_entries = 0;
2401 p_sys->b_need_update = false;
2403 /* Initialize search chain */
2404 p_sys->psz_search_chain = malloc(SEARCH_CHAIN_SIZE + 1);
2405 p_sys->psz_old_search = NULL;
2406 p_sys->i_before_search = 0;
2408 /* Initialize open chain */
2409 p_sys->psz_open_chain = malloc(OPEN_CHAIN_SIZE + 1);
2411 /* Initialize browser options */
2412 char* psz_tmp = var_CreateGetString(p_intf, "browse-dir");
2413 if (psz_tmp && *psz_tmp)
2414 p_sys->psz_current_dir = psz_tmp;
2417 p_sys->psz_current_dir = config_GetUserDir(VLC_HOME_DIR);
2421 p_sys->i_dir_entries = 0;
2422 p_sys->pp_dir_entries = NULL;
2423 p_sys->b_show_hidden_files = false;
2429 /*****************************************************************************
2430 * Close: destroy interface window
2431 *****************************************************************************/
2432 static void Close(vlc_object_t *p_this)
2434 intf_thread_t *p_intf = (intf_thread_t *)p_this;
2435 intf_sys_t *p_sys = p_intf->p_sys;
2437 PlaylistDestroy(p_sys);
2440 free(p_sys->psz_current_dir);
2441 free(p_sys->psz_search_chain);
2442 free(p_sys->psz_old_search);
2443 free(p_sys->psz_open_chain);
2446 vlc_object_release(p_sys->p_input);
2448 /* Close the ncurses interface */
2451 // FIXME msg_Unsubscribe(p_intf, p_sys->p_sub);
2453 /* Destroy structure */