REFACTOR:DONT load MultipleLayouts in Central(s)

--no reason to load Mutiple layouts linked file
as a Pseudo Central layout. This way no needed
checks can be removed and things are still working
as before.
pull/5/head
Michail Vourlakos 6 years ago
parent 1f14405e63
commit f2eb0b6b3a

@ -220,26 +220,6 @@ void CentralLayout::setSharedLayout(SharedLayout *layout)
emit viewsCountChanged();
}
bool CentralLayout::isCentralLayout() const
{
if (!m_corona) {
return false;
}
CentralLayout *centralLayout = m_corona->layoutManager()->centralLayout(m_layoutName);
if (centralLayout) {
return true;
} else {
return false;
}
}
bool CentralLayout::isPseudoLayout() const
{
return m_layoutName == MultipleLayoutsName;
}
void CentralLayout::loadConfig()
{
m_disableBordersForMaximizedWindows = m_layoutGroup.readEntry("disableBordersForMaximizedWindows", false);

@ -61,11 +61,6 @@ public:
bool showInMenu() const;
void setShowInMenu(bool show);
//!this layout is loaded and running
bool isCentralLayout() const;
//!it is original layout compared to pseudo-layouts that are combinations of multiple-original layouts
bool isPseudoLayout() const;
QString sharedLayoutName() const;
void setSharedLayoutName(QString name);

@ -138,6 +138,21 @@ void GenericLayout::setBlockAutomaticLatteViewCreation(bool block)
m_blockAutomaticLatteViewCreation = block;
}
bool GenericLayout::isActive() const
{
if (!m_corona) {
return false;
}
GenericLayout *generic = m_corona->layoutManager()->layout(m_layoutName);
if (generic) {
return true;
} else {
return false;
}
}
bool GenericLayout::isCurrent() const
{
if (!m_corona) {
@ -774,10 +789,7 @@ bool GenericLayout::initToCorona(Latte::Corona *corona)
qDebug() << "Layout ::::: " << name() << " added containments ::: " << m_containments.size();
//! last used activity
if (m_layoutName != MultipleLayoutsName) {
updateLastUsedActivity();
}
updateLastUsedActivity();
//! signals
connect(m_corona->activityConsumer(), &KActivities::Consumer::currentActivityChanged,

@ -71,6 +71,7 @@ public:
void importToCorona();
bool initToCorona(Latte::Corona *corona);
bool isActive() const; //! is loaded and running
virtual bool isCurrent() const;
bool isWritable() const;
bool layoutIsBroken() const;

@ -556,7 +556,6 @@ bool Storage::layoutIsBroken() const
KSharedConfigPtr lFile = KSharedConfig::openConfig(m_layout->file());
if (!m_layout->corona()) {
KConfigGroup containmentsEntries = KConfigGroup(lFile, "Containments");
ids << containmentsEntries.groupList();
@ -613,12 +612,12 @@ bool Storage::layoutIsBroken() const
qDebug() << " ---- ERROR - BROKEN LAYOUT :: " << m_layout->name() << " ----";
if (!m_layout->corona()) {
qDebug() << " --- file : " << m_layout->file();
qDebug() << " --- storaged file : " << m_layout->file();
} else {
if (m_layout->corona()->layoutManager()->memoryUsage() == Types::MultipleLayouts) {
qDebug() << " --- in multiple layouts hidden file : " << Importer::layoutFilePath(AbstractLayout::MultipleLayoutsName);
} else {
qDebug() << " --- in layout file : " << m_layout->file();
qDebug() << " --- in active layout file : " << m_layout->file();
}
}

@ -123,21 +123,19 @@ void LayoutManager::load()
void LayoutManager::unload()
{
bool multipleMode{centralLayout(Layout::AbstractLayout::MultipleLayoutsName)};
//! Unload all CentralLayouts
while (!m_centralLayouts.isEmpty()) {
CentralLayout *layout = m_centralLayouts.at(0);
m_centralLayouts.removeFirst();
if (!layout->isPseudoLayout() && multipleMode) {
if (m_multipleModeInitialized) {
layout->syncToLayoutFile(true);
}
layout->unloadContainments();
layout->unloadLatteViews();
if (!layout->isPseudoLayout() && multipleMode) {
if (m_multipleModeInitialized) {
clearUnloadedContainmentsFromLinkedFile(layout->unloadedContainmentsIds(), true);
}
@ -167,6 +165,8 @@ void LayoutManager::unload()
delete layout;
}*/
m_multipleModeInitialized = false;
//! Remove no-needed temp files
QString temp1File = QDir::homePath() + "/.config/lattedock.copy1.bak";
QString temp2File = QDir::homePath() + "/.config/lattedock.copy2.bak";
@ -254,7 +254,7 @@ QStringList LayoutManager::menuLayouts() const
fixedMenuLayouts.prepend(currentLayoutName());
} else if (memoryUsage() == Types::MultipleLayouts) {
for (const auto layout : m_centralLayouts) {
if (!layout->isPseudoLayout() && !fixedMenuLayouts.contains(layout->name())) {
if (!fixedMenuLayouts.contains(layout->name())) {
fixedMenuLayouts.prepend(layout->name());
}
}
@ -349,10 +349,7 @@ QStringList LayoutManager::centralLayoutsNames()
} else {
for (int i = 0; i < m_centralLayouts.size(); ++i) {
CentralLayout *layout = m_centralLayouts.at(i);
if (!layout->isPseudoLayout()) {
names << layout->name();
}
names << layout->name();
}
}
@ -469,7 +466,7 @@ CentralLayout *LayoutManager::currentLayout() const
}
for (auto layout : m_centralLayouts) {
if ((layout->name() != Layout::AbstractLayout::MultipleLayoutsName) && (layout->activities().isEmpty())) {
if (layout->activities().isEmpty()) {
return layout;
}
}
@ -481,7 +478,7 @@ CentralLayout *LayoutManager::currentLayout() const
void LayoutManager::updateCurrentLayoutNameInMultiEnvironment()
{
for (const auto layout : m_centralLayouts) {
if (!layout->isPseudoLayout() && layout->activities().contains(m_corona->activitiesConsumer()->currentActivity())) {
if (layout->activities().contains(m_corona->activitiesConsumer()->currentActivity())) {
m_currentLayoutNameInMultiEnvironment = layout->name();
emit currentLayoutNameChanged();
return;
@ -489,7 +486,7 @@ void LayoutManager::updateCurrentLayoutNameInMultiEnvironment()
}
for (const auto layout : m_centralLayouts) {
if (!layout->isPseudoLayout() && layout->activities().isEmpty()) {
if (layout->activities().isEmpty()) {
m_currentLayoutNameInMultiEnvironment = layout->name();
emit currentLayoutNameChanged();
return;
@ -571,6 +568,11 @@ void LayoutManager::loadLayouts()
QStringList files = layoutDir.entryList(filter, QDir::Files | QDir::NoSymLinks);
for (const auto &layout : files) {
if (layout.contains(Layout::AbstractLayout::MultipleLayoutsName)) {
//! IMPORTANT: DONT ADD MultipleLayouts hidden file in layouts list
continue;
}
CentralLayout centralLayout(this, layoutDir.absolutePath() + "/" + layout);
QStringList validActivityIds = validActivities(centralLayout.activities());
@ -720,9 +722,7 @@ void LayoutManager::importLatteLayout(QString layoutPath)
void LayoutManager::hideAllViews()
{
for (const auto layout : m_centralLayouts) {
if (!layout->isPseudoLayout()) {
emit currentLayoutIsSwitching(layout->name());
}
emit currentLayoutIsSwitching(layout->name());
}
}
@ -763,9 +763,7 @@ bool LayoutManager::switchToLayout(QString layoutName, int previousMemoryUsage)
//! nice animation that hides these docks/panels
if (previousMemoryUsage != -1) {
for (const auto layout : m_centralLayouts) {
if (!layout->isPseudoLayout()) {
emit currentLayoutIsSwitching(layout->name());
}
emit currentLayoutIsSwitching(layout->name());
}
for (const auto layout : m_sharedLayouts) {
@ -790,7 +788,7 @@ bool LayoutManager::switchToLayout(QString layoutName, int previousMemoryUsage)
CentralLayout *centralForOrphans{nullptr};
for (const auto fromLayout : m_centralLayouts) {
if (!fromLayout->isPseudoLayout() && fromLayout->activities().isEmpty()) {
if (fromLayout->activities().isEmpty()) {
centralForOrphans = fromLayout;
break;
}
@ -813,7 +811,7 @@ bool LayoutManager::switchToLayout(QString layoutName, int previousMemoryUsage)
bool initializingMultipleLayouts{false};
if (memoryUsage() == Types::MultipleLayouts && !centralLayout(Layout::AbstractLayout::MultipleLayoutsName)) {
if (memoryUsage() == Types::MultipleLayouts && !m_multipleModeInitialized) {
initializingMultipleLayouts = true;
}
@ -825,10 +823,17 @@ bool LayoutManager::switchToLayout(QString layoutName, int previousMemoryUsage)
fixedLPath = layoutPath(fixedLayoutName);
}
CentralLayout *newLayout = new CentralLayout(this, fixedLPath, fixedLayoutName);
addLayout(newLayout);
if (fixedLayoutName != Layout::AbstractLayout::MultipleLayoutsName) {
CentralLayout *newLayout = new CentralLayout(this, fixedLPath, fixedLayoutName);
addLayout(newLayout);
}
loadLatteLayout(fixedLPath);
if (initializingMultipleLayouts) {
m_multipleModeInitialized = true;
}
emit centralLayoutsChanged();
}
@ -916,7 +921,6 @@ void LayoutManager::syncMultipleLayoutsToActivities(QString layoutForOrphans)
QStringList layoutsToUnload;
QStringList layoutsToLoad;
layoutsToLoad << Layout::AbstractLayout::MultipleLayoutsName;
bool allRunningActivitiesWillBeReserved{true};
@ -951,23 +955,18 @@ void LayoutManager::syncMultipleLayoutsToActivities(QString layoutForOrphans)
//! Unload no needed Layouts
for (const auto &layoutName : layoutsToUnload) {
if (layoutName != Layout::AbstractLayout::MultipleLayoutsName) {
CentralLayout *layout = centralLayout(layoutName);
int posLayout = centralLayoutPos(layoutName);
CentralLayout *layout = centralLayout(layoutName);
int posLayout = centralLayoutPos(layoutName);
if (posLayout >= 0) {
qDebug() << "REMOVING LAYOUT ::::: " << layoutName;
m_centralLayouts.removeAt(posLayout);
if (posLayout >= 0) {
qDebug() << "REMOVING LAYOUT ::::: " << layoutName;
m_centralLayouts.removeAt(posLayout);
if (!layout->isPseudoLayout()) {
layout->syncToLayoutFile(true);
}
layout->unloadContainments();
layout->unloadLatteViews();
clearUnloadedContainmentsFromLinkedFile(layout->unloadedContainmentsIds());
delete layout;
}
layout->syncToLayoutFile(true);
layout->unloadContainments();
layout->unloadLatteViews();
clearUnloadedContainmentsFromLinkedFile(layout->unloadedContainmentsIds());
delete layout;
}
}
@ -994,7 +993,7 @@ void LayoutManager::syncMultipleLayoutsToActivities(QString layoutForOrphans)
addLayout(newLayout);
newLayout->importToCorona();
if (!newLayout->isPseudoLayout() && m_corona->universalSettings()->showInfoWindow()) {
if (m_corona->universalSettings()->showInfoWindow()) {
showInfoWindow(i18n("Activating layout: <b>%0</b> ...").arg(newLayout->name()), 5000, newLayout->appliedActivities());
}
}
@ -1030,9 +1029,7 @@ void LayoutManager::syncActiveLayoutsToOriginalFiles()
{
if (memoryUsage() == Types::MultipleLayouts) {
for (const auto layout : m_centralLayouts) {
if (!layout->isPseudoLayout()) {
layout->syncToLayoutFile();
}
layout->syncToLayoutFile();
}
for (const auto layout : m_sharedLayouts) {

@ -180,6 +180,8 @@ private:
QStringList validActivities(QStringList currentList);
private:
bool m_multipleModeInitialized{false};
QString m_currentLayoutNameInMultiEnvironment;
QString m_shouldSwitchToLayout;

@ -27,6 +27,7 @@
#include "universalsettings.h"
#include "ui_settingsdialog.h"
#include "../lattecorona.h"
#include "../layout/genericlayout.h"
#include "../layout/centrallayout.h"
#include "../liblatte2/types.h"
#include "../plasma/extended/theme.h"
@ -325,12 +326,9 @@ void SettingsDialog::on_copyButton_clicked()
if (m_corona->layoutManager()->memoryUsage() == Types::MultipleLayouts) {
QString lName = (m_model->data(m_model->index(row, NAMECOLUMN), Qt::DisplayRole)).toString();
if (Importer::layoutExists(lName)) {
CentralLayout *layout = m_corona->layoutManager()->centralLayout(lName);
if (layout && !layout->isPseudoLayout()) {
layout->syncToLayoutFile();
}
Layout::GenericLayout *generic = m_corona->layoutManager()->layout(lName);
if (generic) {
generic->syncToLayoutFile();
}
}
@ -836,51 +834,36 @@ void SettingsDialog::loadSettings()
QString layoutPath = QDir::homePath() + "/.config/latte/" + layout + ".layout.latte";
m_initLayoutPaths.append(layoutPath);
CentralLayout *layoutSets = new CentralLayout(this, layoutPath);
m_layouts[layoutPath] = layoutSets;
CentralLayout *central = new CentralLayout(this, layoutPath);
m_layouts[layoutPath] = central;
QString background = layoutSets->background();
QString background = central->background();
if (background.isEmpty()) {
insertLayoutInfoAtRow(i, layoutPath, layoutSets->color(), QString(), layoutSets->name(),
layoutSets->showInMenu(), layoutSets->disableBordersForMaximizedWindows(),
layoutSets->activities(), !layoutSets->isWritable());
insertLayoutInfoAtRow(i, layoutPath, central->color(), QString(), central->name(),
central->showInMenu(), central->disableBordersForMaximizedWindows(),
central->activities(), !central->isWritable());
} else {
insertLayoutInfoAtRow(i, layoutPath, background, layoutSets->textColor(), layoutSets->name(),
layoutSets->showInMenu(), layoutSets->disableBordersForMaximizedWindows(),
layoutSets->activities(), !layoutSets->isWritable());
insertLayoutInfoAtRow(i, layoutPath, background, central->textColor(), central->name(),
central->showInMenu(), central->disableBordersForMaximizedWindows(),
central->activities(), !central->isWritable());
}
qDebug() << "counter:" << i << " total:" << m_model->rowCount();
i++;
if (layoutSets->name() == m_corona->layoutManager()->currentLayoutName()) {
if (central->name() == m_corona->layoutManager()->currentLayoutName()) {
ui->layoutsView->selectRow(i - 1);
}
CentralLayout *centralLayout = m_corona->layoutManager()->centralLayout(layoutSets->name());
Layout::GenericLayout *generic = m_corona->layoutManager()->layout(central->name());
if ((centralLayout && centralLayout->layoutIsBroken()) || (!centralLayout && layoutSets->layoutIsBroken())) {
brokenLayouts.append(layoutSets->name());
if ((generic && generic->layoutIsBroken()) || (!generic && central->layoutIsBroken())) {
brokenLayouts.append(central->name());
}
}
//! Check Multiple Layouts Integrity
/*if (m_corona->layoutManager()->memoryUsage() == Types::MultipleLayouts) {
m_corona->layoutManager()->syncActiveLayoutsToOriginalFiles();
QString multipleLayoutPath = QDir::homePath() + "/.config/latte/" + Layout::MultipleLayoutsName + ".layout.latte";
Layout multipleHiddenLayouts(this, multipleLayoutPath, "Multiple Layouts File");
if (multipleHiddenLayouts.layoutIsBroken()) {
qDebug() << "Integrity Error ::: Multiple Layouts Hidden file is broken!!!!";
brokenLayouts.append(multipleHiddenLayouts.name());
}
}*/
recalculateAvailableActivities();
m_model->setHorizontalHeaderItem(IDCOLUMN, new QStandardItem(QString("#path")));

Loading…
Cancel
Save