diff options
author | flow <flowlnlnln@gmail.com> | 2022-11-22 14:30:54 -0300 |
---|---|---|
committer | flow <flowlnlnln@gmail.com> | 2022-11-22 14:30:54 -0300 |
commit | 20c281d6f8d5f25573a8c4c930a961ea9ab45380 (patch) | |
tree | 5e6019f36a5428877f0a487aa089c990ba29a620 /launcher/ui | |
parent | 2d69d63efe12a1cfaf391a59cb6b7630a436410e (diff) | |
download | PrismLauncher-20c281d6f8d5f25573a8c4c930a961ea9ab45380.tar.gz PrismLauncher-20c281d6f8d5f25573a8c4c930a961ea9ab45380.tar.bz2 PrismLauncher-20c281d6f8d5f25573a8c4c930a961ea9ab45380.zip |
fix: reset wide bar settings when the list of actions changes
This prevents changes to the actions to cause non-intuitive issues in
the Wide bar, hiding items that previously weren't hidden.
Signed-off-by: flow <flowlnlnln@gmail.com>
Diffstat (limited to 'launcher/ui')
-rw-r--r-- | launcher/ui/widgets/WideBar.cpp | 35 | ||||
-rw-r--r-- | launcher/ui/widgets/WideBar.h | 4 |
2 files changed, 37 insertions, 2 deletions
diff --git a/launcher/ui/widgets/WideBar.cpp b/launcher/ui/widgets/WideBar.cpp index 2ad2caec..81c445cb 100644 --- a/launcher/ui/widgets/WideBar.cpp +++ b/launcher/ui/widgets/WideBar.cpp @@ -1,6 +1,7 @@ #include "WideBar.h" #include <QContextMenuEvent> +#include <QCryptographicHash> #include <QToolButton> class ActionButton : public QToolButton { @@ -211,23 +212,53 @@ void WideBar::contextMenuEvent(QContextMenuEvent* event) state.append(entry.bar_action->isVisible() ? '1' : '0'); } + state.append(','); + state.append(getHash()); + return state; } void WideBar::setVisibilityState(QByteArray&& state) { + auto split = state.split(','); + + auto bits = split.first(); + auto hash = split.last(); + + // If the actions changed, we better not try to load the old one to avoid unwanted hiding + if (!checkHash(hash)) + return; + qsizetype i = 0; for (auto& entry : m_entries) { if (entry.type != BarEntry::Type::Action) continue; - if (i == state.size()) + if (i == bits.size()) break; - entry.bar_action->setVisible(state.at(i++) == '1'); + entry.bar_action->setVisible(bits.at(i++) == '1'); // NOTE: This is needed so that disabled actions get reflected on the button when it is made visible. static_cast<ActionButton*>(widgetForAction(entry.bar_action))->actionChanged(); } } +QByteArray WideBar::getHash() const +{ + QCryptographicHash hash(QCryptographicHash::Sha1); + for (auto const& entry : m_entries) { + if (entry.type != BarEntry::Type::Action) + continue; + hash.addData(entry.menu_action->text().toLatin1()); + } + + return hash.result().toBase64(); +} + +bool WideBar::checkHash(QByteArray const& old_hash) const +{ + return old_hash == getHash(); +} + + #include "WideBar.moc" diff --git a/launcher/ui/widgets/WideBar.h b/launcher/ui/widgets/WideBar.h index 0d60f8a4..ed4cb3c7 100644 --- a/launcher/ui/widgets/WideBar.h +++ b/launcher/ui/widgets/WideBar.h @@ -41,6 +41,10 @@ class WideBar : public QToolBar { auto getMatching(QAction* act) -> QList<BarEntry>::iterator; + /** Used to distinguish between versions of the WideBar with different actions */ + [[nodiscard]] QByteArray getHash() const; + [[nodiscard]] bool checkHash(QByteArray const&) const; + private: QList<BarEntry> m_entries; |