Skip to content

Commit

Permalink
Merge pull request #13326 from ronso0/effects-visible-list
Browse files Browse the repository at this point in the history
(fix) Effects: show newly added effects, read/write HiddenEffects
  • Loading branch information
JoergAtGithub authored Jun 29, 2024
2 parents 4072440 + 8215484 commit df6529d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/effects/effectsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ void EffectsManager::saveEffectsXml() {
quickEffectChainPresets,
standardEffectChainPresets,
outputChainPreset});
m_pVisibleEffectsList->saveEffectsXml(&doc);

m_pVisibleEffectsList->saveEffectsXml(&doc, m_pBackendManager);

QDir settingsPath(m_pConfig->getSettingsPath());
if (!settingsPath.exists()) {
Expand Down
1 change: 1 addition & 0 deletions src/effects/presets/effectxmlelements.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const QString kEqualizerEffects(QStringLiteral("EqualizerEffects"));
const QString kChainPresetName(QStringLiteral("ChainPresetName"));

const QString kVisibleEffects(QStringLiteral("VisibleEffects"));
const QString kHiddenEffects(QStringLiteral("HiddenEffects"));

const QString kChainsRoot(QStringLiteral("Chains"));
const QString kChain(QStringLiteral("EffectChain"));
Expand Down
53 changes: 44 additions & 9 deletions src/effects/visibleeffectslist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,37 @@ const EffectManifestPointer VisibleEffectsList::previous(
}

void VisibleEffectsList::readEffectsXml(
const QDomDocument& doc, EffectsBackendManagerPointer pBackendManager) {
const QDomDocument& doc,
EffectsBackendManagerPointer pBackendManager) {
QList<EffectManifestPointer> visibleEffects = readEffectsList(
doc,
pBackendManager,
EffectXml::kVisibleEffects);
const QList<EffectManifestPointer> hiddenEffects = readEffectsList(
doc,
pBackendManager,
EffectXml::kHiddenEffects);

// New effects will remain hidden since they are neither in the VisibleEffects
// nor in the newly introduced HiddenEffects list.
// Unhide all effects that are not in either list.
const auto manifests = pBackendManager->getManifestsForBackend(EffectBackendType::BuiltIn);
for (const EffectManifestPointer& pManifest : std::as_const(manifests)) {
if (!visibleEffects.contains(pManifest) &&
!hiddenEffects.contains(pManifest)) {
// pre-pend so un-hidden effects are discoverable
visibleEffects.prepend(pManifest);
}
}
setList(visibleEffects);
}

QList<EffectManifestPointer> VisibleEffectsList::readEffectsList(
const QDomDocument& doc,
EffectsBackendManagerPointer pBackendManager,
const QString& xmlElementName) {
QDomElement root = doc.documentElement();
QDomElement visibleEffectsElement = XmlParse::selectElement(root, EffectXml::kVisibleEffects);
QDomElement visibleEffectsElement = XmlParse::selectElement(root, xmlElementName);
QDomNodeList effectsElementsList = visibleEffectsElement.elementsByTagName(EffectXml::kEffect);
QList<EffectManifestPointer> list;

Expand All @@ -67,19 +95,26 @@ void VisibleEffectsList::readEffectsXml(
}
}
}
return list;
}

if (!list.isEmpty()) {
setList(list);
} else {
setList(pBackendManager->getManifestsForBackend(EffectBackendType::BuiltIn));
void VisibleEffectsList::saveEffectsXml(QDomDocument* pDoc,
EffectsBackendManagerPointer pBackendManager) {
saveEffectsListXml(pDoc, m_list, EffectXml::kVisibleEffects);
auto hiddenEffects = pBackendManager->getManifests();
for (const auto& pManifest : std::as_const(m_list)) {
hiddenEffects.removeAll(pManifest);
}
saveEffectsListXml(pDoc, hiddenEffects, EffectXml::kHiddenEffects);
}

void VisibleEffectsList::saveEffectsXml(QDomDocument* pDoc) {
void VisibleEffectsList::saveEffectsListXml(QDomDocument* pDoc,
const QList<EffectManifestPointer>& list,
const QString& xmlElementName) {
QDomElement root = pDoc->documentElement();
QDomElement visibleEffectsElement = pDoc->createElement(EffectXml::kVisibleEffects);
QDomElement visibleEffectsElement = pDoc->createElement(xmlElementName);
root.appendChild(visibleEffectsElement);
for (const auto& pManifest : std::as_const(m_list)) {
for (const auto& pManifest : std::as_const(list)) {
VERIFY_OR_DEBUG_ASSERT(pManifest) {
continue;
}
Expand Down
13 changes: 11 additions & 2 deletions src/effects/visibleeffectslist.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ class VisibleEffectsList : public QObject {
const EffectManifestPointer previous(const EffectManifestPointer pManifest) const;

void setList(const QList<EffectManifestPointer>& newList);
void readEffectsXml(const QDomDocument& doc, EffectsBackendManagerPointer pBackendManager);
void saveEffectsXml(QDomDocument* pDoc);
void readEffectsXml(const QDomDocument& doc,
EffectsBackendManagerPointer pBackendManager);
void saveEffectsXml(QDomDocument* pDoc,
EffectsBackendManagerPointer pBackendManager);

signals:
void visibleEffectsListChanged();

private:
QList<EffectManifestPointer> readEffectsList(const QDomDocument& doc,
EffectsBackendManagerPointer pBackendManager,
const QString& xmlElementName);
void saveEffectsListXml(QDomDocument* pDoc,
const QList<EffectManifestPointer>& list,
const QString& xmlElementName);

QList<EffectManifestPointer> m_list;
};

0 comments on commit df6529d

Please sign in to comment.