Ensure the AP's stay in alphabetical order when new scans come in.
authorRoy Marples <roy@marples.name>
Fri, 21 Nov 2014 16:42:37 +0000 (16:42 +0000)
committerRoy Marples <roy@marples.name>
Fri, 21 Nov 2014 16:42:37 +0000 (16:42 +0000)
src/dhcpcd-gtk/menu.c
src/dhcpcd-qt/dhcpcd-wi.cpp
src/dhcpcd-qt/dhcpcd-wi.h
src/libdhcpcd/dhcpcd.h
src/libdhcpcd/wpa.c

index e68842181ca8cf828d560c4168633b6f6da30555..6924c24be9ec57de9e408e27bd92dd9f34f2a6ff 100644 (file)
@@ -154,7 +154,7 @@ update_item(WI_SCAN *wi, WI_MENU *m, DHCPCD_WI_SCAN *scan)
 }
 
 static WI_MENU *
 }
 
 static WI_MENU *
-create_menu(GtkWidget *m, WI_SCAN *wis, DHCPCD_WI_SCAN *scan)
+create_menu(WI_SCAN *wis, DHCPCD_WI_SCAN *scan)
 {
        WI_MENU *wim;
        GtkWidget *box, *sel;
 {
        WI_MENU *wim;
        GtkWidget *box, *sel;
@@ -205,7 +205,6 @@ create_menu(GtkWidget *m, WI_SCAN *wis, DHCPCD_WI_SCAN *scan)
        g_signal_connect(G_OBJECT(wim->menu), "activate",
            G_CALLBACK(ssid_hook), NULL);
        g_object_set_data(G_OBJECT(wim->menu), "dhcpcd_wi_scan", scan);
        g_signal_connect(G_OBJECT(wim->menu), "activate",
            G_CALLBACK(ssid_hook), NULL);
        g_object_set_data(G_OBJECT(wim->menu), "dhcpcd_wi_scan", scan);
-       gtk_menu_shell_append(GTK_MENU_SHELL(m), wim->menu);
 
        return wim;
 }
 
        return wim;
 }
@@ -216,6 +215,7 @@ menu_update_scans(WI_SCAN *wi, DHCPCD_WI_SCAN *scans)
        WI_MENU *wim, *win;
        DHCPCD_WI_SCAN *s;
        bool found;
        WI_MENU *wim, *win;
        DHCPCD_WI_SCAN *s;
        bool found;
+       int position;
 
        if (wi->ifmenu == NULL) {
                dhcpcd_wi_scans_free(wi->scans);
 
        if (wi->ifmenu == NULL) {
                dhcpcd_wi_scans_free(wi->scans);
@@ -242,6 +242,7 @@ menu_update_scans(WI_SCAN *wi, DHCPCD_WI_SCAN *scans)
 
        for (s = scans; s; s = s->next) {
                found = false;
 
        for (s = scans; s; s = s->next) {
                found = false;
+               position = 0;
                TAILQ_FOREACH(wim, &wi->menus, next) {
                        if (memcmp(wim->scan->bssid, s->bssid,
                            sizeof(s->bssid)) == 0)
                TAILQ_FOREACH(wim, &wi->menus, next) {
                        if (memcmp(wim->scan->bssid, s->bssid,
                            sizeof(s->bssid)) == 0)
@@ -249,10 +250,15 @@ menu_update_scans(WI_SCAN *wi, DHCPCD_WI_SCAN *scans)
                                found = true;
                                break;
                        }
                                found = true;
                                break;
                        }
+                       if (dhcpcd_wi_scan_compare(wim->scan, s) < 0)
+                               position++;
                }
                if (!found) {
                }
                if (!found) {
-                       wim = create_menu(wi->ifmenu, wi, s);
+                       wim = create_menu(wi, s);
+                       printf ("inserting %s\n", s->ssid);
                        TAILQ_INSERT_TAIL(&wi->menus, wim, next);
                        TAILQ_INSERT_TAIL(&wi->menus, wim, next);
+                       gtk_menu_shell_insert(GTK_MENU_SHELL(wi->ifmenu),
+                           wim->menu, position);
                        gtk_widget_show_all(wim->menu);
                }
        }
                        gtk_widget_show_all(wim->menu);
                }
        }
@@ -298,8 +304,9 @@ add_scans(WI_SCAN *wi)
 
        m = gtk_menu_new();
        for (wis = wi->scans; wis; wis = wis->next) {
 
        m = gtk_menu_new();
        for (wis = wi->scans; wis; wis = wis->next) {
-               wim = create_menu(m, wi, wis);
+               wim = create_menu(wi, wis);
                TAILQ_INSERT_TAIL(&wi->menus, wim, next);
                TAILQ_INSERT_TAIL(&wi->menus, wim, next);
+               gtk_menu_shell_append(GTK_MENU_SHELL(m), wim->menu);
        }
 
        return m;
        }
 
        return m;
index 21d5ca08fa988537300424252066b1c6bf9f7232..5bb0ac28ff044cae1774c06edc903d4aa9408d00 100644 (file)
@@ -92,10 +92,12 @@ bool DhcpcdWi::setScans(DHCPCD_WI_SCAN *scans)
                QList<DhcpcdSsidMenu*> lst;
                DHCPCD_WI_SCAN *scan;
 
                QList<DhcpcdSsidMenu*> lst;
                DHCPCD_WI_SCAN *scan;
 
