hi,
I’m not a developer (it’s been a week since I started learning to code), I’m trying to understand, it’s hard.
I’m trying to create a plasmoid on/off switch, I managed to make it work but I’ve been trying for more than 4 days to add a simple passive popup like this :
to indicate the change of state of the switch but I achieves nothing.
but in .qml I couldn’t do it, I also tried to understand Knotification but barely lost the documentation is so hard to understand, it gives the impression that the KDE devs who wrote their documentation don’t want that the general public understands, the language barrier doesn’t help me either (I’m French)
This “passive popup” feature you talk about is called “notifications”. The API to implement this in KDE is called KNotifications.
The documentation for KNotifications QML API seems pretty straight forward: import org.kde.notifications; create a Notification object with the properties you need; update its text and/or title fields as needed; call sendEvent() to trigger the notification.
Which of these is giving your problems, what specific errors or unexpected behavior did you encounter and can you show what you did and didn’t work for you?
I tried to integrate KNotifications following this same doc to test but I got an error which tells me:
kf.notifications: No event config could be found for event id “led_on” under notifyrc file for app “Switch-Toggle”
I searched on the internet and it says that this file is not found in /root, I did not find it (I am using KDE Neon) and I find it strange to have for plasmoid to touch files in /root for a simple passive notification.
Here is my complete code, sorry it’s very ugly, I’m a beginner:
That does not seem like a good explanation. I’m pretty sure that wherever you read that - it was wrong. The /root directory is the home directory for the administrator, and unless you are running as the administrator account (which you shouldn’t and I’m not even sure that you can in modern operating systems), then that is irrelevant.
Ok, I see where the problem is. The KNotifications QML manual assume that you have read the main KNotifications manual and knows how KNotifications work and just need to get it running in QML. I think its a valid assumption.
If you review the above linked document you’ll see that for KNotifications to work you need to have a file called YOURCOMPONENT.notifyrc installed into the KNotifications state directory. The document describes how to create that file and what should be in it, though it doesn’t say in which directory to put the file in - it says “It needs to be installed to knotifications5/appname.notifyrc in a QStandardPaths::GenericDataLocationdirectory” which may not mean much to new developers, so it may worth it to put some time into explaining directory locations:
The QStandardPaths is a mechanism to help developers put things in directories that make sense according to the Linux Filesystem Heirarchy Standard. The Qt implementation of that offers several categories to match the different places in the FSH that applications are expected to put stuff in - you can see the full list by running qtpaths --types or just looking at the linked reference. The GenericDataLocation is where applications should put their state data, into specific folders per application. KNotifications state data (the .notifyrc files) should go into either ${GenericDataLocation}/knotifications5 if you are using Knotifications for Plasma 5 or ${GenericDataLocation}/knotifications6 if you are using it on Plasma 6.
The user’s GenericDataLocation is normally ~/.local/share(*), so if you are developing your plasma widget locally to install into your user account, you use Plasma 6, and you call your component “Switch-Toggle” then you should create the file in ~/.local/share/knotifications6/Switch-Toggle.notifyrc and put the notifications configuration for it.
*) To see other potential GenericDataLocation paths you have on your system, you can run qtpaths --paths GenericDataLocation - this will list a bunch of directory in “PATH” format, i.e. in one line delimited by a colon (“:”).
It works !!! After creating the file: Switch-Toggle.notifyrc in home: .local/share/knotifications6/ in which I put:
[Global]
IconName=folder-appimage
Name=Switch-Toggle
Comment=Switch on/off
DesktopEntry=Switch-Toggle
[Event/led_on]
Name=Switch: Commande activée
Comment=La commande a été exécutée
Sound=Oxygen-Sys-Trash-Emptied.ogg
Action=Popup
Urgency=Low
Do I really have to put this file in: .local/share/knotifications6/?
I mean, isn’t it possible to put the file in the Plasmoid files and make it tell Knotification is located in exemple : .local/share/plasma/plasmoids/Switch-Toggle/contents/ui/?
Because if I want to share the plasmoid I will have to create an installer, that complicates my task, I have never done that.
Thank you so much for your help, I will be sure to mention you if I share it.
The main reason for installing the notifyrc file in the knotifications general data directory, is that you want to allow the user to configure the application notifications (change sounds, control history, enable in d-n-d mode, etc) so you want a way for the Notifications System Settings module to know about all the applications that can show notifications (you can see them by clicking Configure under Application-specific Settings).
There was some discussions about making the notifyrc file optional (for example) but as far as i know nothing came out of it, as of yet.