Bug 378683 - org.kde.plasma.systemtray configKeys not accessible via plasma script api
Summary: org.kde.plasma.systemtray configKeys not accessible via plasma script api
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: System Tray (show other bugs)
Version: 5.9.4
Platform: Neon Linux
: NOR normal
Target Milestone: 1.0
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-12 07:07 UTC by Bernard Gray
Modified: 2020-01-06 11:18 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bernard Gray 2017-04-12 07:07:50 UTC
I'm trying to programmatically customise my corporate desktop environment, which involves hiding a few systemtray items. 

I start up the interactive scripting console as per:
qdbus org.kde.plasmashell /PlasmaShell showInteractiveConsole

My script to interrogate the systemtray widget looks like: 
==========
panel = panels()['0'];
for (var j in panel.widgetIds) {
    var widget = panel.widgetById(panel.widgetIds[j]);
    print(widget.configKeys);
    if (widget.type == "org.kde.plasma.systemtray") {
        print(widget.type);
        print(widget.configGroups);
        widget.currentConfigGroup = ["General"];
        print(widget.currentConfigGroup);
        print(widget.configKeys);
    }
}
==========

This output should contain a bunch of configKeys such as:
* applicationStatusShown
* communicationsShown
* extraItems
* knownItems
* hiddenItems

but I'm not seeing *any*. 

I can also writeConfig("$rand_configKey", "some_value"); and it doesn't error, but it also doesn't change anything.
Comment 1 David Edmundson 2017-04-12 11:56:43 UTC
The system tray is implemented a bit specially. There's an applet, but then that applet links to a containment which then has the configuration you want to edit.

Try this:

panel = panels()['0'];
for (var j in panel.widgetIds) {
    var widget = panel.widgetById(panel.widgetIds[j]);
    sysTrayId = widget.readConfig("SystrayContainmentId", -1);
    if (sysTrayId > 0) {
         var containment = desktopById(sysTrayId);
         containment.currentConfigGroup = ["General"];
         print(containment.configKeys);
         //Your writeConfig code here
    }
}


The fact that we're calling "desktopById" is a bit weird and confusing on our part, it's more just genericContainmentById 

Note also that we don't list configKeys if they match the default as they're not in the conifg file (though maybe we could/should)
Comment 2 Bernard Gray 2017-04-13 00:40:06 UTC
Hi David, 
Thank you so much - that's really helpful!

I've hit one more (hopefully related) snag - so I've got the correct containment now, I can manipulate the widgets that appear in the systemtray, but I'm now having difficult setting the [Auto|Hidden|Shown] immutability(?) configKey on a per widget/applet level.

To clarify, at the SystemTray level the applets can be set to appear or not appear (this is what you've given me access to already) -
At an applet level, they can be set to Appear in the main tray (Shown), Appear in the popup dialog when you click on the SystemTray arrow (Hidden), or work it out for themselves (Auto).

I believe the key for this setting is "immutability", but I can't seem to find how to access this key now - code snippet:

===========
panel = panels()['0'];
for (var j in panel.widgetIds) {
    var widget = panel.widgetById(panel.widgetIds[j]);
    sysTrayId = widget.readConfig("SystrayContainmentId", -1);
    if (sysTrayId > 0) {
        var containment = desktopById(sysTrayId);
        containment.currentConfigGroup = ["General"];
        print(containment.configKeys);
        print(containment.widgetIds);
        for (var w in containment.widgetIds) {
            var cwidget = containment.widgetById(containment.widgetIds[w]);
            print(cwidget.type);
            print(cwidget.configGroups);
            print(cwidget.configKeys);
        }
    }
}
================

cwidget.configGroups and cwidget.configKeys are empty - even after manually setting some different immutability's on various systray widgets - can I be so bold as to ask for another pointer on how to get into these settings?

Thanks -
Comment 3 Bernard Gray 2017-04-13 06:52:09 UTC
Argh! Lastly, there seems to be quite a bit of lag between creating the systemtray widget, and being able to reference/modify it's configKeys - 

eg, the following code does not actually apply/honour any of the configs I write, if executed as per below:
===============
var panel = new Panel();
var widget = panel.addWidget("org.kde.plasma.systemtray");
var sysTrayId = widget.readConfig("SystrayContainmentId", -1);
if (sysTrayId > 0) {
    print(sysTrayId);
    var containment = desktopById(sysTrayId);
    containment.currentConfigGroup = ["General"];
    var showns = [  "org.kde.discovernotifier",
                    "org.kde.kdeconnect",
                    "org.kde.plasma.bluetooth" ,
                    "org.kde.plasma.clipboard" ,
                    "org.kde.plasma.devicenotifier" ,
                    "org.kde.plasma.mediacontroller" ,
                    "org.kde.plasma.networkmanagement" ,
                    "org.kde.plasma.notifications" ,
                    "org.kde.plasma.printmanager" ,
                    "org.kde.plasma.volume"
                    ];

    var hiddens = [ "org.kde.plasma.battery" ,
                    "org.kde.plasma.ktp-contactlist"
                    ];
    containment.writeConfig("extraItems", showns);
    containment.writeConfig("hiddenItems", hiddens);
} 
================

If instead of creating a new panel, I grab the systray from an existing panel, it applies fine...
Comment 4 David Edmundson 2017-04-24 01:40:04 UTC
In what way is it not honoured?

What does the config end up being saved as afterwards?


Based on your code and system tray code, you will get some additional items added to your "extraItems" list as it will also include anything that has enabledByDefault checked
Comment 5 Bernard Gray 2017-04-28 05:43:14 UTC
The config looks as follows after running the script as described above (new panel, add systemtray widget, write systemtray configs):

=============
[Containments][22][General]
extraItems=org.kde.discovernotifier,org.kde.kdeconnect,org.kde.plasma.bluetooth,org.kde.plasma.clipboard,org.kde.plasma.devicenotifier,org.kde.plasma.mediacontroller,org.kde.plasma.networkmanagement,org.kde.plasma.notifications,org.kde.plasma.printmanager,org.kde.plasma.volume,org.kde.ktp-contactlist,org.kde.plasma.battery
hiddenItems=org.kde.plasma.battery,org.kde.plasma.ktp-contactlist
knownItems=org.kde.kdeconnect,org.kde.ktp-contactlist,org.kde.plasma.battery,org.kde.plasma.clipboard,org.kde.plasma.devicenotifier,org.kde.plasma.mediacontroller,org.kde.plasma.networkmanagement,org.kde.plasma.notifications,org.kde.plasma.printmanager,org.kde.plasma.volume
=============

Which looks normal, except the widgets which are explicitly listed under the hiddenItems key are still visible on the newly created panel (battery, ktp-contactlist).
Comment 6 Konrad Materka 2020-01-03 15:03:39 UTC
Is the original issue still affecting you?
Comment 7 Bernard Gray 2020-01-05 22:10:30 UTC
Hi Konrad, 
Apologies, I forgot about this. I'm not sure there was an actual issue in the end, so this should be fine to close - appreciate the assistance!