Don't spam the user about new AP's if we're connected already.
authorRoy Marples <roy@marples.name>
Mon, 6 Nov 2017 13:45:47 +0000 (13:45 +0000)
committerRoy Marples <roy@marples.name>
Mon, 6 Nov 2017 13:45:47 +0000 (13:45 +0000)
src/dhcpcd-gtk/main.c
src/dhcpcd-qt/dhcpcd-qt.cpp

index 00e18d8368b518e084e879ade3b226d2b6f76f10..6444bf8ffefbdd665043faffa8cb32185bd5a4e4 100644 (file)
@@ -584,9 +584,8 @@ dhcpcd_wpa_scan_cb(DHCPCD_WPA *wpa, _unused void *data)
        DHCPCD_IF *i;
        WI_SCAN *w;
        DHCPCD_WI_SCAN *scans, *s1, *s2;
-       char *txt, *t;
-       int lerrno, fd;
        const char *msg;
+       int lerrno, fd;
 
        /* This could be a new WPA so watch it */
        fd = dhcpcd_wpa_get_fd(wpa);
@@ -621,27 +620,31 @@ dhcpcd_wpa_scan_cb(DHCPCD_WPA *wpa, _unused void *data)
                TAILQ_INIT(&w->menus);
                TAILQ_INSERT_TAIL(&wi_scans, w, next);
        } else {
-               txt = NULL;
-               msg = N_("New Access Point");
-               for (s1 = scans; s1; s1 = s1->next) {
-                       for (s2 = w->scans; s2; s2 = s2->next)
-                               if (g_strcmp0(s1->ssid, s2->ssid) == 0)
-                                       break;
-                       if (s2 == NULL) {
-                               if (txt == NULL)
-                                       txt = g_strdup(s1->ssid);
-                               else {
-                                       msg = N_("New Access Points");
-                                       t = g_strconcat(txt, "\n",
-                                           s1->ssid, NULL);
-                                       g_free(txt);
-                                       txt = t;
+               if (!i->up) {
+                       char *txt, *t;
+
+                       txt = NULL;
+                       msg = N_("New Access Point");
+                       for (s1 = scans; s1; s1 = s1->next) {
+                               for (s2 = w->scans; s2; s2 = s2->next)
+                                       if (g_strcmp0(s1->ssid, s2->ssid) == 0)
+                                               break;
+                               if (s2 == NULL) {
+                                       if (txt == NULL)
+                                               txt = g_strdup(s1->ssid);
+                                       else {
+                                               msg = N_("New Access Points");
+                                               t = g_strconcat(txt, "\n",
+                                                               s1->ssid, NULL);
+                                               g_free(txt);
+                                               txt = t;
+                                       }
                                }
                        }
-               }
-               if (txt) {
-                       notify(msg, txt, "network-wireless");
-                       g_free(txt);
+                       if (txt) {
+                               notify(msg, txt, "network-wireless");
+                               g_free(txt);
+                       }
                }
                menu_update_scans(w, scans);
        }
index 98c2a050b35ec771a9d8e69113f87338966c668a..b7932a4cdd4eac5351227bc119a178952895dd73 100644 (file)
@@ -368,26 +368,33 @@ DhcpcdWi *DhcpcdQt::findWi(DHCPCD_WPA *wpa)
 
 void DhcpcdQt::processScans(DhcpcdWi *wi, DHCPCD_WI_SCAN *scans)
 {
-       DHCPCD_WI_SCAN *s1, *s2;
+       DHCPCD_IF *i;
 
-       QString title = tr("New Access Point");
-       QString txt;
-       for (s1 = scans; s1; s1 = s1->next) {
-               for (s2 = wi->getScans(); s2; s2 = s2->next) {
-                       if (strcmp(s1->ssid, s2->ssid) == 0)
-                               break;
-               }
-               if (s2 == NULL) {
-                       if (!txt.isEmpty()) {
-                               title = tr("New Access Points");
-                               txt += '\n';
+       /* Don't spam the user if we're already connected. */
+       i = dhcpcd_wpa_if(wi->getWpa());
+
+       if (!i->up) {
+               QString title = tr("New Access Point");
+               QString txt;
+               DHCPCD_WI_SCAN *s1, *s2;
+
+               for (s1 = scans; s1; s1 = s1->next) {
+                       for (s2 = wi->getScans(); s2; s2 = s2->next) {
+                               if (strcmp(s1->ssid, s2->ssid) == 0)
+                                       break;
+                       }
+                       if (s2 == NULL) {
+                               if (!txt.isEmpty()) {
+                                       title = tr("New Access Points");
+                                       txt += '\n';
+                               }
+                               txt += s1->ssid;
                        }
-                       txt += s1->ssid;
                }
+               if (!txt.isEmpty() &&
+                               (ssidMenu == NULL || !ssidMenu->isVisible()))
+                       notify(title, txt, "network-wireless");
        }
-       if (!txt.isEmpty() &&
-           (ssidMenu == NULL || !ssidMenu->isVisible()))
-               notify(title, txt, "network-wireless");
 
        if (wi->setScans(scans) && ssidMenu && ssidMenu->isVisible())
                ssidMenu->popup(ssidMenuPos);