[GB.DBUS]

* NEW: The application now registers to the DBus bus with its process id added to its name.
* NEW: DBus.Unique is a new property that sets if the application should be unique on the DBus bus. If set, then the process id is not added to the name when registering.
* BUG: If DBus.Unique is set, then registering the application a second time raises an error.


git-svn-id: svn://localhost/gambas/trunk@7779 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2016-05-14 15:59:31 +00:00
parent 0a0157878d
commit 9b13b69fda
5 changed files with 31 additions and 5 deletions

View file

@ -1,7 +1,7 @@
# Gambas Project File 3.0
# Compiled with Gambas 3.8.90
Title=Tray icons using the new DBus protocol
Startup=FTest
Startup=Main
Version=3.8.90
VersionFile=1
Component=gb.image

View file

@ -50,6 +50,7 @@ Public Sub Main()
' File.Save(Application.Path &/ "default.bin", String@(hImage.Data, hImage.W * hImage.H * SizeOf(gb.Integer)))
DBus.Debug = True
DBus.Unique = True
FTest.Show
End

View file

@ -1,4 +1,4 @@
FTest
Main
Tray icons using the new DBus protocol
0
0

View file

@ -7,9 +7,11 @@ Inherits _DBus
Static Property Name As String
Static Public _ApplicationCache As New Collection
Static Property Read Null As Object
Static Property Unique As Boolean
Static Private $sAppName As String
Static Private $iRegisterCount As Integer
Static Private $bUnique As Boolean
Static Public Sub _get((Application) As String) As DBusApplication
@ -71,7 +73,13 @@ Static Public Sub _RegisterApplication(hConnection As DBusConnection) As String
If IsNull(hConnection.Tag) Then
sName = Name_Read()
hConnection._RequestName(sName)
If hConnection._RequestName(sName, True) Then
If $bUnique Then
Error.Raise("Unique application is already registered")
Else
Error.Raise("Application is already registered")
Endif
Endif
hConnection.Tag = sName
Endif
Inc $iRegisterCount
@ -91,8 +99,13 @@ End
Static Private Function Name_Read() As String
Dim sName As String
If $sAppName Then Return $sAppName
Return "org.gambas." & _Normalize(Application.Name, True, "-_")
sName = "org.gambas." & _Normalize(Application.Name, True, "-_")
If Not $bUnique Then sName &= "-" & CStr(Application.Handle)
Return sName
End
@ -138,3 +151,15 @@ Static Public Sub _HasSystemTray() As Boolean
Try Return DBus["org.kde.StatusNotifierWatcher"]["/StatusNotifierWatcher", "org.kde.StatusNotifierWatcher"].IsStatusNotifierHostRegistered
End
Static Private Function Unique_Read() As Boolean
Return $bUnique
End
Static Private Sub Unique_Write(Value As Boolean)
$bUnique = Value
End

View file

@ -1265,7 +1265,7 @@ bool DBUS_register(DBusConnection *connection, const char *name, bool unique)
dbus_error_init(&error);
//fprintf(stderr, "DBUS_register: %s\n", name);
//fprintf(stderr, "DBUS_register: %s / unique = %d\n", name, unique);
ret = dbus_bus_request_name(connection, name, unique ? DBUS_NAME_FLAG_DO_NOT_QUEUE : 0, &error);