1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-23 01:33:50 +03:00

layout:drop isBroken in favor of errors/warnings

This commit is contained in:
Michail Vourlakos 2021-04-30 01:01:31 +03:00
parent 51044ce630
commit 27d9f209ea
10 changed files with 51 additions and 156 deletions

View File

@ -40,7 +40,6 @@ Layout::Layout(Layout &&o)
lastUsedActivity(o.lastUsedActivity),
isActive(o.isActive),
isConsideredActive(o.isConsideredActive),
isBroken(o.isBroken),
isLocked(o.isLocked),
isShownInMenu(o.isShownInMenu),
isTemplate(o.isTemplate),
@ -62,7 +61,6 @@ Layout::Layout(const Layout &o)
lastUsedActivity(o.lastUsedActivity),
isActive(o.isActive),
isConsideredActive(o.isConsideredActive),
isBroken(o.isBroken),
isLocked(o.isLocked),
isShownInMenu(o.isShownInMenu),
isTemplate(o.isTemplate),
@ -86,7 +84,6 @@ Layout &Layout::operator=(Layout &&rhs)
lastUsedActivity = rhs.lastUsedActivity;
isActive = rhs.isActive;
isConsideredActive = rhs.isConsideredActive;
isBroken = rhs.isBroken;
isLocked = rhs.isLocked;
isShownInMenu = rhs.isShownInMenu;
isTemplate = rhs.isTemplate;
@ -111,7 +108,6 @@ Layout &Layout::operator=(const Layout &rhs)
lastUsedActivity = rhs.lastUsedActivity;
isActive = rhs.isActive;
isConsideredActive = rhs.isConsideredActive;
isBroken = rhs.isBroken;
isLocked = rhs.isLocked;
isShownInMenu = rhs.isShownInMenu;
isTemplate = rhs.isTemplate;
@ -133,7 +129,6 @@ bool Layout::operator==(const Layout &rhs) const
&& (color == rhs.color)
&& (background == rhs.background)
&& (textColor == rhs.textColor)
&& (isBroken == rhs.isBroken)
//&& (lastUsedActivity == rhs.lastUsedActivity) /*Disabled because it can change too often*/
//&& (isActive == rhs.isActive) /*Disabled because this is not a data but a layout state*/
//&& (isConsideredActive == rhs.isConsideredActive) /*Disabled because this is not a data but a layout state*/
@ -183,6 +178,16 @@ bool Layout::isSystemTemplate() const
return isTemplate && !id.startsWith(QDir::tempPath()) && !id.startsWith(QDir::homePath());
}
bool Layout::hasErrors() const
{
return errors > 0;
}
bool Layout::hasWarnings() const
{
return warnings > 0;
}
}
}

View File

@ -53,7 +53,6 @@ public:
QString lastUsedActivity;
bool isActive{false};
bool isConsideredActive{false}; //used from settings window to indicate activeness based on selected layouts mode
bool isBroken{false};
bool isLocked{false};
bool isShownInMenu{false};
bool isTemplate{false};
@ -74,6 +73,9 @@ public:
bool isEmpty() const;
bool isSystemTemplate() const;
bool hasErrors() const;
bool hasWarnings() const;
//! Operators
Layout &operator=(const Layout &rhs);
Layout &operator=(Layout &&rhs);

View File

@ -148,7 +148,6 @@ Data::Layout CentralLayout::data() const
cdata.background = customBackground();
cdata.textColor = customTextColor();
cdata.isActive = (m_corona != nullptr);
cdata.isBroken = isBroken();
cdata.isLocked = !isWritable();
cdata.isShownInMenu = showInMenu();
cdata.hasDisabledBorders = disableBordersForMaximizedWindows();

View File

