;;; bbdb-nokia-n900.el --- Send SMS' and make phone calls from ;;; BBDB in GNU Emacs on the Nokia N900 GNU mobile phone via ;;; the Nokia N900 dbus interface ;; Copyright (C) 2009 ShiroiKuma ;; ;; Author: ShiroiKuma.org ;; ;; Version history: ;; 0.1 First version, 2009-12-19-220000 ;; ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 3 of ;; the License, or (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public ;; License along with this program; if not, write to the Free ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ;; MA 02111-1307, USA. ;;; Commentary: ;; ;;; Installation: ;; ;; Add the following to your .emacs file: ;; ;; (add-to-list 'load-path X) ;; ;; ...where X is the directory path where bbdb-nokia-n900.el is stored. ;; ;; (require 'bbdb-nokia-n900) ;; ;;; Requirements: ;; ;; You MUST have the following setup and working: ;; (in GNU Emacs) ;; BBDB ;; ;; To call: put point on the phone number in the BBDB database and then: ;; Y ;; To send and SMS: ;; X ;;; Code: ;; SMS from BBDB (define-key bbdb-mode-map "X" 'bbdb-nokia-n900-sms) (defun bbdb-nokia-n900-sms (bbdb-record text &optional date regrind) "Sends SMS and adds a note for today to the current BBDB record. Call with a prefix to specify date. BBDB-RECORD is the record to modify (default: current). TEXT is the note to add for DATE. If REGRIND is non-nil, redisplay the BBDB record." (interactive (list (bbdb-current-record t) (read-string "SMS text: ") ;; Reading date - more powerful with Planner, but we'll make do if necessary (if (featurep 'planner) (if current-prefix-arg (planner-read-date) (planner-today)) (if current-prefix-arg (read-string "Date (YYYY.MM.DD): ") (format-time-string "%Y.%m.%dT%T%z"))) t)) (let ((field (bbdb-current-field))) (if (not (eq 'phone (car field))) (error "Cannot dial %s, not a phone field" (car field))) (let ((location (aref (car (cdr field)) 0)) (name (aref (car (cdr field)) 1))) ;; Cut out +/-/ /(/) from the phone number to be dialed ;; and then send SMS (let ((number (replace-regexp-in-string "+" "" (replace-regexp-in-string "-" "" (replace-regexp-in-string " " "" (replace-regexp-in-string "(" "" (replace-regexp-in-string ")" "" name))))))) (message "Sending SMS to: %s (%s)" name location) (diamondsms-send-sms-to-number number text) (bbdb-record-putprop bbdb-record 'contact (concat date " " (format-time-string "%H:%M:%S %Z" (current-time)) ": SMS: " name ": " text "\n" (or (bbdb-record-getprop bbdb-record 'contact)))) (if regrind (save-excursion (set-buffer bbdb-buffer-name) (bbdb-redisplay-one-record bbdb-record)))))) nil) ;; Call from BBDB (define-key bbdb-mode-map "Y" 'bbdb-nokia-n900-call) (defun bbdb-nokia-n900-call (bbdb-record &optional date regrind) "Calls contact and adds a note for today to the current BBDB record. Call with a prefix to specify date. BBDB-RECORD is the record to modify (default: current). DATE is the date. If REGRIND is non-nil, redisplay the BBDB record." (interactive (list (bbdb-current-record t) ;; Reading date - more powerful with Planner, but we'll make do if necessary (if (featurep 'planner) (if current-prefix-arg (planner-read-date) (planner-today)) (if current-prefix-arg (read-string "Date (YYYY.MM.DD): ") (format-time-string "%Y.%m.%dT%T%z"))) t)) (let ((field (bbdb-current-field))) (if (not (eq 'phone (car field))) (error "Cannot dial %s, not a phone field" (car field))) (let ((location (aref (car (cdr field)) 0)) (name (aref (car (cdr field)) 1))) ;; Cut out +/-/ /(/) from the phone number to be dialed ;; and then send SMS (let ((number (replace-regexp-in-string "-" "" (replace-regexp-in-string " " "" (replace-regexp-in-string "(" "" (replace-regexp-in-string ")" "" name))))) (start-time (format-time-string "%H:%M:%S %Z" (current-time)))) (message "Calling: %s (%s)" name location) (shell-command (concat "dbus-send --system --dest=com.nokia.csd.Call --type=method_call --print-reply /com/nokia/csd/call com.nokia.csd.Call.CreateWith string:\"" number "\" uint32:0")) (let ((end-time (format-time-string "%H:%M:%S %Z" (current-time)))) (bbdb-record-putprop bbdb-record 'contact (concat date " " start-time " - " end-time ": Phone call: " name "\n" (or (bbdb-record-getprop bbdb-record 'contact))))) (if regrind (save-excursion (set-buffer bbdb-buffer-name) (bbdb-redisplay-one-record bbdb-record)))))) nil) (provide 'bbdb-nokia-n900) ;;; bbdb-nokia-n900.el ends here