2017-07-02 15:02:07 +03:00
/*
2017-07-02 16:12:58 +03:00
* Copyright 2017 Smith AR < audoban @ openmailbox . org >
2017-07-02 15:02:07 +03:00
* 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/>.
*/
# ifndef LAYOUTMANAGER_H
# define LAYOUTMANAGER_H
# include "importer.h"
2018-01-07 19:33:18 +02:00
# include "layout.h"
2017-07-07 14:06:30 -05:00
# include "layoutconfigdialog.h"
2017-07-31 03:53:39 +03:00
# include "launcherssignals.h"
2017-07-02 15:02:07 +03:00
2017-07-03 19:04:37 +03:00
# include <QAction>
2017-07-02 16:12:58 +03:00
# include <QObject>
2017-07-03 19:04:37 +03:00
# include <KLocalizedString>
2018-01-12 20:11:20 +02:00
class DockCorona ;
2017-07-02 21:02:27 +03:00
class Importer ;
2018-01-07 19:33:18 +02:00
class Layout ;
2017-07-17 22:07:04 +03:00
class LayoutConfigDialog ;
2017-07-31 03:53:39 +03:00
class LaunchersSignals ;
2017-07-02 21:02:27 +03:00
2018-01-15 19:44:00 +02:00
namespace KActivities {
class Controller ;
}
2017-07-02 15:02:07 +03:00
namespace Latte {
2017-07-02 15:06:35 +03:00
//! This class is responsible to manipulate all layouts.
//! add,remove,rename, update configurations etc.
2017-07-02 15:02:07 +03:00
class LayoutManager : public QObject {
Q_OBJECT
2017-07-03 20:40:18 +03:00
Q_PROPERTY ( QString currentLayoutName READ currentLayoutName NOTIFY currentLayoutNameChanged )
Q_PROPERTY ( QStringList layouts READ layouts NOTIFY layoutsChanged )
2017-07-17 18:47:48 +03:00
Q_PROPERTY ( QStringList menuLayouts READ menuLayouts NOTIFY menuLayoutsChanged )
2017-07-03 20:40:18 +03:00
2017-07-03 19:04:37 +03:00
Q_PROPERTY ( QAction * addWidgetsAction READ addWidgetsAction NOTIFY addWidgetsActionChanged )
2017-07-31 03:53:39 +03:00
Q_PROPERTY ( LaunchersSignals * launchersSignals READ launchersSignals NOTIFY launchersSignalsChanged )
2017-07-03 19:25:16 +03:00
2017-07-02 15:02:07 +03:00
public :
LayoutManager ( QObject * parent = nullptr ) ;
~ LayoutManager ( ) override ;
2017-07-03 10:41:59 +03:00
DockCorona * corona ( ) ;
2017-07-22 19:49:28 +03:00
Importer * importer ( ) ;
2017-07-03 10:41:59 +03:00
2017-07-02 20:19:18 +03:00
void load ( ) ;
2018-01-15 14:09:41 +02:00
void loadLayoutOnStartup ( QString layoutName ) ;
2018-01-13 03:08:32 +02:00
void unload ( ) ;
2018-01-11 20:34:16 +02:00
void addDock ( Plasma : : Containment * containment , bool forceLoading = false , int expDockScreen = - 1 ) ;
void recreateDock ( Plasma : : Containment * containment ) ;
void syncDockViewsToScreens ( ) ;
2018-01-15 20:16:11 +02:00
void syncActiveLayoutsToOriginalFiles ( ) ;
2017-07-02 20:19:18 +03:00
2017-12-17 17:01:30 +02:00
bool layoutExists ( QString layoutName ) const ;
2017-07-23 21:05:34 +03:00
QString shouldSwitchToLayout ( QString activityId ) ;
2017-07-03 20:40:18 +03:00
QString currentLayoutName ( ) const ;
2017-12-17 17:01:30 +02:00
QString defaultLayoutName ( ) const ;
2017-07-03 20:40:18 +03:00
QStringList layouts ( ) const ;
2017-07-17 18:47:48 +03:00
QStringList menuLayouts ( ) const ;
2017-07-22 10:39:35 +03:00
QStringList presetsPaths ( ) const ;
2017-07-03 20:40:18 +03:00
2018-01-12 20:11:20 +02:00
Dock : : LayoutsMemoryUsage memoryUsage ( ) const ;
void setMemoryUsage ( Dock : : LayoutsMemoryUsage memoryUsage ) ;
2017-07-03 19:04:37 +03:00
QAction * addWidgetsAction ( ) ;
2018-01-11 20:34:16 +02:00
QHash < const Plasma : : Containment * , DockView * > * currentDockViews ( ) const ;
2018-01-13 21:10:58 +02:00
QHash < const Plasma : : Containment * , DockView * > * layoutDockViews ( const QString & layoutName ) const ;
2018-01-11 20:34:16 +02:00
//! returns an active layout with that #id (name), it returns null if such
//! layout cant be found
Layout * activeLayout ( QString id ) const ;
2018-01-14 09:39:31 +02:00
int activeLayoutPos ( QString id ) const ;
2018-01-11 20:34:16 +02:00
2017-07-31 03:53:39 +03:00
LaunchersSignals * launchersSignals ( ) ;
2017-07-03 19:25:16 +03:00
2017-07-18 21:18:33 +03:00
QStringList activities ( ) ;
2018-01-13 12:55:13 +02:00
QStringList runningActivities ( ) ;
QStringList orphanedActivities ( ) ; //! These are activities that havent been assigned to specific layout
2017-07-07 14:06:30 -05:00
2017-12-17 17:42:49 +02:00
void importDefaultLayout ( bool newInstanceIfPresent = false ) ;
2017-07-23 00:24:26 +03:00
void importPresets ( bool includeDefault = false ) ;
2017-07-03 19:04:37 +03:00
public slots :
//! switch to specified layout
Q_INVOKABLE bool switchToLayout ( QString layoutName ) ;
2017-07-02 21:02:27 +03:00
2017-07-03 12:58:02 +03:00
//! creates a new layout with layoutName based on the preset
2017-07-07 14:06:30 -05:00
Q_INVOKABLE QString newLayout ( QString layoutName , QString preset = i18n ( " Default " ) ) ;
Q_INVOKABLE void showLayoutConfigDialog ( ) ;
2017-07-03 19:04:37 +03:00
signals :
2018-01-11 20:34:16 +02:00
void activeLayoutsChanged ( ) ;
2017-07-03 19:04:37 +03:00
void addWidgetsActionChanged ( ) ;
2017-07-03 19:25:16 +03:00
void currentLayoutChanged ( ) ;
2017-07-03 20:40:18 +03:00
void currentLayoutNameChanged ( ) ;
2017-07-31 03:53:39 +03:00
void launchersSignalsChanged ( ) ;
2017-07-03 20:40:18 +03:00
void layoutsChanged ( ) ;
2018-01-12 20:11:20 +02:00
void memoryUsageChanged ( ) ;
2017-07-17 18:47:48 +03:00
void menuLayoutsChanged ( ) ;
2017-07-03 19:04:37 +03:00
2018-01-16 21:05:09 +02:00
void currentLayoutIsSwitching ( QString layoutName ) ;
2017-07-03 19:04:37 +03:00
private slots :
2017-07-23 21:05:34 +03:00
void currentActivityChanged ( const QString & id ) ;
2017-07-26 10:30:03 +03:00
void showInfoWindowChanged ( ) ;
2017-07-03 19:04:37 +03:00
void showWidgetsExplorer ( ) ;
2018-01-14 09:39:31 +02:00
void syncMultipleLayoutsToActivities ( QString layoutForOrphans = QString ( ) ) ;
2017-07-03 19:04:37 +03:00
private :
2018-01-14 17:30:29 +02:00
void clearUnloadedContainmentsFromLinkedFile ( QStringList containmentsIds ) ;
2017-07-23 21:05:34 +03:00
void confirmDynamicSwitch ( ) ;
2018-01-15 10:17:56 +02:00
//! it is used just in order to provide translations for the presets
void ghostForTranslatedPresets ( ) ;
2018-01-13 12:00:47 +02:00
//! This function figures in the beginning if a dock with tasks
//! in it will be loaded taking into account also the screens are present.
//! returns true if it will be loaded, false otherwise
//! firstContainmentWithTasks = the first containment containing a taskmanager plasmoid
bool heuresticForLoadingDockWithTasks ( int * firstContainmentWithTasks ) ;
void importLatteLayout ( QString layoutPath ) ;
void importPreset ( int presetNo , bool newInstanceIfPresent = false ) ;
void loadLatteLayout ( QString layoutPath ) ;
2018-01-15 10:17:56 +02:00
void loadLayouts ( ) ;
2017-07-20 18:02:58 +03:00
void setMenuLayouts ( QStringList layouts ) ;
2018-01-15 00:29:11 +02:00
void showInfoWindow ( QString info , int duration , QStringList activities = { " 0 " } ) ;
2018-01-15 10:17:56 +02:00
void updateCurrentLayoutNameInMultiEnvironment ( ) ;
bool layoutIsAssigned ( QString layoutName ) ;
2017-12-17 17:01:30 +02:00
2017-07-03 19:04:37 +03:00
QString layoutPath ( QString layoutName ) ;
2017-07-03 19:25:16 +03:00
2018-01-15 10:17:56 +02:00
QStringList validActivities ( QStringList currentList ) ;
2017-07-03 12:58:02 +03:00
2017-07-02 15:02:07 +03:00
private :
2018-01-15 10:17:56 +02:00
QString m_currentLayoutNameInMultiEnvironment ;
2017-07-23 21:05:34 +03:00
QString m_shouldSwitchToLayout ;
2017-07-03 20:40:18 +03:00
QStringList m_layouts ;
2017-07-17 18:47:48 +03:00
QStringList m_menuLayouts ;
2017-07-22 10:39:35 +03:00
QStringList m_presetsPaths ;
2017-07-03 20:40:18 +03:00
2017-07-03 19:04:37 +03:00
QAction * m_addWidgetsAction { nullptr } ;
2017-07-07 14:06:30 -05:00
QPointer < LayoutConfigDialog > m_layoutConfigDialog ;
2017-07-20 18:02:58 +03:00
2017-07-23 21:05:34 +03:00
QHash < const QString , QString > m_assignedLayouts ;
QTimer m_dynamicSwitchTimer ;
2018-01-15 10:17:56 +02:00
DockCorona * m_corona { nullptr } ;
Importer * m_importer { nullptr } ;
LaunchersSignals * m_launchersSignals { nullptr } ;
Layout * m_currentLayout { nullptr } ;
QList < Layout * > m_activeLayouts ;
2018-01-15 19:44:00 +02:00
KActivities : : Controller * m_activitiesController ;
2017-07-20 18:02:58 +03:00
friend class LayoutConfigDialog ;
2017-07-02 15:02:07 +03:00
} ;
}
# endif // LAYOUTMANAGER_H