From 1a0008415e3e64cb02990c158ceb3f4a4d313531 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 10 Sep 2024 17:48:20 +0200 Subject: [PATCH] page/Container: add method Alert() --- src/ChatPage.cxx | 2 +- src/FileBrowserPage.cxx | 4 +-- src/KeyDefPage.cxx | 14 +++++----- src/LyricsPage.cxx | 16 +++++------ src/Main.cxx | 2 +- src/QueuePage.cxx | 2 +- src/page/Container.hxx | 7 +++++ src/page/Page.cxx | 6 +++++ src/page/Page.hxx | 2 ++ src/page/ProxyPage.cxx | 6 +++++ src/page/ProxyPage.hxx | 1 + src/screen.cxx | 59 ++++++++++++++++++++++------------------- src/screen.hxx | 1 + 13 files changed, 74 insertions(+), 48 deletions(-) diff --git a/src/ChatPage.cxx b/src/ChatPage.cxx index 01ae0924..5fb581f8 100644 --- a/src/ChatPage.cxx +++ b/src/ChatPage.cxx @@ -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 diff --git a/src/FileBrowserPage.cxx b/src/FileBrowserPage.cxx index 3a20b7dc..96fd4a39 100644 --- a/src/FileBrowserPage.cxx +++ b/src/FileBrowserPage.cxx @@ -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; } @@ -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")); } } diff --git a/src/KeyDefPage.cxx b/src/KeyDefPage.cxx index 6948274c..f9f12e4a 100644 --- a/src/KeyDefPage.cxx +++ b/src/KeyDefPage.cxx @@ -145,7 +145,7 @@ CommandKeysPage::DeleteKey(int key_index) binding->modified = true; UpdateListLength(); - screen_status_message(_("Deleted")); + Alert(_("Deleted")); /* repaint */ SchedulePaint(); @@ -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; } @@ -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 @@ -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; } @@ -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(); } diff --git a/src/LyricsPage.cxx b/src/LyricsPage.cxx index 21236b43..23520c8d 100644 --- a/src/LyricsPage.cxx +++ b/src/LyricsPage.cxx @@ -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(); @@ -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; } @@ -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"), @@ -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: diff --git a/src/Main.cxx b/src/Main.cxx index 937ab548..1746899a 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -243,7 +243,7 @@ Instance::OnCheckKeyBindings() noexcept process */ return; - screen_status_message(buf); + screen_manager.Alert(buf); doupdate(); diff --git a/src/QueuePage.cxx b/src/QueuePage.cxx index 54c9dbd0..f16f7167 100644 --- a/src/QueuePage.cxx +++ b/src/QueuePage.cxx @@ -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; diff --git a/src/page/Container.hxx b/src/page/Container.hxx index 9e7c5acc..e22189f2 100644 --- a/src/page/Container.hxx +++ b/src/page/Container.hxx @@ -3,6 +3,8 @@ #pragma once +#include + class Page; /** @@ -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; }; diff --git a/src/page/Page.cxx b/src/page/Page.cxx index c630b43b..63985a10 100644 --- a/src/page/Page.cxx +++ b/src/page/Page.cxx @@ -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 { diff --git a/src/page/Page.hxx b/src/page/Page.hxx index f3a65ace..31d357cd 100644 --- a/src/page/Page.hxx +++ b/src/page/Page.hxx @@ -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, diff --git a/src/page/ProxyPage.cxx b/src/page/ProxyPage.cxx index 3512ad67..acbcde6f 100644 --- a/src/page/ProxyPage.cxx +++ b/src/page/ProxyPage.cxx @@ -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)); +} diff --git a/src/page/ProxyPage.hxx b/src/page/ProxyPage.hxx index 73ac1ad2..619edba9 100644 --- a/src/page/ProxyPage.hxx +++ b/src/page/ProxyPage.hxx @@ -50,4 +50,5 @@ public: // virtual methods from PageContainer void SchedulePaint(Page &page) noexcept override; + void Alert(std::string message) noexcept override; }; diff --git a/src/screen.cxx b/src/screen.cxx index 77d29082..4d0db0e2 100644 --- a/src/screen.cxx +++ b/src/screen.cxx @@ -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"), @@ -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 @@ -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: @@ -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)); +} diff --git a/src/screen.hxx b/src/screen.hxx index f919df88..4cf5d746 100644 --- a/src/screen.hxx +++ b/src/screen.hxx @@ -191,4 +191,5 @@ public: // virtual methods from PageContainer void SchedulePaint(Page &page) noexcept override; + void Alert(std::string message) noexcept override; };