1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-27 06:03:51 +03:00

storage:provide orphaned subcontainments checker

This commit is contained in:
Michail Vourlakos 2021-04-29 18:21:42 +03:00
parent a2bf28054f
commit 849e66fd80
4 changed files with 60 additions and 0 deletions

View File

@ -73,6 +73,21 @@ bool ViewsTable::operator!=(const ViewsTable &rhs) const
return !(*this == rhs);
}
bool ViewsTable::hasContainmentId(const QString &cid) const
{
if (containsId(cid)) {
return true;
}
for(int i=0; i<rowCount(); ++i) {
if (m_list[i].subcontainments.containsId(cid)) {
return true;
}
}
return false;
}
ViewsTable ViewsTable::subtracted(const ViewsTable &rhs) const
{
ViewsTable subtract;

View File

@ -45,6 +45,8 @@ public:
void appendTemporaryView(const Data::View &view);
bool hasContainmentId(const QString &cid) const;
//! Operators
ViewsTable &operator=(const ViewsTable &rhs);
ViewsTable &operator=(ViewsTable &&rhs);

View File

@ -837,6 +837,47 @@ bool Storage::exportTemplate(const Layout::GenericLayout *layout, Plasma::Contai
return true;
}
bool Storage::hasOrphanedSubContainments(const Layout::GenericLayout *layout, Data::Error &warning)
{
if (!layout || layout->file().isEmpty() || !QFile(layout->file()).exists()) {
return false;
}
warning.id = m_knownErrors[Data::Error::ORPHANEDSUBCONTAINMENTS].id;
warning.name = m_knownErrors[Data::Error::ORPHANEDSUBCONTAINMENTS].name;
Data::ViewsTable views = Layouts::Storage::self()->views(layout);
if (!layout->isActive()) {
for (const auto containment : *layout->containments()) {
QString cid = QString::number(containment->id());
if (views.hasContainmentId(cid)) {
continue;
}
Data::ErrorInformation errorinfo;
errorinfo.containment = metadata(containment->pluginMetaData().pluginId());
warning.information << errorinfo;
}
} else {
KSharedConfigPtr lfile = KSharedConfig::openConfig(layout->file());
KConfigGroup containmentsEntries = KConfigGroup(lfile, "Containments");
for (const auto &cId : containmentsEntries.groupList()) {
if (views.hasContainmentId(cId)) {
continue;
}
Data::ErrorInformation errorinfo;
errorinfo.containment = metadata(containmentsEntries.group(cId).readEntry("plugin", ""));
warning.information << errorinfo;
}
}
return !warning.information.isEmpty();
}
bool Storage::isBroken(const Layout::GenericLayout *layout, QStringList &errors) const
{
if (layout->file().isEmpty() || !QFile(layout->file()).exists()) {

View File

@ -22,6 +22,7 @@
// local
#include "../data/appletdata.h"
#include "../data/errordata.h"
#include "../data/genericdata.h"
#include "../data/generictable.h"
#include "../data/viewstable.h"
@ -131,6 +132,7 @@ private:
QStringList containmentsIds(const QString &filepath);
QStringList appletsIds(const QString &filepath);
bool hasOrphanedSubContainments(const Layout::GenericLayout *layout, Data::Error &warning);
private:
QTemporaryDir m_storageTmpDir;