bluetoothstatus-always-update-devices.patch 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. From 76fce94b66be7bdebbedcc3bce62898da51da15a Mon Sep 17 00:00:00 2001
  2. From: Giovanni Campagna <gcampagna@src.gnome.org>
  3. Date: Wed, 13 Apr 2011 17:08:45 +0000
  4. Subject: BluetoothStatus: always update devices
  5. Previously, we skipped rebuilding device items in case the device
  6. had already been seen, but this caused the connected switch not to
  7. be updated. Now it has been refactored to update in case the device
  8. changes, and to create only when the device is completely new.
  9. https://bugzilla.gnome.org/show_bug.cgi?id=647565
  10. ---
  11. diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js
  12. index 070016a..cee2f90 100644
  13. --- a/js/ui/status/bluetooth.js
  14. +++ b/js/ui/status/bluetooth.js
  15. @@ -127,13 +127,6 @@ Indicator.prototype = {
  16. }
  17. },
  18. - _deviceCompare: function(d1, d2) {
  19. - return d1.device_path == d2.device_path &&
  20. - d1.bdaddr == d2.bdaddr &&
  21. - d1.can_connect == d2.can_connect &&
  22. - d1.capabilities == d2.capabilities;
  23. - },
  24. -
  25. _updateDevices: function() {
  26. let devices = this._applet.get_devices();
  27. @@ -142,12 +135,8 @@ Indicator.prototype = {
  28. let item = this._deviceItems[i];
  29. let destroy = true;
  30. for (let j = 0; j < devices.length; j++) {
  31. - // we need to deep compare because BluetoothSimpleDevice is a boxed type
  32. - // (but we take advantage of that, because _skip will disappear the next
  33. - // time get_devices() is called)
  34. - if (this._deviceCompare(item._device, devices[j])) {
  35. - item.label.text = devices[j].alias;
  36. - devices[j]._skip = true;
  37. + if (item._device.device_path == devices[j].device_path) {
  38. + this._updateDeviceItem(item, devices[j]);
  39. destroy = false;
  40. break;
  41. }
  42. @@ -162,7 +151,7 @@ Indicator.prototype = {
  43. this._hasDevices = newlist.length > 0;
  44. for (let i = 0; i < devices.length; i++) {
  45. let d = devices[i];
  46. - if (d._skip)
  47. + if (d._item)
  48. continue;
  49. let item = this._createDeviceItem(d);
  50. if (item) {
  51. @@ -177,17 +166,55 @@ Indicator.prototype = {
  52. this._deviceSep.actor.hide();
  53. },
  54. + _updateDeviceItem: function(item, device) {
  55. + if (!device.can_connect && device.capabilities == GnomeBluetoothApplet.Capabilities.NONE) {
  56. + item.destroy();
  57. + return;
  58. + }
  59. +
  60. + let prevDevice = item._device;
  61. + let prevCapabilities = prevDevice.capabilities;
  62. + let prevCanConnect = prevDevice.can_connect;
  63. +
  64. + // adopt the new device object
  65. + item._device = device;
  66. + device._item = item;
  67. +
  68. + // update properties
  69. + item.label.text = device.alias;
  70. +
  71. + if (prevCapabilities != device.capabilities ||
  72. + prevCanConnect != device.can_connect) {
  73. + // need to rebuild the submenu
  74. + item.menu.removeAll();
  75. + this._buildDeviceSubMenu(item, device);
  76. + }
  77. +
  78. + // update connected property
  79. + if (device.can_connect)
  80. + item._connectedMenuitem.setToggleState(device.connected);
  81. + },
  82. +
  83. _createDeviceItem: function(device) {
  84. if (!device.can_connect && device.capabilities == GnomeBluetoothApplet.Capabilities.NONE)
  85. return null;
  86. let item = new PopupMenu.PopupSubMenuMenuItem(device.alias);
  87. +
  88. + // adopt the device object, and add a back link
  89. item._device = device;
  90. + device._item = item;
  91. + this._buildDeviceSubMenu(item, device);
  92. +
  93. + return item;
  94. + },
  95. +
  96. + _buildDeviceSubMenu: function(item, device) {
  97. if (device.can_connect) {
  98. item._connected = device.connected;
  99. - let menuitem = new PopupMenu.PopupSwitchMenuItem(_("Connection"), device.connected);
  100. + item._connectedMenuitem = new PopupMenu.PopupSwitchMenuItem(_("Connection"), device.connected);
  101. - menuitem.connect('toggled', Lang.bind(this, function() {
  102. + item._connectedMenuitem.connect('toggled', Lang.bind(this, function() {
  103. if (item._connected > ConnectionState.CONNECTED) {
  104. // operation already in progress, revert
  105. menuitem.setToggleState(menuitem.state);
  106. @@ -217,7 +244,7 @@ Indicator.prototype = {
  107. }
  108. }));
  109. - item.menu.addMenuItem(menuitem);
  110. + item.menu.addMenuItem(item._connectedMenuitem);
  111. }
  112. if (device.capabilities & GnomeBluetoothApplet.Capabilities.OBEX_PUSH) {
  113. @@ -263,8 +290,6 @@ Indicator.prototype = {
  114. default:
  115. break;
  116. }
  117. -
  118. - return item;
  119. },
  120. _updateFullMenu: function() {
  121. --
  122. cgit v0.9