-               lst = menu->findChildren<DhcpcdSsidMenu*>();
                for (scan = scans; scan; scan = scan->next) {
                        bool found = false;
                for (scan = scans; scan; scan = scan->next) {
                        bool found = false;
+                       int position = 0;
+                       QAction *before = NULL;
 
 
+                       lst = menu->findChildren<DhcpcdSsidMenu*>();
                        foreach(DhcpcdSsidMenu *sm, lst) {
                                DHCPCD_WI_SCAN *s = sm->getScan();
                                if (memcmp(scan->bssid, s->bssid,
                        foreach(DhcpcdSsidMenu *sm, lst) {
                                DHCPCD_WI_SCAN *s = sm->getScan();
                                if (memcmp(scan->bssid, s->bssid,
@@ -105,14 +107,17 @@ bool DhcpcdWi::setScans(DHCPCD_WI_SCAN *scans)
                                        found = true;
                                        break;
                                }
                                        found = true;
                                        break;
                                }
+                               if (dhcpcd_wi_scan_compare(scan, s) < 0)
+                                       before = sm;
                        }
 
                        if (!found) {
                        }
 
                        if (!found) {
-                               createMenuItem(menu, scan);
+                               createMenuItem(menu, scan, before);
                                changed++;
                        }
                }
 
                                changed++;
                        }
                }
 
+               lst = menu->findChildren<DhcpcdSsidMenu*>();
                foreach(DhcpcdSsidMenu *sm, lst) {
                        DHCPCD_WI_SCAN *s = sm->getScan();
                        for (scan = scans; scan; scan = scan->next) {
                foreach(DhcpcdSsidMenu *sm, lst) {
                        DHCPCD_WI_SCAN *s = sm->getScan();
                        for (scan = scans; scan; scan = scan->next) {
@@ -133,10 +138,11 @@ bool DhcpcdWi::setScans(DHCPCD_WI_SCAN *scans)
        return !(changed == 0);
 }
 
        return !(changed == 0);
 }
 
-void DhcpcdWi::createMenuItem(QMenu *menu, DHCPCD_WI_SCAN *scan)
+void DhcpcdWi::createMenuItem(QMenu *menu, DHCPCD_WI_SCAN *scan,
+    QAction *before)
 {
        DhcpcdSsidMenu *ssidMenu = new DhcpcdSsidMenu(menu, this, scan);
 {
        DhcpcdSsidMenu *ssidMenu = new DhcpcdSsidMenu(menu, this, scan);
-       menu->addAction(ssidMenu);
+       menu->insertAction(before, ssidMenu);
        connect(ssidMenu, SIGNAL(triggered(DHCPCD_WI_SCAN *)),
            this, SLOT(connectSsid(DHCPCD_WI_SCAN *)));
 }
        connect(ssidMenu, SIGNAL(triggered(DHCPCD_WI_SCAN *)),
            this, SLOT(connectSsid(DHCPCD_WI_SCAN *)));
 }
index fb52985a8837cf7a835c409264ee9f554cd205b6..88ce6de3fcd5dcaa633ba629815a05fc12530007 100644 (file)
@@ -27,6 +27,7 @@
 #ifndef DHCPCD_WI_H
 #define DHCPCD_WI_H
 
 #ifndef DHCPCD_WI_H
 #define DHCPCD_WI_H
 
+#include <QAction>
 #include <QObject>
 
 #include "dhcpcd.h"
 #include <QObject>
 
 #include "dhcpcd.h"
@@ -68,7 +69,8 @@ private:
        QTimer *retryOpenTimer;
 
        QMenu *menu;
        QTimer *retryOpenTimer;
 
        QMenu *menu;
-       void createMenuItem(QMenu *menu, DHCPCD_WI_SCAN *scan);
+       void createMenuItem(QMenu *menu, DHCPCD_WI_SCAN *scan,
+           QAction *before = NULL);
        void createMenu1(QMenu *parent);
 };
 
        void createMenu1(QMenu *parent);
 };
 
index 0f491d2b04421ddc16e51bd7a85c125a825c7020..0608a1d7fc06762db433b23df3647a38351ac7fa 100644 (file)
@@ -228,6 +228,7 @@ void dhcpcd_wpa_set_scan_callback(DHCPCD_CONNECTION *,
     void (*)(DHCPCD_WPA *, void *), void *);
 void dhcpcd_wpa_set_status_callback(DHCPCD_CONNECTION *,
     void (*)(DHCPCD_WPA *, const char *, void *), void *);
     void (*)(DHCPCD_WPA *, void *), void *);
 void dhcpcd_wpa_set_status_callback(DHCPCD_CONNECTION *,
     void (*)(DHCPCD_WPA *, const char *, void *), void *);
+int dhcpcd_wi_scan_compare(DHCPCD_WI_SCAN *a, DHCPCD_WI_SCAN *b);
 DHCPCD_WI_SCAN * dhcpcd_wi_scans(DHCPCD_IF *);
 void dhcpcd_wi_scans_free(DHCPCD_WI_SCAN *);
 void dhcpcd_wi_history_clear(DHCPCD_CONNECTION *);
 DHCPCD_WI_SCAN * dhcpcd_wi_scans(DHCPCD_IF *);
 void dhcpcd_wi_scans_free(DHCPCD_WI_SCAN *);
 void dhcpcd_wi_history_clear(DHCPCD_CONNECTION *);
index c74f682514e774a1537df5e472f81586db31c1c2..408f710cafb10109cb76217ecc1a92e71d616342 100644 (file)
@@ -354,7 +354,7 @@ dhcpcd_wpa_scans_read(DHCPCD_WPA *wpa)
        return wis;
 }
 
        return wis;
 }
 
-static int
+int
 dhcpcd_wi_scan_compare(DHCPCD_WI_SCAN *a, DHCPCD_WI_SCAN *b)
 {
        int cmp;
 dhcpcd_wi_scan_compare(DHCPCD_WI_SCAN *a, DHCPCD_WI_SCAN *b)
 {
        int cmp;