1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-03-10 04:58:16 +03:00

provide a new Layouts::Storage singleton

--this class will be the replacement for layout::storage
and will be responsible for any containment actions for
all layouts either loaded or offloaded. Through this
refactor loading and checking CentralLayouts should become
lighter and also memory efficient
This commit is contained in:
Michail Vourlakos 2020-08-18 01:23:41 +03:00
parent 9ff834ccae
commit d97fe4c59c
6 changed files with 196 additions and 71 deletions

View File

@ -27,6 +27,7 @@
#include "../screenpool.h" #include "../screenpool.h"
#include "../layouts/importer.h" #include "../layouts/importer.h"
#include "../layouts/manager.h" #include "../layouts/manager.h"
#include "../layouts/storage.h"
#include "../layouts/synchronizer.h" #include "../layouts/synchronizer.h"
#include "../shortcuts/shortcutstracker.h" #include "../shortcuts/shortcutstracker.h"
#include "../view/view.h" #include "../view/view.h"
@ -797,8 +798,9 @@ void GenericLayout::addView(Plasma::Containment *containment, bool forceOnPrimar
qDebug() << "step 1..."; qDebug() << "step 1...";
if (!m_storage->isLatteContainment(containment)) if (!Layouts::Storage::self()->isLatteContainment(containment)) {
return; return;
}
qDebug() << "step 2..."; qDebug() << "step 2...";
@ -1164,7 +1166,7 @@ bool GenericLayout::explicitDockOccupyEdge(int screen, Plasma::Types::Location l
} }
for (const auto containment : m_containments) { for (const auto containment : m_containments) {
if (m_storage->isLatteContainment(containment)) { if (Layouts::Storage::self()->isLatteContainment(containment)) {
bool onPrimary = containment->config().readEntry("onPrimary", true); bool onPrimary = containment->config().readEntry("onPrimary", true);
int id = containment->lastScreen(); int id = containment->lastScreen();
Plasma::Types::Location contLocation = containment->location(); Plasma::Types::Location contLocation = containment->location();
@ -1185,7 +1187,7 @@ bool GenericLayout::primaryDockOccupyEdge(Plasma::Types::Location location) cons
} }
for (const auto containment : m_containments) { for (const auto containment : m_containments) {
if (m_storage->isLatteContainment(containment)) { if (Layouts::Storage::self()->isLatteContainment(containment)) {
bool onPrimary{false}; bool onPrimary{false};
if (m_latteViews.contains(containment)) { if (m_latteViews.contains(containment)) {
@ -1238,7 +1240,7 @@ Layout::ViewsMap GenericLayout::validViewsMap(Layout::ViewsMap *occupiedMap)
//! first step: primary docks must be placed in primary screen free edges //! first step: primary docks must be placed in primary screen free edges
for (const auto containment : m_containments) { for (const auto containment : m_containments) {
if (m_storage->isLatteContainment(containment)) { if (Layouts::Storage::self()->isLatteContainment(containment)) {
int screenId = 0; int screenId = 0;
//! valid screen id //! valid screen id
@ -1274,7 +1276,7 @@ Layout::ViewsMap GenericLayout::validViewsMap(Layout::ViewsMap *occupiedMap)
//! second step: explicit docks must be placed in their screens if the screen edge is free //! second step: explicit docks must be placed in their screens if the screen edge is free
for (const auto containment : m_containments) { for (const auto containment : m_containments) {
if (m_storage->isLatteContainment(containment)) { if (Layouts::Storage::self()->isLatteContainment(containment)) {
int screenId = 0; int screenId = 0;
//! valid screen id //! valid screen id
@ -1392,7 +1394,7 @@ QList<int> GenericLayout::containmentSystrays(Plasma::Containment *containment)
{ {
QList<int> trays; QList<int> trays;
if (m_storage->isLatteContainment(containment)) { if (Layouts::Storage::self()->isLatteContainment(containment)) {
auto applets = containment->config().group("Applets"); auto applets = containment->config().group("Applets");
for (const auto &applet : applets.groupList()) { for (const auto &applet : applets.groupList()) {
@ -1469,7 +1471,7 @@ QString GenericLayout::reportHtml(const ScreenPool *screenPool)
//! orphan systrays //! orphan systrays
for (const auto containment : m_containments) { for (const auto containment : m_containments) {
if (!m_storage->isLatteContainment(containment) && !assignedSystrays.contains(containment->id())) { if (!Layouts::Storage::self()->isLatteContainment(containment) && !assignedSystrays.contains(containment->id())) {
orphanSystrays << containment->id(); orphanSystrays << containment->id();
} }
} }
@ -1501,7 +1503,7 @@ QString GenericLayout::reportHtml(const ScreenPool *screenPool)
if (isActive()) { if (isActive()) {
//! collect viewData results //! collect viewData results
for (const auto containment : m_containments) { for (const auto containment : m_containments) {
if (m_storage->isLatteContainment(containment)) { if (Layouts::Storage::self()->isLatteContainment(containment)) {
ViewData vData; ViewData vData;
vData.id = containment->id(); vData.id = containment->id();
vData.active = latteViewExists(containment); vData.active = latteViewExists(containment);
@ -1628,7 +1630,7 @@ QList<int> GenericLayout::viewsScreens()
if (isActive()) { if (isActive()) {
for (const auto containment : m_containments) { for (const auto containment : m_containments) {
if (m_storage->isLatteContainment(containment)) { if (Layouts::Storage::self()->isLatteContainment(containment)) {
int screenId = -1; int screenId = -1;
//! valid screen id //! valid screen id
@ -1659,17 +1661,17 @@ QList<int> GenericLayout::viewsScreens()
bool GenericLayout::isWritable() const bool GenericLayout::isWritable() const
{ {
return m_storage->isWritable(); return Layouts::Storage::self()->isWritable(this);
} }
void GenericLayout::lock() void GenericLayout::lock()
{ {
m_storage->lock(); Layouts::Storage::self()->lock(this);
} }
void GenericLayout::unlock() void GenericLayout::unlock()
{ {
m_storage->unlock(); Layouts::Storage::self()->unlock(this);
} }
void GenericLayout::syncToLayoutFile(bool removeLayoutId) void GenericLayout::syncToLayoutFile(bool removeLayoutId)

View File

@ -25,7 +25,9 @@
#include "../screenpool.h" #include "../screenpool.h"
#include "../layouts/manager.h" #include "../layouts/manager.h"
#include "../layouts/importer.h" #include "../layouts/importer.h"
#include "../layouts/storage.h"
#include "../view/view.h" #include "../view/view.h"
// Qt // Qt
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
@ -53,54 +55,6 @@ Storage::~Storage()
{ {
} }
bool Storage::isWritable() const
{
QFileInfo layoutFileInfo(m_layout->file());
if (layoutFileInfo.exists() && !layoutFileInfo.isWritable()) {
return false;
} else {
return true;
}
}
bool Storage::isLatteContainment(Plasma::Containment *containment) const
{
if (!containment) {
return false;
}
if (containment->pluginMetaData().pluginId() == "org.kde.latte.containment") {
return true;
}
return false;
}
bool Storage::isLatteContainment(const KConfigGroup &group) const
{
QString pluginId = group.readEntry("plugin", "");
return pluginId == "org.kde.latte.containment";
}
void Storage::lock()
{
QFileInfo layoutFileInfo(m_layout->file());
if (layoutFileInfo.exists() && layoutFileInfo.isWritable()) {
QFile(m_layout->file()).setPermissions(QFileDevice::ReadUser | QFileDevice::ReadGroup | QFileDevice::ReadOther);
}
}
void Storage::unlock()
{
QFileInfo layoutFileInfo(m_layout->file());
if (layoutFileInfo.exists() && !layoutFileInfo.isWritable()) {
QFile(m_layout->file()).setPermissions(QFileDevice::ReadUser | QFileDevice::WriteUser | QFileDevice::ReadGroup | QFileDevice::ReadOther);
}
}
void Storage::setStorageTmpDir(const QString &tmpDir) void Storage::setStorageTmpDir(const QString &tmpDir)
{ {
m_storageTmpDir = tmpDir; m_storageTmpDir = tmpDir;
@ -155,7 +109,7 @@ void Storage::importToCorona()
void Storage::syncToLayoutFile(bool removeLayoutId) void Storage::syncToLayoutFile(bool removeLayoutId)
{ {
if (!m_layout->corona() || !isWritable()) { if (!m_layout->corona() || !Layouts::Storage::self()->isWritable(m_layout)) {
return; return;
} }
@ -341,7 +295,7 @@ QList<Plasma::Containment *> Storage::importLayoutFile(QString file)
//QList<Plasma::Containment *> systrays; //QList<Plasma::Containment *> systrays;
for (const auto containment : newContainments) { for (const auto containment : newContainments) {
if (isLatteContainment(containment)) { if (Layouts::Storage::self()->isLatteContainment(containment)) {
qDebug() << "new latte containment id: " << containment->id(); qDebug() << "new latte containment id: " << containment->id();
importedDocks << containment; importedDocks << containment;
} }
@ -361,7 +315,7 @@ void Storage::systraysInformation(QHash<int, QList<int>> &systrays, QList<int> &
//! assigned systrays //! assigned systrays
for (const auto &cId : containmentGroups.groupList()) { for (const auto &cId : containmentGroups.groupList()) {
if (isLatteContainment(containmentGroups.group(cId))) { if (Layouts::Storage::self()->isLatteContainment(containmentGroups.group(cId))) {
auto applets = containmentGroups.group(cId).group("Applets"); auto applets = containmentGroups.group(cId).group("Applets");
for (const auto &applet : applets.groupList()) { for (const auto &applet : applets.groupList()) {
@ -378,7 +332,7 @@ void Storage::systraysInformation(QHash<int, QList<int>> &systrays, QList<int> &
//! orphan systrays //! orphan systrays
for (const auto &cId : containmentGroups.groupList()) { for (const auto &cId : containmentGroups.groupList()) {
if (!isLatteContainment(containmentGroups.group(cId)) && !assignedSystrays.contains(cId.toInt())) { if (!Layouts::Storage::self()->isLatteContainment(containmentGroups.group(cId)) && !assignedSystrays.contains(cId.toInt())) {
orphanSystrays << cId.toInt(); orphanSystrays << cId.toInt();
} }
} }
@ -392,7 +346,7 @@ QList<ViewData> Storage::viewsData(const QHash<int, QList<int>> &systrays)
KConfigGroup containmentGroups = KConfigGroup(lFile, "Containments"); KConfigGroup containmentGroups = KConfigGroup(lFile, "Containments");
for (const auto &cId : containmentGroups.groupList()) { for (const auto &cId : containmentGroups.groupList()) {
if (isLatteContainment(containmentGroups.group(cId))) { if (Layouts::Storage::self()->isLatteContainment(containmentGroups.group(cId))) {
ViewData vData; ViewData vData;
int id = cId.toInt(); int id = cId.toInt();
@ -430,7 +384,7 @@ QList<int> Storage::viewsScreens()
KConfigGroup containmentGroups = KConfigGroup(lFile, "Containments"); KConfigGroup containmentGroups = KConfigGroup(lFile, "Containments");
for (const auto &cId : containmentGroups.groupList()) { for (const auto &cId : containmentGroups.groupList()) {
if (isLatteContainment(containmentGroups.group(cId))) { if (Layouts::Storage::self()->isLatteContainment(containmentGroups.group(cId))) {
int screenId = containmentGroups.group(cId).readEntry("lastScreen", -1); int screenId = containmentGroups.group(cId).readEntry("lastScreen", -1);
if (screenId != -1 && !screens.contains(screenId)) { if (screenId != -1 && !screens.contains(screenId)) {

View File

@ -40,14 +40,9 @@ public:
Storage(GenericLayout *parent); Storage(GenericLayout *parent);
~Storage() override; ~Storage() override;
bool isWritable() const;
bool isLatteContainment(Plasma::Containment *containment) const;
bool isLatteContainment(const KConfigGroup &group) const;
bool layoutIsBroken(QStringList &errors) const; bool layoutIsBroken(QStringList &errors) const;
void importToCorona(); void importToCorona();
void lock(); //! make it only read-only
void unlock(); //! make it writable which it should be the default
void copyView(Plasma::Containment *containment); void copyView(Plasma::Containment *containment);
void syncToLayoutFile(bool removeLayoutId); void syncToLayoutFile(bool removeLayoutId);

View File

@ -3,6 +3,7 @@ set(lattedock-app_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/importer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/importer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/launcherssignals.cpp ${CMAKE_CURRENT_SOURCE_DIR}/launcherssignals.cpp
${CMAKE_CURRENT_SOURCE_DIR}/manager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/manager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/storage.cpp
${CMAKE_CURRENT_SOURCE_DIR}/synchronizer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/synchronizer.cpp
PARENT_SCOPE PARENT_SCOPE
) )

107
app/layouts/storage.cpp Normal file
View File

@ -0,0 +1,107 @@
/*
* Copyright 2020 Michail Vourlakos <mvourlakos@gmail.com>
*
* This file is part of Latte-Dock
*
* Latte-Dock is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* Latte-Dock is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "storage.h"
// local
#include "../layout/storage.h"
// Qt
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFileInfo>
// KDE
#include <KConfigGroup>
#include <KSharedConfig>
// Plasma
#include <Plasma>
#include <Plasma/Applet>
#include <Plasma/Containment>
namespace Latte {
namespace Layouts {
Storage::Storage()
{
qDebug() << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> LAYOUTS::STORAGE, TEMP DIR ::: " << m_storageTmpDir.path();
}
Storage::~Storage()
{
}
Storage *Storage::self()
{
static Storage store;
return &store;
}
bool Storage::isWritable(const Layout::GenericLayout *layout) const
{
QFileInfo layoutFileInfo(layout->file());
if (layoutFileInfo.exists() && !layoutFileInfo.isWritable()) {
return false;
} else {
return true;
}
}
bool Storage::isLatteContainment(Plasma::Containment *containment) const
{
if (!containment) {
return false;
}
if (containment->pluginMetaData().pluginId() == "org.kde.latte.containment") {
return true;
}
return false;
}
bool Storage::isLatteContainment(const KConfigGroup &group) const
{
QString pluginId = group.readEntry("plugin", "");
return pluginId == "org.kde.latte.containment";
}
void Storage::lock(Layout::GenericLayout *layout) const
{
QFileInfo layoutFileInfo(layout->file());
if (layoutFileInfo.exists() && layoutFileInfo.isWritable()) {
QFile(layout->file()).setPermissions(QFileDevice::ReadUser | QFileDevice::ReadGroup | QFileDevice::ReadOther);
}
}
void Storage::unlock(Layout::GenericLayout *layout) const
{
QFileInfo layoutFileInfo(layout->file());
if (layoutFileInfo.exists() && !layoutFileInfo.isWritable()) {
QFile(layout->file()).setPermissions(QFileDevice::ReadUser | QFileDevice::WriteUser | QFileDevice::ReadGroup | QFileDevice::ReadOther);
}
}
}
}

66
app/layouts/storage.h Normal file
View File

@ -0,0 +1,66 @@
/*
* Copyright 2020 Michail Vourlakos <mvourlakos@gmail.com>
*
* This file is part of Latte-Dock
*
* Latte-Dock is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* Latte-Dock is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LAYOUTSSTORAGE_H
#define LAYOUTSSTORAGE_H
// Qt
#include <QTemporaryDir>
// KDE
#include <KConfigGroup>
// Plasma
#include <Plasma/Containment>
namespace Latte {
namespace Layout {
class GenericLayout;
}
}
namespace Latte {
namespace Layouts {
class Storage
{
public:
static Storage *self();
~Storage();
bool isWritable(const Layout::GenericLayout *layout) const;
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
private:
Storage();
private:
QTemporaryDir m_storageTmpDir;
};
}
}
#endif