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

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

[elpa] master 942d83d 15/76: enwc.el, enwc-setup.el: Consolidated and co


From: Ian Dunn
Subject: [elpa] master 942d83d 15/76: enwc.el, enwc-setup.el: Consolidated and concretely defined front-end interface.
Date: Thu, 23 Feb 2017 19:42:45 -0500 (EST)

branch: master
commit 942d83dd249c992cc71e4d0493d6286b1d5561df
Author: Ian D <address@hidden>
Commit: Ian D <address@hidden>

    enwc.el, enwc-setup.el: Consolidated and concretely defined front-end 
interface.
    enwc-wicd.el, enwc-nm.el: Cleaned up code to fit front-end (excluding 
security)
    enwc-cm.el: Added more to the back-end definition.
---
 doc/connman.txt    |   29 +-
 lisp/enwc-cm.el    |  350 ++++++++++++---
 lisp/enwc-nm.el    | 1021 +++++++++++++++++++++-----------------------
 lisp/enwc-setup.el |  101 ++---
 lisp/enwc-wicd.el  |  299 ++++++-------
 lisp/enwc.el       | 1205 +++++++++++++++++++++++++---------------------------
 6 files changed, 1556 insertions(+), 1449 deletions(-)

diff --git a/doc/connman.txt b/doc/connman.txt
index dafbe38..0084365 100644
--- a/doc/connman.txt
+++ b/doc/connman.txt
@@ -4,4 +4,31 @@ net.connman.Manager.GetTechnologies():
 
 net.connman.Manager.GetServices():
 
