[Gambas-user] Class Implementing DBus Notifications
Tony Morehen
tmorehen at ...3602...
Sun Aug 20 13:18:44 CEST 2017
As promised, attached is a heavily commented class implementing DBus
Notifications. It is a complete implementation of the specification.
There are two approaches to using the class:
1) fill in the properties and call SendNotification:
Dim hDbusNotify As New DbusNotify
hDbusNotify.Summary = "Device added:"
hDbusNotify.Body = "/dev" &/ device
hDbusNotify.FullPathToIcon = icon
hDbusNotify.Actions = [""]
notifyID = dbusNotify.SendNotification()
mount = UDisks2.Mount(device)
hDbusNotify.Summary = "Device mounted:"
hDbusNotify.Body = "/dev" &/ device & " to " & mount
hDbusNotify.Actions = ["browse=" & mount, "Browse"]
hints.Add(2, "urgency")
hDbusNotify.Hints = hints
hDbusNotify.Duration = 5000
notifyID = dbusNotify.SendNotification(notifyID)
2) Use the Notify function directly:
Dim hDbusNotify As New DbusNotify
Dim hints As New Collection
hints.Add("device.removed", "category")
hDbusNotify.Notify("Device removed:", "/dev" &/ device, icon,
[""], 0, hints, 5000)
DbusNotify raises 2 events:
Public Sub dbusNotify_ActionInvoked(iNotifyID As Integer, sActionKey As
String)
If Left(LCase(sActionKey), 7) = "browse=" Then
'want to ensure a trailing "/"
sActionKey = "file://" & Trim(Mid(sActionKey, 8) &/ " ")
Shell "xdg-open " & sActionKey
Endif
End
Public Sub dbusNotify_NotificationClosed(iNotifyID As Integer, iReason
As Integer)
'Usually ignored
End
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dbusNotify.class
Type: application/x-java
Size: 7171 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20170820/d11842ba/attachment.bin>
More information about the User
mailing list