Reply to topic

Strange error with onSourceAdded

robertju
Registered Member
Posts
1
Karma
0

Strange error with onSourceAdded

Wed Feb 06, 2019 9:24 pm
Hi, I'm totally new to the KDE world. First thing what I miss here is system monitor applet/indicator (you call it plasmoid widget in KDE I guess...). So the easiest way is write it on my own, right?
I have written something quite usable, but now I'm stuck on strange behavior. Everything works quite well, but on my OpenSuse Tumbleweed at home, PlasmaCore.DataSource.onSourceAdded is never called while in panel. When I debug the applet with plasmoidviewer -a, it works well. Everything also works in my (k)ubuntu at work.
Here is as simplified code as possible (by a newbie). When you uncomment the row // connectedSources: ['cpu/system/user'], you can have at least data for items in the list. My problem is with the network items, which I can't just write as a list like this.
Am I doing something wrong, or is it a bug?

Code: Select all
import QtQuick 2.2
import QtQuick.Layouts 1.1
import QtGraphicalEffects 1.0
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents


Item {
    id: main
   
    Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
   
    property var regexp: /^network\/interfaces\/(?!lo\/)\w+\/(transmitter|receiver)\/(data)$/
   
    PlasmaComponents.Label {
        id: text2
        text: 'change me'
    }

    PlasmaCore.DataSource {
        id: dataSource
        engine: "systemmonitor"
       
        // connectedSources: ['cpu/system/user']
       
        onNewData: {
            text2.text = sourceName;
        }
        onSourceAdded: {
            console.log('WWWWWWWWWWW', source);
            if (source.match(regexp)) {
                dataSource.connectSource(source);
            }
        }
        onSourceRemoved: {
            if (source.match(regexp)) {
                dataSource.disconnectSource(source);
            }
        }
        interval: 1000
    }
   
}

Reply to topic

Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], boudewijn, duns, Exabot [Bot], Google [Bot], interele, retnev, Rytelier, Snudl