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
pull/1/head
Michail Vourlakos 8 years ago
parent aa794ff2e3
commit 4f030849f0

@ -3,5 +3,9 @@
<interface name="org.kde.LatteDock">
<method name="activateLauncherMenu">
</method>
<method name="updateDockItemBadge">
<arg name="identifier" type="s" direction="in"/>
<arg name="value" type="s" direction="in"/>
</method>
</interface>
</node>

@ -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<QQuickItem *>()) {
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<QScreen>();

@ -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);

@ -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
}

@ -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 /////

@ -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();

@ -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;
}
}
}
}
}

@ -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<badgers.length; ++i) {
if (badgers[i].id === result) {
return badgers[i];
}
}
}
function updateBadge(identifier, value) {
var tasks = icList.contentItem.children;
var identifierF = identifier.concat(".desktop");
for(var i=0; i<tasks.length; ++i){
var task = tasks[i];
if (task && task.launcherUrl && task.launcherUrl.indexOf(identifierF) >= 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) {

Loading…
Cancel
Save