Make timestamps in entry contents clickable, like chapter marks

BUG: 446358
This commit is contained in:
Bart De Vries 2023-01-24 14:54:23 +01:00
parent 5678fc0490
commit cdec053375
3 changed files with 51 additions and 4 deletions

View File

@ -365,6 +365,27 @@ QString Entry::adjustedContent(int width, int fontSize)
}
ret.replace(QStringLiteral("<img"), QStringLiteral("<br /> <img"));
// Replace strings that look like timestamps into clickable links with scheme
// "timestamp://". We will pick these up in the GUI to work like chapter marks
QRegularExpression imgRegexDate(QStringLiteral("\\d{1,2}(:\\d{2})+"));
i = imgRegexDate.globalMatch(ret);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
QString timeStamp(match.captured());
QStringList timeFragments(timeStamp.split(QStringLiteral(":")));
int timeUnit = 1;
qint64 time = 0;
for (QList<QString>::const_reverse_iterator iter = timeFragments.crbegin(); iter != timeFragments.crend(); iter++) {
time += (*iter).toInt() * 1000 * timeUnit;
timeUnit *= 60;
}
timeStamp = QStringLiteral("<a href=\"timestamp://%1\">%2</a>").arg(time).arg(timeStamp);
ret.replace(match.captured(), timeStamp);
}
return ret;
}

View File

@ -427,12 +427,23 @@ FocusScope {
Controls.Label {
id: text
text: AudioManager.entry ? AudioManager.entry.content : i18n("No Track Loaded")
text: AudioManager.entry ? AudioManager.entry.adjustedContent(width, font.pixelSize) : i18n("No Track Loaded")
verticalAlignment: Text.AlignTop
baseUrl: AudioManager.entry ? AudioManager.entry.baseUrl : ""
textFormat: Text.RichText
wrapMode: Text.WordWrap
onLinkActivated: Qt.openUrlExternally(link)
onLinkHovered: {
cursorShape: Qt.PointingHandCursor;
}
onLinkActivated: {
if (link.split("://")[0] === "timestamp") {
if (AudioManager.entry && AudioManager.entry.enclosure) {
AudioManager.seek(link.split("://")[1]);
}
} else {
Qt.openUrlExternally(link)
}
}
}
}
}

View File

@ -169,7 +169,7 @@ Kirigami.ScrollablePage {
entry.queueStatus = true;
}
AudioManager.entry = entry;
AudioManager.play()
AudioManager.play();
}
},
Kirigami.Action {
@ -241,7 +241,22 @@ Kirigami.ScrollablePage {
font.pointSize: SettingsManager && !(SettingsManager.articleFontUseSystem) ? SettingsManager.articleFontSize : Kirigami.Theme.defaultFont.pointSize
color: Kirigami.Theme.textColor
onLinkActivated: Qt.openUrlExternally(link)
onLinkActivated: {
if (link.split("://")[0] === "timestamp") {
if (AudioManager.entry && AudioManager.entry.enclosure && entry.enclosure && (entry.enclosure.status === Enclosure.Downloaded || SettingsManager.prioritizeStreaming)) {
if (AudioManager.entry !== entry) {
if (!entry.queueStatus) {
entry.queueStatus = true;
}
AudioManager.entry = entry;
AudioManager.play();
}
AudioManager.seek(link.split("://")[1]);
}
} else {
Qt.openUrlExternally(link)
}
}
onLinkHovered: {
cursorShape: Qt.PointingHandCursor;
}