mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:08:12 +00:00
SoundPlayer: Use an enum for PlaylistModel columns
Also correct some const-positioning.
This commit is contained in:
parent
32e5593ca9
commit
fae350be3f
2 changed files with 26 additions and 16 deletions
|
@ -29,23 +29,23 @@ PlaylistWidget::PlaylistWidget()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI::Variant PlaylistModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
|
GUI::Variant PlaylistModel::data(GUI::ModelIndex const& index, GUI::ModelRole role) const
|
||||||
{
|
{
|
||||||
if (role == GUI::ModelRole::TextAlignment)
|
if (role == GUI::ModelRole::TextAlignment)
|
||||||
return "CenterLeft";
|
return "CenterLeft";
|
||||||
if (role == GUI::ModelRole::Display) {
|
if (role == GUI::ModelRole::Display) {
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case Column::Title:
|
||||||
return m_playlist_items[index.row()].extended_info->track_display_title.value_or(LexicalPath::title(m_playlist_items[index.row()].path));
|
return m_playlist_items[index.row()].extended_info->track_display_title.value_or(LexicalPath::title(m_playlist_items[index.row()].path));
|
||||||
case 1:
|
case Column::Duration:
|
||||||
return human_readable_digital_time(m_playlist_items[index.row()].extended_info->track_length_in_seconds.value_or(0));
|
return human_readable_digital_time(m_playlist_items[index.row()].extended_info->track_length_in_seconds.value_or(0));
|
||||||
case 2:
|
case Column::Group:
|
||||||
return m_playlist_items[index.row()].extended_info->group_name.value_or("");
|
return m_playlist_items[index.row()].extended_info->group_name.value_or("");
|
||||||
case 3:
|
case Column::Album:
|
||||||
return m_playlist_items[index.row()].extended_info->album_title.value_or("");
|
return m_playlist_items[index.row()].extended_info->album_title.value_or("");
|
||||||
case 4:
|
case Column::Artist:
|
||||||
return m_playlist_items[index.row()].extended_info->album_artist.value_or("");
|
return m_playlist_items[index.row()].extended_info->album_artist.value_or("");
|
||||||
case 5:
|
case Column::Filesize:
|
||||||
return human_readable_size(m_playlist_items[index.row()].extended_info->file_size_in_bytes.value_or(0));
|
return human_readable_size(m_playlist_items[index.row()].extended_info->file_size_in_bytes.value_or(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,17 +60,17 @@ GUI::Variant PlaylistModel::data(const GUI::ModelIndex& index, GUI::ModelRole ro
|
||||||
ErrorOr<String> PlaylistModel::column_name(int column) const
|
ErrorOr<String> PlaylistModel::column_name(int column) const
|
||||||
{
|
{
|
||||||
switch (column) {
|
switch (column) {
|
||||||
case 0:
|
case Column::Title:
|
||||||
return "Title"_short_string;
|
return "Title"_short_string;
|
||||||
case 1:
|
case Column::Duration:
|
||||||
return TRY("Duration"_string);
|
return TRY("Duration"_string);
|
||||||
case 2:
|
case Column::Group:
|
||||||
return "Group"_short_string;
|
return "Group"_short_string;
|
||||||
case 3:
|
case Column::Album:
|
||||||
return "Album"_short_string;
|
return "Album"_short_string;
|
||||||
case 4:
|
case Column::Artist:
|
||||||
return "Artist"_short_string;
|
return "Artist"_short_string;
|
||||||
case 5:
|
case Column::Filesize:
|
||||||
return TRY("Filesize"_string);
|
return TRY("Filesize"_string);
|
||||||
}
|
}
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
|
|
|
@ -19,11 +19,21 @@ enum class PlaylistModelCustomRole {
|
||||||
|
|
||||||
class PlaylistModel : public GUI::Model {
|
class PlaylistModel : public GUI::Model {
|
||||||
public:
|
public:
|
||||||
|
enum Column {
|
||||||
|
Title,
|
||||||
|
Duration,
|
||||||
|
Group,
|
||||||
|
Album,
|
||||||
|
Artist,
|
||||||
|
Filesize,
|
||||||
|
__Count
|
||||||
|
};
|
||||||
|
|
||||||
~PlaylistModel() override = default;
|
~PlaylistModel() override = default;
|
||||||
|
|
||||||
int row_count(const GUI::ModelIndex&) const override { return m_playlist_items.size(); }
|
int row_count(GUI::ModelIndex const&) const override { return m_playlist_items.size(); }
|
||||||
int column_count(const GUI::ModelIndex&) const override { return 6; }
|
int column_count(GUI::ModelIndex const&) const override { return 6; }
|
||||||
GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
|
GUI::Variant data(GUI::ModelIndex const&, GUI::ModelRole) const override;
|
||||||
ErrorOr<String> column_name(int column) const override;
|
ErrorOr<String> column_name(int column) const override;
|
||||||
Vector<M3UEntry>& items() { return m_playlist_items; }
|
Vector<M3UEntry>& items() { return m_playlist_items; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue