[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/bluetooth 291e863 43/57: separates adapter api calls fr
From: |
Stefan Monnier |
Subject: |
[elpa] externals/bluetooth 291e863 43/57: separates adapter api calls from device ids |
Date: |
Thu, 7 Nov 2019 23:28:56 -0500 (EST) |
branch: externals/bluetooth
commit 291e86377e35f8973e075dea72896ab67e284397
Author: Raffael Stocker <address@hidden>
Commit: Raffael Stocker <address@hidden>
separates adapter api calls from device ids
---
bluetooth.el | 65 ++++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 41 insertions(+), 24 deletions(-)
diff --git a/bluetooth.el b/bluetooth.el
index d2a4030..641fad4 100644
--- a/bluetooth.el
+++ b/bluetooth.el
@@ -139,9 +139,6 @@ This is usually `:system' if bluetoothd runs as a system
service, or
(api . :adapter) (docstring . "Start discovery mode."))
((command . stop-discovery) (key . [?R]) (method . "StopDiscovery")
(api . :adapter) (docstring . "Stop discovery mode."))
- ((command . remove-device) (key . [?k]) (method . "RemoveDevice")
- (api . :adapter) (args :object-path :path-devid)
- (docstring . "Remove Bluetooth device at point."))
((command . toggle-power) (key . [?s]) (toggle . "Powered")
(api . :adapter) (docstring . "Toggle power supply of adapter."))
((command . pair) (key . [?P]) (method . "Pair")
@@ -183,6 +180,7 @@ For documentation, see URL
`https://gitlab.com/rstocker/emacs-bluetooth'."
tabulated-list-padding 1)
(bluetooth--make-commands)
(define-key bluetooth-mode-map [?i] #'bluetooth-show-device-info)
+ (define-key bluetooth-mode-map [?k] #'bluetooth-remove-device)
(tabulated-list-init-header))
;;; This function returns a list of bluetooth adapters and devices
@@ -258,17 +256,39 @@ For documentation, see URL
`https://gitlab.com/rstocker/emacs-bluetooth'."
do (forward-line 1)
collect (cons (elt entry 0) pos)))
+(defun bluetooth-remove-device ()
+ "Remove Bluetooth device at point."
+ (interactive)
+ (let ((dev-id (tabulated-list-get-id)))
+ (when dev-id
+ (bluetooth--call-method dev-id
+ :adapter
+ #'dbus-call-method-asynchronously
+ "RemoveDevice"
+ #'bluetooth--update-list
+ :timeout bluetooth--timeout
+ :object-path :path-devid))))
+
;;; This function calls FUNCTION with ARGS given the device-id DEV-ID and
;;; Bluez API. This is used on D-Bus functions.
(defun bluetooth--call-method (dev-id api function &rest args)
"For DEV-ID, invoke D-Bus FUNCTION on API, passing ARGS."
- (let ((path (mapconcat (lambda (f) (funcall f dev-id))
- (plist-get (plist-get bluetooth--api-info api) :path)
- "/"))
- (interface (plist-get (plist-get bluetooth--api-info api) :interface)))
- (apply function bluetooth-bluez-bus bluetooth--service path interface
- (mapcar (lambda (x) (if (eq x :path-devid) (concat path "/" dev-id)
x))
- args))))
+ (let ((path (cond ((and (eq :device api)
+ (not (null dev-id)))
+ (concat (bluetooth--dev-state
+ "Adapter"
+ (assoc dev-id bluetooth--device-info))
+ "/" dev-id))
+ ((eq :adapter api)
+ (concat bluetooth--root
+ "/"
+ (caar (bluetooth--get-devices))))
+ (t nil)))
+ (interface (alist-get api bluetooth--interfaces)))
+ (when path
+ (apply function bluetooth-bluez-bus bluetooth--service path interface
+ (mapcar (lambda (x) (if (eq x :path-devid) (concat path "/"
dev-id) x))
+ args)))))
;;; The following functions are the workers for the commands.
;;; They are used by `bluetooth--make-commands'.
@@ -277,29 +297,26 @@ For documentation, see URL
`https://gitlab.com/rstocker/emacs-bluetooth'."
(defun bluetooth--dbus-method (method api &rest args)
"Invoke METHOD on D-Bus API with ARGS."
(let ((dev-id (tabulated-list-get-id)))
- (when dev-id
- (apply #'bluetooth--call-method dev-id api
- #'dbus-call-method-asynchronously method
- #'bluetooth--update-list :timeout bluetooth--timeout args))))
+ (apply #'bluetooth--call-method dev-id api
+ #'dbus-call-method-asynchronously method
+ #'bluetooth--update-list :timeout bluetooth--timeout args)))
;;; Toggle a property.
(defun bluetooth--dbus-toggle (property api)
"Toggle boolean PROPERTY on D-Bus API."
- (let ((dev-id (tabulated-list-get-id)))
- (when dev-id
- (let ((value (bluetooth--call-method dev-id api
- #'dbus-get-property property)))
- (bluetooth--call-method dev-id api #'dbus-set-property property
- (not value))
- (bluetooth--update-list)))))
+ (let* ((dev-id (tabulated-list-get-id))
+ (value (bluetooth--call-method dev-id api
+ #'dbus-get-property property)))
+ (bluetooth--call-method dev-id api #'dbus-set-property property
+ (not value))
+ (bluetooth--update-list)))
;;; Set a property.
(defun bluetooth--dbus-set (property arg api)
"Set PROPERTY to ARG on D-Bus API."
(let ((dev-id (tabulated-list-get-id)))
- (when dev-id
- (bluetooth--call-method dev-id api #'dbus-set-property property arg)
- (bluetooth--update-list))))
+ (bluetooth--call-method dev-id api #'dbus-set-property property arg)
+ (bluetooth--update-list)))
;;; end of worker function definitions
- [elpa] externals/bluetooth 5387639 52/57: adds path loss to device info, (continued)
- [elpa] externals/bluetooth 5387639 52/57: adds path loss to device info, Stefan Monnier, 2019/11/07
- [elpa] externals/bluetooth ea7ccf7 53/57: fixes mode line update, Stefan Monnier, 2019/11/07
- [elpa] externals/bluetooth 21e6a14 34/57: adds hl-line-mode activation, Stefan Monnier, 2019/11/07
- [elpa] externals/bluetooth cb5a39c 29/57: adds SDO UUIDs and simplifies the UUID handling functions, Stefan Monnier, 2019/11/07
- [elpa] externals/bluetooth 44e81ed 42/57: rearranges UUID data and functions, concentrates interface names, Stefan Monnier, 2019/11/07
- [elpa] externals/bluetooth 72f061d 48/57: updates commentary and cleans up whitespace, Stefan Monnier, 2019/11/07
- [elpa] externals/bluetooth 2ce2322 49/57: improves device info printing, Stefan Monnier, 2019/11/07
- [elpa] externals/bluetooth e002888 27/57: updates Readme.org, Stefan Monnier, 2019/11/07
- [elpa] externals/bluetooth 15d1f53 37/57: adds a pointer to the source of assigned numbers data, Stefan Monnier, 2019/11/07
- [elpa] externals/bluetooth d749581 41/57: removes unused `bluetooth--own-intf', Stefan Monnier, 2019/11/07
- [elpa] externals/bluetooth 291e863 43/57: separates adapter api calls from device ids,
Stefan Monnier <=
- [elpa] externals/bluetooth 398d361 44/57: ensures line highlighting after list display update, Stefan Monnier, 2019/11/07
- [elpa] externals/bluetooth 55304bb 57/57: signs copyright over to the FSF for inclusion in ELPA, Stefan Monnier, 2019/11/07
- [elpa] externals/bluetooth 49ca390 55/57: puts single-use stuff into using functions, Stefan Monnier, 2019/11/07
- [elpa] externals/bluetooth 920c308 56/57: updates comments, company IDs and cleans up, Stefan Monnier, 2019/11/07
- [elpa] externals/bluetooth 806b5e9 51/57: adds manufacturer names and more attributes to device info, Stefan Monnier, 2019/11/07
- [elpa] externals/bluetooth 5fa8c5f 54/57: changes all the larger UUID lists into hash tables and cleans up, Stefan Monnier, 2019/11/07