2017-07-31 03:53:39 +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/>.
*/
# include "launcherssignals.h"
2018-12-02 03:05:52 +03:00
// local
2018-12-06 15:35:34 +03:00
# include "lattecorona.h"
2019-02-06 09:52:33 +03:00
# include "layoutmanager.h"
2019-04-05 19:59:15 +03:00
# include "layout/activelayout.h"
2018-02-03 14:10:43 +03:00
2018-12-02 03:05:52 +03:00
// Qt
2018-02-03 12:34:13 +03:00
# include <QQuickItem>
2018-12-02 03:05:52 +03:00
// Plasma
2018-02-03 14:10:43 +03:00
# include <Plasma/Applet>
# include <Plasma/Containment>
2017-07-31 03:53:39 +03:00
namespace Latte {
LaunchersSignals : : LaunchersSignals ( QObject * parent )
: QObject ( parent )
{
m_manager = qobject_cast < LayoutManager * > ( parent ) ;
}
LaunchersSignals : : ~ LaunchersSignals ( )
{
}
2018-01-21 21:17:58 +03:00
QList < Plasma : : Applet * > LaunchersSignals : : lattePlasmoids ( QString layoutName )
2017-07-31 03:53:39 +03:00
{
QList < Plasma : : Applet * > applets ;
2019-04-05 19:59:15 +03:00
ActiveLayout * layout = m_manager - > activeLayout ( layoutName ) ;
2018-01-21 21:17:58 +03:00
QList < Plasma : : Containment * > containments ;
if ( layoutName . isEmpty ( ) ) {
containments = m_manager - > corona ( ) - > containments ( ) ;
} else if ( layout ) {
containments = * ( layout - > containments ( ) ) ;
}
2019-04-04 23:55:44 +03:00
for ( const auto containment : containments ) {
for ( auto * applet : containment - > applets ( ) ) {
2017-07-31 03:53:39 +03:00
KPluginMetaData meta = applet - > kPackage ( ) . metadata ( ) ;
if ( meta . pluginId ( ) = = " org.kde.latte.plasmoid " ) {
applets . append ( applet ) ;
}
}
}
return applets ;
}
2018-01-21 21:17:58 +03:00
void LaunchersSignals : : addLauncher ( QString layoutName , int launcherGroup , QString launcher )
2017-07-31 03:53:39 +03:00
{
2018-12-07 19:55:35 +03:00
Types : : LaunchersGroup group = static_cast < Types : : LaunchersGroup > ( launcherGroup ) ;
2018-01-21 21:17:58 +03:00
2018-12-07 19:55:35 +03:00
if ( ( Types : : LaunchersGroup ) group = = Types : : UniqueLaunchers ) {
2017-07-31 03:53:39 +03:00
return ;
}
2018-12-07 19:55:35 +03:00
QString lName = ( group = = Types : : LayoutLaunchers ) ? layoutName : " " ;
2018-01-21 21:17:58 +03:00
2019-04-04 23:55:44 +03:00
for ( const auto applet : lattePlasmoids ( lName ) ) {
2017-07-31 03:53:39 +03:00
if ( QQuickItem * appletInterface = applet - > property ( " _plasma_graphicObject " ) . value < QQuickItem * > ( ) ) {
const auto & childItems = appletInterface - > childItems ( ) ;
if ( childItems . isEmpty ( ) ) {
continue ;
}
for ( QQuickItem * item : childItems ) {
if ( auto * metaObject = item - > metaObject ( ) ) {
int methodIndex = metaObject - > indexOfMethod ( " extSignalAddLauncher(QVariant,QVariant) " ) ;
if ( methodIndex = = - 1 ) {
continue ;
}
QMetaMethod method = metaObject - > method ( methodIndex ) ;
method . invoke ( item , Q_ARG ( QVariant , launcherGroup ) , Q_ARG ( QVariant , launcher ) ) ;
}
}
}
}
}
2018-01-21 21:17:58 +03:00
void LaunchersSignals : : removeLauncher ( QString layoutName , int launcherGroup , QString launcher )
2017-07-31 03:53:39 +03:00
{
2018-12-07 19:55:35 +03:00
Types : : LaunchersGroup group = static_cast < Types : : LaunchersGroup > ( launcherGroup ) ;
2018-01-21 21:17:58 +03:00
2018-12-07 19:55:35 +03:00
if ( ( Types : : LaunchersGroup ) group = = Types : : UniqueLaunchers ) {
2017-07-31 03:53:39 +03:00
return ;
}
2018-12-07 19:55:35 +03:00
QString lName = ( group = = Types : : LayoutLaunchers ) ? layoutName : " " ;
2018-01-21 21:17:58 +03:00
2019-04-04 23:55:44 +03:00
for ( const auto applet : lattePlasmoids ( lName ) ) {
2017-07-31 03:53:39 +03:00
if ( QQuickItem * appletInterface = applet - > property ( " _plasma_graphicObject " ) . value < QQuickItem * > ( ) ) {
const auto & childItems = appletInterface - > childItems ( ) ;
if ( childItems . isEmpty ( ) ) {
continue ;
}
for ( QQuickItem * item : childItems ) {
if ( auto * metaObject = item - > metaObject ( ) ) {
int methodIndex = metaObject - > indexOfMethod ( " extSignalRemoveLauncher(QVariant,QVariant) " ) ;
if ( methodIndex = = - 1 ) {
continue ;
}
QMetaMethod method = metaObject - > method ( methodIndex ) ;
method . invoke ( item , Q_ARG ( QVariant , launcherGroup ) , Q_ARG ( QVariant , launcher ) ) ;
}
}
}
}
}
2018-01-21 21:17:58 +03:00
void LaunchersSignals : : addLauncherToActivity ( QString layoutName , int launcherGroup , QString launcher , QString activity )
2017-07-31 03:53:39 +03:00
{
2018-12-07 19:55:35 +03:00
Types : : LaunchersGroup group = static_cast < Types : : LaunchersGroup > ( launcherGroup ) ;
2018-01-21 21:17:58 +03:00
2018-12-07 19:55:35 +03:00
if ( ( Types : : LaunchersGroup ) group = = Types : : UniqueLaunchers ) {
2017-07-31 03:53:39 +03:00
return ;
}
2018-12-07 19:55:35 +03:00
QString lName = ( group = = Types : : LayoutLaunchers ) ? layoutName : " " ;
2018-01-21 21:17:58 +03:00
2019-04-04 23:55:44 +03:00
for ( const auto applet : lattePlasmoids ( lName ) ) {
2017-07-31 03:53:39 +03:00
if ( QQuickItem * appletInterface = applet - > property ( " _plasma_graphicObject " ) . value < QQuickItem * > ( ) ) {
const auto & childItems = appletInterface - > childItems ( ) ;
if ( childItems . isEmpty ( ) ) {
continue ;
}
for ( QQuickItem * item : childItems ) {
if ( auto * metaObject = item - > metaObject ( ) ) {
int methodIndex = metaObject - > indexOfMethod ( " extSignalAddLauncherToActivity(QVariant,QVariant,QVariant) " ) ;
if ( methodIndex = = - 1 ) {
continue ;
}
QMetaMethod method = metaObject - > method ( methodIndex ) ;
method . invoke ( item , Q_ARG ( QVariant , launcherGroup ) , Q_ARG ( QVariant , launcher ) , Q_ARG ( QVariant , activity ) ) ;
}
}
}
}
}
2018-01-21 21:17:58 +03:00
void LaunchersSignals : : removeLauncherFromActivity ( QString layoutName , int launcherGroup , QString launcher , QString activity )
2017-07-31 03:53:39 +03:00
{
2018-12-07 19:55:35 +03:00
Types : : LaunchersGroup group = static_cast < Types : : LaunchersGroup > ( launcherGroup ) ;
2018-01-21 21:17:58 +03:00
2018-12-07 19:55:35 +03:00
if ( ( Types : : LaunchersGroup ) group = = Types : : UniqueLaunchers ) {
2017-07-31 03:53:39 +03:00
return ;
}
2018-12-07 19:55:35 +03:00
QString lName = ( group = = Types : : LayoutLaunchers ) ? layoutName : " " ;
2018-01-21 21:17:58 +03:00
2019-04-04 23:55:44 +03:00
for ( const auto applet : lattePlasmoids ( lName ) ) {
2017-07-31 03:53:39 +03:00
if ( QQuickItem * appletInterface = applet - > property ( " _plasma_graphicObject " ) . value < QQuickItem * > ( ) ) {
const auto & childItems = appletInterface - > childItems ( ) ;
if ( childItems . isEmpty ( ) ) {
continue ;
}
for ( QQuickItem * item : childItems ) {
if ( auto * metaObject = item - > metaObject ( ) ) {
int methodIndex = metaObject - > indexOfMethod ( " extSignalRemoveLauncherFromActivity(QVariant,QVariant,QVariant) " ) ;
if ( methodIndex = = - 1 ) {
continue ;
}
QMetaMethod method = metaObject - > method ( methodIndex ) ;
method . invoke ( item , Q_ARG ( QVariant , launcherGroup ) , Q_ARG ( QVariant , launcher ) , Q_ARG ( QVariant , activity ) ) ;
}
}
}
}
}
2018-01-21 21:17:58 +03:00
void LaunchersSignals : : urlsDropped ( QString layoutName , int launcherGroup , QStringList urls )
2017-07-31 03:53:39 +03:00
{
2018-12-07 19:55:35 +03:00
Types : : LaunchersGroup group = static_cast < Types : : LaunchersGroup > ( launcherGroup ) ;
2018-01-21 21:17:58 +03:00
2018-12-07 19:55:35 +03:00
if ( ( Types : : LaunchersGroup ) group = = Types : : UniqueLaunchers ) {
2017-07-31 03:53:39 +03:00
return ;
}
2018-12-07 19:55:35 +03:00
QString lName = ( group = = Types : : LayoutLaunchers ) ? layoutName : " " ;
2018-01-21 21:17:58 +03:00
2019-04-04 23:55:44 +03:00
for ( const auto applet : lattePlasmoids ( lName ) ) {
2017-07-31 03:53:39 +03:00
if ( QQuickItem * appletInterface = applet - > property ( " _plasma_graphicObject " ) . value < QQuickItem * > ( ) ) {
const auto & childItems = appletInterface - > childItems ( ) ;
if ( childItems . isEmpty ( ) ) {
continue ;
}
for ( QQuickItem * item : childItems ) {
if ( auto * metaObject = item - > metaObject ( ) ) {
int methodIndex = metaObject - > indexOfMethod ( " extSignalUrlsDropped(QVariant,QVariant) " ) ;
if ( methodIndex = = - 1 ) {
continue ;
}
QMetaMethod method = metaObject - > method ( methodIndex ) ;
method . invoke ( item , Q_ARG ( QVariant , launcherGroup ) , Q_ARG ( QVariant , urls ) ) ;
}
}
}
}
}
2018-01-21 21:17:58 +03:00
void LaunchersSignals : : moveTask ( QString layoutName , int senderId , int launcherGroup , int from , int to )
2017-07-31 03:53:39 +03:00
{
2018-12-07 19:55:35 +03:00
Types : : LaunchersGroup group = static_cast < Types : : LaunchersGroup > ( launcherGroup ) ;
2018-01-21 21:17:58 +03:00
2018-12-07 19:55:35 +03:00
if ( ( Types : : LaunchersGroup ) group = = Types : : UniqueLaunchers ) {
2017-07-31 03:53:39 +03:00
return ;
}
2018-12-07 19:55:35 +03:00
QString lName = ( group = = Types : : LayoutLaunchers ) ? layoutName : " " ;
2018-01-21 21:17:58 +03:00
2019-04-04 23:55:44 +03:00
for ( const auto applet : lattePlasmoids ( lName ) ) {
2017-07-31 10:26:15 +03:00
if ( applet - > id ( ) ! = senderId ) {
if ( QQuickItem * appletInterface = applet - > property ( " _plasma_graphicObject " ) . value < QQuickItem * > ( ) ) {
const auto & childItems = appletInterface - > childItems ( ) ;
2017-07-31 03:53:39 +03:00
2017-07-31 10:26:15 +03:00
if ( childItems . isEmpty ( ) ) {
continue ;
}
2017-07-31 03:53:39 +03:00
2017-07-31 10:26:15 +03:00
for ( QQuickItem * item : childItems ) {
if ( auto * metaObject = item - > metaObject ( ) ) {
int methodIndex = metaObject - > indexOfMethod ( " extSignalMoveTask(QVariant,QVariant,QVariant) " ) ;
2017-07-31 03:53:39 +03:00
2017-07-31 10:26:15 +03:00
if ( methodIndex = = - 1 ) {
continue ;
}
2017-07-31 03:53:39 +03:00
2017-07-31 10:26:15 +03:00
QMetaMethod method = metaObject - > method ( methodIndex ) ;
method . invoke ( item , Q_ARG ( QVariant , launcherGroup ) , Q_ARG ( QVariant , from ) , Q_ARG ( QVariant , to ) ) ;
}
2017-07-31 03:53:39 +03:00
}
}
}
}
}
2018-11-20 23:10:05 +03:00
void LaunchersSignals : : validateLaunchersOrder ( QString layoutName , int senderId , int launcherGroup , QStringList launchers )
{
2018-12-07 19:55:35 +03:00
Types : : LaunchersGroup group = static_cast < Types : : LaunchersGroup > ( launcherGroup ) ;
2018-11-20 23:10:05 +03:00
2018-12-07 19:55:35 +03:00
if ( ( Types : : LaunchersGroup ) group = = Types : : UniqueLaunchers ) {
2018-11-20 23:10:05 +03:00
return ;
}
2018-12-07 19:55:35 +03:00
QString lName = ( group = = Types : : LayoutLaunchers ) ? layoutName : " " ;
2018-11-20 23:10:05 +03:00
2019-04-04 23:55:44 +03:00
for ( const auto applet : lattePlasmoids ( lName ) ) {
2018-11-20 23:10:05 +03:00
if ( applet - > id ( ) ! = senderId ) {
if ( QQuickItem * appletInterface = applet - > property ( " _plasma_graphicObject " ) . value < QQuickItem * > ( ) ) {
const auto & childItems = appletInterface - > childItems ( ) ;
if ( childItems . isEmpty ( ) ) {
continue ;
}
for ( QQuickItem * item : childItems ) {
if ( auto * metaObject = item - > metaObject ( ) ) {
int methodIndex = metaObject - > indexOfMethod ( " extSignalValidateLaunchersOrder(QVariant,QVariant) " ) ;
if ( methodIndex = = - 1 ) {
continue ;
}
QMetaMethod method = metaObject - > method ( methodIndex ) ;
method . invoke ( item , Q_ARG ( QVariant , launcherGroup ) , Q_ARG ( QVariant , launchers ) ) ;
}
}
}
}
}
}
2017-07-31 03:53:39 +03:00
} //end of namespace