mirror of
https://github.com/KDE/latte-dock.git
synced 2025-03-27 14:50:21 +03:00
NO/ASSIGN active Shares to active Centrals
This commit is contained in:
parent
971d207d86
commit
e7568c8478
@ -60,7 +60,7 @@ void CentralLayout::unloadContainments()
|
||||
Layout::GenericLayout::unloadContainments();
|
||||
|
||||
if (m_sharedLayout) {
|
||||
disconnect(m_sharedLayout, &Layout::GenericLayout::viewsCountChanged, this, &Layout::GenericLayout::viewsCountChanged);
|
||||
disconnectSharedConnections();
|
||||
m_sharedLayout->removeCentralLayout(this);
|
||||
}
|
||||
}
|
||||
@ -207,26 +207,44 @@ void CentralLayout::setSharedLayoutName(QString name)
|
||||
emit sharedLayoutNameChanged();
|
||||
}
|
||||
|
||||
SharedLayout *CentralLayout::sharedLayout() const
|
||||
{
|
||||
return m_sharedLayout;
|
||||
}
|
||||
|
||||
void CentralLayout::setSharedLayout(SharedLayout *layout)
|
||||
{
|
||||
if (m_sharedLayout == layout) {
|
||||
return;
|
||||
}
|
||||
|
||||
disconnectSharedConnections();
|
||||
|
||||
m_sharedLayout = layout;
|
||||
|
||||
if (layout) {
|
||||
setSharedLayoutName(m_sharedLayout->name());
|
||||
|
||||
//! attach new signals
|
||||
m_sharedConnections << connect(m_sharedLayout, &Layout::GenericLayout::viewsCountChanged, this, &Layout::GenericLayout::viewsCountChanged);
|
||||
m_sharedConnections << connect(m_sharedLayout, &Layout::AbstractLayout::nameChanged, this, [this]() {
|
||||
setSharedLayoutName(m_sharedLayout->name());
|
||||
});
|
||||
} else {
|
||||
setSharedLayoutName(QString());
|
||||
}
|
||||
|
||||
emit viewsCountChanged();
|
||||
}
|
||||
|
||||
void CentralLayout::disconnectSharedConnections()
|
||||
{
|
||||
//! drop old signals
|
||||
for (const auto &sc : m_sharedConnections) {
|
||||
QObject::disconnect(sc);
|
||||
}
|
||||
|
||||
m_sharedConnections.clear();
|
||||
|
||||
m_sharedLayout = layout;
|
||||
|
||||
//! attach new signals
|
||||
m_sharedConnections << connect(m_sharedLayout, &Layout::GenericLayout::viewsCountChanged, this, &Layout::GenericLayout::viewsCountChanged);
|
||||
m_sharedConnections << connect(m_sharedLayout, &Layout::AbstractLayout::nameChanged, this, [this]() {
|
||||
setSharedLayoutName(m_sharedLayout->name());
|
||||
});
|
||||
|
||||
emit viewsCountChanged();
|
||||
}
|
||||
|
||||
void CentralLayout::loadConfig()
|
||||
|
@ -67,6 +67,9 @@ public:
|
||||
QStringList activities() const;
|
||||
void setActivities(QStringList activities);
|
||||
|
||||
SharedLayout *sharedLayout() const;
|
||||
void setSharedLayout(SharedLayout *layout);
|
||||
|
||||
//! OVERRIDE GeneralLayout implementations
|
||||
void addView(Plasma::Containment *containment, bool forceOnPrimary = false, int explicitScreen = -1, Layout::ViewsMap *occupied = nullptr);
|
||||
void syncLatteViewsToScreens(Layout::ViewsMap *occupiedMap = nullptr) override;
|
||||
@ -96,11 +99,11 @@ signals:
|
||||
void sharedLayoutNameChanged();
|
||||
|
||||
private slots:
|
||||
void disconnectSharedConnections();
|
||||
|
||||
void loadConfig();
|
||||
void saveConfig();
|
||||
|
||||
void setSharedLayout(SharedLayout *layout);
|
||||
|
||||
private:
|
||||
void init();
|
||||
void importLocalLayout(QString file);
|
||||
|
@ -111,6 +111,7 @@ void SharedLayout::addCentralLayout(CentralLayout *layout)
|
||||
if (layout != nullptr && !m_centralLayouts.contains(layout)) {
|
||||
m_centralLayouts.append(layout);
|
||||
|
||||
qDebug() << " ADDING Central : " << layout->name() << " at Shared: " << name();
|
||||
connect(layout, &GenericLayout::activitiesChanged, this, &GenericLayout::activitiesChanged);
|
||||
emit activitiesChanged();
|
||||
emit viewsCountChanged();
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "../lattecorona.h"
|
||||
#include "../layout/genericlayout.h"
|
||||
#include "../layout/centrallayout.h"
|
||||
#include "../layout/sharedlayout.h"
|
||||
#include "../liblatte2/types.h"
|
||||
#include "../plasma/extended/theme.h"
|
||||
#include "delegates/activitiesdelegate.h"
|
||||
@ -1632,8 +1633,15 @@ bool SettingsDialog::saveAllChanges()
|
||||
}
|
||||
}
|
||||
|
||||
//! update SharedLayouts that are Active
|
||||
if (m_corona->layoutManager()->memoryUsage() == Types::MultipleLayouts) {
|
||||
updateActiveShares();
|
||||
}
|
||||
|
||||
//! reload layouts in layoutmanager
|
||||
m_corona->layoutManager()->loadLayouts();
|
||||
|
||||
//! send to layout manager in which layout to switch
|
||||
Latte::Types::LayoutsMemoryUsage inMemoryOption = static_cast<Latte::Types::LayoutsMemoryUsage>(m_inMemoryButtons->checkedId());
|
||||
|
||||
if (m_corona->layoutManager()->memoryUsage() != inMemoryOption) {
|
||||
@ -1655,6 +1663,70 @@ bool SettingsDialog::saveAllChanges()
|
||||
return true;
|
||||
}
|
||||
|
||||
void SettingsDialog::updateActiveShares()
|
||||
{
|
||||
QHash<const QString, QStringList> currentSharesMap;
|
||||
|
||||
for (int i = 0; i < m_model->rowCount(); ++i) {
|
||||
if (isShared(i)) {
|
||||
QString id = m_model->data(m_model->index(i, IDCOLUMN), Qt::DisplayRole).toString();
|
||||
QStringList shares = m_model->data(m_model->index(i, SHAREDCOLUMN), Qt::UserRole).toStringList();
|
||||
currentSharesMap[id] = shares;
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << " CURRENT SHARES MAP :: " << currentSharesMap;
|
||||
|
||||
QHash<CentralLayout *, SharedLayout *> unassign;
|
||||
|
||||
for (QHash<const QString, QStringList>::iterator i=currentSharesMap.begin(); i!=currentSharesMap.end(); ++i) {
|
||||
SharedLayout *shared = m_corona->layoutManager()->sharedLayout(nameForId(i.key()));
|
||||
if (shared) {
|
||||
qDebug() << " SHARED :: " << shared->name();
|
||||
for (const auto ¢ralId : i.value()) {
|
||||
CentralLayout *central = m_corona->layoutManager()->centralLayout(nameForId(centralId));
|
||||
qDebug() << " CENTRAL NAME :: " << nameForId(centralId);
|
||||
if (central) {
|
||||
//! Assign this Central Layout at a different Shared Layout
|
||||
SharedLayout *oldShared = central->sharedLayout();
|
||||
if (shared != oldShared) {
|
||||
shared->addCentralLayout(central);
|
||||
central->setSharedLayout(shared);
|
||||
if (oldShared) {
|
||||
//! CENTRAL layout that changed from one ACTIVESHARED layout to another
|
||||
unassign[central] = shared;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! CENTRAL Layouts that wont have any SHARED Layout any more
|
||||
for (QHash<const QString, QStringList>::iterator i=m_sharesMap.begin(); i!=m_sharesMap.end(); ++i) {
|
||||
for (const auto ¢ralId : i.value()) {
|
||||
if (!mapHasRecord(centralId, currentSharesMap)) {
|
||||
CentralLayout *central = m_corona->layoutManager()->centralLayout(nameForId(centralId));
|
||||
if (central && central->sharedLayout()) {
|
||||
central->sharedLayout()->removeCentralLayout(central);
|
||||
central->setSharedLayout(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! Unassing from Shared Layouts Central ones that are not assigned any more
|
||||
//! IMPORTANT: This must be done after all the ASSIGNMENTS in order to avoid
|
||||
//! to unload a SharedLayout that it should not
|
||||
for (QHash<CentralLayout *, SharedLayout *>::iterator i=unassign.begin(); i!=unassign.end(); ++i) {
|
||||
i.value()->removeCentralLayout(i.key());
|
||||
}
|
||||
|
||||
//! TODO : (active) SharedLayouts that become Active should be unloaded first
|
||||
m_sharesMap.clear();
|
||||
m_sharesMap = currentSharesMap;
|
||||
}
|
||||
|
||||
bool SettingsDialog::idExistsInModel(QString id)
|
||||
{
|
||||
for (int i = 0; i < m_model->rowCount(); ++i) {
|
||||
@ -1668,6 +1740,17 @@ bool SettingsDialog::idExistsInModel(QString id)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SettingsDialog::mapHasRecord(const QString &record, QHash<const QString, QStringList> &map)
|
||||
{
|
||||
for (QHash<const QString, QStringList>::iterator i=map.begin(); i!=map.end(); ++i) {
|
||||
if (i.value().contains(record)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SettingsDialog::nameExistsInModel(QString name)
|
||||
{
|
||||
for (int i = 0; i < m_model->rowCount(); ++i) {
|
||||
|
@ -103,10 +103,12 @@ private:
|
||||
QStringList activities, bool locked = false);
|
||||
void updateApplyButtonsState();
|
||||
void updateSharedLayoutsStates();
|
||||
void updateActiveShares();
|
||||
|
||||
bool dataAreAccepted();
|
||||
bool idExistsInModel(QString id);
|
||||
bool importLayoutsFromV1ConfigFile(QString file);
|
||||
bool mapHasRecord(const QString &record, QHash<const QString, QStringList> &map);
|
||||
bool nameExistsInModel(QString name);
|
||||
bool saveAllChanges();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user