mirror of
https://github.com/KDE/latte-dock.git
synced 2025-03-09 16:58:16 +03:00
storage:provide appletAndContainmentSameId checker
This commit is contained in:
parent
c74f5cf7fc
commit
2be67b11c5
@ -27,6 +27,7 @@
|
||||
#include "errorinformationdata.h"
|
||||
|
||||
//! Qt
|
||||
#include <QList>
|
||||
#include <QMetaType>
|
||||
#include <QString>
|
||||
|
||||
@ -58,6 +59,8 @@ private:
|
||||
|
||||
};
|
||||
|
||||
typedef QList<Error> ErrorList;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -846,10 +846,11 @@ bool Storage::hasDifferentAppletsWithSameId(const Layout::GenericLayout *layout,
|
||||
error.id = m_knownErrors[Data::Error::APPLETSWITHSAMEID].id;
|
||||
error.name = m_knownErrors[Data::Error::APPLETSWITHSAMEID].name;
|
||||
|
||||
if (!layout->isActive()) { // active layout
|
||||
if (layout->isActive()) { // active layout
|
||||
QStringList registeredapplets;
|
||||
QStringList conflictedapplets;
|
||||
|
||||
//! split ids to normal registered and conflicted
|
||||
for (const auto containment : *layout->containments()) {
|
||||
QString cid = QString::number(containment->id());
|
||||
|
||||
@ -864,7 +865,7 @@ bool Storage::hasDifferentAppletsWithSameId(const Layout::GenericLayout *layout,
|
||||
}
|
||||
}
|
||||
|
||||
//! this way we make sure to file also applets that first touch did not identified them as conflicted
|
||||
//! create error data
|
||||
for (const auto containment : *layout->containments()) {
|
||||
QString cid = QString::number(containment->id());
|
||||
|
||||
@ -891,6 +892,7 @@ bool Storage::hasDifferentAppletsWithSameId(const Layout::GenericLayout *layout,
|
||||
QStringList registeredapplets;
|
||||
QStringList conflictedapplets;
|
||||
|
||||
//! split ids to normal registered and conflicted
|
||||
for (const auto &cid : containmentsEntries.groupList()) {
|
||||
for (const auto &aid : containmentsEntries.group(cid).group("Applets").groupList()) {
|
||||
if (!registeredapplets.contains(aid)) {
|
||||
@ -901,7 +903,7 @@ bool Storage::hasDifferentAppletsWithSameId(const Layout::GenericLayout *layout,
|
||||
}
|
||||
}
|
||||
|
||||
//! this way we make sure to file also applets that first touch did not identified them as conflicted
|
||||
//! create error data
|
||||
for (const auto &cid : containmentsEntries.groupList()) {
|
||||
for (const auto &aid : containmentsEntries.group(cid).group("Applets").groupList()) {
|
||||
if (!conflictedapplets.contains(aid)) {
|
||||
@ -922,6 +924,129 @@ bool Storage::hasDifferentAppletsWithSameId(const Layout::GenericLayout *layout,
|
||||
return !error.information.isEmpty();
|
||||
}
|
||||
|
||||
bool Storage::hasAppletsAndContainmentsWithSameId(const Layout::GenericLayout *layout, Data::Error &warning)
|
||||
{
|
||||
if (!layout || layout->file().isEmpty() || !QFile(layout->file()).exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
warning.id = m_knownErrors[Data::Error::APPLETSANDCONTAINMENTSWITHSAMEID].id;
|
||||
warning.name = m_knownErrors[Data::Error::APPLETSANDCONTAINMENTSWITHSAMEID].name;
|
||||
|
||||
if (layout->isActive()) { // active layout
|
||||
QStringList registeredcontainments;
|
||||
QStringList conflicted;
|
||||
|
||||
//! discover normal containment ids
|
||||
for (const auto containment : *layout->containments()) {
|
||||
QString cid = QString::number(containment->id());
|
||||
|
||||
if (registeredcontainments.contains(cid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
registeredcontainments << cid;
|
||||
}
|
||||
|
||||
//! discover conflicted ids between containments and applets
|
||||
for (const auto containment : *layout->containments()) {
|
||||
QString cid = QString::number(containment->id());
|
||||
|
||||
for (const auto applet : containment->applets()) {
|
||||
QString aid = QString::number(applet->id());
|
||||
|
||||
if (!registeredcontainments.contains(aid)) {
|
||||
continue;
|
||||
} else if (!conflicted.contains(aid)) {
|
||||
conflicted << aid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! create warning data
|
||||
for (const auto containment : *layout->containments()) {
|
||||
QString cid = QString::number(containment->id());
|
||||
|
||||
if (conflicted.contains(cid)) {
|
||||
Data::ErrorInformation errorinfo;
|
||||
errorinfo.containment = metadata(containment->pluginMetaData().pluginId());
|
||||
errorinfo.containment.storageId = cid;
|
||||
|
||||
warning.information << errorinfo;
|
||||
}
|
||||
|
||||
for (const auto applet : containment->applets()) {
|
||||
QString aid = QString::number(applet->id());
|
||||
|
||||
if (!conflicted.contains(aid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Data::ErrorInformation errorinfo;
|
||||
errorinfo.containment = metadata(containment->pluginMetaData().pluginId());
|
||||
errorinfo.containment.storageId = cid;
|
||||
errorinfo.applet = metadata(applet->pluginMetaData().pluginId());
|
||||
errorinfo.applet.storageId = aid;
|
||||
|
||||
warning.information << errorinfo;
|
||||
}
|
||||
}
|
||||
} else { // inactive layout
|
||||
KSharedConfigPtr lfile = KSharedConfig::openConfig(layout->file());
|
||||
KConfigGroup containmentsEntries = KConfigGroup(lfile, "Containments");
|
||||
|
||||
QStringList registeredcontainments;
|
||||
QStringList conflicted;
|
||||
|
||||
//! discover normal containment ids
|
||||
for (const auto &cid : containmentsEntries.groupList()) {
|
||||
if (registeredcontainments.contains(cid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
registeredcontainments << cid;
|
||||
}
|
||||
|
||||
//! discover conflicted ids between containments and applets
|
||||
for (const auto &cid : containmentsEntries.groupList()) {
|
||||
for (const auto &aid : containmentsEntries.group(cid).group("Applets").groupList()) {
|
||||
if (!registeredcontainments.contains(aid)) {
|
||||
continue;
|
||||
} else if (!conflicted.contains(aid)) {
|
||||
conflicted << aid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! create warning data
|
||||
for (const auto &cid : containmentsEntries.groupList()) {
|
||||
if (conflicted.contains(cid)) {
|
||||
Data::ErrorInformation errorinfo;
|
||||
errorinfo.containment = metadata(containmentsEntries.group(cid).readEntry("plugin", ""));
|
||||
errorinfo.containment.storageId = cid;
|
||||
|
||||
warning.information << errorinfo;
|
||||
}
|
||||
|
||||
for (const auto &aid : containmentsEntries.group(cid).group("Applets").groupList()) {
|
||||
if (!conflicted.contains(aid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Data::ErrorInformation errorinfo;
|
||||
errorinfo.containment = metadata(containmentsEntries.group(cid).readEntry("plugin", ""));
|
||||
errorinfo.containment.storageId = cid;
|
||||
errorinfo.applet = metadata(containmentsEntries.group(cid).group("Applets").group(aid).readEntry("plugin", ""));
|
||||
errorinfo.applet.storageId = aid;
|
||||
|
||||
warning.information << errorinfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !warning.information.isEmpty();
|
||||
}
|
||||
|
||||
bool Storage::hasOrphanedSubContainments(const Layout::GenericLayout *layout, Data::Error &warning)
|
||||
{
|
||||
if (!layout || layout->file().isEmpty() || !QFile(layout->file()).exists()) {
|
||||
@ -933,7 +1058,8 @@ bool Storage::hasOrphanedSubContainments(const Layout::GenericLayout *layout, Da
|
||||
|
||||
Data::ViewsTable views = Layouts::Storage::self()->views(layout);
|
||||
|
||||
if (!layout->isActive()) { // active layout
|
||||
if (layout->isActive()) { // active layout
|
||||
//! create warning data
|
||||
for (const auto containment : *layout->containments()) {
|
||||
QString cid = QString::number(containment->id());
|
||||
|
||||
@ -946,10 +1072,12 @@ bool Storage::hasOrphanedSubContainments(const Layout::GenericLayout *layout, Da
|
||||
errorinfo.containment.storageId = cid;
|
||||
warning.information << errorinfo;
|
||||
}
|
||||
|
||||
} else { // inactive layout
|
||||
KSharedConfigPtr lfile = KSharedConfig::openConfig(layout->file());
|
||||
KConfigGroup containmentsEntries = KConfigGroup(lfile, "Containments");
|
||||
|
||||
//! create warning data
|
||||
for (const auto &cid : containmentsEntries.groupList()) {
|
||||
if (views.hasContainmentId(cid)) {
|
||||
continue;
|
||||
|
@ -134,6 +134,7 @@ private:
|
||||
|
||||
//! errors/warnings checkers
|
||||
bool hasDifferentAppletsWithSameId(const Layout::GenericLayout *layout, Data::Error &error);
|
||||
bool hasAppletsAndContainmentsWithSameId(const Layout::GenericLayout *layout, Data::Error &warning);
|
||||
bool hasOrphanedSubContainments(const Layout::GenericLayout *layout, Data::Error &warning);
|
||||
private:
|
||||
QTemporaryDir m_storageTmpDir;
|
||||
|
Loading…
x
Reference in New Issue
Block a user