mirror of
https://github.com/KDE/latte-dock.git
synced 2025-01-09 17:18:11 +03:00
layout:drop isBroken in favor of errors/warnings
This commit is contained in:
parent
51044ce630
commit
27d9f209ea
@ -40,7 +40,6 @@ Layout::Layout(Layout &&o)
|
|||||||
lastUsedActivity(o.lastUsedActivity),
|
lastUsedActivity(o.lastUsedActivity),
|
||||||
isActive(o.isActive),
|
isActive(o.isActive),
|
||||||
isConsideredActive(o.isConsideredActive),
|
isConsideredActive(o.isConsideredActive),
|
||||||
isBroken(o.isBroken),
|
|
||||||
isLocked(o.isLocked),
|
isLocked(o.isLocked),
|
||||||
isShownInMenu(o.isShownInMenu),
|
isShownInMenu(o.isShownInMenu),
|
||||||
isTemplate(o.isTemplate),
|
isTemplate(o.isTemplate),
|
||||||
@ -62,7 +61,6 @@ Layout::Layout(const Layout &o)
|
|||||||
lastUsedActivity(o.lastUsedActivity),
|
lastUsedActivity(o.lastUsedActivity),
|
||||||
isActive(o.isActive),
|
isActive(o.isActive),
|
||||||
isConsideredActive(o.isConsideredActive),
|
isConsideredActive(o.isConsideredActive),
|
||||||
isBroken(o.isBroken),
|
|
||||||
isLocked(o.isLocked),
|
isLocked(o.isLocked),
|
||||||
isShownInMenu(o.isShownInMenu),
|
isShownInMenu(o.isShownInMenu),
|
||||||
isTemplate(o.isTemplate),
|
isTemplate(o.isTemplate),
|
||||||
@ -86,7 +84,6 @@ Layout &Layout::operator=(Layout &&rhs)
|
|||||||
lastUsedActivity = rhs.lastUsedActivity;
|
lastUsedActivity = rhs.lastUsedActivity;
|
||||||
isActive = rhs.isActive;
|
isActive = rhs.isActive;
|
||||||
isConsideredActive = rhs.isConsideredActive;
|
isConsideredActive = rhs.isConsideredActive;
|
||||||
isBroken = rhs.isBroken;
|
|
||||||
isLocked = rhs.isLocked;
|
isLocked = rhs.isLocked;
|
||||||
isShownInMenu = rhs.isShownInMenu;
|
isShownInMenu = rhs.isShownInMenu;
|
||||||
isTemplate = rhs.isTemplate;
|
isTemplate = rhs.isTemplate;
|
||||||
@ -111,7 +108,6 @@ Layout &Layout::operator=(const Layout &rhs)
|
|||||||
lastUsedActivity = rhs.lastUsedActivity;
|
lastUsedActivity = rhs.lastUsedActivity;
|
||||||
isActive = rhs.isActive;
|
isActive = rhs.isActive;
|
||||||
isConsideredActive = rhs.isConsideredActive;
|
isConsideredActive = rhs.isConsideredActive;
|
||||||
isBroken = rhs.isBroken;
|
|
||||||
isLocked = rhs.isLocked;
|
isLocked = rhs.isLocked;
|
||||||
isShownInMenu = rhs.isShownInMenu;
|
isShownInMenu = rhs.isShownInMenu;
|
||||||
isTemplate = rhs.isTemplate;
|
isTemplate = rhs.isTemplate;
|
||||||
@ -133,7 +129,6 @@ bool Layout::operator==(const Layout &rhs) const
|
|||||||
&& (color == rhs.color)
|
&& (color == rhs.color)
|
||||||
&& (background == rhs.background)
|
&& (background == rhs.background)
|
||||||
&& (textColor == rhs.textColor)
|
&& (textColor == rhs.textColor)
|
||||||
&& (isBroken == rhs.isBroken)
|
|
||||||
//&& (lastUsedActivity == rhs.lastUsedActivity) /*Disabled because it can change too often*/
|
//&& (lastUsedActivity == rhs.lastUsedActivity) /*Disabled because it can change too often*/
|
||||||
//&& (isActive == rhs.isActive) /*Disabled because this is not a data but a layout state*/
|
//&& (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*/
|
//&& (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());
|
return isTemplate && !id.startsWith(QDir::tempPath()) && !id.startsWith(QDir::homePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Layout::hasErrors() const
|
||||||
|
{
|
||||||
|
return errors > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Layout::hasWarnings() const
|
||||||
|
{
|
||||||
|
return warnings > 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,6 @@ public:
|
|||||||
QString lastUsedActivity;
|
QString lastUsedActivity;
|
||||||
bool isActive{false};
|
bool isActive{false};
|
||||||
bool isConsideredActive{false}; //used from settings window to indicate activeness based on selected layouts mode
|
bool isConsideredActive{false}; //used from settings window to indicate activeness based on selected layouts mode
|
||||||
bool isBroken{false};
|
|
||||||
bool isLocked{false};
|
bool isLocked{false};
|
||||||
bool isShownInMenu{false};
|
bool isShownInMenu{false};
|
||||||
bool isTemplate{false};
|
bool isTemplate{false};
|
||||||
@ -74,6 +73,9 @@ public:
|
|||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
bool isSystemTemplate() const;
|
bool isSystemTemplate() const;
|
||||||
|
|
||||||
|
bool hasErrors() const;
|
||||||
|
bool hasWarnings() const;
|
||||||
|
|
||||||
//! Operators
|
//! Operators
|
||||||
Layout &operator=(const Layout &rhs);
|
Layout &operator=(const Layout &rhs);
|
||||||
Layout &operator=(Layout &&rhs);
|
Layout &operator=(Layout &&rhs);
|
||||||
|
@ -148,7 +148,6 @@ Data::Layout CentralLayout::data() const
|
|||||||
cdata.background = customBackground();
|
cdata.background = customBackground();
|
||||||
cdata.textColor = customTextColor();
|
cdata.textColor = customTextColor();
|
||||||
cdata.isActive = (m_corona != nullptr);
|
cdata.isActive = (m_corona != nullptr);
|
||||||
cdata.isBroken = isBroken();
|
|
||||||
cdata.isLocked = !isWritable();
|
cdata.isLocked = !isWritable();
|
||||||
cdata.isShownInMenu = showInMenu();
|
cdata.isShownInMenu = showInMenu();
|
||||||
cdata.hasDisabledBorders = disableBordersForMaximizedWindows();
|
cdata.hasDisabledBorders = disableBordersForMaximizedWindows();
|
||||||
|
@ -1669,12 +1669,6 @@ void GenericLayout::importToCorona()
|
|||||||
Layouts::Storage::self()->importToCorona(this);
|
Layouts::Storage::self()->importToCorona(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GenericLayout::isBroken() const
|
|
||||||
{
|
|
||||||
QStringList errors;
|
|
||||||
return Layouts::Storage::self()->isBroken(this, errors);
|
|
||||||
}
|
|
||||||
|
|
||||||
Data::ErrorsList GenericLayout::errors() const
|
Data::ErrorsList GenericLayout::errors() const
|
||||||
{
|
{
|
||||||
return Layouts::Storage::self()->errors(this);
|
return Layouts::Storage::self()->errors(this);
|
||||||
|
@ -75,7 +75,6 @@ public:
|
|||||||
bool isActive() const; //! is loaded and running
|
bool isActive() const; //! is loaded and running
|
||||||
virtual bool isCurrent();
|
virtual bool isCurrent();
|
||||||
bool isWritable() const;
|
bool isWritable() const;
|
||||||
bool isBroken() const;
|
|
||||||
|
|
||||||
virtual int viewsCount(int screen) const;
|
virtual int viewsCount(int screen) const;
|
||||||
virtual int viewsCount(QScreen *screen) const;
|
virtual int viewsCount(QScreen *screen) const;
|
||||||
|
@ -1133,136 +1133,6 @@ Data::WarningsList Storage::warnings(const Layout::GenericLayout *layout)
|
|||||||
return warns;
|
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
|
//! AppletsData Information
|
||||||
Data::Applet Storage::metadata(const QString &pluginId)
|
Data::Applet Storage::metadata(const QString &pluginId)
|
||||||
{
|
{
|
||||||
|
@ -65,7 +65,6 @@ public:
|
|||||||
bool isWritable(const Layout::GenericLayout *layout) const;
|
bool isWritable(const Layout::GenericLayout *layout) const;
|
||||||
bool isLatteContainment(const Plasma::Containment *containment) const;
|
bool isLatteContainment(const Plasma::Containment *containment) const;
|
||||||
bool isLatteContainment(const KConfigGroup &group) 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 isSubContainment(const Layout::GenericLayout *layout, const Plasma::Applet *applet) const;
|
||||||
|
|
||||||
bool containsView(const QString &filepath, const int &viewId);
|
bool containsView(const QString &filepath, const int &viewId);
|
||||||
|
@ -274,9 +274,10 @@ void Synchronizer::updateLayoutsTable()
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < m_layouts.rowCount(); ++i) {
|
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);
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -512,12 +512,11 @@ void Layouts::initLayouts()
|
|||||||
m_handler->corona()->layoutsManager()->synchronizer()->updateLayoutsTable();
|
m_handler->corona()->layoutsManager()->synchronizer()->updateLayoutsTable();
|
||||||
Latte::Data::LayoutsTable layouts = m_handler->corona()->layoutsManager()->synchronizer()->layoutsTable();
|
Latte::Data::LayoutsTable layouts = m_handler->corona()->layoutsManager()->synchronizer()->layoutsTable();
|
||||||
|
|
||||||
|
Latte::Data::LayoutsTable erroredlayouts;
|
||||||
QStringList brokenLayouts;
|
|
||||||
|
|
||||||
for (int i=0; i<layouts.rowCount(); ++i) {
|
for (int i=0; i<layouts.rowCount(); ++i) {
|
||||||
if (layouts[i].isBroken) {
|
if (layouts[i].hasErrors() || layouts[i].hasWarnings()) {
|
||||||
brokenLayouts.append(layouts[i].name);
|
erroredlayouts << layouts[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,13 +532,38 @@ void Layouts::initLayouts()
|
|||||||
applyColumnWidths();
|
applyColumnWidths();
|
||||||
|
|
||||||
//! there are broken layouts and the user must be informed!
|
//! there are broken layouts and the user must be informed!
|
||||||
if (brokenLayouts.count() > 0) {
|
if (erroredlayouts.rowCount() > 0) {
|
||||||
if (brokenLayouts.count() == 1) {
|
messagesForErroredLayouts(erroredlayouts);
|
||||||
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(", ")),
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
KMessageWidget::Error,
|
||||||
true);
|
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,
|
KMessageWidget::Error,
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
|
@ -135,6 +135,8 @@ private:
|
|||||||
QString uniqueTempDirectory();
|
QString uniqueTempDirectory();
|
||||||
QString uniqueLayoutName(QString name);
|
QString uniqueLayoutName(QString name);
|
||||||
|
|
||||||
|
void messagesForErroredLayouts(const Data::LayoutsTable &layouts);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Settings::Handler::TabLayouts *m_handler{nullptr};
|
Settings::Handler::TabLayouts *m_handler{nullptr};
|
||||||
Settings::Part::TemplatesKeeper *m_templatesKeeper{nullptr};
|
Settings::Part::TemplatesKeeper *m_templatesKeeper{nullptr};
|
||||||
|
Loading…
Reference in New Issue
Block a user