Code

po: update German translation
[ncmpc.git] / src / screen_artist.c
index 9bd1b3e0df6a7b85c1359adb05dd31c7002e8430..8ead78c7ddc456af61e2498e7013ded8b5ed4071 100644 (file)
@@ -1,5 +1,5 @@
 /* ncmpc (Ncurses MPD Client)
- * (c) 2004-2009 The Music Player Daemon Project
+ * (c) 2004-2010 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
 
  * This program is free software; you can redistribute it and/or modify
@@ -21,6 +21,7 @@
 #include "screen_interface.h"
 #include "screen_message.h"
 #include "screen_find.h"
+#include "screen_browser.h"
 #include "screen.h"
 #include "i18n.h"
 #include "charset.h"
@@ -40,6 +41,7 @@ static artist_mode_t mode = LIST_ARTISTS;
 static GPtrArray *artist_list, *album_list;
 static char *artist = NULL;
 static char *album  = NULL;
+static char ALL_TRACKS[] = "";
 
 static struct screen_browser browser;
 
@@ -68,13 +70,9 @@ screen_artist_lw_callback(unsigned idx, void *data)
 
        if (mode == LIST_ALBUMS) {
                if (idx == 0)
-                       return "[..]";
-               else if (idx == list->len + 1) {
-                       str = utf8_to_locale(_("All tracks"));
-                       g_snprintf(buf, BUFSIZE, "[%s]", str);
-                       g_free(str);
-                       return buf;
-               }
+                       return "..";
+               else if (idx == list->len + 1)
+                       return _("All tracks");
 
                --idx;
        }
@@ -85,7 +83,7 @@ screen_artist_lw_callback(unsigned idx, void *data)
        assert(str_utf8 != NULL);
 
        str = utf8_to_locale(str_utf8);
-       g_snprintf(buf, BUFSIZE, "[%s]", str);
+       g_strlcpy(buf, str, sizeof(buf));
        g_free(str);
 
        return buf;
@@ -223,7 +221,7 @@ load_song_list(struct mpdclient *c)
                mpd_search_db_songs(connection, true);
                mpd_search_add_tag_constraint(connection, MPD_OPERATOR_DEFAULT,
                                              MPD_TAG_ARTIST, artist);
-               if (album[0] != 0)
+               if (album != ALL_TRACKS)
                        mpd_search_add_tag_constraint(connection, MPD_OPERATOR_DEFAULT,
                                                      MPD_TAG_ALBUM, album);
                mpd_search_commit(connection);
@@ -243,7 +241,8 @@ static void
 free_state(void)
 {
        g_free(artist);
-       g_free(album);
+       if (album != ALL_TRACKS)
+               g_free(album);
        artist = NULL;
        album = NULL;
 
@@ -334,17 +333,58 @@ screen_artist_resize(int cols, int rows)
        list_window_resize(browser.lw, cols, rows);
 }
 
+/**
+ * Paint one item in the artist list.
+ */
+static void
+paint_artist_callback(WINDOW *w, unsigned i,
+                     G_GNUC_UNUSED unsigned y, unsigned width,
+                     bool selected, void *data)
+{
+       GPtrArray *list = data;
+       char *p = utf8_to_locale(g_ptr_array_index(list, i));
+
+       screen_browser_paint_directory(w, width, selected, p);
+       g_free(p);
+}
+
+/**
+ * Paint one item in the album list.  There are two virtual items
+ * inserted: at the beginning, there's the special item ".." to go to
+ * the parent directory, and at the end, there's the item "All tracks"
+ * to view the tracks of all albums.
+ */
+static void
+paint_album_callback(WINDOW *w, unsigned i,
+                    G_GNUC_UNUSED unsigned y, unsigned width,
+                    bool selected, void *data)
+{
+       GPtrArray *list = data;
+       const char *p;
+       char *q = NULL;
+
+       if (i == 0)
+               p = "..";
+       else if (i == list->len + 1)
+               p = _("All tracks");
+       else
+               p = q = utf8_to_locale(g_ptr_array_index(list, i - 1));
+
+       screen_browser_paint_directory(w, width, selected, p);
+       g_free(q);
+}
+
 static void
 screen_artist_paint(void)
 {
        if (browser.filelist) {
                screen_browser_paint(&browser);
        } else if (album_list != NULL)
-               list_window_paint(browser.lw, screen_artist_lw_callback,
-                                 album_list);
+               list_window_paint2(browser.lw,
+                                  paint_album_callback, album_list);
        else if (artist_list != NULL)
-               list_window_paint(browser.lw, screen_artist_lw_callback,
-                                 artist_list);
+               list_window_paint2(browser.lw,
+                                  paint_artist_callback, artist_list);
        else {
                wmove(browser.lw->w, 0, 0);
                wclrtobot(browser.lw->w);
@@ -369,14 +409,17 @@ screen_artist_get_title(char *str, size_t size)
 
        case LIST_SONGS:
                s1 = utf8_to_locale(artist);
-               if (*album != 0) {
-                       s2 = utf8_to_locale(album);
+
+               if (album == ALL_TRACKS)
                        g_snprintf(str, size,
-                                  _("Album: %s - %s"), s1, s2);
+                                  _("All tracks of artist: %s"), s1);
+               else if (*album != 0) {
+                       s2 = utf8_to_locale(album);
+                       g_snprintf(str, size, _("Album: %s - %s"), s1, s2);
                        g_free(s2);
                } else
                        g_snprintf(str, size,
-                                  _("All tracks of artist: %s"), s1);
+                                  _("Tracks of no album of artist: %s"), s1);
                g_free(s1);
                break;
        }
