Commit fc5ab1cb authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

improve error message when editing radio data

parent fb6fe7da
......@@ -17,6 +17,8 @@
#include "editabletrackmetadatamodel.h"
#include <KI18n/KLocalizedString>
#include <QDebug>
EditableTrackMetadataModel::EditableTrackMetadataModel(QObject *parent)
......@@ -83,10 +85,20 @@ void EditableTrackMetadataModel::validData()
newValidState = false;
}
if (!newValidState) {
mErrorMessage = i18nc("Error message when track URL is invalid", "Invalid URL.");
Q_EMIT errorMessageChanged();
}
if (newValidState) {
const auto &titleData = dataFromType(TrackDataType::key_type::TitleRole);
newValidState = newValidState && !titleData.toString().isEmpty();
if (!newValidState) {
mErrorMessage = i18nc("Error message when track title is empty", "Empty title.");
Q_EMIT errorMessageChanged();
}
}
if (mIsDataValid != newValidState) {
......
......@@ -30,6 +30,10 @@ class ELISALIB_EXPORT EditableTrackMetadataModel : public TrackMetadataModel
READ isDataValid
NOTIFY isDataValidChanged)
Q_PROPERTY(QString errorMessage
READ errorMessage
NOTIFY errorMessageChanged)
Q_PROPERTY(bool isDirty
READ isDirty
NOTIFY isDirtyChanged)
......@@ -50,11 +54,18 @@ public:
return mIsDirty;
}
QString errorMessage() const
{
return mErrorMessage;
}
Q_SIGNALS:
void isDataValidChanged();
void isDirtyChanged();
void errorMessageChanged();
public Q_SLOTS:
void saveData();
......@@ -72,6 +83,8 @@ private:
bool mIsDataValid = false;
bool mIsDirty = false;
QString mErrorMessage;
};
......
......@@ -175,7 +175,7 @@ Window {
Kirigami.InlineMessage {
id: formInvalidNotification
text: i18n("Data are not valid. Radio cannot be created or modified.")
text: i18nc("Form validation error message for track data", "Data are not valid. %1", realModel.errorMessage)
type: Kirigami.MessageType.Error
showCloseButton: false
visible: !realModel.isDataValid
......
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