@ -1669,12 +1669,6 @@ void GenericLayout::importToCorona()
Layouts::Storage::self()->importToCorona(this);
}
bool GenericLayout::isBroken() const
{
QStringList errors;
return Layouts::Storage::self()->isBroken(this, errors);
}
Data::ErrorsList GenericLayout::errors() const
{
return Layouts::Storage::self()->errors(this);

View File

@ -75,7 +75,6 @@ public:
bool isActive() const; //! is loaded and running
virtual bool isCurrent();
bool isWritable() const;
bool isBroken() const;
virtual int viewsCount(int screen) const;
virtual int viewsCount(QScreen *screen) const;

View File

@ -1133,136 +1133,6 @@ Data::WarningsList Storage::warnings(const Layout::GenericLayout *layout)
return warns;
}
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;
}
//! AppletsData Information
Data::Applet Storage::metadata(const QString &pluginId)
{

View File

@ -65,7 +65,6 @@ public:
bool isWritable(const Layout::GenericLayout *layout) const;
bool isLatteContainment(const Plasma::Containment *containment) const;
bool isLatteContainment(const KConfigGroup &group) const;
bool isBroken(const Layout::GenericLayout *layout, QStringList &errors) const;
bool isSubContainment(const Layout::GenericLayout *layout, const Plasma::Applet *applet) const;
bool containsView(const QString &filepath, const int &viewId);

View File

@ -274,9 +274,10 @@ void Synchronizer::updateLayoutsTable()
}
for (int i = 0; i < m_layouts.rowCount(); ++i) {
if (m_layouts[i].isBroken && !m_layouts[i].isActive) {
if ((m_layouts[i].errors>0 || m_layouts[i].warnings>0) && !m_layouts[i].isActive) {
CentralLayout central(this, m_layouts[i].id);
m_layouts[i].isBroken = central.isBroken();
m_layouts[i].errors = central.errors().count();
m_layouts[i].warnings = central.warnings().count();
}
}
}

View File

@ -512,12 +512,11 @@ void Layouts::initLayouts()
m_handler->corona()->layoutsManager()->synchronizer()->updateLayoutsTable();
Latte::Data::LayoutsTable layouts = m_handler->corona()->layoutsManager()->synchronizer()->layoutsTable();
QStringList brokenLayouts;
Latte::Data::LayoutsTable erroredlayouts;
for (int i=0; i<layouts.rowCount(); ++i) {
if (layouts[i].isBroken) {
brokenLayouts.append(layouts[i].name);
if (layouts[i].hasErrors() || layouts[i].hasWarnings()) {
erroredlayouts << layouts[i];
}
}
@ -533,13 +532,38 @@ void Layouts::initLayouts()
applyColumnWidths();
//! there are broken layouts and the user must be informed!
if (brokenLayouts.count() > 0) {
if (brokenLayouts.count() == 1) {
m_handler->showInlineMessage(i18nc("settings:broken layout", "Layout <b>%0</b> <i>is broken</i>! Please <b>remove</b> it to improve stability...").arg(brokenLayouts.join(", ")),
if (erroredlayouts.rowCount() > 0) {
messagesForErroredLayouts(erroredlayouts);
}
}
void Layouts::messagesForErroredLayouts(const Data::LayoutsTable &layouts)
{
//! add only warnings first
for (int i=0; i<layouts.rowCount(); ++i) {
if (!layouts[i].hasErrors() && layouts[i].hasWarnings()) {
m_handler->showInlineMessage(i18nc("settings:layout with warnings",
"Warning: Be careful, Layout <b>%0</b> reports <b>%1 warning(s)</b> that might need your attention.").arg(layouts[i].name).arg(layouts[i].warnings),
KMessageWidget::Warning,
true);
}
}
//! add errors in the end in order to be read by the user
for (int i=0; i<layouts.rowCount(); ++i) {
if (layouts[i].hasErrors() && !layouts[i].hasWarnings()) {
m_handler->showInlineMessage(i18nc("settings:layout with errors",
"Error: Be careful, Layout <b>%0</b> reports <b>%1 error(s)</b> that you need to repair.").arg(layouts[i].name).arg(layouts[i].errors),
KMessageWidget::Error,
true);
} else {
m_handler->showInlineMessage(i18nc("settings:broken layouts", "Layouts <b>%0</b> <i>are broken</i>! Please <b>remove</b> them to improve stability...").arg(brokenLayouts.join(", ")),
}
}
//! add most important errors in the end in order to be read by the user
for (int i=0; i<layouts.rowCount(); ++i) {
if (layouts[i].hasErrors() && layouts[i].hasWarnings()) {
m_handler->showInlineMessage(i18nc("settings:layout with errors and warnings",
"Error: Be careful, Layout <b>%0</b> reports <b>%1 error(s)</b> and <b>%2 warning(s)</b> that you need to repair.").arg(layouts[i].name).arg(layouts[i].errors).arg(layouts[i].warnings),
KMessageWidget::Error,
true);
}

View File

@ -135,6 +135,8 @@ private:
QString uniqueTempDirectory();
QString uniqueLayoutName(QString name);
void messagesForErroredLayouts(const Data::LayoutsTable &layouts);
private:
Settings::Handler::TabLayouts *m_handler{nullptr};
Settings::Part::TemplatesKeeper *m_templatesKeeper{nullptr};