From 47fd153ba00d0376c5215e7f2db0c98cf29ddec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Thu, 2 Jul 2015 22:26:05 +0000 Subject: [PATCH] [GB.DBUS] * NEW: A class inheriting DBusVariant can be used a DBus method return value. * BUG: unregistering an object correctly removes it from the children list of its parent. * NEW: DBus.SplitSignature has been renamed as DBus._SplitSignature. [GB.DBUS.TRAYICON] * BUG: Correctly unregister KDE-style trayicons. git-svn-id: svn://localhost/gambas/trunk@7167 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- .../.src/DBusStatusIconMenu.class | 12 +++----- comp/src/gb.dbus.trayicon/.src/TrayIcon.class | 3 +- .../.src/_DBusMenuProperties.class | 2 +- gb.dbus/src/c_dbus.c | 2 +- gb.dbus/src/gb.dbus/.src/DBusObject.class | 29 ++++++++++++++++--- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/comp/src/gb.dbus.trayicon/.src/DBusStatusIconMenu.class b/comp/src/gb.dbus.trayicon/.src/DBusStatusIconMenu.class index c501ffe56..df5e6a25c 100644 --- a/comp/src/gb.dbus.trayicon/.src/DBusStatusIconMenu.class +++ b/comp/src/gb.dbus.trayicon/.src/DBusStatusIconMenu.class @@ -62,7 +62,7 @@ Public Sub com_canonical_dbusmenu_GetGroupProperties(IdList As Integer[], Proper Next hResult = New _DBusMenuProperties - hResult.Value = [aResult] + hResult.Value = aResult Return hResult End @@ -134,7 +134,7 @@ Private Sub UpdateMenuRec(hMenu As Menu) As Integer cProp["id"] = iId cProp["menu"] = hMenu - If iId > 0 Then + 'If iId > 0 Then sText = hMenu.Text If Not sText Then cProp["type"] = "separator" @@ -178,7 +178,7 @@ Private Sub UpdateMenuRec(hMenu As Menu) As Integer cProp["shortcut"] = [aShortcut] Endif - Endif + 'Endif If hMenu.Children.Count Then cProp["children-display"] = "submenu" @@ -200,15 +200,11 @@ End Public Sub _UpdateMenu(hMenu As Menu) - Dim hRevision As _DBusUInt - Inc $iRevision $aProp.Clear UpdateMenuRec(hMenu) - hRevision = New _DBusUInt - hRevision.Value = $iRevision - DBus.Raise(Me, "com.canonical.dbusmenu.LayoutUpdated", [hRevision, 0]) + DBus.Raise(Me, "com.canonical.dbusmenu.LayoutUpdated", [_DBusUInt($iRevision), 0]) End diff --git a/comp/src/gb.dbus.trayicon/.src/TrayIcon.class b/comp/src/gb.dbus.trayicon/.src/TrayIcon.class index 1f0999183..9bdfc43c4 100644 --- a/comp/src/gb.dbus.trayicon/.src/TrayIcon.class +++ b/comp/src/gb.dbus.trayicon/.src/TrayIcon.class @@ -108,7 +108,8 @@ Public Sub Hide() If $bAppIndicator Then DBus[sService].Raise($hObject, "org.kde.StatusNotifierItem.NewStatus", ["Passive"]) - Else + Else + DBus[sService].Unregister($hMenu) DBus[sService].Unregister($hObject) Endif diff --git a/comp/src/gb.dbus.trayicon/.src/_DBusMenuProperties.class b/comp/src/gb.dbus.trayicon/.src/_DBusMenuProperties.class index 6a5b2cf7d..885fa1249 100644 --- a/comp/src/gb.dbus.trayicon/.src/_DBusMenuProperties.class +++ b/comp/src/gb.dbus.trayicon/.src/_DBusMenuProperties.class @@ -1,6 +1,6 @@ ' Gambas class file Export -Inherits DBusValues +Inherits DBusVariant Public Const Signature As String = "a(ia{sv})" diff --git a/gb.dbus/src/c_dbus.c b/gb.dbus/src/c_dbus.c index be9fd6cd3..854343dbf 100644 --- a/gb.dbus/src/c_dbus.c +++ b/gb.dbus/src/c_dbus.c @@ -67,7 +67,7 @@ GB_DESC CDBusDesc[] = GB_CONSTANT("Signal", "i", DBUS_MESSAGE_TYPE_SIGNAL), GB_CONSTANT("Error", "i", DBUS_MESSAGE_TYPE_ERROR), - GB_STATIC_METHOD("SplitSignature", "String[]", DBus_SplitSignature, "(Signature)s"), + GB_STATIC_METHOD("_SplitSignature", "String[]", DBus_SplitSignature, "(Signature)s"), GB_END_DECLARE }; diff --git a/gb.dbus/src/gb.dbus/.src/DBusObject.class b/gb.dbus/src/gb.dbus/.src/DBusObject.class index 5879f22d7..6056a896a 100644 --- a/gb.dbus/src/gb.dbus/.src/DBusObject.class +++ b/gb.dbus/src/gb.dbus/.src/DBusObject.class @@ -81,6 +81,20 @@ Public Sub _AddChild(sChild As String) End +Public Sub _RemoveChild(sChild As String) + + Dim iPos As Integer + + If Not $aChildren Then Return + iPos = $aChildren.Find(sChild) + If iPos >= 0 Then + $aChildren.Remove(iPos) + If $aChildren.Count = 0 Then $aChildren = Null + Endif + +End + + Public Sub _Register(hConnection As DBusConnection, sFullPath As String, Optional aInterface As String[]) Dim hParent As DBusObject @@ -163,17 +177,22 @@ Public Sub _Unregister(hConnection As DBusConnection) Endif If $aChildren Then - For Each sChild In $aChildren + For Each sChild In $aChildren.Copy() hChild = _ObjectCache[$sFullPath &/ sChild] hChild._Unregister(hConnection) Next + $aChildren = Null Endif + hParent = _ObjectCache[File.Dir($sFullPath)] + If hParent Then hParent._RemoveChild(File.Name($sFullPath)) + $hObserver = Null _ObjectCache[$sFullPath] = Null $sFullPath = "" $sPath = "" + If _ObjectCache.Count = 0 Then DBus._UnregisterApplication(hConnection) $sName = "" @@ -368,7 +387,7 @@ Public Sub _Introspect() As String If sType Then If bMulti Then - aType = DBus.SplitSignature(sType) + aType = DBus._SplitSignature(sType) For I = 0 To aType.Max sDesc &= " \n" Next @@ -496,7 +515,7 @@ Private Sub GetAllProperties() Catch - If DBus.Debug Then Error "gb.dbus: org.freedesktop.Properties.GetAll: error: "; Error.Text + If DBus.Debug Then Error "gb.dbus: org.freedesktop.Properties.GetAll: error: "; Error.Text;; Error.Backtrace.Join(" ") $hObserver.Error(Error.Text) End @@ -584,6 +603,9 @@ Public Sub DBusObserver_Message() If TypeOf(vVal) = gb.Object And If vVal Is DBusValues Then sType = vVal.Signature $hObserver.Reply(sType, vVal.Value) + Else If TypeOf(vVal) = gb.Object And If vVal Is DBusVariant Then + sType = vVal.Signature + $hObserver.Reply(sType, [vVal.Value]) Else sType = ConvType(sType) If Not sType Then sType = "v" @@ -596,7 +618,6 @@ Public Sub DBusObserver_Message() Catch - 'Debug Error.Text If DBus.Debug Then Error "gb.dbus: "; sInterface; "."; sMethod; ": error: "; Error.Text;; Error.Backtrace.Join(" ") $hObserver.Error(Error.Text)