emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/bluetooth 2746c62 23/33: change connect and disconnect


From: Stefan Monnier
Subject: [elpa] externals/bluetooth 2746c62 23/33: change connect and disconnect functions to handle single profiles
Date: Sat, 19 Sep 2020 08:43:24 -0400 (EDT)

branch: externals/bluetooth
commit 2746c62a5181e746b8bc8c9b9fc2556c09794704
Author: Raffael Stocker <r.stocker@mnet-mail.de>
Commit: Raffael Stocker <r.stocker@mnet-mail.de>

    change connect and disconnect functions to handle single profiles
---
 bluetooth.el | 41 +++++++++++++++++++++++++++++++++++++----
 1 file changed, 37 insertions(+), 4 deletions(-)

diff --git a/bluetooth.el b/bluetooth.el
index 68d415e..75dc404 100644
--- a/bluetooth.el
+++ b/bluetooth.el
@@ -149,6 +149,43 @@ The generated function name has the form 
`bluetoothPREFIX-NAME'."
                                                                                
(lambda (x) (concat "-" (downcase x)))
                                                                                
name t)))))
 
+(defun bluetooth-connect (uuid)
+  "Connect to the Bluetooth device at point.
+When called with a prefix argument, ask for a profile and
+connect only this profile.  Otherwise, or when called
+non-interactively with UUID set to nil, connect to all profiles."
+  (interactive
+   (if current-prefix-arg
+          (let* ((dev-id (tabulated-list-get-id))
+                         (uuids (bluetooth--device-uuids
+                                         (bluetooth--device-properties 
dev-id)))
+                         (profile (completing-read "Profile: "
+                                                                               
(mapcar #'cadadr uuids) nil t)))
+                (list (cl-rassoc profile uuids :key #'cadar :test #'string=)))
+        '(nil)))
+  (if uuid
+         (bluetooth--dbus-method "ConnectProfile" :device (car uuid))
+       (bluetooth--dbus-method "Connect" :device)))
+
+(defun bluetooth-disconnect (uuid)
+  "Disconnect the Bluetooth device at point.
+When called with a prefix argument, ask for a profile and
+disconnect only this profile.  Otherwise, or when called
+non-interactively with UUID set to nil, disconnect to all
+profiles."
+  (interactive
+   (if current-prefix-arg
+          (let* ((dev-id (tabulated-list-get-id))
+                         (uuids (bluetooth--device-uuids
+                                         (bluetooth--device-properties 
dev-id)))
+                         (profile (completing-read "Profile: "
+                                                                               
(mapcar #'cadadr uuids) nil t)))
+                (list (cl-rassoc profile uuids :key #'cadar :test #'string=)))
+        '(nil)))
+  (if uuid
+         (bluetooth--dbus-method "DisconnectProfile" :device (car uuid))
+       (bluetooth--dbus-method "Disconnect" :device)))
+
 (defmacro bluetooth-defun-method (method api docstring)
   (declare (doc-string 3) (indent 2))
   (let ((name (bluetooth--function-name method)))
@@ -156,10 +193,6 @@ The generated function name has the form 
`bluetoothPREFIX-NAME'."
                        (interactive)
                        (bluetooth--dbus-method ,method ,api))))
 
-(bluetooth-defun-method "Connect" :device
-  "Connect to the Bluetooth device at point.")
-(bluetooth-defun-method "Disconnect" :device
-  "Disconnect Bluetooth device at point.")
 (bluetooth-defun-method "StartDiscovery" :adapter
   "Start discovery mode.")
 (bluetooth-defun-method "StopDiscovery" :adapter



reply via email to

[Prev in Thread] Current Thread [Next in Thread]