2017-07-31 03:53:39 +03:00
/*
2021-05-27 15:01:00 +00:00
SPDX - FileCopyrightText : 2021 Michail Vourlakos < mvourlakos @ gmail . com >
SPDX - License - Identifier : GPL - 2.0 - or - later
2017-07-31 03:53:39 +03:00
*/
2021-01-14 20:21:12 +02:00
# include "syncedlaunchers.h"
2017-07-31 03:53:39 +03:00
2018-12-02 02:05:52 +02:00
// local
2020-04-24 14:52:16 +03:00
# include <coretypes.h>
2019-05-09 17:40:53 +03:00
# include "../lattecorona.h"
# include "../layout/centrallayout.h"
# include "../layouts/manager.h"
2019-05-11 09:23:14 +03:00
# include "../layouts/synchronizer.h"
2018-02-03 13:10:43 +02:00
2018-12-02 02:05:52 +02:00
// Qt
2018-02-03 11:34:13 +02:00
# include <QQuickItem>
2018-12-02 02:05:52 +02:00
// Plasma
2018-02-03 13:10:43 +02:00
# include <Plasma/Applet>
# include <Plasma/Containment>
2020-04-22 14:09:42 +03:00
2017-07-31 03:53:39 +03:00
namespace Latte {
2019-05-09 17:40:53 +03:00
namespace Layouts {
2017-07-31 03:53:39 +03:00
2021-01-14 20:21:12 +02:00
SyncedLaunchers : : SyncedLaunchers ( QObject * parent )
2017-07-31 03:53:39 +03:00
: QObject ( parent )
{
2019-05-09 17:12:57 +03:00
m_manager = qobject_cast < Layouts : : Manager * > ( parent ) ;
2017-07-31 03:53:39 +03:00
}
2021-01-14 20:21:12 +02:00
SyncedLaunchers : : ~ SyncedLaunchers ( )
2017-07-31 03:53:39 +03:00
{
}
2021-01-14 20:21:12 +02:00
void SyncedLaunchers : : addAbilityClient ( QQuickItem * client )
2017-07-31 03:53:39 +03:00
{
2021-01-13 22:53:55 +02:00
if ( m_clients . contains ( client ) ) {
return ;
2018-01-21 20:17:58 +02:00
}
2021-01-13 22:53:55 +02:00
m_clients < < client ;
2017-07-31 03:53:39 +03:00
2021-01-14 20:21:12 +02:00
connect ( client , & QObject : : destroyed , this , & SyncedLaunchers : : removeClientObject ) ;
2017-07-31 03:53:39 +03:00
}
2021-01-14 20:21:12 +02:00
void SyncedLaunchers : : removeAbilityClient ( QQuickItem * client )
2017-07-31 03:53:39 +03:00
{
2021-01-13 22:53:55 +02:00
if ( ! m_clients . contains ( client ) ) {
2017-07-31 03:53:39 +03:00
return ;
}
2021-01-14 20:21:12 +02:00
disconnect ( client , & QObject : : destroyed , this , & SyncedLaunchers : : removeClientObject ) ;
2021-01-13 22:53:55 +02:00
m_clients . removeAll ( client ) ;
}
2017-07-31 03:53:39 +03:00
2021-01-14 20:21:12 +02:00
void SyncedLaunchers : : removeClientObject ( QObject * obj )
2021-01-13 22:53:55 +02:00
{
QQuickItem * item = qobject_cast < QQuickItem * > ( obj ) ;
2017-07-31 03:53:39 +03:00
2021-01-13 22:53:55 +02:00
if ( item ) {
removeAbilityClient ( item ) ;
}
}
2017-07-31 03:53:39 +03:00
2021-01-14 20:21:12 +02:00
QList < QQuickItem * > SyncedLaunchers : : clients ( QString layoutName )
2021-01-13 22:53:55 +02:00
{
QList < QQuickItem * > items ;
2017-07-31 03:53:39 +03:00
2021-01-13 22:53:55 +02:00
if ( ! layoutName . isEmpty ( ) ) {
for ( const auto client : m_clients ) {
QString cLayoutName = client - > property ( " layoutName " ) . toString ( ) ;
if ( cLayoutName = = layoutName ) {
items < < client ;
2017-07-31 03:53:39 +03:00
}
}
2021-01-13 22:53:55 +02:00
} else {
items = m_clients ;
2017-07-31 03:53:39 +03:00
}
2021-01-13 22:53:55 +02:00
return items ;
2017-07-31 03:53:39 +03:00
}
2021-01-14 20:21:12 +02:00
void SyncedLaunchers : : addLauncher ( QString layoutName , int launcherGroup , QString launcher )
2017-07-31 03:53:39 +03:00
{
2020-04-22 21:10:17 +03:00
Types : : LaunchersGroup group = static_cast < Types : : LaunchersGroup > ( launcherGroup ) ;
2018-01-21 20:17:58 +02:00
2020-04-22 21:10:17 +03:00
if ( ( Types : : LaunchersGroup ) group = = Types : : UniqueLaunchers ) {
2017-07-31 03:53:39 +03:00
return ;
}
2020-04-22 21:10:17 +03:00
QString lName = ( group = = Types : : LayoutLaunchers ) ? layoutName : " " ;
2018-01-21 20:17:58 +02:00
2021-01-13 22:53:55 +02:00
for ( const auto client : clients ( lName ) ) {
if ( auto * metaObject = client - > metaObject ( ) ) {
int methodIndex = metaObject - > indexOfMethod ( " addSyncedLauncher(QVariant,QVariant) " ) ;
2017-07-31 03:53:39 +03:00
2021-01-13 22:53:55 +02:00
if ( methodIndex = = - 1 ) {
qDebug ( ) < < " Launchers Syncer Ability: addSyncedLauncher(QVariant,QVariant) was NOT found... " ;
2017-07-31 03:53:39 +03:00
continue ;
}
2021-01-13 22:53:55 +02:00
QMetaMethod method = metaObject - > method ( methodIndex ) ;
method . invoke ( client , Q_ARG ( QVariant , launcherGroup ) , Q_ARG ( QVariant , launcher ) ) ;
2017-07-31 03:53:39 +03:00
}
}
}
2021-01-14 20:21:12 +02:00
void SyncedLaunchers : : removeLauncher ( QString layoutName , int launcherGroup , QString launcher )
2017-07-31 03:53:39 +03:00
{
2020-04-22 21:10:17 +03:00
Types : : LaunchersGroup group = static_cast < Types : : LaunchersGroup > ( launcherGroup ) ;
2018-01-21 20:17:58 +02:00
2020-04-22 21:10:17 +03:00
if ( ( Types : : LaunchersGroup ) group = = Types : : UniqueLaunchers ) {
2017-07-31 03:53:39 +03:00
return ;
}
2020-04-22 21:10:17 +03:00
QString lName = ( group = = Types : : LayoutLaunchers ) ? layoutName : " " ;
2018-01-21 20:17:58 +02:00
2021-01-13 22:53:55 +02:00
for ( const auto client : clients ( lName ) ) {
if ( auto * metaObject = client - > metaObject ( ) ) {
int methodIndex = metaObject - > indexOfMethod ( " removeSyncedLauncher(QVariant,QVariant) " ) ;
2017-07-31 03:53:39 +03:00
2021-01-13 22:53:55 +02:00
if ( methodIndex = = - 1 ) {
qDebug ( ) < < " Launchers Syncer Ability: removeSyncedLauncher(QVariant,QVariant) was NOT found... " ;
2017-07-31 03:53:39 +03:00
continue ;
}
2021-01-13 22:53:55 +02:00
QMetaMethod method = metaObject - > method ( methodIndex ) ;
method . invoke ( client , Q_ARG ( QVariant , launcherGroup ) , Q_ARG ( QVariant , launcher ) ) ;
2017-07-31 03:53:39 +03:00
}
}
}
2021-01-14 20:21:12 +02:00
void SyncedLaunchers : : addLauncherToActivity ( QString layoutName , int launcherGroup , QString launcher , QString activity )
2017-07-31 03:53:39 +03:00
{
2020-04-22 21:10:17 +03:00
Types : : LaunchersGroup group = static_cast < Types : : LaunchersGroup > ( launcherGroup ) ;
2018-01-21 20:17:58 +02:00
2020-04-22 21:10:17 +03:00
if ( ( Types : : LaunchersGroup ) group = = Types : : UniqueLaunchers ) {
2017-07-31 03:53:39 +03:00
return ;
}
2020-04-22 21:10:17 +03:00
QString lName = ( group = = Types : : LayoutLaunchers ) ? layoutName : " " ;
2018-01-21 20:17:58 +02:00
2021-01-13 22:53:55 +02:00
for ( const auto client : clients ( lName ) ) {
if ( auto * metaObject = client - > metaObject ( ) ) {
int methodIndex = metaObject - > indexOfMethod ( " addSyncedLauncherToActivity(QVariant,QVariant,QVariant) " ) ;
2017-07-31 03:53:39 +03:00
2021-01-13 22:53:55 +02:00
if ( methodIndex = = - 1 ) {
qDebug ( ) < < " Launchers Syncer Ability: addSyncedLauncherToActivity(QVariant,QVariant,QVariant) was NOT found... " ;
2017-07-31 03:53:39 +03:00
continue ;
}
2021-01-13 22:53:55 +02:00
QMetaMethod method = metaObject - > method ( methodIndex ) ;
method . invoke ( client , Q_ARG ( QVariant , launcherGroup ) , Q_ARG ( QVariant , launcher ) , Q_ARG ( QVariant , activity ) ) ;
2017-07-31 03:53:39 +03:00
}
}
}
2021-01-14 20:21:12 +02:00
void SyncedLaunchers : : removeLauncherFromActivity ( QString layoutName , int launcherGroup , QString launcher , QString activity )
2017-07-31 03:53:39 +03:00
{
2020-04-22 21:10:17 +03:00
Types : : LaunchersGroup group = static_cast < Types : : LaunchersGroup > ( launcherGroup ) ;
2018-01-21 20:17:58 +02:00
2020-04-22 21:10:17 +03:00
if ( ( Types : : LaunchersGroup ) group = = Types : : UniqueLaunchers ) {
2017-07-31 03:53:39 +03:00
return ;
}
2020-04-22 21:10:17 +03:00
QString lName = ( group = = Types : : LayoutLaunchers ) ? layoutName : " " ;
2018-01-21 20:17:58 +02:00
2021-01-13 22:53:55 +02:00
for ( const auto client : clients ( lName ) ) {
if ( auto * metaObject = client - > metaObject ( ) ) {
int methodIndex = metaObject - > indexOfMethod ( " removeSyncedLauncherFromActivity(QVariant,QVariant,QVariant) " ) ;
2017-07-31 03:53:39 +03:00
2021-01-13 22:53:55 +02:00
if ( methodIndex = = - 1 ) {
qDebug ( ) < < " Launchers Syncer Ability: removeSyncedLauncherFromActivity(QVariant,QVariant,QVariant) was NOT found... " ;
2017-07-31 03:53:39 +03:00
continue ;
}
2021-01-13 22:53:55 +02:00
QMetaMethod method = metaObject - > method ( methodIndex ) ;
method . invoke ( client , Q_ARG ( QVariant , launcherGroup ) , Q_ARG ( QVariant , launcher ) , Q_ARG ( QVariant , activity ) ) ;
2017-07-31 03:53:39 +03:00
}
}
}
2021-01-14 20:21:12 +02:00
void SyncedLaunchers : : urlsDropped ( QString layoutName , int launcherGroup , QStringList urls )
2017-07-31 03:53:39 +03:00
{
2020-04-22 21:10:17 +03:00
Types : : LaunchersGroup group = static_cast < Types : : LaunchersGroup > ( launcherGroup ) ;
2018-01-21 20:17:58 +02:00
2020-04-22 21:10:17 +03:00
if ( ( Types : : LaunchersGroup ) group = = Types : : UniqueLaunchers ) {
2017-07-31 03:53:39 +03:00
return ;
}
2020-04-22 21:10:17 +03:00
QString lName = ( group = = Types : : LayoutLaunchers ) ? layoutName : " " ;
2018-01-21 20:17:58 +02:00
2021-01-13 22:53:55 +02:00
for ( const auto client : clients ( lName ) ) {
if ( auto * metaObject = client - > metaObject ( ) ) {
int methodIndex = metaObject - > indexOfMethod ( " dropSyncedUrls(QVariant,QVariant) " ) ;
2017-07-31 03:53:39 +03:00
2021-01-13 22:53:55 +02:00
if ( methodIndex = = - 1 ) {
qDebug ( ) < < " Launchers Syncer Ability: dropSyncedUrls(QVariant,QVariant) was NOT found... " ;
continue ;
2017-07-31 03:53:39 +03:00
}
2021-01-13 22:53:55 +02:00
QMetaMethod method = metaObject - > method ( methodIndex ) ;
method . invoke ( client , Q_ARG ( QVariant , launcherGroup ) , Q_ARG ( QVariant , urls ) ) ;
2017-07-31 03:53:39 +03:00
}
}
}
2021-01-14 20:21:12 +02:00
void SyncedLaunchers : : validateLaunchersOrder ( QString layoutName , uint senderId , int launcherGroup , QStringList launchers )
2018-11-20 22:10:05 +02:00
{
2020-04-22 21:10:17 +03:00
Types : : LaunchersGroup group = static_cast < Types : : LaunchersGroup > ( launcherGroup ) ;
2018-11-20 22:10:05 +02:00
2020-04-22 21:10:17 +03:00
if ( ( Types : : LaunchersGroup ) group = = Types : : UniqueLaunchers ) {
2018-11-20 22:10:05 +02:00
return ;
}
2020-04-22 21:10:17 +03:00
QString lName = ( group = = Types : : LayoutLaunchers ) ? layoutName : " " ;
2018-11-20 22:10:05 +02:00
2021-01-13 22:53:55 +02:00
for ( const auto client : clients ( lName ) ) {
uint clientId = client - > property ( " clientId " ) . toUInt ( ) ;
if ( clientId ! = senderId ) {
if ( auto * metaObject = client - > metaObject ( ) ) {
int methodIndex = metaObject - > indexOfMethod ( " validateSyncedLaunchersOrder(QVariant,QVariant) " ) ;
2018-11-20 22:10:05 +02:00
2021-01-13 22:53:55 +02:00
if ( methodIndex = = - 1 ) {
qDebug ( ) < < " Launchers Syncer Ability: validateSyncedLaunchersOrder(QVariant,QVariant) was NOT found... " ;
2018-11-20 22:10:05 +02:00
continue ;
}
2021-01-13 22:53:55 +02:00
QMetaMethod method = metaObject - > method ( methodIndex ) ;
method . invoke ( client , Q_ARG ( QVariant , launcherGroup ) , Q_ARG ( QVariant , launchers ) ) ;
2018-11-20 22:10:05 +02:00
}
}
}
}
2019-05-09 17:40:53 +03:00
}
2017-07-31 03:53:39 +03:00
} //end of namespace