Code

use libmpdclient2
[ncmpc.git] / src / screen_artist.c
index 86291d87de633712542f7459a5a329d682ba919b..f6de9dde00621d6dbe9b697aeac481e01ebfd4c4 100644 (file)
@@ -1,20 +1,21 @@
-/*
- * (c) 2005 by Kalle Wallin <kaw@linux.se>
- *
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2009 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- *
+
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
+
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
 
 #include "i18n.h"
 #include "options.h"
 #include "screen.h"
 #include "screen_utils.h"
 #include "screen_browser.h"
-#include "gcc.h"
 
 #include <ctype.h>
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
-#include <ncurses.h>
 
 #define BUFSIZE 1024
 
@@ -61,7 +60,8 @@ compare_utf8(gconstpointer s1, gconstpointer s2)
 
 /* list_window callback */
 static const char *
-artist_lw_callback(unsigned idx, mpd_unused int *highlight, mpd_unused void *data)
+artist_lw_callback(unsigned idx, G_GNUC_UNUSED bool *highlight,
+                  G_GNUC_UNUSED char** sc, G_GNUC_UNUSED void *data)
 {
        GPtrArray *list = data;
        static char buf[BUFSIZE];
@@ -94,12 +94,12 @@ artist_lw_callback(unsigned idx, mpd_unused int *highlight, mpd_unused void *dat
 }
 
 static void
-paint(mpdclient_t *c);
+paint(void);
 
 static void
 artist_repaint(void)
 {
-       paint(NULL);
+       paint();
        wrefresh(browser.lw->w);
 }
 
@@ -110,7 +110,8 @@ artist_repaint_if_active(void)
                artist_repaint();
 }
 
-/* the playlist have been updated -> fix highlights */
+#ifndef NCMPC_MINI
+/* the playlist has been updated -> fix highlights */
 static void
 playlist_changed_callback(mpdclient_t *c, int event, gpointer data)
 {
@@ -118,6 +119,7 @@ playlist_changed_callback(mpdclient_t *c, int event, gpointer data)
 
        artist_repaint_if_active();
 }
+#endif
 
 static GPtrArray *
 g_list_to_ptr_array(GList *in)
@@ -141,14 +143,14 @@ string_array_free(GPtrArray *array)
 
        for (i = 0; i < array->len; ++i) {
                char *value = g_ptr_array_index(array, i);
-               free(value);
+               g_free(value);
        }
 
        g_ptr_array_free(array, TRUE);
 }
 
 static void
-free_lists(struct mpdclient *c)
+free_lists(G_GNUC_UNUSED struct mpdclient *c)
 {
        if (artist_list != NULL) {
                string_array_free(artist_list);
@@ -161,8 +163,10 @@ free_lists(struct mpdclient *c)
        }
 
        if (browser.filelist) {
+#ifndef NCMPC_MINI
                if (c != NULL)
                        mpdclient_remove_playlist_callback(c, playlist_changed_callback);
+#endif
                filelist_free(browser.filelist);
                browser.filelist = NULL;
        }
@@ -180,7 +184,7 @@ load_artist_list(struct mpdclient *c)
        assert(album_list == NULL);
        assert(browser.filelist == NULL);
 
-       list = mpdclient_get_artists_utf8(c);
+       list = mpdclient_get_artists(c);
        /* sort list */
        list = g_list_sort(list, compare_utf8);
 
@@ -198,7 +202,7 @@ load_album_list(struct mpdclient *c)
        assert(album_list == NULL);
        assert(browser.filelist == NULL);
 
-       list = mpdclient_get_albums_utf8(c, artist);
+       list = mpdclient_get_albums(c, artist);
        /* sort list */
        list = g_list_sort(list, compare_utf8);
 
@@ -215,23 +219,25 @@ load_song_list(struct mpdclient *c)
 
        if (album[0] == 0)
                browser.filelist =
-                       mpdclient_filelist_search_utf8(c, TRUE,
-                                                      MPD_TABLE_ARTIST,
-                                                      artist);
+                       mpdclient_filelist_search(c, TRUE,
+                                                 MPD_TAG_ARTIST,
+                                                 artist);
        else
                browser.filelist =
-                       mpdclient_filelist_search_utf8(c, TRUE,
-                                                      MPD_TABLE_ALBUM,
-                                                      album);
+                       mpdclient_filelist_search(c, TRUE,
+                                                 MPD_TAG_ALBUM,
+                                                 album);
        if (browser.filelist == NULL)
-               browser.filelist = filelist_new(NULL);
+               browser.filelist = filelist_new();
 
        /* add a dummy entry for ".." */
        filelist_prepend(browser.filelist, NULL);
 
+#ifndef NCMPC_MINI
        /* install playlist callback and fix highlights */
        sync_highlights(c, browser.filelist);
        mpdclient_install_playlist_callback(c, playlist_changed_callback);
+#endif
 }
 
 static void
