Clear interface menu's sanely when the interface is removed.
authorRoy Marples <roy@marples.name>
Fri, 7 Nov 2014 13:29:32 +0000 (13:29 +0000)
committerRoy Marples <roy@marples.name>
Fri, 7 Nov 2014 13:29:32 +0000 (13:29 +0000)
Fixes [51358a3cbd] based on an initial patch by Simon Long.

src/dhcpcd-gtk/dhcpcd-gtk.h
src/dhcpcd-gtk/main.c
src/dhcpcd-gtk/menu.c

index 309c81401a6974e5ce5c65d3d0c14f20d6eb16b0..855bcf0dac92bc4407149cc0654ca6de42c0316f 100644 (file)
@@ -73,6 +73,7 @@ WI_SCAN * wi_scan_find(DHCPCD_WI_SCAN *);
 
 void menu_init(GtkStatusIcon *, DHCPCD_CONNECTION *);
 void menu_update_scans(WI_SCAN *, DHCPCD_WI_SCAN *);
 
 void menu_init(GtkStatusIcon *, DHCPCD_CONNECTION *);
 void menu_update_scans(WI_SCAN *, DHCPCD_WI_SCAN *);
+void menu_remove_if(WI_SCAN *);
 
 void notify_close(void);
 
 
 void notify_close(void);
 
index 249881f14257f54a7deb09ff0a6cb06375fd7f25..4120dbf08d1bbb09a21d0b4c1edc3276f05ce54a 100644 (file)
@@ -570,11 +570,21 @@ static void
 dhcpcd_wpa_status_cb(DHCPCD_WPA *wpa, const char *status, _unused void *data)
 {
        DHCPCD_IF *i;
 dhcpcd_wpa_status_cb(DHCPCD_WPA *wpa, const char *status, _unused void *data)
 {
        DHCPCD_IF *i;
+       WI_SCAN *w, *wn;
 
        i = dhcpcd_wpa_if(wpa);
        g_message("%s: WPA status %s", i->ifname, status);
 
        i = dhcpcd_wpa_if(wpa);
        g_message("%s: WPA status %s", i->ifname, status);
-       if (g_strcmp0(status, "down") == 0)
+       if (g_strcmp0(status, "down") == 0) {
                dhcpcd_unwatch(-1, wpa);
                dhcpcd_unwatch(-1, wpa);
+               TAILQ_FOREACH_SAFE(w, &wi_scans, next, wn) {
+                       if (w->interface == i) {
+                               TAILQ_REMOVE(&wi_scans, w, next);
+                               menu_remove_if(w);
+                               dhcpcd_wi_scans_free(w->scans);
+                               g_free(w);
+                       }
+               }
+       }
 }
 
 int
 }
 
 int
index 4cfbcb082f4d9819dd4b1b15ebb680ed69a4b520..9c3cb5a8c37280791fc2c6f86f67ada5732743cf 100644 (file)
@@ -216,7 +216,7 @@ menu_update_scans(WI_SCAN *wi, DHCPCD_WI_SCAN *scans)
        DHCPCD_WI_SCAN *s;
        bool found, update;
 
        DHCPCD_WI_SCAN *s;
        bool found, update;
 
-       if (menu == NULL) {
+       if (wi->ifmenu == NULL) {
                dhcpcd_wi_scans_free(wi->scans);
                wi->scans = scans;
                return;
                dhcpcd_wi_scans_free(wi->scans);
                wi->scans = scans;
                return;
@@ -266,6 +266,27 @@ menu_update_scans(WI_SCAN *wi, DHCPCD_WI_SCAN *scans)
                gtk_menu_reposition(GTK_MENU(wi->ifmenu));
 }
 
                gtk_menu_reposition(GTK_MENU(wi->ifmenu));
 }
 
+void
+menu_remove_if(WI_SCAN *wi)
+{
+       WI_MENU *wim;
+
+       if (wi->ifmenu == NULL)
+               return;
+
+       if (wi->ifmenu == menu)
+               menu = NULL;
+
+       gtk_widget_destroy(wi->ifmenu);
+       wi->ifmenu = NULL;
+       while ((wim = TAILQ_FIRST(&wi->menus))) {
+               TAILQ_REMOVE(&wi->menus, wim, next);
+               g_free(wim);
+       }
+
+       if (menu && gtk_widget_get_visible(menu))
+               gtk_menu_reposition(GTK_MENU(menu));
+}
 
 static GtkWidget *
 add_scans(WI_SCAN *wi)
 
 static GtkWidget *
 add_scans(WI_SCAN *wi)