1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-09 17:18:11 +03:00

support running views data from Layouts::Storage

This commit is contained in:
Michail Vourlakos 2021-03-21 15:31:47 +02:00
parent 87ddf1f6d6
commit a7ac422b31
6 changed files with 103 additions and 54 deletions

View File

@ -58,7 +58,6 @@ public:
float maxLength{1.0}; float maxLength{1.0};
Plasma::Types::Location edge{Plasma::Types::BottomEdge}; Plasma::Types::Location edge{Plasma::Types::BottomEdge};
Latte::Types::Alignment alignment{Latte::Types::Center}; Latte::Types::Alignment alignment{Latte::Types::Center};
GenericTable<Data::Generic> subcontainments; GenericTable<Data::Generic> subcontainments;
bool isValid() const; bool isValid() const;

View File

@ -154,17 +154,7 @@ void GenericLayout::setBlockAutomaticLatteViewCreation(bool block)
bool GenericLayout::isActive() const bool GenericLayout::isActive() const
{ {
if (!m_corona) { return m_corona && (m_corona->layoutsManager()->synchronizer()->layout(m_layoutName) != nullptr);
return false;
}
GenericLayout *generic = m_corona->layoutsManager()->synchronizer()->layout(m_layoutName);
if (generic) {
return true;
} else {
return false;
}
} }
bool GenericLayout::isCurrent() bool GenericLayout::isCurrent()

View File

