1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-10 21:18:19 +03:00

Storage::simplify a bit newUniqueIdsFile function

This commit is contained in:
Michail Vourlakos 2021-04-17 13:11:35 +03:00
parent 54e9fcdcec
commit dc56e61e64
2 changed files with 53 additions and 7 deletions

View File

@ -295,13 +295,50 @@ bool Storage::appletGroupIsValid(const KConfigGroup &appletGroup)
&& appletGroup.group("Configuration").hasKey("PreloadWeight") );
}
QString Storage::newUniqueIdsFile(QString originFile, const Layout::GenericLayout *destinationLayout, QString destinationFile)
QStringList Storage::containmentsIds(const QString &filepath)
{
if (destinationFile.isEmpty() && (!destinationLayout || !destinationLayout->corona())) {
QStringList ids;
KSharedConfigPtr filePtr = KSharedConfig::openConfig(filepath);
KConfigGroup containments = KConfigGroup(filePtr, "Containments");
for(const auto &cId : containments.groupList()) {
ids << cId;
}
return ids;
}
QStringList Storage::appletsIds(const QString &filepath)
{
QStringList ids;
KSharedConfigPtr filePtr = KSharedConfig::openConfig(filepath);
KConfigGroup containments = KConfigGroup(filePtr, "Containments");
for(const auto &cId : containments.groupList()) {
for(const auto &aId : containments.group(cId).group("Applets").groupList()) {
ids << aId;
}
}
return ids;
}
QString Storage::newUniqueIdsFile(QString originFile, const Layout::GenericLayout *destinationLayout)
{
if (!destinationLayout) {
return QString();
}
QString tempFile = m_storageTmpDir.path() + "/" + destinationLayout->name() + ".views.newids";
QString currentdestinationname = destinationLayout->name();
QString currentdestinationfile = "";
if (!destinationLayout->isActive()) {
currentdestinationfile = destinationLayout->file();
}
QString tempFile = m_storageTmpDir.path() + "/" + currentdestinationname + ".views.newids";
QFile copyFile(tempFile);
@ -311,8 +348,14 @@ QString Storage::newUniqueIdsFile(QString originFile, const Layout::GenericLayou
//! BEGIN updating the ids in the temp file
QStringList allIds;
allIds << destinationLayout->corona()->containmentsIds();
allIds << destinationLayout->corona()->appletsIds();
if (destinationLayout->isActive()) {
allIds << destinationLayout->corona()->containmentsIds();
allIds << destinationLayout->corona()->appletsIds();
} else {
allIds << containmentsIds(currentdestinationfile);
allIds << appletsIds(currentdestinationfile);
}
QStringList toInvestigateContainmentIds;
QStringList toInvestigateAppletIds;
@ -437,7 +480,7 @@ QString Storage::newUniqueIdsFile(QString originFile, const Layout::GenericLayou
}
}
if (destinationFile.isEmpty() && destinationLayout->corona()->layoutsManager()->memoryUsage() == MemoryUsage::MultipleLayouts) {
if (destinationLayout->isActive() && destinationLayout->corona()->layoutsManager()->memoryUsage() == MemoryUsage::MultipleLayouts) {
//! will be added in main corona multiple layouts file
investigate_conts.group(cId).writeEntry("layoutId", destinationLayout->name());
} else {

View File

@ -129,10 +129,13 @@ private:
//! provides a new file path based the provided file. The new file
//! has updated ids for containments and applets based on the corona
//! loaded ones
QString newUniqueIdsFile(QString originFile, const Layout::GenericLayout *destinationLayout = nullptr, QString destinationFile = QString());
QString newUniqueIdsFile(QString originFile, const Layout::GenericLayout *destinationLayout);
//! imports a layout file and returns the containments for the docks
QList<Plasma::Containment *> importLayoutFile(const Layout::GenericLayout *layout, QString file);
QStringList containmentsIds(const QString &filepath);
QStringList appletsIds(const QString &filepath);
private:
QTemporaryDir m_storageTmpDir;