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 20:33:18 +03:00
# include "layout.h"
2017-07-02 16:12:58 +03:00
2018-02-03 12:34:13 +03:00
# include "dockcorona.h"
# include "importer.h"
# include "layoutmanager.h"
2018-01-07 20:59:18 +03:00
# include "screenpool.h"
2018-05-10 20:26:46 +03:00
# include "universalsettings.h"
2018-02-03 12:34:13 +03:00
# include "dock/dockview.h"
2018-12-01 16:22:33 +03:00
# include "dock/positioner.h"
2018-01-07 20:59:18 +03:00
# include <QDir>
2017-07-02 16:12:58 +03:00
# include <QFile>
2018-04-25 00:10:08 +03:00
# include <QtDBus/QtDBus>
2017-07-02 16:12:58 +03:00
2018-02-03 12:34:13 +03:00
# include <Plasma>
# include <Plasma/Applet>
# include <Plasma/Containment>
# include <KSharedConfig>
2018-01-21 14:52:33 +03:00
# include <KActivities/Consumer>
2017-07-02 16:12:58 +03:00
namespace Latte {
2018-01-13 13:00:47 +03:00
const QString Layout : : MultipleLayoutsName = " .multiple-layouts_hidden " ;
2018-01-07 20:33:18 +03:00
Layout : : Layout ( QObject * parent , QString layoutFile , QString assignedName )
2017-07-02 16:12:58 +03:00
: QObject ( parent )
{
2017-07-22 10:39:35 +03:00
qDebug ( ) < < " Layout file to create object: " < < layoutFile < < " with name: " < < assignedName ;
2017-07-03 21:33:27 +03:00
2017-07-02 20:19:18 +03:00
if ( QFile ( layoutFile ) . exists ( ) ) {
2017-07-22 10:39:35 +03:00
if ( assignedName . isEmpty ( ) ) {
assignedName = layoutName ( layoutFile ) ;
2017-07-03 19:25:16 +03:00
}
2018-01-16 00:04:03 +03:00
//!this order is important because setFile initializes also the m_layoutGroup
2017-07-03 19:25:16 +03:00
setFile ( layoutFile ) ;
2017-07-22 10:39:35 +03:00
setName ( assignedName ) ;
2017-07-03 19:50:42 +03:00
loadConfig ( ) ;
2017-07-02 20:19:18 +03:00
init ( ) ;
2017-07-02 16:12:58 +03:00
}
}
2018-01-07 20:33:18 +03:00
Layout : : ~ Layout ( )
2017-07-02 16:12:58 +03:00
{
2017-07-17 22:07:04 +03:00
if ( ! m_layoutFile . isEmpty ( ) ) {
m_layoutGroup . sync ( ) ;
}
2018-01-10 20:48:23 +03:00
}
2018-01-08 20:21:34 +03:00
2018-07-11 20:17:06 +03:00
void Layout : : syncToLayoutFile ( bool removeLayoutId )
2018-01-14 13:22:45 +03:00
{
2018-04-18 23:27:39 +03:00
if ( ! m_corona | | ! isWritable ( ) ) {
2018-01-14 13:22:45 +03:00
return ;
}
2018-01-16 00:04:03 +03:00
KSharedConfigPtr filePtr = KSharedConfig : : openConfig ( m_layoutFile ) ;
KConfigGroup oldContainments = KConfigGroup ( filePtr , " Containments " ) ;
2018-01-14 13:22:45 +03:00
oldContainments . deleteGroup ( ) ;
oldContainments . sync ( ) ;
2018-01-15 21:16:11 +03:00
qDebug ( ) < < " LAYOUT :: " < < m_layoutName < < " is syncing its original file. " ;
2018-01-14 13:22:45 +03:00
foreach ( auto containment , m_containments ) {
2018-07-11 20:17:06 +03:00
if ( removeLayoutId ) {
containment - > config ( ) . writeEntry ( " layoutId " , " " ) ;
}
2018-01-14 13:22:45 +03:00
KConfigGroup newGroup = oldContainments . group ( QString : : number ( containment - > id ( ) ) ) ;
containment - > config ( ) . copyTo ( & newGroup ) ;
2018-07-11 20:17:06 +03:00
if ( ! removeLayoutId ) {
newGroup . writeEntry ( " layoutId " , " " ) ;
newGroup . sync ( ) ;
}
2018-01-14 13:22:45 +03:00
}
oldContainments . sync ( ) ;
}
2018-01-10 20:48:23 +03:00
void Layout : : unloadContainments ( )
{
if ( ! m_corona ) {
return ;
}
2018-01-14 10:39:31 +03:00
qDebug ( ) < < " Layout - " + name ( ) + " unload: containments ... size ::: " < < m_containments . size ( )
< < " ,dockViews in memory ::: " < < m_dockViews . size ( )
< < " ,hidden dockViews in memory ::: " < < m_waitingDockViews . size ( ) ;
2018-01-10 20:48:23 +03:00
2018-01-11 22:11:46 +03:00
foreach ( auto view , m_dockViews ) {
view - > disconnectSensitiveSignals ( ) ;
}
foreach ( auto view , m_waitingDockViews ) {
view - > disconnectSensitiveSignals ( ) ;
}
2018-01-21 12:34:18 +03:00
m_unloadedContainmentsIds . clear ( ) ;
2018-01-11 22:11:46 +03:00
QList < Plasma : : Containment * > systrays ;
//!identify systrays and unload them first
foreach ( auto containment , m_containments ) {
if ( Plasma : : Applet * parentApplet = qobject_cast < Plasma : : Applet * > ( containment - > parent ( ) ) ) {
systrays . append ( containment ) ;
}
}
while ( ! systrays . isEmpty ( ) ) {
Plasma : : Containment * systray = systrays . at ( 0 ) ;
2018-01-14 18:30:29 +03:00
m_unloadedContainmentsIds < < QString : : number ( systray - > id ( ) ) ;
2018-01-11 22:11:46 +03:00
systrays . removeFirst ( ) ;
m_containments . removeAll ( systray ) ;
delete systray ;
}
2018-01-10 20:48:23 +03:00
while ( ! m_containments . isEmpty ( ) ) {
Plasma : : Containment * containment = m_containments . at ( 0 ) ;
2018-01-14 18:30:29 +03:00
m_unloadedContainmentsIds < < QString : : number ( containment - > id ( ) ) ;
2018-01-10 20:48:23 +03:00
m_containments . removeFirst ( ) ;
delete containment ;
}
2018-01-08 20:21:34 +03:00
}
void Layout : : unloadDockViews ( )
{
2018-01-10 20:48:23 +03:00
if ( ! m_corona ) {
return ;
}
qDebug ( ) < < " Layout - " + name ( ) + " unload: dockViews ... size: " < < m_dockViews . size ( ) ;
2018-01-08 20:21:34 +03:00
qDeleteAll ( m_dockViews ) ;
qDeleteAll ( m_waitingDockViews ) ;
m_dockViews . clear ( ) ;
m_waitingDockViews . clear ( ) ;
2017-07-02 16:12:58 +03:00
}
2018-01-07 20:33:18 +03:00
void Layout : : init ( )
2017-07-02 20:19:18 +03:00
{
2018-01-07 20:33:18 +03:00
connect ( this , & Layout : : activitiesChanged , this , & Layout : : saveConfig ) ;
2018-02-15 22:28:27 +03:00
connect ( this , & Layout : : backgroundChanged , this , & Layout : : saveConfig ) ;
2018-01-07 20:33:18 +03:00
connect ( this , & Layout : : versionChanged , this , & Layout : : saveConfig ) ;
2018-02-15 22:28:27 +03:00
connect ( this , & Layout : : colorChanged , this , & Layout : : textColorChanged ) ;
2018-04-25 00:10:08 +03:00
connect ( this , & Layout : : disableBordersForMaximizedWindowsChanged , this , & Layout : : saveConfig ) ;
2018-01-07 20:33:18 +03:00
connect ( this , & Layout : : showInMenuChanged , this , & Layout : : saveConfig ) ;
2018-02-15 22:28:27 +03:00
connect ( this , & Layout : : textColorChanged , this , & Layout : : saveConfig ) ;
2018-01-07 20:33:18 +03:00
connect ( this , & Layout : : launchersChanged , this , & Layout : : saveConfig ) ;
2018-01-30 15:33:00 +03:00
connect ( this , & Layout : : lastUsedActivityChanged , this , & Layout : : saveConfig ) ;
2017-07-02 20:19:18 +03:00
}
2018-01-08 20:21:34 +03:00
void Layout : : initToCorona ( DockCorona * corona )
{
m_corona = corona ;
2018-01-10 20:48:23 +03:00
foreach ( auto containment , m_corona - > containments ( ) ) {
2018-01-13 13:00:47 +03:00
if ( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Dock : : SingleLayout ) {
addContainment ( containment ) ;
} else if ( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Dock : : MultipleLayouts ) {
QString layoutId = containment - > config ( ) . readEntry ( " layoutId " , QString ( ) ) ;
if ( ! layoutId . isEmpty ( ) & & ( layoutId = = m_layoutName ) ) {
addContainment ( containment ) ;
}
}
2018-01-10 20:48:23 +03:00
}
qDebug ( ) < < " Layout ::::: " < < name ( ) < < " added contaiments ::: " < < m_containments . size ( ) ;
2018-05-10 20:26:46 +03:00
connect ( m_corona - > universalSettings ( ) , & UniversalSettings : : canDisableBordersChanged , this , [ & ] ( ) {
if ( m_corona - > universalSettings ( ) - > canDisableBorders ( ) ) {
kwin_setDisabledMaximizedBorders ( disableBordersForMaximizedWindows ( ) ) ;
} else {
kwin_setDisabledMaximizedBorders ( false ) ;
}
} ) ;
2018-10-07 01:11:09 +03:00
if ( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Dock : : SingleLayout & & m_corona - > universalSettings ( ) - > canDisableBorders ( ) ) {
2018-04-25 00:10:08 +03:00
kwin_setDisabledMaximizedBorders ( disableBordersForMaximizedWindows ( ) ) ;
} else if ( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Dock : : MultipleLayouts ) {
connect ( m_corona - > layoutManager ( ) , & LayoutManager : : currentLayoutNameChanged , this , [ & ] ( ) {
2018-05-10 20:26:46 +03:00
if ( m_corona - > universalSettings ( ) - > canDisableBorders ( )
& & m_corona - > layoutManager ( ) - > currentLayoutName ( ) = = name ( ) ) {
2018-04-25 00:10:08 +03:00
kwin_setDisabledMaximizedBorders ( disableBordersForMaximizedWindows ( ) ) ;
}
} ) ;
}
2018-01-31 21:54:45 +03:00
if ( m_layoutName ! = MultipleLayoutsName ) {
updateLastUsedActivity ( ) ;
}
2018-01-21 14:52:33 +03:00
2018-01-10 20:48:23 +03:00
connect ( m_corona , & Plasma : : Corona : : containmentAdded , this , & Layout : : addContainment ) ;
2018-01-21 14:52:33 +03:00
2018-03-08 18:37:02 +03:00
connect ( m_corona - > m_activityConsumer , & KActivities : : Consumer : : currentActivityChanged ,
this , & Layout : : updateLastUsedActivity ) ;
2018-01-08 20:21:34 +03:00
}
2018-01-07 20:33:18 +03:00
int Layout : : version ( ) const
2017-07-02 20:19:18 +03:00
{
return m_version ;
}
2018-01-07 20:33:18 +03:00
void Layout : : setVersion ( int ver )
2017-07-02 20:19:18 +03:00
{
if ( m_version = = ver ) {
return ;
}
m_version = ver ;
emit versionChanged ( ) ;
}
2018-08-02 12:58:54 +03:00
bool Layout : : blockAutomaticDockViewCreation ( ) const
{
return m_blockAutomaticDockViewCreation ;
}
void Layout : : setBlockAutomaticDockViewCreation ( bool block )
{
if ( m_blockAutomaticDockViewCreation = = block ) {
return ;
}
m_blockAutomaticDockViewCreation = block ;
}
2018-04-25 00:10:08 +03:00
bool Layout : : disableBordersForMaximizedWindows ( ) const
{
return m_disableBordersForMaximizedWindows ;
}
void Layout : : setDisableBordersForMaximizedWindows ( bool disable )
{
if ( m_disableBordersForMaximizedWindows = = disable ) {
return ;
}
m_disableBordersForMaximizedWindows = disable ;
2018-05-10 21:14:48 +03:00
kwin_setDisabledMaximizedBorders ( disable ) ;
2018-04-25 00:10:08 +03:00
emit disableBordersForMaximizedWindowsChanged ( ) ;
}
bool Layout : : kwin_disabledMaximizedBorders ( ) const
{
//! Indentify Plasma Desktop version
QProcess process ;
process . start ( " kreadconfig5 --file kwinrc --group Windows --key BorderlessMaximizedWindows " ) ;
process . waitForFinished ( ) ;
QString output ( process . readAllStandardOutput ( ) ) ;
output = output . remove ( " \n " ) ;
return ( output = = " true " ) ;
}
void Layout : : kwin_setDisabledMaximizedBorders ( bool disable )
{
if ( kwin_disabledMaximizedBorders ( ) = = disable ) {
return ;
}
QString disableText = disable ? " true " : " false " ;
QProcess process ;
QString commandStr = " kwriteconfig5 --file kwinrc --group Windows --key BorderlessMaximizedWindows --type bool " + disableText ;
process . start ( commandStr ) ;
process . waitForFinished ( ) ;
QDBusInterface iface ( " org.kde.KWin " , " /KWin " , " " , QDBusConnection : : sessionBus ( ) ) ;
if ( iface . isValid ( ) ) {
iface . call ( " reconfigure " ) ;
}
}
2018-01-07 20:33:18 +03:00
bool Layout : : showInMenu ( ) const
2017-07-17 18:31:43 +03:00
{
return m_showInMenu ;
}
2018-01-07 20:33:18 +03:00
void Layout : : setShowInMenu ( bool show )
2017-07-17 18:31:43 +03:00
{
if ( m_showInMenu = = show ) {
return ;
}
m_showInMenu = show ;
emit showInMenuChanged ( ) ;
}
2018-04-15 00:43:54 +03:00
bool Layout : : isWritable ( ) const
{
QFileInfo layoutFileInfo ( m_layoutFile ) ;
if ( layoutFileInfo . exists ( ) & & ! layoutFileInfo . isWritable ( ) ) {
return false ;
} else {
return true ;
}
}
void Layout : : lock ( )
{
QFileInfo layoutFileInfo ( m_layoutFile ) ;
if ( layoutFileInfo . exists ( ) & & layoutFileInfo . isWritable ( ) ) {
QFile ( m_layoutFile ) . setPermissions ( QFileDevice : : ReadUser | QFileDevice : : ReadGroup | QFileDevice : : ReadOther ) ;
}
}
void Layout : : unlock ( )
{
QFileInfo layoutFileInfo ( m_layoutFile ) ;
if ( layoutFileInfo . exists ( ) & & ! layoutFileInfo . isWritable ( ) ) {
QFile ( m_layoutFile ) . setPermissions ( QFileDevice : : ReadUser | QFileDevice : : WriteUser | QFileDevice : : ReadGroup | QFileDevice : : ReadOther ) ;
}
}
2018-02-15 22:28:27 +03:00
QString Layout : : background ( ) const
{
return m_background ;
}
void Layout : : setBackground ( QString path )
{
if ( path = = m_background ) {
return ;
}
if ( ! path . isEmpty ( ) & & ! QFileInfo ( path ) . exists ( ) ) {
return ;
}
m_background = path ;
2018-02-17 00:55:43 +03:00
//! initialize the text color also
if ( path . isEmpty ( ) ) {
setTextColor ( QString ( ) ) ;
}
2018-02-15 22:28:27 +03:00
emit backgroundChanged ( ) ;
}
2018-01-07 20:33:18 +03:00
QString Layout : : name ( ) const
2017-07-03 19:25:16 +03:00
{
return m_layoutName ;
}
2018-01-07 20:33:18 +03:00
void Layout : : setName ( QString name )
2017-07-03 19:25:16 +03:00
{
if ( m_layoutName = = name ) {
return ;
}
2017-07-03 21:33:27 +03:00
qDebug ( ) < < " Layout name: " < < name ;
2017-07-03 19:25:16 +03:00
m_layoutName = name ;
emit nameChanged ( ) ;
}
2018-01-16 00:04:03 +03:00
void Layout : : renameLayout ( QString newName )
{
if ( m_layoutFile ! = Importer : : layoutFilePath ( newName ) ) {
setFile ( Importer : : layoutFilePath ( newName ) ) ;
}
if ( m_layoutName ! = newName ) {
setName ( newName ) ;
}
//! thus this is a linked file
if ( m_corona ) {
foreach ( auto containment , m_containments ) {
containment - > config ( ) . writeEntry ( " layoutId " , m_layoutName ) ;
}
}
}
2018-01-07 20:33:18 +03:00
QString Layout : : color ( ) const
2017-07-04 16:53:55 +03:00
{
return m_color ;
}
2018-01-07 20:33:18 +03:00
void Layout : : setColor ( QString color )
2017-07-04 16:53:55 +03:00
{
if ( m_color = = color ) {
return ;
}
m_color = color ;
emit colorChanged ( ) ;
}
2018-02-15 22:28:27 +03:00
QString Layout : : textColor ( ) const
{
//! the user is in default layout theme
if ( m_background . isEmpty ( ) ) {
if ( m_color = = " blue " ) {
return " #D7E3FF " ;
} else if ( m_color = = " brown " ) {
2018-02-28 21:45:57 +03:00
return " #F1DECB " ;
2018-02-15 22:28:27 +03:00
} else if ( m_color = = " darkgrey " ) {
return " #ECECEC " ;
} else if ( m_color = = " gold " ) {
2018-02-28 21:13:13 +03:00
return " #7C3636 " ;
2018-02-15 22:28:27 +03:00
} else if ( m_color = = " green " ) {
2018-02-28 21:13:13 +03:00
return " #4D7549 " ;
2018-02-15 22:28:27 +03:00
} else if ( m_color = = " lightskyblue " ) {
2018-02-28 21:13:13 +03:00
return " #0C2A43 " ;
2018-02-15 22:28:27 +03:00
} else if ( m_color = = " orange " ) {
2018-02-28 21:13:13 +03:00
return " #6F3902 " ;
2018-02-15 22:28:27 +03:00
} else if ( m_color = = " pink " ) {
return " #743C46 " ;
} else if ( m_color = = " purple " ) {
return " #ECD9FF " ;
} else if ( m_color = = " red " ) {
2018-02-28 21:13:13 +03:00
return " #F3E4E4 " ;
2018-02-15 22:28:27 +03:00
} else if ( m_color = = " wheat " ) {
2018-02-28 21:13:13 +03:00
return " #6A4E25 " ;
2018-02-15 22:28:27 +03:00
} else {
return " #FCFCFC " ;
}
}
2018-02-17 01:36:06 +03:00
return " # " + m_textColor ;
2018-02-15 22:28:27 +03:00
}
void Layout : : setTextColor ( QString color )
{
2018-02-17 02:54:06 +03:00
//! remove # if someone is trying to set it this way
if ( color . startsWith ( " # " ) ) {
color . remove ( 0 , 1 ) ;
}
2018-02-15 22:28:27 +03:00
if ( m_textColor = = color ) {
return ;
}
m_textColor = color ;
emit textColorChanged ( ) ;
}
2017-07-03 19:25:16 +03:00
2018-01-07 20:33:18 +03:00
QString Layout : : file ( ) const
2017-07-03 19:25:16 +03:00
{
return m_layoutFile ;
}
2018-01-07 20:33:18 +03:00
void Layout : : setFile ( QString file )
2017-07-03 19:25:16 +03:00
{
if ( m_layoutFile = = file ) {
return ;
}
2017-07-03 21:33:27 +03:00
qDebug ( ) < < " Layout file: " < < file ;
2017-07-03 19:25:16 +03:00
m_layoutFile = file ;
2018-01-16 00:04:03 +03:00
KSharedConfigPtr filePtr = KSharedConfig : : openConfig ( m_layoutFile ) ;
m_layoutGroup = KConfigGroup ( filePtr , " LayoutSettings " ) ;
2017-07-03 19:25:16 +03:00
emit fileChanged ( ) ;
}
2018-01-07 20:33:18 +03:00
QStringList Layout : : launchers ( ) const
2017-07-02 21:02:27 +03:00
{
2017-07-24 17:47:53 +03:00
return m_launchers ;
2017-07-02 21:02:27 +03:00
}
2018-01-07 20:33:18 +03:00
void Layout : : setLaunchers ( QStringList launcherList )
2017-07-02 21:02:27 +03:00
{
2017-07-24 17:56:07 +03:00
if ( m_launchers = = launcherList )
2017-07-02 21:02:27 +03:00
return ;
2017-07-24 17:56:07 +03:00
m_launchers = launcherList ;
2017-07-02 21:02:27 +03:00
2017-07-24 17:47:53 +03:00
emit launchersChanged ( ) ;
2017-07-02 21:02:27 +03:00
}
2018-01-07 20:33:18 +03:00
QStringList Layout : : activities ( ) const
2017-07-17 18:31:43 +03:00
{
return m_activities ;
}
2018-01-07 20:59:18 +03:00
void Layout : : setActivities ( QStringList activities )
2017-07-17 18:31:43 +03:00
{
if ( m_activities = = activities ) {
return ;
}
m_activities = activities ;
emit activitiesChanged ( ) ;
}
2018-01-14 18:30:29 +03:00
QStringList Layout : : unloadedContainmentsIds ( )
{
return m_unloadedContainmentsIds ;
}
2018-01-14 13:22:45 +03:00
bool Layout : : isActiveLayout ( ) const
{
if ( ! m_corona ) {
return false ;
}
Layout * activeLayout = m_corona - > layoutManager ( ) - > activeLayout ( m_layoutName ) ;
if ( activeLayout ) {
return true ;
} else {
return false ;
}
}
bool Layout : : isOriginalLayout ( ) const
{
return m_layoutName ! = MultipleLayoutsName ;
}
2018-01-18 00:32:50 +03:00
bool Layout : : layoutIsBroken ( ) const
2017-07-27 22:00:51 +03:00
{
if ( m_layoutFile . isEmpty ( ) | | ! QFile ( m_layoutFile ) . exists ( ) ) {
return false ;
}
QStringList ids ;
2017-08-20 23:55:35 +03:00
QStringList conts ;
QStringList applets ;
2017-07-27 22:00:51 +03:00
2018-01-18 00:32:50 +03:00
KSharedConfigPtr lFile = KSharedConfig : : openConfig ( m_layoutFile ) ;
if ( ! m_corona ) {
KConfigGroup containmentsEntries = KConfigGroup ( lFile , " Containments " ) ;
ids < < containmentsEntries . groupList ( ) ;
conts < < ids ;
2017-07-27 22:00:51 +03:00
2018-01-18 00:32:50 +03:00
foreach ( auto cId , containmentsEntries . groupList ( ) ) {
auto appletsEntries = containmentsEntries . group ( cId ) . group ( " Applets " ) ;
ids < < appletsEntries . groupList ( ) ;
applets < < appletsEntries . groupList ( ) ;
}
} else {
foreach ( auto containment , m_containments ) {
ids < < QString : : number ( containment - > id ( ) ) ;
2018-11-11 10:29:06 +03:00
conts < < QString : : number ( containment - > id ( ) ) ;
2018-01-18 00:32:50 +03:00
foreach ( auto applet , containment - > applets ( ) ) {
ids < < QString : : number ( applet - > id ( ) ) ;
applets < < QString : : number ( applet - > id ( ) ) ;
}
}
2017-07-27 22:00:51 +03:00
}
QSet < QString > idsSet = QSet < QString > : : fromList ( ids ) ;
2018-01-18 00:32:50 +03:00
/* a different way to count duplicates
2017-08-20 23:55:35 +03:00
QMap < QString , int > countOfStrings ;
for ( int i = 0 ; i < ids . count ( ) ; i + + ) {
countOfStrings [ ids [ i ] ] + + ;
2018-01-18 00:32:50 +03:00
} */
2017-08-20 23:55:35 +03:00
2017-07-27 22:00:51 +03:00
if ( idsSet . count ( ) ! = ids . count ( ) ) {
2018-01-16 19:15:47 +03:00
qDebug ( ) < < " ---- ERROR - BROKEN LAYOUT :: " < < m_layoutName < < " ---- " ;
2018-01-18 00:32:50 +03:00
if ( ! m_corona ) {
2018-11-11 10:29:06 +03:00
qDebug ( ) < < " --- file : " < < m_layoutFile ;
2018-01-18 00:32:50 +03:00
} else {
2018-11-11 10:29:06 +03:00
if ( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Dock : : MultipleLayouts ) {
qDebug ( ) < < " --- in multiple layouts hidden file : " < < Importer : : layoutFilePath ( Layout : : MultipleLayoutsName ) ;
} else {
qDebug ( ) < < " --- in layout file : " < < m_layoutFile ;
}
2018-01-18 00:32:50 +03:00
}
2018-01-16 19:15:47 +03:00
qDebug ( ) < < " Contaiments :: " < < conts ;
qDebug ( ) < < " Applets :: " < < applets ;
2017-08-20 23:55:35 +03:00
foreach ( QString c , conts ) {
if ( applets . contains ( c ) ) {
qDebug ( ) < < " Error: Same applet and containment id found ::: " < < c ;
}
}
for ( int i = 0 ; i < ids . count ( ) ; + + i ) {
for ( int j = i + 1 ; j < ids . count ( ) ; + + j ) {
if ( ids [ i ] = = ids [ j ] ) {
qDebug ( ) < < " Error: Applets with same id ::: " < < ids [ i ] ;
}
}
}
2018-01-16 19:15:47 +03:00
qDebug ( ) < < " -- - -- - -- - -- - - -- - - - - -- - - - - " ;
2018-01-18 00:32:50 +03:00
if ( ! m_corona ) {
KConfigGroup containmentsEntries = KConfigGroup ( lFile , " Containments " ) ;
2018-01-16 19:15:47 +03:00
2018-01-18 00:32:50 +03:00
foreach ( auto cId , containmentsEntries . groupList ( ) ) {
auto appletsEntries = containmentsEntries . group ( cId ) . group ( " Applets " ) ;
qDebug ( ) < < " CONTAINMENT : " < < cId < < " APPLETS : " < < appletsEntries . groupList ( ) ;
}
} else {
foreach ( auto containment , m_containments ) {
QStringList appletsIds ;
2018-01-16 19:15:47 +03:00
2018-01-18 00:32:50 +03:00
foreach ( auto applet , containment - > applets ( ) ) {
appletsIds < < QString : : number ( applet - > id ( ) ) ;
}
qDebug ( ) < < " CONTAINMENT : " < < containment - > id ( ) < < " APPLETS : " < < appletsIds . join ( " , " ) ;
}
}
2018-01-16 19:15:47 +03:00
2017-07-27 22:00:51 +03:00
return true ;
}
return false ;
}
2018-01-07 20:33:18 +03:00
QString Layout : : layoutName ( const QString & fileName )
2017-07-22 10:39:35 +03:00
{
int lastSlash = fileName . lastIndexOf ( " / " ) ;
QString tempLayoutFile = fileName ;
QString layoutName = tempLayoutFile . remove ( 0 , lastSlash + 1 ) ;
int ext = layoutName . lastIndexOf ( " .layout.latte " ) ;
layoutName = layoutName . remove ( ext , 13 ) ;
return layoutName ;
}
2018-01-07 20:33:18 +03:00
void Layout : : loadConfig ( )
2017-07-02 20:19:18 +03:00
{
2017-07-03 19:50:42 +03:00
m_version = m_layoutGroup . readEntry ( " version " , 2 ) ;
2017-07-04 16:53:55 +03:00
m_color = m_layoutGroup . readEntry ( " color " , QString ( " blue " ) ) ;
2018-04-25 00:10:08 +03:00
m_disableBordersForMaximizedWindows = m_layoutGroup . readEntry ( " disableBordersForMaximizedWindows " , false ) ;
2017-07-17 18:31:43 +03:00
m_showInMenu = m_layoutGroup . readEntry ( " showInMenu " , false ) ;
2018-02-15 22:28:27 +03:00
m_textColor = m_layoutGroup . readEntry ( " textColor " , QString ( " fcfcfc " ) ) ;
2017-07-17 18:31:43 +03:00
m_activities = m_layoutGroup . readEntry ( " activities " , QStringList ( ) ) ;
2017-07-24 17:47:53 +03:00
m_launchers = m_layoutGroup . readEntry ( " launchers " , QStringList ( ) ) ;
2018-01-30 15:33:00 +03:00
m_lastUsedActivity = m_layoutGroup . readEntry ( " lastUsedActivity " , QString ( ) ) ;
2018-01-14 14:21:11 +03:00
2018-02-15 22:28:27 +03:00
QString back = m_layoutGroup . readEntry ( " background " , " " ) ;
if ( ! back . isEmpty ( ) ) {
if ( QFileInfo ( back ) . exists ( ) ) {
m_background = back ;
} else {
m_layoutGroup . writeEntry ( " background " , QString ( ) ) ;
}
}
2018-01-14 14:21:11 +03:00
emit activitiesChanged ( ) ;
2017-07-02 20:19:18 +03:00
}
2018-01-07 20:33:18 +03:00
void Layout : : saveConfig ( )
2017-07-02 20:19:18 +03:00
{
2017-07-03 19:50:42 +03:00
qDebug ( ) < < " layout is saving... for layout: " < < m_layoutName ;
2017-07-02 20:19:18 +03:00
m_layoutGroup . writeEntry ( " version " , m_version ) ;
2017-07-17 18:31:43 +03:00
m_layoutGroup . writeEntry ( " showInMenu " , m_showInMenu ) ;
2017-07-04 16:53:55 +03:00
m_layoutGroup . writeEntry ( " color " , m_color ) ;
2018-04-25 00:10:08 +03:00
m_layoutGroup . writeEntry ( " disableBordersForMaximizedWindows " , m_disableBordersForMaximizedWindows ) ;
2017-07-24 17:47:53 +03:00
m_layoutGroup . writeEntry ( " launchers " , m_launchers ) ;
2018-02-15 22:28:27 +03:00
m_layoutGroup . writeEntry ( " background " , m_background ) ;
2017-07-17 18:31:43 +03:00
m_layoutGroup . writeEntry ( " activities " , m_activities ) ;
2018-01-30 15:33:00 +03:00
m_layoutGroup . writeEntry ( " lastUsedActivity " , m_lastUsedActivity ) ;
2018-02-15 22:28:27 +03:00
m_layoutGroup . writeEntry ( " textColor " , m_textColor ) ;
2017-07-24 18:27:53 +03:00
m_layoutGroup . sync ( ) ;
2017-07-02 20:19:18 +03:00
}
2018-01-07 20:59:18 +03:00
//! Containments Actions
2018-01-10 20:48:23 +03:00
void Layout : : addContainment ( Plasma : : Containment * containment )
{
2018-01-13 20:27:32 +03:00
if ( ! containment | | m_containments . contains ( containment ) ) {
2018-01-10 20:48:23 +03:00
return ;
}
2018-01-13 13:00:47 +03:00
bool containmentInLayout { false } ;
if ( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Dock : : SingleLayout ) {
m_containments . append ( containment ) ;
containmentInLayout = true ;
} else if ( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Dock : : MultipleLayouts ) {
QString layoutId = containment - > config ( ) . readEntry ( " layoutId " , QString ( ) ) ;
if ( ! layoutId . isEmpty ( ) & & ( layoutId = = m_layoutName ) ) {
m_containments . append ( containment ) ;
containmentInLayout = true ;
}
}
if ( containmentInLayout ) {
2018-08-02 12:58:54 +03:00
if ( ! blockAutomaticDockViewCreation ( ) ) {
addDock ( containment ) ;
} else {
qDebug ( ) < < " delaying DockView creation for containment :: " < < containment - > id ( ) ;
}
2018-01-13 13:00:47 +03:00
connect ( containment , & QObject : : destroyed , this , & Layout : : containmentDestroyed ) ;
}
2018-01-10 20:48:23 +03:00
}
2018-01-08 20:21:34 +03:00
QHash < const Plasma : : Containment * , DockView * > * Layout : : dockViews ( )
{
return & m_dockViews ;
}
2018-01-21 21:17:58 +03:00
QList < Plasma : : Containment * > * Layout : : containments ( )
{
return & m_containments ;
}
2018-01-13 13:55:13 +03:00
const QStringList Layout : : appliedActivities ( )
{
if ( ! m_corona ) {
return { } ;
}
if ( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Dock : : SingleLayout ) {
return { " 0 " } ;
} else if ( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Dock : : MultipleLayouts ) {
if ( m_activities . isEmpty ( ) ) {
return m_corona - > layoutManager ( ) - > orphanedActivities ( ) ;
} else {
return m_activities ;
}
2018-05-30 22:18:19 +03:00
} else {
return { " 0 " } ;
2018-01-13 13:55:13 +03:00
}
}
2018-01-30 15:33:00 +03:00
QString Layout : : lastUsedActivity ( )
2018-01-21 14:52:33 +03:00
{
2018-01-30 15:33:00 +03:00
return m_lastUsedActivity ;
}
void Layout : : clearLastUsedActivity ( )
{
m_lastUsedActivity = " " ;
emit lastUsedActivityChanged ( ) ;
2018-01-21 14:52:33 +03:00
}
void Layout : : updateLastUsedActivity ( )
{
if ( ! m_corona ) {
return ;
}
2018-01-30 15:33:00 +03:00
if ( ! m_lastUsedActivity . isEmpty ( ) & & ! m_corona - > layoutManager ( ) - > activities ( ) . contains ( m_lastUsedActivity ) ) {
clearLastUsedActivity ( ) ;
}
2018-01-21 14:52:33 +03:00
QString currentId = m_corona - > activitiesConsumer ( ) - > currentActivity ( ) ;
2018-03-08 18:37:02 +03:00
QStringList appliedActivitiesIds = appliedActivities ( ) ;
if ( m_lastUsedActivity ! = currentId
& & ( appliedActivitiesIds . contains ( currentId )
| | m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Dock : : SingleLayout ) ) {
2018-01-30 15:33:00 +03:00
m_lastUsedActivity = currentId ;
emit lastUsedActivityChanged ( ) ;
2018-01-21 14:52:33 +03:00
}
}
2018-01-08 20:21:34 +03:00
void Layout : : destroyedChanged ( bool destroyed )
{
if ( ! m_corona ) {
return ;
}
qDebug ( ) < < " dock containment destroyed changed!!!! " ;
Plasma : : Containment * sender = qobject_cast < Plasma : : Containment * > ( QObject : : sender ( ) ) ;
if ( ! sender ) {
return ;
}
if ( destroyed ) {
m_waitingDockViews [ sender ] = m_dockViews . take ( static_cast < Plasma : : Containment * > ( sender ) ) ;
} else {
m_dockViews [ sender ] = m_waitingDockViews . take ( static_cast < Plasma : : Containment * > ( sender ) ) ;
}
2018-12-01 18:29:17 +03:00
emit viewsCountChanged ( ) ;
2018-01-08 20:21:34 +03:00
emit m_corona - > availableScreenRectChanged ( ) ;
emit m_corona - > availableScreenRegionChanged ( ) ;
}
2018-01-10 20:48:23 +03:00
void Layout : : containmentDestroyed ( QObject * cont )
2018-01-08 20:21:34 +03:00
{
if ( ! m_corona ) {
return ;
}
2018-01-10 20:48:23 +03:00
Plasma : : Containment * containment = static_cast < Plasma : : Containment * > ( cont ) ;
2018-01-08 20:21:34 +03:00
2018-01-10 20:48:23 +03:00
if ( containment ) {
int containmentIndex = m_containments . indexOf ( containment ) ;
2018-01-08 20:21:34 +03:00
2018-01-10 20:48:23 +03:00
if ( containmentIndex > = 0 ) {
m_containments . removeAt ( containmentIndex ) ;
}
2018-01-08 20:21:34 +03:00
2018-01-10 20:48:23 +03:00
qDebug ( ) < < " Layout " < < name ( ) < < " :: containment destroyed!!!! " ;
auto view = m_dockViews . take ( containment ) ;
if ( ! view ) {
view = m_waitingDockViews . take ( containment ) ;
}
if ( view ) {
2018-01-20 01:25:00 +03:00
view - > disconnectSensitiveSignals ( ) ;
2018-12-01 18:29:17 +03:00
2018-01-10 20:48:23 +03:00
view - > deleteLater ( ) ;
2018-12-01 18:29:17 +03:00
emit viewsCountChanged ( ) ;
2018-01-10 20:48:23 +03:00
emit m_corona - > availableScreenRectChanged ( ) ;
emit m_corona - > availableScreenRegionChanged ( ) ;
2018-12-01 10:19:25 +03:00
emit viewColorizerChanged ( ) ;
2018-01-10 20:48:23 +03:00
}
}
2018-01-08 20:21:34 +03:00
}
2018-08-02 12:58:54 +03:00
void Layout : : addDock ( Plasma : : Containment * containment , bool forceOnPrimary , int expDockScreen )
2018-01-08 20:21:34 +03:00
{
2018-01-13 20:27:32 +03:00
qDebug ( ) < < " Layout :::: " < < m_layoutName < < " ::: addDock was called... m_containments :: " < < m_containments . size ( ) ;
2018-01-08 20:21:34 +03:00
if ( ! containment | | ! m_corona | | ! containment - > kPackage ( ) . isValid ( ) ) {
qWarning ( ) < < " the requested containment plugin can not be located or loaded " ;
return ;
}
2018-01-13 20:27:32 +03:00
qDebug ( ) < < " step 1... " ;
2018-08-24 01:27:14 +03:00
if ( ! isLatteContainment ( containment ) )
2018-01-08 20:21:34 +03:00
return ;
2018-01-13 20:27:32 +03:00
qDebug ( ) < < " step 2... " ;
2018-01-08 20:21:34 +03:00
for ( auto * dock : m_dockViews ) {
if ( dock - > containment ( ) = = containment )
return ;
}
2018-01-13 20:27:32 +03:00
qDebug ( ) < < " step 3... " ;
2018-01-08 20:21:34 +03:00
QScreen * nextScreen { qGuiApp - > primaryScreen ( ) } ;
bool onPrimary = containment - > config ( ) . readEntry ( " onPrimary " , true ) ;
int id = containment - > screen ( ) ;
if ( id = = - 1 & & expDockScreen = = - 1 ) {
id = containment - > lastScreen ( ) ;
}
if ( expDockScreen > - 1 ) {
id = expDockScreen ;
}
2018-08-02 12:58:54 +03:00
qDebug ( ) < < " add dock - containment id: " < < containment - > id ( ) < < " ,screen : " < < id < < " - " < < m_corona - > screenPool ( ) - > connector ( id )
< < " ,onprimary: " < < onPrimary < < " - " < < qGuiApp - > primaryScreen ( ) - > name ( ) < < " ,forceOnPrimary: " < < forceOnPrimary ;
2018-01-08 20:21:34 +03:00
2018-08-02 12:58:54 +03:00
if ( id > = 0 & & ! onPrimary & & ! forceOnPrimary ) {
2018-01-08 20:21:34 +03:00
QString connector = m_corona - > screenPool ( ) - > connector ( id ) ;
qDebug ( ) < < " add dock - connector : " < < connector ;
bool found { false } ;
foreach ( auto scr , qGuiApp - > screens ( ) ) {
if ( scr & & scr - > name ( ) = = connector ) {
found = true ;
nextScreen = scr ;
break ;
}
}
if ( ! found ) {
2018-07-24 22:25:19 +03:00
qDebug ( ) < < " reject : adding explicit dock, screen not available ! : " < < connector ;
2018-01-08 20:21:34 +03:00
return ;
}
2018-07-24 22:25:19 +03:00
2018-10-07 22:04:17 +03:00
//! explicit dock can not be added at explicit screen when that screen is the same with
//! primary screen and that edge is already occupied by a primary dock
if ( nextScreen = = qGuiApp - > primaryScreen ( ) & & primaryDockOccupyEdge ( containment - > location ( ) ) ) {
2018-07-24 22:25:19 +03:00
qDebug ( ) < < " reject : adding explicit dock, primary dock occupies edge at screen ! : " < < connector ;
2018-09-04 19:38:54 +03:00
return ;
2018-07-24 22:25:19 +03:00
}
}
if ( id > = 0 & & onPrimary ) {
QString connector = m_corona - > screenPool ( ) - > connector ( id ) ;
qDebug ( ) < < " add dock - connector : " < < connector ;
foreach ( auto view , m_dockViews ) {
auto testContainment = view - > containment ( ) ;
int testScreenId = testContainment - > screen ( ) ;
if ( testScreenId = = - 1 ) {
testScreenId = testContainment - > lastScreen ( ) ;
}
bool testOnPrimary = testContainment - > config ( ) . readEntry ( " onPrimary " , true ) ;
Plasma : : Types : : Location testLocation = static_cast < Plasma : : Types : : Location > ( ( int ) testContainment - > config ( ) . readEntry ( " location " , ( int ) Plasma : : Types : : BottomEdge ) ) ;
if ( ! testOnPrimary & & m_corona - > screenPool ( ) - > primaryScreenId ( ) = = testScreenId & & testLocation = = containment - > location ( ) ) {
qDebug ( ) < < " Rejected explicit dockView and removing it in order add an onPrimary with higher priority at screen: " < < connector ;
auto viewToDelete = m_dockViews . take ( testContainment ) ;
viewToDelete - > disconnectSensitiveSignals ( ) ;
viewToDelete - > deleteLater ( ) ;
}
}
}
/* old behavior to not add primary docks on explicit one
else if ( onPrimary ) {
2018-01-31 21:25:56 +03:00
if ( explicitDockOccupyEdge ( m_corona - > screenPool ( ) - > primaryScreenId ( ) , containment - > location ( ) ) ) {
2018-01-13 20:27:32 +03:00
qDebug ( ) < < " CORONA ::: adding dock rejected, the edge is occupied by explicit dock ! : " < < containment - > location ( ) ;
2018-01-08 20:21:34 +03:00
//we must check that an onPrimary dock should never catch up the same edge on
//the same screen with an explicit dock
return ;
}
2018-07-24 22:25:19 +03:00
} */
2018-01-08 20:21:34 +03:00
qDebug ( ) < < " Adding dock for container... " ;
qDebug ( ) < < " onPrimary: " < < onPrimary < < " screen!!! : " < < nextScreen - > name ( ) ;
//! it is used to set the correct flag during the creation
//! of the window... This of course is also used during
//! recreations of the window between different visibility modes
auto mode = static_cast < Dock : : Visibility > ( containment - > config ( ) . readEntry ( " visibility " , static_cast < int > ( Dock : : DodgeActive ) ) ) ;
bool dockWin { true } ;
if ( mode = = Dock : : AlwaysVisible | | mode = = Dock : : WindowsGoBelow ) {
dockWin = true ;
} else {
dockWin = containment - > config ( ) . readEntry ( " dockWindowBehavior " , true ) ;
}
auto dockView = new DockView ( m_corona , nextScreen , dockWin ) ;
2018-03-06 23:54:37 +03:00
2018-01-08 20:21:34 +03:00
dockView - > init ( ) ;
dockView - > setContainment ( containment ) ;
2018-01-10 23:55:19 +03:00
dockView - > setManagedLayout ( this ) ;
2018-01-08 20:21:34 +03:00
//! force this special dock case to become primary
//! even though it isnt
2018-08-02 12:58:54 +03:00
if ( forceOnPrimary ) {
2018-09-04 19:38:54 +03:00
qDebug ( ) < < " Enforcing onPrimary:true as requested for DockView... " ;
2018-01-08 20:21:34 +03:00
dockView - > setOnPrimary ( true ) ;
}
2018-01-10 20:48:23 +03:00
// connect(containment, &QObject::destroyed, this, &Layout::containmentDestroyed);
2018-01-08 20:21:34 +03:00
connect ( containment , & Plasma : : Applet : : destroyedChanged , this , & Layout : : destroyedChanged ) ;
connect ( containment , & Plasma : : Applet : : locationChanged , m_corona , & DockCorona : : dockLocationChanged ) ;
connect ( containment , & Plasma : : Containment : : appletAlternativesRequested
, m_corona , & DockCorona : : showAlternativesForApplet , Qt : : QueuedConnection ) ;
2018-01-13 20:27:32 +03:00
if ( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Dock : : MultipleLayouts ) {
connect ( containment , & Plasma : : Containment : : appletCreated , this , & Layout : : appletCreated ) ;
}
2018-12-01 10:19:25 +03:00
connect ( dockView - > effects ( ) , & View : : Effects : : colorizerEnabledChanged , this , & Layout : : viewColorizerChanged ) ;
2018-03-06 23:54:37 +03:00
2018-01-08 20:21:34 +03:00
//! Qt 5.9 creates a crash for this in wayland, that is why the check is used
//! but on the other hand we need this for copy to work correctly and show
//! the copied dock under X11
//if (!KWindowSystem::isPlatformWayland()) {
dockView - > show ( ) ;
//}
m_dockViews [ containment ] = dockView ;
2018-12-01 10:19:25 +03:00
emit viewColorizerChanged ( ) ;
2018-12-01 18:29:17 +03:00
emit viewsCountChanged ( ) ;
2018-01-08 20:21:34 +03:00
}
2018-01-07 20:59:18 +03:00
void Layout : : copyDock ( Plasma : : Containment * containment )
{
if ( ! containment | | ! m_corona )
return ;
qDebug ( ) < < " copying containment layout " ;
//! Settting mutable for create a containment
m_corona - > setImmutability ( Plasma : : Types : : Mutable ) ;
QString temp1File = QDir : : homePath ( ) + " /.config/lattedock.copy1.bak " ;
//! WE NEED A WAY TO COPY A CONTAINMENT!!!!
QFile copyFile ( temp1File ) ;
if ( copyFile . exists ( ) )
copyFile . remove ( ) ;
2018-01-14 22:43:54 +03:00
KSharedConfigPtr newFile = KSharedConfig : : openConfig ( temp1File ) ;
2018-01-07 20:59:18 +03:00
KConfigGroup copied_conts = KConfigGroup ( newFile , " Containments " ) ;
KConfigGroup copied_c1 = KConfigGroup ( & copied_conts , QString : : number ( containment - > id ( ) ) ) ;
KConfigGroup copied_systray ;
2018-01-13 04:08:32 +03:00
// toCopyContainmentIds << QString::number(containment->id());
// toCopyAppletIds << containment->config().group("Applets").groupList();
2018-01-07 20:59:18 +03:00
containment - > config ( ) . copyTo ( & copied_c1 ) ;
//!investigate if there is a systray in the containment to copy also
int systrayId = - 1 ;
QString systrayAppletId ;
auto applets = containment - > config ( ) . group ( " Applets " ) ;
foreach ( auto applet , applets . groupList ( ) ) {
KConfigGroup appletSettings = applets . group ( applet ) . group ( " Configuration " ) ;
2018-01-14 18:30:29 +03:00
int tSysId = appletSettings . readEntry ( " SystrayContainmentId " , - 1 ) ;
2018-01-07 20:59:18 +03:00
if ( tSysId ! = - 1 ) {
systrayId = tSysId ;
systrayAppletId = applet ;
2018-01-13 04:08:32 +03:00
qDebug ( ) < < " systray was found in the containment... ::: " < < tSysId ;
2018-01-07 20:59:18 +03:00
break ;
}
}
if ( systrayId ! = - 1 ) {
Plasma : : Containment * systray { nullptr } ;
foreach ( auto containment , m_corona - > containments ( ) ) {
if ( containment - > id ( ) = = systrayId ) {
systray = containment ;
break ;
}
}
if ( systray ) {
copied_systray = KConfigGroup ( & copied_conts , QString : : number ( systray - > id ( ) ) ) ;
2018-01-13 04:08:32 +03:00
// toCopyContainmentIds << QString::number(systray->id());
// toCopyAppletIds << systray->config().group("Applets").groupList();
2018-01-07 20:59:18 +03:00
systray - > config ( ) . copyTo ( & copied_systray ) ;
}
}
//! end of systray specific code
2018-01-13 04:08:32 +03:00
//! update ids to unique ones
QString temp2File = newUniqueIdsLayoutFromFile ( temp1File ) ;
2018-01-07 20:59:18 +03:00
2018-08-30 08:47:53 +03:00
//! Don't create DockView when the containment is created because we must update
2018-08-02 12:58:54 +03:00
//! its screen settings first
setBlockAutomaticDockViewCreation ( true ) ;
2018-01-07 20:59:18 +03:00
//! Finally import the configuration
2018-01-13 04:08:32 +03:00
QList < Plasma : : Containment * > importedDocks = importLayoutFile ( temp2File ) ;
2018-01-07 20:59:18 +03:00
Plasma : : Containment * newContainment { nullptr } ;
2018-01-13 04:08:32 +03:00
if ( importedDocks . size ( ) = = 1 ) {
newContainment = importedDocks [ 0 ] ;
2018-01-07 20:59:18 +03:00
}
if ( ! newContainment | | ! newContainment - > kPackage ( ) . isValid ( ) ) {
qWarning ( ) < < " the requested containment plugin can not be located or loaded " ;
return ;
}
auto config = newContainment - > config ( ) ;
//in multi-screen environment the copied dock is moved to alternative screens first
const auto screens = qGuiApp - > screens ( ) ;
2018-01-08 20:21:34 +03:00
auto dock = m_dockViews [ containment ] ;
2018-01-07 20:59:18 +03:00
bool setOnExplicitScreen = false ;
int dockScrId = - 1 ;
int copyScrId = - 1 ;
if ( dock ) {
2018-12-01 18:11:29 +03:00
dockScrId = dock - > positioner ( ) - > currentScreenId ( ) ;
2018-01-07 20:59:18 +03:00
qDebug ( ) < < " COPY DOCK SCREEN ::: " < < dockScrId ;
if ( dockScrId ! = - 1 & & screens . count ( ) > 1 ) {
foreach ( auto scr , screens ) {
copyScrId = m_corona - > screenPool ( ) - > id ( scr - > name ( ) ) ;
//the screen must exist and not be the same with the original dock
if ( copyScrId > - 1 & & copyScrId ! = dockScrId ) {
2018-01-31 19:45:15 +03:00
QList < Plasma : : Types : : Location > fEdges = freeEdges ( copyScrId ) ;
2018-01-07 20:59:18 +03:00
if ( fEdges . contains ( ( Plasma : : Types : : Location ) containment - > location ( ) ) ) {
///set this containment to an explicit screen
config . writeEntry ( " onPrimary " , false ) ;
config . writeEntry ( " lastScreen " , copyScrId ) ;
newContainment - > setLocation ( containment - > location ( ) ) ;
qDebug ( ) < < " COPY DOCK SCREEN NEW SCREEN ::: " < < copyScrId ;
setOnExplicitScreen = true ;
break ;
}
}
}
}
}
if ( ! setOnExplicitScreen ) {
2018-01-31 19:45:15 +03:00
QList < Plasma : : Types : : Location > edges = freeEdges ( newContainment - > screen ( ) ) ;
2018-01-07 20:59:18 +03:00
if ( edges . count ( ) > 0 ) {
newContainment - > setLocation ( edges . at ( 0 ) ) ;
} else {
newContainment - > setLocation ( Plasma : : Types : : BottomEdge ) ;
}
config . writeEntry ( " onPrimary " , false ) ;
config . writeEntry ( " lastScreen " , dockScrId ) ;
}
newContainment - > config ( ) . sync ( ) ;
if ( setOnExplicitScreen & & copyScrId > - 1 ) {
qDebug ( ) < < " Copy Dock in explicit screen ::: " < < copyScrId ;
2018-08-02 12:58:54 +03:00
addDock ( newContainment , false , copyScrId ) ;
2018-01-07 20:59:18 +03:00
newContainment - > reactToScreenChange ( ) ;
} else {
qDebug ( ) < < " Copy Dock in current screen... " ;
2018-08-02 12:58:54 +03:00
addDock ( newContainment , false , dockScrId ) ;
2018-01-07 20:59:18 +03:00
}
2018-08-02 12:58:54 +03:00
setBlockAutomaticDockViewCreation ( false ) ;
2018-01-07 20:59:18 +03:00
}
2018-01-13 20:27:32 +03:00
void Layout : : appletCreated ( Plasma : : Applet * applet )
{
//! In Multiple Layout the orphaned systrays must be assigned to layouts
//! when the user adds them
KConfigGroup appletSettings = applet - > containment ( ) - > config ( ) . group ( " Applets " ) . group ( QString : : number ( applet - > id ( ) ) ) . group ( " Configuration " ) ;
2018-01-14 18:30:29 +03:00
int systrayId = appletSettings . readEntry ( " SystrayContainmentId " , - 1 ) ;
2018-01-13 20:27:32 +03:00
2018-01-14 18:30:29 +03:00
if ( systrayId ! = - 1 ) {
uint sId = ( uint ) systrayId ;
2018-01-13 20:27:32 +03:00
foreach ( auto containment , m_corona - > containments ( ) ) {
if ( containment - > id ( ) = = sId ) {
containment - > config ( ) . writeEntry ( " layoutId " , m_layoutName ) ;
}
addContainment ( containment ) ;
}
}
}
void Layout : : importToCorona ( )
{
if ( ! m_corona ) {
return ;
}
//! Settting mutable for create a containment
m_corona - > setImmutability ( Plasma : : Types : : Mutable ) ;
2018-07-13 20:38:07 +03:00
QString temp1FilePath = QDir : : homePath ( ) + " /.config/lattedock.copy1.bak " ;
//! we need to copy first the layout file because the kde cache
//! may not have yet been updated (KSharedConfigPtr)
//! this way we make sure at the latest changes stored in the layout file
//! will be also available when changing to Myltiple Layouts
QString tempLayoutFilePath = QDir : : homePath ( ) + " /.config/lattedock.layout.bak " ;
2018-01-13 20:27:32 +03:00
//! WE NEED A WAY TO COPY A CONTAINMENT!!!!
2018-07-13 20:38:07 +03:00
QFile tempLayoutFile ( tempLayoutFilePath ) ;
QFile copyFile ( temp1FilePath ) ;
QFile layoutOriginalFile ( m_layoutFile ) ;
if ( tempLayoutFile . exists ( ) ) {
tempLayoutFile . remove ( ) ;
}
2018-01-13 20:27:32 +03:00
if ( copyFile . exists ( ) )
copyFile . remove ( ) ;
2018-07-13 20:38:07 +03:00
layoutOriginalFile . copy ( tempLayoutFilePath ) ;
KSharedConfigPtr filePtr = KSharedConfig : : openConfig ( tempLayoutFilePath ) ;
KSharedConfigPtr newFile = KSharedConfig : : openConfig ( temp1FilePath ) ;
2018-01-13 20:27:32 +03:00
KConfigGroup copyGroup = KConfigGroup ( newFile , " Containments " ) ;
2018-01-16 00:04:03 +03:00
KConfigGroup current_containments = KConfigGroup ( filePtr , " Containments " ) ;
2018-01-13 20:27:32 +03:00
current_containments . copyTo ( & copyGroup ) ;
copyGroup . sync ( ) ;
//! update ids to unique ones
2018-07-13 20:38:07 +03:00
QString temp2File = newUniqueIdsLayoutFromFile ( temp1FilePath ) ;
2018-01-13 20:27:32 +03:00
//! Finally import the configuration
importLayoutFile ( temp2File ) ;
}
2018-01-07 20:59:18 +03:00
QString Layout : : availableId ( QStringList all , QStringList assigned , int base )
{
bool found = false ;
int i = base ;
2018-01-13 04:08:32 +03:00
while ( ! found & & i < 32000 ) {
2018-01-07 20:59:18 +03:00
QString iStr = QString : : number ( i ) ;
if ( ! all . contains ( iStr ) & & ! assigned . contains ( iStr ) ) {
return iStr ;
}
i + + ;
}
return QString ( " " ) ;
}
2018-01-14 18:30:29 +03:00
QString Layout : : newUniqueIdsLayoutFromFile ( QString file )
2018-01-13 04:08:32 +03:00
{
if ( ! m_corona ) {
return QString ( ) ;
}
QString tempFile = QDir : : homePath ( ) + " /.config/lattedock.copy2.bak " ;
QFile copyFile ( tempFile ) ;
if ( copyFile . exists ( ) )
copyFile . remove ( ) ;
//! BEGIN updating the ids in the temp file
QStringList allIds ;
allIds < < m_corona - > containmentsIds ( ) ;
allIds < < m_corona - > appletsIds ( ) ;
QStringList toInvestigateContainmentIds ;
QStringList toInvestigateAppletIds ;
QStringList toInvestigateSystrayContIds ;
//! first is the systray containment id
QHash < QString , QString > systrayParentContainmentIds ;
QHash < QString , QString > systrayAppletIds ;
//qDebug() << "Ids:" << allIds;
//qDebug() << "to copy containments: " << toCopyContainmentIds;
//qDebug() << "to copy applets: " << toCopyAppletIds;
QStringList assignedIds ;
QHash < QString , QString > assigned ;
KSharedConfigPtr filePtr = KSharedConfig : : openConfig ( file ) ;
KConfigGroup investigate_conts = KConfigGroup ( filePtr , " Containments " ) ;
//KConfigGroup copied_c1 = KConfigGroup(&copied_conts, QString::number(containment->id()));
//! Record the containment and applet ids
foreach ( auto cId , investigate_conts . groupList ( ) ) {
toInvestigateContainmentIds < < cId ;
auto appletsEntries = investigate_conts . group ( cId ) . group ( " Applets " ) ;
toInvestigateAppletIds < < appletsEntries . groupList ( ) ;
//! investigate for systrays
foreach ( auto appletId , appletsEntries . groupList ( ) ) {
KConfigGroup appletSettings = appletsEntries . group ( appletId ) . group ( " Configuration " ) ;
2018-01-14 18:30:29 +03:00
int tSysId = appletSettings . readEntry ( " SystrayContainmentId " , - 1 ) ;
2018-01-13 04:08:32 +03:00
//! It is a systray !!!
2018-01-14 18:30:29 +03:00
if ( tSysId ! = - 1 ) {
QString tSysIdStr = QString : : number ( tSysId ) ;
toInvestigateSystrayContIds < < tSysIdStr ;
systrayParentContainmentIds [ tSysIdStr ] = cId ;
systrayAppletIds [ tSysIdStr ] = appletId ;
2018-01-13 04:08:32 +03:00
qDebug ( ) < < " systray was found in the containment... " ;
}
}
}
//! Reassign containment and applet ids to unique ones
foreach ( auto contId , toInvestigateContainmentIds ) {
2018-01-14 18:30:29 +03:00
QString newId = availableId ( allIds , assignedIds , 12 ) ;
2018-01-14 13:22:45 +03:00
2018-01-13 04:08:32 +03:00
assignedIds < < newId ;
assigned [ contId ] = newId ;
}
foreach ( auto appId , toInvestigateAppletIds ) {
2018-01-14 18:30:29 +03:00
QString newId = availableId ( allIds , assignedIds , 40 ) ;
2018-01-14 13:22:45 +03:00
2018-01-13 04:08:32 +03:00
assignedIds < < newId ;
assigned [ appId ] = newId ;
}
2018-01-14 18:30:29 +03:00
qDebug ( ) < < " ALL CORONA IDS ::: " < < allIds ;
qDebug ( ) < < " FULL ASSIGNMENTS ::: " < < assigned ;
foreach ( auto cId , toInvestigateContainmentIds ) {
QString value = assigned [ cId ] ;
if ( assigned . contains ( value ) ) {
QString value2 = assigned [ value ] ;
if ( cId ! = assigned [ cId ] & & ! value2 . isEmpty ( ) & & cId = = value2 ) {
qDebug ( ) < < " PROBLEM APPEARED !!!! FOR :::: " < < cId < < " .. fixed .. " ;
assigned [ cId ] = cId ;
assigned [ value ] = value ;
}
}
}
foreach ( auto aId , toInvestigateAppletIds ) {
QString value = assigned [ aId ] ;
if ( assigned . contains ( value ) ) {
QString value2 = assigned [ value ] ;
if ( aId ! = assigned [ aId ] & & ! value2 . isEmpty ( ) & & aId = = value2 ) {
qDebug ( ) < < " PROBLEM APPEARED !!!! FOR :::: " < < aId < < " .. fixed .. " ;
assigned [ aId ] = aId ;
assigned [ value ] = value ;
}
}
}
qDebug ( ) < < " FIXED FULL ASSIGNMENTS ::: " < < assigned ;
2018-01-13 04:08:32 +03:00
2018-01-13 13:00:47 +03:00
//! update applet ids in their contaiment order and in MultipleLayouts update also the layoutId
2018-01-13 04:08:32 +03:00
foreach ( auto cId , investigate_conts . groupList ( ) ) {
2018-01-16 00:26:10 +03:00
//! Update (appletOrder) and (lockedZoomApplets)
for ( int i = 1 ; i < = 2 ; + + i ) {
QString settingStr = ( i = = 1 ) ? " appletOrder " : " lockedZoomApplets " ;
QString order1 = investigate_conts . group ( cId ) . group ( " General " ) . readEntry ( settingStr , QString ( ) ) ;
2018-01-13 04:08:32 +03:00
2018-01-16 00:26:10 +03:00
if ( ! order1 . isEmpty ( ) ) {
QStringList order1Ids = order1 . split ( " ; " ) ;
QStringList fixedOrder1Ids ;
2018-01-13 04:08:32 +03:00
2018-01-16 00:26:10 +03:00
for ( int i = 0 ; i < order1Ids . count ( ) ; + + i ) {
fixedOrder1Ids . append ( assigned [ order1Ids [ i ] ] ) ;
}
2018-01-13 04:08:32 +03:00
2018-01-16 00:26:10 +03:00
QString fixedOrder1 = fixedOrder1Ids . join ( " ; " ) ;
investigate_conts . group ( cId ) . group ( " General " ) . writeEntry ( settingStr , fixedOrder1 ) ;
}
2018-01-13 04:08:32 +03:00
}
2018-01-13 13:00:47 +03:00
if ( m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Dock : : MultipleLayouts ) {
investigate_conts . group ( cId ) . writeEntry ( " layoutId " , m_layoutName ) ;
}
2018-01-13 04:08:32 +03:00
}
//! must update also the systray id in its applet
foreach ( auto systrayId , toInvestigateSystrayContIds ) {
KConfigGroup systrayParentContainment = investigate_conts . group ( systrayParentContainmentIds [ systrayId ] ) ;
systrayParentContainment . group ( " Applets " ) . group ( systrayAppletIds [ systrayId ] ) . group ( " Configuration " ) . writeEntry ( " SystrayContainmentId " , assigned [ systrayId ] ) ;
systrayParentContainment . sync ( ) ;
}
investigate_conts . sync ( ) ;
2018-01-14 22:43:54 +03:00
//! Copy To Temp 2 File And Update Correctly The Ids
KSharedConfigPtr file2Ptr = KSharedConfig : : openConfig ( tempFile ) ;
KConfigGroup fixedNewContainmets = KConfigGroup ( file2Ptr , " Containments " ) ;
2018-01-13 04:08:32 +03:00
2018-01-14 22:43:54 +03:00
foreach ( auto contId , investigate_conts . groupList ( ) ) {
2018-02-08 18:49:27 +03:00
QString pluginId = investigate_conts . group ( contId ) . readEntry ( " plugin " , " " ) ;
2018-01-13 04:08:32 +03:00
2018-08-30 08:47:53 +03:00
if ( pluginId ! = " org.kde.desktopcontainment " ) { //!don't add ghost containments
2018-02-08 18:49:27 +03:00
KConfigGroup newContainmentGroup = fixedNewContainmets . group ( assigned [ contId ] ) ;
investigate_conts . group ( contId ) . copyTo ( & newContainmentGroup ) ;
2018-01-13 04:08:32 +03:00
2018-02-08 18:49:27 +03:00
newContainmentGroup . group ( " Applets " ) . deleteGroup ( ) ;
foreach ( auto appId , investigate_conts . group ( contId ) . group ( " Applets " ) . groupList ( ) ) {
KConfigGroup appletGroup = investigate_conts . group ( contId ) . group ( " Applets " ) . group ( appId ) ;
KConfigGroup newAppletGroup = fixedNewContainmets . group ( assigned [ contId ] ) . group ( " Applets " ) . group ( assigned [ appId ] ) ;
appletGroup . copyTo ( & newAppletGroup ) ;
}
2018-01-14 13:48:43 +03:00
}
2018-01-13 04:08:32 +03:00
}
2018-01-14 22:43:54 +03:00
fixedNewContainmets . sync ( ) ;
2018-01-13 04:08:32 +03:00
return tempFile ;
}
QList < Plasma : : Containment * > Layout : : importLayoutFile ( QString file )
{
KSharedConfigPtr filePtr = KSharedConfig : : openConfig ( file ) ;
2018-01-13 13:00:47 +03:00
auto newContainments = m_corona - > importLayout ( KConfigGroup ( filePtr , " " ) ) ;
2018-01-13 04:08:32 +03:00
///Find latte and systray containments
2018-01-13 13:00:47 +03:00
qDebug ( ) < < " imported containments ::: " < < newContainments . length ( ) ;
2018-01-13 04:08:32 +03:00
QList < Plasma : : Containment * > importedDocks ;
//QList<Plasma::Containment *> systrays;
2018-01-13 13:00:47 +03:00
foreach ( auto containment , newContainments ) {
2018-08-24 01:27:14 +03:00
if ( isLatteContainment ( containment ) ) {
2018-01-13 04:08:32 +03:00
qDebug ( ) < < " new latte containment id: " < < containment - > id ( ) ;
importedDocks < < containment ;
}
}
///after systrays were found we must update in latte the relevant ids
/*if (!systrays.isEmpty()) {
foreach ( auto systray , systrays ) {
qDebug ( ) < < " systray found with id : " < < systray - > id ( ) ;
Plasma : : Applet * parentApplet = qobject_cast < Plasma : : Applet * > ( systray - > parent ( ) ) ;
if ( parentApplet ) {
KConfigGroup appletSettings = parentApplet - > config ( ) . group ( " Configuration " ) ;
if ( appletSettings . hasKey ( " SystrayContainmentId " ) ) {
qDebug ( ) < < " !!! updating systray id to : " < < systray - > id ( ) ;
appletSettings . writeEntry ( " SystrayContainmentId " , systray - > id ( ) ) ;
}
}
}
} */
return importedDocks ;
}
2018-01-08 20:21:34 +03:00
void Layout : : recreateDock ( Plasma : : Containment * containment )
{
if ( ! m_corona ) {
return ;
}
//! give the time to config window to close itself first and then recreate the dock
//! step:1 remove the dockview
QTimer : : singleShot ( 350 , [ this , containment ] ( ) {
auto view = m_dockViews . take ( containment ) ;
if ( view ) {
qDebug ( ) < < " recreate - step 1: removing dock for containment: " < < containment - > id ( ) ;
//! step:2 add the new dockview
connect ( view , & QObject : : destroyed , this , [ this , containment ] ( ) {
QTimer : : singleShot ( 250 , this , [ this , containment ] ( ) {
if ( ! m_dockViews . contains ( containment ) ) {
qDebug ( ) < < " recreate - step 2: adding dock for containment: " < < containment - > id ( ) ;
addDock ( containment ) ;
}
} ) ;
} ) ;
view - > deleteLater ( ) ;
}
} ) ;
}
//! the central functions that updates loading/unloading dockviews
//! concerning screen changed (for multi-screen setups mainly)
void Layout : : syncDockViewsToScreens ( )
{
if ( ! m_corona ) {
return ;
}
2018-07-24 22:25:19 +03:00
qDebug ( ) < < " start of, syncDockViewsToScreens .... " ;
2018-01-31 19:45:15 +03:00
qDebug ( ) < < " LAYOUT ::: " < < name ( ) ;
2018-01-08 20:21:34 +03:00
qDebug ( ) < < " screen count changed -+-+ " < < qGuiApp - > screens ( ) . size ( ) ;
2018-07-24 22:25:19 +03:00
QHash < QString , QList < Plasma : : Types : : Location > > futureDocksLocations ;
QList < uint > futureShownViews ;
QString prmScreenName = qGuiApp - > primaryScreen ( ) - > name ( ) ;
2018-01-08 20:21:34 +03:00
2018-07-24 22:25:19 +03:00
//! first step: primary docks must be placed in primary screen free edges
foreach ( auto containment , m_containments ) {
2018-08-24 01:27:14 +03:00
if ( isLatteContainment ( containment ) ) {
int screenId = containment - > screen ( ) ;
2018-01-08 20:21:34 +03:00
2018-08-24 01:27:14 +03:00
if ( screenId = = - 1 ) {
screenId = containment - > lastScreen ( ) ;
}
2018-01-08 20:21:34 +03:00
2018-08-24 01:27:14 +03:00
bool onPrimary = containment - > config ( ) . readEntry ( " onPrimary " , true ) ;
Plasma : : Types : : Location location = static_cast < Plasma : : Types : : Location > ( ( int ) containment - > config ( ) . readEntry ( " location " , ( int ) Plasma : : Types : : BottomEdge ) ) ;
2018-01-08 20:21:34 +03:00
2018-08-24 01:27:14 +03:00
if ( onPrimary & & ! futureDocksLocations [ prmScreenName ] . contains ( location ) ) {
futureDocksLocations [ prmScreenName ] . append ( location ) ;
futureShownViews . append ( containment - > id ( ) ) ;
}
2018-01-08 20:21:34 +03:00
}
}
2018-07-24 22:25:19 +03:00
//! second step: explicit docks must be placed in their screens if the screen edge is free
foreach ( auto containment , m_containments ) {
2018-08-24 01:27:14 +03:00
if ( isLatteContainment ( containment ) ) {
int screenId = containment - > screen ( ) ;
2018-01-08 20:21:34 +03:00
2018-08-24 01:27:14 +03:00
if ( screenId = = - 1 ) {
screenId = containment - > lastScreen ( ) ;
}
2018-01-08 20:21:34 +03:00
2018-08-24 01:27:14 +03:00
bool onPrimary = containment - > config ( ) . readEntry ( " onPrimary " , true ) ;
Plasma : : Types : : Location location = static_cast < Plasma : : Types : : Location > ( ( int ) containment - > config ( ) . readEntry ( " location " , ( int ) Plasma : : Types : : BottomEdge ) ) ;
2018-01-08 20:21:34 +03:00
2018-08-24 01:27:14 +03:00
if ( ! onPrimary ) {
QString expScreenName = m_corona - > screenPool ( ) - > connector ( screenId ) ;
2018-07-24 22:25:19 +03:00
2018-08-24 01:27:14 +03:00
if ( m_corona - > screenPool ( ) - > screenExists ( screenId ) & & ! futureDocksLocations [ expScreenName ] . contains ( location ) ) {
futureDocksLocations [ expScreenName ] . append ( location ) ;
futureShownViews . append ( containment - > id ( ) ) ;
}
2018-01-08 20:21:34 +03:00
}
}
2018-07-24 22:25:19 +03:00
}
qDebug ( ) < < " PRIMARY SCREEN :: " < < prmScreenName ;
qDebug ( ) < < " DOCKVIEWS MUST BE PRESENT AT :: " < < futureDocksLocations ;
2018-08-24 01:27:14 +03:00
qDebug ( ) < < " FUTURESHOWNVIEWS MUST BE :: " < < futureShownViews ;
2018-01-08 20:21:34 +03:00
2018-07-24 22:25:19 +03:00
//! add views
foreach ( auto containment , m_containments ) {
int screenId = containment - > screen ( ) ;
if ( screenId = = - 1 ) {
screenId = containment - > lastScreen ( ) ;
2018-01-08 20:21:34 +03:00
}
2018-07-24 22:25:19 +03:00
if ( ! dockViewExists ( containment ) & & futureShownViews . contains ( containment - > id ( ) ) ) {
2018-08-24 01:27:14 +03:00
qDebug ( ) < < " syncDockViewsToScreens: view must be added... for containment: " < < containment - > id ( ) < < " at screen: " < < m_corona - > screenPool ( ) - > connector ( screenId ) ;
2018-07-24 22:25:19 +03:00
addDock ( containment ) ;
2018-01-08 20:21:34 +03:00
}
}
2018-07-24 22:25:19 +03:00
//! remove views
2018-01-08 20:21:34 +03:00
foreach ( auto view , m_dockViews ) {
2018-07-24 22:25:19 +03:00
if ( view - > containment ( ) & & ! futureShownViews . contains ( view - > containment ( ) - > id ( ) ) ) {
2018-12-01 16:22:33 +03:00
qDebug ( ) < < " syncDockViewsToScreens: view must be deleted... for containment: " < < view - > containment ( ) - > id ( ) < < " at screen: " < < view - > positioner ( ) - > currentScreenName ( ) ;
2018-07-24 22:25:19 +03:00
auto viewToDelete = m_dockViews . take ( view - > containment ( ) ) ;
viewToDelete - > disconnectSensitiveSignals ( ) ;
viewToDelete - > deleteLater ( ) ;
}
}
//! reconsider views
foreach ( auto view , m_dockViews ) {
if ( view - > containment ( ) & & futureShownViews . contains ( view - > containment ( ) - > id ( ) ) ) {
//! if the dock will not be deleted its a very good point to reconsider
//! if the screen in which is running is the correct one
view - > reconsiderScreen ( ) ;
}
}
/*
qDebug ( ) < < " adding consideration.... " ;
qDebug ( ) < < " dock view running : " < < m_dockViews . count ( ) ;
2018-01-08 20:21:34 +03:00
foreach ( auto scr , qGuiApp - > screens ( ) ) {
2018-07-24 22:25:19 +03:00
qDebug ( ) < < " Found screen: " < < scr - > name ( ) ;
foreach ( auto cont , m_containments ) {
int id = cont - > screen ( ) ;
if ( id = = - 1 ) {
id = cont - > lastScreen ( ) ;
}
bool onPrimary = cont - > config ( ) . readEntry ( " onPrimary " , true ) ;
Plasma : : Types : : Location location = static_cast < Plasma : : Types : : Location > ( ( int ) cont - > config ( ) . readEntry ( " location " , ( int ) Plasma : : Types : : BottomEdge ) ) ;
//! two main situations that a dock must be added when it is not already running
//! 1. when a dock is primary, not running and the edge for which is associated is free
//! 2. when a dock in explicit, not running and the associated screen currently exists
//! e.g. the screen has just been added
if ( ( ( onPrimary & & freeEdges ( qGuiApp - > primaryScreen ( ) ) . contains ( location ) ) | | ( ! onPrimary & & ( m_corona - > screenPool ( ) - > connector ( id ) = = scr - > name ( ) ) ) )
& & ( ! m_dockViews . contains ( cont ) ) ) {
qDebug ( ) < < " screen Count signal: view must be added... for: " < < scr - > name ( ) ;
addDock ( cont ) ;
}
2018-01-08 20:21:34 +03:00
}
}
2018-07-24 22:25:19 +03:00
qDebug ( ) < < " removing consideration & updating screen for always on primary docks.... " ;
2018-01-08 20:21:34 +03:00
2018-07-24 22:25:19 +03:00
//! this code tries to find a containment that must not be deleted by
//! automatic algorithm. Currently the containment with the minimum id
//! containing tasks plasmoid wins
int preserveContainmentId { - 1 } ;
bool dockWithTasksWillBeShown { false } ;
//! associate correct values for preserveContainmentId and
//! dockWithTasksWillBeShown
foreach ( auto view , m_dockViews ) {
bool found { false } ;
foreach ( auto scr , qGuiApp - > screens ( ) ) {
if ( scr - > name ( ) = = view - > currentScreen ( )
| | ( view - > onPrimary ( ) & & scr = = qGuiApp - > primaryScreen ( ) ) ) {
found = true ;
break ;
}
2018-01-08 20:21:34 +03:00
}
2018-07-24 22:25:19 +03:00
//!check if a tasks dock will be shown (try to prevent its deletion)
if ( found & & view - > tasksPresent ( ) ) {
dockWithTasksWillBeShown = true ;
}
if ( ! found & & ! view - > onPrimary ( ) & & ( m_dockViews . size ( ) > 1 ) & & m_dockViews . contains ( view - > containment ( ) )
& & ! ( view - > tasksPresent ( ) & & noDocksWithTasks ( ) = = 1 ) ) { //do not delete last dock containing tasks
if ( view - > tasksPresent ( ) ) {
if ( preserveContainmentId = = - 1 )
preserveContainmentId = view - > containment ( ) - > id ( ) ;
else if ( view - > containment ( ) - > id ( ) < preserveContainmentId )
preserveContainmentId = view - > containment ( ) - > id ( ) ;
}
}
2018-01-08 20:21:34 +03:00
}
2018-07-24 22:25:19 +03:00
//! check which docks must be deleted e.g. when the corresponding
//! screen does not exist any more.
//! The code is smart enough in order
//! to never delete the last tasks dock and also it makes sure that
//! the last tasks dock which will exist in the end will be the one
//! with the lowest containment id
foreach ( auto view , m_dockViews ) {
bool found { false } ;
foreach ( auto scr , qGuiApp - > screens ( ) ) {
if ( scr - > name ( ) = = view - > currentScreen ( )
| | ( view - > onPrimary ( ) & & scr = = qGuiApp - > primaryScreen ( ) ) ) {
found = true ;
break ;
}
}
//! which explicit docks can be deleted
if ( ! found & & ! view - > onPrimary ( ) & & ( m_dockViews . size ( ) > 1 ) & & m_dockViews . contains ( view - > containment ( ) )
& & ! ( view - > tasksPresent ( ) & & noDocksWithTasks ( ) = = 1 ) ) {
//do not delete last dock containing tasks
if ( dockWithTasksWillBeShown | | preserveContainmentId ! = view - > containment ( ) - > id ( ) ) {
qDebug ( ) < < " screen Count signal: view must be deleted... for: " < < view - > currentScreen ( ) ;
auto viewToDelete = m_dockViews . take ( view - > containment ( ) ) ;
viewToDelete - > disconnectSensitiveSignals ( ) ;
viewToDelete - > deleteLater ( ) ;
}
//!which primary docks can be deleted
} else if ( view - > onPrimary ( ) & & ! found
& & ! freeEdges ( qGuiApp - > primaryScreen ( ) ) . contains ( view - > location ( ) ) ) {
qDebug ( ) < < " screen Count signal: primary view must be deleted... for: " < < view - > currentScreen ( ) ;
auto viewToDelete = m_dockViews . take ( view - > containment ( ) ) ;
viewToDelete - > disconnectSensitiveSignals ( ) ;
viewToDelete - > deleteLater ( ) ;
} else {
//! if the dock will not be deleted its a very good point to reconsider
//! if the screen in which is running is the correct one
view - > reconsiderScreen ( ) ;
}
}
*/
qDebug ( ) < < " end of, syncDockViewsToScreens .... " ;
2018-01-08 20:21:34 +03:00
}
2018-01-21 12:34:18 +03:00
void Layout : : assignToLayout ( DockView * dockView , QList < Plasma : : Containment * > containments )
{
if ( ! m_corona ) {
return ;
}
if ( dockView ) {
m_dockViews [ dockView - > containment ( ) ] = dockView ;
m_containments < < containments ;
foreach ( auto containment , containments ) {
containment - > config ( ) . writeEntry ( " layoutId " , name ( ) ) ;
2018-01-21 14:07:08 +03:00
connect ( containment , & QObject : : destroyed , this , & Layout : : containmentDestroyed ) ;
connect ( containment , & Plasma : : Applet : : destroyedChanged , this , & Layout : : destroyedChanged ) ;
connect ( containment , & Plasma : : Containment : : appletCreated , this , & Layout : : appletCreated ) ;
2018-01-21 12:34:18 +03:00
}
dockView - > setManagedLayout ( this ) ;
2018-12-01 18:29:17 +03:00
emit viewsCountChanged ( ) ;
2018-01-21 12:34:18 +03:00
emit m_corona - > availableScreenRectChanged ( ) ;
emit m_corona - > availableScreenRegionChanged ( ) ;
}
2018-07-11 20:17:06 +03:00
//! sync the original layout file for integrity
if ( m_corona & & m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Dock : : MultipleLayouts ) {
syncToLayoutFile ( false ) ;
}
2018-01-21 12:34:18 +03:00
}
QList < Plasma : : Containment * > Layout : : unassignFromLayout ( DockView * dockView )
{
QList < Plasma : : Containment * > containments ;
if ( ! m_corona ) {
return containments ;
}
containments < < dockView - > containment ( ) ;
foreach ( auto containment , m_containments ) {
Plasma : : Applet * parentApplet = qobject_cast < Plasma : : Applet * > ( containment - > parent ( ) ) ;
//! add systrays from that dockView
if ( parentApplet & & parentApplet - > containment ( ) & & parentApplet - > containment ( ) = = dockView - > containment ( ) ) {
containments < < containment ;
2018-01-21 14:07:08 +03:00
disconnect ( containment , & QObject : : destroyed , this , & Layout : : containmentDestroyed ) ;
disconnect ( containment , & Plasma : : Applet : : destroyedChanged , this , & Layout : : destroyedChanged ) ;
disconnect ( containment , & Plasma : : Containment : : appletCreated , this , & Layout : : appletCreated ) ;
2018-01-21 12:34:18 +03:00
}
}
foreach ( auto containment , containments ) {
m_containments . removeAll ( containment ) ;
}
if ( containments . size ( ) > 0 ) {
m_dockViews . remove ( dockView - > containment ( ) ) ;
}
2018-07-11 20:17:06 +03:00
//! sync the original layout file for integrity
if ( m_corona & & m_corona - > layoutManager ( ) - > memoryUsage ( ) = = Dock : : MultipleLayouts ) {
syncToLayoutFile ( false ) ;
}
2018-01-21 12:34:18 +03:00
return containments ;
}
2018-07-24 22:25:19 +03:00
bool Layout : : dockViewExists ( Plasma : : Containment * containment )
{
if ( ! m_corona ) {
return false ;
}
return m_dockViews . keys ( ) . contains ( containment ) ;
}
2018-10-07 22:04:17 +03:00
QList < Plasma : : Types : : Location > Layout : : availableEdgesForView ( QScreen * scr , DockView * forView ) const
2018-01-31 19:45:15 +03:00
{
using Plasma : : Types ;
QList < Types : : Location > edges { Types : : BottomEdge , Types : : LeftEdge ,
Types : : TopEdge , Types : : RightEdge } ;
if ( ! m_corona ) {
return edges ;
}
foreach ( auto view , m_dockViews ) {
2018-10-07 22:04:17 +03:00
//! make sure that availabe edges takes into account only views that should be excluded,
//! this is why the forView should not be excluded
2018-12-01 16:22:33 +03:00
if ( view & & view ! = forView & & view - > positioner ( ) - > currentScreenName ( ) = = scr - > name ( ) ) {
2018-10-07 22:04:17 +03:00
edges . removeOne ( view - > location ( ) ) ;
}
}
return edges ;
}
2018-12-01 17:13:35 +03:00
QList < int > Layout : : qmlFreeEdges ( int screen ) const
{
if ( ! m_corona ) {
const QList < int > emptyEdges ;
return emptyEdges ;
}
const auto edges = freeEdges ( screen ) ;
QList < int > edgesInt ;
foreach ( Plasma : : Types : : Location edge , edges ) {
edgesInt . append ( static_cast < int > ( edge ) ) ;
}
return edgesInt ;
}
2018-10-07 22:04:17 +03:00
QList < Plasma : : Types : : Location > Layout : : freeEdges ( QScreen * scr ) const
{
using Plasma : : Types ;
QList < Types : : Location > edges { Types : : BottomEdge , Types : : LeftEdge ,
Types : : TopEdge , Types : : RightEdge } ;
if ( ! m_corona ) {
return edges ;
}
foreach ( auto view , m_dockViews ) {
2018-12-01 16:22:33 +03:00
if ( view & & view - > positioner ( ) - > currentScreenName ( ) = = scr - > name ( ) ) {
2018-01-31 19:45:15 +03:00
edges . removeOne ( view - > location ( ) ) ;
}
}
return edges ;
}
QList < Plasma : : Types : : Location > Layout : : freeEdges ( int screen ) const
{
using Plasma : : Types ;
QList < Types : : Location > edges { Types : : BottomEdge , Types : : LeftEdge ,
Types : : TopEdge , Types : : RightEdge } ;
if ( ! m_corona ) {
return edges ;
}
QScreen * scr = m_corona - > screenPool ( ) - > screenForId ( screen ) ;
foreach ( auto view , m_dockViews ) {
2018-12-01 16:22:33 +03:00
if ( view & & scr & & view - > positioner ( ) - > currentScreenName ( ) = = scr - > name ( ) ) {
2018-01-31 19:45:15 +03:00
edges . removeOne ( view - > location ( ) ) ;
}
}
return edges ;
}
2018-01-31 21:25:56 +03:00
bool Layout : : explicitDockOccupyEdge ( int screen , Plasma : : Types : : Location location ) const
{
if ( ! m_corona ) {
return false ;
}
foreach ( auto containment , m_containments ) {
2018-08-24 01:27:14 +03:00
if ( isLatteContainment ( containment ) ) {
2018-01-31 21:25:56 +03:00
bool onPrimary = containment - > config ( ) . readEntry ( " onPrimary " , true ) ;
int id = containment - > lastScreen ( ) ;
Plasma : : Types : : Location contLocation = containment - > location ( ) ;
if ( ! onPrimary & & id = = screen & & contLocation = = location ) {
return true ;
}
}
}
return false ;
}
2018-07-24 22:25:19 +03:00
bool Layout : : primaryDockOccupyEdge ( Plasma : : Types : : Location location ) const
{
if ( ! m_corona ) {
return false ;
}
foreach ( auto containment , m_containments ) {
2018-08-24 01:27:14 +03:00
if ( isLatteContainment ( containment ) ) {
2018-07-24 22:25:19 +03:00
bool onPrimary = containment - > config ( ) . readEntry ( " onPrimary " , true ) ;
Plasma : : Types : : Location contLocation = containment - > location ( ) ;
if ( onPrimary & & contLocation = = location ) {
return true ;
}
}
}
return false ;
}
2018-01-31 21:25:56 +03:00
2018-08-24 01:27:14 +03:00
bool Layout : : isLatteContainment ( Plasma : : Containment * containment ) const
{
if ( ! containment ) {
return false ;
}
if ( containment - > pluginMetaData ( ) . pluginId ( ) = = " org.kde.latte.containment " ) {
return true ;
}
return false ;
}
2018-01-31 21:17:50 +03:00
int Layout : : noDocksWithTasks ( ) const
{
2018-01-31 21:25:56 +03:00
if ( ! m_corona ) {
return 0 ;
}
2018-01-31 21:17:50 +03:00
int result = 0 ;
foreach ( auto view , m_dockViews ) {
if ( view - > tasksPresent ( ) ) {
result + + ;
}
}
return result ;
}
2018-01-31 21:45:55 +03:00
int Layout : : docksCount ( int screen ) const
{
if ( ! m_corona ) {
return 0 ;
}
QScreen * scr = m_corona - > screenPool ( ) - > screenForId ( screen ) ;
int docks { 0 } ;
foreach ( auto view , m_dockViews ) {
if ( view & & view - > screen ( ) = = scr & & ! view - > containment ( ) - > destroyed ( ) ) {
+ + docks ;
}
}
return docks ;
}
2018-12-01 18:29:17 +03:00
int Layout : : docksCount ( QScreen * screen ) const
2018-01-31 21:45:55 +03:00
{
if ( ! m_corona ) {
return 0 ;
}
int docks { 0 } ;
foreach ( auto view , m_dockViews ) {
2018-12-01 18:29:17 +03:00
if ( view & & view - > screen ( ) = = screen & & ! view - > containment ( ) - > destroyed ( ) ) {
2018-01-31 21:45:55 +03:00
+ + docks ;
}
}
return docks ;
}
2018-12-01 18:29:17 +03:00
int Layout : : viewsCount ( ) const
2018-01-31 21:45:55 +03:00
{
if ( ! m_corona ) {
return 0 ;
}
int docks { 0 } ;
foreach ( auto view , m_dockViews ) {
2018-12-01 18:29:17 +03:00
if ( view & & view - > containment ( ) & & ! view - > containment ( ) - > destroyed ( ) ) {
2018-01-31 21:45:55 +03:00
+ + docks ;
}
}
return docks ;
}
2017-07-02 16:12:58 +03:00
}