2019-05-11 03:11:50 +03:00
/*
2021-05-27 15:01:00 +00:00
SPDX - FileCopyrightText : 2019 Michail Vourlakos < mvourlakos @ gmail . com >
SPDX - License - Identifier : GPL - 2.0 - or - later
2019-05-11 03:11:50 +03:00
*/
# ifndef LAYOUTSSYNCHRONIZER_H
# define LAYOUTSSYNCHRONIZER_H
2020-08-29 20:42:15 +03:00
// local
2020-08-30 14:04:04 +03:00
# include "../apptypes.h"
2020-08-29 20:42:15 +03:00
# include "../data/layoutdata.h"
# include "../data/layoutstable.h"
2019-05-11 03:11:50 +03:00
// Qt
# include <QObject>
# include <QHash>
# include <QTimer>
2021-11-20 11:57:14 +02:00
# include <QStringList>
2019-05-11 03:11:50 +03:00
namespace Latte {
class CentralLayout ;
class View ;
namespace Layout {
class GenericLayout ;
}
namespace Layouts {
class Manager ;
}
}
2019-06-15 21:38:07 +03:00
namespace Plasma {
class Containment ;
}
2019-05-11 03:11:50 +03:00
namespace KActivities {
class Controller ;
}
namespace Latte {
namespace Layouts {
2020-08-25 16:09:51 +03:00
//! This is a Layouts map in the following structure:
//! ACTIVITY ID -> Layout Names for that activity
2020-08-25 18:07:24 +03:00
typedef QHash < QString , QStringList > AssignedLayoutsHash ;
2019-05-11 09:23:14 +03:00
//! Layouts::Synchronizer is a very IMPORTANT class which is responsible
//! for all ACTIVE layouts, meaning layouts that have been loaded
//! in memory.
//!
//! The main task of Synchronizer is to load/unload layouts based
//! on "user preferences"/"activities settings"/"application current
//! phase" (e.g. startup/closing)
//!
2019-05-11 03:11:50 +03:00
class Synchronizer : public QObject {
Q_OBJECT
public :
Synchronizer ( QObject * parent ) ;
~ Synchronizer ( ) override ;
void unloadLayouts ( ) ;
void hideAllViews ( ) ;
void pauseLayout ( QString layoutName ) ;
void syncActiveLayoutsToOriginalFiles ( ) ;
void syncLatteViewsToScreens ( ) ;
2021-11-20 11:57:14 +02:00
void syncMultipleLayoutsToActivities ( QStringList preloadedLayouts = QStringList ( ) ) ;
2019-05-11 03:11:50 +03:00
2021-02-14 20:11:25 +02:00
//! In that case single layout file must be removed after loading the new layout
void setIsSingleLayoutInDeprecatedRenaming ( const bool & enabled ) ;
2019-05-11 03:11:50 +03:00
bool latteViewExists ( Latte : : View * view ) const ;
bool layoutExists ( QString layoutName ) const ;
//! switch to specified layout, default previousMemoryUsage means that it didn't change
2020-08-30 14:04:04 +03:00
bool switchToLayout ( QString layoutName , MemoryUsage : : LayoutsMemory newMemoryUsage = MemoryUsage : : Current ) ;
2019-05-11 03:11:50 +03:00
int centralLayoutPos ( QString id ) const ;
QStringList centralLayoutsNames ( ) ;
2020-08-27 17:10:13 +03:00
QStringList currentLayoutsNames ( ) const ;
2019-05-11 03:11:50 +03:00
QStringList layouts ( ) const ;
QStringList menuLayouts ( ) const ;
QStringList activities ( ) ;
2020-08-27 16:11:19 +03:00
QStringList freeActivities ( ) ;
2019-05-11 03:11:50 +03:00
QStringList runningActivities ( ) ;
2020-08-27 16:11:19 +03:00
QStringList freeRunningActivities ( ) ; //! These are activities that haven't been assigned to specific layout
2020-08-30 21:28:22 +03:00
QStringList validActivities ( const QStringList & layoutActivities ) ;
2019-05-11 03:11:50 +03:00
2021-04-13 10:56:15 +03:00
int screenForContainment ( Plasma : : Containment * containment ) ;
2019-06-15 21:38:07 +03:00
Latte : : View * viewForContainment ( Plasma : : Containment * containment ) ;
2020-08-25 19:30:33 +03:00
Latte : : View * viewForContainment ( uint id ) ;
QList < CentralLayout * > currentLayouts ( ) const ;
QList < Latte : : View * > currentViews ( ) const ;
QList < Latte : : View * > currentViewsWithPlasmaShortcuts ( ) const ;
2021-12-11 17:39:44 +02:00
QList < Latte : : View * > currentOriginalViews ( ) const ;
2020-08-25 19:30:33 +03:00
QList < Latte : : View * > sortedCurrentViews ( ) const ;
2021-12-11 17:39:44 +02:00
QList < Latte : : View * > sortedCurrentOriginalViews ( ) const ;
2020-08-25 22:15:39 +03:00
QList < Latte : : View * > viewsBasedOnActivityId ( const QString & id ) const ;
2019-06-15 21:38:07 +03:00
2020-08-25 22:15:39 +03:00
CentralLayout * centralLayout ( QString layoutname ) const ;
Layout : : GenericLayout * layout ( QString layoutname ) const ;
QList < CentralLayout * > centralLayoutsForActivity ( const QString activityid ) const ;
2019-05-11 03:11:50 +03:00
2020-03-16 18:17:17 +02:00
KActivities : : Controller * activitiesController ( ) const ;
2021-05-15 13:31:56 +03:00
Data : : Layout data ( const QString & storedLayoutName ) const ;
2020-08-29 20:42:15 +03:00
Data : : LayoutsTable layoutsTable ( ) const ;
void setLayoutsTable ( const Data : : LayoutsTable & table ) ;
2020-08-26 20:54:44 +03:00
public slots :
2020-08-29 20:42:15 +03:00
void initLayouts ( ) ;
2020-08-26 20:54:44 +03:00
void updateKWinDisabledBorders ( ) ;
2020-08-29 23:37:52 +03:00
void updateLayoutsTable ( ) ;
2019-05-11 03:11:50 +03:00
signals :
void centralLayoutsChanged ( ) ;
void layoutsChanged ( ) ;
void runningActicitiesChanged ( ) ;
2021-12-06 19:26:34 +02:00
void initializationFinished ( ) ;
2019-05-11 03:11:50 +03:00
void currentLayoutIsSwitching ( QString layoutName ) ;
2020-08-29 23:37:52 +03:00
void newLayoutAdded ( const Data : : Layout & layout ) ;
2020-08-30 20:32:13 +03:00
void layoutActivitiesChanged ( const Data : : Layout & layout ) ;
2020-08-29 23:37:52 +03:00
2019-05-11 03:11:50 +03:00
private slots :
2020-08-31 10:43:37 +03:00
void onActivityRemoved ( const QString & activityid ) ;
2020-08-13 21:28:52 +03:00
void onLayoutAdded ( const QString & layoutpath ) ;
2021-11-20 11:57:14 +02:00
void unloadPreloadedLayouts ( ) ;
2020-08-29 23:37:52 +03:00
void reloadAssignedLayouts ( ) ;
2021-12-12 12:52:55 +02:00
void updateBorderlessMaximizedAfterTimer ( ) ;
2020-08-29 23:37:52 +03:00
2019-05-11 03:11:50 +03:00
private :
void addLayout ( CentralLayout * layout ) ;
void unloadCentralLayout ( CentralLayout * layout ) ;
2021-11-20 11:57:14 +02:00
void unloadLayouts ( const QStringList & layoutNames , const QStringList & preloadedLayouts ) ;
2019-05-11 03:11:50 +03:00
2020-08-30 14:04:04 +03:00
bool initSingleMode ( QString layoutName ) ;
bool initMultipleMode ( QString layoutName ) ;
bool switchToLayoutInMultipleMode ( QString layoutName ) ;
bool switchToLayoutInSingleMode ( QString layoutName ) ;
2020-08-30 20:32:13 +03:00
bool switchToLayoutInMultipleModeBasedOnActivities ( const QString & layoutName ) ;
2020-08-30 14:04:04 +03:00
2020-08-25 18:07:24 +03:00
bool isAssigned ( QString layoutName ) const ;
2020-08-30 14:04:04 +03:00
bool memoryInitialized ( ) const ;
2019-05-11 03:11:50 +03:00
QString layoutPath ( QString layoutName ) ;
private :
bool m_multipleModeInitialized { false } ;
2020-08-13 22:23:59 +03:00
bool m_isLoaded { false } ;
2021-02-14 20:11:25 +02:00
bool m_isSingleLayoutInDeprecatedRenaming { false } ;
2019-05-11 03:11:50 +03:00
2021-12-12 12:52:55 +02:00
QTimer m_updateBorderlessMaximized ;
2020-08-29 20:42:15 +03:00
Data : : LayoutsTable m_layouts ;
2019-05-11 03:11:50 +03:00
QList < CentralLayout * > m_centralLayouts ;
2020-08-29 20:42:15 +03:00
AssignedLayoutsHash m_assignedLayouts ;
2019-05-11 03:11:50 +03:00
Layouts : : Manager * m_manager ;
KActivities : : Controller * m_activitiesController ;
} ;
}
}
# endif