From 77aa689d8531655c8805774296e7b0c9ad51dad1 Mon Sep 17 00:00:00 2001
From: Abhi Yerra <abhi@berkeley.edu>
Date: Sun, 8 May 2011 09:23:48 -0700
Subject: [PATCH] bbdb-dial: Made it useful for contemporary settings.

---
 lisp/bbdb-com.el |   58 +++++------------------------------------------------
 lisp/bbdb.el     |   39 +++++------------------------------
 2 files changed, 12 insertions(+), 85 deletions(-)

diff --git a/lisp/bbdb-com.el b/lisp/bbdb-com.el
index 1a7951c..299fc51 100644
--- a/lisp/bbdb-com.el
+++ b/lisp/bbdb-com.el
@@ -2382,61 +2382,15 @@ If pefix DELETE is non-nil, remove ALIAS from RECORD."
 
 ;;; Dialing numbers from BBDB
 
-(defun bbdb-play-sound (num &optional volume)
-  "Play the specified touchtone number NUM at VOLUME.
-Uses external program `bbdb-sound-player' if set, otherwise
-try to use internal sound if available."
-  ;; We cannot tell a priori if Emacs facility will actually work.
-  (cond ((not (condition-case nil
-                  (play-sound (list 'sound
-                                    :file (aref bbdb-sound-files
-                                                (string-to-number num))
-                                    :volume (or volume bbdb-sound-volume)))
-                (error nil))))
-        ((and bbdb-sound-player
-              (file-exists-p bbdb-sound-player))
-         (call-process bbdb-sound-player nil nil nil
-                       (aref bbdb-sound-files num)))
-        ((error "BBDB has no means of playing sound."))))
-
 (defun bbdb-dial-number (phone-string)
   "Dial the number specified by PHONE-STRING.
-The number is dialed either by playing touchtones through the audio
-device using `bbdb-sound-player', or by sending a dial sequence to
-`bbdb-modem-device'. # and * are dialed as-is, and a space is treated as
-a pause in the dial sequence."
+The number is dialed by using the tel uri syntax to open up a native app.
+If `bbdb-dial-handler` is specified with a function then that is called
+to make calls."
   (interactive "sDial number: ")
-  (if bbdb-modem-dial
-      (with-temp-buffer
-        (insert bbdb-modem-dial)
-        (insert (mapconcat
-                 (lambda (d)
-                   (cond ((eq ?\s d) ",")
-                         ((memq d '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?* ?#))
-                          (format "%c" d))
-                         (t "")))
-                 phone-string "") ";\r\n")
-        (write-region (point-min) (point-max) bbdb-modem-device t)
-        (message "%s dialed. Pick up the phone now and hit any key ..."
-                 phone-string)
-        (read-event)
-        (erase-buffer)
-        (insert "ATH\r\n")
-        (write-region (point-min) (point-max) bbdb-modem-device t))
-
-    (mapc (lambda (d)
-            (cond
-             ((eq ?# d)
-              (bbdb-play-sound 10))
-             ((eq ?* d)
-              (bbdb-play-sound 11))
-             ((eq ?\s d)
-              ;; if we use `sit-for', the user can interrupt!
-              (sleep-for 1)) ;; configurable?
-             ((memq d '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
-              (bbdb-play-sound (- d ?0)))
-             (t)))
-          phone-string)))
+  (if bbdb-dial-handler
+      (funcall bbdb-dial-handler phone)
+    (browse-url (concat "tel:" phone-string))))
 
 ;;;###autoload
 (defun bbdb-dial (phone force-area-code)
diff --git a/lisp/bbdb.el b/lisp/bbdb.el
index aea6ae4..ed1a162 100644
--- a/lisp/bbdb.el
+++ b/lisp/bbdb.el
@@ -1221,41 +1221,14 @@ when dialling (international dialing prefix.)"
   :type '(choice (const :tag "No digits required" nil)
                  (string :tag "Dial this first" "1")))
 
-(defcustom bbdb-sound-player nil
-  "The program to be used to play the sounds for the touch-tone digits."
+(defcustom bbdb-dial-handler nil
+  "Dial hook.
+If this is not nil this function will be used by `bbdb-dial` and
+`bbdb-dial-number`. The function which is passed will require one
+argument which is a phone string."
   :group 'bbdb-dialing
-  :type '(choice (const :tag "No External Player" nil)
-                 (file :tag "Sound Player" "/usr/local/bin/play")))
-
-(defcustom bbdb-sound-files
-  (vconcat
-   (mapcar (lambda (x) (format "/usr/demo/SOUND/sounds/touchtone.%s.au" x))
-           '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "pound" "star")))
-  "Vector of sound files to be used for dialing.
-They correspond to the 0, 1, 2, ... 9 digits, pound and star, respectively."
-  :group 'bbdb-dialing
-  :type 'vector)
-
-(defcustom bbdb-modem-dial nil
-  "Type of dialing to use.
-If this value is nil, the audio device is used for dialing. Otherwise,
-this string is fed to the modem before the phone number digits."
-  :group 'bbdb-dialing
-  :type '(choice (const  :tag "audio" nil)
-                 (string :tag "tone dialing" "ATDT ")
-                 (string :tag "pulse dialing" "ATDP ")))
-
-(defcustom bbdb-modem-device "/dev/modem"
-  "The name of the modem device.
-This is only used if `bbdb-modem-dial' is set to something other than nil."
-  :group 'bbdb-dialing
-  :type 'string)
+  :type 'function)
 
-(defcustom bbdb-sound-volume 50
-  "The volume to play back dial tones at. The range is 0 to 100.
-This is only used if `bbdb-modem-dial' is set to nil."
-  :group 'bbdb-dialing
-  :type 'integer)
 
 ;;; Internal variables
 (eval-and-compile
-- 
1.7.4

