Skip to content

Commit

Permalink
page/Container: add method Alert()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Sep 10, 2024
1 parent 1985451 commit 1a00084
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/ChatPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ ChatPage::EnterMessage(struct mpdclient &c)
if (CheckChatSupport(c))
SendMessage(c, message.c_str());
else
screen_status_message(_("Message could not be sent"));
Alert(_("Message could not be sent"));
}

bool
Expand Down
4 changes: 2 additions & 2 deletions src/FileBrowserPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ FileBrowserPage::HandleDelete(struct mpdclient &c)
/* translators: the "delete" command is only possible
for playlists; the user attempted to delete a song
or a directory or something else */
screen_status_message(_("Deleting this item is not possible"));
Alert(_("Deleting this item is not possible"));
Bell();
continue;
}
Expand All @@ -260,7 +260,7 @@ FileBrowserPage::HandleDelete(struct mpdclient &c)

/* translators: MPD deleted the playlist, as requested by the
user */
screen_status_message(_("Playlist deleted"));
Alert(_("Playlist deleted"));
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/KeyDefPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ CommandKeysPage::DeleteKey(int key_index)
binding->modified = true;
UpdateListLength();

screen_status_message(_("Deleted"));
Alert(_("Deleted"));

/* repaint */
SchedulePaint();
Expand All @@ -166,12 +166,12 @@ CommandKeysPage::OverwriteKey(int key_index)
const int key = screen_getch(screen, prompt);

if (key == ERR) {
screen_status_message(_("Aborted"));
Alert(_("Aborted"));
return;
}

if (key == '\0') {
screen_status_message(_("Ctrl-Space can't be used"));
Alert(_("Ctrl-Space can't be used"));
return;
}

Expand Down Expand Up @@ -369,9 +369,9 @@ CommandListPage::Apply()
if (IsModified()) {
auto &orginal_bindings = GetGlobalKeyBindings();
orginal_bindings = *bindings;
screen_status_message(_("You have new key bindings"));
Alert(_("You have new key bindings"));
} else
screen_status_message(_("Keybindings unchanged."));
Alert(_("Keybindings unchanged."));
}

