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>
# include <KConfigGroup>
# include <KSharedConfig>
# include "dockcorona.h"
namespace Latte {
2018-01-07 19:59:18 +02:00
class DockCorona ;
2018-01-10 22:55:19 +02:00
class DockView ;
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-01-07 19:33:18 +02: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 )
2017-07-04 16:53:55 +03:00
Q_PROPERTY ( QString color READ color WRITE setColor NOTIFY colorChanged )
2017-07-03 19:25:16 +03:00
Q_PROPERTY ( QString name READ name NOTIFY nameChanged )
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-01-14 12:22:45 +02:00
void syncToLayoutFile ( ) ;
2018-01-10 19:48:23 +02:00
void unloadContainments ( ) ;
2018-01-08 19:21:34 +02:00
void unloadDockViews ( ) ;
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 ;
2017-07-17 18:31:43 +03:00
int version ( ) const ;
void setVersion ( int ver ) ;
2017-07-04 16:53:55 +03:00
QString color ( ) const ;
void setColor ( QString color ) ;
2018-01-21 13:52:33 +02:00
QString lastUsedActivityId ( ) ;
QString name ( ) const ;
QString file ( ) const ;
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
void addDock ( Plasma : : Containment * containment , bool forceLoading = 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-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 ) ;
2017-07-02 20:19:18 +03:00
signals :
2017-07-17 18:31:43 +03:00
void activitiesChanged ( ) ;
2017-07-04 16:53:55 +03:00
void colorChanged ( ) ;
2017-07-03 19:25:16 +03:00
void fileChanged ( ) ;
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 ( ) ;
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-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 :
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
2017-07-04 16:53:55 +03:00
QString m_color ;
2018-01-21 13:52:33 +02:00
QString m_lastUsedActivityId { " 0 " } ; //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 ;
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