Code

Merge branch 'master' of git://git.musicpd.org/avuton/ncmpc
authorMax Kellermann <max@duempel.org>
Fri, 1 Jan 2010 14:01:52 +0000 (15:01 +0100)
committerMax Kellermann <max@duempel.org>
Fri, 1 Jan 2010 14:01:52 +0000 (15:01 +0100)
NEWS
doc/ncmpc.1
src/hscroll.h
src/list_window.c
src/resolver.c
src/screen_browser.c
src/screen_interface.h
src/screen_queue.c
src/screen_song.c
src/song_paint.h
src/window.h

diff --git a/NEWS b/NEWS
index c1c83425c69e0bed722324b372652a173d9ad8bd..31f5e172e862e28ff270761daa6b4d15b0d73c4c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,5 @@
 ncmpc 0.17 - not yet released
+* screen_queue: always update the list size
 
 
 ncmpc 0.16 - (12/25/2009)
index 7c4e8df26ef731e016f9a75bc7690b884b632b1b..4cd54d16b195eb017b35ce2150093a7d49b4e3e8 100644 (file)
@@ -222,9 +222,9 @@ You can view ncmpc's key bindings by pressing '1' (help) when
 ncmpc is running. To edit key bindings use the key editor in ncmpc (press 'K').
 .SH "SONG FORMAT"
 Format of song display for status and the list window.
-The  metadata  delimeters  are: %name%, %artist%, %track%, %time%, %file%, %shortfile%.
+The  metadata  delimiters  are: %name%, %artist%, %track%, %time%, %file%, %shortfile%.
 
-The [] operators is used to group output such that if no metadata delimeters are found or matched between '[' and ']', then none of  the  characters between '[' and ']' are outputed. '&' and '|' are logical operators for and and or. '#'  is used to escape characters. 
+The [] operators is used to group output such that if no metadata delimiters are found or matched between '[' and ']', then none of  the  characters between '[' and ']' are output. '&' and '|' are logical operators for AND and OR. '#'  is used to escape characters. 
 
 Some  useful examples for format are: 
 
@@ -237,7 +237,7 @@ and
 Report bugs on http://www.musicpd.org/mantis/
 .SH "NOTE"
 Since MPD uses UTF\-8, ncmpc needs to convert characters to the 
-charset used by the local system. If you get character conversion errors when your running ncmpc you probably need to set up your locale. This is done by setting any of the LC_CTYPE, LANG or LC_ALL enviroment variables (LC_CTYPE only affects character handling).
+charset used by the local system. If you get character conversion errors when your running ncmpc you probably need to set up your locale. This is done by setting any of the LC_CTYPE, LANG or LC_ALL environment variables (LC_CTYPE only affects character handling).
 
 .SH "SEE ALSO"
 mpc(1), mpd(1), locale(5), locale(7)
index 37c6721a164ad0962184712cf96e1e65c43c9054..3e8fd79322b4c3e623ea82074a7c1411ae925a2c 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef HSCROLL_H
 #define HSCROLL_H
 
+#include "config.h"
+
 #include <glib.h>
 
 #ifdef HAVE_NCURSESW_NCURSES_H