@@ -394,12 +437,12 @@ screen_artist_update(struct mpdclient *c)
                /* the db has changed -> update the list */
                reload_lists(c);
 
-       if (c->events & (MPD_IDLE_DATABASE | MPD_IDLE_PLAYLIST))
+       if (c->events & (MPD_IDLE_DATABASE | MPD_IDLE_QUEUE))
                screen_browser_sync_highlights(browser.filelist, &c->playlist);
 
        if (c->events & (MPD_IDLE_DATABASE
 #ifndef NCMPC_MINI
-                        | MPD_IDLE_PLAYLIST
+                        | MPD_IDLE_QUEUE
 #endif
                         ))
                artist_repaint();
@@ -419,14 +462,17 @@ add_query(struct mpdclient *c, enum mpd_tag_type table, char *_filter)
 
        str = utf8_to_locale(_filter);
        if (table == MPD_TAG_ALBUM)
-               screen_status_printf("Adding album %s...", str);
+               screen_status_printf(_("Adding album %s..."), str);
        else
-               screen_status_printf("Adding %s...", str);
+               screen_status_printf(_("Adding %s..."), str);
        g_free(str);
 
        mpd_search_db_songs(connection, true);
        mpd_search_add_tag_constraint(connection, MPD_OPERATOR_DEFAULT,
                                      table, _filter);
+       if (table == MPD_TAG_ALBUM)
+               mpd_search_add_tag_constraint(connection, MPD_OPERATOR_DEFAULT,
+                                             MPD_TAG_ARTIST, artist);
        mpd_search_commit(connection);
 
        addlist = filelist_new_recv(connection);
@@ -474,6 +520,7 @@ screen_artist_cmd(struct mpdclient *c, command_t cmd)
        struct list_window_range range;
        char *selected;
        char *old;
+       char *old_ptr;
        int idx;
 
        switch(cmd) {
@@ -508,7 +555,7 @@ screen_artist_cmd(struct mpdclient *c, command_t cmd)
                                }
                        } else if (browser.lw->selected == album_list->len + 1) {
                                /* handle "show all" */
-                               open_song_list(c, g_strdup(artist), g_strdup("\0"));
+                               open_song_list(c, g_strdup(artist), ALL_TRACKS);
                                list_window_reset(browser.lw);
                        } else {
                                /* select album */
@@ -525,11 +572,12 @@ screen_artist_cmd(struct mpdclient *c, command_t cmd)
                        if (browser.lw->selected == 0) {
                                /* handle ".." */
                                old = g_strdup(album);
+                               old_ptr = album;
 
                                open_album_list(c, g_strdup(artist));
                                list_window_reset(browser.lw);
                                /* restore previous list window state */
-                               idx = *old == 0
+                               idx = old_ptr == ALL_TRACKS
                                        ? (int)album_list->len
                                        : string_array_find(album_list, old);
                                g_free(old);
@@ -571,11 +619,12 @@ screen_artist_cmd(struct mpdclient *c, command_t cmd)
 
                case LIST_SONGS:
                        old = g_strdup(album);
+                       old_ptr = album;
 
                        open_album_list(c, g_strdup(artist));
                        list_window_reset(browser.lw);
                        /* restore previous list window state */
-                       idx = *old == 0
+                       idx = old_ptr == ALL_TRACKS
                                ? (int)album_list->len
                                : string_array_find(album_list, old);
                        g_free(old);
@@ -674,13 +723,13 @@ screen_artist_cmd(struct mpdclient *c, command_t cmd)
                switch (mode) {
                case LIST_ARTISTS:
                        screen_jump(browser.lw, screen_artist_lw_callback,
-                                   NULL, artist_list);
+                                   paint_artist_callback, artist_list);
                        artist_repaint();
                        return true;
 
                case LIST_ALBUMS:
                        screen_jump(browser.lw, screen_artist_lw_callback,
-                                   NULL, album_list);
+                                   paint_album_callback, album_list);
                        artist_repaint();
                        return true;