Skip to content

Commit

Permalink
page/Container: new class
Browse files Browse the repository at this point in the history
This class makes handling of the "dirty" flag more robust and allows
removing a dirty kludge from class ProxyPage.
  • Loading branch information
MaxKellermann committed Sep 9, 2024
1 parent b0c3a4a commit fc458a8
Show file tree
Hide file tree
Showing 26 changed files with 165 additions and 153 deletions.
2 changes: 0 additions & 2 deletions src/ChatPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ ChatPage::ProcessMessage(const struct mpd_message &message)
assert(StringIsEqual(mpd_message_get_channel(&message), chat_channel));

Append(mpd_message_get_text(&message));

SetDirty();
}

void
Expand Down
6 changes: 3 additions & 3 deletions src/EditPlaylistPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class EditPlaylistPage final : public FileListPage {

public:
EditPlaylistPage(ScreenManager &_screen, const Window _window, Size size) noexcept
:FileListPage(_screen, _window, size,
:FileListPage(_screen, _screen, _window, size,
options.list_format.c_str())
{
}
Expand Down Expand Up @@ -83,7 +83,7 @@ EditPlaylistPage::Reload(struct mpdclient &c)
{
filelist = LoadPlaylist(c, name.c_str());
lw.SetLength(filelist->size());
SetDirty();
SchedulePaint();
}

void
Expand Down Expand Up @@ -178,7 +178,7 @@ EditPlaylistPage::OnMouse(struct mpdclient &c, Point p, mmask_t bstate)
}

SaveSelection();
SetDirty();
SchedulePaint();

return true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/FileBrowserPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FileBrowserPage final : public FileListPage {
public:
FileBrowserPage(ScreenManager &_screen, const Window _window,
Size size) noexcept
:FileListPage(_screen, _window, size,
:FileListPage(_screen, _screen, _window, size,
options.list_format.c_str()) {}

bool GotoSong(struct mpdclient &c, const struct mpd_song &song) noexcept;
Expand Down Expand Up @@ -100,7 +100,7 @@ FileBrowserPage::Reload(struct mpdclient &c) noexcept

lw.SetLength(filelist->size());

SetDirty();
SchedulePaint();
}

bool
Expand Down Expand Up @@ -174,7 +174,7 @@ FileBrowserPage::GotoSong(struct mpdclient &c, const struct mpd_song &song) noex
i = 0;

lw.SetCursor(i);
SetDirty();
SchedulePaint();
return true;
}

Expand Down Expand Up @@ -300,7 +300,7 @@ FileBrowserPage::Update(struct mpdclient &c, unsigned events) noexcept
#endif
)) {
screen_browser_sync_highlights(*filelist, c.playlist);
SetDirty();
SchedulePaint();
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/FileListPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ using std::string_view_literals::operator""sv;
static constexpr unsigned HIGHLIGHT = 0x01;
#endif

FileListPage::FileListPage(ScreenManager &_screen, Window _window,
FileListPage::FileListPage(PageContainer &_parent, ScreenManager &_screen, Window _window,
Size size,
const char *_song_format) noexcept
:ListPage(_window, size),
:ListPage(_parent, _window, size),
screen(_screen),
song_format(_song_format)
{
Expand Down Expand Up @@ -289,7 +289,7 @@ FileListPage::HandleSelect(struct mpdclient &c) noexcept
success = browser_select_entry(c, *entry, true);
}

SetDirty();
SchedulePaint();

return range.end_index == range.start_index + 1 && success;
}
Expand Down Expand Up @@ -342,7 +342,7 @@ FileListPage::HandleSelectAll(struct mpdclient &c) noexcept
browser_select_entry(c, entry, false);
}

SetDirty();
SchedulePaint();
}

#ifdef HAVE_GETMOUSE
Expand All @@ -368,7 +368,7 @@ FileListPage::OnMouse(struct mpdclient &c, Point p,
HandleSelect(c);
}

SetDirty();
SchedulePaint();

return true;
}
Expand All @@ -390,11 +390,11 @@ FileListPage::OnCommand(struct mpdclient &c, Command cmd)
case Command::LIST_FIND_NEXT:
case Command::LIST_RFIND_NEXT:
screen_find(screen, lw, cmd, *this);
SetDirty();
SchedulePaint();
return true;
case Command::LIST_JUMP:
screen_jump(screen, lw, *this, *this);
SetDirty();
SchedulePaint();
return true;

#ifdef ENABLE_SONG_SCREEN
Expand Down Expand Up @@ -435,13 +435,13 @@ FileListPage::OnCommand(struct mpdclient &c, Command cmd)
case Command::SELECT:
if (HandleSelect(c))
lw.HandleCommand(Command::LIST_NEXT);
SetDirty();
SchedulePaint();
return true;