-(("/net/connman/service/wifi_0026b6e6518e_7270695f3830322e3178_managed_wep" 
(("Type" ("wifi")) ("Security" (("wep"))) ("State" ("idle")) ("Strength" (79)) 
("Favorite" (nil)) ("Immutable" (nil)) ("AutoConnect" (nil)) ("Name" 
("rpi_802.1x")) ("Ethernet" ((("Method" ("auto")) ("Interface" ("wlan0")) 
("Address" ("00:26:B6:E6:51:8E")) ("MTU" (1500))))) ("IPv4" (nil)) 
("IPv4.Configuration" ((("Method" ("dhcp"))))) ("IPv6" (nil)) 
("IPv6.Configuration" ((("Method" ("auto")) ("Privacy" ("disabled [...]
+(("/net/connman/service/wifi_0026b6e6518e_7270695f3830322e3178_managed_wep"
+  (("Type" ("wifi"))
+   ("Security" (("wep")))
+   ("State" ("idle"))
+   ("Strength" (79))
+   ("Favorite" (nil))
+   ("Immutable" (nil))
+   ("AutoConnect" (nil))
+   ("Name" ("rpi_802.1x"))
+   ("Ethernet"
+     ((("Method" ("auto"))
+     ("Interface" ("wlan0"))
+     ("Address" ("00:26:B6:E6:51:8E"))
+     ("MTU" (1500)))))
+   ("IPv4" (nil))
+   ("IPv4.Configuration" ((("Method" ("dhcp")))))
+   ("IPv6" (nil))
+   ("IPv6.Configuration" ((("Method" ("auto")) ("Privacy" ("disabled")))))
+   ("Nameservers" (nil))
+   ("Nameservers.Configuration" (nil))
+   ("Timeservers" (nil))
+   ("Timeservers.Configuration" (nil))
+   ("Domains" (nil))
+   ("Domains.Configuration" (nil))
+   ("Proxy" (nil))
+   ("Proxy.Configuration" (nil))
+   ("Provider" (nil))
+   )) ("/net/connman/service/wifi_0026b6e6518e_hidden_managed_none" (("Type" 
("wifi")) ("Security" (("none"))) ("State" ("idle")) ("Strength" (79)) 
("Favorite" (nil)) ("Immutable" (nil)) ("AutoConnect" (nil)) ("Ethernet" 
((("Method" ("auto")) ("Interface" ("wlan0")) ("Address" ("00:26:B6:E6:51:8E")) 
("MTU" (1500))))) ("IPv4" (nil)) ("IPv4.Configuration" ((("Method" ("dhcp"))))) 
("IPv6" (nil)) ("IPv6.Configuration" ((("Method" ("auto")) ("Privacy" 
("disabled"))))) ("Nameservers" (nil)) (" [...]
diff --git a/lisp/enwc-cm.el b/lisp/enwc-cm.el
index 21faba6..5ff6eef 100644
--- a/lisp/enwc-cm.el
+++ b/lisp/enwc-cm.el
@@ -55,97 +55,313 @@
   :group 'enwc-cm
   :type 'string)
 
+(defcustom enwc-cm-dbus-technology-interface "net.connman.Technology"
+  "ConnMan D-Bus Technology Interface"
+  :group 'enwc-cm
+  :type 'string)
+
+(defcustom enwc-cm-dbus-technology-path "/net/connman/technology/"
+  "ConnMan D-Bus Technology Path"
+  :group 'enwc-cm
+  :type 'string)
+
+(defcustom enwc-cm-dbus-service-path "/net/connman/service"
+  "ConnMan D-Bus Service Path"
+  :group 'enwc-cm
+  :type 'string)
+
+(defcustom enwc-cm-dbus-agent-service "org.gnu.enwc.agent"
+  "The service for the ConnMan Agent for ENWC to use."
+  :group 'enwc-cm
+  :type 'string)
+
+(defcustom enwc-cm-dbus-agent-path "/org/gnu/enwc/agent"
+  "The path to the Agent for ENWC to use for ConnMan security."
+  :group 'enwc-cm
+  :type 'string)
+
+(defcustom enwc-cm-dbus-agent-interface "org.gnu.enwc.agent"
+  "The interface for the ConnMan Agent for ENWC to use."
+  :group 'enwc-cm
+  :type 'string)
+
 (defvar enwc-cm-details-list
-  '("Name" "bssid" "Strength" "Security" "mode" "channel"))
+  '("Name" "Ethernet/Address" "Strength" "Security" "mode" "channel"))
 
-(defun enwc-cm-get-services ()
-  (dbus-call-method :system
-                   enwc-cm-dbus-service
-                   "/"
-                   enwc-cm-dbus-manager-interface
-                   "GetServices"))
+(defun enwc-cm-get-wifi-tech-path ()
+  "Return the ConnMan Wifi Technology path."
+  (concat enwc-cm-dbus-technology-path "wifi"))
 
-(defun enwc-cm-get-networks ()
-  (let ((services (enwc-cm-get-services)))
-    (mapcar 'car services)))
+(defun enwc-cm-get-wired-tech-path ()
+  "Return the ConnMan Ethernet Technology path."
+  (concat enwc-cm-dbus-technology-path "ethernet"))
 
 (defun enwc-cm-get-network (id)
   (nth id (enwc-cm-get-services)))
 
-;; scan
-(defun enwc-cm-scan (wired)
-  (dbus-call-method :system
-                   enwc-cm-dbus-service
-                   "/net/connman/technology/(ethernet|wifi)"
-                   "net.connman.Technology"
-                   "Scan"))
-
 ;; connect
 (defun enwc-cm-connect (wired id)
-  (dbus-call-method :system
-                   enwc-cm-dbus-service
-                   "/net/connman/service/serviceID"
-                   enwc-cm-dbus-service-interface
-                   "Connect"))
-
+  (let ((path (concat enwc-cm-dbus-service-path (number-to-string id))))
+    (dbus-call-method :system
+                      enwc-cm-dbus-service
+                      path
+                      enwc-cm-dbus-service-interface
+                      "Connect")))
 
+;; disconnect
 (defun enwc-cm-disconnect (wired)
   (dbus-call-method :system
-                   enwc-cm-dbus-service
-                   "/net/connman/service/CONNECTED-SERVICE"
-                   enwc-cm-dbus-service-interface
-                   "Disconnect"))
+                    enwc-cm-dbus-service
+                    "/net/connman/service/CONNECTED-SERVICE"
+                    enwc-cm-dbus-service-interface
+                    "Disconnect"))
+
+;; scan
+(defun enwc-cm-scan (wired)
+  (let ((path (if wired (enwc-cm-get-wired-tech-path)
+                (enwc-cm-get-wifi-tech-path))))
+    (dbus-call-method-asynchronously :system
+                                     path
+                                     enwc-cm-dbus-technology-interface
+                                     "Scan"
+                                     'enwc-process-scan
+                                     :timeout 6000)))
+
+;; (defun enwc-cm-scan (wired)
+;;   (dbus-call-method :system
+;;                  enwc-cm-dbus-service
+;;                  "/net/connman/technology/(ethernet|wifi)"
+;;                  "net.connman.Technology"
+;;                  "Scan"))
+
+;; get-network-props
+(defun enwc-cm-dict-assoc (dict prop)
+  (let ((path-list (split-string prop "/"))
+        (cur-list dict))
+    (while (and path-list cur-list)
+      (let ((cur-path (pop path-list)))
+        (setq cur-list
+              (if (assoc cur-path cur-list)
+                  (caadr (assoc cur-path cur-list))
+                nil))))
+    (if (and cur-list (consp cur-list)) (car cur-list) cur-list)))
 
 (defun enwc-cm-get-nw-prop (id prop)
   (let ((network (enwc-cm-get-network id)))
     (car (cadr (assoc prop (cadr network))))))
 
+(defun enwc-cm-get-network-props (id wired)
+  (let ((network (enwc-cm-get-network id))
+         props)
+    ;; network should be a pair, (path . props)
+    (if (not network)
+        (error "Invalid Network Id %d" id))
+    (setq props (cadr network))
+    (mapcar
+     (lambda (det)
+       (enwc-cm-dict-assoc props det))
+     enwc-cm-details-list)))
+
 (defun enwc-cm-get-wireless-network-property (id prop)
   (enwc-cm-get-nw-prop id prop))
 
-(defun enwc-cm-get-encryption-type (id)
-  (enwc-cm-get-nw-prop id "Security"))
+;; get-profile-props
+(defun enwc-cm-get-profile-props (prof wired)
+  (let ((network (enwc-cm-get-network prof))
+        props
+        ipv4-settings
+        dns-settings)
+    (if (not network)
+        (error "Invalid Network Id %d" id))
+    (setq props (cadr network))
+    (setq ipv4-settings (enwc-cm-dict-assoc "IPv4.Configuration" props)
+          dns-settings  (enwc-cm-dict-assoc "Domains.Configuration" props))
+    `(("addr"    . ,(cadr (assoc "Address" ipv4-settings)))
+      ("netmask" . ,(cadr (assoc "Netmask" ipv4-settings)))
+      ("gateway" . ,(cadr (assoc "Gateway" ipv4-settings)))
+      ("dns1"    . ,(nth 0 dns-settings))
+      ("dns2"    . ,(nth 1 dns-settings)))))
+
+;; get-current-nw-id
+(defun enwc-cm-is-disconnected-p (service)
+  (member (enwc-cm-dict-assoc (cadr service) "State")
+          '("idle" "disconnect")))
 
-(defun enwc-cm-get-ip-addr (wired id)
-  (let ((ipv4-config (enwc-cm-get-nw-prop id "IPv4.Configuration")))
-    (car (cadr (assoc "Address" ipv4-config)))))
+(defun enwc-cm-is-connecting-p (service)
+  (member (enwc-cm-dict-assoc (cadr service) "State")
+          '("association" "configuration")))
 
-(defun enwc-cm-get-netmask (wired id)
-  (let ((ipv4-config (enwc-cm-get-nw-prop id "IPv4.Configuration")))
-    (car (cadr (assoc "Netmask" ipv4-config)))))
+(defun enwc-cm-is-connected-p (service)
+  (member (enwc-cm-dict-assoc (cadr service) "State")
+          '("ready" "online")))
 
-(defun enwc-cm-get-gateway (wired id)
-  (let ((ipv4-config (enwc-cm-get-nw-prop id "IPv4.Configuration")))
-    (car (cadr (assoc "Gateway" ipv4-config)))))
+(defun enwc-cm--find-connected-service (services num)
+  (if services
+      (if (enwc-cm-is-connected-p (car services))
+          num
+        (enwc-cm--find-connected-service (cdr services) (1+ num)))
+    -1))
 
-(defun enwc-cm-get-dns (wired id)
-  (enwc-cm-get-nw-prop id "Nameservers.Configuration"))
+(defun enwc-cm-get-current-nw-id ()
+  "Get the current network id."
+  (let* ((services (enwc-cm-get-services)))
+    (enwc-cm--find-connected-service services 0)))
 
+;; save-profile
 (defun enwc-cm-set-nw-prop (wired id prop val)
   (dbus-call-method :system
-                   enwc-cm-dbus-service
-                   (car (enwc-cm-get-network id))
-                   enwc-cm-dbus-service-interface
-                   "SetProperty"
-                   prop
-                   val))
-
-(defun enwc-cm-save-nw-settings (wired id settings)
-  (let* ((ipv4 (enwc-cm-get-nw-prop id "IPv4.Configuration"))
-        (method (car (cadr (assoc "Method" ipv4))))
-        (ip-addr (cdr (assoc "addr" settings)))
-        (netmask (cdr (assoc "netmask" settings)))
-        (gateway (cdr (assoc "gateway" settings)))
-        new-ipv4-config new-dns-config)
-    (setq new-ipv4-config
-         (list (list (cons "Method" (cons (cons method nil) nil))
-                     (cons "Address" (cons (cons ip-addr nil) nil))
-                     (cons "Netmask" (cons (cons netmask nil) nil))
-                     (cons "Gateway" (cons (cons gateway nil) nil)))))
-    (setq new-dns-config
-         (list (list (cdr (assoc "dns1" settings))
-                     (cdr (assoc "dns2" settings)))))
-    (enwc-cm-set-nw-prop wired id "IPv4.Configuration"
-                        new-ipv4-config)
-    (enwc-cm-set-nw-prop wired id "Nameservers.Configuration"
-                        new-dns-config)))
+                    enwc-cm-dbus-service
+                    (car (enwc-cm-get-network id))
+                    enwc-cm-dbus-service-interface
+                    "SetProperty"
+                    :string prop
+                    val))
+
+(defun enwc-cm-save-profile (prof settings wired)
+  (let ((network (enwc-cm-get-network prof))
+        props
+        ipv4-settings
+        dns-settings)
+    (if (not network)
+        (error "Invalid Network Id %d" id))
+    (setq props (cadr network))
+    (setq ipv4-settings
+          `((("Method" ("manual"))
+             ("Address" (,(cdr (assoc "addr" settings))))
+             ("Netmask" (,(cdr (assoc "netmask" settings))))
+             ("Gateway" (,(cdr (assoc "gateway" settings)))))))
+    (setq dns-settings
+          `((,(cdr (assoc "dns1" settings)))
+            (,(cdr (assoc "dns2" settings)))))
+    (enwc-cm-set-nw-prop wired prof "IPv4.Configuration" ipv4-settings)
+    (enwc-cm-set-nw-prop wired prof "Domains.Configuration" dns-settings)))
+
+;; check-connecting-p
+(defun enwc-cm--find-connecting-service (services)
+  (if services
+      (or (enwc-cm-is-connecting-p (car services))
+          (enwc-cm--find-connecting-service (cdr services)))))
+
+(defun enwc-cm-check-connecting-p ()
+  (let ((services (enwc-cm-get-services)))
+    (enwc-cm--find-connecting-service services)))
+
+;; get-networks
+(defun enwc-cm-get-services ()
+  (dbus-call-method :system
+                    enwc-cm-dbus-service
+                    "/"
+                    enwc-cm-dbus-manager-interface
+                    "GetServices"))
+
+(defun enwc-cm-get-networks ()
+  (let ((services (enwc-cm-get-services)))
+    (mapcar 'car services)))
+
+;; Agent
+;; ConnMan requires that an agent is registered, so we create one here.
+
+(defun enwc-cm-agent-release (&rest args)
+  )
+
+(defun enwc-cm-agent-report-error (service err)
+  )
+
+(defun enwc-cm-agent-report-peer-error (peer err))
+
+(defun enwc-cm-agent-request-browser (service url)
+  (browse-url url))
+
+(defun enwc-cm-agent-request-input (service fields)
+  "Called when a user requests input.
+SERVICE is the current service.
+FIELDS is an associative list of requested fields."
+  ;; Obtain the information from somewhere.
+  )
+
+(defun enwc-cm-agent-request-peer-authorization (peer fields))
+
+(defun enwc-cm-agent-cancel ())
+
+(defun enwc-cm-method-to-defun (method)
+  (let ((case-fold-search nil))
+    (combine-and-quote-strings
+     (mapcar 'downcase
+             (cdr (split-string
+                   (replace-regexp-in-string "\\([[:upper:]]\\)" " \\1" method)
+                   " ")))
+     "-")))
+
+(defmacro enwc-cm-agent-register-method (method)
+  "Register a method METHOD with D-Bus.
+METHOD is assumed to be the camel-case D-Bus method."
+  `((dbus-register-method :session
+                          enwc-cm-dbus-agent-service
+                          enwc-cm-dbus-agent-path
+                          enwc-cm-dbus-agent-interface
+                          ,method
+                          (quote ,(car (read-from-string
+                                        (concat
+                                         "enwc-cm-agent-"
+                                         (enwc-cm-method-to-defun 
method))))))))
+
+;; Run during setup.
+(defun enwc-cm-setup ()
+
+
+  ;; Setup the agent.
+  (dbus-register-service :session enwc-cm-dbus-agent-service)
+
+  (enwc-cm-agent-register-method "Release")
+  (enwc-cm-agent-register-method "ReportError")
+  (enwc-cm-agent-register-method "ReportPeerError")
+  (enwc-cm-agent-register-method "RequestBrowser")
+  (enwc-cm-agent-register-method "RequestInput")
+  (enwc-cm-agent-register-method "RequestPeerAuthorization")
+  (enwc-cm-agent-register-method "Cancel")
+
+  (dbus-call-method :system
+                    enwc-cm-dbus-manager-service
+                    enwc-cm-dbus-manager-path
+                    enwc-cm-dbus-manager-interface
+                    "RegisterAgent"
+                    :string enwc-cm-dbus-agent-path))
+
+
+;; (defun enwc-cm-get-encryption-type (id)
+;;   (enwc-cm-get-nw-prop id "Security"))
+
+;; (defun enwc-cm-get-ip-addr (wired id)
+;;   (let ((ipv4-config (enwc-cm-get-nw-prop id "IPv4.Configuration")))
+;;     (car (cadr (assoc "Address" ipv4-config)))))
+
+;; (defun enwc-cm-get-netmask (wired id)
+;;   (let ((ipv4-config (enwc-cm-get-nw-prop id "IPv4.Configuration")))
+;;     (car (cadr (assoc "Netmask" ipv4-config)))))
+
+;; (defun enwc-cm-get-gateway (wired id)
+;;   (let ((ipv4-config (enwc-cm-get-nw-prop id "IPv4.Configuration")))
+;;     (car (cadr (assoc "Gateway" ipv4-config)))))
+
+;; (defun enwc-cm-get-dns (wired id)
+;;   (enwc-cm-get-nw-prop id "Nameservers.Configuration"))
+
+;; (defun enwc-cm-save-nw-settings (wired id settings)
+;;   (let* ((ipv4 (enwc-cm-get-nw-prop id "IPv4.Configuration"))
+;;          (method (car (cadr (assoc "Method" ipv4))))
+;;          (ip-addr (cdr (assoc "addr" settings)))
+;;          (netmask (cdr (assoc "netmask" settings)))
+;;          (gateway (cdr (assoc "gateway" settings)))
+;;          new-ipv4-config new-dns-config)
+;;     (setq new-ipv4-config
+;;           (list (list (cons "Method" (cons (cons method nil) nil))
+;;                       (cons "Address" (cons (cons ip-addr nil) nil))
+;;                       (cons "Netmask" (cons (cons netmask nil) nil))
+;;                       (cons "Gateway" (cons (cons gateway nil) nil)))))
+;;     (setq new-dns-config
+;;           (list (list (cdr (assoc "dns1" settings))
+;;                       (cdr (assoc "dns2" settings)))))
+;;     (enwc-cm-set-nw-prop wired id "IPv4.Configuration"
+;;                          new-ipv4-config)
+;;     (enwc-cm-set-nw-prop wired id "Nameservers.Configuration"
+;;                          new-dns-config)))
diff --git a/lisp/enwc-nm.el b/lisp/enwc-nm.el
index 15f93dd..278d1a0 100644
--- a/lisp/enwc-nm.el
+++ b/lisp/enwc-nm.el
@@ -96,35 +96,35 @@
 
 (defvar enwc-nm-sec-types
   '(("eap-leap" . (("Name" . "eap-leap")
-                  ("reqs" . ((("identity" . "Username")
-                              ("password" . "Password"))))))
+                   ("reqs" . ((("identity" . "Username")
+                               ("password" . "Password"))))))
     ("eap-peap" . (("Name" . "eap-peap")
-                  ("reqs" . ((("anonymous-identity" . "Anonymous Identity")
-                              ("ca-cert" . "CA Certificate")
-                              ("phase2-auth" . "Inner Authentication")
-                              ("phase1-peapver" . "PEAP Version")
-                              ("identity" . "Username")
-                              ("password" . "Password"))))))
+                   ("reqs" . ((("anonymous-identity" . "Anonymous Identity")
+                               ("ca-cert" . "CA Certificate")
+                               ("phase2-auth" . "Inner Authentication")
+                               ("phase1-peapver" . "PEAP Version")
+                               ("identity" . "Username")
+                               ("password" . "Password"))))))
     ("eap-tls" . (("Name" . "eap-tls")
-                 ("reqs" . ((("identity" . "Identity")
-                             ("client-cert" . "User Certificate")
-                             ("ca-cert" . "CA Certificate")
-                             ("private-key" . "Private Key")
-                             ("private-key-password" . "Private Key 
Password"))))))
+                  ("reqs" . ((("identity" . "Identity")
+                              ("client-cert" . "User Certificate")
+                              ("ca-cert" . "CA Certificate")
+                              ("private-key" . "Private Key")
+                              ("private-key-password" . "Private Key 
Password"))))))
     ("eap-ttls" . (("Name" . "eap-ttls")
-                  ("reqs" . ((("anonymous-identity" . "Anonymous Identity")
-                              ("ca-cert" . "CA Certificate")
-                              ("phase2-auth" . "Inner Authentication")
-                              ("identity" . "Username")
-                              ("password" . "Password"))))))
+                   ("reqs" . ((("anonymous-identity" . "Anonymous Identity")
+                               ("ca-cert" . "CA Certificate")
+                               ("phase2-auth" . "Inner Authentication")
+                               ("identity" . "Username")
+                               ("password" . "Password"))))))
     ("wpa-psk" . (("Name" . "wpa2")
-                 ("reqs" . ((("psk" . "PSK"))))))
+                  ("reqs" . ((("psk" . "PSK"))))))
     ("wep" . (("Name" . "wep")
-             ("reqs" . ((("wep-key0" . "WEP Key")
-                         ("wep-key-type" . "WEP Key Type"))))))
+              ("reqs" . ((("wep-key0" . "WEP Key")
+                          ("wep-key-type" . "WEP Key Type"))))))
     ("leap" . (("Name" . "leap")
-              ("reqs" . ((("leap-username" . "Username")
-                         ("leap-password" . "Password"))))))
+               ("reqs" . ((("leap-username" . "Username")
+                           ("leap-password" . "Password"))))))
     )
   "The security types for NetworkManager.
 This is still in the process of being worked on."
@@ -148,110 +148,112 @@ This is still in the process of being worked on."
 (defvar enwc-nm-edit-info nil
   "The information for the network connection being edited.")
 
+(defun enwc-nm-dbus-call-method (method &optional path interface &rest args)
+  (unless path (setq path enwc-nm-dbus-path))
+  (unless interface (setq interface enwc-nm-dbus-interface))
+  (apply 'dbus-call-method :system
+         enwc-nm-dbus-service
+         path
+         interface
+         method
+         :timeout 25000
+         args))
+
+(defun enwc-nm-dbus-default-call-method (method &rest args)
+  (enwc-nm-dbus-call-method method nil nil args))
+
+(defun enwc-nm-dbus-settings-call-method (method &rest args)
+  (enwc-nm-dbus-call-method method
+                            enwc-nm-dbus-settings-path
+                            enwc-nm-dbus-settings-interface
+                            args))
+
+(defun enwc-nm-dbus-wireless-call-method (method &rest args)
+  (enwc-nm-dbus-call-method method
+                            enwc-nm-wireless-dev
+                            enwc-nm-dbus-wireless-interface
+                            args))
+
+(defun enwc-nm-dbus-wired-call-method (method &rest args)
+  (enwc-nm-dbus-call-method method
+                            enwc-nm-wired-dev
+                            enwc-nm-dbus-wired-interface
+                            args))
+
 (defun enwc-nm-get-settings (conn)
   "Gets the connection settings.
 CONN is an object path to the connection."
   (dbus-call-method :system
-                   enwc-nm-dbus-service
-                   conn
-                   enwc-nm-dbus-connections-interface
-                   "GetSettings"
-                   :timeout 25000))
-  
+                    enwc-nm-dbus-service
+                    conn
+                    enwc-nm-dbus-connections-interface
+                    "GetSettings"
+                    :timeout 25000))
 
 (defun enwc-nm-list-connections ()
   "List the connections."
-  (dbus-call-method :system
-                   enwc-nm-dbus-service
-                   enwc-nm-dbus-settings-path
-                   enwc-nm-dbus-settings-interface
-                   "ListConnections"
-                   :timeout 25000))
+  (enwc-nm-dbus-settings-call-method "ListConnections"))
 
 ;; Default
 (defun enwc-nm-get-device-by-name (name)
-  (dbus-call-method :system
-                   enwc-nm-dbus-service
-                   enwc-nm-dbus-path
-                   enwc-nm-dbus-interface
-                   "GetDeviceByIpIface"
-                   :timeout 25000
-                   :string name))
+  (enwc-nm-dbus-default-call-method "GetDeviceByIpIface" :string name))
 
 ;; Settings, Connections
 (defun enwc-nm-get-uuid-by-ssid (ssid)
   "Gets the uuid of the network with ssid SSID."
   (let ((conns (enwc-nm-list-connections))
-       cur-conn cur-ssid uuid)
+        cur-conn cur-ssid uuid)
     (while (and conns (not uuid))
       (setq cur-conn (pop conns))
       (let ((settings (enwc-nm-get-settings cur-conn)))
-       (if (not (assoc "802-11-wireless" settings))
-           nil
-         (setq cur-ssid
-               (dbus-byte-array-to-string (car (cadr (assoc "ssid"
-                                                            (cadr (assoc 
"802-11-wireless"
-                                                                         
settings)))))))
-         (if (string= cur-ssid ssid)
-             (setq uuid
-                   (car (cadr (assoc "uuid"
-                                     (cadr (assoc "connection"
-                                                  settings))))))))))
+        (when (assoc "802-11-wireless" settings)
+          (setq cur-ssid
+                (dbus-byte-array-to-string (car (cadr (assoc "ssid"
+                                                             (cadr (assoc 
"802-11-wireless"
+                                                                          
settings)))))))
+          (when (string= cur-ssid ssid)
+            (setq uuid
+                  (car (cadr (assoc "uuid"
+                                    (cadr (assoc "connection"
+                                                 settings))))))))))
     uuid))
 
 (defun enwc-nm-get-uuid-by-id (id)
   "Gets a network connection's uuid by the network's id.
 ID is a string that NetworkManager uses to identify this network."
   (let ((conns (enwc-nm-list-connections))
-       cur-conn cur-id uuid)
+        cur-conn cur-id uuid)
     (while (and conns (not uuid))
       (setq cur-conn (pop conns))
       (let ((settings (enwc-nm-get-settings cur-conn))
-           conn-set)
-       (if (not (assoc "connection" settings))
-           nil
-         (setq conn-set (assoc "connection" settings))
-         (setq cur-id (car (cadr (assoc "id" (cadr conn-set)))))
-         (if (string= cur-id id)
-             (setq uuid (car (cadr (assoc "uuid" (cadr conn-set)))))))))))
+            conn-set)
+        (if (not (assoc "connection" settings))
+            nil
+          (setq conn-set (assoc "connection" settings))
+          (setq cur-id (car (cadr (assoc "id" (cadr conn-set)))))
+          (if (string= cur-id id)
+              (setq uuid (car (cadr (assoc "uuid" (cadr conn-set)))))))))))
 
 (defun enwc-nm-get-conn-by-uuid (uuid)
-  (dbus-call-method :system
-                   enwc-nm-dbus-service
-                   enwc-nm-dbus-settings-path
-                   enwc-nm-dbus-settings-interface
-                   "GetConnectionByUuid"
-                   :timeout 25000
-                   uuid))
+  (enwc-nm-dbus-settings-call-method "GetConnectionByUuid"
+                                     uuid))
 
 ;; Settings
+;; Not used.
 (defun enwc-nm-get-conn-by-ssid (ssid)
   "Gets the connection path for the access point with ssid SSID."
   (let ((uuid (enwc-nm-get-uuid-by-ssid ssid)))
     (if uuid
-       (enwc-nm-get-conn-by-uuid uuid)
+        (enwc-nm-get-conn-by-uuid uuid)
       nil)))
 
+;; Not used.
 (defun enwc-nm-get-conn-by-id (id)
   "Gets a connection object with the id ID.
 ID is the identifier used by Network Manager."
   (let ((uuid (enwc-nm-get-uuid-by-id id)))
     (enwc-nm-get-conn-by-uuid uuid)))
 
-;;;;;;;;;
-;; Scan
-;;;;;;;;;
-
-(defun enwc-nm-scan ()
-  "The NetworkManager scan function."
-  (dbus-call-method :system
-                   enwc-nm-dbus-service
-                   enwc-nm-wireless-dev
-                   enwc-nm-dbus-wireless-interface
-                   "RequestScan"
-                   :timeout 25000
-                   '(:array :signature "{sv}")))
-
 ;;;;;;;;;;;;;;;;;
 ;; Get networks
 ;;;;;;;;;;;;;;;;;
@@ -264,207 +266,198 @@ ID is the identifier used by Network Manager."
 (defun enwc-nm-get-wireless-networks ()
   "The NetworkManager get networks function.
 This returns a list of D-Bus paths to the access points."
-  (dbus-call-method :system
-                   enwc-nm-dbus-service
-                   enwc-nm-wireless-dev
-                   enwc-nm-dbus-wireless-interface
-                   "GetAccessPoints"))
+  (enwc-nm-dbus-wireless-call-method "GetAccessPoints"))
 
 (defun enwc-nm-get-wired-profiles ()
   (let ((profs-list (enwc-nm-list-connections)))
-    (mapcar (lambda (x)
-             (let ((props (enwc-nm-get-settings x)))
-               (if (string= (caar props) "connection")
-                   (car (cadr (car (cadr (car props))))))))
-           profs-list)))
+    (mapcar
+     (lambda (x)
+       (let ((props (enwc-nm-get-settings x)))
+         (when (string= (caar props) "connection")
+           (car (cadr (car (cadr (car props))))))))
+     profs-list)))
+
+;;;;;;;;;;;;;
+;; Connect ;;
+;;;;;;;;;;;;;
+
+;; Default
+(defun enwc-nm-connect (nw &optional wired)
+  "The NetworkManager connect function.
+This gets the connection path from NW, and connects to it."
+  (if wired
+      (enwc-nm-wired-connect nw)
+    (enwc-nm-wireless-connect nw)))
+
+(defun enwc-nm-wireless-connect (nw)
+  (enwc-nm-dbus-default-call-method "ActivateConnection"
+                                    :object-path nw
+                                    :object-path enwc-nm-wireless-dev
+                                    :object-path nw))
+
+(defun enwc-nm-wired-connect (nw)
+  (enwc-nm-dbus-default-call-method "ActivateConnection"
+                                    :object-path nw
+                                    :object-path enwc-nm-wired-dev
+                                    :object-path nw))
+
+;;;;;;;;;;;;;;;;
+;; Disconnect ;;
+;;;;;;;;;;;;;;;;
+
+(defun enwc-nm-disconnect (&optional wired)
+  (if wired
+      (enwc-nm-wired-disconnect)
+    (enwc-nm-disconnect-wireless)))
+
+;; Device
+(defun enwc-nm-disconnect-wireless ()
+  (enwc-nm-dbus-call-method "Disconnect"
+                            enwc-nm-wireless-dev
+                            enwc-nm-dbus-device-interface))
+
+(defun enwc-nm-wired-disconnect ()
+  (enwc-nm-dbus-call-method "Disconnect"
+                            enwc-nm-wired-dev
+                            enwc-nm-dbus-device-interface))
+
+;;;;;;;;;;
+;; Scan ;;
+;;;;;;;;;;
+
+(defun enwc-nm-scan (&optional wired)
+  "The NetworkManager scan function."
+  (let ((dev (if wired
+                 enwc-nm-wired-dev
+               enwc-nm-wireless-dev))
+        (interface (if wired
+                       enwc-nm-dbus-wired-interface
+                     enwc-nm-dbus-wireless-interface)))
+    (enwc-nm-dbus-call-method "RequestScan"
+                              dev interface
+                              '(:array :signature "{sv}"))
+    ;; (dbus-call-method :system
+    ;;                   enwc-nm-dbus-service
+    ;;                   dev
+    ;;                   interface
+    ;;                   "RequestScan"
+    ;;                   :timeout 25000
+    ;;                   '(:array :signature "{sv}"))
+    ))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Get network properties
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-;; Accesspoint
-(defun enwc-nm-get-wireless-network-property (id prop)
+(defun enwc-nm-get-wireless-network-property (nw prop)
   "The NetworkManager get wireless network property function.
 This runs like normal, using element ID of `enwc-access-points'
  to determine the access point path, then obtains the property
 PROP from that access point.  It also sets the channel from the
  frequency if necessary."
-  (let ((ap (nth id enwc-access-points))
-       (mod-prop prop)
-       ret)
-    (if (string= mod-prop "essid")
-       (setq mod-prop "Ssid"))
-    (setq ret (dbus-get-property :system
-                                enwc-nm-dbus-service
-                                ap
-                                enwc-nm-dbus-accesspoint-interface
-                                mod-prop))
-    (if (not ret)
-       (progn
-         (if (not enwc-nm-edit-info)
-             (setq ret ""))
-         (progn
-           (setq ret (assoc mod-prop
-                            (cadr (assoc "802-1x"
-                                         enwc-nm-edit-info))))
-           (if (not ret)
-               (setq ret (assoc mod-prop
-                                (cadr (assoc "802-11-wireless-security"
-                                             enwc-nm-edit-info)))))
-           (setq ret (car (cadr ret))))))
-    (if (string= mod-prop "Frequency")
-       (setq ret (number-to-string (1+ (/ (- ret 2412) 5)))))
-    (if (string= mod-prop "Ssid")
-       (setq ret (dbus-byte-array-to-string ret)))
-    (if (string= mod-prop "Mode")
-       (setq ret (cond ((= ret 0) "Unknown")
-                       ((= ret 1) "Ad-Hoc")
-                       ((= ret 2) "Infrastructure"))))
-    ret))
+  (dbus-get-property :system
+                     enwc-nm-dbus-service
+                     nw
+                     enwc-nm-dbus-accesspoint-interface
+                     prop))
 
 (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)
-    (setq ret (dbus-get-all-properties :system
-                                      enwc-nm-dbus-service
-                                      ap
-                                      enwc-nm-dbus-accesspoint-interface))
-    (setq tmp-val (cdr (assoc "Mode" ret)))
-    (setcdr (assoc "Frequency" ret)
-           (number-to-string (1+ (/ (- (cdr (assoc "Frequency" ret))
-                                       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")))
-    (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))
+  (pcase prop
+    ("Ssid" 'essid)
+    ("HwAddres" 'bssid)
+    ("Strength" 'strength)
+    ("Flags" 'encrypt)
+    ("Mode" 'mode)
+    ("Channel" 'channel)))
+
+(defun enwc-nm--freq-to-channel (freq)
+  "Convert a frequency FREQ into a channel."
+  (1+ (/ (- freq 2412) 5)))
+
+(defun enwc-nm-get-wireless-nw-props (nw)
+  "Gets the network properties for the network NW."
+  (let ((props (dbus-get-all-properties :system
+                                        enwc-nm-dbus-service
+                                        nw
+                                        enwc-nm-dbus-accesspoint-interface)))
+
+    `((essid    . ,(dbus-byte-array-to-string (cdr (assoc "Ssid" props))))
+      (bssid    . ,(cdr (assoc "HwAddres" props)))
+      (strength . ,(cdr (assoc "Strength" props)))
+      (encrypt  . ,(or (enwc-nm-get-encryption-type nw) "Unsecured"))
+      (channel  . ,(number-to-string (enwc-nm--freq-to-channel
+                                      (cdr (assoc "Frequency" props))))))))
 
 (defun enwc-nm-get-conn-by-nid (nid)
   "Gets a connection object with the network id NID."
   (let* ((ssid (enwc-nm-get-wireless-network-property nid
-                                                     "Ssid"))
-        (uuid (enwc-nm-get-uuid-by-ssid ssid)))
-    (if uuid
-       (enwc-nm-get-conn-by-uuid uuid)
-      nil)))
+                                                      "Ssid"))
+         (uuid (enwc-nm-get-uuid-by-ssid ssid)))
+    (when uuid
+      (enwc-nm-get-conn-by-uuid uuid))))
 
