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

storage:provide update view containment

This commit is contained in:
Michail Vourlakos 2021-04-13 00:54:42 +03:00
parent d420a75b8a
commit 32566ea6ae
4 changed files with 63 additions and 1 deletions

View File

@ -382,6 +382,17 @@ Latte::View *GenericLayout::viewForContainment(uint id) const
return nullptr;
}
Plasma::Containment *GenericLayout::containmentForId(uint id) const
{
for(auto containment : m_containments) {
if (containment->id() == id) {
return containment;
}
}
return nullptr;
}
Latte::View *GenericLayout::viewForContainment(Plasma::Containment *containment) const
{
if (m_containments.contains(containment) && m_latteViews.contains(containment)) {

View File

@ -92,6 +92,7 @@ public:
Latte::View *highestPriorityView();
Latte::View *viewForContainment(uint id) const;
Latte::View *viewForContainment(Plasma::Containment *containment) const;
Plasma::Containment *containmentForId(uint id) const;
static bool viewAtLowerScreenPriority(Latte::View *test, Latte::View *base);
static bool viewAtLowerEdgePriority(Latte::View *test, Latte::View *base);

View File

@ -1081,7 +1081,7 @@ Data::AppletsTable Storage::plugins(const Layout::GenericLayout *layout, const i
//! searching for specific containment and subcontainments and ignore all other containments
for(auto containment : *layout->containments()) {
if (containment->id() != containmentid) {
if (((int)containment->id()) != containmentid) {
//! ignore irrelevant containments
continue;
}
@ -1284,6 +1284,53 @@ Data::View Storage::view(const KConfigGroup &containmentGroup)
return vdata;
}
void Storage::updateView(KConfigGroup viewGroup, const Data::View &viewData)
{
if (!Layouts::Storage::self()->isLatteContainment(viewGroup)) {
return;
}
viewGroup.writeEntry("name", viewData.name);
viewGroup.writeEntry("onPrimary", viewData.onPrimary);
viewGroup.writeEntry("lastScreen", viewData.screen);
viewGroup.group("General").writeEntry("screenEdgeMargin", viewData.screenEdgeMargin);
viewGroup.writeEntry("location", (int)viewData.edge);
viewGroup.writeEntry("maxLength", viewData.maxLength);
viewGroup.group("General").writeEntry("alignment", (int)viewData.alignment);
viewGroup.sync();
}
void Storage::updateView(const Layout::GenericLayout *layout, const Data::View &viewData)
{
if (!layout) {
return;
}
auto view = layout->viewForContainment(viewData.id.toUInt());
if (view) {
qDebug() << "Storage::updateView should not be called because view is active and present...";
return;
}
if (layout->isActive()) {
//! active view but is not present in active screens;
auto containment = layout->containmentForId(viewData.id.toUInt());
if (containment) {
updateView(containment->config(), viewData);
}
} else {
//! inactive view and in layout storage
KSharedConfigPtr lFile = KSharedConfig::openConfig(layout->file());
KConfigGroup containmentGroups = KConfigGroup(lFile, "Containments");
KConfigGroup viewContainment = containmentGroups.group(viewData.id);
if (viewContainment.exists() && Layouts::Storage::self()->isLatteContainment(viewContainment)) {
updateView(viewContainment, viewData);
}
}
}
Data::ViewsTable Storage::views(const Layout::GenericLayout *layout)
{
Data::ViewsTable vtable;

View File

@ -86,6 +86,9 @@ public:
ViewDelayedCreationData copyView(const Layout::GenericLayout *layout, Plasma::Containment *containment);
ViewDelayedCreationData newView(const Layout::GenericLayout *destination, const QString &templateFile);
void updateView(const Layout::GenericLayout *layout, const Data::View &viewData);
void updateView(KConfigGroup viewGroup, const Data::View &viewData);
bool exportTemplate(const QString &originFile, const QString &destinationFile, const Data::AppletsTable &approvedApplets);
bool exportTemplate(const Layout::GenericLayout *layout, Plasma::Containment *containment, const QString &destinationFile, const Data::AppletsTable &approvedApplets);