branch: master commit cb321220de2ab88f4fe13bb7049878aaab7348e1 Author: Ian D <du...@gnu.org> Commit: Ian D <du...@gnu.org>
(enwc-nm-prop-to-prop, enwc-wicd-prop-to-prop): Convert the properties used internally to the property names used externally. (enwc-nm-get-wireless-nw-props, enwc-wicd-build-prop-list): Uses the external property names for the returned assocative list. (enwc-nm-get-wireless-nw-props, enwc-wicd-get-wireless-nw-props): Get the encryption type in the back-ends instead of the front-end. (enwc-setup-backend): No longer initializes enwc-details-list. (enwc-wicd-get-current-nw-id): Uses the actual d-bus functions instead of tracking the network id internally. (enwc-details-list): Initialized in the front-end. (enwc-str-width): Changed to enwc-strength-width. (enwc-chnl-width): Changed to enwc-channel-width. (enwc-detail-to-ident): Removed. (enwc-format-mode-line-string): Only calls the functions to check for a pending or wired connection once. (enwc-enable-display-mode-line, enwc-disable-display-mode-line, enwc-toggle-auto-scan): Displays a message when finished. (enwc-process-scan, enwc-display-wireless-networks): Sets the width of each display column (enwc-process-scan): Redisplays the network list even when non-interactive. --- lisp/enwc-nm.el | 29 ++++++++++++-- lisp/enwc-setup.el | 3 -- lisp/enwc-wicd.el | 40 +++++++++++++++----- lisp/enwc.el | 109 +++++++++++++++++++++++++---------------------------- 4 files changed, 106 insertions(+), 75 deletions(-) diff --git a/lisp/enwc-nm.el b/lisp/enwc-nm.el index 20b3d16..32a9245 100644 --- a/lisp/enwc-nm.el +++ b/lisp/enwc-nm.el @@ -299,7 +299,18 @@ PROP from that access point. It also sets the channel from the ((= ret 2) "Infrastructure")))) ret)) +(defun enwc-nm-prop-to-prop (prop) + "Converts a NetworkManager property to an ENWC network property." + (cond + ((equal prop "Ssid") "essid") + ((equal prop "HwAddres") "bssid") + ((equal prop "Strength") "strength") + ((equal prop "Flags") "encrypt") + ((equal prop "Mode") "mode") + ((equal prop "Channel") "channel"))) + (defun enwc-nm-get-wireless-nw-props (id) + "Gets the network properties for the network with id ID." (let ((ap (nth id enwc-access-points)) tmp-val ret) @@ -310,14 +321,25 @@ PROP from that access point. It also sets the channel from the (setq tmp-val (cdr (assoc "Mode" ret))) (setcdr (assoc "Frequency" ret) (number-to-string (1+ (/ (- (cdr (assoc "Frequency" ret)) - 2412) 5)))) + 2412) + 5)))) (setcdr (assoc "Ssid" ret) (dbus-byte-array-to-string (cdr (assoc "Ssid" ret)))) (setcdr (assoc "Mode" ret) (cond ((= tmp-val 0) "Unkown") ((= tmp-val 1) "Ad-Hoc") ((= tmp-val 2) "Infrastructure"))) - ret)) + (let ((enc-type (enwc-nm-get-encryption-type id))) + (setcdr (assoc "Flags" ret) + (if enc-type + enc-type + "Unsecured"))) + (mapcar + (lambda (x) + (cons (enwc-nm-prop-to-prop (car x)) + (cdr x))) + ret))) + ;;ret)) (defun enwc-nm-get-conn-by-nid (nid) "Gets a connection object with the network id NID." @@ -901,8 +923,7 @@ and SETTINGS is the list of settings." enwc-nm-dbus-path enwc-nm-dbus-interface "StateChanged" - 'enwc-nm-prop-changed) - ) + 'enwc-nm-prop-changed)) (provide 'enwc-nm) diff --git a/lisp/enwc-setup.el b/lisp/enwc-setup.el index 2dc9f16..52f0a64 100644 --- a/lisp/enwc-setup.el +++ b/lisp/enwc-setup.el @@ -42,9 +42,6 @@ enwc-get-wireless-nw-props-func (intern (concat "enwc-" sym-name "-get-wireless-nw-props")) - enwc-details-list (symbol-value (intern (concat "enwc-" - sym-name - "-details-list"))) enwc-get-encryption-type-func (intern (concat "enwc-" sym-name "-get-encryption-type")) diff --git a/lisp/enwc-wicd.el b/lisp/enwc-wicd.el index b6db670..377987b 100644 --- a/lisp/enwc-wicd.el +++ b/lisp/enwc-wicd.el @@ -107,6 +107,16 @@ 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-prop-to-prop (prop) + "Converts a Wicd network property to an ENWC network property." + (cond + ((equal prop "essid") "essid") + ((equal prop "bssid") "bssid") + ((equal prop "quality") "strength") + ((equal prop "encryption") "encrypt") + ((equal prop "mode") "mode") + ((equal prop "channel") "channel"))) + (defun enwc-wicd-get-wireless-network-property (id prop) "Wicd get wireless network property function. This calls the D-Bus method on Wicd to get the property PROP @@ -126,12 +136,14 @@ from wireless network with id ID." (act-det-list (reverse det-list))) (while act-det-list (let* ((cur-det (pop act-det-list)) - (cur-prop (assoc cur-det prop-list))) + (cur-prop (assoc cur-det prop-list)) + (act-det (enwc-wicd-prop-to-prop cur-det))) (setq ret - (if cur-prop - (cons cur-prop ret) - (cons (cons cur-det nil) nil))) - )) + (cons (cons act-det + (if cur-prop + (cdr cur-prop) + nil)) + ret)))) ret)) (defun enwc-wicd-get-wireless-nw-props (id) @@ -149,6 +161,14 @@ For a list of properties, see `enwc-wicd-details-list'." (while (< enwc-wicd-prop-num 6) (read-event nil nil 0.001))) + (if (assoc "encryption" enwc-wicd-prop-values) + (let ((enc-type (enwc-wicd-get-encryption-type id))) + (setcdr (assoc "encryption" enwc-wicd-prop-values) + (or enc-type "Unsecured"))) + (setq enwc-wicd-prop-values + (cons (cons "encryption" "Unsecured") + enwc-wicd-prop-values))) + (enwc-wicd-build-prop-list enwc-wicd-prop-values enwc-wicd-details-list)) (defun enwc-wicd-get-encryption-type (id) @@ -166,11 +186,12 @@ network with id ID." (defun enwc-wicd-get-current-nw-id (wired) "Wicd get current network id function. -This calls the D-Bus method on Wicd to get the current -wireless network id." +The current network id is updated upon connect, +so this jut returns the tracked network id." (if wired -1 - enwc-wicd-current-nw-id)) + (enwc-wicd-dbus-wireless-call-method "GetCurrentNetworkID"))) + ;;enwc-wicd-current-nw-id)) (defun enwc-wicd-check-connecting () "The Wicd check connecting function." @@ -327,8 +348,7 @@ the network with id ID." (enwc-wicd-get-sec-types wired)))))) (enwc-wicd-set-nw-prop wired id (car x) (cdr (assoc (car x) settings))))) - (enwc-wicd-save-nw-profile wired id)) - ) + (enwc-wicd-save-nw-profile wired id))) (defun enwc-wicd-wireless-prop-changed (state info) (if state diff --git a/lisp/enwc.el b/lisp/enwc.el index 6b94115..8787021 100644 --- a/lisp/enwc.el +++ b/lisp/enwc.el @@ -25,7 +25,8 @@ ;; connect ;; disconnect ;; scan -;; get-prop +;; get-network-prop +;; get-profile-prop ;; save-profile ;; get-networks ;; check-connecting @@ -206,7 +207,8 @@ the DNS Server Addresses for a given network.") This is redefined during setup to be the function to save the network settings of a given network.") -(defvar enwc-details-list nil +(defvar enwc-details-list + '("essid" "bssid" "strength" "mode" "encrypt" "channel") "The network details list. This is redefined during setup to be the details list @@ -232,7 +234,7 @@ These correspond to the details in `enwc-details-list'.") (defvar enwc-id-width 3 "The width of the id column.") -(defvar enwc-str-width 5 +(defvar enwc-strength-width 5 "The width of the strength column.") (defvar enwc-essid-width 5 "The initial width of the essid column. @@ -243,7 +245,7 @@ This is reset in wicd-scan-internal.") "The width of the bssid column.") (defvar enwc-mode-width 16 "The width of the mode column.") -(defvar enwc-chnl-width 3 +(defvar enwc-channel-width 3 "The width of the channel column.") (defvar enwc-last-scan nil @@ -291,21 +293,6 @@ This is only used internally.") "The face for the connected network." :group 'enwc) - -;; Small helper function. - -(defun enwc-detail-to-ident (detail) - "Converts network detail DETAIL to a constant identifier. -This function is used to synchronize the different backends -to display consistent results." - (case (intern detail) - ((essid Ssid) "essid") - ((bssid HwAddress) "bssid") - ((quality Strength) "quality") - ((encryption Flags) "encryption") - ((mode Mode) "mode") - ((channel Frequency) "channel"))) - ;;;;;;;;;;;;;;;;;;;; ;; ENWC functions ;;;;;;;;;;;;;;;;;;;; @@ -451,10 +438,12 @@ See the documentation for it for more details." (p 0) (l (length f)) (cur-id (enwc-get-current-nw-id)) + (wiredp (enwc-is-wired-p)) + (connectingp (enwc-check-connecting-p)) c fin-str) (while (< p l) - (setq c (elt f p)) - (setq p (1+ p)) + (setq c (elt f p) + p (1+ p)) (setq fin-str (concat fin-str @@ -464,24 +453,24 @@ See the documentation for it for more details." (cond ((eq (elt f (1- p)) ?s) (cond - ((enwc-is-wired-p) "100") + (wiredp "100") ((or (not (enwc-is-valid-nw-id cur-id)) (not enwc-last-scan))"0") - ((enwc-check-connecting-p) "*") + (connectingp "*") (t (number-to-string - (cdr (assoc "quality" (nth cur-id enwc-last-scan))))))) + (cdr (assoc "strength" (nth cur-id enwc-last-scan))))))) ((eq (elt f (1- p)) ?e) (cond - ((enwc-is-wired-p) "Wired") + (wiredp "Wired") ((or (not (enwc-is-valid-nw-id cur-id)) - (enwc-check-connecting-p) + connectingp (not enwc-last-scan)) "None") (t (cdr (assoc "essid" (nth cur-id enwc-last-scan)))))) ((eq (elt f (1- p)) ?b) (cond - ((enwc-is-wired-p) "wired") + (wiredp "wired") ((or (not (enwc-is-valid-nw-id cur-id)) - (enwc-check-connecting-p) + connectingp (not enwc-last-scan)) "none") (t (cdr (assoc "bssid" (nth cur-id enwc-last-scan)))))) ((eq (elt f (1- p)) ?%) "%")))))) @@ -504,7 +493,8 @@ This is initiated during setup, and runs once every second." (setq global-mode-string (append global-mode-string '(enwc-display-string)))) (if (not enwc-display-mode-line-timer) (setq enwc-display-mode-line-timer - (run-at-time t 1 'enwc-update-mode-line)))) + (run-at-time t 1 'enwc-update-mode-line))) + (message "ENWC mode line enabled")) (defun enwc-disable-display-mode-line () "Disables the mode line display." @@ -514,7 +504,8 @@ This is initiated during setup, and runs once every second." (setq global-mode-string (remove 'enwc-display-string global-mode-string)) (if enwc-display-mode-line-timer (cancel-timer enwc-display-mode-line-timer)) - (setq enwc-display-mode-line-timer nil)) + (setq enwc-display-mode-line-timer nil) + (message "ENWC mode line disabled")) (defun enwc-toggle-display-mode-line () "Toggles the mode line display." @@ -529,9 +520,11 @@ This will use the current value of `enwc-auto-scan-interval'." (interactive) (let ((new (not enwc-auto-scan))) (if new - (setq enwc-scan-timer - (run-at-time t enwc-auto-scan-interval 'enwc-scan t)) - (cancel-timer enwc-scan-timer)) + (progn (setq enwc-scan-timer + (run-at-time t enwc-auto-scan-interval 'enwc-scan t)) + (message "Auto-scan enabled")) + (cancel-timer enwc-scan-timer) + (message "Auto scan disabled")) (setq enwc-auto-scan new))) ;;;;;;;;;;;;;;;;;; @@ -562,8 +555,10 @@ the scan results." (nw-prop-list nil)) (if enwc-scan-interactive (message "Scanning... Done")) - (setq enwc-access-points (enwc-get-nw) - enwc-essid-width 5) + (setq enwc-access-points (enwc-get-nw)) + (dolist (det enwc-details-list) + (set (intern (concat "enwc-" det "-width")) + 1)) (setq nw-prop-list (mapcar 'enwc-get-wireless-nw-props (number-sequence 0 (1- (length enwc-access-points))))) @@ -573,20 +568,18 @@ the scan results." (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))) - (ident (enwc-detail-to-ident det)) - pos-len) - (if (string= ident "essid") - (progn - (setq pos-len (length cur-item)) - (setq enwc-essid-width - (max enwc-essid-width - pos-len)))) - (if (string= ident "encryption") - (setq cur-item - (if cur-item - (enwc-get-encryption-type x) - "Unsecured"))) + (let* ((cur-item (cdr (assoc det prop-list))) + (ident det) + (width-name (concat "enwc-" + ident + "-width")) + (cur-width (eval (intern width-name))) + (pos-len (if (and cur-item + (not (equal ident "strength"))) + (length cur-item) + 0))) + (set (intern width-name) + (max cur-width pos-len)) (setq ret-itm (append ret-itm (cons (cons ident cur-item) @@ -595,8 +588,8 @@ the scan results." (number-sequence 0 (1- (length enwc-access-points)))))) (setq enwc-essid-width (1+ enwc-essid-width)) (setq enwc-scan-done t) - (if enwc-scan-interactive - (enwc-display-wireless-networks enwc-last-scan)) + ;;(if enwc-scan-interactive + (enwc-display-wireless-networks enwc-last-scan);;) (setq enwc-scan-interactive nil))) (defun enwc-scan-internal-wired () @@ -668,13 +661,13 @@ NETWORKS must be in the format returned by (pos 0)) (setq tabulated-list-format - (vector '("ID" 2) + (vector `("ID" ,enwc-id-width) '("STR" 4) `("ESSID" ,enwc-essid-width) - '("ENCRYPT" 9) - '("BSSID" 17) - '("MODE" 15) - '("CHNL" 2)))) + `("ENCRYPT" ,enwc-encrypt-width) + `("BSSID" ,enwc-bssid-width) + `("MODE" ,enwc-mode-width) + `("CHNL" ,enwc-channel-width)))) (dolist (nw networks) (let ((id (cdr (assoc "id" nw))) @@ -683,10 +676,10 @@ NETWORKS must be in the format returned by (vector (enwc-maybe-pretty-entry (number-to-string (cdr (assoc "id" nw)))) (enwc-maybe-pretty-entry - (concat (number-to-string (cdr (assoc "quality" nw))) + (concat (number-to-string (cdr (assoc "strength" nw))) "%")) (enwc-maybe-pretty-entry (cdr (assoc "essid" nw))) - (enwc-maybe-pretty-entry (cdr (assoc "encryption" nw))) + (enwc-maybe-pretty-entry (cdr (assoc "encrypt" nw))) (enwc-maybe-pretty-entry (cdr (assoc "bssid" nw))) (enwc-maybe-pretty-entry (cdr (assoc "mode" nw))) (enwc-maybe-pretty-entry (cdr (assoc "channel" nw))))))