[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/bluetooth c75d2e3495 22/32: handle removal of devices i
From: |
Stefan Kangas |
Subject: |
[elpa] externals/bluetooth c75d2e3495 22/32: handle removal of devices in list view |
Date: |
Mon, 3 Jan 2022 15:11:08 -0500 (EST) |
branch: externals/bluetooth
commit c75d2e34957847ce88d99dfc91f9b6e1bfefc42f
Author: Raffael Stocker <r.stocker@mnet-mail.de>
Commit: Raffael Stocker <r.stocker@mnet-mail.de>
handle removal of devices in list view
---
bluetooth.el | 59 +++++++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 47 insertions(+), 12 deletions(-)
diff --git a/bluetooth.el b/bluetooth.el
index 51b6e33840..fb591136d6 100644
--- a/bluetooth.el
+++ b/bluetooth.el
@@ -397,14 +397,15 @@ properties."
"Return the device struct for DEVICE-ID."
(gethash device-id bluetooth--device-info))
-(defun bluetooth--dev-state (key device)
+(defun bluetooth--device-state (key device)
"Return state information regarding KEY for DEVICE."
(let ((value (bluetooth-device-property device key)))
(cond ((stringp value) value)
((null value) "no")
(t "yes"))))
-(defun bluetooth--create-device (adapter dev-id)
+;; TODO install signal handler if the device is paired
+(defun bluetooth--device-create (adapter dev-id)
"Create a bluetooth device struct for DEV-ID on ADAPTER."
(let* ((path (mapconcat #'identity
(list bluetooth--root adapter
dev-id)
@@ -416,6 +417,20 @@ properties."
:device bluetooth--interfaces))))
(make-bluetooth-device :id dev-id :properties props)))
+;; TODO remove signal handler
+(defun bluetooth--device-remove (dev-id)
+ "Remove the device with id DEV-ID from the device info."
+ (remhash dev-id bluetooth--device-info))
+
+(defun bluetooth--device-add (dev-id device)
+ "Add bluetooth DEVICE with id DEV-ID to device info."
+ (puthash dev-id device bluetooth--device-info))
+
+(defun bluetooth--device-update (dev-id device)
+ "Update device info for id DEV-ID with data in DEVICE."
+ (setf (bluetooth-device-properties (bluetooth--device dev-id))
+ (bluetooth-device-properties device)))
+
(defun bluetooth--adapter-properties (adapter)
"Return the properties of bluetooth ADAPTER.
This function evaluates to an alist of attribute/value pairs."
@@ -432,27 +447,45 @@ This function evaluates to an alist of attribute/value
pairs."
NOTE: the strings MUST correspond to Bluez device properties
as they are used to gather the information from Bluez.")
-(defun bluetooth--update-device-info ()
- "Update the bluetooth devices list."
+(defun bluetooth--initialize-device-info ()
+ "Initialize bluetooth device info. Call only once."
(mapc (lambda (adapter)
- (mapc (lambda (dev)
- (puthash dev
-
(bluetooth--create-device adapter dev)
- bluetooth--device-info))
- (bluetooth--query-devices adapter)))
+ (mapc (lambda (dev-id)
+ (bluetooth--device-add dev-id
+
(bluetooth--device-create adapter
+
dev-id)))
+ (bluetooth--query-devices adapter)))
(bluetooth--query-adapters)))
+(defun bluetooth--update-device-info (adapter)
+ "Update the bluetooth devices list for ADAPTER."
+ (let ((queried-devices (bluetooth--query-devices adapter)))
+ (let ((removed-devices (cl-set-difference (hash-table-keys
+
bluetooth--device-info)
+
queried-devices)))
+ (mapc (lambda (dev-id)
+ (bluetooth--device-remove dev-id))
+ removed-devices)
+ (mapc (lambda (dev-id)
+ (if-let (device (bluetooth--device dev-id))
+ (bluetooth--device-update dev-id device)
+ (bluetooth--device-add dev-id
+
(bluetooth--device-create adapter
+
dev-id))))
+ queried-devices))))
+
;; This function provides the list entries for the tabulated-list
;; view. It is called from `tabulated-list-print'.
(defun bluetooth--list-entries ()
"Provide the list entries for the tabulated view."
- (bluetooth--update-device-info) ; TODO this can later be
removed when
+ (mapc #'bluetooth--update-device-info
+ (bluetooth--query-adapters)) ; TODO this can later
be removed when
; update is by dbus change notifications
(let (dev-list)
(maphash (lambda (dev dev-info)
(push (list dev
(cl-map 'vector (lambda (key)
-
(bluetooth--dev-state key dev-info))
+
(bluetooth--device-state key dev-info))
(mapcar
#'cl-first bluetooth--list-format)))
dev-list))
bluetooth--device-info)
@@ -543,6 +576,7 @@ This function only uses the first adapter reported by
Bluez."
(bluetooth--handle-prop-change (alist-get :adapter
bluetooth--interfaces)
info)))
+;; TODO de-register all the signal handlers
(defun bluetooth--cleanup ()
"Clean up when mode buffer is killed."
;; This function is registered as a kill-buffer-hook, so we don't
@@ -556,6 +590,7 @@ This function only uses the first adapter reported by
Bluez."
(dbus-unregister-object bluetooth--adapter-signal)
(cancel-timer bluetooth--update-timer)))
+;; TODO de-register all the signal handlers
(defun bluetooth-unload-function ()
"Clean up when the bluetooth feature is unloaded."
(when (buffer-live-p (get-buffer bluetooth-buffer-name))
@@ -648,7 +683,7 @@ scanning the bus, displaying device info etc."
(erase-buffer)
(bluetooth-mode)
(setq bluetooth--device-info (make-hash-table :test #'equal))
- (bluetooth--update-device-info)
+ (bluetooth--initialize-device-info)
(setq bluetooth--method-objects (bluetooth--register-agent))
(cl-pushnew bluetooth--mode-info mode-line-process)
(add-hook 'kill-buffer-hook #'bluetooth--cleanup nil t)
- [elpa] externals/bluetooth 9878aa8051 14/32: add adapter parameters in adapter-properties and devices functions, (continued)
- [elpa] externals/bluetooth 9878aa8051 14/32: add adapter parameters in adapter-properties and devices functions, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth f2d43ebab5 16/32: make bluetooth--choose-uuid somewhat more readable, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 5a49391b00 07/32: clean up device property handling (breaks info view code), Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 0627cceab3 08/32: clean up the info view code and add an adapter info view, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth f75ac5e43d 11/32: clean up the method registration function, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth e69e4151ff 12/32: clean things up for readability, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth a411243fbe 17/32: add a function for bluetooth device info access, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 7a78351220 19/32: set tabulated-list-padding to 0, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 1f048b5949 20/32: clean up and drop multiple adapter plans, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth fa3761da3c 21/32: add timer to periodically update the device table in discovery mode, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth c75d2e3495 22/32: handle removal of devices in list view,
Stefan Kangas <=
- [elpa] externals/bluetooth ddad595699 23/32: move command definitions to bottom of file, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 1254ec44d2 24/32: add signal handlers for paired devices, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 7a0ba3c7ea 29/32: update Readme.org, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 1fcdce66f8 31/32: require dash 2.18.1, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 7ed3db7260 32/32: Release 0.3 and bump copyright year, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth ab3a4c9cc5 18/32: move bluetooth--create-device to the other --device functions, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth a20d488f9a 28/32: delete invalid todo, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth b6c501ae6e 04/32: add bluetooth--adapters function, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth cc8f69992d 06/32: adjust initial hash table sizes, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 0ba4d39085 13/32: correct indentation, Stefan Kangas, 2022/01/03