On Sun, 20 Aug 2017 07:18:44 -0400
Tony Morehen <tmore...@ajmconsulting.ca> wrote:

> 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
> 

Thanks, for that Tony, some good stuff in there (the least of which is that 
damned "hints" collection!) Since my original post and everyones comments I 
have spent more time reading than doing. So a few comments (in the most 
sincerest mode possible).

1. We (gambas "we") should strive for agnosticism. This class is very dependent 
on some specific implementations of the so called gnome "standard" which is 
turn looks very much like the "specification" for the (lousy) notify-osd 
daemon. ("lousy" because it was dumbed down so far that even Shuttleworth could 
understand it.) Your class is dependent on the notification daemon that is 
running on a machine to a) use DBus messaging the way those (ahem) standards 
and specifications state.  DE's that use non-compliant notification daemons are 
not supported by your code.  This is not a biggy, But one has to take care. 
Secondly, you are relying on the daemon DBus interface being called exactly 
"org.freedesktop.Notifications" which is fine for all the common ones but I did 
find one today (might have been for IceWM - can't remember?) that registers as 
"org.freedesktop.notify".

2. (Very specific) the code at line 114: result.Add(sa[3], 
"SpecificationVersion") is very specific to notify-osd. All the so called 
standards only refer to 3 required items being returned from 
GetServerInformation.

3. This "duration" parameter seems to be supported/interpreted/used/abused 
willy nilly by different daemons. In general, it "appears" that a value of 0 
tends to indicate a non-disappearing notification (but then again sometimes 
not). It "appears" that a value of -1 is generally used to do whatever the 
daemon designers thought might be a good idea. It appears that other values may 
or may not be used as a timeout period.  In short, 
apart from the actual libnotify library (which after all is only going to pass 
that value on to the display daemon) its' use is rarely "the timeout before a 
notification is closed" ( without user interaction).

4. One thing I did find that was quite good and apparently generally broadly 
implemented is the use of the so called "standard" desktop icon names e.g. 
instead of passing a fully qualified path to a specific icon you can send one 
of these "names". For example, setting IconPath to, say, "task-due" will use 
the task-due picture depending on the users actual active icon set. The names 
are at: 
https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html#names

5. Question: In the (little) amount of playing around today I am having trouble 
with the "replaces_id" parameter for the notify method, i.e your $iLastNotifyID 
returned by the Notify function.  All I ever seem to get back is zero?? The 
Ubuntu spec (for notify-osd) seems to be pretty quiet about this value, but 
then again they refer to it elsewhere as being of significant importance? any 
clues?

Finally, I have spent a couple of hours today building a skeleton component 
version of what you have put in one class.  Essentially, it exports two classes 
"CNotify" and "CMessage", CNotify is intended to be a facade to some (currently 
one) lower level worker classes that do the actual talking to the daemon. The 
"currently one" is the CDBusNotify class that is going to talk to ... gues 
what. This is sort of like the gb.gui aproach where your client project doesn't 
care what widget manager is actually being used. CMessage is really just a 
struct that carries the specific stuff for each "message"  around ( header, 
text and icon). Early days yet, but I'll be using a lot of your class code! So 
thanks again.

regards
bruce
-- 
B Bruen <adamn...@gnail.com (sort of)>

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to