support plasma tasks model for tracking

pull/15/head
Michail Vourlakos 5 years ago
parent 76781094af
commit 99db4d54f2

@ -47,6 +47,7 @@ ContainmentInterface::ContainmentInterface(Latte::View *parent)
m_corona = qobject_cast<Latte::Corona *>(m_view->corona());
m_latteTasksModel = new TasksModel(this);
m_plasmaTasksModel = new TasksModel(this);
m_appletsExpandedConnectionsTimer.setInterval(2000);
m_appletsExpandedConnectionsTimer.setSingleShot(true);
@ -56,7 +57,7 @@ ContainmentInterface::ContainmentInterface(Latte::View *parent)
connect(m_view, &View::containmentChanged
, this, [&]() {
if (m_view->containment()) {
connect(m_view->containment(), &Plasma::Containment::appletAdded, this, &ContainmentInterface::updateAppletsTracking);
connect(m_view->containment(), &Plasma::Containment::appletAdded, this, &ContainmentInterface::on_appletAdded);
m_appletsExpandedConnectionsTimer.start();
}
@ -479,6 +480,11 @@ QAbstractListModel *ContainmentInterface::latteTasksModel() const
return m_latteTasksModel;
}
QAbstractListModel *ContainmentInterface::plasmaTasksModel() const
{
return m_plasmaTasksModel;
}
void ContainmentInterface::on_appletExpandedChanged()
{
PlasmaQuick::AppletQuickItem *appletItem = static_cast<PlasmaQuick::AppletQuickItem *>(QObject::sender());
@ -525,44 +531,34 @@ void ContainmentInterface::updateAppletsTracking()
}
for (const auto applet : m_view->containment()->applets()) {
if (m_view->layout() && m_view->layout()->isInternalContainment(applet)) {
//! internal containment case
Plasma::Containment *internalC = m_view->layout()->internalContainmentOf(applet);
PlasmaQuick::AppletQuickItem *contAi = applet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
if (contAi && !m_appletsExpandedConnections.contains(contAi)) {
m_appletsExpandedConnections[contAi] = connect(contAi, &PlasmaQuick::AppletQuickItem::expandedChanged, this, &ContainmentInterface::on_appletExpandedChanged);
on_appletAdded(applet);
}
}
connect(contAi, &QObject::destroyed, this, [&, contAi](){
m_appletsExpandedConnections.remove(contAi);
removeExpandedApplet(contAi->applet()->id());
});
}
void ContainmentInterface::on_appletAdded(Plasma::Applet *applet)
{
if (!m_view->containment() || !applet) {
return;
}
for (const auto internalApplet : internalC->applets()) {
PlasmaQuick::AppletQuickItem *ai = internalApplet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
if (m_view->layout() && m_view->layout()->isInternalContainment(applet)) {
//! internal containment case
Plasma::Containment *internalC = m_view->layout()->internalContainmentOf(applet);
PlasmaQuick::AppletQuickItem *contAi = applet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
if (ai && !m_appletsExpandedConnections.contains(ai) ){
m_appletsExpandedConnections[ai] = connect(ai, &PlasmaQuick::AppletQuickItem::expandedChanged, this, &ContainmentInterface::on_appletExpandedChanged);
if (contAi && !m_appletsExpandedConnections.contains(contAi)) {
m_appletsExpandedConnections[contAi] = connect(contAi, &PlasmaQuick::AppletQuickItem::expandedChanged, this, &ContainmentInterface::on_appletExpandedChanged);
connect(ai, &QObject::destroyed, this, [&, ai](){
m_appletsExpandedConnections.remove(ai);
removeExpandedApplet(ai->applet()->id());
});
}
}
} else {
PlasmaQuick::AppletQuickItem *ai = applet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
if (!ai) {
continue;
}
connect(contAi, &QObject::destroyed, this, [&, contAi](){
m_appletsExpandedConnections.remove(contAi);
removeExpandedApplet(contAi->applet()->id());
});
}
KPluginMetaData meta = applet->kPackage().metadata();
for (const auto internalApplet : internalC->applets()) {
PlasmaQuick::AppletQuickItem *ai = internalApplet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
if (meta.pluginId() == "org.kde.latte.plasmoid") {
m_latteTasksModel->addTask(ai);
} else if (!m_appletsExpandedConnections.contains(ai)) {
if (ai && !m_appletsExpandedConnections.contains(ai) ){
m_appletsExpandedConnections[ai] = connect(ai, &PlasmaQuick::AppletQuickItem::expandedChanged, this, &ContainmentInterface::on_appletExpandedChanged);
connect(ai, &QObject::destroyed, this, [&, ai](){
@ -571,7 +567,32 @@ void ContainmentInterface::updateAppletsTracking()
});
}
}
} else {
PlasmaQuick::AppletQuickItem *ai = applet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
if (!ai) {
return;
}
KPluginMetaData meta = applet->kPackage().metadata();
const auto &provides = KPluginMetaData::readStringList(meta.rawData(), QStringLiteral("X-Plasma-Provides"));
if (meta.pluginId() == "org.kde.latte.plasmoid") {
//! populate latte tasks applet
m_latteTasksModel->addTask(ai);
} else if (provides.contains(QLatin1String("org.kde.plasma.multitasking"))) {
//! populate plasma tasks applet
m_plasmaTasksModel->addTask(ai);
} else if (!m_appletsExpandedConnections.contains(ai)) {
m_appletsExpandedConnections[ai] = connect(ai, &PlasmaQuick::AppletQuickItem::expandedChanged, this, &ContainmentInterface::on_appletExpandedChanged);
connect(ai, &QObject::destroyed, this, [&, ai](){
m_appletsExpandedConnections.remove(ai);
removeExpandedApplet(ai->applet()->id());
});
}
}
}

@ -30,6 +30,10 @@
#include <QQuickItem>
#include <QTimer>
namespace Plasma {
class Applet;
}
namespace PlasmaQuick {
class AppletQuickItem;
}
@ -39,7 +43,6 @@ class Corona;
class View;
}
namespace Latte {
namespace ViewPart {
@ -49,6 +52,7 @@ class ContainmentInterface: public QObject
Q_PROPERTY(bool hasExpandedApplet READ hasExpandedApplet NOTIFY hasExpandedAppletChanged)
Q_PROPERTY(QAbstractListModel *latteTasksModel READ latteTasksModel() NOTIFY latteTasksModelChanged)
Q_PROPERTY(QAbstractListModel *plasmaTasksModel READ plasmaTasksModel() NOTIFY plasmaTasksModelChanged)
public:
ContainmentInterface(Latte::View *parent);
@ -78,6 +82,7 @@ public:
int appletIdForIndex(const int index);
QAbstractListModel *latteTasksModel() const;
QAbstractListModel *plasmaTasksModel() const;
public slots:
Q_INVOKABLE void deactivateApplets();
@ -90,12 +95,14 @@ signals:
void hasExpandedAppletChanged();
void expandedAppletStateChanged();
void latteTasksModelChanged();
void plasmaTasksModelChanged();
private slots:
void identifyMainItem();
void identifyMethods();
void updateAppletsTracking();
void on_appletAdded(Plasma::Applet *applet);
void on_appletExpandedChanged();
private:
@ -119,6 +126,7 @@ private:
QTimer m_appletsExpandedConnectionsTimer;
TasksModel *m_latteTasksModel;
TasksModel *m_plasmaTasksModel;
QHash<PlasmaQuick::AppletQuickItem *, QMetaObject::Connection> m_appletsExpandedConnections;
QList<int> m_expandedAppletIds;

@ -22,6 +22,9 @@
// Qt
#include <QDebug>
// Plasma
#include <PlasmaQuick/AppletQuickItem>
namespace Latte {
namespace ViewPart {
@ -61,7 +64,7 @@ QHash<int, QByteArray> TasksModel::roleNames() const{
return roles;
}
void TasksModel::addTask(QObject *plasmoid)
void TasksModel::addTask(PlasmaQuick::AppletQuickItem *plasmoid)
{
if (plasmoid && m_tasks.contains(plasmoid)) {
return;
@ -78,7 +81,7 @@ void TasksModel::addTask(QObject *plasmoid)
emit countChanged();
}
void TasksModel::removeTask(QObject *plasmoid)
void TasksModel::removeTask(PlasmaQuick::AppletQuickItem *plasmoid)
{
if (!plasmoid || (plasmoid && !m_tasks.contains(plasmoid))) {
return;

@ -22,6 +22,10 @@
#include <QAbstractListModel>
namespace PlasmaQuick {
class AppletQuickItem;
}
namespace Latte {
namespace ViewPart {
@ -39,14 +43,14 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
void addTask(QObject *plasmoid);
void removeTask(QObject *plasmoid);
void addTask(PlasmaQuick::AppletQuickItem *plasmoid);
void removeTask(PlasmaQuick::AppletQuickItem *plasmoid);
signals:
void countChanged();
private:
QList<QObject *> m_tasks;
QList<PlasmaQuick::AppletQuickItem *> m_tasks;
};
}

Loading…
Cancel
Save