-(defun enwc-nm-get-encryption-type (id)
+(defun enwc-nm-get-encryption-type (nw)
   "The NetworkManager get encryption type function.
-This gets the WPA flags and RSN flags from access point in ID.
+This gets the WPA flags and RSN flags from access point in NW.
 If both are 0, then it returns WEP, otherwise WPA."
-  (let ((wpa-flags (enwc-nm-get-wireless-network-property id "WpaFlags"))
-       (rsn-flags (enwc-nm-get-wireless-network-property id "RsnFlags")))
+  (let ((wpa-flags (enwc-nm-get-wireless-network-property nw "WpaFlags"))
+        (rsn-flags (enwc-nm-get-wireless-network-property nw "RsnFlags")))
     (if (and (= wpa-flags 0) (= rsn-flags 0))
-       "WEP"
+        "WEP"
       "WPA")))
 
-;; Default
-(defun enwc-nm-connect (id &optional wired)
-  "The NetworkManager connect function.
-This gets the connection path from ID, and connects to it."
-  (if wired
-      (enwc-nm-wired-connect id)
-    (enwc-nm-wireless-connect id)))
+;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Get Current network id
+;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-(defun enwc-nm-wireless-connect (id)
-  (let ((ssid (enwc-nm-get-wireless-network-property id "Ssid")))
-    (dbus-call-method :system
-                     enwc-nm-dbus-service
-                     enwc-nm-dbus-path
-                     enwc-nm-dbus-interface
-                     "ActivateConnection"
-                     :timeout 25000
-                     :object-path (enwc-nm-get-conn-by-ssid ssid)
-                     :object-path enwc-nm-wireless-dev
-                     :object-path (nth id enwc-access-points))))
-
-
-(defun enwc-nm-string-idx (obj list)
-  (let ((tmp-list list)
-       (cur-pos -1)
-       cur-obj)
+(defun enwc-nm-string-idx (obj ls)
+  "Determine the index of string OBJ in LIST."
+  (unless (stringp obj)
+    (signal 'wrong-type-argument `(stringp ,obj)))
+  (unless (listp ls)
+    (signal 'wrong-type-argument `(listp ,ls)))
+  (let ((tmp-list ls)
+        (cur-pos -1)
+        cur-obj)
     (while (and (not cur-obj) tmp-list)
       (setq cur-obj (pop tmp-list))
       (setq cur-pos (1+ cur-pos))
-      (if (not (string= obj cur-obj))
-         (setq cur-obj nil)))
+      (unless (string= obj cur-obj)
+        (setq cur-obj nil)))
     cur-pos))
 
 (defun enwc-nm-wireless-prop-changed (props)
-  (if (assoc "ActiveAccessPoint" props)
-      (setq enwc-nm-active-ap (car (cadr (assoc "ActiveAccessPoint"
-                                               props))))))
+  "Called when network properties are changed.
+PROPS is a list of updated properties."
+  (let ((ap (assoc "ActiveAccessPoint" props)))
+    (when ap
+      (setq enwc-nm-active-ap (car (cadr ap))))))
 
-;; Wireless
 (defun enwc-nm-get-current-nw-id (wired)
   "The NetworkManager get current network id function.
 This simply checks for the active access point."
-  (if (or wired (string= enwc-nm-active-ap "/"))
-      -1
-    (enwc-nm-string-idx enwc-nm-active-ap enwc-access-points)))
+  (cond
+   (wired 'wired)
+   ((string= enwc-nm-active-ap "/") nil)
+   (t enwc-nm-active-ap)))
 
 (defun enwc-nm-prop-changed (state)
+  "Called when NetworkManager's state is changed.
+STATE is the new state."
   (setq enwc-nm-connecting-p (eq state 40)))
 
-;; Default
+;;;;;;;;;;;;;;;;;;;;;
+;; Check Connecting
+;;;;;;;;;;;;;;;;;;;;;
+
 (defun enwc-nm-check-connecting ()
   "The NetworkManager check connecting function."
   enwc-nm-connecting-p)
 
-;; Device
-(defun enwc-nm-disconnect-wireless ()
-  (dbus-call-method :system
-                   enwc-nm-dbus-service
-                   enwc-nm-wireless-dev
-                   enwc-nm-dbus-device-interface
-                   "Disconnect"))
-
 ;; Settings, Connections
 
-
-(defun enwc-nm-wired-connect (id)
-  (let ((nid (nth id enwc-access-points)))
-    (dbus-call-method :system
-                     enwc-nm-dbus-service
-                     enwc-nm-dbus-path
-                     enwc-nm-dbus-interface
-                     :timeout 25000
-                     :object-path (enwc-nm-get-conn-by-id nid)
-                     :object-path enwc-nm-wired-dev
-                     :objec-path "/")))
-
 ;; Device
-(defun enwc-nm-wired-disconnect ()
-  (dbus-call-method :system
-                   enwc-nm-dbus-service
-                   enwc-nm-wired-dev
-                   enwc-nm-dbus-device-interface
-                   "Disconnect"))
 
 (defun enwc-nm-dev-prop-changed (new-state old-state reason)
   (setq enwc-nm-wired-p (eq new-state 100)))
@@ -483,60 +476,41 @@ This simply checks for the active access point."
 ;;  "keyXX" => String that the backend uses for this security entry.
 ;;  "EntryXX" => String that ENWC displays for this security entry.
 
-(defun enwc-nm-get-sec-types (wired)
+(defun enwc-nm-get-sec-types (&optional wired)
   "Get security types."
   (if wired
       nil
-    enwc-nm-sec-types)
-  )
+    enwc-nm-sec-types))
 
 (defun enwc-nm-gen-uuid ()
   (random t)
   (let ((hex-nums
-        (mapcar (lambda (x)
-                  (random 65535))
-                (number-sequence 0 7)))
-       fin-str)
-    (setq fin-str (format "%04x%04x-%04x-%04x-%04x-%04x%04x%04x"
-                         (nth 0 hex-nums)
-                         (nth 1 hex-nums)
-                         (nth 2 hex-nums)
-                         (nth 3 hex-nums)
-                         (nth 4 hex-nums)
-                         (nth 5 hex-nums)
-                         (nth 6 hex-nums)
-                         (nth 7 hex-nums)))))
+         (mapcar (lambda (x)
+                   (random 65535))
+                 (number-sequence 0 7)))
+        fin-str)
+    (setq fin-str (apply 'format "%04x%04x-%04x-%04x-%04x-%04x%04x%04x" 
hex-nums))))
+
+(defmacro enwc-nm--hex-substring (str st ed)
+  "Get a standard integer from hex string STR starting at ST and ending st ED"
+  `(string-to-number (substring ,str ,st ,ed) 16))
 
 (defun enwc-nm-convert-addr (addr)
   (if addr
       (let* ((hex-addr (format "%08x" addr))
-            (ret-addr (format "%i.%i.%i.%i"
-                              (string-to-number (substring hex-addr
-                                                           6 8)
-                                                16)
-                              (string-to-number (substring hex-addr
-                                                           4 6)
-                                                16)
-                              (string-to-number (substring hex-addr
-                                                           2 4)
-                                                16)
-                              (string-to-number (substring hex-addr
-                                                           0 2)
-                                                16))))
-       ret-addr)
+             (subs (mapcar
+                    (lambda (n)
+                      (enwc-nm--hex-substring hex-addr n (+ n 2)))
+                    (number-sequence 6 0 -2))))
+        (apply 'format "%i.%i.%i.%i" subs))
     ""))
 
 (defun enwc-nm-addr-back (addr)
-  (let ((bytes (split-string addr "."))
-        ret-val)
-    (setq ret-val (logior (lsh (string-to-number (nth 3 bytes))
-                              0)
-                         (lsh (string-to-number (nth 2 bytes))
-                              1)
-                         (lsh (string-to-number (nth 1 bytes))
-                              2)
-                         (lsh (string-to-number (nth 0 bytes))
-                              3)))))
+  (let* ((bytes (split-string addr "\\."))
+         (byte-string (mapcar
+                       (lambda (n) (lsh (string-to-number (nth (- 3 n) bytes)) 
n))
+                       (number-sequence 0 3))))
+    (apply 'logior byte-string)))
 
 ;; These next two come from libnm-util/nm-utils.c in NM's source.
 
@@ -545,193 +519,166 @@ This simply checks for the active access point."
 NETMASK is an ip address in network byte order."
   (if netmask
       (let* ((mask netmask)
-            (cur-pos 3)
-            (cur-mark (logand (lsh mask (* -8 cur-pos)) 255))
-            (pf 0))
-       (while (and (eq cur-mark 255) (>= cur-pos 0))
-         (setq pf (+ pf 8))
-         (setq cur-pos (1- cur-pos))
-         (setq cur-mark (logand (lsh mask (* -8 cur-pos)) 255))
-         )
-
-       (if (>= cur-pos 0)
-           (let ((v (logand (lsh mask (* -8 cur-pos)) 255)))
-             (while (not (eq v 0))
-               (setq pf (1+ pf))
-               (setq v (lsh v 1)))))
-       pf)
+             (cur-pos 3)
+             (cur-mark (logand (lsh mask (* -8 cur-pos)) 255))
+             (pf 0))
+        (while (and (eq cur-mark 255) (>= cur-pos 0))
+          (setq pf (+ pf 8))
+          (setq cur-pos (1- cur-pos))
+          (setq cur-mark (logand (lsh mask (* -8 cur-pos)) 255)))
+
+        (if (>= cur-pos 0)
+            (let ((v (logand (lsh mask (* -8 cur-pos)) 255)))
+              (while (not (eq v 0))
+                (setq pf (1+ pf))
+                (setq v (lsh v 1)))))
+        pf)
     0))
 
 (defun enwc-nm-prefix-to-netmask (prefix)
   "Converts a prefix to a netmask.
 PREFIX is an integer <= 32."
+  (if (not (integerp prefix))
+      (signal 'wrong-type-argument `(integerp ,prefix)))
   (let ((pf prefix)
-       (netmask 0)
-       (msk #x80000000))
-  (while (> pf 0)
-    (setq netmask (logior netmask msk))
-    (setq msk (lsh msk -1))
-    (setq pf (1- pf)))
-  netmask))
+        (netmask 0)
+        (msk #x80000000))
+    (while (> pf 0)
+      (setq netmask (logior netmask msk))
+      (setq msk (lsh msk -1))
+      (setq pf (1- pf)))
+    netmask))
 
 (defun enwc-nm-get-profile-info (id &optional wired)
   (let ((conn (enwc-nm-get-conn-by-nid id)))
-    (if conn
-       (setq enwc-nm-edit-info
-             (enwc-nm-get-settings conn))))
+    (when conn
+      (setq enwc-nm-edit-info
+            (enwc-nm-get-settings conn))))
 
   (let (ip-addr netmask gateway dns-list nw-info)
-    (if enwc-nm-edit-info
-       (progn
-         (setq ip-addr (nth 0 (caar (cadr (assoc "addresses"
-                                                 (cadr (assoc "ipv4"
-                                                              
enwc-nm-edit-info))))))
-               netmask (nth 3 (caar (cadr (assoc "addresses"
-                                                 (cadr (assoc "ipv4"
-                                                              
enwc-nm-edit-info))))))
-               gateway (nth 2 (caar (cadr (assoc "address"
-                                                 (cadr (assoc "ipv4"
-                                                              
enwc-nm-edit-info))))))
-               dns-list (car (cadr (assoc "dns" (cadr (assoc "ipv4"
-                                                             
enwc-nm-edit-info))))))
-         (setq ip-addr (enwc-nm-convert-addr ip-addr)
-               netmask (enwc-nm-convert-addr netmask)
-               gateway (enwc-nm-convert-addr gateway)
-               dns-list (mapcar 'enwc-nm-convert-addr
-                                dns-list))
-         (setq nw-info (list (cons (cons "addr"
-                                         ip-addr)
-                                    nil)
-                             (cons (cons "netmask"
-                                         netmask)
-                                    nil)
-                             (cons (cons "gateway"
-                                         gateway)
-                                    nil)
-                             (cons (cons "dns1"
-                                         (nth 0
-                                              dns-list))
-                                   nil)
-                             (cons (cons "dns2"
-                                         (nth 1
-                                              dns-list))
-                                   nil)
-                             (cons (cons "enctype"
-                                         "None")
-                                    nil))))
+    (when enwc-nm-edit-info
+      (setq ip-addr (nth 0 (caar (cadr (assoc "addresses" (cadr (assoc "ipv4" 
enwc-nm-edit-info))))))
+            netmask (nth 3 (caar (cadr (assoc "addresses" (cadr (assoc "ipv4" 
enwc-nm-edit-info))))))
+            gateway (nth 2 (caar (cadr (assoc "address"   (cadr (assoc "ipv4" 
enwc-nm-edit-info))))))
+            dns-list (car (cadr (assoc "dns" (cadr (assoc "ipv4" 
enwc-nm-edit-info))))))
+      (setq ip-addr (enwc-nm-convert-addr ip-addr)
+            netmask (enwc-nm-convert-addr netmask)
+            gateway (enwc-nm-convert-addr gateway)
+            dns-list (mapcar 'enwc-nm-convert-addr
+                             dns-list))
+      `(("addr" . ,ip-addr)
+        ("netmask" . ,netmask)
+        ("gateway" . ,gateway)
+        ("dns1"    . ,(nth 0 dns-list))
+        ("dns2"    . ,(nth 1 dns-list)))
       nil)))
 
 (defun enwc-nm-get-ip-addr (wired id)
   "Gets the IP Address of a connection profile."
   (let ((props (enwc-nm-get-settings (enwc-nm-get-conn-by-nid id)))
-       ipaddr ret-addr)
+        ipaddr ret-addr)
     (if (not props)
-       (setq ret-addr "")
+        (setq ret-addr "")
       (setq ipaddr (nth 0 (caar (cadr (assoc "addresses"
-                                            (cadr (assoc "ipv4"
-                                                         props)))))))
+                                             (cadr (assoc "ipv4"
+                                                          props)))))))
       (setq ret-addr (enwc-nm-convert-addr ipaddr)))))
 
 (defun enwc-nm-get-netmask (wired id)
   "Gets the Netmask of a connection profile."
   (let ((props (enwc-nm-get-settings (enwc-nm-get-conn-by-nid id)))
-       ipaddr hex-addr ret-addr)
+        ipaddr hex-addr ret-addr)
     (if (not props)
-       (setq ret-addr "")
+        (setq ret-addr "")
       (setq ipaddr (nth 3 (caar (cadr (assoc "addresses"
-                                            (cadr (assoc "ipv4"
-                                                         props)))))))
+                                             (cadr (assoc "ipv4"
+                                                          props)))))))
       (setq hex-addr (enwc-nm-prefix-to-netmask ipaddr))
       (setq ret-addr (format "%i.%i.%i.%i"
-                            (logand hex-addr 255)
-                            (logand (lsh hex-addr -8) 255)
-                            (logand (lsh hex-addr -16) 255)
-                            (logand (lsh hex-addr -24) 255))))))
-    
+                             (logand hex-addr 255)
+                             (logand (lsh hex-addr -8) 255)
+                             (logand (lsh hex-addr -16) 255)
+                             (logand (lsh hex-addr -24) 255))))))
 
 (defun enwc-nm-get-gateway (wired id)
   "Gets the Gateway of a connection profile."
   (let ((props (enwc-nm-get-settings (enwc-nm-get-conn-by-nid id)))
-       ipaddr ret-addr)
+        ipaddr ret-addr)
     (if (not props)
-       (setq ret-addr "")
+        (setq ret-addr "")
       (setq ipaddr (nth 2 (caar (cadr (assoc "addresses"
-                                            (cadr (assoc "ipv4"
-                                                         props)))))))
+                                             (cadr (assoc "ipv4"
+                                                          props)))))))
       (setq ret-addr (enwc-nm-convert-addr ipaddr)))))
 
 (defun enwc-nm-get-dns (wired id)
   "Gets the DNS settings of a connection profile."
   (let ((props (enwc-nm-get-settings (enwc-nm-get-conn-by-nid id)))
-       dns-list)
+        dns-list)
     (setq dns-list (car (cadr (assoc "dns" (cadr (assoc "ipv4"
-                                                       props))))))
+                                                        props))))))
     (mapcar 'enwc-nm-convert-addr
-           dns-list)))
+            dns-list)))
 
 (defun enwc-nm-process-enctype (settings nw-settings)
   "Process the encryption type.
 Sets up the encryption type passed in through SETTINGS."
   (let* ((ret-list nw-settings)
-        (req-list (nthcdr 6 settings))
-        (enctype (cdr (assoc "enctype" settings)))
-        key-mgmt
-        new-list name-list
-        ;;(name-list (cdr (assoc "reqs" (cdr (assoc enctype 
enwc-nm-sec-types)))))
-        key-name)
+         (req-list (nthcdr 6 settings))
+         (enctype (cdr (assoc "enctype" settings)))
+         key-mgmt
+         new-list name-list
+         key-name)
 
     ;; There is a possibility that any of these don't exist in
     ;; nw-settings.
 
     (setq new-list `("802-11-wireless-security" (("pairwise" (("wep40" 
"wep104")))
-                                                ("group" (("wep40" "wep104")))
-                                                ("auth-alg" (nil))
-                                                ("key-mgmt" (nil)))))
+                                                 ("group" (("wep40" "wep104")))
+                                                 ("auth-alg" (nil))
+                                                 ("key-mgmt" (nil)))))
 
     (if (not (assoc "802-11-wireless-security" ret-list))
-       (setq ret-list (append ret-list (list new-list))))
+        (setq ret-list (append ret-list (list new-list))))
 
     (if (or (string= enctype "eap-leap")
-           (string= enctype "eap-peap")
-           (string= enctype "eap-tls")
-           (string= enctype "eap-ttls"))
-       (progn
-         (setq key-name "802-1x")
-         (setq key-mgmt "ieee8021x")
-         (setq req-list (push (cons "eap" (substring enctype 4)) req-list))
-         (print req-list)
-         ;;(setcdr (assoc "eap" (cadr (assoc "802-1x" ret-list))) (list (list 
(list (substring enctype 4)))))
-         )
+            (string= enctype "eap-peap")
+            (string= enctype "eap-tls")
+            (string= enctype "eap-ttls"))
+        (progn
+          (setq key-name "802-1x")
+          (setq key-mgmt "ieee8021x")
+          (setq req-list (push (cons "eap" (substring enctype 4)) req-list)))
       (setq key-name "802-11-wireless-security")
       (setq key-mgmt
-           (cond ((string= enctype "wep") "none")
-                 ((string= enctype "wpa-psk") "wpa-psk")
-                 ((string= enctype "leap") "iee8021x"))))
+            (cond ((string= enctype "wep") "none")
+                  ((string= enctype "wpa-psk") "wpa-psk")
+                  ((string= enctype "leap") "iee8021x"))))
     (setcdr (assoc "key-mgmt" (cadr (assoc "802-11-wireless-security" 
ret-list)))
-           (list (list key-mgmt)))
+            (list (list key-mgmt)))
 
