fix(glossary): handle save errors and improve playlist controls
This commit is contained in:
1 parent
3d8f644d8d
commit
309801d059
7 files changed
+204
-33
No files matched your search
@@ -139,25 +139,51 @@ QString TranslationService::glossaryDirectory() const
|
||||
return m_glossary.directory;
|
||||
}
|
||||
|
||||
QString TranslationService::glossaryError() const
|
||||
{
|
||||
return m_glossaryError;
|
||||
}
|
||||
|
||||
void TranslationService::loadGlossary(const QUrl &videoUrl)
|
||||
{
|
||||
const QString directory = videoUrl.isLocalFile() ? QFileInfo(videoUrl.toLocalFile()).absolutePath() : QString();
|
||||
m_glossary = directory.isEmpty() ? GlossaryStore::Glossary{} : GlossaryStore::load(directory);
|
||||
if (!m_glossaryError.isEmpty()) {
|
||||
m_glossaryError.clear();
|
||||
Q_EMIT glossaryErrorChanged();
|
||||
}
|
||||
Q_EMIT glossaryChanged();
|
||||
}
|
||||
|
||||
void TranslationService::saveGlossary(const QVariantList &entries)
|
||||
bool TranslationService::saveGlossary(const QVariantList &entries)
|
||||
{
|
||||
QList<GlossaryStore::Entry> result;
|
||||
for (const QVariant &value : entries) {
|
||||
const QVariantMap map = value.toMap();
|
||||
result.append({map.value(u"source"_s).toString().trimmed(), map.value(u"target"_s).toString().trimmed()});
|
||||
}
|
||||
m_glossary.entries = result;
|
||||
if (!m_glossary.directory.isEmpty()) {
|
||||
GlossaryStore::save(m_glossary);
|
||||
|
||||
GlossaryStore::Glossary candidate = m_glossary;
|
||||
candidate.entries = result;
|
||||
if (!candidate.directory.isEmpty()) {
|
||||
QString error;
|
||||
if (!GlossaryStore::save(candidate, &error)) {
|
||||
const QString message = error.isEmpty() ? i18n("Could not save the translation glossary.")
|
||||
: i18n("Could not save the translation glossary: %1", error);
|
||||
if (m_glossaryError != message) {
|
||||
m_glossaryError = message;
|
||||
Q_EMIT glossaryErrorChanged();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
m_glossary = candidate;
|
||||
if (!m_glossaryError.isEmpty()) {
|
||||
m_glossaryError.clear();
|
||||
Q_EMIT glossaryErrorChanged();
|
||||
}
|
||||
Q_EMIT glossaryChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
void TranslationService::clearGlossary()
|
||||
|
||||
Reference in new issue
Block a user