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

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

[elpa] master 3491895 14/76: Cleaned up code and consolidated front-end


From: Ian Dunn
Subject: [elpa] master 3491895 14/76: Cleaned up code and consolidated front-end functions.
Date: Thu, 23 Feb 2017 19:42:45 -0500 (EST)

branch: master
commit 3491895bb73e257d5a6c985fadcfd77e9128700b
Author: Ian D <address@hidden>
Commit: Ian D <address@hidden>

    Cleaned up code and consolidated front-end functions.
---
 lisp/enwc-nm.el    |  59 ++++++++---
 lisp/enwc-setup.el | 130 ++++++++++++-----------
 lisp/enwc-wicd.el  | 114 ++++++++++++++++-----
 lisp/enwc.el       | 295 +++++++++++++++++++++++++++++------------------------
 4 files changed, 355 insertions(+), 243 deletions(-)

diff --git a/lisp/enwc-nm.el b/lisp/enwc-nm.el
index 32a9245..15f93dd 100644
--- a/lisp/enwc-nm.el
+++ b/lisp/enwc-nm.el
@@ -238,7 +238,10 @@ ID is the identifier used by Network Manager."
   (let ((uuid (enwc-nm-get-uuid-by-id id)))
     (enwc-nm-get-conn-by-uuid uuid)))
 
-;; Wireless
+;;;;;;;;;
+;; Scan
+;;;;;;;;;
+
 (defun enwc-nm-scan ()
   "The NetworkManager scan function."
   (dbus-call-method :system
@@ -249,8 +252,16 @@ ID is the identifier used by Network Manager."
                    :timeout 25000
                    '(:array :signature "{sv}")))
 
-;; Wireless
-(defun enwc-nm-get-networks ()
+;;;;;;;;;;;;;;;;;
+;; Get networks
+;;;;;;;;;;;;;;;;;
+
+(defun enwc-nm-get-networks (&optional wired)
+  (if wired
+      (enwc-nm-get-wired-profiles)
+    (enwc-nm-get-wireless-networks)))
+
+(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
@@ -259,6 +270,18 @@ This returns a list of D-Bus paths to the access points."
                    enwc-nm-dbus-wireless-interface
                    "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)))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Get network properties
+;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
 ;; Accesspoint
 (defun enwc-nm-get-wireless-network-property (id prop)
   "The NetworkManager get wireless network property function.
@@ -361,9 +384,14 @@ If both are 0, then it returns WEP, otherwise WPA."
       "WPA")))
 
 ;; Default
-(defun enwc-nm-connect (id)
+(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)))
+
+(defun enwc-nm-wireless-connect (id)
   (let ((ssid (enwc-nm-get-wireless-network-property id "Ssid")))
     (dbus-call-method :system
                      enwc-nm-dbus-service
@@ -417,13 +445,7 @@ This simply checks for the active access point."
                    "Disconnect"))
 
 ;; Settings, Connections
-(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)))
+
 
 (defun enwc-nm-wired-connect (id)
   (let ((nid (nth id enwc-access-points)))
@@ -552,7 +574,7 @@ PREFIX is an integer <= 32."
     (setq pf (1- pf)))
   netmask))
 
-(defun enwc-nm-get-nw-info (wired id)
+(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
@@ -578,11 +600,14 @@ PREFIX is an integer <= 32."
                dns-list (mapcar 'enwc-nm-convert-addr
                                 dns-list))
          (setq nw-info (list (cons (cons "addr"
-                                         ip-addr) nil)
+                                         ip-addr)
+                                    nil)
                              (cons (cons "netmask"
-                                         netmask) nil)
+                                         netmask)
+                                    nil)
                              (cons (cons "gateway"
-                                         gateway) nil)
+                                         gateway)
+                                    nil)
                              (cons (cons "dns1"
                                          (nth 0
                                               dns-list))
@@ -592,8 +617,8 @@ PREFIX is an integer <= 32."
                                               dns-list))
                                    nil)
                              (cons (cons "enctype"
-                                         "None") nil)
-                             )))
+                                         "None")
+                                    nil))))
       nil)))
 
 (defun enwc-nm-get-ip-addr (wired id)
diff --git a/lisp/enwc-setup.el b/lisp/enwc-setup.el
index 52f0a64..4e060ff 100644
--- a/lisp/enwc-setup.el
+++ b/lisp/enwc-setup.el
@@ -31,62 +31,68 @@
   "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-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-nw-info-func (intern (concat "enwc-"
-                                               sym-name
-                                               "-get-nw-info"))
-         enwc-save-nw-settings-func (intern (concat "enwc-"
-                                                    sym-name
-                                                    "-save-nw-settings")))
+                                         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")))))
 
 (defun enwc-setup ()
@@ -101,16 +107,16 @@ on D-Bus."
             (run-at-time t enwc-auto-scan-interval 'enwc-scan t)))
 
   (let ((cur-back nil)
-       (back-list enwc-backends))
+        (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)))
+                          (symbol-value (intern (concat "enwc-"
+                                                        (symbol-name cur-back)
+                                                        "-dbus-service")))))
+          (setq cur-back nil)))
     (if cur-back
-       (enwc-setup-backend cur-back)
+        (enwc-setup-backend cur-back)
       (error "No usable backend found."))))
 
 (provide 'enwc-setup)
diff --git a/lisp/enwc-wicd.el b/lisp/enwc-wicd.el
index 377987b..718d29a 100644
--- a/lisp/enwc-wicd.el
+++ b/lisp/enwc-wicd.el
@@ -88,14 +88,35 @@ the wicd wired interface."
         :timeout 25000
         args))
 
