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
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,
- *this);
+ screen_jump(screen, &lw, *this, *this);
SetDirty();
return true;
#include "ListPage.hxx"
#include "ListRenderer.hxx"
+#include "ListText.hxx"
#include <vector>
#include <string>
class ScreenManager;
-class AlbumListPage final : public ListPage, ListRenderer {
+class AlbumListPage final : public ListPage, ListRenderer, ListText {
ScreenManager &screen;
std::vector<std::string> album_list;
std::string artist;
/* virtual methods from class ListRenderer */
void PaintListItem(WINDOW *w, unsigned i, unsigned y, unsigned width,
bool selected) const override;
+
+ /* virtual methods from class ListText */
+ const char *GetListItemText(unsigned i) const override;
};
#endif
return n < 0;
}
-/* list_window callback */
-static const char *
-screen_artist_lw_callback(unsigned idx, void *data)
+const char *
+ArtistListPage::GetListItemText(unsigned idx) const
{
- const auto &list = *(const std::vector<std::string> *)data;
-
- assert(idx < list.size());
+ assert(idx < artist_list.size());
- const char *str_utf8 = list[idx].c_str();
+ const char *str_utf8 = artist_list[idx].c_str();
static char buf[BUFSIZE];
g_strlcpy(buf, Utf8ToLocale(str_utf8).c_str(), sizeof(buf));
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT:
case CMD_LIST_RFIND_NEXT:
- screen_find(screen, &lw, cmd,
- screen_artist_lw_callback, &artist_list);
+ screen_find(screen, &lw, cmd, *this);
SetDirty();
return true;
case CMD_LIST_JUMP:
- screen_jump(screen, &lw,
- screen_artist_lw_callback, &artist_list,
- *this);
+ screen_jump(screen, &lw, *this, *this);
SetDirty();
return true;
#include "ListPage.hxx"
#include "ListRenderer.hxx"
+#include "ListText.hxx"
#include <vector>
#include <string>
class ScreenManager;
-class ArtistListPage final : public ListPage, ListRenderer {
+class ArtistListPage final : public ListPage, ListRenderer, ListText {
ScreenManager &screen;
std::vector<std::string> artist_list;
/* virtual methods from class ListRenderer */
void PaintListItem(WINDOW *w, unsigned i, unsigned y, unsigned width,
bool selected) const override;
+
+ /* virtual methods from class ListText */
+ const char *GetListItemText(unsigned i) const override;
};
#endif
--- /dev/null
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2018 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef LIST_TEXT_HXX
+#define LIST_TEXT_HXX
+
+class ListText {
+public:
+ virtual const char *GetListItemText(unsigned i) const = 0;
+};
+
+#endif
#include "ListWindow.hxx"
#include "ListRenderer.hxx"
+#include "ListText.hxx"
#include "config.h"
#include "options.hxx"
#include "charset.hxx"
}
bool
-ListWindow::Find(list_window_callback_fn_t callback,
- void *callback_data,
+ListWindow::Find(const ListText &text,
const char *str,
bool wrap,
bool bell_on_wrap)
do {
while (i < length) {
- const char *label = callback(i, callback_data);
+ const char *label = text.GetListItemText(i);
assert(label != nullptr);
if (match_line(label, str)) {
}
bool
-ListWindow::ReverseFind(list_window_callback_fn_t callback,
- void *callback_data,
+ListWindow::ReverseFind(const ListText &text,
const char *str,
bool wrap,
bool bell_on_wrap)
do {
while (i >= 0) {
- const char *label = callback(i, callback_data);
+ const char *label = text.GetListItemText(i);
assert(label != nullptr);
if (match_line(label, str)) {
#ifdef NCMPC_MINI
bool
-ListWindow::Jump(list_window_callback_fn_t callback,
- void *callback_data,
- const char *str)
+ListWindow::Jump(const ListText &text, const char *str)
{
assert(str != nullptr);
for (unsigned i = 0; i < length; i++) {
- const char *label = callback(i, callback_data);
+ const char *label = text.GetListItemText(i);
assert(label != nullptr);
if (g_ascii_strncasecmp(label, str, strlen(str)) == 0) {
}
#else
bool
-ListWindow::Jump(list_window_callback_fn_t callback,
- void *callback_data,
- const char *str)
+ListWindow::Jump(const ListText &text, const char *str)
{
assert(str != nullptr);
return false;
for (unsigned i = 0; i < length; i++) {
- const char *label = callback(i, callback_data);
+ const char *label = text.GetListItemText(i);
assert(label != nullptr);
if (match_regex(regex, label)) {
#include "ncmpc_curses.h"
#include "Size.hxx"
+class ListText;
class ListRenderer;
-typedef const char *
-(*list_window_callback_fn_t)(unsigned i, void *data);
-
/**
* The bounds of a range selection, see list_window_get_range().
*/
/**
* Find a string in a list window.
*/
- bool Find(list_window_callback_fn_t callback, void *callback_data,
+ bool Find(const ListText &text,
const char *str,
bool wrap,
bool bell_on_wrap);
/**
* Find a string in a list window (reversed).
*/
- bool ReverseFind(list_window_callback_fn_t callback,
- void *callback_data,
+ bool ReverseFind(const ListText &text,
const char *str,
bool wrap,
bool bell_on_wrap);
* Find a string in a list window which begins with the given
* characters in *str.
*/
- bool Jump(list_window_callback_fn_t callback, void *callback_data,
- const char *str);
+ bool Jump(const ListText &text, const char *str);
private:
gcc_pure
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "config.h"
#include "TextListRenderer.hxx"
+#include "ListText.hxx"
#include "paint.hxx"
#include <assert.h>
TextListRenderer::PaintListItem(WINDOW *w, unsigned i, unsigned,
unsigned width, bool selected) const
{
- const char *label = callback(i, callback_data);
+ const char *label = text.GetListItemText(i);
assert(label != nullptr);
list_window_paint_row(w, width, selected, label);
#ifndef NCMPC_TEXT_LIST_RENDERER_HXX
#define NCMPC_TEXT_LIST_RENDERER_HXX
-#include "ListWindow.hxx"
#include "ListRenderer.hxx"
class ScreenManager;
+class ListText;
class TextListRenderer final : public ListRenderer {
- list_window_callback_fn_t callback;
- void *callback_data;
+ const ListText &text;
public:
- TextListRenderer(list_window_callback_fn_t _callback,
- void *_callback_data)
- :callback(_callback), callback_data(_callback_data) {}
+ explicit TextListRenderer(const ListText &_text)
+ :text(_text) {}
/* virtual methods from class ListRenderer */
void PaintListItem(WINDOW *w, unsigned i, unsigned y, unsigned width,
}
const char *
-TextPage::ListCallback(unsigned idx) const
+TextPage::GetListItemText(unsigned idx) const
{
assert(idx < lines.size());
void
TextPage::Paint() const
{
- lw.Paint(TextListRenderer(ListCallback, const_cast<TextPage *>(this)));
+ lw.Paint(TextListRenderer(*this));
}
bool
return true;
lw.SetCursor(lw.start);
- if (screen_find(screen, &lw, cmd, ListCallback, this)) {
+ if (screen_find(screen, &lw, cmd, *this)) {
/* center the row */
lw.Center(lw.selected);
SetDirty();
#define TEXT_PAGE_HXX
#include "ListPage.hxx"
+#include "ListText.hxx"
#include <vector>
#include <string>
struct mpdclient;
class ScreenManager;
-class TextPage : public ListPage {
+class TextPage : public ListPage, ListText {
protected:
ScreenManager &screen;
wrefresh(lw.w);
}
-private:
- const char *ListCallback(unsigned idx) const;
-
- static const char *ListCallback(unsigned idx, void *data) {
- const auto &p = *(const TextPage *)data;
- return p.ListCallback(idx);
- }
-
public:
/* virtual methods from class Page */
void Paint() const override;
bool OnCommand(struct mpdclient &c, command_t cmd) override;
+
+private:
+ /* virtual methods from class ListText */
+ const char *GetListItemText(unsigned i) const override;
};
#endif
#endif
-/* list_window callback */
-static const char *
-browser_lw_callback(unsigned idx, void *data)
+const char *
+FileListPage::GetListItemText(unsigned idx) const
{
- const auto *fl = (const FileList *) data;
static char buf[BUFSIZE];
- assert(fl != nullptr);
- assert(idx < fl->size());
+ assert(filelist != nullptr);
+ assert(idx < filelist->size());
- const auto &entry = (*fl)[idx];
+ const auto &entry = (*filelist)[idx];
const auto *entity = entry.entity;
if( entity == nullptr )
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT:
case CMD_LIST_RFIND_NEXT:
- screen_find(screen, &lw, cmd, browser_lw_callback, filelist);
+ screen_find(screen, &lw, cmd, *this);
SetDirty();
return true;
case CMD_LIST_JUMP:
- screen_jump(screen, &lw,
- browser_lw_callback, filelist,
- *this);
+ screen_jump(screen, &lw, *this, *this);
SetDirty();
return true;
#include "ncmpc_curses.h"
#include "ListPage.hxx"
#include "ListRenderer.hxx"
+#include "ListText.hxx"
struct mpdclient;
struct MpdQueue;
class FileList;
struct FileListEntry;
-class FileListPage : public ListPage, ListRenderer {
+class FileListPage : public ListPage, ListRenderer, ListText {
protected:
ScreenManager &screen;
unsigned y, unsigned width,
bool selected) const final;
+ /* virtual methods from class ListText */
+ const char *GetListItemText(unsigned i) const override;
+
public:
/* virtual methods from class Page */
void Paint() const override;
#include "screen_utils.hxx"
#include "screen_status.hxx"
#include "screen.hxx"
+#include "ListWindow.hxx"
#include "keyboard.hxx"
#include "i18n.h"
#include "options.hxx"
/* query user for a string and find it in a list window */
bool
screen_find(ScreenManager &screen, ListWindow *lw, command_t findcmd,
- list_window_callback_fn_t callback_fn,
- void *callback_data)
+ const ListText &text)
{
bool found;
const char *prompt = FIND_PROMPT;
return true;
found = reversed
- ? lw->ReverseFind(callback_fn, callback_data,
+ ? lw->ReverseFind(text,
screen.findbuf.c_str(),
options.find_wrap,
options.bell_on_wrap)
- : lw->Find(callback_fn, callback_data,
+ : lw->Find(text,
screen.findbuf.c_str(),
options.find_wrap,
options.bell_on_wrap);
* which begins with this string while the users types */
void
screen_jump(ScreenManager &screen, ListWindow *lw,
- list_window_callback_fn_t callback_fn, void *callback_data,
+ const ListText &text,
const ListRenderer &renderer)
{
constexpr size_t WRLN_MAX_LINE_SIZE = 1024;
if (iter < buffer + WRLN_MAX_LINE_SIZE - 3)
++iter;
}
- lw->Jump(callback_fn, callback_data, search_str);
+ lw->Jump(text, search_str);
/* repaint the list_window */
lw->Paint(renderer);
#define NCMPC_SCREEN_FIND_H
#include "command.hxx"
-#include "ListWindow.hxx"
class ScreenManager;
+class ListWindow;
class ListRenderer;
+class ListText;
/**
* query user for a string and find it in a list window
bool
screen_find(ScreenManager &screen, ListWindow *lw,
command_t findcmd,
- list_window_callback_fn_t callback_fn,
- void *callback_data);
+ const ListText &text);
/* query user for a string and jump to the entry
* which begins with this string while the users types */
void
screen_jump(ScreenManager &screen, ListWindow *lw,
- list_window_callback_fn_t callback_fn, void *callback_data,
- const ListRenderer &renderer);
+ const ListText &text, const ListRenderer &renderer);
#endif
#include "screen_interface.hxx"
#include "ListPage.hxx"
#include "ListRenderer.hxx"
+#include "ListText.hxx"
#include "screen_find.hxx"
#include "paint.hxx"
#include "charset.hxx"
#endif
};
-class HelpPage final : public ListPage, ListRenderer {
+class HelpPage final : public ListPage, ListRenderer, ListText {
ScreenManager &screen;
public:
unsigned y, unsigned width,
bool selected) const override;
+ /* virtual methods from class ListText */
+ const char *GetListItemText(unsigned i) const override;
+
/* virtual methods from class Page */
void Paint() const override;
bool OnCommand(struct mpdclient &c, command_t cmd) override;
}
};
-static const char *
-list_callback(unsigned i, gcc_unused void *data)
+const char *
+HelpPage::GetListItemText(unsigned i) const
{
const struct help_text_row *row = &help_text[i];
return true;
lw.SetCursor(lw.start);
- if (screen_find(screen, &lw, cmd, list_callback, nullptr)) {
+ if (screen_find(screen, &lw, cmd, *this)) {
/* center the row */
lw.Center(lw.selected);
SetDirty();
#include "screen_keydef.hxx"
#include "screen_interface.hxx"
#include "ListPage.hxx"
+#include "ListText.hxx"
#include "TextListRenderer.hxx"
#include "ProxyPage.hxx"
#include "screen_status.hxx"
#include <string.h>
#include <glib.h>
-class CommandKeysPage final : public ListPage {
+class CommandKeysPage final : public ListPage, ListText {
ScreenManager &screen;
command_definition_t *cmds;
*/
void AddKey(int cmd_index);
- const char *ListCallback(unsigned idx) const;
-
- static const char *ListCallback(unsigned idx, void *data) {
- const auto &p = *(const CommandKeysPage *)data;
- return p.ListCallback(idx);
- }
-
public:
/* virtual methods from class Page */
void OnOpen(struct mpdclient &c) override;
void Paint() const override;
bool OnCommand(struct mpdclient &c, command_t cmd) override;
const char *GetTitle(char *s, size_t size) const override;
+
+private:
+ /* virtual methods from class ListText */
+ const char *GetListItemText(unsigned i) const override;
};
/* TODO: rename to check_n_keys / subcmd_count_keys? */
}
const char *
-CommandKeysPage::ListCallback(unsigned idx) const
+CommandKeysPage::GetListItemText(unsigned idx) const
{
static char buf[256];
void
CommandKeysPage::Paint() const
{
- lw.Paint(TextListRenderer(ListCallback,
- const_cast<CommandKeysPage *>(this)));
+ lw.Paint(TextListRenderer(*this));
}
bool
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT:
case CMD_LIST_RFIND_NEXT:
- screen_find(screen, &lw, cmd, ListCallback, this);
+ screen_find(screen, &lw, cmd, *this);
SetDirty();
return true;
return false;
}
-class CommandListPage final : public ListPage {
+class CommandListPage final : public ListPage, ListText {
ScreenManager &screen;
command_definition_t *cmds = nullptr;
void Apply();
void Save();
-private:
- const char *ListCallback(unsigned idx) const;
-
- static const char *ListCallback(unsigned idx, void *data) {
- const auto &p = *(const CommandListPage *)data;
- return p.ListCallback(idx);
- }
-
public:
/* virtual methods from class Page */
void OnOpen(struct mpdclient &c) override;
void Paint() const override;
bool OnCommand(struct mpdclient &c, command_t cmd) override;
const char *GetTitle(char *s, size_t size) const override;
+
+private:
+ /* virtual methods from class ListText */
+ const char *GetListItemText(unsigned i) const override;
};
bool
}
const char *
-CommandListPage::ListCallback(unsigned idx) const
+CommandListPage::GetListItemText(unsigned idx) const
{
static char buf[256];
void
CommandListPage::Paint() const
{
- lw.Paint(TextListRenderer(ListCallback,
- const_cast<CommandListPage *>(this)));
+ lw.Paint(TextListRenderer(*this));
}
bool
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT:
case CMD_LIST_RFIND_NEXT:
- screen_find(screen, &lw, cmd, ListCallback, this);
+ screen_find(screen, &lw, cmd, *this);
SetDirty();
return true;
#include "screen_interface.hxx"
#include "ListPage.hxx"
#include "ListRenderer.hxx"
+#include "ListText.hxx"
#include "screen_file.hxx"
#include "screen_status.hxx"
#include "screen_find.hxx"
#define MAX_SONG_LENGTH 512
-class QueuePage final : public ListPage, ListRenderer {
+class QueuePage final : public ListPage, ListRenderer, ListText {
ScreenManager &screen;
#ifndef NCMPC_MINI
unsigned y, unsigned width,
bool selected) const override;
+ /* virtual methods from class ListText */
+ const char *GetListItemText(unsigned i) const override;
+
public:
/* virtual methods from class Page */
void OnOpen(struct mpdclient &c) override;
SaveSelection();
}
-static const char *
-screen_queue_lw_callback(unsigned idx, void *data)
+const char *
+QueuePage::GetListItemText(unsigned idx) const
{
- auto &playlist = *(MpdQueue *)data;
static char songname[MAX_SONG_LENGTH];
- assert(idx < playlist.size());
+ assert(idx < playlist->size());
- const auto &song = playlist[idx];
+ const auto &song = (*playlist)[idx];
strfsong(songname, MAX_SONG_LENGTH, options.list_format, &song);
return songname;
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT:
case CMD_LIST_RFIND_NEXT:
- screen_find(screen, &lw, cmd,
- screen_queue_lw_callback, &c.playlist);
+ screen_find(screen, &lw, cmd, *this);
SaveSelection();
SetDirty();
return true;
case CMD_LIST_JUMP:
- screen_jump(screen, &lw, screen_queue_lw_callback, &c.playlist,
- *this);
+ screen_jump(screen, &lw, *this, *this);
SaveSelection();
SetDirty();
return true;
};
/* search info */
-static const char *
-lw_search_help_callback(unsigned idx, gcc_unused void *data)
-{
- assert(idx < G_N_ELEMENTS(help_text));
+class SearchHelpText final : public ListText {
+public:
+ /* virtual methods from class ListText */
+ const char *GetListItemText(unsigned idx) const override {
+ assert(idx < G_N_ELEMENTS(help_text));
- return help_text[idx];
-}
+ return help_text[idx];
+ }
+};
void
SearchPage::Clear(bool clear_pattern)
if (filelist) {
FileListPage::Paint();
} else {
- lw.Paint(TextListRenderer(lw_search_help_callback, nullptr));
+ lw.Paint(TextListRenderer(SearchHelpText()));
}
}
#include "screen_song.hxx"
#include "screen_interface.hxx"
#include "ListPage.hxx"
+#include "ListText.hxx"
#include "TextListRenderer.hxx"
#include "screen_file.hxx"
#include "screen_lyrics.hxx"
static struct mpd_song *next_song;
-class SongPage final : public ListPage {
+class SongPage final : public ListPage, ListText {
ScreenManager &screen;
mpd_song *selected_song = nullptr;
void Update(struct mpdclient &c, unsigned events) override;
bool OnCommand(struct mpdclient &c, command_t cmd) override;
const char *GetTitle(char *s, size_t size) const override;
+
+private:
+ /* virtual methods from class ListText */
+ const char *GetListItemText(unsigned i) const override;
};
void
}
}
-static const char *
-screen_song_list_callback(unsigned idx, void *data)
+const char *
+SongPage::GetListItemText(unsigned idx) const
{
- const auto &lines = *(const std::vector<std::string> *)data;
-
return lines[idx].c_str();
}
void
SongPage::Paint() const
{
- lw.Paint(TextListRenderer(screen_song_list_callback,
- const_cast<void *>((const void *)&lines)));
+ lw.Paint(TextListRenderer(*this));
}
void
break;
}
- if (screen_find(screen, &lw, cmd, screen_song_list_callback, &lines)) {
+ if (screen_find(screen, &lw, cmd, *this)) {
/* center the row */
lw.Center(lw.selected);
SetDirty();