drop currentLayoutName as signal from synchronizer

pull/20/head
Michail Vourlakos 4 years ago
parent a9774ff13f
commit 7393ac02eb

@ -1082,7 +1082,7 @@ void Corona::addViewForLayout(QString layoutName)
void Corona::loadDefaultLayout() void Corona::loadDefaultLayout()
{ {
addViewForLayout(m_layoutsManager->currentLayoutName()); // addViewForLayout(m_layoutsManager->currentLayoutsNames());
} }
QStringList Corona::containmentsIds() QStringList Corona::containmentsIds()
@ -1203,7 +1203,7 @@ QStringList Corona::contextMenuData()
} }
data << QString::number((int)m_layoutsManager->memoryUsage()); data << QString::number((int)m_layoutsManager->memoryUsage());
data << m_layoutsManager->currentLayoutName(); data << m_layoutsManager->synchronizer()->currentLayoutsNames().join(";;");
data << QString::number((int)viewType); data << QString::number((int)viewType);
for(const auto &layoutName : m_layoutsManager->menuLayouts()) { for(const auto &layoutName : m_layoutsManager->menuLayouts()) {

@ -172,7 +172,7 @@ bool GenericLayout::isCurrent()
return false; return false;
} }
return name() == m_corona->layoutsManager()->currentLayoutName(); return m_corona->layoutsManager()->currentLayoutsNames().contains(name());
} }
QString GenericLayout::background() const QString GenericLayout::background() const