+;;;;;;;;;
+;; Scan
+;;;;;;;;;
+
 (defun enwc-wicd-scan ()
   "Wicd scan function."
   (enwc-wicd-dbus-wireless-call-method "Scan"))
 
-(defun enwc-wicd-get-networks ()
+;;;;;;;;;;;;;;;;;
+;; Get networks
+;;;;;;;;;;;;;;;;;
+
+(defun enwc-wicd-get-networks (&optional wired)
+  (if wired
+      (enwc-wicd-get-wired-profiles)
+    (enwc-wicd-get-wireless-networks)))
+
+(defun enwc-wicd-get-wireless-networks ()
   "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
+;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
 (defvar enwc-wicd-prop-values nil)
 (defvar enwc-wicd-prop-num 0)
 (defvar enwc-wicd-prop-timeout 3)
@@ -178,12 +199,56 @@ property from wireless network with id ID."
   (enwc-wicd-dbus-wireless-call-method "GetWirelessProperty"
                                       id "encryption_method"))
 
-(defun enwc-wicd-connect (id)
+(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
+;;;;;;;;;;;;;;;;;;;;;
+
+(defun enwc-wicd-connect (id &optional wired)
   "Wicd connect function.
-This calls the D-Bus method on Wicd to connect to wireless
-network with id ID."
+This calls the D-Bus method on Wicd to connect to a
+wired or wireless network with id ID."
+  (if wired
+      (enwc-wicd-wired-connect id)
+    (enwc-wicd-dbus-wireless-call-method "ConnectWireless" id)))
+
+(defun enwc-wicd-wireless-connect (id)
+  "Wicd connect function.
+This calls the D-Bus method on Wicd to connect to a
+wireless network with id ID."
   (enwc-wicd-dbus-wireless-call-method "ConnectWireless" 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)))
+    (enwc-wicd-dbus-wired-call-method "ReadWiredNetworkProfile" prf)
+    (enwc-wicd-dbus-wired-call-method "ConnectWired")))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Disconnect functions.
+;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defun enwc-wicd-disconnect (&optional wired)
+  (if wired
+      (enwc-wicd-wired-disconnect)
+    (enwc-wicd-wireless-disconnect)))
+
+(defun enwc-wicd-wireless-disconnect ()
+  "Wicd disconnect function."
+  (enwc-wicd-dbus-wireless-call-method "DisconnectWireless"))
+
+(defun enwc-wicd-wired-disconnect ()
+  "Disconnects from the wired connection."
+  (enwc-wicd-dbus-wired-call-method "DisconnectWired"))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Get current network id
+;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
 (defun enwc-wicd-get-current-nw-id (wired)
   "Wicd get current network id function.
 The current network id is updated upon connect,
@@ -193,37 +258,22 @@ so this jut returns the tracked network id."
     (enwc-wicd-dbus-wireless-call-method "GetCurrentNetworkID")))
     ;;enwc-wicd-current-nw-id))
 
+;;;;;;;;;;;;;;;;;;;;
+;; Check Connecting
+;;;;;;;;;;;;;;;;;;;;
+
 (defun enwc-wicd-check-connecting ()
   "The Wicd check connecting function."
   (enwc-wicd-dbus-wireless-call-method "CheckIfWirelessConnecting"))
 
