1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-23 01:33:50 +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};
Plasma::Types::Location edge{Plasma::Types::BottomEdge};
Latte::Types::Alignment alignment{Latte::Types::Center};
GenericTable<Data::Generic> subcontainments;
bool isValid() const;

View File

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

View File

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

View File

@ -69,7 +69,7 @@ public:
static const int IDBASE;
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 isBroken(const Layout::GenericLayout *layout, QStringList &errors) 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 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>
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 Layout::GenericLayout *layout);
private:
Storage();
@ -125,9 +127,6 @@ private:
//! imports a layout file and returns the containments for the docks
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:
QTemporaryDir m_storageTmpDir;

View File

@ -1273,6 +1273,27 @@ bool View::mimeContainsPlasmoid(QMimeData *mimeData, QString name)
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
{
return m_colorizer;

View File

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