diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 50e31ca59..828b9d143 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -8,6 +8,7 @@ set(lattedock-app_SRCS coretypes.h ) +add_subdirectory(declarativeimports) add_subdirectory(indicator) add_subdirectory(layout) add_subdirectory(layouts) diff --git a/app/declarativeimports/CMakeLists.txt b/app/declarativeimports/CMakeLists.txt new file mode 100644 index 000000000..2d1d1af95 --- /dev/null +++ b/app/declarativeimports/CMakeLists.txt @@ -0,0 +1,5 @@ +set(lattedock-app_SRCS + ${lattedock-app_SRCS} + ${CMAKE_CURRENT_SOURCE_DIR}/interfaces.cpp + PARENT_SCOPE +) diff --git a/app/declarativeimports/interfaces.cpp b/app/declarativeimports/interfaces.cpp new file mode 100644 index 000000000..4d94886d7 --- /dev/null +++ b/app/declarativeimports/interfaces.cpp @@ -0,0 +1,79 @@ +/* + * Copyright 2020 Michail Vourlakos + * + * 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 . + * + */ + +#include "interfaces.h" + +#include + +namespace Latte{ + +Interfaces::Interfaces(QObject *parent) + : QObject(parent) +{ +} + +QObject *Interfaces::globalShortcuts() const +{ + return m_globalShortcuts; +} + +QObject *Interfaces::layoutsManager() const +{ + return m_layoutsManager; +} + +QObject *Interfaces::themeExtended() const +{ + return m_themeExtended; +} + +QObject *Interfaces::universalSettings() const +{ + return m_universalSettings; +} + +QObject *Interfaces::view() const +{ + return m_view; +} + +QObject *Interfaces::plasmoidInterface() const +{ + return m_plasmoid; +} + +void Interfaces::setPlasmoidInterface(QObject *interface) +{ + PlasmaQuick::AppletQuickItem *plasmoid = qobject_cast(interface); + + if (plasmoid && m_plasmoid != plasmoid) { + m_plasmoid = plasmoid; + + m_globalShortcuts = plasmoid->property("_latte_globalShortcuts_object").value(); + m_layoutsManager = plasmoid->property("_latte_layoutsManager_object").value(); + m_themeExtended = plasmoid->property("_latte_themeExtended_object").value(); + m_universalSettings = plasmoid->property("_latte_universalSettings_object").value(); + m_view = plasmoid->property("_latte_view_object").value(); + + emit interfacesChanged(); + } +} + +} diff --git a/app/declarativeimports/interfaces.h b/app/declarativeimports/interfaces.h new file mode 100644 index 000000000..26a0669ed --- /dev/null +++ b/app/declarativeimports/interfaces.h @@ -0,0 +1,75 @@ +/* + * Copyright 2020 Michail Vourlakos + * + * 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 . + * + */ + +#ifndef APPINTERFACES_H +#define APPINTERFACES_H + +// Qt +#include + + +// Plasma +#include + +namespace Latte{ + +class Interfaces: public QObject +{ + Q_OBJECT + Q_PROPERTY(QObject *plasmoidInterface READ plasmoidInterface WRITE setPlasmoidInterface NOTIFY interfacesChanged) + + Q_PROPERTY(QObject *globalShortcuts READ globalShortcuts NOTIFY interfacesChanged) + Q_PROPERTY(QObject *layoutsManager READ layoutsManager NOTIFY interfacesChanged) + Q_PROPERTY(QObject *themeExtended READ themeExtended NOTIFY interfacesChanged) + Q_PROPERTY(QObject *universalSettings READ universalSettings NOTIFY interfacesChanged) + Q_PROPERTY(QObject *view READ view NOTIFY interfacesChanged) + +public: + explicit Interfaces(QObject *parent = nullptr); + + QObject *globalShortcuts() const; + + QObject *layoutsManager() const; + + QObject *themeExtended() const; + + QObject *universalSettings() const; + + QObject *view() const; + + QObject *plasmoidInterface() const; + void setPlasmoidInterface(QObject *interface); + +signals: + void interfacesChanged(); + +private: + QObject *m_globalShortcuts{nullptr}; + QObject *m_layoutsManager{nullptr}; + QObject *m_themeExtended{nullptr}; + QObject *m_universalSettings{nullptr}; + QObject *m_view{nullptr}; + + PlasmaQuick::AppletQuickItem *m_plasmoid{nullptr}; +}; + +} + +#endif diff --git a/app/lattecorona.cpp b/app/lattecorona.cpp index 80b4fdf64..ac355b865 100644 --- a/app/lattecorona.cpp +++ b/app/lattecorona.cpp @@ -26,6 +26,7 @@ #include "apptypes.h" #include "lattedockadaptor.h" #include "screenpool.h" +#include "declarativeimports/interfaces.h" #include "indicator/factory.h" #include "layout/centrallayout.h" #include "layout/genericlayout.h" @@ -1272,6 +1273,7 @@ inline void Corona::qmlRegisterTypes() const "Error: only enums of latte app settings"); qmlRegisterType("org.kde.latte.private.app", 0, 1, "BackgroundTracker"); + qmlRegisterType("org.kde.latte.private.app", 0, 1, "Interfaces"); #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index 97d39a186..5321d258c 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -895,7 +895,7 @@ void GenericLayout::addView(Plasma::Containment *containment, bool forceOnPrimar auto latteView = new Latte::View(m_corona, nextScreen, byPassWM); - latteView->init(); + latteView->init(containment); latteView->setContainment(containment); //! force this special dock case to become primary diff --git a/app/view/indicator/indicator.cpp b/app/view/indicator/indicator.cpp index a22344ac4..d7fc4ad33 100644 --- a/app/view/indicator/indicator.cpp +++ b/app/view/indicator/indicator.cpp @@ -76,6 +76,8 @@ Indicator::Indicator(Latte::View *parent) Indicator::~Indicator() { + unloadIndicators(); + if (m_component) { m_component->deleteLater(); } diff --git a/app/view/view.cpp b/app/view/view.cpp index 648bc69b4..6322491f5 100644 --- a/app/view/view.cpp +++ b/app/view/view.cpp @@ -182,11 +182,6 @@ View::~View() disconnect(containment(), SIGNAL(statusChanged(Plasma::Types::ItemStatus)), this, SLOT(statusChanged(Plasma::Types::ItemStatus))); qDebug() << "dock view deleting..."; - rootContext()->setContextProperty(QStringLiteral("dock"), nullptr); - rootContext()->setContextProperty(QStringLiteral("layoutsManager"), nullptr); - rootContext()->setContextProperty(QStringLiteral("shortcutsEngine"), nullptr); - rootContext()->setContextProperty(QStringLiteral("themeExtended"), nullptr); - rootContext()->setContextProperty(QStringLiteral("universalSettings"), nullptr); //! this disconnect does not free up connections correctly when //! latteView is deleted. A crash for this example is the following: @@ -229,7 +224,7 @@ View::~View() } } -void View::init() +void View::init(Plasma::Containment *plasma_containment) { connect(this, &QQuickWindow::xChanged, this, &View::xChanged); connect(this, &QQuickWindow::xChanged, this, &View::updateAbsoluteGeometry); @@ -287,17 +282,19 @@ void View::init() connect(m_corona->indicatorFactory(), &Latte::Indicator::Factory::indicatorRemoved, this, &View::indicatorPluginRemoved); - ///!!!!! - rootContext()->setContextProperty(QStringLiteral("latteView"), this); + //! Assign app interfaces in be accessible through containment graphic item + QQuickItem *containmentGraphicItem = qobject_cast(plasma_containment->property("_plasma_graphicObject").value()); - if (m_corona) { - rootContext()->setContextProperty(QStringLiteral("layoutsManager"), m_corona->layoutsManager()); - rootContext()->setContextProperty(QStringLiteral("shortcutsEngine"), m_corona->globalShortcuts()->shortcutsTracker()); - rootContext()->setContextProperty(QStringLiteral("themeExtended"), m_corona->themeExtended()); - rootContext()->setContextProperty(QStringLiteral("universalSettings"), m_corona->universalSettings()); + if (containmentGraphicItem) { + containmentGraphicItem->setProperty("_latte_globalShortcuts_object", QVariant::fromValue(m_corona->globalShortcuts()->shortcutsTracker())); + containmentGraphicItem->setProperty("_latte_layoutsManager_object", QVariant::fromValue(m_corona->layoutsManager())); + containmentGraphicItem->setProperty("_latte_themeExtended_object", QVariant::fromValue(m_corona->themeExtended())); + containmentGraphicItem->setProperty("_latte_universalSettings_object", QVariant::fromValue(m_corona->universalSettings())); + containmentGraphicItem->setProperty("_latte_view_object", QVariant::fromValue(this)); } setSource(corona()->kPackage().filePath("lattedockui")); + m_positioner->syncGeometry(); qDebug() << "SOURCE:" << source(); diff --git a/app/view/view.h b/app/view/view.h index a128a6ea3..b0f338352 100644 --- a/app/view/view.h +++ b/app/view/view.h @@ -131,7 +131,7 @@ public: View(Plasma::Corona *corona, QScreen *targetScreen = nullptr, bool byPassWM = false); virtual ~View(); - void init(); + void init(Plasma::Containment *plasma_containment = nullptr); Types::ViewType type() const; void setType(Types::ViewType type); diff --git a/containment/package/contents/ui/editmode/Visual.qml b/containment/package/contents/ui/editmode/Visual.qml index 57575843e..8f3e6f2be 100644 --- a/containment/package/contents/ui/editmode/Visual.qml +++ b/containment/package/contents/ui/editmode/Visual.qml @@ -56,8 +56,6 @@ Item{ property rect efGeometry - property string layoutColor: latteView && latteView.layout ? latteView.layout.color : "blue" - readonly property real appliedOpacity: imageTiler.opacity readonly property real maxOpacity: root.inConfigureAppletsMode || !LatteCore.WindowSystem.compositingActive ? 1 : plasmoid.configuration.editBackgroundOpacity @@ -128,10 +126,15 @@ Item{ opacity: 0 fillMode: Image.Tile - source: hasBackground ? latteView.layout.background : "../../icons/"+latteView.layout.background+"print.jpg" + source: { + if (hasBackground) { + return viewLayout.background; + } + + return viewLayout ? "../../icons/"+viewLayout.background+"print.jpg" : "../../icons/blueprint.jpg" + } - readonly property bool hasBackground: (latteView && latteView.layout && latteView.layout.background.startsWith("/")) ? - true : false + readonly property bool hasBackground: (viewLayout && viewLayout.background.startsWith("/")) ? true : false Connections { target: editVisual diff --git a/containment/package/contents/ui/main.qml b/containment/package/contents/ui/main.qml index 4254b645f..615ac55ed 100644 --- a/containment/package/contents/ui/main.qml +++ b/containment/package/contents/ui/main.qml @@ -443,13 +443,14 @@ Item { readonly property alias maskManager: visibilityManager readonly property alias layoutsContainerItem: layoutsContainer - property QtObject latteView: null - property QtObject shortcutsEngine: null - property QtObject themeExtended: null - property QtObject universalSettings: null - property QtObject layoutsManager: null - property QtObject viewLayout: latteView && latteView.layout ? latteView.layout : null - property QtObject selectedWindowsTracker: { + readonly property alias latteView: _interfaces.view + readonly property alias layoutsManager: _interfaces.layoutsManager + readonly property alias shortcutsEngine: _interfaces.globalShortcuts + readonly property alias themeExtended: _interfaces.themeExtended + readonly property alias universalSettings: _interfaces.universalSettings + + readonly property QtObject viewLayout: latteView && latteView.layout ? latteView.layout : null + readonly property QtObject selectedWindowsTracker: { if (latteView && latteView.windowsTracker) { switch(plasmoid.configuration.activeWindowFilter) { case LatteContainment.Types.ActiveInCurrentScreen: @@ -1709,6 +1710,11 @@ Item { indicators: indicatorsManager } + LatteApp.Interfaces { + id: _interfaces + plasmoidInterface: plasmoid + } + ///////////////END ABILITIES ///////////////BEGIN TIMER elements diff --git a/shell/package/contents/views/Panel.qml b/shell/package/contents/views/Panel.qml index faba4750d..8ae331bc2 100644 --- a/shell/package/contents/views/Panel.qml +++ b/shell/package/contents/views/Panel.qml @@ -96,11 +96,6 @@ PlasmaCore.FrameSvgItem { for(var i=0; i