From 4f030849f02fe6569e90a5bcf63a367339f2d5b9 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Tue, 11 Apr 2017 20:23:43 +0300 Subject: [PATCH] expose through dbus updateBadge for dock items --apps can sent through dbus and identificator e.g. "kmail" and a value for unread mails e.g.2 Latte afterwards will update that specific badger --- app/dbus/org.kde.LatteDock.xml | 4 ++ app/dockcorona.cpp | 52 ++++++++++++++++++++ app/dockcorona.h | 1 + plasmoid/contents/ui/CircleText.qml | 17 +++++-- plasmoid/contents/ui/TaskDelegate.qml | 11 +++++ plasmoid/contents/ui/TaskIconItem.qml | 4 +- plasmoid/contents/ui/TaskProgressOverlay.qml | 14 +++++- plasmoid/contents/ui/main.qml | 35 +++++++++++++ 8 files changed, 129 insertions(+), 9 deletions(-) diff --git a/app/dbus/org.kde.LatteDock.xml b/app/dbus/org.kde.LatteDock.xml index 30fe479b3..e941553d9 100644 --- a/app/dbus/org.kde.LatteDock.xml +++ b/app/dbus/org.kde.LatteDock.xml @@ -3,5 +3,9 @@ + + + + diff --git a/app/dockcorona.cpp b/app/dockcorona.cpp index 21e975fec..2a006b3c5 100644 --- a/app/dockcorona.cpp +++ b/app/dockcorona.cpp @@ -1186,6 +1186,58 @@ void DockCorona::activateTaskManagerEntry(int index, Qt::Key modifier) } +//! update badge for specific dock item +void DockCorona::updateDockItemBadge(QString identifier, QString value) +{ + qDebug() << "DBUS CALL ::: " << identifier << " - " << value; + auto updateBadgeForTaskInContainment = [this](const Plasma::Containment * c, QString identifier, QString value) { + const auto &applets = c->applets(); + + for (auto *applet : applets) { + KPluginMetaData meta = applet->kPackage().metadata(); + + if (meta.pluginId() == "org.kde.latte.plasmoid") { + + if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value()) { + const auto &childItems = appletInterface->childItems(); + + if (childItems.isEmpty()) { + continue; + } + + for (QQuickItem *item : childItems) { + if (auto *metaObject = item->metaObject()) { + // not using QMetaObject::invokeMethod to avoid warnings when calling + // this on applets that don't have it or other child items since this + // is pretty much trial and error. + // Also, "var" arguments are treated as QVariant in QMetaObject + + int methodIndex = metaObject->indexOfMethod("updateBadge(QVariant,QVariant)"); + + if (methodIndex == -1) { + continue; + } + + QMetaMethod method = metaObject->method(methodIndex); + + if (method.invoke(item, Q_ARG(QVariant, identifier), Q_ARG(QVariant, value))) { + return true; + } + } + } + } + } + } + + return false; + }; + + // update badges in all Latte Tasks plasmoids + for (auto it = m_dockViews.constBegin(), end = m_dockViews.constEnd(); it != end; ++it) { + updateBadgeForTaskInContainment(it.key(), identifier, value); + } +} + inline void DockCorona::qmlRegisterTypes() const { qmlRegisterType(); diff --git a/app/dockcorona.h b/app/dockcorona.h index 2da04714b..1b4b54509 100644 --- a/app/dockcorona.h +++ b/app/dockcorona.h @@ -83,6 +83,7 @@ public slots: void activateLauncherMenu(); void loadDefaultLayout() override; void dockContainmentDestroyed(QObject *cont); + void updateDockItemBadge(QString identifier, QString value); signals: void configurationShown(PlasmaQuick::ConfigView *configView); diff --git a/plasmoid/contents/ui/CircleText.qml b/plasmoid/contents/ui/CircleText.qml index aa6072223..465154295 100644 --- a/plasmoid/contents/ui/CircleText.qml +++ b/plasmoid/contents/ui/CircleText.qml @@ -22,6 +22,8 @@ import QtQuick 2.2 import QtGraphicalEffects 1.0 +import org.kde.plasma.plasmoid 2.0 + Rectangle { property double proportion: 0 @@ -45,7 +47,7 @@ Rectangle { property color alphaBackColor: Qt.rgba(theme.backgroundColor.r, theme.backgroundColor.g, theme.backgroundColor.b, 0.45) property color alphaBackColor2: Qt.rgba(theme.backgroundColor.r, theme.backgroundColor.g, theme.backgroundColor.b, 0.8) - color: alphaBackColor + color: mainItemContainer.badgeIndicator > 0 ? alphaBackColor2 : alphaBackColor radius: width border.width: Math.max(1,width/64) border.color: alphaBackColor2 @@ -76,14 +78,18 @@ Rectangle { width: parent.width - 2 * parent.border.width height: parent.height - 2 * parent.border.width - opacity: 0.7 + opacity: proportion > 0 ? 1 : 0 anchors.centerIn: parent + property color drawColor: mainItemContainer.badgeIndicator > 0 ? theme.buttonFocusColor : theme.highlightColor; + + onDrawColorChanged: requestPaint(); + onPaint: { var ctx = getContext('2d'); ctx.clearRect(0, 0, canvas.width, canvas.height); - ctx.fillStyle = theme.highlightColor; + ctx.fillStyle = drawColor; var startRadian = - Math.PI / 2; @@ -102,8 +108,9 @@ Rectangle { id: valueText anchors.centerIn: parent text: numberValue - font.pixelSize: fontPixelSize - color: theme.textColor + font.pixelSize: 0.6 * parent.height + font.bold: true + color: mainItemContainer.badgeIndicator > 0 ? theme.backgroundColor : theme.textColor visible: showNumber } diff --git a/plasmoid/contents/ui/TaskDelegate.qml b/plasmoid/contents/ui/TaskDelegate.qml index 940f476a9..f41d9a0df 100644 --- a/plasmoid/contents/ui/TaskDelegate.qml +++ b/plasmoid/contents/ui/TaskDelegate.qml @@ -75,6 +75,7 @@ MouseArea{ property bool pressed: false property int animationTime: root.durationTime * 1.2 * units.shortDuration + property int badgeIndicator: 0 //it is used from external apps property int directAnimationTime: 0 property int hoveredIndex: icList.hoveredIndex property int itemIndex: index @@ -549,6 +550,16 @@ MouseArea{ checkWindowsStates(); } + onLauncherUrlChanged: { + var badger = root.getBadger(launcherUrl); + + if (badger && !isLauncher) { + badgeIndicator = badger.value; + } else { + badgeIndicator = 0; + } + } + ////// End of Values Changes ///// diff --git a/plasmoid/contents/ui/TaskIconItem.qml b/plasmoid/contents/ui/TaskIconItem.qml index 264995dee..500ca7e85 100644 --- a/plasmoid/contents/ui/TaskIconItem.qml +++ b/plasmoid/contents/ui/TaskIconItem.qml @@ -226,7 +226,7 @@ Item{ id: progressLoader anchors.fill: parent active: (centralItem.smartLauncherEnabled && centralItem.smartLauncherItem - && centralItem.smartLauncherItem.progressVisible) + && (centralItem.smartLauncherItem.progressVisible || mainItemContainer.badgeIndicator > 0)) asynchronous: true sourceComponent: Item{ @@ -291,7 +291,7 @@ Item{ //badgeMask } hideSource: true - live: false + live: mainItemContainer.badgeIndicator > 0 ? true : false } // onWidthChanged: mask.scheduleUpdate(); diff --git a/plasmoid/contents/ui/TaskProgressOverlay.qml b/plasmoid/contents/ui/TaskProgressOverlay.qml index a6e724692..984877cd7 100644 --- a/plasmoid/contents/ui/TaskProgressOverlay.qml +++ b/plasmoid/contents/ui/TaskProgressOverlay.qml @@ -56,10 +56,20 @@ Item { anchors.centerIn: parent width: 0.8 * parent.width height: width - numberValue: centralItem.smartLauncherItem.count + numberValue: mainItemContainer.badgeIndicator > 0 ? mainItemContainer.badgeIndicator : centralItem.smartLauncherItem.count fullCircle: true showNumber: true - proportion: centralItem.smartLauncherItem ? centralItem.smartLauncherItem.progress / 100 : 0 + proportion: { + if (mainItemContainer.badgeIndicator > 0) { + return 100; + } + + if (centralItem.smartLauncherItem) { + return centralItem.smartLauncherItem.progress / 100; + } else { + return 0; + } + } } } } diff --git a/plasmoid/contents/ui/main.qml b/plasmoid/contents/ui/main.qml index 051f41cdb..6343cb131 100644 --- a/plasmoid/contents/ui/main.qml +++ b/plasmoid/contents/ui/main.qml @@ -82,6 +82,10 @@ Item { property real textColorLuma: 0.2126*theme.textColor.r + 0.7152*theme.textColor.g + 0.0722*theme.textColor.b + //a small badgers record (id,value) + //in order to track badgers when there are changes + //in launcher reference from libtaskmanager + property variant badgers:[] property variant launchersOnActivities: [] property QtObject contextMenuComponent: Qt.createComponent("ContextMenu.qml"); @@ -1111,6 +1115,37 @@ Item { root.position = newPosition; } + function getBadger(identifier) { + var ident1 = identifier; + var n = ident1.lastIndexOf('/'); + var result = n>=0 ? ident1.substring(n + 1) : identifier; + + for(var i=0; i= 0) { + task.badgeIndicator = value === "" ? 0 : Number(value); + var badge = getBadger(identifierF); + if (badge) { + badge.value = value; + } else { + badgers.push({id: identifierF, value: value}); + } + } + } + } + function outsideContainsMouse(){ //console.log("disable restore zoom:"+disableRestoreZoom); if (disableRestoreZoom) {