branch: master commit d6aa3eeea915158e26be60baa736ba06db7dcb07 Author: Ian D <du...@gnu.org> Commit: Ian D <du...@gnu.org>
Fixed up enwc-wicd network properties. --- lisp/enwc-wicd.el | 36 ++++++++++++++---------- lisp/enwc.el | 82 +++++++++++++++---------------------------------------- 2 files changed, 43 insertions(+), 75 deletions(-) diff --git a/lisp/enwc-wicd.el b/lisp/enwc-wicd.el index 0343648..f02f4b6 100644 --- a/lisp/enwc-wicd.el +++ b/lisp/enwc-wicd.el @@ -1,6 +1,6 @@ ;;; enwc-wicd.el --- The Wicd backend to ENWC -;; Copyright (C) 2012,2013 Free Software Foundation +;; Copyright (C) 2012,2013,2014 Free Software Foundation ;; Author: Ian Dunn ;; Keywords: enwc, network, wicd, manager, nm @@ -100,8 +100,11 @@ the wicd wired interface." (defvar enwc-wicd-prop-num 0) (defvar enwc-wicd-prop-timeout 3) -(defun enwc-wicd-nw-prop-handler (&rest args) - (setq enwc-wicd-prop-values (cons args enwc-wicd-prop-values)) +(defun enwc-wicd-nw-prop-handler (prop &rest args) + "The handler for `enwc-wicd-get-wireless-network-property'. +This receives the value of network property PROP, +and appends the value to `enwc-wicd-prop-values'." + (setq enwc-wicd-prop-values (cons (cons prop (car args)) enwc-wicd-prop-values)) (setq enwc-wicd-prop-num (1+ enwc-wicd-prop-num))) (defun enwc-wicd-get-wireless-network-property (id prop) @@ -113,7 +116,7 @@ from wireless network with id ID." enwc-wicd-dbus-wireless-path enwc-wicd-dbus-wireless-interface "GetWirelessProperty" - 'enwc-wicd-nw-prop-handler + `(lambda (x) (enwc-wicd-nw-prop-handler ,prop x)) :timeout 1000 :int32 id :string prop)) @@ -121,14 +124,21 @@ from wireless network with id ID." (defun enwc-wicd-build-prop-list (prop-list det-list) (let (ret (act-det-list (reverse det-list))) - (while prop-list - (let ((cur-prop (pop prop-list)) - (cur-det (pop act-det-list))) - (setq ret (append ret (cons (cons cur-det (car cur-prop)) nil))) + (while act-det-list + (let* ((cur-det (pop act-det-list)) + (cur-prop (assoc cur-det prop-list))) + (setq ret + (if cur-prop + (cons cur-prop ret) + (cons (cons cur-det nil) nil))) )) ret)) (defun enwc-wicd-get-wireless-nw-props (id) + "Get the network properties of a network. +This function returns an associative list of properties +for the network with id ID. +For a list of properties, see `enwc-wicd-details-list'." (setq enwc-wicd-prop-values nil) (setq enwc-wicd-prop-num 0) (mapc (lambda (x) @@ -138,8 +148,7 @@ from wireless network with id ID." (with-timeout (enwc-wicd-prop-timeout) (while (< enwc-wicd-prop-num 6) (read-event nil nil 0.001))) - (while (< enwc-wicd-prop-num 6) - (enwc-wicd-nw-prop-handler nil)) + (enwc-wicd-build-prop-list enwc-wicd-prop-values enwc-wicd-details-list)) (defun enwc-wicd-get-encryption-type (id) @@ -159,7 +168,6 @@ network with id ID." "Wicd get current network id function. This calls the D-Bus method on Wicd to get the current wireless network id." - ;;(enwc-wicd-dbus-wireless-call-method "GetCurrentNetworkID")) (if wired -1 enwc-wicd-current-nw-id)) @@ -332,8 +340,7 @@ the network with id ID." (nthcdr 3 info) (caar (nthcdr 3 info)) (string-to-number (caar (nthcdr 3 info)))) - -1))) - )) + -1))))) (defun enwc-wicd-setup () ;; Thanks to Michael Albinus for pointing out this signal. @@ -349,8 +356,7 @@ the network with id ID." "/org/wicd/daemon" enwc-wicd-dbus-service "StatusChanged" - 'enwc-wicd-wireless-prop-changed) - ) + 'enwc-wicd-wireless-prop-changed)) (provide 'enwc-wicd) diff --git a/lisp/enwc.el b/lisp/enwc.el index a131516..825cb5f 100644 --- a/lisp/enwc.el +++ b/lisp/enwc.el @@ -308,6 +308,7 @@ network with id ID." "Gets the list of wired profiles." (funcall enwc-get-wired-profiles-func)) +;;TODO: Add hooks to run after connecting. (defun enwc-wireless-connect (id) "Begins a connection to wireless network with id ID." @@ -446,14 +447,18 @@ the scan results." (if (or enwc-using-wired (not enwc-scan-requested)) nil (setq enwc-scan-requested nil) - (let ((cur-id 0)) + (let ((cur-id 0) + (nw-prop-list nil)) (message "Scanning... Done") (setq enwc-access-points (enwc-get-nw) enwc-essid-width 5) + (setq nw-prop-list + (mapcar 'enwc-get-wireless-nw-props + (number-sequence 0 (1- (length enwc-access-points))))) (setq enwc-last-scan (mapcar (lambda (x) (let ((ret-itm (cons (cons "id" cur-id) nil)) - (prop-list (enwc-get-wireless-nw-props x))) + (prop-list (pop nw-prop-list))) (setq cur-id (1+ cur-id)) (dolist (det enwc-details-list) (let ((cur-item (cdr (assoc det prop-list))) @@ -479,11 +484,7 @@ the scan results." (setq enwc-essid-width (1+ enwc-essid-width)) (setq enwc-scan-done t) (if enwc-scan-interactive - (progn - (enwc-display-wireless-networks enwc-last-scan) - ;;(goto-char 0) - ;;(forward-line) - )))) + (enwc-display-wireless-networks enwc-last-scan)))) (defun enwc-scan-internal-wired () "The scanning routine for a wired connection. @@ -541,10 +542,8 @@ NETWORKS must be in the format returned by (enwc-setup-buffer)) (if (not (listp networks)) (error "NETWORKS must be a list of association lists.")) - (let (;;(inhibit-read-only t) - (cur-id (enwc-get-current-nw-id)) + (let ((cur-id (enwc-get-current-nw-id)) entries) - ;;(erase-buffer) (let ((header enwc-wireless-headers) (pos 0)) @@ -555,17 +554,7 @@ NETWORKS must be in the format returned by '("ENCRYPT" 9) '("BSSID" 17) '("MODE" 15) - '("CHNL" 2))) - - ;; (dolist (hd header) - ;; (insert (propertize hd 'face 'enwc-header-face)) - ;; (setq pos (length hd)) - ;; (insert-char 32 (- (symbol-value (intern (concat "enwc-" - ;; (downcase hd) - ;; "-width"))) - ;; pos))) - ) - ;;(insert "\n") + '("CHNL" 2)))) ;;TODO: Setup faces. (dolist (nw networks) @@ -574,9 +563,9 @@ NETWORKS must be in the format returned by (setq entry (list nil (vector (number-to-string (cdr (assoc "id" nw))) - (concat (number-to-string (cdr (assoc "quality" nw))) + (concat (number-to-string (cdr (assoc "quality" nw))) "%") - (cdr (assoc "essid" nw)) + (cdr (assoc "essid" nw)) (cdr (assoc "encryption" nw)) (cdr (assoc "bssid" nw)) (cdr (assoc "mode" nw)) @@ -586,34 +575,7 @@ NETWORKS must be in the format returned by (setq tabulated-list-entries (nreverse entries)) (tabulated-list-init-header) - ;; (dolist (nw networks) - ;; (let* ((id (propertize (number-to-string (cdr (assoc "id" nw))) - ;; 'width enwc-id-width)) - ;; (str (propertize (concat (number-to-string (cdr (assoc "quality" - ;; nw))) - ;; "%") - ;; 'width enwc-str-width)) - ;; (essid (propertize (cdr (assoc "essid" nw)) - ;; 'width enwc-essid-width)) - ;; (encrypt (propertize (cdr (assoc "encryption" nw)) - ;; 'width enwc-encrypt-width)) - ;; (bssid (propertize (cdr (assoc "bssid" nw)) - ;; 'width enwc-bssid-width)) - ;; (mode (propertize (cdr (assoc "mode" nw)) - ;; 'width enwc-mode-width)) - ;; (chnl (propertize (cdr (assoc "channel" nw)) - ;; 'width enwc-chnl-width)) - ;; props) - - ;; (setq props (list id str essid encrypt bssid mode chnl)) - - ;; (dolist (ent props) - ;; (if (eq (string-to-number id) cur-id) - ;; (setq ent (propertize ent 'face 'enwc-connected-face))) - ;; (enwc-insert-ent ent (get-text-property 0 'width ent))) - ;; (insert "\n"))) - (tabulated-list-print) - )) + (tabulated-list-print))) (defun enwc-display-networks (networks) "Displays the network in NETWORKS. This is an entry to the display @@ -631,15 +593,15 @@ functions, and checks whether or not ENWC is using wired." the ENWC buffer if necessary, and scans and displays the networks." (interactive) (setq enwc-scan-interactive t) - (if (not (eq major-mode 'enwc-mode)) - (switch-to-buffer "*ENWC*")) - (if enwc-using-wired - (progn - (enwc-scan-internal) - ;;(enwc-display-networks enwc-last-scan) - (goto-char 0) - (forward-line)) - (enwc-scan-internal))) + (if (get-buffer "*ENWC*") + (with-current-buffer "*ENWC*" + (if enwc-using-wired + (progn + (enwc-scan-internal) + ;;(enwc-display-networks enwc-last-scan) + (goto-char 0) + (forward-line)) + (enwc-scan-internal))))) (defun enwc-find-network (essid &optional networks) "Checks through NETWORKS for the network with essid ESSID,