case Command::ADD:
if (HandleAdd(c))
lw.HandleCommand(Command::LIST_NEXT);
SetDirty();
SchedulePaint();
return true;

#ifdef ENABLE_PLAYLIST_EDITOR
Expand Down
2 changes: 1 addition & 1 deletion src/FileListPage.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected:
const char *const song_format;

public:
FileListPage(ScreenManager &_screen, Window _window,
FileListPage(PageContainer &_parent, ScreenManager &_screen, Window _window,
Size size,
const char *_song_format) noexcept;

Expand Down
5 changes: 3 additions & 2 deletions src/HelpPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "GlobalBindings.hxx"
#include "config.h"
#include "i18n.h"
#include "screen.hxx"
#include "page/ListPage.hxx"
#include "ui/ListRenderer.hxx"
#include "ui/ListText.hxx"
Expand Down Expand Up @@ -210,7 +211,7 @@ class HelpPage final : public ListPage, ListRenderer, ListText {

public:
HelpPage(ScreenManager &_screen, const Window _window, Size size)
:ListPage(_window, size), screen(_screen) {
:ListPage(_screen, _window, size), screen(_screen) {
lw.HideCursor();
lw.SetLength(std::size(help_text));
}
Expand Down Expand Up @@ -310,7 +311,7 @@ HelpPage::OnCommand(struct mpdclient &c, Command cmd)
lw.SetCursorFromOrigin(0);

if (screen_find(screen, lw, cmd, *this)) {
SetDirty();
SchedulePaint();
return true;
}

Expand Down
23 changes: 12 additions & 11 deletions src/KeyDefPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "KeyDefPage.hxx"
#include "PageMeta.hxx"
#include "screen.hxx"
#include "screen_status.hxx"
#include "screen_find.hxx"
#include "KeyName.hxx"
Expand Down Expand Up @@ -42,9 +43,9 @@ class CommandKeysPage final : public ListPage, ListText {
unsigned n_keys = 0;

public:
CommandKeysPage(ScreenManager &_screen, Page *_parent,
CommandKeysPage(PageContainer &_container, ScreenManager &_screen, Page *_parent,
const Window _window, Size size) noexcept
:ListPage(_window, size), screen(_screen), parent(_parent) {}
:ListPage(_container, _window, size), screen(_screen), parent(_parent) {}

void SetCommand(KeyBindings *_bindings, unsigned _cmd) {
bindings = _bindings;
Expand Down Expand Up @@ -148,7 +149,7 @@ CommandKeysPage::DeleteKey(int key_index)
screen_status_message(_("Deleted"));

/* repaint */
SetDirty();
SchedulePaint();

/* update key conflict flags */
bindings->Check(nullptr, 0);
Expand Down Expand Up @@ -193,7 +194,7 @@ CommandKeysPage::OverwriteKey(int key_index)
UpdateListLength();

/* repaint */
SetDirty();
SchedulePaint();

/* update key conflict flags */
bindings->Check(nullptr, 0);
Expand Down Expand Up @@ -277,7 +278,7 @@ CommandKeysPage::OnCommand(struct mpdclient &c, Command cmd)
case Command::LIST_FIND_NEXT:
case Command::LIST_RFIND_NEXT:
screen_find(screen, lw, cmd, *this);
SetDirty();
SchedulePaint();
return true;

default:
Expand All @@ -294,8 +295,8 @@ class CommandListPage final : public ListPage, ListText {
static constexpr size_t command_n_commands = size_t(Command::NONE);

public:
CommandListPage(ScreenManager &_screen, const Window _window, Size size)
:ListPage(_window, size), screen(_screen) {}
CommandListPage(PageContainer &_container, ScreenManager &_screen, const Window _window, Size size)
:ListPage(_container, _window, size), screen(_screen) {}

~CommandListPage() override {
delete bindings;
Expand Down Expand Up @@ -485,7 +486,7 @@ CommandListPage::OnCommand(struct mpdclient &c, Command cmd)
case Command::LIST_FIND_NEXT:
case Command::LIST_RFIND_NEXT:
screen_find(screen, lw, cmd, *this);
SetDirty();
SchedulePaint();
return true;

default:
Expand All @@ -501,9 +502,9 @@ class KeyDefPage final : public ProxyPage {

public:
KeyDefPage(ScreenManager &screen, const Window _window, Size size)
:ProxyPage(_window),
command_list_page(screen, _window, size),
command_keys_page(screen, this, _window, size) {}
:ProxyPage(screen, _window),
command_list_page(*this, screen, _window, size),
command_keys_page(*this, screen, this, _window, size) {}

public:
/* virtual methods from class Page */
Expand Down
15 changes: 8 additions & 7 deletions src/LibraryPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "mpdclient.hxx"
#include "filelist.hxx"
#include "Options.hxx"
#include "screen.hxx"
#include "page/ProxyPage.hxx"
#include "lib/fmt/ToSpan.hxx"

Expand Down Expand Up @@ -56,9 +57,9 @@ class SongListPage final : public FileListPage {
TagFilter filter;

public:
SongListPage(ScreenManager &_screen, Page *_parent,
SongListPage(PageContainer &_container, ScreenManager &_screen, Page *_parent,
const Window _window, Size size) noexcept
:FileListPage(_screen, _window, size,
:FileListPage(_container, _screen, _window, size,
options.list_format.c_str()),
parent(_parent) {}

Expand Down Expand Up @@ -99,13 +100,13 @@ class LibraryTagListPage final : public TagListPage {
ArtistBrowserPage &library_page;

public:
LibraryTagListPage(ScreenManager &_screen,
LibraryTagListPage(PageContainer &_container, ScreenManager &_screen,
ArtistBrowserPage &_library_page,
Page *_parent,
const enum mpd_tag_type _tag,
const char *_all_text,
const Window _window, Size size) noexcept
:TagListPage(_screen, _parent, _tag, _all_text, _window, size),
:TagListPage(_container, _screen, _parent, _tag, _all_text, _window, size),
library_page(_library_page) {}

protected:
Expand All @@ -121,13 +122,13 @@ class ArtistBrowserPage final : public ProxyPage {
public:
ArtistBrowserPage(ScreenManager &_screen, const Window _window,
Size size)
:ProxyPage(_window),
song_list_page(_screen, this,
:ProxyPage(_screen, _window),
song_list_page(*this, _screen, this,
_window, size) {

bool first = true;
for (const auto &tag : options.library_page_tags) {
tag_list_pages.emplace_back(_screen, *this,
tag_list_pages.emplace_back(*this, _screen, *this,
first ? nullptr : this,
tag,
first ? nullptr : _("All"),
Expand Down
20 changes: 3 additions & 17 deletions src/LyricsPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,6 @@ class LyricsPage final : public TextPage, PluginResponseHandler {

void Cancel() noexcept;

/**
* Repaint and update the screen, if it is currently active.
*/
void RepaintIfActive() noexcept {
if (screen.IsVisible(*this))
Repaint();

/* XXX repaint the screen title */
}

void Set(const char *s) noexcept;

void StartPluginCycle() noexcept;
Expand Down Expand Up @@ -170,10 +160,6 @@ LyricsPage::Set(const char *s) noexcept
}

reloading = false;

/* paint new data */

RepaintIfActive();
}

void
Expand All @@ -193,7 +179,7 @@ LyricsPage::OnPluginSuccess(const char *_plugin_name,
StopPluginCycle();

/* schedule a full repaint so the page title gets updated */
screen.SchedulePaint();
SchedulePaint();
}

void
Expand All @@ -210,7 +196,7 @@ LyricsPage::OnPluginError(std::string error) noexcept
StopPluginCycle();

/* schedule a full repaint so the page title gets updated */
screen.SchedulePaint();
SchedulePaint();
}

void
Expand Down Expand Up @@ -277,7 +263,7 @@ LyricsPage::Reload() noexcept
if (plugin_cycle == nullptr && artist != nullptr && title != nullptr) {
reloading = true;
StartPluginCycle();
Repaint();
SchedulePaint();
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/OutputsPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "OutputsPage.hxx"
#include "Deleter.hxx"
#include "PageMeta.hxx"
#include "screen.hxx"
#include "screen_status.hxx"
#include "Command.hxx"
#include "screen_utils.hxx"
Expand Down Expand Up @@ -108,7 +109,7 @@ class OutputsPage final : public ListPage, ListRenderer {

public:
OutputsPage(ScreenManager &_screen, const Window window, Size size)
:ListPage(window, size), screen(_screen) {}
:ListPage(_screen, window, size), screen(_screen) {}

private:
void Clear();
Expand Down Expand Up @@ -339,7 +340,7 @@ OutputsPage::Reload(struct mpdclient &c) noexcept
#endif

lw.SetLength(items.size());
SetDirty();
SchedulePaint();

/* restore the cursor position */
lw.SetCursorHash(items, hash);
Expand Down Expand Up @@ -446,7 +447,7 @@ OutputsPage::OnCommand(struct mpdclient &c, Command cmd)
Clear();
fill_outputs_list(&c, items);
lw.SetLength(items.size());
SetDirty();
SchedulePaint();
return true;

#if LIBMPDCLIENT_CHECK_VERSION(2,18,0)
Expand Down
Loading

0 comments on commit fc458a8

Please sign in to comment.