2017-07-02 16:12:58 +03:00
/*
* 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/>.
*/
2019-05-03 17:01:48 +03:00
# include "centrallayout.h"
2017-07-02 16:12:58 +03:00
2018-12-02 03:05:52 +03:00
// local
2020-04-24 14:52:16 +03:00
# include <coretypes.h>
2020-04-24 12:31:03 +03:00
# include "../apptypes.h"
2019-01-22 19:17:55 +03:00
# include "../lattecorona.h"
2019-04-07 23:02:13 +03:00
# include "../screenpool.h"
2019-05-09 17:57:12 +03:00
# include "../layouts/importer.h"
2019-05-09 17:12:57 +03:00
# include "../layouts/manager.h"
2019-05-11 09:23:14 +03:00
# include "../layouts/synchronizer.h"
2019-02-03 01:10:07 +03:00
# include "../settings/universalsettings.h"
2019-04-07 23:02:13 +03:00
# include "../view/view.h"
2018-01-07 20:59:18 +03:00
2018-12-02 03:05:52 +03:00
// KDE
2019-04-06 18:56:24 +03:00
# include <KConfigGroup>
2018-12-02 03:05:52 +03:00
# include <KActivities/Consumer>
2020-04-22 14:09:42 +03:00
2017-07-02 16:12:58 +03:00
namespace Latte {
2019-05-03 17:01:48 +03:00
CentralLayout : : CentralLayout ( QObject * parent , QString layoutFile , QString assignedName )
2019-04-05 20:39:19 +03:00
: Layout : : GenericLayout ( parent , layoutFile , assignedName )
2017-07-02 16:12:58 +03:00
{
2019-04-05 20:39:19 +03:00
if ( m_loadedCorrectly ) {
2017-07-03 19:50:42 +03:00
loadConfig ( ) ;
2017-07-02 20:19:18 +03:00
init ( ) ;
2017-07-02 16:12:58 +03:00
}
}
2019-05-03 17:01:48 +03:00
CentralLayout : : ~ CentralLayout ( )
2017-07-02 16:12:58 +03:00
{
2018-01-10 20:48:23 +03:00
}
2018-01-08 20:21:34 +03:00
2019-05-03 17:01:48 +03:00
void CentralLayout : : init ( )
2017-07-02 20:19:18 +03:00
{
2020-08-30 20:32:13 +03:00
connect ( this , & GenericLayout : : activitiesChanged , this , & CentralLayout : : saveConfig ) ;
2019-05-03 17:01:48 +03:00
connect ( this , & CentralLayout : : disableBordersForMaximizedWindowsChanged , this , & CentralLayout : : saveConfig ) ;
connect ( this , & CentralLayout : : showInMenuChanged , this , & CentralLayout : : saveConfig ) ;
2017-07-02 20:19:18 +03:00
}
2019-05-03 17:01:48 +03:00
void CentralLayout : : initToCorona ( Latte : : Corona * corona )
2018-01-08 20:21:34 +03:00
{
2019-04-06 02:00:37 +03:00
if ( GenericLayout : : initToCorona ( corona ) ) {
2020-08-26 20:54:44 +03:00
connect ( this , & CentralLayout : : disableBordersForMaximizedWindowsChanged ,
m_corona - > layoutsManager ( ) - > synchronizer ( ) , & Layouts : : Synchronizer : : updateKWinDisabledBorders ) ;
2018-08-02 12:58:54 +03:00
}
}
2019-05-03 17:01:48 +03:00
bool CentralLayout : : disableBordersForMaximizedWindows ( ) const
2018-04-25 00:10:08 +03:00
{
return m_disableBordersForMaximizedWindows ;
}
2019-05-03 17:01:48 +03:00
void CentralLayout : : setDisableBordersForMaximizedWindows ( bool disable )
2018-04-25 00:10:08 +03:00
{
if ( m_disableBordersForMaximizedWindows = = disable ) {
return ;
}
m_disableBordersForMaximizedWindows = disable ;
emit disableBordersForMaximizedWindowsChanged ( ) ;
}
2019-05-03 17:01:48 +03:00
bool CentralLayout : : showInMenu ( ) const
2017-07-17 18:31:43 +03:00
{
return m_showInMenu ;
}
2019-05-03 17:01:48 +03:00
void CentralLayout : : setShowInMenu ( bool show )
2017-07-17 18:31:43 +03:00
{
if ( m_showInMenu = = show ) {
return ;
}
m_showInMenu = show ;
emit showInMenuChanged ( ) ;
}
2020-08-26 00:15:06 +03:00
bool CentralLayout : : isCurrent ( )
{
QStringList appliedactivities = appliedActivities ( ) ;
return ( appliedactivities . contains ( Data : : Layout : : ALLACTIVITIESID )
| | appliedactivities . contains ( m_corona - > activitiesConsumer ( ) - > currentActivity ( ) ) ) ;
}
2020-08-25 14:39:00 +03:00
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 ) ;
}
2019-05-03 17:01:48 +03:00
Layout : : Type CentralLayout : : type ( ) const
2019-05-02 12:58:56 +03:00
{
2019-05-03 17:01:48 +03:00
return Layout : : Type : : Central ;
2019-05-02 12:58:56 +03:00
}
2019-05-03 17:01:48 +03:00
QStringList CentralLayout : : activities ( ) const
2017-07-17 18:31:43 +03:00
{
return m_activities ;
}
2019-05-03 17:01:48 +03:00
void CentralLayout : : setActivities ( QStringList activities )
2017-07-17 18:31:43 +03:00
{
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 ;
2020-08-12 13:42:45 +03:00
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 ( ) ;
2020-08-29 23:37:52 +03:00
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 ( ) ;
2020-08-30 20:32:13 +03:00
cdata . lastUsedActivity = lastUsedActivity ( ) ;
2020-08-12 12:27:35 +03:00
2021-04-30 00:26:47 +03:00
cdata . errors = errors ( ) . count ( ) ;
cdata . warnings = warnings ( ) . count ( ) ;
2020-08-12 12:27:35 +03:00
return cdata ;
}
2019-05-03 17:01:48 +03:00
void CentralLayout : : loadConfig ( )
2017-07-02 20:19:18 +03:00
{
2018-04-25 00:10:08 +03:00
m_disableBordersForMaximizedWindows = m_layoutGroup . readEntry ( " disableBordersForMaximizedWindows " , false ) ;
2019-05-03 00:56:51 +03:00
m_showInMenu = m_layoutGroup . readEntry ( " showInMenu " , false ) ;
2017-07-17 18:31:43 +03:00
m_activities = m_layoutGroup . readEntry ( " activities " , QStringList ( ) ) ;
2018-01-14 14:21:11 +03:00
emit activitiesChanged ( ) ;
2017-07-02 20:19:18 +03:00
}
2019-05-03 17:01:48 +03:00
void CentralLayout : : saveConfig ( )
2017-07-02 20:19:18 +03:00
{
2019-05-03 17:01:48 +03:00
qDebug ( ) < < " CENTRAL layout is saving... for layout: " < < m_layoutName ;
2017-07-17 18:31:43 +03:00
m_layoutGroup . writeEntry ( " showInMenu " , m_showInMenu ) ;
2018-04-25 00:10:08 +03:00
m_layoutGroup . writeEntry ( " disableBordersForMaximizedWindows " , m_disableBordersForMaximizedWindows ) ;
2017-07-17 18:31:43 +03:00
m_layoutGroup . writeEntry ( " activities " , m_activities ) ;
2021-01-10 13:43:19 +03:00
m_layoutGroup . sync ( ) ;
2017-07-02 20:19:18 +03:00
}
2019-04-08 22:02:50 +03:00
//! OVERRIDES
2019-05-03 17:01:48 +03:00
const QStringList CentralLayout : : appliedActivities ( )
2018-01-10 20:48:23 +03:00
{
2019-04-06 02:00:37 +03:00
if ( ! m_corona ) {
return { } ;
2018-01-10 20:48:23 +03:00
}
2020-08-26 20:54:44 +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 ) ;
2018-01-13 13:55:13 +03:00
}
}
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 ;
}
2017-07-02 16:12:58 +03:00
}