void
Expand All @@ -381,7 +381,7 @@ CommandListPage::Save()
if (options.key_file.empty()) {
filename = MakeKeysPath();
if (filename.empty()) {
screen_status_message(_("Unable to write configuration"));
Alert(_("Unable to write configuration"));
Bell();
return;
}
Expand Down Expand Up @@ -529,7 +529,7 @@ void
KeyDefPage::OnClose() noexcept
{
if (command_list_page.IsModified())
screen_status_message(_("Note: Did you forget to \'Apply\' your changes?"));
Alert(_("Note: Did you forget to \'Apply\' your changes?"));

ProxyPage::OnClose();
}
Expand Down
16 changes: 8 additions & 8 deletions src/LyricsPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ LyricsPage::OnPluginError(std::string error) noexcept
Set(error.c_str());

/* translators: no lyrics were found for the song */
screen_status_message(_("No lyrics"));
Alert(_("No lyrics"));

plugin_timeout.Cancel();
StopPluginCycle();
Expand Down Expand Up @@ -330,12 +330,12 @@ LyricsPage::Edit() noexcept
{
const auto path = cache.MakePath(artist, title);
if (path.empty()) {
screen_status_message(_("Lyrics cache is unavailable"));
Alert(_("Lyrics cache is unavailable"));
return;
}

if (options.text_editor.empty()) {
screen_status_message(_("Editor not configured"));
Alert(_("Editor not configured"));
return;
}

Expand Down Expand Up @@ -373,7 +373,7 @@ LyricsPage::Edit() noexcept
/* update to get the changes */
Reload();
else if (WEXITSTATUS(status) == 127)
screen_status_message(_("Can't start editor"));
Alert(_("Can't start editor"));
else
screen_status_printf("%s (%d)",
_("Editor exited unexpectedly"),
Expand Down Expand Up @@ -402,14 +402,14 @@ LyricsPage::OnCommand(struct mpdclient &c, Command cmd)
if (plugin_cycle == nullptr && artist != nullptr &&
title != nullptr && Save())
/* lyrics for the song were saved on hard disk */
screen_status_message (_("Lyrics saved"));
Alert (_("Lyrics saved"));
return true;
case Command::DELETE:
if (plugin_cycle == nullptr && artist != nullptr &&
title != nullptr) {
screen_status_message(cache.Delete(artist, title)
? _("Lyrics deleted")
: _("No saved lyrics"));
Alert(cache.Delete(artist, title)
? _("Lyrics deleted")
: _("No saved lyrics"));
}
return true;
case Command::LYRICS_UPDATE:
Expand Down
2 changes: 1 addition & 1 deletion src/Main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ Instance::OnCheckKeyBindings() noexcept
process */
return;

screen_status_message(buf);
screen_manager.Alert(buf);

doupdate();

Expand Down
2 changes: 1 addition & 1 deletion src/QueuePage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ QueuePage::OnCommand(struct mpdclient &c, Command cmd)

if (mpd_run_shuffle_range(connection, range.start_index,
range.end_index))
screen_status_message(_("Shuffled queue"));
Alert(_("Shuffled queue"));
else
c.HandleError();
return true;
Expand Down
7 changes: 7 additions & 0 deletions src/page/Container.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#pragma once

#include <string>

class Page;

/**
Expand All @@ -12,4 +14,9 @@ class Page;
class PageContainer {
public:
virtual void SchedulePaint(Page &page) noexcept = 0;

/**
* Show a message in the status bar.
*/
virtual void Alert(std::string message) noexcept = 0;
};
6 changes: 6 additions & 0 deletions src/page/Page.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ Page::SchedulePaint() noexcept
parent.SchedulePaint(*this);
}

void
Page::Alert(std::string message) noexcept
{
parent.Alert(std::move(message));
}

bool
Page::PaintStatusBarOverride(Window) const noexcept
{
Expand Down
2 changes: 2 additions & 0 deletions src/page/Page.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ protected:

void SchedulePaint() noexcept;

void Alert(std::string message) noexcept;

/**
* Start a coroutine. This method returns when the coroutine
* finishes or gets suspended. When the coroutine finishes,
Expand Down
6 changes: 6 additions & 0 deletions src/page/ProxyPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,9 @@ ProxyPage::SchedulePaint(Page &page) noexcept
if (&page == current_page)
SchedulePaint();
}

void
ProxyPage::Alert(std::string message) noexcept
{
Page::Alert(std::move(message));
}
1 change: 1 addition & 0 deletions src/page/ProxyPage.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ public:

// virtual methods from PageContainer
void SchedulePaint(Page &page) noexcept override;
void Alert(std::string message) noexcept override;
};
59 changes: 31 additions & 28 deletions src/screen.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -149,33 +149,30 @@ ScreenManager::Update(struct mpdclient &c, const DelayedSeek &seek) noexcept
}

if (repeat != mpd_status_get_repeat(c.status))
screen_status_message(mpd_status_get_repeat(c.status) ?
_("Repeat mode is on") :
_("Repeat mode is off"));
Alert(mpd_status_get_repeat(c.status) ?
_("Repeat mode is on") :
_("Repeat mode is off"));

if (random_enabled != mpd_status_get_random(c.status))
screen_status_message(mpd_status_get_random(c.status) ?
_("Random mode is on") :
_("Random mode is off"));
Alert(mpd_status_get_random(c.status) ?
_("Random mode is on") :
_("Random mode is off"));

if (single != mpd_status_get_single(c.status))
screen_status_message(mpd_status_get_single(c.status) ?
/* "single" mode means
that MPD will
automatically stop
after playing one
single song */
_("Single mode is on") :
_("Single mode is off"));
Alert(mpd_status_get_single(c.status) ?
/* "single" mode means that MPD will
automatically stop after playing one
single song */
_("Single mode is on") :
_("Single mode is off"));

if (consume != mpd_status_get_consume(c.status))
screen_status_message(mpd_status_get_consume(c.status) ?
/* "consume" mode means
that MPD removes each
song which has
finished playing */
_("Consume mode is on") :
_("Consume mode is off"));
Alert(mpd_status_get_consume(c.status) ?
/* "consume" mode means that MPD removes
each song which has finished
playing */
_("Consume mode is on") :
_("Consume mode is off"));

if (crossfade != mpd_status_get_crossfade(c.status))
screen_status_printf(_("Crossfade %d seconds"),
Expand All @@ -190,7 +187,7 @@ ScreenManager::Update(struct mpdclient &c, const DelayedSeek &seek) noexcept

if ((events & MPD_IDLE_DATABASE) != 0 && was_connected &&
now_connected)
screen_status_message(_("Database updated"));
Alert(_("Database updated"));
was_connected = now_connected;
#endif

Expand Down Expand Up @@ -233,16 +230,16 @@ ScreenManager::OnCommand(struct mpdclient &c, DelayedSeek &seek, Command cmd)
switch(cmd) {
case Command::TOGGLE_FIND_WRAP:
ui_options.find_wrap = !ui_options.find_wrap;
screen_status_message(ui_options.find_wrap ?
_("Find mode: Wrapped") :
_("Find mode: Normal"));
Alert(ui_options.find_wrap ?
_("Find mode: Wrapped") :
_("Find mode: Normal"));
return;

case Command::TOGGLE_AUTOCENTER:
options.auto_center = !options.auto_center;
screen_status_message(options.auto_center ?
_("Auto center mode: On") :
_("Auto center mode: Off"));
Alert(options.auto_center ?
_("Auto center mode: On") :
_("Auto center mode: Off"));
return;

case Command::SCREEN_UPDATE:
Expand Down Expand Up @@ -469,3 +466,9 @@ ScreenManager::SchedulePaint(Page &page) noexcept
main_dirty = true;
SchedulePaint();
}

void
ScreenManager::Alert(std::string message) noexcept
{
status_bar.SetMessage(std::move(message));
}
1 change: 1 addition & 0 deletions src/screen.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,5 @@ public:

// virtual methods from PageContainer
void SchedulePaint(Page &page) noexcept override;
void Alert(std::string message) noexcept override;
};

0 comments on commit 1a00084

Please sign in to comment.