Re: [Gambas-user] Class Implementing DBus Notifications

2017-08-20 Thread Tony Morehen
I saw that.  As far as I could tell, it's identical to the gnome 
discussion.  Including having the hints category and urgency discussion 
before the hints chapter!



On 2017-08-20 12:06 PM, adamn...@gmail.com wrote:

On Sun, 20 Aug 2017 11:37:38 -0400
Tony Morehen  wrote:


1)  I tried to be as agnostic as possible.  The reference to the Gnome
developer's specification is there because it is the only one available
on the web.

http://www.galago-project.org/specs/notification/0.9/index.html
seems to the one for the notify-osd "spec" but there is at least a 1.1 version 
around somewhere. Can't find it though.

There is not even one on freedesktop.org.  It is my
understanding that modern DEs conform to that spec, including KDE,
Gnome, Cinnamon, XFCE etc.  If the server supports a current libnotify,
then is should support my code. Btw, I'm running Xfce on Manjaro.  Wrt

 etc

cheers
b




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


Re: [Gambas-user] Class Implementing DBus Notifications

2017-08-20 Thread adamn...@gmail.com
On Sun, 20 Aug 2017 11:37:38 -0400
Tony Morehen  wrote:

> 1)  I tried to be as agnostic as possible.  The reference to the Gnome 
> developer's specification is there because it is the only one available 
> on the web.  
http://www.galago-project.org/specs/notification/0.9/index.html
seems to the one for the notify-osd "spec" but there is at least a 1.1 version 
around somewhere. Can't find it though.
> There is not even one on freedesktop.org.  It is my 
> understanding that modern DEs conform to that spec, including KDE, 
> Gnome, Cinnamon, XFCE etc.  If the server supports a current libnotify, 
> then is should support my code. Btw, I'm running Xfce on Manjaro.  Wrt 
 etc

cheers
b
-- 
B Bruen 

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


Re: [Gambas-user] Class Implementing DBus Notifications

2017-08-20 Thread Tony Morehen
1)  I tried to be as agnostic as possible.  The reference to the Gnome 
developer's specification is there because it is the only one available 
on the web.  There is not even one on freedesktop.org.  It is my 
understanding that modern DEs conform to that spec, including KDE, 
Gnome, Cinnamon, XFCE etc.  If the server supports a current libnotify, 
then is should support my code. Btw, I'm running Xfce on Manjaro.  Wrt 
Icewm, Icewm has not been updated since 2011.  It probably implements an 
old version of the spec.  People have my code they can change to suit 
their needs.   I recommend D-feet as a Dbus explorer, so people can see 
what application names, paths and interfaces to use.


2) Yes, this was a slip on my part.  My daemon returns the 4 parts that 
I coded for, but in the back of my mind I knew that only 3 were 
official.  I've changed the code to make SpecificationVersion optional.


3) I've added 0 = no timeout to the comments on duration. Another 
oversight.  Yes, some daemons ignore the Duration variable.  In fact 
they can ignore almost any of the Send parameters.  So providing a value 
may be wishful thinking, but at least it won't generate an error.


4) You're right, you can use standard icon names.  I've renamed the 
property to IconNameOrPath and the comment to reflect this. I'd insisted 
on full path because that was the only thing that worked for me.  The 
iconname I was using was drive-harddisk-usb, which is an icon in my 
theme.  It turns out that is a non-standard icon and so needs a full 
path to work.  When I shortened it to drive-harddisk, the simple name 
worked.


5) NotifyID is supposed to be a unique unsigned integer, starting at 0 
and increasing by one for each notification message that occurs during 
the session.  You need such an Id to replace a current notification or 
to close an open one, particularly a non-expiring one.  In my system, 
that is exactly what occurs.  For example, in my AutoMount program, when 
I plug in a drive, device added pops up, which is then replaced by drive 
mounted.  I use 2 separate notifications because mounting can take some 
time.


Anyway, attached is a revised class.


On 2017-08-20 10:19 AM, adamn...@gmail.com wrote:
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 

Re: [Gambas-user] Class Implementing DBus Notifications

2017-08-20 Thread adamn...@gmail.com
On Sun, 20 Aug 2017 07:18:44 -0400
Tony Morehen  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 

[Gambas-user] Class Implementing DBus Notifications

2017-08-20 Thread Tony Morehen
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



dbusNotify.class
Description: application/java
--
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