]> git.sesse.net Git - vlc/blobdiff - modules/gui/ncurses.c
Qt: EPGRuler: compute sizes based on widget's
[vlc] / modules / gui / ncurses.c
index 95bfc4a563938eca6f30f123f02678925cf72f22..d3f7755ee43201fcf20fc4caf69c3a5117b9f395 100644 (file)
 # include "config.h"
 #endif
 
-#include <vlc_common.h>
-#include <vlc_plugin.h>
-
 #define _XOPEN_SOURCE_EXTENDED 1
+
+#include <assert.h>
 #include <wchar.h>
+#include <sys/stat.h>
+#include <math.h>
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 
 #include <ncurses.h>
 
 #include <vlc_interface.h>
 #include <vlc_vout.h>
-#include <vlc_aout_intf.h>
 #include <vlc_charset.h>
 #include <vlc_input.h>
 #include <vlc_es.h>
 #include <vlc_fs.h>
 #include <vlc_url.h>
 
-#include <assert.h>
-
-#ifdef HAVE_SYS_STAT_H
-#   include <sys/stat.h>
-#endif
-
 /*****************************************************************************
  * Local prototypes.
  *****************************************************************************/
@@ -181,6 +178,7 @@ struct pl_item_t
 
 struct intf_sys_t
 {
+    vlc_thread_t    thread;
     input_thread_t *p_input;
 
     bool            color;
@@ -193,7 +191,7 @@ struct intf_sys_t
     int             box_start;        // first line of box displayed
     int             box_idx;          // selected line
 
-    msg_subscription_t  *sub;         // message bank subscription
+    msg_subscription_t sub;         // message bank subscription
     struct
     {
         int              type;
@@ -802,49 +800,49 @@ static int DrawStats(intf_thread_t *intf)
 
     /* Input */
     if (sys->color) color_set(C_CATEGORY, NULL);
-    MainBoxWrite(sys, l++, _("  [Incoming]"));
+    MainBoxWrite(sys, l++, _("+-[Incoming]"));
     if (sys->color) color_set(C_DEFAULT, NULL);
-    MainBoxWrite(sys, l++, _("      input bytes read : %8.0f KiB"),
+    MainBoxWrite(sys, l++, _("| input bytes read : %8.0f KiB"),
             (float)(p_stats->i_read_bytes)/1024);
-    MainBoxWrite(sys, l++, _("      input bitrate    :   %6.0f kb/s"),
+    MainBoxWrite(sys, l++, _("| input bitrate    :   %6.0f kb/s"),
             p_stats->f_input_bitrate*8000);
-    MainBoxWrite(sys, l++, _("      demux bytes read : %8.0f KiB"),
+    MainBoxWrite(sys, l++, _("| demux bytes read : %8.0f KiB"),
             (float)(p_stats->i_demux_read_bytes)/1024);
-    MainBoxWrite(sys, l++, _("      demux bitrate    :   %6.0f kb/s"),
+    MainBoxWrite(sys, l++, _("| demux bitrate    :   %6.0f kb/s"),
             p_stats->f_demux_bitrate*8000);
 
     /* Video */
     if (i_video) {
         if (sys->color) color_set(C_CATEGORY, NULL);
-        MainBoxWrite(sys, l++, _("  [Video Decoding]"));
+        MainBoxWrite(sys, l++, _("+-[Video Decoding]"));
         if (sys->color) color_set(C_DEFAULT, NULL);
-        MainBoxWrite(sys, l++, _("      video decoded    :    %"PRId64),
+        MainBoxWrite(sys, l++, _("| video decoded    :    %5"PRIi64),
                 p_stats->i_decoded_video);
-        MainBoxWrite(sys, l++, _("      frames displayed :    %"PRId64),
+        MainBoxWrite(sys, l++, _("| frames displayed :    %5"PRIi64),
                 p_stats->i_displayed_pictures);
-        MainBoxWrite(sys, l++, _("      frames lost      :    %"PRId64),
+        MainBoxWrite(sys, l++, _("| frames lost      :    %5"PRIi64),
                 p_stats->i_lost_pictures);
     }
     /* Audio*/
     if (i_audio) {
         if (sys->color) color_set(C_CATEGORY, NULL);
-        MainBoxWrite(sys, l++, _("  [Audio Decoding]"));
+        MainBoxWrite(sys, l++, _("+-[Audio Decoding]"));
         if (sys->color) color_set(C_DEFAULT, NULL);
-        MainBoxWrite(sys, l++, _("      audio decoded    :    %"PRId64),
+        MainBoxWrite(sys, l++, _("| audio decoded    :    %5"PRIi64),
                 p_stats->i_decoded_audio);
-        MainBoxWrite(sys, l++, _("      buffers played   :    %"PRId64),
+        MainBoxWrite(sys, l++, _("| buffers played   :    %5"PRIi64),
                 p_stats->i_played_abuffers);
-        MainBoxWrite(sys, l++, _("      buffers lost     :    %"PRId64),
+        MainBoxWrite(sys, l++, _("| buffers lost     :    %5"PRIi64),
                 p_stats->i_lost_abuffers);
     }
     /* Sout */
     if (sys->color) color_set(C_CATEGORY, NULL);
-    MainBoxWrite(sys, l++, _("  [Streaming]"));
+    MainBoxWrite(sys, l++, _("+-[Streaming]"));
     if (sys->color) color_set(C_DEFAULT, NULL);
-    MainBoxWrite(sys, l++, _("      packets sent     :    %5i"), p_stats->i_sent_packets);
-    MainBoxWrite(sys, l++, _("      bytes sent       : %8.0f KiB"),
+    MainBoxWrite(sys, l++, _("| packets sent     :    %5"PRIi64), p_stats->i_sent_packets);
+    MainBoxWrite(sys, l++, _("| bytes sent       : %8.0f KiB"),
             (float)(p_stats->i_sent_bytes)/1025);
-    MainBoxWrite(sys, l++, _("      sending bitrate  :   %6.0f kb/s"),
+    MainBoxWrite(sys, l++, _("| sending bitrate  :   %6.0f kb/s"),
             p_stats->f_send_bitrate*8000);
     if (sys->color) color_set(C_DEFAULT, NULL);
 
@@ -866,7 +864,7 @@ static int DrawHelp(intf_thread_t *intf)
     if (sys->color) color_set(C_DEFAULT, NULL);
     H(_(" h,H                    Show/Hide help box"));
     H(_(" i                      Show/Hide info box"));
-    H(_(" m                      Show/Hide metadata box"));
+    H(_(" M                      Show/Hide metadata box"));
     H(_(" L                      Show/Hide messages box"));
     H(_(" P                      Show/Hide playlist box"));
     H(_(" B                      Show/Hide filebrowser"));
@@ -889,6 +887,7 @@ static int DrawHelp(intf_thread_t *intf)
     /* xgettext: You can use ← and → characters */
     H(_(" <left>,<right>         Seek -/+ 1%%"));
     H(_(" a, z                   Volume Up/Down"));
+    H(_(" m                      Mute"));
     /* xgettext: You can use ↑ and ↓ characters */
     H(_(" <up>,<down>            Navigate through the box line by line"));
     /* xgettext: You can use ⇞ and ⇟ characters */
@@ -1071,7 +1070,7 @@ static int DrawStatus(intf_thread_t *intf)
             };
             char buf1[MSTRTIME_MAX_SIZE];
             char buf2[MSTRTIME_MAX_SIZE];
-            unsigned i_volume;
+            float volume;
 
         case INIT_S:
         case END_S:
@@ -1092,9 +1091,12 @@ static int DrawStatus(intf_thread_t *intf)
 
             mvnprintw(y++, 0, COLS, _(" Position : %s/%s"), buf1, buf2);
 
-            i_volume = aout_VolumeGet(p_playlist);
-            mvnprintw(y++, 0, COLS, _(" Volume   : %u%%"),
-                      i_volume*100/AOUT_VOLUME_DEFAULT);
+            volume = playlist_VolumeGet(p_playlist);
+            int mute = playlist_MuteGet(p_playlist);
+            mvnprintw(y++, 0, COLS,
+                      mute ? _(" Volume   : Mute") :
+                      volume >= 0.f ? _(" Volume   : %3ld%%") : _(" Volume   : ----"),
+                      lroundf(volume * 100.f));
 
             if (!var_Get(p_input, "title", &val)) {
                 int i_title_count = var_CountChoices(p_input, "title");
@@ -1407,8 +1409,7 @@ static bool HandleBrowseKey(intf_thread_t *intf, int key)
             return true;
         }
 
-        char *uri = make_URI(path, dir_entry->file ? "file"
-                                                             : "directory");
+        char *uri = vlc_path2uri(path, "file");
         free(path);
         if (uri == NULL)
             return true;
@@ -1445,7 +1446,7 @@ static bool HandleBrowseKey(intf_thread_t *intf, int key)
 static void OpenSelection(intf_thread_t *intf)
 {
     intf_sys_t *sys = intf->p_sys;
-    char *uri = make_URI(sys->open_chain, NULL);
+    char *uri = vlc_path2uri(sys->open_chain, NULL);
     if (uri == NULL)
         return;
 
@@ -1563,7 +1564,7 @@ static void HandleCommonKey(intf_thread_t *intf, int key)
     case 'h':
     case 'H': BoxSwitch(sys, BOX_HELP);       return;
     case 'i': BoxSwitch(sys, BOX_INFO);       return;
-    case 'm': BoxSwitch(sys, BOX_META);       return;
+    case 'M': BoxSwitch(sys, BOX_META);       return;
     case 'L': BoxSwitch(sys, BOX_LOG);        return;
     case 'P': BoxSwitch(sys, BOX_PLAYLIST);   return;
     case 'B': BoxSwitch(sys, BOX_BROWSE);     return;
@@ -1607,8 +1608,9 @@ static void HandleCommonKey(intf_thread_t *intf, int key)
 
     case 'p': playlist_Prev(p_playlist);            break;
     case 'n': playlist_Next(p_playlist);            break;
-    case 'a': aout_VolumeUp(p_playlist, 1, NULL);   break;
-    case 'z': aout_VolumeDown(p_playlist, 1, NULL); break;
+    case 'a': playlist_VolumeUp(p_playlist, 1, NULL);   break;
+    case 'z': playlist_VolumeDown(p_playlist, 1, NULL); break;
+    case 'm': playlist_MuteToggle(p_playlist); break;
 
     case 0x0c:  /* ^l */
     case KEY_CLEAR:
@@ -1753,13 +1755,12 @@ static inline void UpdateInput(intf_sys_t *sys, playlist_t *p_playlist)
 /*****************************************************************************
  * Run: ncurses thread
  *****************************************************************************/
-static void Run(intf_thread_t *intf)
+static void *Run(void *data)
 {
+    intf_thread_t *intf = data;
     intf_sys_t    *sys = intf->p_sys;
     playlist_t    *p_playlist = pl_Get(intf);
 
-    int canc = vlc_savecancel();
-
     var_AddCallback(p_playlist, "intf-change", PlaylistChanged, intf);
     var_AddCallback(p_playlist, "item-change", ItemChanged, intf);
     var_AddCallback(p_playlist, "playlist-item-append", PlaylistChanged, intf);
@@ -1773,7 +1774,7 @@ static void Run(intf_thread_t *intf)
     var_DelCallback(p_playlist, "intf-change", PlaylistChanged, intf);
     var_DelCallback(p_playlist, "item-change", ItemChanged, intf);
     var_DelCallback(p_playlist, "playlist-item-append", PlaylistChanged, intf);
-    vlc_restorecancel(canc);
+    return NULL;
 }
 
 /*****************************************************************************
@@ -1792,7 +1793,7 @@ static int Open(vlc_object_t *p_this)
     vlc_mutex_init(&sys->pl_lock);
 
     sys->verbosity = var_InheritInteger(intf, "verbose");
-    sys->sub = vlc_Subscribe(MsgCallback, sys);
+    vlc_Subscribe(&sys->sub, MsgCallback, sys);
 
     sys->box_type = BOX_PLAYLIST;
     sys->plidx_follow = true;
@@ -1824,7 +1825,9 @@ static int Open(vlc_object_t *p_this)
     PlaylistRebuild(intf),
     PL_UNLOCK;
 
-    intf->pf_run = Run;
+    if (vlc_clone(&sys->thread, Run, intf, VLC_THREAD_PRIORITY_LOW))
+        abort(); /* TODO */
+
     return VLC_SUCCESS;
 }
 
@@ -1835,6 +1838,8 @@ static void Close(vlc_object_t *p_this)
 {
     intf_sys_t *sys = ((intf_thread_t*)p_this)->p_sys;
 
+    vlc_join(sys->thread, NULL);
+
     PlaylistDestroy(sys);
     DirsDestroy(sys);
 
@@ -1845,7 +1850,7 @@ static void Close(vlc_object_t *p_this)
 
     endwin();   /* Close the ncurses interface */
 
-    vlc_Unsubscribe(sys->sub);
+    vlc_Unsubscribe(&sys->sub);
     vlc_mutex_destroy(&sys->msg_lock);
     vlc_mutex_destroy(&sys->pl_lock);
     for(unsigned i = 0; i < sizeof sys->msgs / sizeof *sys->msgs; i++) {