From 2470997fc92fc00501b84f939146ce2ef6fbde69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcolas=20F=2E=20R=2E=20A=2E=20Prado?= Date: Sun, 27 Feb 2022 21:05:04 -0500 Subject: SoundPlayer: Rename NoVisualization to AlbumCoverVisualization Since the NoVisualization widget now shows the album cover, it should be called AlbumCoverVisualization instead. --- .../SoundPlayer/AlbumCoverVisualizationWidget.cpp | 53 ++++++++++++++++++++++ .../SoundPlayer/AlbumCoverVisualizationWidget.h | 29 ++++++++++++ Userland/Applications/SoundPlayer/CMakeLists.txt | 2 +- .../SoundPlayer/NoVisualizationWidget.cpp | 53 ---------------------- .../SoundPlayer/NoVisualizationWidget.h | 29 ------------ Userland/Applications/SoundPlayer/main.cpp | 10 ++-- 6 files changed, 88 insertions(+), 88 deletions(-) create mode 100644 Userland/Applications/SoundPlayer/AlbumCoverVisualizationWidget.cpp create mode 100644 Userland/Applications/SoundPlayer/AlbumCoverVisualizationWidget.h delete mode 100644 Userland/Applications/SoundPlayer/NoVisualizationWidget.cpp delete mode 100644 Userland/Applications/SoundPlayer/NoVisualizationWidget.h diff --git a/Userland/Applications/SoundPlayer/AlbumCoverVisualizationWidget.cpp b/Userland/Applications/SoundPlayer/AlbumCoverVisualizationWidget.cpp new file mode 100644 index 0000000000..c4bee0352c --- /dev/null +++ b/Userland/Applications/SoundPlayer/AlbumCoverVisualizationWidget.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2021, Cesar Torres + * Copyright (c) 2022, the SerenityOS developers. + * Copyright (c) 2022, NĂ­colas F. R. A. Prado + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "AlbumCoverVisualizationWidget.h" +#include +#include +#include + +void AlbumCoverVisualizationWidget::paint_event(GUI::PaintEvent& event) +{ + Frame::paint_event(event); + GUI::Painter painter(*this); + + if (m_album_cover) { + painter.draw_scaled_bitmap(frame_inner_rect(), *m_album_cover, m_album_cover->rect(), 1.0f); + } else { + if (!m_serenity_bg) + m_serenity_bg = Gfx::Bitmap::try_load_from_file("/res/wallpapers/sunset-retro.png").release_value_but_fixme_should_propagate_errors(); + painter.draw_scaled_bitmap(frame_inner_rect(), *m_serenity_bg, m_serenity_bg->rect(), 1.0f); + } +} + +ErrorOr> AlbumCoverVisualizationWidget::get_album_cover(StringView const filename) +{ + auto directory = LexicalPath::dirname(filename); + + static constexpr auto possible_cover_filenames = Array { "cover.png"sv, "cover.jpg"sv }; + for (auto& it : possible_cover_filenames) { + LexicalPath cover_path = LexicalPath::join(directory, it); + if (Core::File::exists(cover_path.string())) + return Gfx::Bitmap::try_load_from_file(cover_path.string()); + } + + return Error::from_string_literal("No cover file found"); +} + +void AlbumCoverVisualizationWidget::start_new_file(StringView filename) +{ + auto album_cover_or_error = get_album_cover(filename); + if (album_cover_or_error.is_error()) + m_album_cover = nullptr; + else + m_album_cover = album_cover_or_error.value(); +} + +void AlbumCoverVisualizationWidget::set_buffer(RefPtr) +{ +} diff --git a/Userland/Applications/SoundPlayer/AlbumCoverVisualizationWidget.h b/Userland/Applications/SoundPlayer/AlbumCoverVisualizationWidget.h new file mode 100644 index 0000000000..9cc54c5d0b --- /dev/null +++ b/Userland/Applications/SoundPlayer/AlbumCoverVisualizationWidget.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021, Cesar Torres + * Copyright (c) 2022, the SerenityOS developers. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include "VisualizationWidget.h" +#include +#include + +class AlbumCoverVisualizationWidget final : public VisualizationWidget { + C_OBJECT(AlbumCoverVisualizationWidget) + +public: + ~AlbumCoverVisualizationWidget() override = default; + void set_buffer(RefPtr) override; + void start_new_file(StringView) override; + +private: + void paint_event(GUI::PaintEvent&) override; + AlbumCoverVisualizationWidget() = default; + ErrorOr> get_album_cover(StringView const filename); + + RefPtr m_serenity_bg; + RefPtr m_album_cover; +}; diff --git a/Userland/Applications/SoundPlayer/CMakeLists.txt b/Userland/Applications/SoundPlayer/CMakeLists.txt index e2d0e6f0bb..09dff754b2 100644 --- a/Userland/Applications/SoundPlayer/CMakeLists.txt +++ b/Userland/Applications/SoundPlayer/CMakeLists.txt @@ -13,7 +13,7 @@ set(SOURCES SampleWidget.cpp SoundPlayerWidgetAdvancedView.cpp BarsVisualizationWidget.cpp - NoVisualizationWidget.cpp + AlbumCoverVisualizationWidget.cpp M3UParser.cpp PlaylistWidget.cpp ) diff --git a/Userland/Applications/SoundPlayer/NoVisualizationWidget.cpp b/Userland/Applications/SoundPlayer/NoVisualizationWidget.cpp deleted file mode 100644 index 7a05c20e36..0000000000 --- a/Userland/Applications/SoundPlayer/NoVisualizationWidget.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2021, Cesar Torres - * Copyright (c) 2022, the SerenityOS developers. - * Copyright (c) 2022, NĂ­colas F. R. A. Prado - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include "NoVisualizationWidget.h" -#include -#include -#include - -void NoVisualizationWidget::paint_event(GUI::PaintEvent& event) -{ - Frame::paint_event(event); - GUI::Painter painter(*this); - - if (m_album_cover) { - painter.draw_scaled_bitmap(frame_inner_rect(), *m_album_cover, m_album_cover->rect(), 1.0f); - } else { - if (!m_serenity_bg) - m_serenity_bg = Gfx::Bitmap::try_load_from_file("/res/wallpapers/sunset-retro.png").release_value_but_fixme_should_propagate_errors(); - painter.draw_scaled_bitmap(frame_inner_rect(), *m_serenity_bg, m_serenity_bg->rect(), 1.0f); - } -} - -ErrorOr> NoVisualizationWidget::get_album_cover(StringView const filename) -{ - auto directory = LexicalPath::dirname(filename); - - static constexpr auto possible_cover_filenames = Array { "cover.png"sv, "cover.jpg"sv }; - for (auto& it : possible_cover_filenames) { - LexicalPath cover_path = LexicalPath::join(directory, it); - if (Core::File::exists(cover_path.string())) - return Gfx::Bitmap::try_load_from_file(cover_path.string()); - } - - return Error::from_string_literal("No cover file found"); -} - -void NoVisualizationWidget::start_new_file(StringView filename) -{ - auto album_cover_or_error = get_album_cover(filename); - if (album_cover_or_error.is_error()) - m_album_cover = nullptr; - else - m_album_cover = album_cover_or_error.value(); -} - -void NoVisualizationWidget::set_buffer(RefPtr) -{ -} diff --git a/Userland/Applications/SoundPlayer/NoVisualizationWidget.h b/Userland/Applications/SoundPlayer/NoVisualizationWidget.h deleted file mode 100644 index fb789e0846..0000000000 --- a/Userland/Applications/SoundPlayer/NoVisualizationWidget.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2021, Cesar Torres - * Copyright (c) 2022, the SerenityOS developers. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include "VisualizationWidget.h" -#include -#include - -class NoVisualizationWidget final : public VisualizationWidget { - C_OBJECT(NoVisualizationWidget) - -public: - ~NoVisualizationWidget() override = default; - void set_buffer(RefPtr) override; - void start_new_file(StringView) override; - -private: - void paint_event(GUI::PaintEvent&) override; - NoVisualizationWidget() = default; - ErrorOr> get_album_cover(StringView const filename); - - RefPtr m_serenity_bg; - RefPtr m_album_cover; -}; diff --git a/Userland/Applications/SoundPlayer/main.cpp b/Userland/Applications/SoundPlayer/main.cpp index 1521e0a7fa..8ff1a76621 100644 --- a/Userland/Applications/SoundPlayer/main.cpp +++ b/Userland/Applications/SoundPlayer/main.cpp @@ -5,8 +5,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include "AlbumCoverVisualizationWidget.h" #include "BarsVisualizationWidget.h" -#include "NoVisualizationWidget.h" #include "Player.h" #include "SampleWidget.h" #include "SoundPlayerWidgetAdvancedView.h" @@ -124,11 +124,11 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(visualization_menu->try_add_action(samples)); visualization_actions.add_action(samples); - auto none = GUI::Action::create_checkable("&None", [&](auto&) { - static_cast(player)->set_visualization(); + auto album_cover_visualization = GUI::Action::create_checkable("&Album Cover", [&](auto&) { + static_cast(player)->set_visualization(); }); - TRY(visualization_menu->try_add_action(none)); - visualization_actions.add_action(none); + TRY(visualization_menu->try_add_action(album_cover_visualization)); + visualization_actions.add_action(album_cover_visualization); auto help_menu = TRY(window->try_add_menu("&Help")); TRY(help_menu->try_add_action(GUI::CommonActions::make_about_action("Sound Player", app_icon, window))); -- cgit v1.2.3