index a98176fbc937610ff20c000b79133e3bc5527346..d44fd29329b427965abedef04a113f3445187015 100644 (file)
@@ -127,6 +127,9 @@ list_window_resize(struct list_window *lw, unsigned width, unsigned height)
 void
 list_window_set_length(struct list_window *lw, unsigned length)
 {
+       if (length == lw->length)
+               return;
+
        lw->length = length;
 
        list_window_check_selected(lw);
index f6f1c8984836e108658ae4a31f29558887129bb3..6898bedda9f96f2989e2d9fac9db724b48be6954 100644 (file)
@@ -30,6 +30,7 @@
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+#include "config.h"
 #include "resolver.h"
 
 #include <netdb.h>
index 49827647d6e8f0898032fbad629c3b69b6e3a6e9..66727611d0901a41ef0ba71d0b765ab56863ab62 100644 (file)
@@ -17,6 +17,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
+#include "config.h"
 #include "screen_browser.h"
 #include "screen_file.h"
 #include "screen_song.h"
index 8371b537004d9459efeaebd24987ee6f5e798482..a91c4d6cbc0890a9ff44857abe7041873afccb84 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef NCMPC_SCREEN_INTERFACE_H
 #define NCMPC_SCREEN_INTERFACE_H
 
+#include "config.h"
 #include "command.h"
 
 #include <stdbool.h>
index 1ee8c001dab4b43db898d40ffc43bb82bc2cfd2b..c8fad68d2c7e52e2cf126a7aae6312ac094d7b51 100644 (file)
@@ -550,6 +550,10 @@ screen_queue_update(struct mpdclient *c)
 {
        if (c->events & MPD_IDLE_QUEUE)
                screen_queue_restore_selection();
+       else
+               /* the queue size may have changed, even if we havn't
+                  revceived the QUEUE idle event yet */
+               list_window_set_length(lw, playlist_length(playlist));
 
        if (((c->events & MPD_IDLE_PLAYER) != 0 &&
             screen_queue_song_change(c->status)) ||
index 27b8b8bc1eefd0003fadacbeebf0d44bda9bb8e6..2c451c1599c38d2043fafa9ee97d3289c8daf24c 100644 (file)
 #include <assert.h>
 #include <string.h>
 
+enum {
+       LABEL_LENGTH = MPD_TAG_COUNT,
+       LABEL_BITRATE,
+};
+
+static const char *const tag_labels[] = {
+       [MPD_TAG_ARTIST] = N_("Artist"),
+       [MPD_TAG_TITLE] = N_("Title"),
+       [MPD_TAG_ALBUM] = N_("Album"),
+       [LABEL_LENGTH] = N_("Length"),
+       [MPD_TAG_COMPOSER] = N_("Composer"),
+       [MPD_TAG_NAME] = N_("Name"),
+       [MPD_TAG_DISC] = N_("Disc"),
+       [MPD_TAG_TRACK] = N_("Track"),
+       [MPD_TAG_DATE] = N_("Date"),
+       [MPD_TAG_GENRE] = N_("Genre"),
+       [MPD_TAG_COMMENT] = N_("Comment"),
+       [LABEL_BITRATE] = N_("Bitrate"),
+};
+
+static unsigned max_tag_label_width;
+
+enum stats_label {
+       STATS_ARTISTS,
+       STATS_ALBUMS,
+       STATS_SONGS,
+       STATS_UPTIME,
+       STATS_DBUPTIME,
+       STATS_PLAYTIME,
+       STATS_DBPLAYTIME,
+};
+
+static const char *const stats_labels[] = {
+       [STATS_ARTISTS] = N_("Number of artists"),
+       [STATS_ALBUMS] = N_("Number of albums"),
+       [STATS_SONGS] = N_("Number of songs"),
+       [STATS_UPTIME] = N_("Uptime"),
+       [STATS_DBUPTIME] = N_("Most recent db update"),
+       [STATS_PLAYTIME] = N_("Playtime"),
+       [STATS_DBPLAYTIME] = N_("DB playtime"),
+};
+
+static unsigned max_stats_label_width;
+
 static struct list_window *lw;
 
 static struct mpd_song *next_song;
@@ -87,6 +131,24 @@ screen_song_list_callback(unsigned idx, G_GNUC_UNUSED void *data)
 static void
 screen_song_init(WINDOW *w, int cols, int rows)
 {
+       for (unsigned i = 0; i < G_N_ELEMENTS(tag_labels); ++i) {
+               if (tag_labels[i] != NULL) {
+                       unsigned width = utf8_width(_(tag_labels[i]));
+
+                       if (width > max_tag_label_width)
+                               max_tag_label_width = width;
+               }
+       }
+
+       for (unsigned i = 0; i < G_N_ELEMENTS(stats_labels); ++i) {
+               if (stats_labels[i] != NULL) {
+                       unsigned width = utf8_width(_(stats_labels[i]));
+
+                       if (width > max_stats_label_width)
+                               max_stats_label_width = width;
+               }
+       }
+
        /* We will need at least 10 lines, so this saves 10 reallocations :) */
        current.lines = g_ptr_array_sized_new(10);
        lw = list_window_init(w, cols, rows);
@@ -180,141 +242,102 @@ screen_song_append(const char *label, const char *value, unsigned label_col)
 }
 
 static void
-screen_song_append_tag(const char *label, const struct mpd_song *song,
-                      enum mpd_tag_type tag, unsigned label_col)
+screen_song_append_tag(const struct mpd_song *song, enum mpd_tag_type tag)
 {
+       const char *label = _(tag_labels[tag]);
        unsigned i = 0;
        const char *value;
 
+       assert((unsigned)tag < G_N_ELEMENTS(tag_labels));
+       assert(label != NULL);
+
        while ((value = mpd_song_get_tag(song, tag, i++)) != NULL)
-               screen_song_append(label, value, label_col);
+               screen_song_append(label, value, max_tag_label_width);
 }
 
 static void
 screen_song_add_song(const struct mpd_song *song, const struct mpdclient *c)
 {
-       unsigned i, max_label_width;
-       enum label {
-               ARTIST, TITLE, ALBUM, LENGTH, COMPOSER, NAME, DISC, TRACK,
-               DATE, GENRE, COMMENT, BITRATE
-       };
-       const char *labels[] = { [ARTIST] = _("Artist"),
-               [TITLE] = _("Title"),
-               [ALBUM] = _("Album"),
-               [LENGTH] = _("Length"),
-               [COMPOSER] = _("Composer"),
-               [NAME] = _("Name"),
-               [DISC] = _("Disc"),
-               [TRACK] = _("Track"),
-               [DATE] = _("Date"),
-               [GENRE] = _("Genre"),
-               [COMMENT] = _("Comment"),
-               [BITRATE] = _("Bitrate"),
-       };
-       /* Determine the width of the longest label */
-       max_label_width = utf8_width(labels[0]);
-       for (i = 1; i < G_N_ELEMENTS(labels); ++i) {
-               if (utf8_width(labels[i]) > max_label_width)
-                       max_label_width = utf8_width(labels[i]);
-       }
-
        assert(song != NULL);
 
-       screen_song_append_tag(labels[ARTIST], song, MPD_TAG_ARTIST,
-                              max_label_width);
-       screen_song_append_tag(labels[TITLE], song, MPD_TAG_TITLE,
-                              max_label_width);
-       screen_song_append_tag(labels[ALBUM], song, MPD_TAG_ALBUM,
-                              max_label_width);
+       screen_song_append_tag(song, MPD_TAG_ARTIST);
+       screen_song_append_tag(song, MPD_TAG_TITLE);
+       screen_song_append_tag(song, MPD_TAG_ALBUM);
+
        /* create time string and add it */
        if (mpd_song_get_duration(song) > 0) {
                char length[16];
                format_duration_short(length, sizeof(length),
                                      mpd_song_get_duration(song));
-               screen_song_append(labels[LENGTH], length, max_label_width);
+               screen_song_append(_(tag_labels[LABEL_LENGTH]), length,
+                                  max_tag_label_width);
        }
-       screen_song_append_tag(labels[COMPOSER], song, MPD_TAG_COMPOSER,
-                              max_label_width);
-       screen_song_append_tag(labels[NAME], song, MPD_TAG_NAME,
-                              max_label_width);
-       screen_song_append_tag(labels[DISC], song, MPD_TAG_DISC,
-                              max_label_width);
-       screen_song_append_tag(labels[TRACK], song, MPD_TAG_TRACK,
-                              max_label_width);
-       screen_song_append_tag(labels[DATE], song, MPD_TAG_DATE,
-                              max_label_width);
-       screen_song_append_tag(labels[GENRE], song, MPD_TAG_GENRE,
-                              max_label_width);
-       screen_song_append_tag(labels[COMMENT], song, MPD_TAG_COMMENT,
-                              max_label_width);
-       screen_song_append(_("Path"), mpd_song_get_uri(song), max_label_width);
+
+       screen_song_append_tag(song, MPD_TAG_COMPOSER);
+       screen_song_append_tag(song, MPD_TAG_NAME);
+       screen_song_append_tag(song, MPD_TAG_DISC);
+       screen_song_append_tag(song, MPD_TAG_TRACK);
+       screen_song_append_tag(song, MPD_TAG_DATE);
+       screen_song_append_tag(song, MPD_TAG_GENRE);
+       screen_song_append_tag(song, MPD_TAG_COMMENT);
+
+       screen_song_append(_("Path"), mpd_song_get_uri(song),
+                          max_tag_label_width);
        if (mpdclient_is_playing(c) && c->song != NULL &&
            strcmp(mpd_song_get_uri(c->song), mpd_song_get_uri(song)) == 0) {
                char buf[16];
                g_snprintf(buf, sizeof(buf), _("%d kbps"),
                           mpd_status_get_kbit_rate(c->status));
-               screen_song_append(labels[BITRATE], buf, max_label_width);
+               screen_song_append(_(tag_labels[LABEL_BITRATE]), buf,
+                                  max_tag_label_width);
        }
 }
 
+static void
+screen_song_append_stats(enum stats_label label, const char *value)
+{
+       screen_song_append(_(stats_labels[label]), value,
+                          max_stats_label_width);
+}
+
 static bool
 screen_song_add_stats(struct mpd_connection *connection)
 {
-       unsigned i, max_label_width;
        char buf[64];
        GDate *date;
-       enum label {
-               ARTISTS, ALBUMS, SONGS, UPTIME,
-               DBUPTIME, PLAYTIME, DBPLAYTIME
-       };
-       const char *labels[] = { [ARTISTS] = _("Number of artists"),
-               [ALBUMS] = _("Number of albums"),
-               [SONGS] = _("Number of songs"),
-               [UPTIME] = _("Uptime"),
-               [DBUPTIME] =_("Most recent db update"),
-               [PLAYTIME] = _("Playtime"),
-               [DBPLAYTIME] = _("DB playtime")
-       };
        struct mpd_stats *mpd_stats;
 
        mpd_stats = mpd_run_stats(connection);
        if (mpd_stats == NULL)
                return false;
 
-       /* Determine the width of the longest label */
-       max_label_width = utf8_width(labels[0]);
-       for (i = 1; i < G_N_ELEMENTS(labels); ++i) {
-               if (utf8_width(labels[i]) > max_label_width)
-                       max_label_width = utf8_width(labels[i]);
-       }
-
        g_ptr_array_add(current.lines, g_strdup(_("MPD statistics")) );
        g_snprintf(buf, sizeof(buf), "%d",
                   mpd_stats_get_number_of_artists(mpd_stats));
-       screen_song_append(labels[ARTISTS], buf, max_label_width);
+       screen_song_append_stats(STATS_ARTISTS, buf);
        g_snprintf(buf, sizeof(buf), "%d",
                   mpd_stats_get_number_of_albums(mpd_stats));
-       screen_song_append(labels[ALBUMS], buf, max_label_width);
+       screen_song_append_stats(STATS_ALBUMS, buf);
        g_snprintf(buf, sizeof(buf), "%d",
                   mpd_stats_get_number_of_songs(mpd_stats));
-       screen_song_append(labels[SONGS], buf, max_label_width);
+       screen_song_append_stats(STATS_SONGS, buf);
 
        format_duration_long(buf, sizeof(buf),
                             mpd_stats_get_db_play_time(mpd_stats));
-       screen_song_append(labels[DBPLAYTIME], buf, max_label_width);
+       screen_song_append_stats(STATS_DBPLAYTIME, buf);
 
        format_duration_long(buf, sizeof(buf),
                             mpd_stats_get_play_time(mpd_stats));
-       screen_song_append(labels[PLAYTIME], buf, max_label_width);
+       screen_song_append_stats(STATS_PLAYTIME, buf);
 
        format_duration_long(buf, sizeof(buf),
                             mpd_stats_get_uptime(mpd_stats));
-       screen_song_append(labels[UPTIME], buf, max_label_width);
+       screen_song_append_stats(STATS_UPTIME, buf);
 
        date = g_date_new();
        g_date_set_time_t(date, mpd_stats_get_db_update_time(mpd_stats));
        g_date_strftime(buf, sizeof(buf), "%x", date);
-       screen_song_append(labels[DBUPTIME], buf, max_label_width);
+       screen_song_append_stats(STATS_DBUPTIME, buf);
        g_date_free(date);
 
        mpd_stats_free(mpd_stats);
index e46f4f5413d51bf527a5a31a4a4b5011f17588b1..10efde4ae9ef03e9df91567ab2869d13eb0c8e75 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef NCMPC_SONG_PAINT_H
 #define NCMPC_SONG_PAINT_H
 
+#include "config.h"
+
 #include <stdbool.h>
 
 #ifdef HAVE_NCURSESW_NCURSES_H
index 4ebe6d7b52fd0eb1a5bf07be214bf5769308490b..5a33012df3b4e673a75b6728171983026d128e9c 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef NCMPC_WINDOW_H
 #define NCMPC_WINDOW_H
 
+#include "config.h"
+
 #ifdef HAVE_NCURSESW_NCURSES_H
 #include <ncursesw/ncurses.h>
 #else