@ -56,10 +56,8 @@ Manager::Manager(QObject *parent)
m_synchronizer = new Synchronizer(this); m_synchronizer = new Synchronizer(this);
if (m_corona) { if (m_corona) {
connect(m_corona->universalSettings(), &UniversalSettings::currentLayoutNameChanged, this, &Manager::currentLayoutNameChanged);
connect(m_synchronizer, &Synchronizer::centralLayoutsChanged, this, &Manager::centralLayoutsChanged); connect(m_synchronizer, &Synchronizer::centralLayoutsChanged, this, &Manager::centralLayoutsChanged);
connect(m_synchronizer, &Synchronizer::currentLayoutNameChanged, this, &Manager::currentLayoutNameChanged);
connect(m_synchronizer, &Synchronizer::currentLayoutIsSwitching, this, &Manager::currentLayoutIsSwitching); connect(m_synchronizer, &Synchronizer::currentLayoutIsSwitching, this, &Manager::currentLayoutIsSwitching);
connect(m_synchronizer, &Synchronizer::layoutsChanged, this, &Manager::layoutsChanged); connect(m_synchronizer, &Synchronizer::layoutsChanged, this, &Manager::layoutsChanged);
connect(m_synchronizer, &Synchronizer::menuLayoutsChanged, this, &Manager::menuLayoutsChanged); connect(m_synchronizer, &Synchronizer::menuLayoutsChanged, this, &Manager::menuLayoutsChanged);
@ -143,11 +141,6 @@ Synchronizer *Manager::synchronizer() const
return m_synchronizer; return m_synchronizer;
} }
QString Manager::currentLayoutName() const
{
return m_synchronizer->currentLayoutName();
}
QStringList Manager::layouts() const QStringList Manager::layouts() const
{ {
return m_synchronizer->layouts(); return m_synchronizer->layouts();
@ -178,6 +171,11 @@ QStringList Manager::centralLayoutsNames()
return m_synchronizer->centralLayoutsNames(); return m_synchronizer->centralLayoutsNames();
} }
QStringList Manager::currentLayoutsNames() const
{
return m_synchronizer->currentLayoutsNames();
}
QList<CentralLayout *> Manager::currentLayouts() const QList<CentralLayout *> Manager::currentLayouts() const
{ {
return m_synchronizer->currentLayouts(); return m_synchronizer->currentLayouts();

@ -70,8 +70,6 @@ class Manager : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString currentLayoutName READ currentLayoutName NOTIFY currentLayoutNameChanged)
Q_PROPERTY(QStringList layouts READ layouts NOTIFY layoutsChanged) Q_PROPERTY(QStringList layouts READ layouts NOTIFY layoutsChanged)
Q_PROPERTY(QStringList menuLayouts READ menuLayouts NOTIFY menuLayoutsChanged) Q_PROPERTY(QStringList menuLayouts READ menuLayouts NOTIFY menuLayoutsChanged)
@ -89,10 +87,9 @@ public:
void showInfoWindow(QString info, int duration, QStringList activities = {"0"}); void showInfoWindow(QString info, int duration, QStringList activities = {"0"});
void unload(); void unload();
QString currentLayoutName() const;
QStringList layouts() const; QStringList layouts() const;
QStringList menuLayouts() const; QStringList menuLayouts() const;
QStringList currentLayoutsNames() const;
MemoryUsage::LayoutsMemory memoryUsage() const; MemoryUsage::LayoutsMemory memoryUsage() const;
void setMemoryUsage(MemoryUsage::LayoutsMemory memoryUsage); void setMemoryUsage(MemoryUsage::LayoutsMemory memoryUsage);
@ -116,7 +113,6 @@ public slots:
signals: signals:
void centralLayoutsChanged(); void centralLayoutsChanged();
void currentLayoutChanged(); void currentLayoutChanged();
void currentLayoutNameChanged();
void launchersSignalsChanged(); void launchersSignalsChanged();
void layoutsChanged(); void layoutsChanged();
void menuLayoutsChanged(); void menuLayoutsChanged();

@ -122,32 +122,6 @@ int Synchronizer::centralLayoutPos(QString id) const
return -1; return -1;
} }
QString Synchronizer::currentLayoutName() const
{
if (m_manager->memoryUsage() == MemoryUsage::SingleLayout) {
return m_manager->corona()->universalSettings()->currentLayoutName();
} else if (m_manager->memoryUsage() == MemoryUsage::MultipleLayouts) {
return currentLayoutNameInMultiEnvironment();
}
return QString();
}
QString Synchronizer::currentLayoutNameInMultiEnvironment() const
{
return m_currentLayoutNameInMultiEnvironment;
}
void Synchronizer::setCurrentLayoutNameInMultiEnvironment(const QString &name)
{
if (m_currentLayoutNameInMultiEnvironment == name) {
return;
}
m_currentLayoutNameInMultiEnvironment = name;
emit currentLayoutNameChanged();
}
QString Synchronizer::layoutPath(QString layoutName) QString Synchronizer::layoutPath(QString layoutName)
{ {
QString path = Layouts::Importer::layoutUserFilePath(layoutName); QString path = Layouts::Importer::layoutUserFilePath(layoutName);
@ -209,6 +183,19 @@ QStringList Synchronizer::centralLayoutsNames()
return names; return names;
} }
QStringList Synchronizer::currentLayoutsNames() const
{
QList<CentralLayout *> currents = currentLayouts();
QStringList currentNames;
for (int i = 0; i < currents.size(); ++i) {
CentralLayout *layout = currents.at(i);
currentNames << layout->name();
}
return currentNames;
}
QStringList Synchronizer::layouts() const QStringList Synchronizer::layouts() const
{ {
return m_layouts; return m_layouts;
@ -218,15 +205,9 @@ QStringList Synchronizer::menuLayouts() const
{ {
QStringList fixedMenuLayouts = m_menuLayouts; QStringList fixedMenuLayouts = m_menuLayouts;
//! in case the current layout isnt checked to be shown in the menus for (const auto layout : m_centralLayouts) {
//! we must add it on top if (!fixedMenuLayouts.contains(layout->name())) {
if (!fixedMenuLayouts.contains(currentLayoutName()) && m_manager->memoryUsage() == MemoryUsage::SingleLayout) { fixedMenuLayouts.prepend(layout->name());
fixedMenuLayouts.prepend(currentLayoutName());
} else if (m_manager->memoryUsage() == MemoryUsage::MultipleLayouts) {
for (const auto layout : m_centralLayouts) {
if (!fixedMenuLayouts.contains(layout->name())) {
fixedMenuLayouts.prepend(layout->name());
}
} }
} }
@ -374,7 +355,6 @@ void Synchronizer::addLayout(CentralLayout *layout)
void Synchronizer::onCurrentActivityChanged(const QString &id) void Synchronizer::onCurrentActivityChanged(const QString &id)
{ {
if (m_manager->memoryUsage() == MemoryUsage::MultipleLayouts) { if (m_manager->memoryUsage() == MemoryUsage::MultipleLayouts) {
updateCurrentLayoutNameInMultiEnvironment();
updateKWinDisabledBorders(); updateKWinDisabledBorders();
} }
} }
@ -516,29 +496,14 @@ void Synchronizer::unloadLayouts()
m_multipleModeInitialized = false; m_multipleModeInitialized = false;
} }
void Synchronizer::updateCurrentLayoutNameInMultiEnvironment()
{
for (const auto layout : m_centralLayouts) {
if (layout->activities().contains(m_manager->corona()->activitiesConsumer()->currentActivity())) {
setCurrentLayoutNameInMultiEnvironment(layout->name());
return;
}
}
for (const auto layout : m_centralLayouts) {
if (layout->activities().isEmpty()) {
setCurrentLayoutNameInMultiEnvironment(layout->name());
return;
}
}
}
bool Synchronizer::switchToLayout(QString layoutName, int previousMemoryUsage) bool Synchronizer::switchToLayout(QString layoutName, int previousMemoryUsage)
{ {
if (m_centralLayouts.size() > 0 && currentLayoutName() == layoutName && previousMemoryUsage == -1) { if (m_centralLayouts.size() > 0 && previousMemoryUsage == -1) {
return false; return false;
} }
qDebug() << " >>>>> SWITCHING >> " << layoutName << " __ " << previousMemoryUsage;
//! First Check If that Layout is already present and in that case //! First Check If that Layout is already present and in that case
//! we can just switch to the proper Activity //! we can just switch to the proper Activity
if (m_manager->memoryUsage() == MemoryUsage::MultipleLayouts && previousMemoryUsage == -1) { if (m_manager->memoryUsage() == MemoryUsage::MultipleLayouts && previousMemoryUsage == -1) {
@ -554,6 +519,8 @@ bool Synchronizer::switchToLayout(QString layoutName, int previousMemoryUsage)
return true; return true;
} }
} }
} else if (m_manager->memoryUsage() == MemoryUsage::SingleLayout && m_centralLayouts.size()>0 && m_centralLayouts[0]->name() == layoutName) {
return false;
} }
//! When going from memory usage to different memory usage we first //! When going from memory usage to different memory usage we first
@ -569,7 +536,7 @@ bool Synchronizer::switchToLayout(QString layoutName, int previousMemoryUsage)
if ((m_manager->memoryUsage() == MemoryUsage::SingleLayout && !lPath.isEmpty()) || m_manager->memoryUsage() == MemoryUsage::MultipleLayouts) { if ((m_manager->memoryUsage() == MemoryUsage::SingleLayout && !lPath.isEmpty()) || m_manager->memoryUsage() == MemoryUsage::MultipleLayouts) {
if (m_manager->memoryUsage() == MemoryUsage::SingleLayout) { if (m_manager->memoryUsage() == MemoryUsage::SingleLayout) {
emit currentLayoutIsSwitching(currentLayoutName()); emit currentLayoutIsSwitching(m_centralLayouts[0]->name());
} else if (m_manager->memoryUsage() == MemoryUsage::MultipleLayouts && layoutName != Layout::MULTIPLELAYOUTSHIDDENNAME) { } else if (m_manager->memoryUsage() == MemoryUsage::MultipleLayouts && layoutName != Layout::MULTIPLELAYOUTSHIDDENNAME) {
//! do nothing //! do nothing
} }
@ -609,12 +576,9 @@ bool Synchronizer::switchToLayout(QString layoutName, int previousMemoryUsage)
if (m_manager->memoryUsage() == MemoryUsage::MultipleLayouts) { if (m_manager->memoryUsage() == MemoryUsage::MultipleLayouts) {
syncMultipleLayoutsToActivities(); syncMultipleLayoutsToActivities();
} } else {
//! single layout
m_manager->corona()->universalSettings()->setCurrentLayoutName(layoutName); m_manager->corona()->universalSettings()->setCurrentLayoutName(layoutName);
if (!isAssigned(layoutName)) {
m_manager->corona()->universalSettings()->setLastNonAssignedLayoutName(layoutName);
} }
}); });
} else { } else {
@ -722,8 +686,6 @@ void Synchronizer::syncMultipleLayoutsToActivities()
qSort(currents); qSort(currents);
qSort(layoutsToLoad); qSort(layoutsToLoad);
updateCurrentLayoutNameInMultiEnvironment();
if (currents != layoutsToLoad) { if (currents != layoutsToLoad) {
emit centralLayoutsChanged(); emit centralLayoutsChanged();
} }

@ -84,12 +84,8 @@ public:
int centralLayoutPos(QString id) const; int centralLayoutPos(QString id) const;
QString currentLayoutName() const;
QString currentLayoutNameInMultiEnvironment() const;
void setCurrentLayoutNameInMultiEnvironment(const QString &name);
QStringList centralLayoutsNames(); QStringList centralLayoutsNames();
QStringList currentLayoutsNames() const;
QStringList layouts() const; QStringList layouts() const;
QStringList menuLayouts() const; QStringList menuLayouts() const;
void setMenuLayouts(QStringList layouts); void setMenuLayouts(QStringList layouts);
@ -120,7 +116,6 @@ public slots:
signals: signals:
void centralLayoutsChanged(); void centralLayoutsChanged();
void currentLayoutNameChanged();
void layoutsChanged(); void layoutsChanged();
void menuLayoutsChanged(); void menuLayoutsChanged();
void runningActicitiesChanged(); void runningActicitiesChanged();
@ -128,10 +123,7 @@ signals:
void currentLayoutIsSwitching(QString layoutName); void currentLayoutIsSwitching(QString layoutName);
private slots: private slots:
void updateCurrentLayoutNameInMultiEnvironment();
void onCurrentActivityChanged(const QString &id); void onCurrentActivityChanged(const QString &id);
void onLayoutAdded(const QString &layoutpath); void onLayoutAdded(const QString &layoutpath);
private: private:
@ -146,8 +138,6 @@ private:
bool m_multipleModeInitialized{false}; bool m_multipleModeInitialized{false};
bool m_isLoaded{false}; bool m_isLoaded{false};
QString m_currentLayoutNameInMultiEnvironment;
QStringList m_layouts; QStringList m_layouts;
QStringList m_menuLayouts; QStringList m_menuLayouts;

@ -75,7 +75,7 @@ void ScreenGeometries::init()
connect(m_corona, &Latte::Corona::availableScreenRectChangedFrom, this, &ScreenGeometries::availableScreenGeometryChangedFrom); connect(m_corona, &Latte::Corona::availableScreenRectChangedFrom, this, &ScreenGeometries::availableScreenGeometryChangedFrom);
connect(m_corona, &Latte::Corona::availableScreenRegionChangedFrom, this, &ScreenGeometries::availableScreenGeometryChangedFrom); connect(m_corona, &Latte::Corona::availableScreenRegionChangedFrom, this, &ScreenGeometries::availableScreenGeometryChangedFrom);
connect(m_corona->layoutsManager(), &Latte::Layouts::Manager::currentLayoutNameChanged, this, [&]() { connect(m_corona->layoutsManager()->synchronizer(), &Latte::Layouts::Synchronizer::centralLayoutsChanged, this, [&]() {
m_publishTimer.start(); m_publishTimer.start();
}); });

@ -414,7 +414,10 @@ void Layouts::loadLayouts()
m_model->setOriginalData(layoutsBuffer, inMultiple); m_model->setOriginalData(layoutsBuffer, inMultiple);
m_model->setOriginalLayoutForFreeActivities(layoutsBuffer.idForName(m_handler->corona()->universalSettings()->lastNonAssignedLayoutName())); m_model->setOriginalLayoutForFreeActivities(layoutsBuffer.idForName(m_handler->corona()->universalSettings()->lastNonAssignedLayoutName()));
m_view->selectRow(rowForName(m_handler->corona()->layoutsManager()->currentLayoutName())); QStringList currentLayoutNames = m_handler->corona()->layoutsManager()->currentLayoutsNames();
if (currentLayoutNames.count() > 0) {
m_view->selectRow(rowForName(currentLayoutNames[0]));
}
applyColumnWidths(); applyColumnWidths();
@ -609,7 +612,10 @@ bool Layouts::importLayoutsFromV1ConfigFile(QString file)
void Layouts::reset() void Layouts::reset()
{ {
m_model->resetData(); m_model->resetData();
m_view->selectRow(rowForName(m_handler->corona()->layoutsManager()->currentLayoutName())); QStringList currentLayoutNames = m_handler->corona()->layoutsManager()->currentLayoutsNames();
if (currentLayoutNames.count() > 0) {
m_view->selectRow(rowForName(currentLayoutNames[0]));
}
} }
void Layouts::save() void Layouts::save()
@ -687,10 +693,6 @@ void Layouts::save()
QString tempFile = layoutTempDir.path() + "/" + QString(generic->name() + ".layout.latte"); QString tempFile = layoutTempDir.path() + "/" + QString(generic->name() + ".layout.latte");
qDebug() << "new temp file ::: " << tempFile; qDebug() << "new temp file ::: " << tempFile;
if ((m_handler->corona()->layoutsManager()->memoryUsage() == MemoryUsage::SingleLayout) && (generic->name() == m_handler->corona()->layoutsManager()->currentLayoutName())) {
switchToLayout = iLayoutCurrentData.name;
}
generic = m_layouts.take(iLayoutCurrentData.id); generic = m_layouts.take(iLayoutCurrentData.id);
delete generic; delete generic;
@ -756,26 +758,25 @@ void Layouts::save()
//! reload layouts in layoutsmanager //! reload layouts in layoutsmanager
m_handler->corona()->layoutsManager()->synchronizer()->loadLayouts(); m_handler->corona()->layoutsManager()->synchronizer()->loadLayouts();
if (!m_model->layoutNameForFreeActivities().isEmpty() || inMultipleMode()) {
//! make sure that there is a layout for free activities
//! send to layout manager in which layout to switch
MemoryUsage::LayoutsMemory inMemoryOption = Latte::MemoryUsage::SingleLayout;
if (inMultipleMode()) { //! make sure that there is a layout for free activities
inMemoryOption = Latte::MemoryUsage::MultipleLayouts; //! send to layout manager in which layout to switch
} MemoryUsage::LayoutsMemory inMemoryOption = inMultipleMode() ? Latte::MemoryUsage::MultipleLayouts : Latte::MemoryUsage::SingleLayout;
if (m_handler->corona()->layoutsManager()->memoryUsage() != inMemoryOption) { if (m_handler->corona()->layoutsManager()->memoryUsage() != inMemoryOption) {
MemoryUsage::LayoutsMemory previousMemoryUsage = m_handler->corona()->layoutsManager()->memoryUsage(); MemoryUsage::LayoutsMemory previousMemoryUsage = m_handler->corona()->layoutsManager()->memoryUsage();
m_handler->corona()->layoutsManager()->setMemoryUsage(inMemoryOption); m_handler->corona()->layoutsManager()->setMemoryUsage(inMemoryOption);
m_handler->corona()->layoutsManager()->switchToLayout(m_model->layoutNameForFreeActivities(), previousMemoryUsage); if (m_handler->corona()->layoutsManager()->memoryUsage() == MemoryUsage::SingleLayout) {
m_handler->corona()->layoutsManager()->switchToLayout(m_handler->corona()->universalSettings()->currentLayoutName(), previousMemoryUsage);
} else { } else {
if (m_handler->corona()->layoutsManager()->memoryUsage() == MemoryUsage::MultipleLayouts) { m_handler->corona()->layoutsManager()->switchToLayout("", previousMemoryUsage);
m_handler->corona()->layoutsManager()->synchronizer()->syncMultipleLayoutsToActivities(); }
} else { } else {
m_handler->corona()->layoutsManager()->switchToLayout(m_model->layoutNameForFreeActivities()); if (m_handler->corona()->layoutsManager()->memoryUsage() == MemoryUsage::MultipleLayouts) {
} m_handler->corona()->layoutsManager()->synchronizer()->syncMultipleLayoutsToActivities();
} else {
m_handler->corona()->layoutsManager()->switchToLayout(m_handler->corona()->universalSettings()->currentLayoutName());
} }
} }

@ -58,8 +58,6 @@ Layouts::Layouts(QObject *parent, Latte::Corona *corona)
emit dataChanged(index(0, NAMECOLUMN), index(rowCount()-1, ACTIVITYCOLUMN), roles); emit dataChanged(index(0, NAMECOLUMN), index(rowCount()-1, ACTIVITYCOLUMN), roles);
}); });
connect(this, &Layouts::inMultipleModeChanged, this, &Layouts::updateActiveStates);
connect(m_corona->layoutsManager(), &Latte::Layouts::Manager::currentLayoutNameChanged, this, &Layouts::updateActiveStates);
connect(m_corona->layoutsManager(), &Latte::Layouts::Manager::centralLayoutsChanged, this, &Layouts::updateActiveStates); connect(m_corona->layoutsManager(), &Latte::Layouts::Manager::centralLayoutsChanged, this, &Layouts::updateActiveStates);
} }
@ -509,7 +507,10 @@ QVariant Layouts::data(const QModelIndex &index, int role) const
break; break;
case NAMECOLUMN: case NAMECOLUMN:
if (role == SORTINGROLE) { if (role == SORTINGROLE) {
if (m_layoutsTable[row].isActive) { if ((inMultipleMode() && m_layoutsTable[row].isActive)
|| (!inMultipleMode()
&& !original.name.isEmpty()
&& original.name == m_corona->universalSettings()->currentLayoutName())) {
return sortingPriority(HIGHESTPRIORITY, row); return sortingPriority(HIGHESTPRIORITY, row);
} }
@ -724,8 +725,7 @@ void Layouts::updateActiveStates()
for(int i=0; i<rowCount(); ++i) { for(int i=0; i<rowCount(); ++i) {
bool iActive{false}; bool iActive{false};
if (m_inMultipleMode && m_corona->layoutsManager()->synchronizer()->layout(m_layoutsTable[i].name) if (m_corona->layoutsManager()->synchronizer()->layout(m_layoutsTable[i].name)) {
|| (!m_inMultipleMode && originalData(m_layoutsTable[i].id).name == m_corona->layoutsManager()->currentLayoutName())) {
iActive = true; iActive = true;
} }

@ -203,14 +203,14 @@ void Menu::populateLayouts()
if (m_data.size() > LAYOUTSPOS + 1) { if (m_data.size() > LAYOUTSPOS + 1) {
//when there are more than 1 layouts present //when there are more than 1 layouts present
LayoutsMemoryUsage memoryUsage = static_cast<LayoutsMemoryUsage>((m_data[0]).toInt()); LayoutsMemoryUsage memoryUsage = static_cast<LayoutsMemoryUsage>((m_data[0]).toInt());
QString currentName = m_data[1]; QStringList currentNames = m_data[1].split(";;");
for (int i = LAYOUTSPOS; i < m_data.size(); ++i) { for (int i = LAYOUTSPOS; i < m_data.size(); ++i) {
bool isActive = m_data[i].startsWith("0") ? false : true; bool isActive = m_data[i].startsWith("0") ? false : true;
QString layout = m_data[i].right(m_data[i].length() - 2); QString layout = m_data[i].right(m_data[i].length() - 2);
QString currentText = (memoryUsage == MultipleLayouts && layout == currentName) ? QString currentText = (memoryUsage == MultipleLayouts && currentNames.contains(layout)) ?
(" " + i18nc("current layout", "(Current)")) : ""; (" " + i18nc("current layout", "(Current)")) : "";
QString layoutName = layout + currentText; QString layoutName = layout + currentText;

Loading…
Cancel
Save