Commit e0a2a944 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵

add a modify button to MediaTrackMetadataView dialog

fix many problems when adding modify capability to the dialog

use states to model the different states (not perfect in the case of
radios but should ease maintenance)

playlist metadata dialog not able to modify metadata for tracks

toto
parent 41fddfe6
......@@ -272,7 +272,25 @@ QVariant TrackMetadataModel::data(const QModelIndex &index, int role) const
result = false;
break;
case DataTypes::ResourceRole:
result = true;
switch (mFullData.elementType())
{
case ElisaUtils::Track:
result = true;
break;
case ElisaUtils::Radio:
result = false;
break;
case ElisaUtils::Album:
case ElisaUtils::Artist:
case ElisaUtils::Composer:
case ElisaUtils::Container:
case ElisaUtils::FileName:
case ElisaUtils::Genre:
case ElisaUtils::Lyricist:
case ElisaUtils::Unknown:
result = true;
break;
}
break;
case DataTypes::ImageUrlRole:
result = false;
......@@ -590,22 +608,23 @@ void TrackMetadataModel::initializeForNewRadio()
void TrackMetadataModel::fillDataForNewRadio()
{
beginResetModel();
mFullData.clear();
mTrackData.clear();
mTrackKeys.clear();
auto allRoles = {DataTypes::TitleRole, DataTypes::ResourceRole,
DataTypes::CommentRole, DataTypes::ImageUrlRole,
DataTypes::DatabaseIdRole};
DataTypes::CommentRole, DataTypes::ImageUrlRole};
for (auto role : allRoles) {
mTrackKeys.push_back(role);
if (role == DataTypes::DatabaseIdRole) {
mTrackData[role] = -1;
mFullData[role] = -1;
} else {
mTrackData[role] = QString();
mFullData[role] = QString();
}
}
mTrackData = mFullData;
mFullData[DataTypes::ElementTypeRole] = ElisaUtils::Radio;
filterDataFromTrackData();
endResetModel();
}
......@@ -642,8 +661,7 @@ void TrackMetadataModel::radioData(const TrackDataType &radiosData)
}
const QList<DataTypes::ColumnsRoles> fieldsForTrack({DataTypes::TitleRole, DataTypes::ResourceRole,
DataTypes::CommentRole, DataTypes::ImageUrlRole,
DataTypes::DatabaseIdRole});
DataTypes::CommentRole, DataTypes::ImageUrlRole});
fillDataFromTrackData(radiosData, fieldsForTrack);
}
......
......@@ -35,6 +35,9 @@ Item {
property int contextCoverImageSize: 100
property int smallImageSize: 32
property int metaDataDialogHeight: 400 * Kirigami.Units.devicePixelRatio
property int metaDataDialogWidth: 600 * Kirigami.Units.devicePixelRatio
property int tooltipRadius: 3
property int shadowOffset: 2
......
......@@ -43,7 +43,6 @@ FocusScope {
"showTrackFileName": entryType !== ElisaUtils.Radio,
"showDeleteButton": entryType === ElisaUtils.Radio,
"editableMetadata": true,
"widthIndex": (entryType === ElisaUtils.Radio ? 4.5 : 2.8),
});
metadataLoader.active = true
}
......@@ -57,7 +56,6 @@ FocusScope {
"showTrackFileName": false,
"showDeleteButton": true,
"editableMetadata": true,
"widthIndex": 4.5,
});
metadataLoader.active = true
}
......
......@@ -20,11 +20,11 @@ Window {
property var modelType
property url fileName
property bool editableMetadata
property bool isModifying: false
property bool isCreation: false
property alias showImage: metadataImage.visible
property alias showTrackFileName: fileNameRow.visible
property bool showDeleteButton: false
property double widthIndex: 2.8
signal rejected()
......@@ -46,8 +46,8 @@ Window {
color: myPalette.window
minimumHeight: elisaTheme.coverImageSize * 1.8
minimumWidth: elisaTheme.coverImageSize * trackMetadata.widthIndex
minimumHeight: elisaTheme.metaDataDialogHeight
minimumWidth: elisaTheme.metaDataDialogWidth
onClosing: {
trackMetadata.rejected()
......@@ -128,7 +128,8 @@ Window {
}
}
delegate: editableMetadata && !isReadOnly ? editableMetaDataDelegate: metaDataDelegate
delegate: ((dialogStates.state === 'readWrite' || dialogStates.state === 'readWriteAndDirty' ||
dialogStates.state === 'create' || dialogStates.state === 'createAndDirty') && !realModel.isReadOnly) ? editableMetaDataDelegate: metaDataDelegate
}
}
}
......@@ -209,10 +210,16 @@ Window {
alignment: Qt.AlignRight
Button {
id: applyButton
id: modifyButton
text: i18n("Modify")
icon.name: 'document-edit'
DialogButtonBox.buttonRole: DialogButtonBox.ActionRole
onClicked: isModifying = true
}
enabled: realModel.isDataValid && realModel.isDirty
visible: editableMetadata
Button {
id: applyButton
text: i18n("Apply")
icon.name: 'dialog-ok-apply'
......@@ -220,9 +227,13 @@ Window {
onClicked:
{
realModel.saveData()
isCreation = false
if (isCreation) {
isCreation = false
isModifying = true
}
}
}
Button {
text: i18n("Close")
icon.name: 'dialog-cancel'
......@@ -254,4 +265,119 @@ Window {
}
}
}
StateGroup {
id: dialogStates
states: [
State {
name: 'consultOnly'
when: !editableMetadata
changes: [
PropertyChanges {
target: modifyButton
enabled: false
visible: false
},
PropertyChanges {
target: applyButton
enabled: false
visible: false
}
]
},
State {
name: 'readOnly'
when: editableMetadata && !isModifying && !isCreation
changes: [
PropertyChanges {
target: modifyButton
enabled: true
visible: true
},
PropertyChanges {
target: applyButton
enabled: false
visible: true
}
]
},
State {
name: 'readWrite'
when: editableMetadata && isModifying && !isCreation && (!realModel.isDataValid || !realModel.isDirty)
changes: [
PropertyChanges {
target: modifyButton
enabled: false
visible: true
},
PropertyChanges {
target: applyButton
enabled: false
visible: true
}
]
},
State {
name: 'readWriteAndDirty'
when: editableMetadata && isModifying && !isCreation && realModel.isDataValid && realModel.isDirty
changes: [
PropertyChanges {
target: modifyButton
enabled: false
visible: true
},
PropertyChanges {
target: applyButton
enabled: true
visible: true
}
]
},
State {
name: 'create'
when: editableMetadata && !isModifying && isCreation && (!realModel.isDataValid || !realModel.isDirty)
changes: [
PropertyChanges {
target: modifyButton
enabled: false
visible: true
},
PropertyChanges {
target: applyButton
enabled: false
visible: true
}
]
},
State {
name: 'createAndDirty'
when: editableMetadata && !isModifying && isCreation && realModel.isDataValid && realModel.isDirty
changes: [
PropertyChanges {
target: modifyButton
enabled: false
visible: true
},
PropertyChanges {
target: applyButton
enabled: true
visible: true
}
]
}
]
}
}
......@@ -40,8 +40,8 @@ RowLayout {
Loader {
id: textDisplayLoader
active: type === EditableTrackMetadataModel.TextEntry || type === EditableTrackMetadataModel.IntegerEntry
visible: type === EditableTrackMetadataModel.TextEntry || type === EditableTrackMetadataModel.IntegerEntry
active: type === EditableTrackMetadataModel.TextEntry || type === EditableTrackMetadataModel.IntegerEntry || type === EditableTrackMetadataModel.UrlEntry
visible: type === EditableTrackMetadataModel.TextEntry || type === EditableTrackMetadataModel.IntegerEntry || type === EditableTrackMetadataModel.UrlEntry
Layout.fillWidth: true
Layout.alignment: Qt.AlignTop
......
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