-(defun enwc-wicd-disconnect ()
-  "Wicd disconnect function."
-  (enwc-wicd-dbus-wireless-call-method "DisconnectWireless"))
-
-(defun enwc-wicd-get-wired-profiles ()
-  "Gets the list of wired network profiles."
-  (enwc-wicd-dbus-wired-call-method "GetWiredProfileList"))
-
-(defun enwc-wicd-wired-connect (id)
-  "Connects to the wired network with profile id ID."
-  (let* ((profs (enwc-get-wired-profiles))
-        (prf (nth id profs)))
-    (enwc-wicd-dbus-wired-call-method "ReadWiredNetworkProfile" prf)
-    (enwc-wicd-dbus-wired-call-method "ConnectWired")))
-
-(defun enwc-wicd-wired-disconnect ()
-  "Disconnects from the wired connection."
-  (enwc-wicd-dbus-wired-call-method "DisconnectWired"))
+;;;;;;;;;;;;;
+;; Is Wired
+;;;;;;;;;;;;;
 
 (defun enwc-wicd-is-wired ()
   "Checks to see if wired is connected."
   (not (not (enwc-wicd-dbus-wired-call-method "GetWiredIP"))))
 
-(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))
-
 ;; Each entry in sec-types should be:
 ;; ("IDENT" (("Name" . "NAME") ("reqs" . (("key1" . "Entry1") ("key2" . 
"Entry2") ... ))))
 ;; Where:
@@ -234,6 +284,10 @@ so this jut returns the tracked network id."
 ;;  "keyXX" => String that the backend uses for this security entry.
 ;;  "EntryXX" => String that ENWC displays for this security entry.
 
+;;;;;;;;;;;;;;;;;;;;;
+;; Get Profile Info
+;;;;;;;;;;;;;;;;;;;;;
+
 (defun enwc-wicd-get-sec-types (wired)
   "Gets the list of security types.
 WIRED indicates whether this is a wired connection.
@@ -277,7 +331,7 @@ functions, allowing for a single function that checks for 
wired."
       (enwc-wicd-get-wired-nw-prop id ent)
     (enwc-wicd-dbus-wireless-call-method "GetWirelessProperty" id ent)))
 
-(defun enwc-wicd-get-nw-info (wired id)
+(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)
@@ -307,6 +361,10 @@ WIRED is set to indicate whether this is a wired network."
        (or (enwc-wicd-get-profile-ent wired id "dns2") "")
        (or (enwc-wicd-get-profile-ent wired id "dns3") "")))
 
+;;;;;;;;;;;;;;;;;;;;;;;;
+;; Save Network Settings
+;;;;;;;;;;;;;;;;;;;;;;;;
+
 (defun enwc-wicd-set-nw-prop (wired id prop val)
   "Sets the network property PROP of the network with id ID
 to VAL.
@@ -324,7 +382,7 @@ WIRED indicates whether this is a wired network."
       (enwc-wicd-dbus-wired-call-method "SaveWiredNetworkProfile" id)
     (enwc-wicd-dbus-wireless-call-method "SaveWirelessNetworkProfile" id)))
 
-(defun enwc-wicd-save-nw-settings (wired id settings)
+(defun enwc-wicd-save-nw-settings (id settings &optional wired)
   "Saves the settings indicated by the association list SETTINGS for
 the network with id ID."
   (let ((enctype (cdr (assoc "enctype" settings))))
diff --git a/lisp/enwc.el b/lisp/enwc.el
index 8787021..ec187c3 100644
--- a/lisp/enwc.el
+++ b/lisp/enwc.el
@@ -118,22 +118,28 @@ This variable is set during setup.")
 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-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-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.")
 
-(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-disconnect-func nil
+  "The function variable for the disconnect function.")
 
 (defvar enwc-get-current-nw-id-func nil
   "The function variable to be used in `enwc-get-current-nw-id'.
@@ -150,57 +156,59 @@ check whether or not ENWC is connecting.")
 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-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-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-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-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-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-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-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-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-nw-info-func nil)
+(defvar enwc-get-profile-info-func nil)
+
+;;(defvar enwc-get-profile-info-func nil)
 
 (defvar enwc-save-nw-settings-func nil
   "The function variable to be used in `enwc-save-nw-settings'.
@@ -317,40 +325,46 @@ 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-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))
 
-(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-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))
+;; (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-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-wireless-disconnect ()
-  "Disconnects the wireless."
-  (funcall enwc-wireless-disconnect-func))
+(defun enwc-disconnect ()
+  (funcall enwc-disconnect-func enwc-using-wired))
 
-(defun enwc-wired-connect (id)
-  "Connects to the wired profile with id ID."
-  (funcall enwc-wired-connect-func id))
+;; (defun enwc-wireless-disconnect ()
+;;   "Disconnects the wireless."
+;;   (funcall enwc-wireless-disconnect-func))
 
-(defun enwc-wired-disconnect ()
-  "Disconnects from the current network."
-  (funcall enwc-wired-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))
 
 (defun enwc-is-wired-p ()
   "Checks whether or not ENWC is connected to
@@ -365,54 +379,54 @@ 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-nw-info (wired id)
-  (funcall enwc-get-nw-info-func wired id))
-
-(defun enwc-save-nw-settings (wired id settings)
+;; (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)
+  (funcall enwc-get-profile-info-func id 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."
-  (funcall enwc-save-nw-settings-func wired id settings))
+  (funcall enwc-save-nw-settings-func id settings enwc-using-wired))
 
 ;;;;;;;;;;;;;;;;;;;;;
 ;; Actual Functions
@@ -426,9 +440,10 @@ a wired network."
   "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)))
+  ;; (if wired
+  ;;     (enwc-get-wired-nw-prop id prop)
+  ;;   (enwc-get-wireless-nw-prop id prop))
+  )
 
 (defun enwc-format-mode-line-string ()
   "Formats the mode line string.
@@ -588,15 +603,14 @@ the scan results."
                    (number-sequence 0 (1- (length enwc-access-points))))))
     (setq enwc-essid-width (1+ enwc-essid-width))
     (setq enwc-scan-done t)
