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/>.
*/
2018-01-07 19:33:18 +02:00
# ifndef LAYOUT_H
# define LAYOUT_H
2017-07-02 16:12:58 +03:00
# include <QObject>
2018-02-03 11:34:13 +02:00
# include <QScreen>
# include <Plasma>
2017-07-02 16:12:58 +03:00
# include <KConfigGroup>
# include <KSharedConfig>
2018-02-03 11:34:13 +02:00
namespace Plasma {
class Applet ;
class Containment ;
class Types ;
}
2017-07-02 16:12:58 +03:00
namespace Latte {
2018-01-07 19:59:18 +02:00
class DockCorona ;
2018-01-10 22:55:19 +02:00
class DockView ;
2018-02-03 11:34:13 +02:00
}
namespace Latte {
2018-01-07 19:59:18 +02:00
2017-07-02 16:12:58 +03:00
//! This class is responsible to hold the settings for a specific layout.
//! It also updates always the relevant layout configuration concerning
//! its general settings (no the containments)
2018-07-03 22:15:45 +03:00
class Layout : public QObject
{
2017-07-02 16:12:58 +03:00
Q_OBJECT
2017-07-17 18:31:43 +03:00
Q_PROPERTY ( bool showInMenu READ showInMenu WRITE setShowInMenu NOTIFY showInMenuChanged )
2018-02-15 21:28:27 +02:00
Q_PROPERTY ( QString background READ background NOTIFY backgroundChanged )
2017-07-04 16:53:55 +03:00
Q_PROPERTY ( QString color READ color WRITE setColor NOTIFY colorChanged )
2018-03-06 22:54:37 +02:00
Q_PROPERTY ( QString lastUsedActivity READ lastUsedActivity NOTIFY lastUsedActivityChanged )
2017-07-03 19:25:16 +03:00
Q_PROPERTY ( QString name READ name NOTIFY nameChanged )
2018-02-15 21:28:27 +02:00
Q_PROPERTY ( QString textColor READ textColor NOTIFY textColorChanged )
2017-07-24 17:47:53 +03:00
Q_PROPERTY ( QStringList launchers READ launchers WRITE setLaunchers NOTIFY launchersChanged )
2017-07-17 18:31:43 +03:00
Q_PROPERTY ( QStringList activities READ activities WRITE setActivities NOTIFY activitiesChanged )
2017-07-02 16:12:58 +03:00
public :
2018-01-07 19:33:18 +02:00
Layout ( QObject * parent , QString layoutFile , QString layoutName = QString ( ) ) ;
~ Layout ( ) override ;
2017-07-02 16:12:58 +03:00
2018-01-13 12:00:47 +02:00
static const QString MultipleLayoutsName ;
2018-01-08 19:21:34 +02:00
void initToCorona ( DockCorona * corona ) ;
2018-07-11 20:17:06 +03:00
void syncToLayoutFile ( bool removeLayoutId = false ) ;
2018-01-10 19:48:23 +02:00
void unloadContainments ( ) ;
2018-01-08 19:21:34 +02:00
void unloadDockViews ( ) ;
2018-04-25 00:10:08 +03:00
bool disableBordersForMaximizedWindows ( ) const ;
void setDisableBordersForMaximizedWindows ( bool disable ) ;
2017-07-17 18:31:43 +03:00
bool showInMenu ( ) const ;
void setShowInMenu ( bool show ) ;
2018-01-17 23:32:50 +02:00
bool layoutIsBroken ( ) const ;
2017-07-27 22:00:51 +03:00
2018-01-14 12:22:45 +02:00
//!this layout is loaded and running
bool isActiveLayout ( ) const ;
//!it is original layout compared to pseudo-layouts that are combinations of multiple-original layouts
bool isOriginalLayout ( ) const ;
2018-04-15 00:43:54 +03:00
bool isWritable ( ) const ;
2018-07-24 22:25:19 +03:00
bool dockViewExists ( Plasma : : Containment * containment ) ;
2017-07-17 18:31:43 +03:00
int version ( ) const ;
void setVersion ( int ver ) ;
2018-02-15 21:28:27 +02:00
QString background ( ) const ;
void setBackground ( QString path ) ;
2017-07-04 16:53:55 +03:00
QString color ( ) const ;
void setColor ( QString color ) ;
2018-01-30 14:33:00 +02:00
QString lastUsedActivity ( ) ;
void clearLastUsedActivity ( ) ; //!e.g. when we export a layout
2018-01-21 13:52:33 +02:00
QString name ( ) const ;
QString file ( ) const ;
2018-02-15 21:28:27 +02:00
QString textColor ( ) const ;
void setTextColor ( QString color ) ;
2017-07-17 18:31:43 +03:00
QStringList activities ( ) const ;
void setActivities ( QStringList activities ) ;
2017-07-24 17:47:53 +03:00
QStringList launchers ( ) const ;
2017-07-24 17:56:07 +03:00
void setLaunchers ( QStringList launcherList ) ;
2017-07-02 21:02:27 +03:00
2018-01-08 19:21:34 +02:00
static QString layoutName ( const QString & fileName ) ;
2018-01-15 23:04:03 +02:00
void renameLayout ( QString newName ) ;
2018-01-14 17:30:29 +02:00
QStringList unloadedContainmentsIds ( ) ;
2018-01-08 19:21:34 +02:00
//! this function needs the layout to have first set the corona through initToCorona() function
2018-08-02 12:58:54 +03:00
void addDock ( Plasma : : Containment * containment , bool forceOnPrimary = false , int expDockScreen = - 1 ) ;
2018-01-07 19:59:18 +02:00
void copyDock ( Plasma : : Containment * containment ) ;
2018-01-08 19:21:34 +02:00
void recreateDock ( Plasma : : Containment * containment ) ;
2018-01-21 11:34:18 +02:00
2018-01-08 19:21:34 +02:00
void syncDockViewsToScreens ( ) ;
2018-01-13 19:27:32 +02:00
void importToCorona ( ) ;
2018-01-21 11:34:18 +02:00
2018-01-13 12:55:13 +02:00
const QStringList appliedActivities ( ) ;
2018-01-07 19:59:18 +02:00
2018-01-21 20:17:58 +02:00
QList < Plasma : : Containment * > * containments ( ) ;
2018-01-08 19:21:34 +02:00
QHash < const Plasma : : Containment * , DockView * > * dockViews ( ) ;
2017-07-22 10:39:35 +03:00
2018-01-21 11:34:18 +02:00
//! Bind this dockView and its relevant containments(including systrays)
//! to this layout. It is used for moving a dockView from layout to layout)
void assignToLayout ( DockView * dockView , QList < Plasma : : Containment * > containments ) ;
//! Unassign that dockView from this layout (this is used for moving a dockView
//! from layout to layout) and returns all the containments relevant to
//! that dockView
QList < Plasma : : Containment * > unassignFromLayout ( DockView * dockView ) ;
2018-01-31 18:45:15 +02:00
QList < Plasma : : Types : : Location > freeEdges ( QScreen * screen ) const ;
QList < Plasma : : Types : : Location > freeEdges ( int screen ) const ;
2018-04-15 00:43:54 +03:00
//! make it only read-only
void lock ( ) ;
//! make it writable which it should be the default
void unlock ( ) ;
2018-01-31 20:17:50 +02:00
int noDocksWithTasks ( ) const ;
2018-01-31 20:45:55 +02:00
int docksCount ( ) const ;
int docksCount ( int screen ) const ;
int docksCount ( QScreen * screen ) const ;
2018-01-31 20:17:50 +02:00
2017-07-02 20:19:18 +03:00
signals :
2017-07-17 18:31:43 +03:00
void activitiesChanged ( ) ;
2018-02-15 21:28:27 +02:00
void backgroundChanged ( ) ;
2017-07-04 16:53:55 +03:00
void colorChanged ( ) ;
2018-04-25 00:10:08 +03:00
void disableBordersForMaximizedWindowsChanged ( ) ;
2018-03-06 22:54:37 +02:00
void dockColorizerSupportChanged ( ) ;
2017-07-03 19:25:16 +03:00
void fileChanged ( ) ;
2018-01-30 14:33:00 +02:00
void lastUsedActivityChanged ( ) ;
2017-07-24 17:47:53 +03:00
void launchersChanged ( ) ;
2017-07-03 19:25:16 +03:00
void nameChanged ( ) ;
2017-07-02 20:19:18 +03:00
void versionChanged ( ) ;
2017-07-17 18:31:43 +03:00
void showInMenuChanged ( ) ;
2018-02-15 21:28:27 +02:00
void textColorChanged ( ) ;
2017-07-02 20:19:18 +03:00
private slots :
void loadConfig ( ) ;
void saveConfig ( ) ;
2018-01-10 19:48:23 +02:00
void addContainment ( Plasma : : Containment * containment ) ;
2018-01-13 19:27:32 +02:00
void appletCreated ( Plasma : : Applet * applet ) ;
2018-01-08 19:21:34 +02:00
void destroyedChanged ( bool destroyed ) ;
2018-01-10 19:48:23 +02:00
void containmentDestroyed ( QObject * cont ) ;
2018-01-21 13:52:33 +02:00
void updateLastUsedActivity ( ) ;
2018-01-08 19:21:34 +02:00
2017-07-02 20:19:18 +03:00
private :
2018-01-13 03:08:32 +02:00
void importLocalLayout ( QString file ) ;
2017-07-02 20:19:18 +03:00
void init ( ) ;
2017-07-03 19:25:16 +03:00
void setName ( QString name ) ;
void setFile ( QString file ) ;
2017-07-02 20:19:18 +03:00
2018-08-02 12:58:54 +03:00
//! It can be used in order for DockViews to not be created automatically when
//! their corresponding containments are created e.g. copyDock functionality
bool blockAutomaticDockViewCreation ( ) const ;
void setBlockAutomaticDockViewCreation ( bool block ) ;
2018-01-31 20:25:56 +02:00
bool explicitDockOccupyEdge ( int screen , Plasma : : Types : : Location location ) const ;
2018-07-24 22:25:19 +03:00
bool primaryDockOccupyEdge ( Plasma : : Types : : Location location ) const ;
2018-01-31 20:25:56 +02:00
2018-04-25 00:10:08 +03:00
bool kwin_disabledMaximizedBorders ( ) const ;
void kwin_setDisabledMaximizedBorders ( bool disable ) ;
2018-01-07 19:59:18 +02:00
QString availableId ( QStringList all , QStringList assigned , int base ) ;
2018-01-13 03:08:32 +02:00
//! provides a new file path based the provided file. The new file
//! has updated ids for containments and applets based on the corona
//! loaded ones
2018-01-14 17:30:29 +02:00
QString newUniqueIdsLayoutFromFile ( QString file ) ;
2018-01-13 03:08:32 +02:00
//! imports a layout file and returns the containments for the docks
QList < Plasma : : Containment * > importLayoutFile ( QString file ) ;
2018-01-07 19:59:18 +02:00
2017-07-02 16:12:58 +03:00
private :
2018-08-02 12:58:54 +03:00
bool m_blockAutomaticDockViewCreation { false } ;
2018-04-25 00:10:08 +03:00
bool m_disableBordersForMaximizedWindows { false } ;
2017-07-17 18:31:43 +03:00
bool m_showInMenu { false } ;
2017-07-02 20:19:18 +03:00
//if version doesnt exist it is and old layout file
2017-07-03 19:50:42 +03:00
int m_version { 2 } ;
2017-07-02 21:02:27 +03:00
2018-02-15 21:28:27 +02:00
QString m_background ;
2017-07-04 16:53:55 +03:00
QString m_color ;
2018-01-30 14:33:00 +02:00
QString m_lastUsedActivity ; //the last used activity for this layout
2017-07-02 16:12:58 +03:00
QString m_layoutFile ;
2017-07-03 19:25:16 +03:00
QString m_layoutName ;
2018-02-15 21:28:27 +02:00
QString m_textColor ;
2017-07-17 18:31:43 +03:00
QStringList m_activities ;
2017-07-24 17:47:53 +03:00
QStringList m_launchers ;
2017-07-02 16:12:58 +03:00
2018-01-14 17:30:29 +02:00
QStringList m_unloadedContainmentsIds ;
2017-07-02 16:12:58 +03:00
DockCorona * m_corona { nullptr } ;
KConfigGroup m_layoutGroup ;
2018-01-08 19:21:34 +02:00
2018-01-10 19:48:23 +02:00
QList < Plasma : : Containment * > m_containments ;
2018-01-08 19:21:34 +02:00
QHash < const Plasma : : Containment * , DockView * > m_dockViews ;
QHash < const Plasma : : Containment * , DockView * > m_waitingDockViews ;
2017-07-02 16:12:58 +03:00
} ;
}
2018-01-07 19:33:18 +02:00
# endif // LAYOUT_H