1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-23 01:33:50 +03:00

layout:add function to remove orphan subcontainment

This commit is contained in:
Michail Vourlakos 2021-05-02 09:08:30 +03:00
parent b9c2560a77
commit 837842f1f1
4 changed files with 49 additions and 8 deletions

View File

@ -1651,12 +1651,36 @@ void GenericLayout::removeView(const Latte::Data::View &viewData)
}
Plasma::Containment *viewcontainment = containmentForId(viewData.id.toUInt());
if (viewcontainment) {
m_containments.removeAll(viewcontainment);
viewcontainment->setImmutability(Plasma::Types::Mutable);
viewcontainment->destroy();
destroyContainment(viewcontainment);
}
void GenericLayout::removeOrphanedSubContainment(const int &containmentId)
{
Data::ViewsTable views = viewsTable();
QString cidstr = QString::number(containmentId);
if (views.hasContainmentId(cidstr)) {
return;
}
if (!isActive()) {
Layouts::Storage::self()->removeContainment(file(), cidstr);
return;
}
Plasma::Containment *orphanedcontainment = containmentForId(cidstr.toUInt());
destroyContainment(orphanedcontainment);
}
void GenericLayout::destroyContainment(Plasma::Containment *containment)
{
if (!containment) {
return;
}
m_containments.removeAll(containment);
containment->setImmutability(Plasma::Types::Mutable);
containment->destroy();
}
QString GenericLayout::storedView(const int &containmentId)

View File

@ -129,6 +129,7 @@ public:
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
void removeOrphanedSubContainment(const int &containmentId);
//! Available edges for specific view in that screen
virtual QList<Plasma::Types::Location> availableEdgesForView(QScreen *scr, Latte::View *forView) const;
@ -207,6 +208,8 @@ private:
QList<Latte::Data::View> sortedViewsData(const QList<Latte::Data::View> &viewsData);
void destroyContainment(Plasma::Containment *containment);
private:
bool m_blockAutomaticLatteViewCreation{false};

View File

@ -1582,15 +1582,27 @@ void Storage::removeView(const QString &filepath, const Data::View &viewData)
return;
}
removeContainment(filepath, viewData.id);
for (int i=0; i<viewData.subcontainments.rowCount(); ++i) {
removeContainment(filepath, viewData.subcontainments[i].id);
}
}
void Storage::removeContainment(const QString &filepath, const QString &containmentId)
{
if (containmentId.isEmpty()) {
return;
}
KSharedConfigPtr lFile = KSharedConfig::openConfig(filepath);
KConfigGroup containmentGroups = KConfigGroup(lFile, "Containments");
containmentGroups.group(viewData.id).deleteGroup();
for (int i=0; i<viewData.subcontainments.rowCount(); ++i) {
containmentGroups.group(viewData.subcontainments[i].id).deleteGroup();
if (!containmentGroups.group(containmentId).exists()) {
return;
}
containmentGroups.group(containmentId).deleteGroup();
containmentGroups.sync();
}

View File

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