@ -20,6 +20,7 @@
#include "storage.h" #include "storage.h"
// local // local
#include <coretypes.h>
#include "importer.h" #include "importer.h"
#include "manager.h" #include "manager.h"
#include "../lattecorona.h" #include "../lattecorona.h"
@ -84,7 +85,7 @@ bool Storage::isWritable(const Layout::GenericLayout *layout) const
} }
} }
bool Storage::isLatteContainment(Plasma::Containment *containment) const bool Storage::isLatteContainment(const Plasma::Containment *containment) const
{ {
if (!containment) { if (!containment) {
return false; return false;
@ -1173,40 +1174,32 @@ Data::AppletsTable Storage::plugins(const QString &layoutfile, const int contain
return knownapplets; return knownapplets;
} }
//! Views Data
//! Data For Reports Data::GenericTable<Data::Generic> Storage::subcontainments(const Layout::GenericLayout *layout, const Plasma::Containment *lattecontainment) const
void Storage::subContainmentsInfo(const QString &file, QHash<int, QList<int>> &subContainments, QList<int> &assignedSubContainments, QList<int> &orphanSubContainments)
{ {
subContainments.clear(); Data::GenericTable<Data::Generic> subs;
assignedSubContainments.clear();
orphanSubContainments.clear();
KSharedConfigPtr lFile = KSharedConfig::openConfig(file); if (!layout || !Layouts::Storage::self()->isLatteContainment(lattecontainment)) {
KConfigGroup containmentGroups = KConfigGroup(lFile, "Containments"); return subs;
//! assigned subcontainments
for (const auto &cId : containmentGroups.groupList()) {
if (Layouts::Storage::self()->isLatteContainment(containmentGroups.group(cId))) {
auto applets = containmentGroups.group(cId).group("Applets");
for (const auto &applet : applets.groupList()) {
KConfigGroup appletSettings = applets.group(applet).group("Configuration");
int tSubId = appletSettings.readEntry("SystrayContainmentId", IDNULL);
if (isValid(tSubId)) {
assignedSubContainments << tSubId;
subContainments[cId.toInt()].append(tSubId);
} }
for (const auto containment : (*layout->containments())) {
if (containment == lattecontainment) {
continue;
} }
Plasma::Applet *parentApplet = qobject_cast<Plasma::Applet *>(containment->parent());
//! add subcontainments for that lattecontainment
if (parentApplet && parentApplet->containment() && parentApplet->containment() == lattecontainment) {
Data::Generic subdata;
subdata.id = QString::number(containment->id());
subs << subdata;
} }
} }
//! orphan subcontainments return subs;
for (const auto &cId : containmentGroups.groupList()) {
if (!Layouts::Storage::self()->isLatteContainment(containmentGroups.group(cId)) && !assignedSubContainments.contains(cId.toInt())) {
orphanSubContainments << cId.toInt();
}
}
} }
Data::GenericTable<Data::Generic> Storage::subcontainments(const KConfigGroup &containmentGroup) Data::GenericTable<Data::Generic> Storage::subcontainments(const KConfigGroup &containmentGroup)
@ -1230,6 +1223,26 @@ Data::GenericTable<Data::Generic> Storage::subcontainments(const KConfigGroup &c
return subs; return subs;
} }
Data::View Storage::view(const Layout::GenericLayout *layout, const Plasma::Containment *lattecontainment)
{
Data::View vdata;
if (!layout || !Layouts::Storage::self()->isLatteContainment(lattecontainment)) {
return vdata;
}
vdata = view(lattecontainment->config());
vdata.screen = lattecontainment->screen();
if (!isValid(vdata.screen)) {
vdata.screen = lattecontainment->lastScreen();
}
vdata.subcontainments = subcontainments(layout, lattecontainment);
return vdata;
}
Data::View Storage::view(const KConfigGroup &containmentGroup) Data::View Storage::view(const KConfigGroup &containmentGroup)
{ {
Data::View vdata; Data::View vdata;
@ -1238,28 +1251,52 @@ Data::View Storage::view(const KConfigGroup &containmentGroup)
return vdata; return vdata;
} }
//! id
vdata.id = containmentGroup.name(); vdata.id = containmentGroup.name();
//! active
vdata.isActive = false; vdata.isActive = false;
//! onPrimary
vdata.onPrimary = containmentGroup.readEntry("onPrimary", true); vdata.onPrimary = containmentGroup.readEntry("onPrimary", true);
//! screen
vdata.screen = containmentGroup.readEntry("lastScreen", IDNULL); vdata.screen = containmentGroup.readEntry("lastScreen", IDNULL);
//! edge
int location = containmentGroup.readEntry("location", (int)Plasma::Types::BottomEdge); int location = containmentGroup.readEntry("location", (int)Plasma::Types::BottomEdge);
vdata.edge = (Plasma::Types::Location)location; vdata.edge = (Plasma::Types::Location)location;
//! subcontainments vdata.maxLength = containmentGroup.group("General").readEntry("maxLength", (float)100.0);
int alignment = containmentGroup.group("General").readEntry("alignment", (int)Latte::Types::Center) ;
vdata.alignment = (Latte::Types::Alignment)alignment;
vdata.subcontainments = subcontainments(containmentGroup); vdata.subcontainments = subcontainments(containmentGroup);
vdata.setState(Data::View::IsCreated);
return vdata; return vdata;
} }
Data::ViewsTable Storage::views(const Layout::GenericLayout *layout)
{
Data::ViewsTable vtable;
if (!layout) {
return vtable;
} else if (!layout->isActive()) {
return views(layout->file());
}
for (const auto containment : (*layout->containments())) {
if (!isLatteContainment(containment)) {
continue;
}
Latte::View *vw = layout->viewForContainment(containment);
if (vw) {
vtable << vw->data();
} else {
vtable << view(layout, containment);
}
}
return vtable;
}
Data::ViewsTable Storage::views(const QString &file) Data::ViewsTable Storage::views(const QString &file)
{ {
Data::ViewsTable vtable; Data::ViewsTable vtable;

View File

@ -69,7 +69,7 @@ public:
static const int IDBASE; static const int IDBASE;
bool isWritable(const Layout::GenericLayout *layout) const; bool isWritable(const Layout::GenericLayout *layout) const;
bool isLatteContainment(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 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;
@ -100,13 +100,15 @@ public:
Data::AppletsTable plugins(const Layout::GenericLayout *layout, const int containmentid = IDNULL); Data::AppletsTable plugins(const Layout::GenericLayout *layout, const int containmentid = IDNULL);
Data::AppletsTable plugins(const QString &layoutfile, const int containmentid = IDNULL); Data::AppletsTable plugins(const QString &layoutfile, const int containmentid = IDNULL);
//! Functions used from Layout Reports
//! [containment id, list<subcontainment ids>], list<subcontainment ids>, list[subcontainment ids]
void subContainmentsInfo(const QString &file, QHash<int, QList<int>> &subContainments, QList<int> &assignedSubContainments, QList<int> &orphanSubContainments);
//! list<screens ids> //! list<screens ids>
QList<int> viewsScreens(const QString &file); QList<int> viewsScreens(const QString &file);
Data::GenericTable<Data::Generic> subcontainments(const KConfigGroup &containmentGroup);
Data::GenericTable<Data::Generic> subcontainments(const Layout::GenericLayout *layout, const Plasma::Containment *lattecontainment) const;
Data::View view(const KConfigGroup &containmentGroup);
Data::View view(const Layout::GenericLayout *layout, const Plasma::Containment *lattecontainment);
Data::ViewsTable views(const QString &file); Data::ViewsTable views(const QString &file);
Data::ViewsTable views(const Layout::GenericLayout *layout);
private: private:
Storage(); Storage();
@ -125,9 +127,6 @@ private:
//! imports a layout file and returns the containments for the docks //! imports a layout file and returns the containments for the docks
QList<Plasma::Containment *> importLayoutFile(const Layout::GenericLayout *layout, QString file); QList<Plasma::Containment *> importLayoutFile(const Layout::GenericLayout *layout, QString file);
Data::View view(const KConfigGroup &containmentGroup);
Data::GenericTable<Data::Generic> subcontainments(const KConfigGroup &containmentGroup);
private: private:
QTemporaryDir m_storageTmpDir; QTemporaryDir m_storageTmpDir;

View File

@ -1273,6 +1273,27 @@ bool View::mimeContainsPlasmoid(QMimeData *mimeData, QString name)
return false; return false;
} }
Latte::Data::View View::data() const
{
Latte::Data::View vdata;
vdata.id = QString::number(containment()->id());
vdata.isActive = true;
vdata.onPrimary = onPrimary();
vdata.screen = containment()->screen();
if (!Layouts::Storage::isValid(vdata.screen)) {
vdata.screen = containment()->lastScreen();
}
vdata.edge = location();
vdata.maxLength = m_maxLength * 100;
vdata.alignment = m_alignment;
vdata.subcontainments = Layouts::Storage::self()->subcontainments(layout(), containment());
vdata.setState(Latte::Data::View::IsCreated);
return vdata;
}
QQuickItem *View::colorizer() const QQuickItem *View::colorizer() const
{ {
return m_colorizer; return m_colorizer;

View File

@ -32,6 +32,7 @@
#include "indicator/indicator.h" #include "indicator/indicator.h"
#include "settings/primaryconfigview.h" #include "settings/primaryconfigview.h"
#include "windowstracker/windowstracker.h" #include "windowstracker/windowstracker.h"
#include "../data/viewdata.h"
#include "../shortcuts/globalshortcuts.h" #include "../shortcuts/globalshortcuts.h"
#include "../layout/genericlayout.h" #include "../layout/genericlayout.h"
#include "../plasma/quick/containmentview.h" #include "../plasma/quick/containmentview.h"
@ -237,6 +238,8 @@ public:
QQuickView *configView(); QQuickView *configView();
Latte::Data::View data() const;
ViewPart::Effects *effects() const; ViewPart::Effects *effects() const;
ViewPart::ContextMenu *contextMenu() const; ViewPart::ContextMenu *contextMenu() const;
ViewPart::ContainmentInterface *extendedInterface() const; ViewPart::ContainmentInterface *extendedInterface() const;