-    (if (string= enctype "leap")
-       (setcdr (assoc "auth-alg" (cadr (assoc "802-11-wireless-security" 
ret-list)))
-               (list (list "leap"))))
+    (when (string= enctype "leap")
+      (setcdr (assoc "auth-alg" (cadr (assoc "802-11-wireless-security" 
ret-list)))
+              (list (list "leap"))))
 
     (setq name-list (cons key-name
-                         (list (mapcar (lambda (x)
-                                         (cons (car x)
-                                               (cons (cons (cdr x) nil)
-                                                     nil)))
-                                       req-list))))
+                          (list (mapcar (lambda (x)
+                                          (cons (car x)
+                                                (cons (cons (cdr x) nil)
+                                                      nil)))
+                                        req-list))))
 
     (if (not (assoc key-name ret-list))
-       (setq ret-list (append ret-list (list name-list)))
+        (setq ret-list (append ret-list (list name-list)))
       (setcdr (assoc key-name ret-list) (list name-list)))
 
 
-    (if (or (string= enctype "eap-leap")
-           (string= enctype "eap-peap")
-           (string= enctype "eap-tls")
-           (string= enctype "eap-ttls"))
-       (setcdr (assoc "eap" (cadr (assoc "802-1x" ret-list)))
-               (cons (cons (cons (substring enctype 4) nil) nil) nil)))
+    (when (or (string= enctype "eap-leap")
+              (string= enctype "eap-peap")
+              (string= enctype "eap-tls")
+              (string= enctype "eap-ttls"))
+      (setcdr (assoc "eap" (cadr (assoc "802-1x" ret-list)))
+              (cons (cons (cons (substring enctype 4) nil) nil) nil)))
 
     ret-list))
 
@@ -741,128 +688,118 @@ SETTINGS is the list of settings list to setup.
 This will place all of the necessary markers in the list,
 such as :array, :dict-entry, etc."
   (cons :array
-       (let (first-one)
-         (mapc (lambda (x)
-                 (setq first-one (cons :dict-entry first-one))
-                 (setq first-one
-                       (cons (cons :string
-                                   (cons (car x)
-                                         (cons (cons :array
-                                                     (let (this-one)
-                                                       (mapc (lambda (y)
-                                                               (setq this-one
-                                                                     (cons 
:dict-entry this-one))
-                                                               (setq this-one
-                                                                     (cons 
(list :string (car y)
-                                                                               
  :variant
-                                                                               
  (if (string= (car y) "ssid")
-                                                                               
      (cons (dbus-string-to-byte-array
-                                                                               
             (dbus-byte-array-to-string (car (cadr y))))
-                                                                               
            nil)
-                                                                               
    (cadr y)))
-                                                                           
this-one)))
-                                                             (cadr x))
-                                                       (nreverse this-one))) 
nil)))
-                             first-one)))
-               settings)
-         (nreverse first-one))))
+        (let (first-one)
+          (dolist (x settings)
+            (setq first-one (cons :dict-entry first-one))
+            (setq first-one
+                  (cons
+                   (cons :string
+                         (cons (car x)
+                               (cons
+                                (cons :array
+                                      (let (this-one)
+                                        (dolist (y (cadr x))
+                                          (setq this-one
+                                                (cons :dict-entry this-one))
+                                          (setq this-one
+                                                (cons
+                                                 (list
+                                                  :string (car y)
+                                                  :variant
+                                                  (if (string= (car y) "ssid")
+                                                      (cons 
(dbus-string-to-byte-array
+                                                             
(dbus-byte-array-to-string (car (cadr y))))
+                                                            nil)
+                                                    (cadr y)))
+                                                 this-one)))
+                                        (nreverse this-one)))
+                                nil)))
+                   first-one)))
+          (nreverse first-one))))
 
 (defun enwc-nm-create-settings (wired ssid)
   (let ((uuid (enwc-nm-gen-uuid))
-       (id (concat ssid " settings"))
-       type
-       ret-list
-       conn-list
-       ipv4-list ipv6-list
-       mod-list
-       new-ssid
-       80211-list)
+        (id (concat ssid " settings"))
+        type
+        ret-list
+        conn-list
+        ipv4-list ipv6-list
+        mod-list
+        new-ssid
+        80211-list)
 
     (if (not wired)
-       (setq new-ssid (dbus-string-to-byte-array ssid))
-       (progn
-         (setq 80211-list `("802-11-wireless" (("security" (nil))
-                                               ("ssid" (,new-ssid))
-                                               ("mode" ("infrastructure")))))
-
-         (setq ret-list (append ret-list (list 80211-list))
-               type "802-11-wireless"))
+        (setq new-ssid (dbus-string-to-byte-array ssid))
+      (progn
+        (setq 80211-list `("802-11-wireless" (("security" (nil))
+                                              ("ssid" (,new-ssid))
+                                              ("mode" ("infrastructure")))))
+
+        (setq ret-list (append ret-list (list 80211-list))
+              type "802-11-wireless"))
       (setq type "802-3-ethernet"))
     (setq conn-list `("connection" (("id" (,id))
-                                   ("uuid" (,uuid))
-                                   ("autoconnect" (nil))
-                                   ("type" (,type)))))
+                                    ("uuid" (,uuid))
+                                    ("autoconnect" (nil))
+                                    ("type" (,type)))))
 
     (setq ipv4-list '("ipv4" (("addresses" (nil))
-                             ("dns" (nil))
-                             ("method" ("auto"))
-                             ("routes" (nil)))))
+                              ("dns" (nil))
+                              ("method" ("auto"))
+                              ("routes" (nil)))))
 
     (setq ipv6-list '("ipv4" (("addresses" (nil))
-                             ("dns" (nil))
-                             ("method" ("auto"))
-                             ("routes" (nil)))))
+                              ("dns" (nil))
+                              ("method" ("auto"))
+                              ("routes" (nil)))))
 
     (setq ret-list (append ret-list (list conn-list)))
     (setq ret-list (append ret-list (list ipv4-list)))
-    (setq ret-list (append ret-list (list ipv6-list)))
-    ))
+    (setq ret-list (append ret-list (list ipv6-list)))))
 
 (defun enwc-nm-setup-settings (wired id settings)
   "Sets up NetworkManager settings.
 Gets the current network properties of network ID
 and uses the information in the association list SETTINGS
 to put it in the form that NetworkManager will recognize."
-  (print settings)
   (let (ssid uuid conn props)
 
     (if (not enwc-nm-edit-info)
-       (progn
-         (setq ssid
-               (enwc-nm-get-wireless-network-property (nth id
-                                                           enwc-access-points)
-                                                      "Ssid"))
-         (setq props (enwc-nm-create-settings wired ssid)))
+        (progn
+          (setq ssid
+                (enwc-nm-get-wireless-network-property (nth id
+                                                            enwc-access-points)
+                                                       "Ssid"))
+          (setq props (enwc-nm-create-settings wired ssid)))
       (setq props enwc-nm-edit-info))
 
-    (print enwc-nm-edit-info)
-         ;; (setq uuid (enwc-nm-get-uuid-by-ssid ssid))
-         ;; (if uuid
-         ;;     (setq conn (enwc-nm-get-conn-by-uuid uuid)))))
-
-    ;; (setq props
-    ;;           (if conn
-    ;;               (enwc-nm-get-settings (enwc-nm-get-conn-by-nid id))
-    ;;             (enwc-nm-create-settings wired ssid)))
-
     (setcdr (assoc "type" (cadr (assoc "connection" props)))
-           (list (list (cond (wired "802-3-ethernet")
-                             ((not wired) "802-11-wireless")))))
+            (list (list (cond (wired "802-3-ethernet")
+                              ((not wired) "802-11-wireless")))))
 
     (if (= (length (cdr (assoc "addr" settings))) 0)
-       (setcdr (assoc "addresses" (cadr (assoc "ipv4" props)))
-               (cons (cons nil nil) nil))
+        (setcdr (assoc "addresses" (cadr (assoc "ipv4" props)))
+                (cons (cons nil nil) nil))
 
       (setcdr (assoc "addresses" (cadr (assoc "ipv4" props)))
-             (list (list (list (list (enwc-nm-addr-back
-                                      (cdr (assoc "addr" settings)))
-                                     (enwc-nm-netmask-to-prefix 
(enwc-nm-addr-back
-                                                                 (cdr (assoc 
"netmask"
-                                                                             
settings))))
-                                     (enwc-nm-addr-back
-                                      (cdr (assoc "gateway" settings)))))))))
+              (list (list (list (list (enwc-nm-addr-back
+                                       (cdr (assoc "addr" settings)))
+                                      (enwc-nm-netmask-to-prefix 
(enwc-nm-addr-back
+                                                                  (cdr (assoc 
"netmask"
+                                                                              
settings))))
+                                      (enwc-nm-addr-back
+                                       (cdr (assoc "gateway" settings)))))))))
 
     (if (= (length (cdr (assoc "dns1" settings))) 0)
-       (setcdr (assoc "dns" (cadr (assoc "ipv4" props)))
-               (cons (cons nil nil) nil))
+        (setcdr (assoc "dns" (cadr (assoc "ipv4" props)))
+                (cons (cons nil nil) nil))
       (setcdr (assoc "dns" (cadr (assoc "ipv4" props)))
-             (list (list (list (enwc-nm-addr-back
-                                (cdr (assoc "dns1" settings)))
-                               (enwc-nm-addr-back
-                                (cdr (assoc "dns2" settings))))))))
+              (list (list (list (enwc-nm-addr-back
+                                 (cdr (assoc "dns1" settings)))
+                                (enwc-nm-addr-back
+                                 (cdr (assoc "dns2" settings))))))))
 
     (setq props (enwc-nm-process-enctype settings props))
-    (print props)
 
     (enwc-nm-finalize-settings props)))
 
@@ -872,83 +809,79 @@ ID is the network id of the profile to save,
 WIRED denotes whether or not this is a wired profile,
 and SETTINGS is the list of settings."
   (let ((mod-sets (enwc-nm-setup-settings wired id settings)))
-    (print mod-sets)
-    (print id)
     (dbus-call-method :system
-                     enwc-nm-dbus-service
-                     ;;(nth id enwc-access-points)
-                     (enwc-nm-get-conn-by-nid id)
-                     enwc-nm-dbus-connections-interface
-                     (if (not enwc-nm-edit-info)
-                         "AddConnection"
-                       "Update")
-                     :timeout 25000
-                     :array mod-sets)
-    ))
+                      enwc-nm-dbus-service
+                      (enwc-nm-get-conn-by-nid id)
+                      enwc-nm-dbus-connections-interface
+                      (if (not enwc-nm-edit-info)
+                          "AddConnection"
+                        "Update")
+                      :timeout 25000
+                      :array mod-sets)))
 
 (defun enwc-nm-setup ()
   (setq enwc-nm-wired-dev (enwc-nm-get-device-by-name enwc-wired-device)
-       enwc-nm-wireless-dev (enwc-nm-get-device-by-name enwc-wireless-device))
+        enwc-nm-wireless-dev (enwc-nm-get-device-by-name enwc-wireless-device))
 
   (dbus-register-signal :system
-                       enwc-nm-dbus-service
-                       enwc-nm-wireless-dev
-                       enwc-nm-dbus-wireless-interface
-                       "AccessPointAdded"
-                       'enwc-process-scan)
+                        enwc-nm-dbus-service
+                        enwc-nm-wireless-dev
+                        enwc-nm-dbus-wireless-interface
+                        "AccessPointAdded"
+                        'enwc-process-scan)
 
   (dbus-register-signal :system
-                       enwc-nm-dbus-service
-                       enwc-nm-wireless-dev
-                       enwc-nm-dbus-wireless-interface
-                       "AccessPointRemoved"
-                       'enwc-process-scan)
+                        enwc-nm-dbus-service
+                        enwc-nm-wireless-dev
+                        enwc-nm-dbus-wireless-interface
+                        "AccessPointRemoved"
+                        'enwc-process-scan)
 
   (setq enwc-nm-active-ap
-       (let ((cur-net (dbus-get-property :system
-                                         enwc-nm-dbus-service
-                                         enwc-nm-wireless-dev
-                                         enwc-nm-dbus-wireless-interface
-                                         "ActiveAccessPoint")))
-         (if (string= cur-net "/")
-             "/"
-           cur-net)))
+        (let ((cur-net (dbus-get-property :system
+                                          enwc-nm-dbus-service
+                                          enwc-nm-wireless-dev
+                                          enwc-nm-dbus-wireless-interface
+                                          "ActiveAccessPoint")))
+          (if (string= cur-net "/")
+              "/"
+            cur-net)))
 
   (dbus-register-signal :system
-                       enwc-nm-dbus-service
-                       enwc-nm-wireless-dev
-                       enwc-nm-dbus-wireless-interface
-                       "PropertiesChanged"
-                       'enwc-nm-wireless-prop-changed)
+                        enwc-nm-dbus-service
+                        enwc-nm-wireless-dev
+                        enwc-nm-dbus-wireless-interface
+                        "PropertiesChanged"
+                        'enwc-nm-wireless-prop-changed)
 
   (setq enwc-nm-connecting-p
-       (let ((state (dbus-get-property :system
-                                       enwc-nm-dbus-service
-                                       enwc-nm-dbus-path
-                                       enwc-nm-dbus-interface
-                                       "State")))
-         (eq state 40)))
+        (let ((state (dbus-get-property :system
+                                        enwc-nm-dbus-service
+                                        enwc-nm-dbus-path
+                                        enwc-nm-dbus-interface
+                                        "State")))
+          (eq state 40)))
 
   (dbus-register-signal :system
-                       enwc-nm-dbus-service
-                       enwc-nm-wired-dev
-                       enwc-nm-dbus-device-interface
-                       "StateChanged"
-                       'enwc-nm-dev-prop-changed)
+                        enwc-nm-dbus-service
+                        enwc-nm-wired-dev
+                        enwc-nm-dbus-device-interface
+                        "StateChanged"
+                        'enwc-nm-dev-prop-changed)
 
   (setq enwc-nm-wired-p
-       (let ((state (dbus-get-property :system
-                                       enwc-nm-dbus-service
-                                       enwc-nm-wired-dev
-                                       enwc-nm-dbus-device-interface
-                                       "State")))
-         (eq state 100)))
+        (let ((state (dbus-get-property :system
+                                        enwc-nm-dbus-service
+                                        enwc-nm-wired-dev
+                                        enwc-nm-dbus-device-interface
+                                        "State")))
+          (eq state 100)))
   (dbus-register-signal :system
-                       enwc-nm-dbus-service
-                       enwc-nm-dbus-path
-                       enwc-nm-dbus-interface
-                       "StateChanged"
-                       'enwc-nm-prop-changed))
+                        enwc-nm-dbus-service
+                        enwc-nm-dbus-path
+                        enwc-nm-dbus-interface
+                        "StateChanged"
+                        'enwc-nm-prop-changed))
 
 
 (provide 'enwc-nm)
diff --git a/lisp/enwc-setup.el b/lisp/enwc-setup.el
index 4e060ff..086cc08 100644
--- a/lisp/enwc-setup.el
+++ b/lisp/enwc-setup.el
@@ -27,94 +27,45 @@
 (require 'enwc-wicd)
 (require 'enwc-nm)
 
+(defun enwc--intern-sym (sym-name suffix)
+  (intern (concat "enwc-" sym-name suffix)))
+
 (defun enwc-setup-backend (cur-back)
   "Sets up ENWC to use the correct function for the backend CUR-BACK."
-  (let ((sym-name (symbol-name cur-back)))
-    (setq enwc-scan-func (intern (concat "enwc-"
-                                         sym-name
-                                         "-scan"))
-          enwc-get-nw-func (intern (concat "enwc-"
-                                           sym-name
-                                           "-get-networks"))
-          ;; enwc-get-wireless-nw-prop-func (intern (concat "enwc-"
-          ;;                                                sym-name
-          ;;                                                
"-get-wireless-network-property"))
-          enwc-get-wireless-nw-props-func (intern (concat "enwc-"
-                                                          sym-name
-                                                          
"-get-wireless-nw-props"))
-          enwc-connect-func (intern (concat "enwc-"
-                                            sym-name
-                                            "-connect"))
-          enwc-disconnect-func (intern (concat "enwc-"
-                                               sym-name
-                                               "-disconnect"))
-          ;; enwc-get-encryption-type-func (intern (concat "enwc-"
-          ;;                                            sym-name
-          ;;                                            
"-get-encryption-type"))
-          ;; enwc-wireless-connect-func (intern (concat "enwc-"
-          ;;                                            sym-name
-          ;;                                            "-connect"))
-          enwc-get-current-nw-id-func (intern (concat "enwc-"
-                                                      sym-name
-                                                      "-get-current-nw-id"))
-          enwc-check-connecting-func (intern (concat "enwc-"
-                                                     sym-name
-                                                     "-check-connecting"))
-          ;; enwc-get-wired-profiles-func (intern (concat "enwc-"
-          ;;                                              sym-name
-          ;;                                              
"-get-wired-profiles"))
-          enwc-is-wired-func (intern (concat "enwc-"
-                                             sym-name
-                                             "-is-wired"))
-          ;; enwc-wired-connect-func (intern (concat "enwc-"
-          ;;                                         sym-name
-          ;;                                         "-wired-connect"))
-          ;; enwc-wired-disconnect-func (intern (concat "enwc-"
-          ;;                                            sym-name
-          ;;                                            "-wired-disconnect"))
-          enwc-get-sec-types-func (intern (concat "enwc-"
-                                                  sym-name
-                                                  "-get-sec-types"))
-          ;; enwc-get-ip-addr-func (intern (concat "enwc-"
-          ;;                                       sym-name
-          ;;                                       "-get-ip-addr"))
-          ;; enwc-get-netmask-func (intern (concat "enwc-"
-          ;;                                       sym-name
-          ;;                                       "-get-netmask"))
-          ;; enwc-get-gateway-func (intern (concat "enwc-"
-          ;;                                       sym-name
-          ;;                                       "-get-gateway"))
-          ;; enwc-get-dns-func (intern (concat "enwc-"
-          ;;                                   sym-name
-          ;;                                   "-get-dns"))
-          enwc-get-profile-info-func (intern (concat "enwc-"
-                                                     sym-name
-                                                     "-get-profile-info"))
-          enwc-save-nw-settings-func (intern (concat "enwc-"
-                                                     sym-name
-                                                     "-save-nw-settings")))
-    (funcall (intern (concat "enwc-" sym-name "-setup")))))
+  (let* ((sym-name (symbol-name cur-back))
+         (eis (apply-partially 'enwc--intern-sym sym-name)))
+    (setq enwc-scan-func (funcall eis "-scan")
+          enwc-get-networks-func (funcall eis "-get-networks")
+          enwc-get-wireless-nw-props-func (funcall eis 
"-get-wireless-nw-props")
+          enwc-connect-func (funcall eis "-connect")
+          enwc-disconnect-func (funcall eis "-disconnect")
+          enwc-get-current-nw-id-func (funcall eis "-get-current-nw-id")
+          enwc-check-connecting-func (funcall eis "-check-connecting")
+          enwc-is-wired-func (funcall eis "-is-wired")
+          enwc-get-profile-info-func (funcall eis "-get-profile-info")
+          enwc-save-nw-settings-func (funcall eis "-save-nw-settings"))
+    (funcall (funcall eis "-setup"))))
 
 (defun enwc-setup ()
   "Sets up ENWC.
 This setups ENWC and confirms that one of the backends can be found
 on D-Bus."
-  (if enwc-display-mode-line
-      (enwc-enable-display-mode-line))
+  (when enwc-display-mode-line
+    (enwc-enable-display-mode-line))
 
-  (if (and enwc-auto-scan (> enwc-auto-scan-interval 0))
-      (setq enwc-scan-timer
-            (run-at-time t enwc-auto-scan-interval 'enwc-scan t)))
+  (when (and enwc-auto-scan (> enwc-auto-scan-interval 0))
+    (setq enwc-scan-timer
+          (run-at-time t enwc-auto-scan-interval 'enwc-scan t)))
 
   (let ((cur-back nil)
         (back-list enwc-backends))
     (while (and back-list (not cur-back))
       (setq cur-back (pop back-list))
-      (if (not (dbus-ping :system
-                          (symbol-value (intern (concat "enwc-"
-                                                        (symbol-name cur-back)
-                                                        "-dbus-service")))))
-          (setq cur-back nil)))
+      (unless (dbus-ping :system
+                         (symbol-value (intern (concat "enwc-"
+                                                       (symbol-name cur-back)
+                                                       "-dbus-service"))))
+        (setq cur-back nil)))
     (if cur-back
         (enwc-setup-backend cur-back)
       (error "No usable backend found."))))
diff --git a/lisp/enwc-wicd.el b/lisp/enwc-wicd.el
index 718d29a..5dfa555 100644
--- a/lisp/enwc-wicd.el
+++ b/lisp/enwc-wicd.el
@@ -59,7 +59,8 @@
   :type 'string)
 
 (defvar enwc-wicd-details-list
-  '("essid" "bssid" "quality" "encryption" "mode" "channel")
+  ;;'("essid" "bssid" "quality" "encryption" "mode" "channel")
+  '("essid" "bssid" "quality" "encryption" "channel")
   "The list of the desired details to be obtained from each network.")
 
 (defvar enwc-wicd-current-ap "")
@@ -70,35 +71,35 @@
   "Calls D-Bus method METHOD with arguments ARGS within
 the wicd wireless interface."
   (apply 'dbus-call-method :system
-        enwc-wicd-dbus-service
-        enwc-wicd-dbus-wireless-path
-        enwc-wicd-dbus-wireless-interface
-        method
-        :timeout 25000
-        args))
+         enwc-wicd-dbus-service
+         enwc-wicd-dbus-wireless-path
+         enwc-wicd-dbus-wireless-interface
+         method
+         :timeout 25000
+         args))
 
 (defun enwc-wicd-dbus-wired-call-method (method &rest args)
   "Calls D-Bus method METHOD with arguments ARGS within
 the wicd wired interface."
   (apply 'dbus-call-method :system
-        enwc-wicd-dbus-service
-        enwc-wicd-dbus-wired-path
-        enwc-wicd-dbus-wired-interface
-        method
-        :timeout 25000
-        args))
+         enwc-wicd-dbus-service
+         enwc-wicd-dbus-wired-path
+         enwc-wicd-dbus-wired-interface
+         method
+         :timeout 25000
+         args))
 
-;;;;;;;;;
-;; Scan
-;;;;;;;;;
+;;;;;;;;;;
+;; Scan ;;
+;;;;;;;;;;
 
 (defun enwc-wicd-scan ()
   "Wicd scan function."
   (enwc-wicd-dbus-wireless-call-method "Scan"))
 
-;;;;;;;;;;;;;;;;;
-;; Get networks
-;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;
+;; Get networks ;;
+;;;;;;;;;;;;;;;;;;
 
 (defun enwc-wicd-get-networks (&optional wired)
   (if wired
@@ -106,16 +107,17 @@ the wicd wired interface."
     (enwc-wicd-get-wireless-networks)))
 
 (defun enwc-wicd-get-wireless-networks ()
-  "Wicd get networks function.  Just returns a number sequence."
+  "Wicd get networks function.
+Just returns a number sequence."
   (number-sequence 0 (1- (enwc-wicd-dbus-wireless-call-method 
"GetNumberOfNetworks"))))
 
 (defun enwc-wicd-get-wired-profiles ()
   "Gets the list of wired network profiles."
   (enwc-wicd-dbus-wired-call-method "GetWiredProfileList"))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Get network properties
-;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Get network properties ;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defvar enwc-wicd-prop-values nil)
 (defvar enwc-wicd-prop-num 0)
@@ -125,47 +127,42 @@ the wicd wired interface."
   "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-values (cons (cons prop (car args)) 
enwc-wicd-prop-values))
+  (push `(,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."
+  "Convert 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")))
+   ((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
 from wireless network with id ID."
   (dbus-call-method-asynchronously :system
-                                  enwc-wicd-dbus-service
-                                  enwc-wicd-dbus-wireless-path
-                                  enwc-wicd-dbus-wireless-interface
-                                  "GetWirelessProperty"
-                                  `(lambda (x) (enwc-wicd-nw-prop-handler 
,prop x))
+                                   enwc-wicd-dbus-service
+                                   enwc-wicd-dbus-wireless-path
+                                   enwc-wicd-dbus-wireless-interface
+                                   "GetWirelessProperty"
+                                   `(lambda (x) (enwc-wicd-nw-prop-handler 
,prop x))
                                    :timeout 1000
-                                  :int32 id
-                                  :string prop))
+                                   :int32 id
+                                   :string prop))
 
 (defun enwc-wicd-build-prop-list (prop-list det-list)
-  (let (ret
-       (act-det-list (reverse det-list)))
-    (while act-det-list
-      (let* ((cur-det (pop act-det-list))
-             (cur-prop (assoc cur-det prop-list))
-             (act-det (enwc-wicd-prop-to-prop cur-det)))
-        (setq ret
-              (cons (cons act-det
-                          (if cur-prop
-                              (cdr cur-prop)
-                            nil))
-                    ret))))
-    ret))
+  (mapcar
+   (lambda (det)
+     (let* ((cur-prop (assoc det prop-list))
+            (act-det (enwc-wicd-prop-to-prop det))
+            (act-prop (when cur-prop (cdr cur-prop))))
+       `(,act-det . ,act-prop)))
+   det-list))
 
 (defun enwc-wicd-get-wireless-nw-props (id)
   "Get the network properties of a network.
@@ -174,13 +171,12 @@ 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)
-           (enwc-wicd-get-wireless-network-property id x))
-         enwc-wicd-details-list)
-  ;; Wait for less than a second.
+  (dolist (x enwc-wicd-details-list)
+    (enwc-wicd-get-wireless-network-property id x))
+
   (with-timeout (enwc-wicd-prop-timeout)
-      (while (< enwc-wicd-prop-num 6)
-       (read-event nil nil 0.001)))
+    (while (< enwc-wicd-prop-num (length enwc-wicd-details-list))
+      (read-event nil nil 0.001)))
 
   (if (assoc "encryption" enwc-wicd-prop-values)
       (let ((enc-type (enwc-wicd-get-encryption-type id)))
@@ -192,20 +188,22 @@ For a list of properties, see `enwc-wicd-details-list'."
 
   (enwc-wicd-build-prop-list enwc-wicd-prop-values enwc-wicd-details-list))
 
+(defalias 'enwc-wicd-get-wireless-network-props 
'enwc-wicd-get-wireless-nw-props)
+
 (defun enwc-wicd-get-encryption-type (id)
   "Wicd get encryption type function.
 This calls the D-Bus method on Wicd to get the encryption_method
 property from wireless network with id ID."
   (enwc-wicd-dbus-wireless-call-method "GetWirelessProperty"
-                                      id "encryption_method"))
+                                       id "encryption_method"))
 
 (defun enwc-wicd-get-wired-nw-prop (id det)
   "Gets property DET from the wired network with id ID."
   (enwc-wicd-dbus-wired-call-method "GetWiredProperty" id det))
 
-;;;;;;;;;;;;;;;;;;;;;
-;; Connect Functions
-;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;
+;; Connect Functions ;;
+;;;;;;;;;;;;;;;;;;;;;;;
 
 (defun enwc-wicd-connect (id &optional wired)
   "Wicd connect function.
@@ -224,13 +222,13 @@ wireless network with id ID."
 (defun enwc-wicd-wired-connect (id)
   "Connects to the wired network with profile id ID."
   (let* ((profs (enwc-wicd-get-wired-profiles))
-        (prf (nth id profs)))
+         (prf (nth id profs)))
     (enwc-wicd-dbus-wired-call-method "ReadWiredNetworkProfile" prf)
     (enwc-wicd-dbus-wired-call-method "ConnectWired")))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Disconnect functions.
-;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Disconnect functions ;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defun enwc-wicd-disconnect (&optional wired)
   (if wired
@@ -245,22 +243,28 @@ wireless network with id ID."
   "Disconnects from the wired connection."
   (enwc-wicd-dbus-wired-call-method "DisconnectWired"))
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Get current network id
-;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Get current network id ;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-(defun enwc-wicd-get-current-nw-id (wired)
+(defun enwc-wicd-get-current-nw-id (wired-p)
   "Wicd get current network id function.
 The current network id is updated upon connect,
 so this jut returns the tracked network id."
-  (if wired
-      -1
-    (enwc-wicd-dbus-wireless-call-method "GetCurrentNetworkID")))
-    ;;enwc-wicd-current-nw-id))
-
-;;;;;;;;;;;;;;;;;;;;
-;; Check Connecting
-;;;;;;;;;;;;;;;;;;;;
+  (let ((ap (enwc-wicd-dbus-wireless-call-method "GetCurrentNetworkID")))
+    (cond
+     (wired-p 'wired)
+     ((< ap 0) nil)
+     (t ap)))
+  ;; (if wired
+  ;;     -1
+  ;;   (enwc-wicd-dbus-wireless-call-method "GetCurrentNetworkID"))
+  )
+;;enwc-wicd-current-nw-id))
+
+;;;;;;;;;;;;;;;;;;;;;;
+;; Check Connecting ;;
+;;;;;;;;;;;;;;;;;;;;;;
 
 (defun enwc-wicd-check-connecting ()
   "The Wicd check connecting function."
@@ -295,32 +299,32 @@ The returned list will be in the format:
  (name . ((\"Name\" . \"DISPLAY-NAME\")
           (\"reqs\" . ((\"Display\" . \"id\") ...))))"
   (let (sec-types
-       ret-list)
+        ret-list)
     (with-temp-buffer
       (insert-file-contents (concat "/etc/wicd/encryption/templates/active"
-                                   (if wired
-                                       "_wired")))
+                                    (if wired
+                                        "_wired")))
       (setq sec-types (split-string (buffer-string) "\n")))
     (setq ret-list
-         (mapcar (lambda (x)
-                   (if (not (eq (length x) 0))
-                       (let (name reqs)
-                         (with-temp-buffer
-                           (insert-file-contents (concat 
"/etc/wicd/encryption/templates/"
-                                                         x))
-                           (re-search-forward "name[ \t]*=[ 
\t]*\\([^\n]*\\)[\n]")
-                           (setq name (match-string 1))
-                           (re-search-forward "require[ \t]*\\([^\n]*\\)[\n]")
-                           (let ((str-reqs (split-string (match-string 1) " 
")))
-                             (while str-reqs
-                               (setq reqs
-                                     (append reqs
-                                             (cons (cons (pop str-reqs)
-                                                         (pop str-reqs))
-                                                   nil)))))
-                           (cons x (cons (cons "Name" name) (cons (cons "reqs" 
(cons reqs nil)) nil)))
-                           ))))
-                 sec-types))))
+          (mapcar (lambda (x)
+                    (if (not (eq (length x) 0))
+                        (let (name reqs)
+                          (with-temp-buffer
+                            (insert-file-contents (concat 
"/etc/wicd/encryption/templates/"
+                                                          x))
+                            (re-search-forward "name[ \t]*=[ 
\t]*\\([^\n]*\\)[\n]")
+                            (setq name (match-string 1))
+                            (re-search-forward "require[ \t]*\\([^\n]*\\)[\n]")
+                            (let ((str-reqs (split-string (match-string 1) " 
")))
+                              (while str-reqs
+                                (setq reqs
+                                      (append reqs
+                                              (cons (cons (pop str-reqs)
+                                                          (pop str-reqs))
+                                                    nil)))))
+                            (cons x (cons (cons "Name" name) (cons (cons 
"reqs" (cons reqs nil)) nil)))
+                            ))))
+                  sec-types))))
 
 (defun enwc-wicd-get-profile-ent (wired id ent)
   "Gets profile entry ENT from the network with id ID.
@@ -334,10 +338,22 @@ functions, allowing for a single function that checks for 
wired."
 (defun enwc-wicd-get-profile-info (id &optional wired)
   (let ((dns-list (enwc-wicd-get-dns wired id)))
     (list (cons (cons "addr" (enwc-wicd-get-ip-addr wired id)) nil)
-         (cons (cons "netmask" (enwc-wicd-get-netmask wired id)) nil)
-         (cons (cons "gateway" (enwc-wicd-get-gateway wired id)) nil)
-         (cons (cons "dns1" (nth 0 dns-list)) nil)
-         (cons (cons "dns2" (nth 1 dns-list)) nil))))
+          (cons (cons "netmask" (enwc-wicd-get-netmask wired id)) nil)
+          (cons (cons "gateway" (enwc-wicd-get-gateway wired id)) nil)
+          (cons (cons "dns1" (nth 0 dns-list)) nil)
+          (cons (cons "dns2" (nth 1 dns-list)) nil))))
+
+(defun enwc-wicd-get-profile-sec-info (id sec-type &optional wired)
+  "Get the security info for profile with id ID and security type SEC-TYPE."
+  (let ((sec-reqs (cadr (assoc "reqs"
+                               (cdr (assoc sec-type
+                                           (enwc-wicd-get-sec-types wired))))))
+        ret-list)
+    (setq ret-list
+          (mapcar (lambda (x)
+                    (if (not (eq (length (cdr x)) 0))
+                        (cons (cdr x) (enwc-wicd-get-profile-ent wired id (car 
x)))))
+                  sec-reqs))))
 
 (defun enwc-wicd-get-ip-addr (wired id)
   "Gets the IP Address from the network with id ID.
@@ -350,20 +366,20 @@ WIRED is set to indicate whether this is a wired network."
   (or (enwc-wicd-get-profile-ent wired id "netmask") ""))
 
 (defun enwc-wicd-get-gateway (wired id)
-    "Gets the Gateway from the network with id ID.
+  "Gets the Gateway from the network with id ID.
 WIRED is set to indicate whether this is a wired network."
   (or (enwc-wicd-get-profile-ent wired id "gateway") ""))
 
 (defun enwc-wicd-get-dns (wired id)
-    "Gets the list of DNS servers from the network with id ID.
+  "Gets the list of DNS servers from the network with id ID.
 WIRED is set to indicate whether this is a wired network."
   (list (or (enwc-wicd-get-profile-ent wired id "dns1") "")
-       (or (enwc-wicd-get-profile-ent wired id "dns2") "")
-       (or (enwc-wicd-get-profile-ent wired id "dns3") "")))
+        (or (enwc-wicd-get-profile-ent wired id "dns2") "")
+        (or (enwc-wicd-get-profile-ent wired id "dns3") "")))
 
