1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-09 17:18:11 +03:00
latte-dock/app/layout/centrallayout.cpp

211 lines
5.6 KiB
C++
Raw Normal View History

/*
* Copyright 2017 Smith AR <audoban@openmailbox.org>
* 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 "centrallayout.h"
2018-12-02 03:05:52 +03:00
// local
#include <coretypes.h>
#include "../apptypes.h"
2019-01-22 19:17:55 +03:00
#include "../lattecorona.h"
#include "../screenpool.h"
#include "../layouts/importer.h"
#include "../layouts/manager.h"
#include "../layouts/synchronizer.h"
#include "../settings/universalsettings.h"
#include "../view/view.h"
2018-01-07 20:59:18 +03:00
2018-12-02 03:05:52 +03:00
// KDE
#include <KConfigGroup>
2018-12-02 03:05:52 +03:00
#include <KActivities/Consumer>
namespace Latte {
CentralLayout::CentralLayout(QObject *parent, QString layoutFile, QString assignedName)
: Layout::GenericLayout(parent, layoutFile, assignedName)
{
if (m_loadedCorrectly) {
loadConfig();
init();
}
}
CentralLayout::~CentralLayout()
{
2018-01-10 20:48:23 +03:00
}
void CentralLayout::init()
{
connect(this, &GenericLayout::activitiesChanged, this, &CentralLayout::saveConfig);
connect(this, &CentralLayout::disableBordersForMaximizedWindowsChanged, this, &CentralLayout::saveConfig);
connect(this, &CentralLayout::showInMenuChanged, this, &CentralLayout::saveConfig);
}
void CentralLayout::initToCorona(Latte::Corona *corona)
{
if (GenericLayout::initToCorona(corona)) {
connect(this, &CentralLayout::disableBordersForMaximizedWindowsChanged,
m_corona->layoutsManager()->synchronizer(), &Layouts::Synchronizer::updateKWinDisabledBorders);
}
}
bool CentralLayout::disableBordersForMaximizedWindows() const
{
return m_disableBordersForMaximizedWindows;
}
void CentralLayout::setDisableBordersForMaximizedWindows(bool disable)
{
if (m_disableBordersForMaximizedWindows == disable) {
return;
}
m_disableBordersForMaximizedWindows = disable;
emit disableBordersForMaximizedWindowsChanged();
}
bool CentralLayout::showInMenu() const
{
return m_showInMenu;
}
void CentralLayout::setShowInMenu(bool show)
{
if (m_showInMenu == show) {
return;
}
m_showInMenu = show;
emit showInMenuChanged();
}
bool CentralLayout::isCurrent()
{
QStringList appliedactivities = appliedActivities();
return (appliedactivities.contains(Data::Layout::ALLACTIVITIESID)
|| appliedactivities.contains(m_corona->activitiesConsumer()->currentActivity()));
}
bool CentralLayout::isOnAllActivities() const
{
return (m_activities.count() == 1 && m_activities[0] == Data::Layout::ALLACTIVITIESID);
}
bool CentralLayout::isForFreeActivities() const
{
return (m_activities.count() == 1 && m_activities[0] == Data::Layout::FREEACTIVITIESID);
}
Layout::Type CentralLayout::type() const
2019-05-02 12:58:56 +03:00
{
return Layout::Type::Central;
2019-05-02 12:58:56 +03:00
}
QStringList CentralLayout::activities() const
{
return m_activities;
}
void CentralLayout::setActivities(QStringList activities)
{
if (m_activities == activities) {
return;
}
m_activities = activities;
emit activitiesChanged();
}
2020-08-12 12:27:35 +03:00
Data::Layout CentralLayout::data() const
{
Data::Layout cdata;
cdata.id = file();
2020-08-12 12:27:35 +03:00
cdata.name = name();
cdata.icon = icon();
cdata.backgroundStyle = backgroundStyle();
cdata.color = color();
cdata.background = customBackground();
cdata.textColor = customTextColor();
cdata.isActive = (m_corona != nullptr);
2020-08-12 12:27:35 +03:00
cdata.isLocked = !isWritable();
cdata.isShownInMenu = showInMenu();
cdata.hasDisabledBorders = disableBordersForMaximizedWindows();
2021-05-03 02:50:23 +03:00
cdata.popUpMargin = popUpMargin();
2020-08-12 12:27:35 +03:00
cdata.activities = activities();
cdata.lastUsedActivity = lastUsedActivity();
2020-08-12 12:27:35 +03:00
cdata.errors = errors().count();
cdata.warnings = warnings().count();
2020-08-12 12:27:35 +03:00
return cdata;
}
void CentralLayout::loadConfig()
{
m_disableBordersForMaximizedWindows = m_layoutGroup.readEntry("disableBordersForMaximizedWindows", false);
m_showInMenu = m_layoutGroup.readEntry("showInMenu", false);
m_activities = m_layoutGroup.readEntry("activities", QStringList());
emit activitiesChanged();
}
void CentralLayout::saveConfig()
{
qDebug() << "CENTRAL layout is saving... for layout:" << m_layoutName;
m_layoutGroup.writeEntry("showInMenu", m_showInMenu);
m_layoutGroup.writeEntry("disableBordersForMaximizedWindows", m_disableBordersForMaximizedWindows);
m_layoutGroup.writeEntry("activities", m_activities);
m_layoutGroup.sync();
}
//! OVERRIDES
const QStringList CentralLayout::appliedActivities()
2018-01-10 20:48:23 +03:00
{
if (!m_corona) {
return {};
2018-01-10 20:48:23 +03:00
}
if (isOnAllActivities() || m_corona->layoutsManager()->memoryUsage() == MemoryUsage::SingleLayout) {
2020-08-25 18:07:24 +03:00
return QStringList(Data::Layout::ALLACTIVITIESID);
} else if (isForFreeActivities()) {
2020-08-27 16:11:19 +03:00
return m_corona->layoutsManager()->synchronizer()->freeRunningActivities();
2018-05-30 22:18:19 +03:00
} else {
2020-08-30 21:28:22 +03:00
return m_corona->layoutsManager()->synchronizer()->validActivities(m_activities);
}
}
2020-03-14 15:41:07 +03:00
Types::ViewType CentralLayout::latteViewType(uint containmentId) const
2019-05-12 13:24:00 +03:00
{
for (const auto view : m_latteViews) {
2020-03-14 15:41:07 +03:00
if (view->containment() && view->containment()->id() == (uint)containmentId) {
2019-05-12 13:24:00 +03:00
return view->type();
}
}
return Types::DockView;
}
}