ListWindow: convert list_window_callback_fn_t to an abstract class
[ncmpc-debian.git] / src / AlbumListPage.cxx
index ce71de1..b8b5a35 100644 (file)
@@ -48,35 +48,23 @@ CompareUTF8(const std::string &a, const std::string &b)
        return n < 0;
 }
 
-/* list_window callback */
-static const char *
-album_lw_callback(unsigned idx, void *data)
-{
-       const auto &list = *(const std::vector<std::string> *)data;
-
-       assert(idx < list.size());
-
-       const char *str_utf8 = list[idx].c_str();
-
-       static char buf[BUFSIZE];
-       g_strlcpy(buf, Utf8ToLocale(str_utf8).c_str(), sizeof(buf));
-       return buf;
-}
-
-/* list_window callback */
-static const char *
-AlbumListCallback(unsigned idx, void *data)
+const char *
+AlbumListPage::GetListItemText(unsigned idx) const
 {
-       const auto &list = *(const std::vector<std::string> *)data;
-
        if (idx == 0)
                return "..";
-       else if (idx == list.size() + 1)
+       else if (idx == album_list.size() + 1)
                return _("All tracks");
 
        --idx;
 
-       return album_lw_callback(idx, data);
+       assert(idx < album_list.size());
+
+       const char *str_utf8 = album_list[idx].c_str();
+
+       static char buf[BUFSIZE];
+       g_strlcpy(buf, Utf8ToLocale(str_utf8).c_str(), sizeof(buf));
+       return buf;
 }
 
 static void
@@ -128,21 +116,20 @@ AlbumListPage::Reload(struct mpdclient &c)
  * 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,
-                    gcc_unused unsigned y, unsigned width,
-                    bool selected, const void *data)
+void
+AlbumListPage::PaintListItem(WINDOW *w, unsigned i,
+                            gcc_unused unsigned y, unsigned width,
+                            bool selected) const
 {
-       const auto &list = *(const std::vector<std::string> *)data;
        const char *p;
        char *q = nullptr;
 
        if (i == 0)
                p = "..";
-       else if (i == list.size() + 1)
+       else if (i == album_list.size() + 1)
                p = _("All tracks");
        else
-               p = q = utf8_to_locale(list[i - 1].c_str());
+               p = q = utf8_to_locale(album_list[i - 1].c_str());
 
        screen_browser_paint_directory(w, width, selected, p);
        g_free(q);
@@ -151,7 +138,7 @@ paint_album_callback(WINDOW *w, unsigned i,
 void
 AlbumListPage::Paint() const
 {
-       lw.Paint(paint_album_callback, &album_list);
+       lw.Paint(*this);
 }
 
 const char *
@@ -241,15 +228,12 @@ AlbumListPage::OnCommand(struct mpdclient &c, command_t cmd)
        case CMD_LIST_RFIND:
        case CMD_LIST_FIND_NEXT:
        case CMD_LIST_RFIND_NEXT:
-               screen_find(screen, &lw, cmd,
-                           AlbumListCallback, &album_list);
+               screen_find(screen, &lw, cmd, *this);
                SetDirty();
                return true;
 
        case CMD_LIST_JUMP:
-               screen_jump(screen, &lw,
-                           AlbumListCallback, &album_list,
-                           paint_album_callback, &album_list);
+               screen_jump(screen, &lw, *this, *this);
                SetDirty();
                return true;