layouts::storage support importToCorona()

pull/19/head
Michail Vourlakos 5 years ago
parent 2fd9d6cbfd
commit 9a1346d04a

@ -1688,7 +1688,7 @@ void GenericLayout::copyView(Plasma::Containment *containment)
void GenericLayout::importToCorona()
{
m_storage->importToCorona();
Layouts::Storage::self()->importToCorona(this);
}
bool GenericLayout::layoutIsBroken() const

@ -60,53 +60,6 @@ void Storage::setStorageTmpDir(const QString &tmpDir)
m_storageTmpDir = tmpDir;
}
void Storage::importToCorona()
{
if (!m_layout->corona()) {
return;
}
//! Setting mutable for create a containment
m_layout->corona()->setImmutability(Plasma::Types::Mutable);
QString temp1FilePath = m_storageTmpDir + "/" + m_layout->name() + ".multiple.views";
//! we need to copy first the layout file because the kde cache
//! may not have yet been updated (KSharedConfigPtr)
//! this way we make sure at the latest changes stored in the layout file
//! will be also available when changing to Multiple Layouts
QString tempLayoutFilePath = m_storageTmpDir + "/" + m_layout->name() + ".multiple.tmplayout";
//! WE NEED A WAY TO COPY A CONTAINMENT!!!!
QFile tempLayoutFile(tempLayoutFilePath);
QFile copyFile(temp1FilePath);
QFile layoutOriginalFile(m_layout->file());
if (tempLayoutFile.exists()) {
tempLayoutFile.remove();
}
if (copyFile.exists())
copyFile.remove();
layoutOriginalFile.copy(tempLayoutFilePath);
KSharedConfigPtr filePtr = KSharedConfig::openConfig(tempLayoutFilePath);
KSharedConfigPtr newFile = KSharedConfig::openConfig(temp1FilePath);
KConfigGroup copyGroup = KConfigGroup(newFile, "Containments");
KConfigGroup current_containments = KConfigGroup(filePtr, "Containments");
current_containments.copyTo(&copyGroup);
copyGroup.sync();
//! update ids to unique ones
QString temp2File = newUniqueIdsLayoutFromFile(temp1FilePath);
//! Finally import the configuration
importLayoutFile(temp2File);
}
void Storage::syncToLayoutFile(bool removeLayoutId)
{
if (!m_layout->corona() || !Layouts::Storage::self()->isWritable(m_layout)) {

@ -42,8 +42,6 @@ public:
bool layoutIsBroken(QStringList &errors) const;
void importToCorona();
void copyView(Plasma::Containment *containment);
void syncToLayoutFile(bool removeLayoutId);

@ -87,7 +87,7 @@ bool Storage::isLatteContainment(const KConfigGroup &group) const
return pluginId == "org.kde.latte.containment";
}
void Storage::lock(Layout::GenericLayout *layout) const
void Storage::lock(const Layout::GenericLayout *layout)
{
QFileInfo layoutFileInfo(layout->file());
@ -96,7 +96,7 @@ void Storage::lock(Layout::GenericLayout *layout) const
}
}
void Storage::unlock(Layout::GenericLayout *layout) const
void Storage::unlock(const Layout::GenericLayout *layout)
{
QFileInfo layoutFileInfo(layout->file());
@ -105,6 +105,55 @@ void Storage::unlock(Layout::GenericLayout *layout) const
}
}
void Storage::importToCorona(const Layout::GenericLayout *layout)
{
if (!layout->corona()) {
return;
}
//! Setting mutable for create a containment
layout->corona()->setImmutability(Plasma::Types::Mutable);
QString temp1FilePath = m_storageTmpDir.path() + "/" + layout->name() + ".multiple.views";
//! we need to copy first the layout file because the kde cache
//! may not have yet been updated (KSharedConfigPtr)
//! this way we make sure at the latest changes stored in the layout file
//! will be also available when changing to Multiple Layouts
QString tempLayoutFilePath = m_storageTmpDir.path() + "/" + layout->name() + ".multiple.tmplayout";
//! WE NEED A WAY TO COPY A CONTAINMENT!!!!
QFile tempLayoutFile(tempLayoutFilePath);
QFile copyFile(temp1FilePath);
QFile layoutOriginalFile(layout->file());
if (tempLayoutFile.exists()) {
tempLayoutFile.remove();
}
if (copyFile.exists())
copyFile.remove();
layoutOriginalFile.copy(tempLayoutFilePath);
KSharedConfigPtr filePtr = KSharedConfig::openConfig(tempLayoutFilePath);
KSharedConfigPtr newFile = KSharedConfig::openConfig(temp1FilePath);
KConfigGroup copyGroup = KConfigGroup(newFile, "Containments");
KConfigGroup current_containments = KConfigGroup(filePtr, "Containments");
current_containments.copyTo(&copyGroup);
copyGroup.sync();
//! update ids to unique ones
QString temp2File = newUniqueIdsLayoutFromFile(layout, temp1FilePath);
//! Finally import the configuration
importLayoutFile(layout, temp2File);
}
QString Storage::availableId(QStringList all, QStringList assigned, int base)
{
bool found = false;

@ -49,8 +49,10 @@ public:
bool isLatteContainment(Plasma::Containment *containment) const;
bool isLatteContainment(const KConfigGroup &group) const;
void lock(Layout::GenericLayout *layout) const; //! make it only read-only
void unlock(Layout::GenericLayout *layout) const; //! make it writable which it should be the default
void lock(const Layout::GenericLayout *layout); //! make it only read-only
void unlock(const Layout::GenericLayout *layout); //! make it writable which it should be the default
void importToCorona(const Layout::GenericLayout *layout);
/// STATIC
//! Check if an applet config group is valid or belongs to removed applet

Loading…
Cancel
Save