-;;;;;;;;;;;;;;;;;;;;;;;;
-;; Save Network Settings
-;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Save Network Settings ;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defun enwc-wicd-set-nw-prop (wired id prop val)
   "Sets the network property PROP of the network with id ID
@@ -371,9 +387,9 @@ to VAL.
 WIRED indicates whether this is a wired network."
   (if wired
       (enwc-wicd-dbus-wired-call-method "SetWiredProperty"
-                                       id prop val)
+                                        id prop val)
     (enwc-wicd-dbus-wireless-call-method "SetWirelessProperty"
-                                        id prop val)))
+                                         id prop val)))
 
 (defun enwc-wicd-save-nw-profile (wired id)
   "Save the network profile with for the network with id ID.
@@ -388,53 +404,52 @@ the network with id ID."
   (let ((enctype (cdr (assoc "enctype" settings))))
 
     (enwc-wicd-set-nw-prop wired id "ip"
-                          (cdr (assoc "addr" settings)))
+                           (cdr (assoc "addr" settings)))
     (enwc-wicd-set-nw-prop wired id "netmask"
-                          (cdr (assoc "netmask" settings)))
+                           (cdr (assoc "netmask" settings)))
     (enwc-wicd-set-nw-prop wired id "gateway"
-                          (cdr (assoc "gateway" settings)))
+                           (cdr (assoc "gateway" settings)))
 
     (enwc-wicd-set-nw-prop wired id "dns1"
-                          (cdr (assoc "dns1" settings)))
+                           (cdr (assoc "dns1" settings)))
     (enwc-wicd-set-nw-prop wired id "dns2"
-                          (cdr (assoc "dns2" settings)))
+                           (cdr (assoc "dns2" settings)))
 
     (enwc-wicd-set-nw-prop wired id "enctype" enctype)
     (if (not (string= enctype "None"))
-       (dolist (x (cadr (assoc "reqs"
-                               (cdr (assoc enctype
-                                           (enwc-wicd-get-sec-types wired))))))
-         (enwc-wicd-set-nw-prop wired id (car x)
-                                (cdr (assoc (car x) settings)))))
+        (dolist (x (cadr (assoc "reqs"
+                                (cdr (assoc enctype
+                                            (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)))
 
 (defun enwc-wicd-wireless-prop-changed (state info)
-  (if state
-      (if (eq state 0)
-         (setq enwc-wicd-current-ap ""
-               enwc-wicd-current-nw-id -1)
-       (setq enwc-wicd-current-ap (car (cadr info))
-             enwc-wicd-current-nw-id (or (and info
-                                              (nthcdr 3 info)
-                                              (caar (nthcdr 3 info))
-                                              (string-to-number (caar (nthcdr 
3 info))))
-                                         -1)))))
+  (when state
+    (if (eq state 0)
+        (setq enwc-wicd-current-ap ""
+              enwc-wicd-current-nw-id nil)
+      (setq enwc-wicd-current-ap (car (cadr info))
+            enwc-wicd-current-nw-id (and info
+                                         (nthcdr 3 info)
+                                         (caar (nthcdr 3 info))
+                                         (string-to-number (caar (nthcdr 3 
info))))))))
 
 (defun enwc-wicd-setup ()
   ;; Thanks to Michael Albinus for pointing out this signal.
   (dbus-register-signal :system
-                       enwc-wicd-dbus-service
-                       enwc-wicd-dbus-wireless-path
-                       enwc-wicd-dbus-wireless-interface
-                       "SendEndScanSignal"
-                       'enwc-process-scan)
+                        enwc-wicd-dbus-service
+                        enwc-wicd-dbus-wireless-path
+                        enwc-wicd-dbus-wireless-interface
+                        "SendEndScanSignal"
+                        'enwc-process-scan)
 
   (dbus-register-signal :system
-                       enwc-wicd-dbus-service
-                       "/org/wicd/daemon"
-                       enwc-wicd-dbus-service
-                       "StatusChanged"
-                       'enwc-wicd-wireless-prop-changed))
+                        enwc-wicd-dbus-service
+                        "/org/wicd/daemon"
+                        enwc-wicd-dbus-service
+                        "StatusChanged"
+                        'enwc-wicd-wireless-prop-changed))
 
 (provide 'enwc-wicd)
 
diff --git a/lisp/enwc.el b/lisp/enwc.el
index ec187c3..6c9d7b3 100644
--- a/lisp/enwc.el
+++ b/lisp/enwc.el
@@ -37,18 +37,18 @@
 ;;
 ;; (require 'enwc-setup)
 ;; (enwc-setup)
-;; 
+;;
 ;; to your .emacs file.
 
 (require 'dbus)
 (require 'wid-edit)
 (require 'tabulated-list)
+(require 'cl-lib)
+(require 'cl-macs)
+(require 'format-spec)
 
 ;;; Code:
 
-(eval-when-compile
-  (require 'cl))
-
 (defgroup enwc nil
   "*The Emacs Network Client"
   :prefix "ewnc-"
@@ -94,47 +94,40 @@ networks every `enwc-auto-scan-interval' seconds."
 (defcustom enwc-mode-line-format "[%s%%]"
   "The format for displaying the mode line.
 
-%s = The current signal strength.  If wired, then this is set to
-100.
+%s = The current signal strength.  If wired, then this is set to 100.
+
+%e = The essid of the current network.  If wired, then this set to 'Wired'
 
-%e = The essid of the current network.  If wired, then this set to
-'Wired'
+%b = The bssid of the current network.  If using a wired connection, then this
+is set to 'Wired'.
 
-%b = The bssid of the current network.  If using a wired connection,
-then this is set to 'Wired'.
+%n = The encryption type of the current network, or 'Wired' if using a wired
+connection.
+
+%c = The channel of the current network, or 'Wired' if using a wired 
connection.
 
 %% = A Normal '%'"
   :group 'enwc
   :type 'string)
 
+(defcustom enwc-sec-types
+  '("wpa" "wep" "wpa-leap" "wpa-peap" "leap" "peap")
+  "The security types used for ENWC.
+Each of these have associations within the back-ends.")
+
 ;;; The function variables for the abstract layer.
 
 (defvar enwc-scan-func nil
   "The function variable for the scan function.
 This variable is set during setup.")
 
-(defvar enwc-get-nw-func nil
-  "A function variable to be used in `enwc-get-nw'.
+(defvar enwc-get-networks-func nil
+  "A function variable to be used in `enwc-get-networks'.
 This is redefined during setup to be the function to get the network
  list.")
 
-;; (defvar enwc-get-wireless-nw-prop-func nil
-;;   "A function variable to be used in `enwc-get-wireless-nw-prop'.
-;; This is redefined during setup to be the function to get
-;; a wireless network property.")
-
 (defvar enwc-get-wireless-nw-props-func nil)
 
-;; (defvar enwc-get-encryption-type-func nil
-;;   "A function variable to be used in `enwc-get-encryption-type'.
-;; This is redefined during setup to be the function to get the encryption
-;; type for the selected backend.")
-
-;; (defvar enwc-wireless-connect-func nil
-;;   "The function variable for the wireless connect function.
-;; This is redefined during setup to be the function to connect
-;; for the selected backend.")
-
 (defvar enwc-connect-func nil
   "The function variable for the connect function.")
 
@@ -151,110 +144,52 @@ the current network id.")
 This is redefined during setup to be the function to
 check whether or not ENWC is connecting.")
 
-(defvar enwc-wireless-disconnect-func nil
-  "The function variable for the wireless disconnect function.
-This is redefined during setup to be the function to
-disconnect from the wireless network.")
-
-;; (defvar enwc-get-wired-profiles-func nil
-;;   "The function variable to be used in `enwc-get-wired-profiles'.
-;; This is redefined during setup to be the function to
-;; get the list of wired network profiles.")
-
-;; (defvar enwc-wired-connect-func nil
-;;   "The function variable for the wired connect function.
-;; This is redefined during setup to be the function
-;; to connect to a wired network.")
-
-;; (defvar enwc-wired-disconnect-func nil
-;;   "The function variable for the wired disconnect function.
-;; This is redefined during setup to be the function
-;; to disconnect from a wired network.")
-
 (defvar enwc-is-wired-func nil
   "The function variable to be used in `enwc-is-wired'.
 This is redefined during setup to be the function to
 check whether or not a wired connection is active.")
 
-;; (defvar enwc-get-wired-nw-prop-func nil
-;;   "The function variable to be used in `enwc-get-wired-nw-prop'.
-;; This is redefined during setup to be the function to get
-;; a network property from a wired network.")
-
-(defvar enwc-get-sec-types-func nil
-  "The function variable to be used in `enwc-get-sec-types'.
-This is redefined during setup to be the function to get
-the security types for a given network.")
-
-;; (defvar enwc-get-ip-addr-func nil
-;;   "The function variable to be used in `enwc-get-ip-addr'.
-;; This is redefined during setup to be the function to get
-;; the IP Address of a given network.")
-
-;; (defvar enwc-get-netmask-func nil
-;;   "The function variable to be used in `enwc-get-netmask'.
-;; This is redefined during setup to be the function to get
-;; the Netmask of a given network.")
-
-;; (defvar enwc-get-gateway-func nil
-;;   "The function variable to be used in `enwc-get-gateway'.
-;; This is redefined during setup to be the function to get
-;; the Gateway of a given network.")
-
-;; (defvar enwc-get-dns-func nil
-;;   "The function variable to be used in `enwc-get-dns'.
-;; This is redefined during setup to be the function to get
-;; the DNS Server Addresses for a given network.")
-
 (defvar enwc-get-profile-info-func nil)
 
-;;(defvar enwc-get-profile-info-func nil)
+(defvar enwc-get-profile-sec-info-func nil)
 
 (defvar enwc-save-nw-settings-func nil
   "The function variable to be used in `enwc-save-nw-settings'.
 This is redefined during setup to be the function to save
 the network settings of a given network.")
 
-(defvar enwc-details-list
-  '("essid" "bssid" "strength" "mode" "encrypt" "channel")
-  "The network details list.
-
-This is redefined during setup to be the details list
-for the selected backend.
-
-This usually includes signal strength, essid, encryption type,
-bssid, mode, and channel.")
-
 (defvar enwc-display-string " [0%] "
   "The mode line display string.
 This is altered every second to display the current network strength
 in `enwc-update-mode-line'.")
 
-;; (setq tabulated-list-format (vector `("ID" ,enwc-id-width sort) ...))
-;; (setq tabulated-list-entries `((,id [id str essid encrypt ...]) ...))
-;; (tabulated-list-init-header)
-;; (tabulated-list-print)
-
-(defvar enwc-wireless-headers '("ID" "STR" "ESSID"
-                               "ENCRYPT" "BSSID" "MODE" "CHNL")
-  "The list of headers to be displayed in the ENWC buffer.
-These correspond to the details in `enwc-details-list'.")
-
-(defvar enwc-id-width 3
-  "The width of the id column.")
-(defvar enwc-strength-width 5
-  "The width of the strength column.")
-(defvar enwc-essid-width 5
-  "The initial width of the essid column.
-This is reset in wicd-scan-internal.")
-(defvar enwc-encrypt-width 10
-  "The width of the encryption column.")
-(defvar enwc-bssid-width 18
-  "The width of the bssid column.")
-(defvar enwc-mode-width 16
-  "The width of the mode column.")
-(defvar enwc-channel-width 3
-  "The width of the channel column.")
+(defun enwc-print-strength (s)
+  "Convert signal strength S to a string to dispay."
+  (concat (number-to-string s) "%"))
+
+(defvar enwc-details-alist
+  `((strength . ((display . "Str")
+                 (width   . 0)
+                 (conv    . enwc-print-strength)))
+    (essid    . ((display . "Essid")
+                 (width   . 0)
+                 (conv    . identity)))
+    (encrypt  . ((display . "Encrypt")
+                 (width   . 0)
+                 (conv    . identity)))
+    (bssid    . ((display . "Bssid")
+                 (width   . 0)
+                 (conv    . identity)))
+    (channel  . ((display . "Chnl")
+                 (width   . 0)
+                 (conv    . identity))))
+  "Alist of the details to their information.
+
+The information entries themselves are an alist, with the following keys:
+
+DISPLAY is the display name.
+WIDTH is used during display to keep track of the width of each one.
+CONV is the conversion function used during display.")
 
 (defvar enwc-last-scan nil
   "The most recent scan results.")
@@ -265,7 +200,7 @@ This is reset in wicd-scan-internal.")
 (defvar enwc-using-wired nil
   "Whether or not wired mode is active.
 
-This is `non-NIL' if ENWC is using wired connections.
+This is `non-nil' if ENWC is using wired connections.
 Note that this is NOT the same as `enwc-is-wired'.  This checks
 whether or not ENWC is in wired mode.")
 
@@ -290,6 +225,7 @@ This is only used internally.")
   "The timer for automatic scanning.")
 
 (make-local-variable 'enwc-edit-id)
+
 ;; The Faces
 
 (defface enwc-connected-face
@@ -301,195 +237,157 @@ This is only used internally.")
   "The face for the connected network."
   :group 'enwc)
 
+;; Necessary for the macros used later.
+(eval-when-compile
+  (defun enwc--break-by-words (str)
+    "Break up string STR into a list of words."
+    (cl-check-type str string)
+    (split-string str "-\\|_"))
+
+  (defun enwc--sym-to-str (sym &optional seps)
+    "Create a string from symbol SYM.
+SEPS is a string specifying the separator to use to combine the words,
+or \" \" if not specified."
+    (cl-check-type sym symbol)
+    (unless seps
+      (setq seps " "))
+    (cl-check-type seps string)
+    (combine-and-quote-strings (enwc--break-by-words (symbol-name sym)) seps))
+
+  (defun ewnc--str-to-sym (str &optional seps)
+    "Create a symbol from the string STR.
+This will break STR into words, and then put it back together separating
+each word by SEPS, which defaults to \"-\"."
+    (cl-check-type str string)
+    (unless seps
+      (setq seps "-"))
+    (cl-check-type seps string)
+    (intern (combine-and-quote-strings (enwc--break-by-words str) seps))))
+
 ;;;;;;;;;;;;;;;;;;;;
-;; ENWC functions
+;; ENWC functions ;;
 ;;;;;;;;;;;;;;;;;;;;
 
+(defun enwc-get-networks ()
+  "Gets the identifiers for the access points
+from a previous scan."
+  (funcall enwc-get-networks-func))
+
 (defun enwc-do-scan ()
   "Runs a backend scan."
   (funcall enwc-scan-func))
 
-(defun enwc-get-nw ()
-  "Gets the identifiers for the access points
-from a previous scan."
-  (funcall enwc-get-nw-func))
+(defun enwc-connect (id)
+  "Connect to network with id ID.
+
+ID is specific to the backend."
+  (funcall enwc-connect-func id enwc-using-wired))
+
+(defun enwc-disconnect ()
+  "Disconnect from the current network."
+  (funcall enwc-disconnect-func enwc-using-wired))
 
 (defun enwc-get-current-nw-id ()
   "Gets the id of the current network id,
-or `nil' if there isn't one."
+or nil if there isn't one.
+
+The returned id is specific to the backend."
   (funcall enwc-get-current-nw-id-func enwc-using-wired))
 
 (defun enwc-check-connecting-p ()
-  "Checks to see if there is a connection
-in progress.  Returns `non-NIL' if there is one,
-`NIL' otherwise."
+  "Check to see if there is a connection in progress.
+Returns `non-nil' if there is one, nil otherwise."
   (funcall enwc-check-connecting-func))
 
-;; (defun enwc-get-wireless-nw-prop (id prop)
-;;   "Gets property PROP from wireless network with id
-;; ID and returns it."
-;;   (funcall enwc-get-wireless-nw-prop-func id prop))
-
 (defun enwc-get-wireless-nw-props (id)
-  (funcall enwc-get-wireless-nw-props-func id))
+  "Get the network properties of the wireless network with id ID.
+This will return an associative list with the keys
+corresponding to `enwc-details-alist'.
 
-;; (defun enwc-get-encryption-type (id)
-;;   "Gets the encryption type used by the wireless
-;; network with id ID."
-;;   (funcall enwc-get-encryption-type-func id))
-
-;; (defun enwc-get-wired-profiles ()
-;;   "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."
-;;   (funcall enwc-wireless-connect-func id))
-
-(defun enwc-connect (id)
-  (funcall enwc-connect-func id enwc-using-wired))
-
-(defun enwc-disconnect ()
-  (funcall enwc-disconnect-func enwc-using-wired))
-
-;; (defun enwc-wireless-disconnect ()
-;;   "Disconnects the wireless."
-;;   (funcall enwc-wireless-disconnect-func))
-
-;; (defun enwc-wired-connect (id)
-;;   "Connects to the wired profile with id ID."
-;;   (funcall enwc-wired-connect-func id))
-
-;; (defun enwc-wired-disconnect ()
-;;   "Disconnects from the current network."
-;;   (funcall enwc-wired-disconnect-func))
+ID is specific to the backend."
+  (funcall enwc-get-wireless-nw-props-func id))
 
 (defun enwc-is-wired-p ()
-  "Checks whether or not ENWC is connected to
-a wired network.
+  "Checks whether or not ENWC is connected to a wired network.
 Note that this is NOT the same as `enwc-using-wired'.
 This checks for an active wired connection."
   (funcall enwc-is-wired-func))
 
-(defun enwc-get-sec-types (wired)
-  "Gets the security types for network.
-WIRED is set to indicate whether or not this is
-a wired network."
-  (funcall enwc-get-sec-types-func wired))
-
-;; (defun enwc-get-network-ent (wired id ent)
-;;   "Gets network entry ENT from the network with network id ID.
-;; WIRED is set to indicate whether or not this is
-;; a wired network."
-;;   (if wired
-;;       nil
-;;     (enwc-get-wireless-nw-prop id ent)))
-
-;; (defun enwc-get-wired-nw-prop (id prop)
-;;   "Gets network property PROP from
-;;  the wired network with network id ID."
-;;   (funcall enwc-get-wired-nw-prop-func id prop))
-
-;; (defun enwc-get-ip-addr (wired id)
-;;   "Gets the IP Address from the network with network id ID.
-;; WIRED is set to indicate whether or not this is
-;; a wired network."
-;;   (funcall enwc-get-ip-addr-func wired id))
-
-;; (defun enwc-get-netmask (wired id)
-;;   "Gets the Netmask from the network with network id ID.
-;; WIRED is set to indicate whether or not this is
-;; a wired network."
-;;   (funcall enwc-get-netmask-func wired id))
-
-;; (defun enwc-get-gateway (wired id)
-;;   "Gets the Gateway from the network with network id ID.
-;; WIRED is set to indicate whether or not this is
-;; a wired network."
-;;   (funcall enwc-get-gateway-func wired id))
-
-;; (defun enwc-get-dns (wired id)
-;;   "Gets the DNS Servers from the network with network id ID.
-;; WIRED is set to indicate whether or not this is
-;; a wired network."
-;;   (funcall enwc-get-dns-func wired id))
-
 (defun enwc-get-profile-info (id)
+  "Get the profile information for network ID.
+
+ID is specific to the backend."
   (funcall enwc-get-profile-info-func id enwc-using-wired))
 
+(defun enwc-get-profile-sec-info (id sec-type)
+  "Get the security info for the network ID.
+SEC-TYPE is the type of security for which to obtain the data.
+
+ID is specific to the backend."
+  (funcall enwc-get-profile-sec-info-func id sec-type enwc-using-wired))
+
 (defun enwc-save-nw-settings (id settings)
-  "Saves network settings SETTINGS to the network profile with
-network id ID.
-SETTINGS is an association list with entries for the IP Address,
-Netmask, Gateway, DNS Servers, and Security.
-WIRED is set to indicate whether or not this is
-a wired network."
+  "Saves network settings SETTINGS to the network profile with network id ID.
+SETTINGS is an association list with entries for the IP Address, Netmask,
+Gateway, DNS Servers, and Security.  WIRED is set to indicate whether or not
+this is a wired network.
+
+ID is specific to the backend."
   (funcall enwc-save-nw-settings-func id settings enwc-using-wired))
 
-;;;;;;;;;;;;;;;;;;;;;
-;; Actual Functions
-;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;
+;; Actual Functions ;;
+;;;;;;;;;;;;;;;;;;;;;;
 
-(defun enwc-is-valid-nw-id (id)
+(defun enwc-is-valid-nw-id-p (id)
   "Confirms that ID is a valid network id."
-  (<= 0 id))
+  (and id (not (eq id 'wired))))
+
+(defun enwc-value-from-scan (detail &optional id)
+  "Retrieve a value for DETAIL from `enwc-last-scan'.
+If ID is specified, then it will get the entry for ID.
+Otherwise, ID is set to the current network ID.
+
+If DETAIL is not found in `enwc-last-scan', then return nil."
+  (unless id
+    (setq id (enwc-get-current-nw-id)))
+  (when enwc-last-scan
+    (alist-get detail (alist-get id enwc-last-scan))))
 
-(defun enwc-get-nw-prop (wired id prop)
-  "Small function to get network property PROP from the network
-with network id ID.
-WIRED indicates whether or not this is a wired connection."
-  ;; (if wired
-  ;;     (enwc-get-wired-nw-prop id prop)
-  ;;   (enwc-get-wireless-nw-prop id prop))
-  )
+(defun enwc-make-format-spec ()
+  (let* ((cur-id (enwc-get-current-nw-id))
+         (wiredp (enwc-is-wired-p))
+         (no-last (not enwc-last-scan))
+         (invalid-id (not (enwc-is-valid-nw-id-p cur-id)))
+         (connectingp (enwc-check-connecting-p)))
+    (format-spec-make ?s (cond
+                          (wiredp "100")
+                          ((or invalid-id no-last) "0")
+                          (connectingp "*")
+                          (t (enwc-value-from-scan 'strength cur-id)))
+                      ?e (cond
+                          (wiredp "Wired")
+                          ((or invalid-id connectingp no-last) "None")
+                          (t (enwc-value-from-scan 'essid cur-id)))
+                      ?b (cond
+                          (wiredp "Wired")
+                          ((or invalid-id connectingp no-last) "none")
+                          (t (enwc-value-from-scan 'bssid cur-id)))
+                      ?n (cond
+                          (wiredp "None")
+                          ((or invalid-id connectingp no-last) "None")
+                          (t (enwc-value-from-scan 'encrypt cur-id)))
+                      ?c (cond
+                          (wiredp "None")
+                          ((or invalid-id connectingp no-last) "None")
+                          (t (enwc-value-from-scan 'channel cur-id)))
+                      ?% "%")))
 
 (defun enwc-format-mode-line-string ()
   "Formats the mode line string.
 This is derived from `enwc-mode-line-format'.
 See the documentation for it for more details."
-  (let* ((f enwc-mode-line-format)
-         (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)
-            p (1+ p))
-      (setq fin-str
-            (concat
-             fin-str
-             (if (not (eq c ?%))
-                 (char-to-string c)
-               (setq p (1+ p))
-               (cond
-                ((eq (elt f (1- p)) ?s)
-                 (cond
-                  (wiredp "100")
-                  ((or (not (enwc-is-valid-nw-id cur-id))
-                       (not enwc-last-scan))"0")
-                  (connectingp "*")
-                  (t (number-to-string
-                      (cdr (assoc "strength" (nth cur-id enwc-last-scan)))))))
-                ((eq (elt f (1- p)) ?e)
-                 (cond
-                  (wiredp "Wired")
-                  ((or (not (enwc-is-valid-nw-id cur-id))
-                       connectingp
-                       (not enwc-last-scan)) "None")
-                  (t (cdr (assoc "essid" (nth cur-id enwc-last-scan))))))
-                ((eq (elt f (1- p)) ?b)
-                 (cond
-                  (wiredp "wired")
-                  ((or (not (enwc-is-valid-nw-id cur-id))
-                       connectingp
-                       (not enwc-last-scan)) "none")
-                  (t (cdr (assoc "bssid" (nth cur-id enwc-last-scan))))))
-                ((eq (elt f (1- p)) ?%) "%"))))))
-    fin-str))
+  (format-spec enwc-mode-line-format (enwc-make-format-spec)))
 
 (defun enwc-update-mode-line ()
   "Updates the mode line display.
@@ -503,12 +401,11 @@ This is initiated during setup, and runs once every 
second."
   (interactive)
   (or global-mode-string (setq global-mode-string '("")))
   (setq enwc-display-mode-line t)
-  (unless (member 'enwc-display-string
-                  global-mode-string)
+  (unless (member 'enwc-display-string global-mode-string)
     (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)))
+  (unless enwc-display-mode-line-timer
+    (setq enwc-display-mode-line-timer
+          (run-at-time t 1 'enwc-update-mode-line)))
   (message "ENWC mode line enabled"))
 
 (defun enwc-disable-display-mode-line ()
@@ -517,8 +414,8 @@ This is initiated during setup, and runs once every second."
   (or global-mode-string (setq global-mode-string '("")))
   (setq enwc-display-mode-line nil)
   (setq global-mode-string (remove 'enwc-display-string global-mode-string))
-  (if enwc-display-mode-line-timer
-      (cancel-timer enwc-display-mode-line-timer))
+  (when enwc-display-mode-line-timer
+    (cancel-timer enwc-display-mode-line-timer))
   (setq enwc-display-mode-line-timer nil)
   (message "ENWC mode line disabled"))
 
@@ -542,9 +439,26 @@ This will use the current value of 
`enwc-auto-scan-interval'."
       (message "Auto scan disabled"))
     (setq enwc-auto-scan new)))
 
-;;;;;;;;;;;;;;;;;;
-;; Scan internal
-;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;
+;; Scan internal ;;
+;;;;;;;;;;;;;;;;;;;
+
+(defun enwc-scan (&optional nodisp)
+  "The frontend of the scanning routine.  Sets up and moves to
+the ENWC buffer if necessary, and scans and displays the networks.
+If NODISP is non-nil, then do not display the results in the ENWC
+buffer."
+  (interactive "p")
+  (unless nodisp
+    (setq enwc-scan-interactive t))
+  (when (get-buffer "*ENWC*")
+    (with-current-buffer "*ENWC*"
+      (if enwc-using-wired
+          (progn
+            (enwc-scan-internal)
+            (goto-char 0)
+            (forward-line))
+        (enwc-scan-internal)))))
 
 (defun enwc-scan-internal-wireless ()
   "The initial scan routine.
@@ -553,73 +467,24 @@ waiting for the callback.
 
 All back-ends must call enwc-process-scan in some way
 upon completion of a scan."
-  (if enwc-scan-interactive
-      (message "Scanning..."))
+  (when enwc-scan-interactive
+    (message "Scanning..."))
   (setq enwc-scan-requested t)
   (setq enwc-scan-done nil)
   (enwc-do-scan))
 
-(defun enwc-process-scan (&rest args)
-  "The scanning callback.
-After a scan has been performed, this processes and displays
-the scan results."
-  (if (or enwc-using-wired (not enwc-scan-requested))
-      nil
-    (setq enwc-scan-requested nil)
-    (let ((cur-id 0)
-         (nw-prop-list nil))
-      (if enwc-scan-interactive
-          (message "Scanning... Done"))
-      (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)))))
-      (setq enwc-last-scan
-           (mapcar (lambda (x)
-                     (let ((ret-itm (cons (cons "id" cur-id) nil))
-                           (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 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)
-                                                       nil)))))
-                       ret-itm))
-                   (number-sequence 0 (1- (length enwc-access-points))))))
-    (setq enwc-essid-width (1+ enwc-essid-width))
-    (setq enwc-scan-done t)
-    (enwc-display-wireless-networks enwc-last-scan)
-    (setq enwc-scan-interactive nil)))
-
 (defun enwc-scan-internal-wired ()
   "The scanning routine for a wired connection.
 This gets the list of wired network profiles."
   (message "Updating Profiles...")
-  (let ((profs (enwc-get-nw))
-       cur-prof fin-profs)
-    (while profs
-      (setq cur-prof (pop profs))
-      (if cur-prof
-         (setq fin-profs (cons cur-prof
-                               fin-profs))))
+  (let ((profs (enwc-get-networks))
+        fin-profs)
+    (dolist (cur-prof profs)
+      (when cur-prof
+        (push cur-prof fin-profs)))
     (message "Updating Profiles... Done")
-    (setq enwc-access-points fin-profs)
-    (setq enwc-last-scan fin-profs)
+    (setq enwc-access-points fin-profs
+          enwc-last-scan     fin-profs)
     fin-profs))
 
 (defun enwc-scan-internal ()
@@ -630,16 +495,55 @@ This checks whether or not wired is being used,
       (enwc-scan-internal-wired)
     (enwc-scan-internal-wireless)))
 
-;;;;;;;;;;;;;;;;;;;;;
-;; Display Networks
-;;;;;;;;;;;;;;;;;;;;;
+(defun enwc-update-width (detail &optional val)
+  "Update the width for column DETAIL to VAL.
+This modifies the width entry in `enwc-details-alist' that corresponds to
+DETAIL.
+
+If VAL is not specified, then use the width of the display name for DETAIL."
+  (unless val
+    (setq val (1+ (length (cdr (assq 'display (cdr (assq detail 
enwc-details-alist))))))))
+  (setq val
+        (max val (cdr (assq 'width (cdr (assq detail enwc-details-alist))))))
+  (setcdr (assq 'width (cdr (assq detail enwc-details-alist)))
+          val))
+
+(defun enwc-reset-widths ()
+  "Reset the column widths for display."
+  (dolist (det enwc-details-alist)
+    (enwc-update-width (car det))))
+
+(defun enwc-process-scan (&rest args)
+  "The scanning callback.
+After a scan has been performed, this processes and displays
+the scan results."
+  (unless (or enwc-using-wired (not enwc-scan-requested))
+    (setq enwc-scan-requested nil
+          enwc-access-points  (enwc-get-networks))
+    (when enwc-scan-interactive
+      (message "Scanning... Done"))
+    (enwc-reset-widths)
+    (setq enwc-last-scan (mapcar
+                          (lambda (ap)
+                            `(,ap . ,(enwc-get-wireless-nw-props ap)))
+                          enwc-access-points))
+    (dolist (nw enwc-last-scan)
+      (dolist (props (cdr nw))
+        (enwc-update-width (car props) (length (prin1-to-string (cdr 
props))))))
+    (setq enwc-scan-done t)
+    (enwc-display-wireless-networks enwc-last-scan)
+    (setq enwc-scan-interactive nil)))
+
+;;;;;;;;;;;;;;;;;;;;;;
+;; Display Networks ;;
+;;;;;;;;;;;;;;;;;;;;;;
 
 (defun enwc-display-wired-networks (networks)
   "Displays the wired networks specified in the list NETWORKS.
 NETWORKS must be in the form returned from
 `enwc-scan-internal-wired'."
-  (if (not (listp networks))
-      (error "NETWORKS must be a list of networks."))
+  (unless (listp networks)
+    (error "NETWORKS must be a list of networks."))
   (let ((inhibit-read-only t))
     (erase-buffer)
     (insert (propertize "Profile" 'face 'enwc-header-face))
@@ -648,14 +552,8 @@ NETWORKS must be in the form returned from
       (insert pr)
       (insert "\n"))))
 
-(defun enwc-insert-ent (ent width)
-  "Small function to insert a network property entry.
-ENT is the entry, and WIDTH is the column width."
-  (insert ent)
-  (insert-char 32 (- width (length ent))))
-
 (defmacro enwc-maybe-pretty-entry (entry)
-  `(if (eq cur-id (cdr (assoc "id" nw)))
+  `(if (eq cur-id (cdr (assq 'id nw)))
        (propertize ,entry
                    'font-lock-face 'enwc-connected-face)
      ,entry))
@@ -664,75 +562,53 @@ ENT is the entry, and WIDTH is the column width."
   "Displays the networks in the list NETWORKS in the current buffer.
 NETWORKS must be in the format returned by
 `enwc-scan-internal-wireless'."
-  (if (not (get-buffer "*ENWC*"))
-      (enwc-setup-buffer t))
-  (if (not (listp networks))
-      (error "NETWORKS must be a list of association lists."))
+  (unless (get-buffer "*ENWC*")
+    (enwc-setup-buffer t))
+  (unless (listp networks)
+    (signal 'wrong-type-argument `(listp ,networks)))
   (with-current-buffer (get-buffer "*ENWC*")
     (let ((cur-id (enwc-get-current-nw-id))
           entries)
-      (let ((header enwc-wireless-headers)
-            (pos 0))
-
-        (setq tabulated-list-format
-              (vector `("ID" ,enwc-id-width)
-                      '("STR" 4)
-                      `("ESSID" ,enwc-essid-width)
-                      `("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)))
-              entry)
-          (setq entry (list nil
-                            (vector
-                             (enwc-maybe-pretty-entry (number-to-string (cdr 
(assoc "id" nw))))
-                             (enwc-maybe-pretty-entry
-                              (concat (number-to-string (cdr (assoc "strength" 
nw)))
-                                      "%"))
-                             (enwc-maybe-pretty-entry (cdr (assoc "essid" 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))))))
-          (setq entries (cons entry entries))))
-
-      (setq tabulated-list-entries (nreverse entries))
-      (tabulated-list-init-header)
-
-      (tabulated-list-print))))
+      (setq tabulated-list-format
+            (apply 'vector
+                   (mapcar
+                    (lambda (det)
+                      `(,(alist-get 'display (cdr det))
+                        ,(alist-get 'width   (cdr det))))
+                    enwc-details-alist)))
+
+      (setq tabulated-list-entries
+            (mapcar
+             (lambda (nw)
+               `(,(car nw)
+                 ,(apply 'vector
+                         (mapcar
+                          (lambda (det)
+                            (let ((conv (alist-get 'conv (cdr det)))
+                                  (ent  (alist-get (car det) (cdr nw))))
+                              (if (equal cur-id (car nw))
+                                  (propertize (funcall conv ent)
+                                              'font-lock-face
+                                              'enwc-connected-face)
+                                (funcall conv ent))))
+                          enwc-details-alist))))
+             networks)))
+    (tabulated-list-init-header)
+
+    (tabulated-list-print)))
 
 (defun enwc-display-networks (networks)
   "Displays the network in NETWORKS.
 This is an entry to the display functions,
 and checks whether or not ENWC is using wired."
-  (if (not (eq major-mode 'enwc-mode))
-      (enwc-setup-buffer))
-  (if (not (listp networks))
-      (error "NETWORKS must be a list."))
+  (unless (eq major-mode 'enwc-mode)
+    (enwc-setup-buffer))
+  (unless (listp networks)
+    (signal 'wrong-type-argument `(listp ,networks)))
   (if enwc-using-wired
       (enwc-display-wired-networks networks)
     (enwc-display-wireless-networks networks)))
 
-(defun enwc-scan (&optional nodisp)
-  "The frontend of the scanning routine.  Sets up and moves to
-the ENWC buffer if necessary, and scans and displays the networks.
-If NODISP is non-nil, then do not display the results in the ENWC
-buffer."
-  (interactive "p")
-  (if (not nodisp)
-      (setq enwc-scan-interactive t))
-  (if (get-buffer "*ENWC*")
-      (with-current-buffer "*ENWC*"
-       (if enwc-using-wired
-           (progn
-             (enwc-scan-internal)
-             (goto-char 0)
-             (forward-line))
-         (enwc-scan-internal)))))
-  
 (defun enwc-find-network (essid &optional networks)
   "Checks through NETWORKS for the network with essid ESSID,
 and returns the network identifier.  Uses `enwc-last-scan' if
@@ -741,63 +617,48 @@ NETWORKS is nil.  If the network is not found, then it 
returns nil.
    When called interactively, this only prints out what it finds.
 Otherwise, it actually returns it."
   (interactive "sNetwork ESSID: ")
-  (if (not (or networks enwc-last-scan))
-      (progn
-       (setq enwc-scan-interactive nil)
-       (enwc-scan-internal)))
+  (unless (or networks enwc-last-scan)
+    (setq enwc-scan-interactive nil)
+    (enwc-scan-internal))
   (let ((nets (or networks enwc-last-scan))
-       need-break cur-net)
-    (if (not nets)
-       (setq nets enwc-last-scan))
+        need-break cur-net)
+    (unless nets
+      (setq nets enwc-last-scan))
     (while (and nets (not need-break))
       (let (cur-essid)
-       (setq cur-net (pop nets))
-       (setq cur-essid (cdr (assoc "essid" cur-net)))
-       (if (string= cur-essid essid)
-           (setq need-break t))))
+        (setq cur-net (pop nets))
+        (setq cur-essid (cdr (assq 'essid cur-net)))
+        (when (string= cur-essid essid)
+          (setq need-break t))))
     (if need-break
-       (if (called-interactively-p 'any)
-           (message (number-to-string (cdr (assoc "id" cur-net))))
-         (cdr (assoc "id" cur-net)))
-      (if (called-interactively-p 'any)
-         (message "Network not found.")
-       nil))))
+        (if (called-interactively-p 'any)
+            (message (number-to-string (cdr (assq 'id cur-net))))
+          (cdr (assq 'id cur-net)))
+      (when (called-interactively-p 'any)
+        (message "Network not found.")))))
 
-;;;;;;;;;;;;;;;;;;;;
-;; Connect Network
-;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;
+;; Connect Network ;;
+;;;;;;;;;;;;;;;;;;;;;
 
 (defun enwc-connect-network (id)
   "Connect to network with id ID.
 This is an entry point for the internal connection functions,
 and checks whether or not ENWC is using wired."
-  (let (cur-net)
-    (enwc-connect id)
-    (if enwc-using-wired
-        (setq cur-net (nth id (enwc-get-nw)))
-      (if enwc-last-scan
-          (setq cur-net (cdr (assoc "essid" (nth id enwc-last-scan))))))
-    cur-net))
-    ;; (if enwc-using-wired
-    ;;     (progn
-    ;;       (enwc-wired-connect id)
-    ;;       (setq cur-net (nth id (enwc-get-wired-profiles))))
-    ;;   (enwc-wireless-connect id)
-    ;;   (if enwc-last-scan
-    ;;       (setq cur-net (cdr (assoc "essid" (nth id enwc-last-scan)))))
-    ;; cur-net)
+  (enwc-connect id)
+  (if enwc-using-wired
+      (nth id (enwc-get-networks))
+    (when enwc-last-scan
+      (enwc-value-from-scan 'essid id))))
 
 (defun enwc-connect-to-network (net-id)
   "Connects the the network with network id NET-ID.
 Confirms that NET-ID is a valid network id.
 This calls `enwc-connect-network' as a subroutine."
-  (interactive "nNetwork ID: ")
-  (if (not (numberp net-id))
-      (error "NET-ID must be a number"))
-  (let ((num-ids (length enwc-last-scan))
-       cur-net)
-    (if (or (< net-id 0) (>= net-id num-ids))
-       (error "Invalid network id."))
+  (interactive "sNetwork ID: ")
+  (let (cur-net)
+    (unless (enwc-is-valid-nw-id-p net-id)
+      (error "Invalid network id."))
     (setq cur-net (enwc-connect-network net-id))
     (message (concat "Connecting to " cur-net))))
 
@@ -806,35 +667,30 @@ This calls `enwc-connect-network' as a subroutine."
   (interactive "sNetwork ESSID: ")
   (let ((net-id (enwc-find-network essid)))
     (if net-id
-       (enwc-connect-to-network net-id)
+        (enwc-connect-to-network net-id)
       (message "Network not found."))))
 
 (defun enwc-connect-to-network-at-point ()
   "Connects to the network at the current line number.
 Moves to the enwc buffer if necessary."
   (interactive)
-  (if (not (eq major-mode 'enwc-mode))
-      (enwc-setup-buffer))
-  (let ((id (- (line-number-at-pos) 1)))
-    (enwc-connect-to-network id)))
+  (unless (eq major-mode 'enwc-mode)
+    (enwc-setup-buffer))
+  ;;TODO: Fix this for wired (which doesn't have tabulated list)
+  (enwc-connect-to-network (tabulated-list-get-id)))
 
 (defun enwc-disconnect-network ()
   "Disconnects from the network, if any."
   (interactive)
   (message "Disconnecting")
   (enwc-disconnect))
-  ;; (if (not (eq major-mode 'enwc-mode))
-  ;;     (enwc-setup-buffer))
-  ;; (if enwc-using-wired
-  ;;     (enwc-wired-disconnect)
-  ;;   (enwc-wireless-disconnect))
 
 (defun enwc-toggle-wired ()
   "Toggle the display and mode between wireless and wired.
 This function also sets the variable `enwc-using-wired'."
   (interactive)
-  (if (not (eq major-mode 'enwc-mode))
-      (enwc-setup-buffer))
+  (unless (eq major-mode 'enwc-mode)
+    (enwc-setup-buffer))
   (let ((inhibit-read-only t))
     (erase-buffer)
     (setq enwc-using-wired (not enwc-using-wired))
@@ -869,188 +725,297 @@ In order to use this, one must have already run
   "View the text of the entry at point.
 This is mostly useful to view the text of the hidden entries."
   (interactive)
-  (if (not (get-buffer "*ENWC Edit*"))
-      (error "Not editing a network entry."))
-  (if (not (eq (current-buffer) (get-buffer "*ENWC Edit*")))
-      (switch-to-buffer "*ENWC Edit*"))
-  (if (not (widget-at))
-      (error "No widget at point"))
+  (unless (get-buffer "*ENWC Edit*")
+    (error "Not editing a network entry."))
+  (unless (eq (current-buffer) (get-buffer "*ENWC Edit*"))
+    (switch-to-buffer "*ENWC Edit*"))
+  (unless (widget-at)
+    (error "No widget at point"))
   (message (widget-field-value-get (widget-at))))
 
-(defun enwc-display-sec-reqs (widget &rest stuff)
-  "Display the security requirements.
-This is a callback to the security selection widget.
-WIDGET is always the menu drop-down of security types."
-  (let (reqs
-       (inhibit-read-only t)
-       type-wid-list)
-    ;; First, erase any of the old ones.
-    (goto-char (1+ (widget-get widget :to)))
-    (widget-forward 1)
-    (while (>= (point) (widget-get widget :to))
-      (widget-delete (widget-at))
-      (widget-forward 1))
-    (goto-char (point-max))
-    ;; Then check to see if widget-value is None
-    (if (string= (widget-value widget) "None")
-       nil
-      (setq type-wid-list
-           (cadr (assoc "reqs"
-                        (cdr (assoc (widget-value widget)
-                                    (enwc-get-sec-types enwc-using-wired))))))
-      (setq reqs
-           (mapcar (lambda (x)
-                     (if (not (eq (length (cdr x)) 0))
-                         (widget-create 'editable-field
-                                        :format (concat "  "
-                                                        (cdr x)
-                                                        ": %v")
-                                        :secret ?*
-                                        :keymap 'enwc-edit-field-map
-                                        ;; :value (or (enwc-get-nw-prop 
enwc-using-wired
-                                        ;;                           
enwc-edit-id
-                                        ;;                           (car x))
-                                        ;;            "")
-                                         )))
-                   type-wid-list))
-      (widget-setup)
-      reqs)))
+(define-widget 'enwc-profile-props-widget 'group
+  "ENWC edit widget."
+  :convert-widget 'identity
+  :format "IPv4 Settings:\n %v"
+  :value-to-internal 'enwc-profile-props-to-widget
+  :value-to-external 'enwc-widget-to-profile-props
+  :match #'(lambda nil t)
+  :args '((string :tag "Address")
+          (string :tag "Netmask")
+          (string :tag "Gateway")
+          (string :tag "DNS1")
+          (string :tag "DNS2")))
+
+(defun enwc-profile-props-to-widget (widget props)
+  "Create a profile props widget."
+  (list
+   (alist-get 'addr props "")
+   (alist-get 'netmask props "")
+   (alist-get 'gateway props "")
+   (alist-get 'dns1 props "")
+   (alist-get 'dns2 props "")))
+
+(defun enwc-widget-to-profile-props (widget vals)
+  (let ((addr (nth 0 vals))
+        (netmask (nth 1 vals))
+        (gateway (nth 2 vals))
+        (dns1 (nth 3 vals))
+        (dns2 (nth 4 vals)))
+    `((addr . ,addr)
+      (netmask . ,netmask)
+      (gateway . ,gateway)
+      (dns1 . ,dns1)
+      (dns2 . ,dns2))))
+
+;;;;;;;;;;;;;;
+;; Security ;;
+;;;;;;;;;;;;;;
+
+(defmacro enwc--make-supplicant-multi (key &rest args)
+  `(cons (quote ,key)
+         (quote (checklist :tag ,(capitalize (enwc--sym-to-str key))
+                           :format "%{%t%}: %v"
+                           :sample-face bold
+                           :args ,(mapcar
+                                   (lambda (arg)
+                                     `(item :tag ,arg :value ,(downcase arg)))
+                                   args)))))
+
+(defmacro enwc--make-supplicant-choice (key &rest args)
+  `(cons (quote ,key)
+         (quote (menu-choice :tag ,(capitalize (enwc--sym-to-str key))
+                             :format "%{%t%}: %v"
+                             :sample-face bold
+                             ,@(mapcar
+                                (lambda (arg)
+                                  `(item :tag ,(downcase arg) :value ,arg))
+                                args)))))
+
+(defmacro enwc--make-supplicant-secret (key)
+  `(cons (quote ,key)
+         (quote (editable-field :tag ,(capitalize (enwc--sym-to-str key))
+                                :format "%{%t%}: %v"
+                                :sample-face bold
+                                :keymap enwc-edit-field-map
+                                :secret ?*))))
+
+(defmacro enwc--make-supplicant-entry (key)
+  `(cons (quote ,key)
+         (quote (editable-field :tag ,(capitalize (enwc--sym-to-str key))
+                                :sample-face bold
+                                :format "%{%t%}: %v"))))
+
+(defmacro enwc--make-supplicant-file (key)
+  `(cons (quote ,key)
+         (quote (file :tag ,(capitalize (enwc--sym-to-str key))
+                      :format "%{%t%}: %v"
+                      :sample-face bold
+                      :must-match t))))
+
+(defmacro enwc--make-supplicant-list (key &rest args)
+  `(cons (quote ,key)
+         (quote (list :tag ,(capitalize (enwc--sym-to-str key))
+                      :format "%{%t%}: %v"
+                      :sample-face bold
+                      ,@(mapcar 'cdr args)))))
+
+(defconst enwc-supplicant-alist
+  (list
+   (enwc--make-supplicant-multi proto "WPA" "RSN")
+   (enwc--make-supplicant-multi key-mgmt "None" "WPA-PSK" "WPA-EAP" 
"IEEE8021X")
+   (enwc--make-supplicant-choice auth-alg "OPEN" "SHARED" "LEAP")
+   (enwc--make-supplicant-multi pairwise "CCMP" "TKIP" "NONE")
+   (enwc--make-supplicant-multi group "CCMP" "TKIP" "WEP104" "WEP40")
+   (enwc--make-supplicant-secret psk)
+   (enwc--make-supplicant-secret wep-key0)
+   (enwc--make-supplicant-secret wep-key1)
+   (enwc--make-supplicant-secret wep-key2)
+   (enwc--make-supplicant-secret wep-key3)
+   (enwc--make-supplicant-choice wep-tx-keyidx "0" "1" "2" "3")
+   (enwc--make-supplicant-choice eap "TLS" "PEAP" "TTLS" "LEAP" "FAST")
+   (enwc--make-supplicant-entry identity)
+   (enwc--make-supplicant-entry anonymous-identity)
+   (enwc--make-supplicant-secret password)
+   (enwc--make-supplicant-file ca-cert)
+   (enwc--make-supplicant-file client-cert)
+   (enwc--make-supplicant-file private-key)
+   (enwc--make-supplicant-secret private-key-passwd)
+   (enwc--make-supplicant-file pac-file)
+   (enwc--make-supplicant-list phase1
+                               (enwc--make-supplicant-choice peapver "0" "1")
+                               (enwc--make-supplicant-choice peaplabel "0" "1")
+                               (enwc--make-supplicant-choice fast-provisioning 
"0" "1" "2" "3"))
+   (enwc--make-supplicant-list phase2
+                               (enwc--make-supplicant-choice auth "MD5" 
"MSCHAPV2" "OTP" "GTC" "TLS")
+                               (enwc--make-supplicant-choice autheap "MD5" 
"MSCHAPV2" "OTP" "GTC" "TLS")
+                               (enwc--make-supplicant-file ca-cert)
+                               (enwc--make-supplicant-file client-cert)
+                               (enwc--make-supplicant-file private-key)
+                               (enwc--make-supplicant-secret 
private-key-passwd)))
+  "An alist that maps supplicant entries to a widget type.
+
+For more information, see the documentation for wpa_supplicant.")
+
+(defcustom enwc-supplicant-template-alist
+  `((wep . ((key-mgmt . ("none"))
+            (wep-key0 . req)
+            (wep-tx-keyidx . "0")))
+    (wpa2 . ((proto . ("wpa" "rsn"))
+             (key-mgmt . "wpa-psk")
+             (pairwise . ("ccmp" "tkip"))
+             (group . ("ccmp" "tkip"))
+             (psk . req)))
+    (leap . ((eap . "leap")
+             (key-mgmt . ("ieee8021x"))
+             (auth-alg . "leap")
+             (identity . req)
+             (password . req)))
+    (eap-fast . ((proto . ("rsn" "wpa"))
+                 (pairwise . ("ccmp" "tkip"))
+                 (group . ("ccmp" "tkip"))
+                 (key-mgmt . ("wpa-eap"))
+                 (eap . "fast")
+                 (identity . req)
+                 (password . req)
+                 (phase1 . ((fast-provisioning . "1")))
+                 (pac-file . opt)))
+    (eap-tls . ((key-mgmt . ("wpa-eap"))
+                (pairwise . ("tkip"))
+                (group . ("tkip"))
+                (eap . "tls")
+                (identity . req)
+                (ca-cert . opt)
+                (client-cert . opt)
+                (private-key . req)
+                (private-key-passwd . req)))
+    (peap . ((proto . ("rsn"))
+             (key-mgmt . ("wpa-eap"))
+             (pairwise . ("ccmp"))
+             (eap . "peap")
+             (identity . req)
+             (password . req)))
+    (peap-tkip . ((proto . ("wpa"))
+                  (key-mgmt . ("wpa-eap"))
+                  (pairwise . ("tkip"))
+                  (group . ("tkip"))
+                  (eap . "peap")
+                  (identity . req)
+                  (password . req)
+                  (ca-cert . opt)
+                  (phase1 . ((peaplabel . "0")))
+                  (phase2 . ((auth . "mschapv2"))))))
+  "The alist of templates for security.
+This should be an alist of the form (KEY . ((SUPPLICANT-KEY . INITIAL-INPUT) 
...))
+Each SUPPLICANT-KEY should be a key from `enwc-supplicant-alist', and 
INITIAL-INPUT
+should be an acceptable value for SUPPLICANT-KEY.
+
+If INITIAL-INPUT is the symbol req, then this option is required.
+The value opt means that the option is optional."
+  :group 'enwc
+  :type '(alist :key-type symbol :value-type (alist :key-type symbol)))
+
+(defun enwc--get-supplicant-entry (ent &optional sec-info)
+  "Create a widget definition from ENT.
+
+If optional parameter SEC-INFO is non-nil, then use it
+for security information."
+  (let ((init (cdr ent))
+        (wid (assq (car ent) enwc-supplicant-alist))
+        fin)
+    (unless wid
+      (error "Unknown supplicant type %s" (car ent)))
+    ;; Set the initial value for the widget.
+    (cons (cadr wid)
+          (append (pcase init
+                  (`req `(:required t :value ,(alist-get (car ent) sec-info 
"")))
+                  (`opt `(:value ,(alist-get (car ent) sec-info "")))
+                  (_ `(:value ,init)))
+                (cddr wid)))))
+
+(defun enwc-create-template-menu (&optional sec-info)
+  "Create the widget declaration for the menu of templates.
+
+If specified, SEC-INFO is passed to the templates to initialize them."
+  `(menu-choice
+    :tag "Security"
+    ,@(mapcar
+       (lambda (tm)
+         `(list
+           :tag ,(symbol-name (car tm))
+           :menu-tag ,(symbol-name (car tm))
+           ,@(mapcar
+              (lambda (ent)
+                (enwc--get-supplicant-entry ent sec-info))
+              (cdr tm))))
+       enwc-supplicant-template-alist)))
+
+(defun enwc-display-sec-widget (&optional sec-info)
+  "Create the menu of security templates.
+If specified, SEC-INFO is passed to the templates to initialize them."
+  (widget-create (enwc-create-template-menu sec-info)))
+
+(defun enwc-sec-widget-data (widget)
+  "Get the data from a securirty widget WIDGET."
+  (let* ((type (widget-get (widget-get widget :choice) :tag))
+         (values (widget-value widget))
+         (template (assq (intern type) enwc-supplicant-template-alist)))
+    (unless template
+      (error "Unrecognized security template."))
+    (setq template (cdr template))
+    (cons
+     `(sec-type ,(intern type))
+     (mapcar
+      (lambda (val)
+        (cons (car val) (pop values)))
+      template))))
+
+(defvar enwc-network-edit-widget nil
+  "The network information widget used in the edit buffer.")
+
+(defvar enwc-security-edit-widget nil
+  "The security widget used in the edit buffer.")
 
 (defun enwc-setup-edit-buffer ()
   "Setup the edit buffer.  This removes the old one if neccessary,
 and redisplays the settings from the network profile
  with id `enwc-edit-id', which is set in `enwc-edit-entry-at-point'."
-  (if (get-buffer "*ENWC Edit*")
-      (kill-buffer "*ENWC Edit*"))
+  (when (get-buffer "*ENWC Edit*")
+    (kill-buffer "*ENWC Edit*"))
   (with-current-buffer (get-buffer-create "*ENWC Edit*")
-    (let ((sec-types (enwc-get-sec-types enwc-using-wired))
-         (nw-info (enwc-get-profile-info enwc-edit-id))
-         ip-addr netmask gateway dns-1 dns-2
-         addr-wid net-wid gate-wid
-         dns-1-wid dns-2-wid dns-list
-         type-wid type-wid-list)
+    (let ((nw-info (enwc-get-profile-info enwc-edit-id)))
 
       (widget-insert (concat "Settings for access point "
-                            (cdr (assoc "essid"
-                                        (nth enwc-edit-id
-                                             enwc-last-scan)))
-                            "\n"))
-      (widget-insert "\n")
-      ;; ip
-      (widget-insert "IPv4 Settings:\n")
-      (setq addr-wid (widget-create 'editable-field
-                                   :format "  Address: %v"
-                                   :value (or (assoc "addr" nw-info) "")))
-      ;; netmask
-      (setq net-wid (widget-create 'editable-field
-                                  :format "  Netmask: %v"
-                                  :value (or (assoc "netmask" nw-info) "")))
-
-      ;; gateway
-      (setq gate-wid (widget-create 'editable-field
-                                   :format "  Gateway: %v"
-                                   :value (or (assoc "gateway" nw-info) "")))
-      ;; dns1
+                             (enwc-value-from-scan 'essid enwc-edit-id)
+                             "\n"))
       (widget-insert "\n")
-      ;;(setq dns-list (enwc-get-dns enwc-using-wired enwc-edit-id))
-      (setq dns-1-wid (widget-create 'editable-field
-                                    :format "    DNS 1: %v"
-                                    :value (or (assoc "dns1" nw-info) "")))
-
-      ;; dns2
-      (setq dns-2-wid (widget-create 'editable-field
-                                    :format "    DNS 2: %v"
-                                    :value (or (assoc "dns2" nw-info) "")))
+      (setq enwc-network-edit-widget
+            (widget-create 'enwc-profile-props-widget :value nw-info))
 
       (widget-insert "\n")
-      (widget-insert "Security:\n")
-      (setq type-wid (apply 'widget-create
-                           'menu-choice
-                                   :tag "Type "
-                           :value (or (assoc "enctype" nw-info) "None")
-                           :notify 'enwc-display-sec-reqs
-                                   '(item :tag "No Encryption"
-                                  :value "None")
-                           (mapcar (lambda (x)
-                                     `(item :format "%t\n"
-                                            :value ,(car x)
-                                            :tag ,(cdr (assoc "Name" (cdr 
x)))))
-                                           sec-types)))
-      (enwc-display-sec-reqs type-wid)
+      (setq enwc-security-edit-widget (enwc-display-sec-widget nw-info))
+
       (use-local-map enwc-edit-map)
       (widget-setup)))
 
   (switch-to-buffer "*ENWC Edit*"))
 
 (defun enwc-edit-save ()
-  "Save the network settings."
-  ;; Basically, just iterate through the widgets,
-  ;; retrieving values from each.
+  "Save the network settings from the edit buffer."
   (interactive)
-  (if (not (get-buffer "*ENWC Edit*"))
-      (error "Not editing a network entry."))
-  (if (not (eq (current-buffer) (get-buffer "*ENWC Edit*")))
-      (switch-to-buffer "*ENWC Edit*"))
-  (goto-char 0)
-  (let (settings start-pos type-wid-list)
-
-    (widget-forward 1)
-    (setq settings
-         (append settings
-                 (cons (cons "addr"
-                             (widget-field-value-get (widget-at)))
-                       nil)))
-    (widget-forward 1)
-    (setq settings
-         (append settings
-                 (cons (cons "netmask"
-                             (widget-field-value-get (widget-at)))
-                       nil)))
-    (widget-forward 1)
-    (setq settings
-         (append settings
-                 (cons (cons "gateway"
-                             (widget-field-value-get (widget-at)))
-                       nil)))
-    (widget-forward 1)
-    (setq settings
-         (append settings
-                 (cons (cons "dns1"
-                             (widget-field-value-get (widget-at)))
-                       nil)))
-    (widget-forward 1)
-    (setq settings
-         (append settings
-                 (cons (cons "dns2"
-                             (widget-field-value-get (widget-at)))
-                       nil)))
-    (widget-forward 1)
-    (setq settings
-         (append settings
-                 (cons (cons "enctype"
-                             (widget-value (widget-at)))
-                       nil)))
-    (setq start-pos (widget-get (widget-at) :to))
-    (if (not (string= (widget-value (widget-at)) "None"))
-       (setq type-wid-list
-             (cadr (assoc "reqs"
-                          (cdr (assoc (widget-value (widget-at))
-                                      (enwc-get-sec-types 
enwc-using-wired)))))))
-    (dolist (x type-wid-list)
-      (widget-forward 1)
-      (if (not (string= (widget-field-value-get (widget-at)) ""))
-         (setq settings
-               (append settings
-                       (cons (cons (car x)
-                                   (widget-field-value-get (widget-at)))
-                             nil)))))
-    ;;(print settings)
-    (enwc-save-nw-settings enwc-edit-id settings)))
+  (unless (get-buffer "*ENWC Edit*")
+    (error "Not editing a network entry"))
+  (unless (eq (current-buffer) (get-buffer "*ENWC Edit*"))
+    (switch-to-buffer "*ENWC Edit*"))
+
+  (enwc-save-nw-settings
+   enwc-edit-id
+   (append (widget-value enwc-network-edit-widget)
+           (enwc-sec-widget-data enwc-security-edit-widget))))
 
 (defun enwc-edit-entry-at-point ()
   "Edit the current network entry."
   (interactive)
-  (setq enwc-edit-id (- (line-number-at-pos) 1))
+  (setq enwc-edit-id (tabulated-list-get-id))
   (select-window (split-window))
   (enwc-setup-edit-buffer))
 
@@ -1089,11 +1054,11 @@ and if it doesn't, then create it.
 
 If NOMOVE is non-nil, then do not move to the
 newly created buffer."
-  (if (not (get-buffer "*ENWC*"))
-      (with-current-buffer (get-buffer-create "*ENWC*")
-       (enwc-mode)))
-  (if (not nomove)
-      (switch-to-buffer "*ENWC*")))
+  (unless (get-buffer "*ENWC*")
+    (with-current-buffer (get-buffer-create "*ENWC*")
+      (enwc-mode)))
+  (unless nomove
+    (switch-to-buffer "*ENWC*")))
 
 (provide 'enwc)
 



reply via email to

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