-    ;;(if enwc-scan-interactive
-    (enwc-display-wireless-networks enwc-last-scan);;)
+    (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-wired-profiles))
+  (let ((profs (enwc-get-nw))
        cur-prof fin-profs)
     (while profs
       (setq cur-prof (pop profs))
@@ -758,14 +772,20 @@ Otherwise, it actually returns it."
 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
-       (progn
-         (enwc-wired-connect id)
-         (setq cur-net (nth id (enwc-get-wired-profiles))))
-      (enwc-wireless-connect id)
+        (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)))
+          (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)
 
 (defun enwc-connect-to-network (net-id)
   "Connects the the network with network id NET-ID.
@@ -798,14 +818,16 @@ Moves to the enwc buffer if necessary."
   (let ((id (- (line-number-at-pos) 1)))
     (enwc-connect-to-network id)))
 
-(defun enwc-disconnect ()
+(defun enwc-disconnect-network ()
   "Disconnects from the network, if any."
   (interactive)
-  (if (not (eq major-mode 'enwc-mode))
-      (enwc-setup-buffer))
-  (if enwc-using-wired
-      (enwc-wired-disconnect)
-    (enwc-wireless-disconnect)))
+  (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.
@@ -885,10 +907,11 @@ WIDGET is always the menu drop-down of security types."
                                                         ": %v")
                                         :secret ?*
                                         :keymap 'enwc-edit-field-map
-                                        :value (or (enwc-get-nw-prop 
enwc-using-wired
-                                                                     
enwc-edit-id
-                                                                     (car x))
-                                                   ""))))
+                                        ;; :value (or (enwc-get-nw-prop 
enwc-using-wired
+                                        ;;                           
enwc-edit-id
+                                        ;;                           (car x))
+                                        ;;            "")
+                                         )))
                    type-wid-list))
       (widget-setup)
       reqs)))
@@ -901,7 +924,7 @@ and redisplays the settings from the network profile
       (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-nw-info enwc-using-wired enwc-edit-id))
+         (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
@@ -1022,7 +1045,7 @@ and redisplays the settings from the network profile
                                    (widget-field-value-get (widget-at)))
                              nil)))))
     ;;(print settings)
-    (enwc-save-nw-settings enwc-using-wired enwc-edit-id settings)))
+    (enwc-save-nw-settings enwc-edit-id settings)))
 
 (defun enwc-edit-entry-at-point ()
   "Edit the current network entry."
@@ -1035,7 +1058,7 @@ and redisplays the settings from the network profile
   (let ((map (make-sparse-keymap)))
     (define-key map (kbd "R") 'enwc-scan)
     (define-key map (kbd "C") 'enwc-connect-to-network-essid)
-    (define-key map (kbd "D") 'enwc-disconnect)
+    (define-key map (kbd "D") 'enwc-disconnect-network)
     (define-key map (kbd "W") 'enwc-toggle-wired)
     (define-key map (kbd "E") 'enwc-edit-entry-at-point)
     (define-key map (kbd "RET") 'enwc-connect-to-network-at-point)



reply via email to

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