Commit eb209bf8 authored by Jerome Guidon's avatar Jerome Guidon Committed by Matthieu Gallien

Radios: add support for images

Summary:
Album images where disabled for radios. This patch adds support for images in the radio view. A field has been added to EditableMetaData to allow the user to choose the image he wants for a radio. It can be a local file or an url.

Linked to: T7567

Reviewers: #elisa, mgallien, ngraham, astippich

Reviewed By: #elisa, astippich

Subscribers: ndavis, astippich, ngraham, mgallien

Differential Revision: https://phabricator.kde.org/D23859
parent 91abe0d3
This diff is collapsed.
......@@ -165,8 +165,10 @@ QVariant TrackMetadataModel::data(const QModelIndex &index, int role) const
case DataTypes::ResourceRole:
result = i18nc("Radio HTTP address for radio metadata view", "Stream Http Address");
break;
case DataTypes::SecondaryTextRole:
case DataTypes::ImageUrlRole:
result = i18nc("Image address for radio metadata view", "Image Address");
break;
case DataTypes::SecondaryTextRole:
case DataTypes::ShadowForImageRole:
case DataTypes::ChildModelRole:
case DataTypes::StringDurationRole:
......@@ -174,7 +176,6 @@ QVariant TrackMetadataModel::data(const QModelIndex &index, int role) const
case DataTypes::AllArtistsRole:
case DataTypes::HighestTrackRating:
case DataTypes::IdRole:
case DataTypes::ParentIdRole:
case DataTypes::DatabaseIdRole:
case DataTypes::IsSingleDiscAlbumRole:
case DataTypes::ContainerDataRole:
......@@ -195,6 +196,7 @@ QVariant TrackMetadataModel::data(const QModelIndex &index, int role) const
result = TextEntry;
break;
case DataTypes::ResourceRole:
case DataTypes::ImageUrlRole:
result = TextEntry;
break;
case DataTypes::ArtistRole:
......@@ -244,7 +246,6 @@ QVariant TrackMetadataModel::data(const QModelIndex &index, int role) const
case DataTypes::BitRateRole:
case DataTypes::ChannelsRole:
case DataTypes::SecondaryTextRole:
case DataTypes::ImageUrlRole:
case DataTypes::ShadowForImageRole:
case DataTypes::ChildModelRole:
case DataTypes::StringDurationRole:
......@@ -500,6 +501,7 @@ void TrackMetadataModel::fillDataForNewRadio()
DataTypes::TitleRole,
DataTypes::ResourceRole,
DataTypes::CommentRole,
DataTypes::ImageUrlRole,
DataTypes::DatabaseIdRole
}) {
......@@ -539,6 +541,14 @@ void TrackMetadataModel::setDatabase(DatabaseInterface *trackDatabase)
void TrackMetadataModel::saveData()
{
QString imageUrl = mTrackData[DataTypes::ImageUrlRole].toString();
if (!imageUrl.isEmpty()
&& !imageUrl.startsWith(QStringLiteral("http://"))
&& !imageUrl.startsWith(QStringLiteral("https://"))
&& !imageUrl.startsWith(QStringLiteral("file://"))) {
mTrackData[DataTypes::ImageUrlRole] = QStringLiteral("file:/").append(imageUrl);
}
Q_EMIT saveRadioData(mTrackData);
}
......@@ -557,7 +567,8 @@ void TrackMetadataModel::radioData(const TrackDataType &radiosData)
}
const QList<DataTypes::ColumnsRoles> fieldsForTrack({DataTypes::TitleRole, DataTypes::ResourceRole,
DataTypes::CommentRole, DataTypes::DatabaseIdRole});
DataTypes::CommentRole, DataTypes::ImageUrlRole,
DataTypes::DatabaseIdRole});
fillDataFromTrackData(radiosData, fieldsForTrack);
}
......
......@@ -45,11 +45,12 @@ FocusScope {
"initialDatabaseId": databaseId,
"fileName": url,
"modelType": viewHeader.modelType,
"showImage": false,
"showImage": true,
"showTrackFileName": false,
"showDeleteButton": databaseId !== -1,
"showApplyButton": true,
"editableMetadata": true,
"widthIndex": 4.5,
});
} else {
metadataLoader.setSource("MediaTrackMetadataView.qml",
......
......@@ -164,6 +164,12 @@ FocusScope {
color: myPalette.shadow
}
onStatusChanged: {
if (coverImageElement.status === Image.Error) {
source = 'image://icon/media-optical-audio'
}
}
}
}
......@@ -313,6 +319,16 @@ FocusScope {
}
}
Connections {
target: mediaTrack
onImageUrlChanged: {
if (coverImageElement.source !== imageUrl) {
coverImageElement.source = (imageUrl != '' ? imageUrl : Qt.resolvedUrl(elisaTheme.defaultAlbumImage))
}
}
}
states: [
State {
name: 'notSelected'
......
......@@ -35,6 +35,7 @@ Window {
property alias showTrackFileName: fileNameRow.visible
property alias showDeleteButton: deleteButtonBox.visible
property alias showApplyButton: applyButton.visible
property double widthIndex: 2.8
signal rejected()
......@@ -56,7 +57,7 @@ Window {
color: myPalette.window
minimumHeight: elisaTheme.coverImageSize * 1.8
minimumWidth: elisaTheme.coverImageSize * 2.8
minimumWidth: elisaTheme.coverImageSize * trackMetadata.widthIndex
ColumnLayout {
anchors.fill: parent
......@@ -89,6 +90,12 @@ Window {
Layout.minimumWidth: elisaTheme.coverImageSize
Layout.maximumHeight: elisaTheme.coverImageSize
Layout.maximumWidth: elisaTheme.coverImageSize
onStatusChanged: {
if (metadataImage.status === Image.Error) {
source = Qt.resolvedUrl(elisaTheme.defaultAlbumImage)
}
}
}
ListView {
......@@ -230,6 +237,14 @@ Window {
}
}
Connections {
target: realModel
onCoverUrlChanged: {
metadataImage.source = realModel.coverUrl
}
}
Component.onCompleted: {
if (elisa.musicManager) {
if (initialDatabaseId === -1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment