2019-04-05 19:59:15 +03:00
/*
2021-05-27 18:01:00 +03:00
SPDX - FileCopyrightText : 2019 Michail Vourlakos < mvourlakos @ gmail . com >
SPDX - License - Identifier : GPL - 2.0 - or - later
2019-04-05 19:59:15 +03:00
*/
# ifndef GENERICLAYOUT_H
# define GENERICLAYOUT_H
// local
2020-04-24 14:52:16 +03:00
# include <coretypes.h>
2019-04-05 19:59:15 +03:00
# include "abstractlayout.h"
2021-04-30 00:26:47 +03:00
# include "../data/errordata.h"
2021-03-21 15:36:25 +03:00
# include "../data/viewdata.h"
2021-03-21 17:54:58 +03:00
# include "../data/viewstable.h"
2019-04-05 19:59:15 +03:00
// Qt
# include <QObject>
2019-04-06 02:00:37 +03:00
# include <QQuickView>
2019-04-06 18:56:24 +03:00
# include <QPointer>
2019-04-06 02:00:37 +03:00
# include <QScreen>
// Plasma
# include <Plasma>
namespace Plasma {
class Applet ;
class Containment ;
class Types ;
}
namespace Latte {
class Corona ;
2019-07-14 23:44:16 +03:00
class ScreenPool ;
2019-04-06 02:00:37 +03:00
class View ;
}
2019-04-05 19:59:15 +03:00
namespace Latte {
namespace Layout {
2019-04-07 01:16:59 +03:00
//! This is views map in the following structure:
//! SCREEN_NAME -> EDGE -> VIEWID
2020-03-07 19:30:22 +03:00
typedef QHash < QString , QHash < Plasma : : Types : : Location , QList < uint > > > ViewsMap ;
2019-04-07 01:16:59 +03:00
2019-04-05 19:59:15 +03:00
class GenericLayout : public AbstractLayout
{
Q_OBJECT
2019-04-06 02:00:37 +03:00
Q_PROPERTY ( int viewsCount READ viewsCount NOTIFY viewsCountChanged )
2019-04-05 19:59:15 +03:00
2019-05-02 12:58:56 +03:00
public :
2019-04-05 20:39:19 +03:00
GenericLayout ( QObject * parent , QString layoutFile , QString assignedName = QString ( ) ) ;
2019-04-05 19:59:15 +03:00
~ GenericLayout ( ) override ;
2019-04-06 02:00:37 +03:00
2020-07-30 18:09:49 +03:00
QString background ( ) const override ;
QString textColor ( ) const override ;
2019-04-06 02:00:37 +03:00
virtual const QStringList appliedActivities ( ) = 0 ; // to move at an interface
2021-12-11 18:39:44 +03:00
virtual bool initCorona ( ) ;
2019-04-06 02:00:37 +03:00
void importToCorona ( ) ;
2021-12-11 18:39:44 +03:00
bool initContainments ( ) ;
void setCorona ( Latte : : Corona * corona ) ;
2019-04-06 02:00:37 +03:00
2019-05-04 03:01:16 +03:00
bool isActive ( ) const ; //! is loaded and running
2020-08-26 00:15:06 +03:00
virtual bool isCurrent ( ) ;
2019-04-06 02:00:37 +03:00
bool isWritable ( ) const ;
2021-12-11 18:39:44 +03:00
bool hasCorona ( ) const ;
2019-04-06 02:00:37 +03:00
2019-04-07 23:02:13 +03:00
virtual int viewsCount ( int screen ) const ;
virtual int viewsCount ( QScreen * screen ) const ;
virtual int viewsCount ( ) const ;
2019-04-06 02:00:37 +03:00
2019-05-02 12:58:56 +03:00
Type type ( ) const override ;
2020-08-18 01:44:10 +03:00
Latte : : Corona * corona ( ) const ;
2019-04-07 15:46:03 +03:00
2019-04-06 02:00:37 +03:00
QStringList unloadedContainmentsIds ( ) ;
2020-03-14 15:41:07 +03:00
virtual Types : : ViewType latteViewType ( uint containmentId ) const ;
2020-08-18 02:15:28 +03:00
const QList < Plasma : : Containment * > * containments ( ) const ;
2019-04-06 02:00:37 +03:00
2021-04-13 10:56:15 +03:00
bool contains ( Plasma : : Containment * containment ) const ;
2021-04-15 00:58:41 +03:00
bool containsView ( const int & containmentId ) const ;
2021-04-13 10:56:15 +03:00
int screenForContainment ( Plasma : : Containment * containment ) ;
2019-04-06 02:00:37 +03:00
Latte : : View * highestPriorityView ( ) ;
2020-08-25 19:30:33 +03:00
Latte : : View * viewForContainment ( uint id ) const ;
2020-08-18 02:56:33 +03:00
Latte : : View * viewForContainment ( Plasma : : Containment * containment ) const ;
2021-04-13 00:54:42 +03:00
Plasma : : Containment * containmentForId ( uint id ) const ;
2021-04-18 11:03:22 +03:00
QList < Plasma : : Containment * > subContainmentsOf ( uint id ) const ;
2020-08-25 19:30:33 +03:00
2022-05-08 13:52:55 +03:00
static bool viewAtLowerScreenPriority ( Latte : : View * test , Latte : : View * base , QScreen * primaryScreen ) ;
2020-08-25 19:30:33 +03:00
static bool viewAtLowerEdgePriority ( Latte : : View * test , Latte : : View * base ) ;
2022-05-08 13:52:55 +03:00
static QList < Latte : : View * > sortedLatteViews ( QList < Latte : : View * > views , QScreen * primaryScreen ) ;
2020-08-25 19:30:33 +03:00
QList < Latte : : View * > sortedLatteViews ( ) ;
2019-04-07 23:02:13 +03:00
virtual QList < Latte : : View * > viewsWithPlasmaShortcuts ( ) ;
2019-04-07 19:35:55 +03:00
virtual QList < Latte : : View * > latteViews ( ) ;
2021-12-11 18:39:44 +03:00
virtual QList < Latte : : View * > onlyOriginalViews ( ) ;
ViewsMap validViewsMap ( ) ;
virtual void syncLatteViewsToScreens ( ) ;
2019-04-06 02:00:37 +03:00
void syncToLayoutFile ( bool removeLayoutId = false ) ;
void lock ( ) ; //! make it only read-only
void renameLayout ( QString newName ) ;
2019-04-07 17:20:10 +03:00
virtual void unloadContainments ( ) ;
2019-04-06 02:00:37 +03:00
void unloadLatteViews ( ) ;
void unlock ( ) ; //! make it writable which it should be the default
2019-05-25 17:49:02 +03:00
virtual void setLastConfigViewFor ( Latte : : View * view ) ;
2019-05-25 18:05:24 +03:00
virtual Latte : : View * lastConfigViewFor ( ) ;
2019-05-25 17:40:29 +03:00
2021-12-11 18:39:44 +03:00
//! this function needs the layout to have first set the corona through setCorona() function
virtual void addView ( Plasma : : Containment * containment ) ;
2019-06-20 17:42:49 +03:00
void recreateView ( Plasma : : Containment * containment , bool delayed = true ) ;
2021-12-11 18:39:44 +03:00
bool hasLatteView ( Plasma : : Containment * containment ) ;
2019-04-06 02:00:37 +03:00
2021-06-28 17:07:53 +03:00
bool newView ( const QString & templateName ) ;
2021-04-18 10:19:14 +03:00
Data : : View newView ( const Latte : : Data : : View & nextViewData ) ;
2021-04-15 00:58:41 +03:00
void removeView ( const Latte : : Data : : View & viewData ) ;
2021-04-17 14:37:09 +03:00
void updateView ( const Latte : : Data : : View & viewData ) ;
2021-04-18 11:03:22 +03:00
QString storedView ( const int & containmentId ) ; //returns temp filepath containing all view data
2021-05-02 09:08:30 +03:00
void removeOrphanedSubContainment ( const int & containmentId ) ;
2021-04-11 19:37:54 +03:00
2019-04-06 02:00:37 +03:00
//! Available edges for specific view in that screen
2019-04-07 23:02:13 +03:00
virtual QList < Plasma : : Types : : Location > availableEdgesForView ( QScreen * scr , Latte : : View * forView ) const ;
2019-04-06 02:00:37 +03:00
//! All free edges in that screen
2019-04-07 23:02:13 +03:00
virtual QList < Plasma : : Types : : Location > freeEdges ( QScreen * scr ) const ;
virtual QList < Plasma : : Types : : Location > freeEdges ( int screen ) const ;
2019-04-06 02:00:37 +03:00
2020-08-19 16:26:08 +03:00
//! Bind this latteView and its relevant containments(including subcontainments)
2019-04-06 02:00:37 +03:00
//! to this layout. It is used for moving a Latte::View from layout to layout)
void assignToLayout ( Latte : : View * latteView , QList < Plasma : : Containment * > containments ) ;
//! Unassign that latteView from this layout (this is used for moving a latteView
//! from layout to layout) and returns all the containments relevant to
//! that latteView
2021-04-27 00:08:16 +03:00
QList < Plasma : : Containment * > unassignFromLayout ( Plasma : : Containment * latteContainment ) ;
2019-04-06 02:00:37 +03:00
2021-06-03 20:36:54 +03:00
QList < int > viewsExplicitScreens ( ) ;
2019-07-14 13:59:02 +03:00
2021-03-21 17:54:58 +03:00
Latte : : Data : : ViewsTable viewsTable ( ) const ;
2021-04-30 00:26:47 +03:00
//! errors/warnings
Data : : ErrorsList errors ( ) const ;
Data : : WarningsList warnings ( ) const ;
2019-04-06 02:00:37 +03:00
public slots :
Q_INVOKABLE int viewsWithTasks ( ) const ;
2019-04-07 23:02:13 +03:00
virtual Q_INVOKABLE QList < int > qmlFreeEdges ( int screen ) const ; //change <Plasma::Types::Location> to <int> types
2019-04-06 02:00:37 +03:00
2021-05-03 23:49:39 +03:00
void toggleHiddenState ( QString viewName , QString screenName , Plasma : : Types : : Location edge ) ;
2020-03-01 18:19:24 +03:00
2019-04-06 02:00:37 +03:00
signals :
void activitiesChanged ( ) ; // to move at an interface
void viewsCountChanged ( ) ;
2019-05-09 23:45:52 +03:00
void viewEdgeChanged ( ) ;
2019-04-06 02:00:37 +03:00
//! used from ConfigView(s) in order to be informed which is one should be shown
2019-05-25 17:40:29 +03:00
void lastConfigViewForChanged ( Latte : : View * view ) ;
2019-04-06 02:00:37 +03:00
//! used from LatteView(s) in order to exist only one each time that has the highest priority
//! to use the global shortcuts activations
void preferredViewForShortcutsChanged ( Latte : : View * view ) ;
2019-04-07 19:07:24 +03:00
protected :
void updateLastUsedActivity ( ) ;
2019-04-06 02:00:37 +03:00
protected :
Latte : : Corona * m_corona { nullptr } ;
QList < Plasma : : Containment * > m_containments ;
QHash < const Plasma : : Containment * , Latte : : View * > m_latteViews ;
QHash < const Plasma : : Containment * , Latte : : View * > m_waitingLatteViews ;
2019-04-07 19:07:24 +03:00
private slots :
void addContainment ( Plasma : : Containment * containment ) ;
void appletCreated ( Plasma : : Applet * applet ) ;
void destroyedChanged ( bool destroyed ) ;
void containmentDestroyed ( QObject * cont ) ;
2020-08-26 00:41:13 +03:00
void onLastConfigViewChangedFrom ( Latte : : View * view ) ;
2019-04-07 15:46:03 +03:00
2019-04-07 19:07:24 +03:00
private :
2019-04-06 02:00:37 +03:00
//! It can be used in order for LatteViews to not be created automatically when
//! their corresponding containments are created e.g. copyView functionality
bool blockAutomaticLatteViewCreation ( ) const ;
void setBlockAutomaticLatteViewCreation ( bool block ) ;
bool explicitDockOccupyEdge ( int screen , Plasma : : Types : : Location location ) const ;
bool primaryDockOccupyEdge ( Plasma : : Types : : Location location ) const ;
2021-03-21 15:36:25 +03:00
bool viewDataAtLowerEdgePriority ( const Latte : : Data : : View & test , const Latte : : Data : : View & base ) const ;
bool viewDataAtLowerScreenPriority ( const Latte : : Data : : View & test , const Latte : : Data : : View & base ) const ;
bool viewDataAtLowerStatePriority ( const Latte : : Data : : View & test , const Latte : : Data : : View & base ) const ;
2019-07-14 18:23:52 +03:00
2019-04-07 01:16:59 +03:00
bool mapContainsId ( const ViewsMap * map , uint viewId ) const ;
2021-12-11 18:39:44 +03:00
QString mapScreenName ( const ViewsMap * map , uint viewId ) const ;
2019-04-07 01:16:59 +03:00
2020-08-19 16:26:08 +03:00
QList < int > subContainmentsOf ( Plasma : : Containment * containment ) const ;
2019-07-14 18:23:52 +03:00
2021-03-21 15:36:25 +03:00
QList < Latte : : Data : : View > sortedViewsData ( const QList < Latte : : Data : : View > & viewsData ) ;
2019-07-14 18:23:52 +03:00
2021-05-02 09:08:30 +03:00
void destroyContainment ( Plasma : : Containment * containment ) ;
2019-04-06 02:00:37 +03:00
private :
bool m_blockAutomaticLatteViewCreation { false } ;
2021-12-11 18:39:44 +03:00
bool m_hasInitializedContainments { false } ;
2019-05-25 17:40:29 +03:00
QPointer < Latte : : View > m_lastConfigViewFor ;
2019-04-06 02:00:37 +03:00
QStringList m_unloadedContainmentsIds ;
2019-04-06 18:56:24 +03:00
2019-06-20 11:21:12 +03:00
//! try to avoid crashes from recreating the same views all the time
QList < const Plasma : : Containment * > m_viewsToRecreate ;
2021-04-13 10:56:15 +03:00
//! Containments that are pending screen/state updates
Latte : : Data : : ViewsTable m_pendingContainmentUpdates ;
2019-05-09 23:45:52 +03:00
friend class Latte : : View ;
2019-04-05 19:59:15 +03:00
} ;
}
}
# endif