Commit 9c83b853 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵

make MediaTrackMetadataView able to modify metadata for tracks

only preliminary implementation

the model is not yet able to modify anything else apart from radios

BUG: 406472
parent 3b80b000
......@@ -265,6 +265,90 @@ QVariant TrackMetadataModel::data(const QModelIndex &index, int role) const
break;
}
break;
case ReadOnlyRole:
switch (currentKey)
{
case DataTypes::TitleRole:
result = false;
break;
case DataTypes::ResourceRole:
result = true;
break;
case DataTypes::ImageUrlRole:
result = false;
break;
case DataTypes::ArtistRole:
result = false;
break;
case DataTypes::AlbumRole:
result = false;
break;
case DataTypes::AlbumArtistRole:
result = false;
break;
case DataTypes::TrackNumberRole:
result = false;
break;
case DataTypes::DiscNumberRole:
result = false;
break;
case DataTypes::RatingRole:
result = false;
break;
case DataTypes::GenreRole:
result = false;
break;
case DataTypes::LyricistRole:
result = false;
break;
case DataTypes::ComposerRole:
result = false;
break;
case DataTypes::CommentRole:
result = false;
break;
case DataTypes::YearRole:
result = false;
break;
case DataTypes::LastPlayDate:
result = true;
break;
case DataTypes::PlayCounter:
result = true;
break;
case DataTypes::LyricsRole:
result = false;
break;
case DataTypes::DurationRole:
case DataTypes::SampleRateRole:
case DataTypes::BitRateRole:
case DataTypes::ChannelsRole:
case DataTypes::SecondaryTextRole:
case DataTypes::ShadowForImageRole:
case DataTypes::ChildModelRole:
case DataTypes::StringDurationRole:
case DataTypes::IsValidAlbumArtistRole:
case DataTypes::AllArtistsRole:
case DataTypes::HighestTrackRating:
case DataTypes::IdRole:
case DataTypes::ParentIdRole:
case DataTypes::DatabaseIdRole:
case DataTypes::IsSingleDiscAlbumRole:
case DataTypes::ContainerDataRole:
case DataTypes::IsPartialDataRole:
case DataTypes::AlbumIdRole:
case DataTypes::HasEmbeddedCover:
case DataTypes::FileModificationTime:
case DataTypes::FirstPlayDate:
case DataTypes::PlayFrequency:
case DataTypes::ElementTypeRole:
case DataTypes::FullDataRole:
case DataTypes::IsDirectoryRole:
case DataTypes::IsPlayListRole:
case DataTypes::FilePathRole:
break;
}
break;
}
return result;
......@@ -290,6 +374,7 @@ QHash<int, QByteArray> TrackMetadataModel::roleNames() const
names[ItemNameRole] = "name";
names[ItemTypeRole] = "type";
names[ReadOnlyRole] = "isReadOnly";
return names;
}
......
......@@ -52,6 +52,7 @@ public:
{
ItemNameRole = Qt::UserRole + 1,
ItemTypeRole,
ReadOnlyRole,
};
enum ItemType
......
......@@ -42,8 +42,7 @@ FocusScope {
"showImage": entryType !== ElisaUtils.Radio,
"showTrackFileName": entryType !== ElisaUtils.Radio,
"showDeleteButton": entryType === ElisaUtils.Radio,
"showApplyButton": entryType === ElisaUtils.Radio,
"editableMetadata": entryType === ElisaUtils.Radio,
"editableMetadata": true,
"widthIndex": (entryType === ElisaUtils.Radio ? 4.5 : 2.8),
});
metadataLoader.active = true
......@@ -56,8 +55,7 @@ FocusScope {
"isCreation": true,
"showImage": false,
"showTrackFileName": false,
"showDeleteButton": false,
"showApplyButton": true,
"showDeleteButton": true,
"editableMetadata": true,
"widthIndex": 4.5,
});
......
......@@ -12,14 +12,22 @@ import org.kde.elisa 1.0
RowLayout {
id: delegateRow
property string name
property int index
property var type
property string display
spacing: 0
signal edited()
Label {
id: metaDataLabels
text: {
if (model.name !== undefined) {
return i18nc("Label for a piece of metadata, e.g. 'Album Artist:'", "%1:", model.name)
if (name !== undefined) {
return i18nc("Label for a piece of metadata, e.g. 'Album Artist:'", "%1:", name)
}
return ""
}
......@@ -37,18 +45,18 @@ RowLayout {
Loader {
id: textDisplayLoader
focus: model.index === 0
focus: index === 0
active: model.type === EditableTrackMetadataModel.TextEntry || model.type === EditableTrackMetadataModel.UrlEntry || model.type === EditableTrackMetadataModel.IntegerEntry
visible: model.type === EditableTrackMetadataModel.TextEntry || model.type === EditableTrackMetadataModel.UrlEntry || model.type === EditableTrackMetadataModel.IntegerEntry
active: type === EditableTrackMetadataModel.TextEntry || type === EditableTrackMetadataModel.UrlEntry || type === EditableTrackMetadataModel.IntegerEntry
visible: type === EditableTrackMetadataModel.TextEntry || type === EditableTrackMetadataModel.UrlEntry || type === EditableTrackMetadataModel.IntegerEntry
Layout.fillWidth: true
Layout.alignment: Qt.AlignTop
sourceComponent: TextField {
text: model.display
text: display
focus: model.index === 0
focus: index === 0
horizontalAlignment: Text.AlignLeft
......@@ -57,8 +65,42 @@ RowLayout {
anchors.fill: parent
onTextEdited: {
if (model.display !== text) {
model.display = text
if (display !== text) {
display = text
edited()
}
}
}
}
Loader {
focus: index === 0
active: type === EditableTrackMetadataModel.RatingEntry
visible: type === EditableTrackMetadataModel.RatingEntry
Layout.fillWidth: true
Layout.alignment: Qt.AlignTop
sourceComponent: RatingStar {
starRating: display
readOnly: false
hoverWidgetOpacity: 1
anchors {
left: parent.left
top: parent.top
bottom: parent.bottom
}
onRatingEdited: {
if (display !== starRating) {
display = starRating
edited()
}
}
}
......
......@@ -46,7 +46,6 @@ FocusScope {
modelType: gridEntry.entryType
showTrackFileName: true
showDeleteButton: false
showApplyButton: false
editableMetadata: false
onRejected: metadataLoader.active = false;
......
......@@ -23,8 +23,7 @@ Window {
property bool isCreation: false
property alias showImage: metadataImage.visible
property alias showTrackFileName: fileNameRow.visible
property alias showDeleteButton: deleteButtonBox.visible
property alias showApplyButton: applyButton.visible
property bool showDeleteButton: false
property double widthIndex: 2.8
signal rejected()
......@@ -105,7 +104,12 @@ Window {
id: metaDataDelegate
MetaDataDelegate {
width: trackData.width
width: scrollBar.visible ? (!LayoutMirroring.enabled ? trackData.width - scrollBar.width : trackData.width) : trackData.width
index: model.index
name: model.name
display: model.display
type: model.type
}
}
......@@ -113,11 +117,18 @@ Window {
id: editableMetaDataDelegate
EditableMetaDataDelegate {
width: trackData.width
width: scrollBar.visible ? (!LayoutMirroring.enabled ? trackData.width - scrollBar.width : trackData.width) : trackData.width
index: model.index
name: model.name
display: model.display
type: model.type
onEdited: model.display = display
}
}
delegate: editableMetadata ? editableMetaDataDelegate: metaDataDelegate
delegate: editableMetadata && !isReadOnly ? editableMetaDataDelegate: metaDataDelegate
}
}
}
......@@ -175,6 +186,8 @@ Window {
Layout.minimumHeight: implicitHeight
alignment: Qt.AlignLeft
visible: showDeleteButton && !isCreation
Button {
id: deleteButton
text: i18n("Delete")
......@@ -199,6 +212,7 @@ Window {
id: applyButton
enabled: realModel.isDataValid && realModel.isDirty
visible: editableMetadata
text: i18n("Apply")
icon.name: 'dialog-ok-apply'
......@@ -206,9 +220,7 @@ Window {
onClicked:
{
realModel.saveData()
if (!deleteButtonBox.visible && editableMetadata) {
deleteButtonBox.visible = true
}
isCreation = false
}
}
Button {
......
......@@ -12,14 +12,20 @@ import org.kde.elisa 1.0
RowLayout {
id: delegateRow
property string name
property int index
property var type
property string display
spacing: 0
height: (model.type === EditableTrackMetadataModel.LongTextEntry ? longTextDisplayLoader.height : (Kirigami.Units.gridUnit + Kirigami.Units.smallSpacing / 2))
height: (type === EditableTrackMetadataModel.LongTextEntry ? longTextDisplayLoader.height : (Kirigami.Units.gridUnit + Kirigami.Units.smallSpacing / 2))
Label {
id: metaDataLabels
text: i18nc("Label for a piece of metadata, e.g. 'Album Artist:'", "%1:", model.name)
text: i18nc("Label for a piece of metadata, e.g. 'Album Artist:'", "%1:", name)
font.weight: Font.Bold
......@@ -34,15 +40,15 @@ RowLayout {
Loader {
id: textDisplayLoader
active: model.type === EditableTrackMetadataModel.TextEntry || model.type === EditableTrackMetadataModel.IntegerEntry
visible: model.type === EditableTrackMetadataModel.TextEntry || model.type === EditableTrackMetadataModel.IntegerEntry
active: type === EditableTrackMetadataModel.TextEntry || type === EditableTrackMetadataModel.IntegerEntry
visible: type === EditableTrackMetadataModel.TextEntry || type === EditableTrackMetadataModel.IntegerEntry
Layout.fillWidth: true
Layout.alignment: Qt.AlignTop
sourceComponent: LabelWithToolTip {
text: model.display
text: display
horizontalAlignment: Text.AlignLeft
elide: Text.ElideRight
......@@ -54,15 +60,15 @@ RowLayout {
Loader {
id: longTextDisplayLoader
active: model.type === EditableTrackMetadataModel.LongTextEntry
visible: model.type === EditableTrackMetadataModel.LongTextEntry
active: type === EditableTrackMetadataModel.LongTextEntry
visible: type === EditableTrackMetadataModel.LongTextEntry
Layout.fillWidth: true
Layout.maximumWidth: delegateRow.width - (0.8 * elisaTheme.coverImageSize + Kirigami.Units.largeSpacing * 2)
Layout.alignment: Qt.AlignTop
sourceComponent: Label {
text: model.display
text: display
horizontalAlignment: Text.AlignLeft
elide: Text.ElideRight
......@@ -74,8 +80,8 @@ RowLayout {
}
Loader {
active: model.type === EditableTrackMetadataModel.DateEntry
visible: model.type === EditableTrackMetadataModel.DateEntry
active: type === EditableTrackMetadataModel.DateEntry
visible: type === EditableTrackMetadataModel.DateEntry
Layout.fillWidth: true
Layout.alignment: Qt.AlignTop
......@@ -88,19 +94,19 @@ RowLayout {
anchors.fill: parent
property date rawDate: new Date(model.display)
property date rawDate: new Date(display)
}
}
Loader {
active: model.type === EditableTrackMetadataModel.RatingEntry
visible: model.type === EditableTrackMetadataModel.RatingEntry
active: type === EditableTrackMetadataModel.RatingEntry
visible: type === EditableTrackMetadataModel.RatingEntry
Layout.fillWidth: true
Layout.alignment: Qt.AlignTop
sourceComponent: RatingStar {
starRating: model.display
starRating: display
readOnly: true
......
......@@ -63,7 +63,6 @@ FocusScope {
modelType: entryType
showTrackFileName: entryType !== ElisaUtils.Radio
showDeleteButton: entryType === ElisaUtils.Radio
showApplyButton: entryType === ElisaUtils.Radio
editableMetadata: entryType === ElisaUtils.Radio
onRejected: metadataLoader.active = false
......
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