mirror of
https://github.com/KDE/latte-dock.git
synced 2025-01-09 17:18:11 +03:00
layouts::storage, move isBroken() function
This commit is contained in:
parent
9a1346d04a
commit
d97be6744d
@ -612,7 +612,7 @@ QList<ViewData> GenericLayout::sortedViewsData(const QList<ViewData> &viewsData)
|
||||
}
|
||||
|
||||
|
||||
const QList<Plasma::Containment *> *GenericLayout::containments()
|
||||
const QList<Plasma::Containment *> *GenericLayout::containments() const
|
||||
{
|
||||
return &m_containments;
|
||||
}
|
||||
@ -1603,7 +1603,7 @@ QString GenericLayout::reportHtml(const ScreenPool *screenPool)
|
||||
report += "<br/><hr>";
|
||||
|
||||
QStringList errorsList;
|
||||
bool broken = m_storage->layoutIsBroken(errorsList);
|
||||
bool broken = Layouts::Storage::self()->isBroken(this, errorsList);
|
||||
|
||||
if (!broken && unknownScreens.count() == 0) {
|
||||
report += "<font color='green'>" + i18n("No errors were identified for this layout...") + "</font><br/>";
|
||||
@ -1691,10 +1691,10 @@ void GenericLayout::importToCorona()
|
||||
Layouts::Storage::self()->importToCorona(this);
|
||||
}
|
||||
|
||||
bool GenericLayout::layoutIsBroken() const
|
||||
bool GenericLayout::isBroken() const
|
||||
{
|
||||
QStringList errors;
|
||||
return m_storage->layoutIsBroken(errors);
|
||||
return Layouts::Storage::self()->isBroken(this, errors);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ public:
|
||||
bool isActive() const; //! is loaded and running
|
||||
virtual bool isCurrent() const;
|
||||
bool isWritable() const;
|
||||
bool layoutIsBroken() const;
|
||||
bool isBroken() const;
|
||||
|
||||
bool isSubContainment(Plasma::Applet *applet) const;
|
||||
Plasma::Containment *subContainmentOf(Plasma::Applet *applet) const;
|
||||
@ -104,7 +104,7 @@ public:
|
||||
QStringList unloadedContainmentsIds();
|
||||
|
||||
virtual Types::ViewType latteViewType(uint containmentId) const;
|
||||
const QList<Plasma::Containment *> *containments();
|
||||
const QList<Plasma::Containment *> *containments() const;
|
||||
|
||||
Latte::View *highestPriorityView();
|
||||
Latte::View *viewForContainment(Plasma::Containment *containment);
|
||||
|
@ -540,135 +540,5 @@ QString Storage::newUniqueIdsLayoutFromFile(QString file)
|
||||
return tempFile;
|
||||
}
|
||||
|
||||
bool Storage::layoutIsBroken(QStringList &errors) const
|
||||
{
|
||||
if (m_layout->file().isEmpty() || !QFile(m_layout->file()).exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList ids;
|
||||
QStringList conts;
|
||||
QStringList applets;
|
||||
|
||||
KSharedConfigPtr lFile = KSharedConfig::openConfig(m_layout->file());
|
||||
|
||||
if (!m_layout->corona()) {
|
||||
KConfigGroup containmentsEntries = KConfigGroup(lFile, "Containments");
|
||||
ids << containmentsEntries.groupList();
|
||||
conts << ids;
|
||||
|
||||
for (const auto &cId : containmentsEntries.groupList()) {
|
||||
auto appletsEntries = containmentsEntries.group(cId).group("Applets");
|
||||
|
||||
QStringList validAppletIds;
|
||||
bool updated{false};
|
||||
|
||||
for (const auto &appletId : appletsEntries.groupList()) {
|
||||
KConfigGroup appletGroup = appletsEntries.group(appletId);
|
||||
|
||||
if (Layouts::Storage::appletGroupIsValid(appletGroup)) {
|
||||
validAppletIds << appletId;
|
||||
} else {
|
||||
updated = true;
|
||||
//! heal layout file by removing applet config records that are not used any more
|
||||
qDebug() << "Layout: " << m_layout->name() << " removing deprecated applet : " << appletId;
|
||||
appletsEntries.deleteGroup(appletId);
|
||||
}
|
||||
}
|
||||
|
||||
if (updated) {
|
||||
appletsEntries.sync();
|
||||
}
|
||||
|
||||
ids << validAppletIds;
|
||||
applets << validAppletIds;
|
||||
}
|
||||
} else {
|
||||
for (const auto containment : *m_layout->containments()) {
|
||||
ids << QString::number(containment->id());
|
||||
conts << QString::number(containment->id());
|
||||
|
||||
for (const auto applet : containment->applets()) {
|
||||
ids << QString::number(applet->id());
|
||||
applets << QString::number(applet->id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
|
||||
QSet<QString> idsSet = QSet<QString>::fromList(ids);
|
||||
#else
|
||||
QSet<QString> idsSet(ids.begin(), ids.end());
|
||||
#endif
|
||||
/* a different way to count duplicates
|
||||
QMap<QString, int> countOfStrings;
|
||||
|
||||
for (int i = 0; i < ids.count(); i++) {
|
||||
countOfStrings[ids[i]]++;
|
||||
}*/
|
||||
|
||||
if (idsSet.count() != ids.count()) {
|
||||
qDebug() << " ---- ERROR - BROKEN LAYOUT :: " << m_layout->name() << " ----";
|
||||
|
||||
if (!m_layout->corona()) {
|
||||
qDebug() << " --- storaged file : " << m_layout->file();
|
||||
} else {
|
||||
if (m_layout->corona()->layoutsManager()->memoryUsage() == MemoryUsage::MultipleLayouts) {
|
||||
qDebug() << " --- in multiple layouts hidden file : " << Layouts::Importer::layoutUserFilePath(MULTIPLELAYOUTSHIDDENNAME);
|
||||
} else {
|
||||
qDebug() << " --- in active layout file : " << m_layout->file();
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "Containments :: " << conts;
|
||||
qDebug() << "Applets :: " << applets;
|
||||
|
||||
for (const QString &c : conts) {
|
||||
if (applets.contains(c)) {
|
||||
QString errorStr = i18n("Same applet and containment id found ::: ") + c;
|
||||
qDebug() << "Error: " << errorStr;
|
||||
errors << errorStr;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < ids.count(); ++i) {
|
||||
for (int j = i + 1; j < ids.count(); ++j) {
|
||||
if (ids[i] == ids[j]) {
|
||||
QString errorStr = i18n("Different applets with same id ::: ") + ids[i];
|
||||
qDebug() << "Error: " << errorStr;
|
||||
errors << errorStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << " -- - -- - -- - -- - - -- - - - - -- - - - - ";
|
||||
|
||||
if (!m_layout->corona()) {
|
||||
KConfigGroup containmentsEntries = KConfigGroup(lFile, "Containments");
|
||||
|
||||
for (const auto &cId : containmentsEntries.groupList()) {
|
||||
auto appletsEntries = containmentsEntries.group(cId).group("Applets");
|
||||
|
||||
qDebug() << " CONTAINMENT : " << cId << " APPLETS : " << appletsEntries.groupList();
|
||||
}
|
||||
} else {
|
||||
for (const auto containment : *m_layout->containments()) {
|
||||
QStringList appletsIds;
|
||||
|
||||
for (const auto applet : containment->applets()) {
|
||||
appletsIds << QString::number(applet->id());
|
||||
}
|
||||
|
||||
qDebug() << " CONTAINMENT : " << containment->id() << " APPLETS : " << appletsIds.join(",");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -40,8 +40,6 @@ public:
|
||||
Storage(GenericLayout *parent);
|
||||
~Storage() override;
|
||||
|
||||
bool layoutIsBroken(QStringList &errors) const;
|
||||
|
||||
void copyView(Plasma::Containment *containment);
|
||||
void syncToLayoutFile(bool removeLayoutId);
|
||||
|
||||
|
@ -20,8 +20,10 @@
|
||||
#include "storage.h"
|
||||
|
||||
// local
|
||||
#include "importer.h"
|
||||
#include "manager.h"
|
||||
#include "../lattecorona.h"
|
||||
#include "../layout/abstractlayout.h"
|
||||
#include "../layout/storage.h"
|
||||
|
||||
// Qt
|
||||
@ -375,5 +377,133 @@ QList<Plasma::Containment *> Storage::importLayoutFile(const Layout::GenericLayo
|
||||
return importedDocks;
|
||||
}
|
||||
|
||||
bool Storage::isBroken(const Layout::GenericLayout *layout, QStringList &errors) const
|
||||
{
|
||||
if (layout->file().isEmpty() || !QFile(layout->file()).exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList ids;
|
||||
QStringList conts;
|
||||
QStringList applets;
|
||||
|
||||
KSharedConfigPtr lFile = KSharedConfig::openConfig(layout->file());
|
||||
|
||||
if (!layout->corona()) {
|
||||
KConfigGroup containmentsEntries = KConfigGroup(lFile, "Containments");
|
||||
ids << containmentsEntries.groupList();
|
||||
conts << ids;
|
||||
|
||||
for (const auto &cId : containmentsEntries.groupList()) {
|
||||
auto appletsEntries = containmentsEntries.group(cId).group("Applets");
|
||||
|
||||
QStringList validAppletIds;
|
||||
bool updated{false};
|
||||
|
||||
for (const auto &appletId : appletsEntries.groupList()) {
|
||||
KConfigGroup appletGroup = appletsEntries.group(appletId);
|
||||
|
||||
if (Layouts::Storage::appletGroupIsValid(appletGroup)) {
|
||||
validAppletIds << appletId;
|
||||
} else {
|
||||
updated = true;
|
||||
//! heal layout file by removing applet config records that are not used any more
|
||||
qDebug() << "Layout: " << layout->name() << " removing deprecated applet : " << appletId;
|
||||
appletsEntries.deleteGroup(appletId);
|
||||
}
|
||||
}
|
||||
|
||||
if (updated) {
|
||||
appletsEntries.sync();
|
||||
}
|
||||
|
||||
ids << validAppletIds;
|
||||
applets << validAppletIds;
|
||||
}
|
||||
} else {
|
||||
for (const auto containment : *layout->containments()) {
|
||||
ids << QString::number(containment->id());
|
||||
conts << QString::number(containment->id());
|
||||
|
||||
for (const auto applet : containment->applets()) {
|
||||
ids << QString::number(applet->id());
|
||||
applets << QString::number(applet->id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
|
||||
QSet<QString> idsSet = QSet<QString>::fromList(ids);
|
||||
#else
|
||||
QSet<QString> idsSet(ids.begin(), ids.end());
|
||||
#endif
|
||||
/* a different way to count duplicates
|
||||
QMap<QString, int> countOfStrings;
|
||||
|
||||
for (int i = 0; i < ids.count(); i++) {
|
||||
countOfStrings[ids[i]]++;
|
||||
}*/
|
||||
|
||||
if (idsSet.count() != ids.count()) {
|
||||
qDebug() << " ---- ERROR - BROKEN LAYOUT :: " << layout->name() << " ----";
|
||||
|
||||
if (!layout->corona()) {
|
||||
qDebug() << " --- storaged file : " << layout->file();
|
||||
} else {
|
||||
if (layout->corona()->layoutsManager()->memoryUsage() == MemoryUsage::MultipleLayouts) {
|
||||
qDebug() << " --- in multiple layouts hidden file : " << Layouts::Importer::layoutUserFilePath(Layout::MULTIPLELAYOUTSHIDDENNAME);
|
||||
} else {
|
||||
qDebug() << " --- in active layout file : " << layout->file();
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "Containments :: " << conts;
|
||||
qDebug() << "Applets :: " << applets;
|
||||
|
||||
for (const QString &c : conts) {
|
||||
if (applets.contains(c)) {
|
||||
QString errorStr = i18n("Same applet and containment id found ::: ") + c;
|
||||
qDebug() << "Error: " << errorStr;
|
||||
errors << errorStr;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < ids.count(); ++i) {
|
||||
for (int j = i + 1; j < ids.count(); ++j) {
|
||||
if (ids[i] == ids[j]) {
|
||||
QString errorStr = i18n("Different applets with same id ::: ") + ids[i];
|
||||
qDebug() << "Error: " << errorStr;
|
||||
errors << errorStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << " -- - -- - -- - -- - - -- - - - - -- - - - - ";
|
||||
|
||||
if (!layout->corona()) {
|
||||
KConfigGroup containmentsEntries = KConfigGroup(lFile, "Containments");
|
||||
|
||||
for (const auto &cId : containmentsEntries.groupList()) {
|
||||
auto appletsEntries = containmentsEntries.group(cId).group("Applets");
|
||||
|
||||
qDebug() << " CONTAINMENT : " << cId << " APPLETS : " << appletsEntries.groupList();
|
||||
}
|
||||
} else {
|
||||
for (const auto containment : *layout->containments()) {
|
||||
QStringList appletsIds;
|
||||
|
||||
for (const auto applet : containment->applets()) {
|
||||
appletsIds << QString::number(applet->id());
|
||||
}
|
||||
|
||||
qDebug() << " CONTAINMENT : " << containment->id() << " APPLETS : " << appletsIds.join(",");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ public:
|
||||
bool isWritable(const Layout::GenericLayout *layout) const;
|
||||
bool isLatteContainment(Plasma::Containment *containment) const;
|
||||
bool isLatteContainment(const KConfigGroup &group) const;
|
||||
bool isBroken(const Layout::GenericLayout *layout, QStringList &errors) const;
|
||||
|
||||
void lock(const Layout::GenericLayout *layout); //! make it only read-only
|
||||
void unlock(const Layout::GenericLayout *layout); //! make it writable which it should be the default
|
||||
|
@ -434,7 +434,7 @@ void Layouts::loadLayouts()
|
||||
|
||||
Latte::Layout::GenericLayout *generic = m_handler->corona()->layoutsManager()->synchronizer()->layout(central->name());
|
||||
|
||||
if ((generic && generic->layoutIsBroken()) || (!generic && central->layoutIsBroken())) {
|
||||
if ((generic && generic->isBroken()) || (!generic && central->isBroken())) {
|
||||
brokenLayouts.append(central->name());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user