DBus notify images

Post your Gambas programming questions here.
Post Reply
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

DBus notify images

Post by BruceSteers »

Has anyone managed to use the "icon" property when using DBus DesktopPortal.Notify ?



I've tried various methods
I've read the docs here https://docs.flatpak.org/en/latest/port ... tification
portal docs wrote: icon v

Serialized icon (see g_icon_serialize()).

The portal only accepts serialized GThemedIcon and GBytesIcons.
Both of these have the form (sv).
For themed icons, the string is "themed", and the value is an array of strings containing the icon names.
For bytes icons, the string is "bytes", and the value is a bytestring containing the icon data in png, jpeg or svg form.
For historical reasons, it is also possible to send a simple string for themed icons with a single icon name.

There may be further restrictions on the supported kinds of icons.
  Dim cNotification As Collection
  Dim s As String = User.Home & "/Pictures/Me.png"

  cNotification = ["icon": ["themed": s], "title": Title, "body": "\n" & Text & "\n", "priority": $aPriorities[Priority]]
  DBus["session://org.freedesktop.portal.Desktop"]["/org/freedesktop/portal/desktop", "org.freedesktop.portal.Notification"].AddNotification(Application.Id, cNotification)



I've tried as an array [s]
Ive tried as a direct string
  Dim s As String = File.Load(User.Home & "/Pictures/Me.png")
  cNotification = ["icon": ["bytes": s], "title": Title, "body": "\n" & Text & "\n", "priority": $aPriorities[Priority]]


looking like i may need extern library function to get g_icon_serialize() and make a proper GIcon
:(

Or to find someone who knows a way to do this :roll: :)
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: DBus notify images

Post by BruceSteers »

I'm making an alternative to Message.class that uses DBus notify

This is it in action..
Screenshot at 2023-11-25 21-14-54.png
Screenshot at 2023-11-25 21-14-54.png (139.12 KiB) Viewed 7249 times

really need to be able to make images show though.

Currently i have DBMessage.Info() and DBMessage.Question() but want images to enable others like Error.
DBMessage.Question(Title As String, Text As String, Buttons As String[], Optional {Default} As Integer = -1) As Integer


There's property DBMessage.Wait that if true DBMessage.Question() will wait for selection then return the value

if false then the program can continue and the static DBMessage_Click() event is used. (if not Wait then the message can and will timeout)
The form that will get the DBMessage_Click() event can be set using the DBMessage.AttachTo property otherwise it uses either Application.MainWindow or if not set Windows[0].

There is no way to tell if a notification has timed out so to enable "Wait" i am using a trick that just cancels and resends the notification every 6 seconds.
notifications normally timeout in 7 seconds on my machine so i redo the notification until the user interacts.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: DBus notify images

Post by BruceSteers »

So I figured something out.

I was trying my code with the icon name "question" thinking that was a stock icon name.
I was wrong and the stock icon i was looking for was called dialog-question :-\

So it turns out you can add icons by simply giving a icon name., i think the available icon name vary on theme being used.
I found the official list from freedesktop https://specifications.freedesktop.org/ ... 01s04.html

so for notify with a question image i just need to add ["icon": "dialog-question"] to the collection.
If at first you don't succeed , try doing something differently.
BruceS
Post Reply