provide Storage/Layout::storedView function

--it is going to be used in order for
Duplicate/Cut/Copy functionality to be supported
properly. Its main purpose is to accept a
layout and a containment_id and based on
that to provide a stored view temp file
which is going to be used as a template
for any future addition.
work/spdx
Michail Vourlakos 4 years ago
parent 2c8d7134bd
commit 9d113ba754

@ -1457,6 +1457,33 @@ void GenericLayout::syncLatteViewsToScreens(Layout::ViewsMap *occupiedMap)
qDebug() << "end of, syncLatteViewsToScreens ....";
}
QList<Plasma::Containment *> GenericLayout::subContainmentsOf(uint id) const
{
QList<Plasma::Containment *> subs;
auto containment = containmentForId(id);
if (!containment || !Layouts::Storage::self()->isLatteContainment(containment)) {
return subs;
}
auto applets = containment->config().group("Applets");
for (const auto &applet : applets.groupList()) {
int tSubId = Layouts::Storage::self()->subContainmentId(applets.group(applet));
if (Layouts::Storage::isValid(tSubId)) {
auto subcontainment = containmentForId(tSubId);
if (subcontainment) {
subs << subcontainment;
}
}
}
return subs;
}
QList<int> GenericLayout::subContainmentsOf(Plasma::Containment *containment) const
{
QList<int> subs;
@ -1670,6 +1697,11 @@ void GenericLayout::removeView(const Latte::Data::View &viewData)
}
}
QString GenericLayout::storedView(const int &containmentId)
{
return Layouts::Storage::self()->storedView(this, containmentId);
}
void GenericLayout::importToCorona()
{
Layouts::Storage::self()->importToCorona(this);

@ -97,6 +97,7 @@ public:
Latte::View *viewForContainment(uint id) const;
Latte::View *viewForContainment(Plasma::Containment *containment) const;
Plasma::Containment *containmentForId(uint id) const;
QList<Plasma::Containment *> subContainmentsOf(uint id) const;
static bool viewAtLowerScreenPriority(Latte::View *test, Latte::View *base);
static bool viewAtLowerEdgePriority(Latte::View *test, Latte::View *base);
@ -128,6 +129,7 @@ public:
Data::View newView(const Latte::Data::View &nextViewData);
void removeView(const Latte::Data::View &viewData);
void updateView(const Latte::Data::View &viewData);
QString storedView(const int &containmentId); //returns temp filepath containing all view data
//! Available edges for specific view in that screen
virtual QList<Plasma::Types::Location> availableEdgesForView(QScreen *scr, Latte::View *forView) const;

@ -668,35 +668,6 @@ Data::View Storage::newView(const Layout::GenericLayout *destinationLayout, cons
}
return updatedNextViews[0];
/*
auto config = newContainment->config();
int primaryScrId = destination->corona()->screenPool()->primaryScreenId();
QList<Plasma::Types::Location> edges = destination->freeEdges(primaryScrId);
qDebug() << "org.kde.latte current template edge : " << newContainment->location() << " free edges :: " << edges;
//! if selected template screen edge is not free
if (!edges.contains(newContainment->location())) {
if (edges.count() > 0) {
newContainment->setLocation(edges.at(0));
} else {
newContainment->setLocation(Plasma::Types::BottomEdge);
}
}
config.writeEntry("onPrimary", true);
config.writeEntry("lastScreen", primaryScrId);
newContainment->config().sync();
ViewDelayedCreationData result;
result.containment = newContainment;
result.forceOnPrimary = false;
result.explicitScreen = primaryScrId;
result.reactToScreenChange = false;
return result;*/
}
void Storage::clearExportedLayoutSettings(KConfigGroup &layoutSettingsGroup)
@ -1458,6 +1429,76 @@ void Storage::removeView(const QString &filepath, const Data::View &viewData)
containmentGroups.sync();
}
QString Storage::storedView(const Layout::GenericLayout *layout, const int &containmentId)
{
//! make sure that layout and containmentId are valid
if (!layout) {
return QString();
}
if (layout->isActive()) {
auto containment = layout->containmentForId((uint)containmentId);
if (!containment || !isLatteContainment(containment)) {
return QString();
}
} else {
if (!containsView(layout->file(), containmentId)) {
return QString();
}
}
//! at this point we are sure that both layout and containmentId are acceptable
QString nextTmpStoredViewAbsolutePath = m_storageTmpDir.path() + "/" + QFileInfo(layout->name()).fileName() + "." + QString::number(containmentId) + ".stored.tmp";
KSharedConfigPtr destinationPtr = KSharedConfig::openConfig(nextTmpStoredViewAbsolutePath);
KConfigGroup destinationContainments = KConfigGroup(destinationPtr, "Containments");
if (layout->isActive()) {
//! update and copy containments
auto containment = layout->containmentForId((uint)containmentId);
containment->config().sync();
KConfigGroup destinationViewContainment(&destinationContainments, QString::number(containment->id()));
containment->config().copyTo(&destinationViewContainment);
QList<Plasma::Containment *> subconts = layout->subContainmentsOf(containment->id());
for(const auto subcont : subconts) {
subcont->config().sync();
KConfigGroup destinationsubcontainment(&destinationContainments, QString::number(subcont->id()));
subcont->config().copyTo(&destinationsubcontainment);
}
//! update with latest view data if active view is present
auto view = layout->viewForContainment(containment);
if (view) {
Data::View currentviewdata = view->data();
updateView(destinationViewContainment, currentviewdata);
}
} else {
QString containmentid = QString::number(containmentId);
KConfigGroup destinationViewContainment(&destinationContainments, containmentid);
KSharedConfigPtr originPtr = KSharedConfig::openConfig(layout->file());
KConfigGroup originContainments = KConfigGroup(originPtr, "Containments");
originContainments.group(containmentid).copyTo(&destinationViewContainment);
Data::GenericTable<Data::Generic> subconts = subcontainments(originContainments.group(containmentid));
for(int i=0; i<subconts.rowCount(); ++i) {
QString subid = subconts[i].id;
KConfigGroup destinationsubcontainment(&destinationContainments, subid);
originContainments.group(subid).copyTo(&destinationsubcontainment);
}
}
destinationContainments.sync();
return nextTmpStoredViewAbsolutePath;
}
Data::ViewsTable Storage::views(const Layout::GenericLayout *layout)
{
Data::ViewsTable vtable;

@ -91,6 +91,7 @@ public:
void updateView(const Layout::GenericLayout *layout, const Data::View &viewData);
void updateView(KConfigGroup viewGroup, const Data::View &viewData);
void removeView(const QString &filepath, const Data::View &viewData);
QString storedView(const Layout::GenericLayout *layout, const int &containmentId); //returns temp filepath containing all view data
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);

Loading…
Cancel
Save