Don't rebind all if found a SSID to rebind.
[dhcpcd-ui] / src / dhcpcd-gtk / main.c
index fb6575713126b3914fcce9c091e4d312b3ab521f..5b9d8abf8d1bff1d84b9fd9981273afe5117c4a3 100644 (file)
@@ -158,6 +158,7 @@ update_online(DHCPCD_CONNECTION *con, bool showif)
 
        if (online != ison || carrier != iscarrier) {
                online = ison;
 
        if (online != ison || carrier != iscarrier) {
                online = ison;
+               carrier = iscarrier;
                if (ani_timer != 0) {
                        g_source_remove(ani_timer);
                        ani_timer = 0;
                if (ani_timer != 0) {
                        g_source_remove(ani_timer);
                        ani_timer = 0;
@@ -319,7 +320,8 @@ dhcpcd_watch(int fd,
 }
 
 static void
 }
 
 static void
-dhcpcd_status_cb(DHCPCD_CONNECTION *con, const char *status, _unused void *data)
+dhcpcd_status_cb(DHCPCD_CONNECTION *con, const char *status,
+    _unused void *data)
 {
        static char *last = NULL;
        const char *msg;
 {
        static char *last = NULL;
        const char *msg;
@@ -335,10 +337,10 @@ dhcpcd_status_cb(DHCPCD_CONNECTION *con, const char *status, _unused void *data)
                        ani_timer = 0;
                        ani_counter = 0;
                }
                        ani_timer = 0;
                        ani_counter = 0;
                }
+               online = carrier = false;
                gtk_status_icon_set_from_icon_name(status_icon,
                    "network-offline");
                gtk_status_icon_set_tooltip_text(status_icon, msg);
                gtk_status_icon_set_from_icon_name(status_icon,
                    "network-offline");
                gtk_status_icon_set_tooltip_text(status_icon, msg);
-               notify(_("No network"), msg, "network-offline");
                dhcpcd_prefs_abort();
                while (wi_scans) {
                        w = wi_scans->next;
                dhcpcd_prefs_abort();
                while (wi_scans) {
                        w = wi_scans->next;
@@ -354,7 +356,7 @@ dhcpcd_status_cb(DHCPCD_CONNECTION *con, const char *status, _unused void *data)
                            dhcpcd_version(con));
                        refresh = true;
                } else
                            dhcpcd_version(con));
                        refresh = true;
                } else
-                       refresh = false;
+                       refresh = g_strcmp0(last, "opened") ? false : true;
                update_online(con, refresh);
        }
 
                update_online(con, refresh);
        }
 
@@ -387,19 +389,28 @@ dhcpcd_try_open(gpointer data)
        static int last_error;
 
        con = (DHCPCD_CONNECTION *)data;
        static int last_error;
 
        con = (DHCPCD_CONNECTION *)data;
-       fd = dhcpcd_open(con);
+       fd = dhcpcd_open(con, true);
        if (fd == -1) {
        if (fd == -1) {
-               if (errno != last_error)
+               if (errno == EACCES || errno == EPERM) {
+                       if ((fd = dhcpcd_open(con, false)) != -1)
+                               goto unprived;
+               }
+               if (errno != last_error) {
                        g_critical("dhcpcd_open: %s", strerror(errno));
                        g_critical("dhcpcd_open: %s", strerror(errno));
-               last_error = errno;
+                       last_error = errno;
+               }
                return TRUE;
        }
 
                return TRUE;
        }
 
+unprived:
        if (!dhcpcd_watch(fd, dhcpcd_cb, con)) {
                dhcpcd_close(con);
                return TRUE;
        }
 
        if (!dhcpcd_watch(fd, dhcpcd_cb, con)) {
                dhcpcd_close(con);
                return TRUE;
        }
 
+       /* Start listening to WPA events */
+       dhcpcd_wpa_start(con);
+
        return FALSE;
 }
 
        return FALSE;
 }
 
@@ -411,30 +422,30 @@ dhcpcd_if_cb(DHCPCD_IF *i, _unused void *data)
        const char *icon;
        bool new_msg;
 
        const char *icon;
        bool new_msg;
 
-       /* Update the tooltip with connection information */
-       con = dhcpcd_if_connection(i);
-       update_online(con, false);
-
        /* We should ignore renew and stop so we don't annoy the user */
        /* We should ignore renew and stop so we don't annoy the user */
-       if (g_strcmp0(i->reason, "RENEW") == 0 ||
-           g_strcmp0(i->reason, "STOP") == 0 ||
-           g_strcmp0(i->reason, "STOPPED") == 0)
-               return;
-
-       msg = dhcpcd_if_message(i, &new_msg);
-       if (msg) {
-               g_message("%s", msg);
-               if (new_msg) {
-                       if (i->up)
-                               icon = "network-transmit-receive";
-                       //else
-                       //      icon = "network-transmit";
-                       if (!i->up)
-                               icon = "network-offline";
-                       notify(_("Network event"), msg, icon);
+       if (g_strcmp0(i->reason, "RENEW") &&
+           g_strcmp0(i->reason, "STOP") &&
+           g_strcmp0(i->reason, "STOPPED"))
+       {
+               msg = dhcpcd_if_message(i, &new_msg);
+               if (msg) {
+                       g_message("%s", msg);
+                       if (new_msg) {
+                               if (i->up)
+                                       icon = "network-transmit-receive";
+                               //else
+                               //      icon = "network-transmit";
+                               if (!i->up)
+                                       icon = "network-offline";
+                               notify(_("Network event"), msg, icon);
+                       }
+                       g_free(msg);
                }
                }
-               g_free(msg);
        }
        }
+
+       /* Update the tooltip with connection information */
+       con = dhcpcd_if_connection(i);
+       update_online(con, false);
 }
 
 static gboolean
 }
 
 static gboolean
@@ -549,6 +560,7 @@ dhcpcd_wpa_scan_cb(DHCPCD_WPA *wpa, _unused void *data)
                        notify(msg, txt, "network-wireless");
                        g_free(txt);
                }
                        notify(msg, txt, "network-wireless");
                        g_free(txt);
                }
+               menu_update_scans(w->interface, scans);
                dhcpcd_wi_scans_free(w->scans);
        }
        w->scans = scans;
                dhcpcd_wi_scans_free(w->scans);
        }
        w->scans = scans;
@@ -584,6 +596,7 @@ main(int argc, char *argv[])
                g_critical("libdhcpcd: %s", strerror(errno));
                exit(EXIT_FAILURE);
        }
                g_critical("libdhcpcd: %s", strerror(errno));
                exit(EXIT_FAILURE);
        }
+       dhcpcd_set_progname(con, "dhcpcd-gtk");
        dhcpcd_set_status_callback(con, dhcpcd_status_cb, NULL);
        dhcpcd_set_if_callback(con, dhcpcd_if_cb, NULL);
        dhcpcd_wpa_set_scan_callback(con, dhcpcd_wpa_scan_cb, NULL);
        dhcpcd_set_status_callback(con, dhcpcd_status_cb, NULL);
        dhcpcd_set_if_callback(con, dhcpcd_if_cb, NULL);
        dhcpcd_wpa_set_scan_callback(con, dhcpcd_wpa_scan_cb, NULL);