@@ -302,7 +308,7 @@ reload_lists(struct mpdclient *c)
 
 /* db updated */
 static void
-browse_callback(mpdclient_t *c, int event, mpd_unused gpointer data)
+browse_callback(mpdclient_t *c, int event, G_GNUC_UNUSED gpointer data)
 {
        switch(event) {
        case BROWSE_DB_UPDATED:
@@ -331,7 +337,7 @@ quit(void)
 }
 
 static void
-open(mpd_unused screen_t *screen, mpdclient_t *c)
+open(mpdclient_t *c)
 {
        static gboolean callback_installed = FALSE;
 
@@ -352,7 +358,7 @@ resize(int cols, int rows)
 }
 
 static void
-paint(mpd_unused mpdclient_t *c)
+paint(void)
 {
        if (browser.filelist) {
                list_window_paint(browser.lw, browser_lw_callback,
@@ -401,7 +407,7 @@ get_title(char *str, size_t size)
 }
 
 static void
-add_query(mpdclient_t *c, int table, char *_filter)
+add_query(mpdclient_t *c, enum mpd_tag_type table, char *_filter)
 {
        char *str;
        mpdclient_filelist_t *addlist;
@@ -409,13 +415,13 @@ add_query(mpdclient_t *c, int table, char *_filter)
        assert(filter != NULL);
 
        str = utf8_to_locale(_filter);
-       if (table== MPD_TABLE_ALBUM)
+       if (table == MPD_TAG_ALBUM)
                screen_status_printf("Adding album %s...", str);
        else
                screen_status_printf("Adding %s...", str);
        g_free(str);
 
-       addlist = mpdclient_filelist_search_utf8(c, TRUE, table, _filter);
+       addlist = mpdclient_filelist_search(c, TRUE, table, _filter);
        if (addlist) {
                mpdclient_filelist_add_all(c, addlist);
                filelist_free(addlist);
@@ -434,7 +440,7 @@ metalist_length(void)
 }
 
 static int
-artist_lw_cmd(struct screen *screen, struct mpdclient *c, command_t cmd)
+artist_lw_cmd(struct mpdclient *c, command_t cmd)
 {
        switch (mode) {
        case LIST_ARTISTS:
@@ -442,7 +448,7 @@ artist_lw_cmd(struct screen *screen, struct mpdclient *c, command_t cmd)
                return list_window_cmd(browser.lw, metalist_length(), cmd);
 
        case LIST_SONGS:
-               return browser_cmd(&browser, screen, c, cmd);
+               return browser_cmd(&browser, c, cmd);
        }
 
        assert(0);
@@ -462,8 +468,8 @@ string_array_find(GPtrArray *array, const char *value)
        return -1;
 }
 
-static int
-artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
+static bool
+artist_cmd(mpdclient_t *c, command_t cmd)
 {
        char *selected;
        char *old;
@@ -606,22 +612,33 @@ artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
        case CMD_ADD:
                switch(mode) {
                case LIST_ARTISTS:
-                       selected = g_ptr_array_index(artist_list,
-                                                    browser.lw->selected);
-                       add_query(c, MPD_TABLE_ARTIST, selected);
-                       cmd = CMD_LIST_NEXT; /* continue and select next item... */
+               {
+                       unsigned i;
+                       for(i = browser.lw->selected_start; i <= browser.lw->selected_end; ++i)
+                       {
+                               selected = g_ptr_array_index(artist_list, i);
+                               add_query(c, MPD_TAG_ARTIST, selected);
+                               cmd = CMD_LIST_NEXT; /* continue and select next item... */
+                       }
                        break;
-
+               }
                case LIST_ALBUMS:
-                       if (browser.lw->selected == album_list->len + 1)
-                               add_query(c, MPD_TABLE_ARTIST, artist);
-                       else if (browser.lw->selected > 0) {
-                               selected = g_ptr_array_index(album_list,
-                                                            browser.lw->selected - 1);
-                               add_query(c, MPD_TABLE_ALBUM, selected);
-                               cmd = CMD_LIST_NEXT; /* continue and select next item... */
+               {
+                       unsigned i;
+                       for(i = browser.lw->selected_start; i <= browser.lw->selected_end; ++i)
+                       {
+                               if(i == album_list->len + 1)
+                                       add_query(c, MPD_TAG_ARTIST, artist);
+                               else if (i > 0)
+                               {
+                                       selected = g_ptr_array_index(album_list,
+                                                                    browser.lw->selected - 1);
+                                       add_query(c, MPD_TAG_ALBUM, selected);
+                                       cmd = CMD_LIST_NEXT; /* continue and select next item... */
+                               }
                        }
                        break;
+               }
 
                case LIST_SONGS:
                        /* handled by browser_cmd() */
@@ -632,8 +649,7 @@ artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
                /* continue and update... */
        case CMD_SCREEN_UPDATE:
                reload_lists(c);
-               screen_status_printf(_("Screen updated!"));
-               return 0;
+               return false;
 
        case CMD_LIST_FIND:
        case CMD_LIST_RFIND:
@@ -641,18 +657,32 @@ artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
        case CMD_LIST_RFIND_NEXT:
                switch (mode) {
                case LIST_ARTISTS:
-                       screen_find(screen,
-                                   browser.lw, artist_list->len,
+                       screen_find(browser.lw, artist_list->len,
                                    cmd, artist_lw_callback, artist_list);
                        artist_repaint();
-                       return 1;
+                       return true;
 
                case LIST_ALBUMS:
-                       screen_find(screen,
-                                   browser.lw, album_list->len + 2,
+                       screen_find(browser.lw, album_list->len + 2,
                                    cmd, artist_lw_callback, album_list);
                        artist_repaint();
-                       return 1;
+                       return true;
+
+               case LIST_SONGS:
+                       /* handled by browser_cmd() */
+                       break;
+               }
+       case CMD_LIST_JUMP:
+               switch (mode) {
+               case LIST_ARTISTS:
+                       screen_jump(browser.lw, artist_lw_callback, artist_list);
+                       artist_repaint();
+                       return true;
+
+               case LIST_ALBUMS:
+                       screen_jump(browser.lw, artist_lw_callback, album_list);
+                       artist_repaint();
+                       return true;
 
                case LIST_SONGS:
                        /* handled by browser_cmd() */
@@ -665,12 +695,13 @@ artist_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
                break;
        }
 
-       if (artist_lw_cmd(screen, c, cmd)) {
-               artist_repaint();
-               return 1;
+       if (artist_lw_cmd(c, cmd)) {
+               if (screen_is_visible(&screen_artist))
+                       artist_repaint();
+               return true;
        }
 
-       return 0;
+       return false;
 }
 
 const struct screen_functions screen_artist = {