Only update menu items if visible as we force a redraw when re-shown.
authorRoy Marples <roy@marples.name>
Wed, 3 Dec 2014 10:20:10 +0000 (10:20 +0000)
committerRoy Marples <roy@marples.name>
Wed, 3 Dec 2014 10:20:10 +0000 (10:20 +0000)
Sort association on newly created menus.

src/dhcpcd-qt/dhcpcd-qt.cpp
src/dhcpcd-qt/dhcpcd-wi.cpp

index b84c17c9834816372396d41db97f04aa176744ee..1b612e82361a5c5c47a7224f3e748918a26d7808 100644 (file)
@@ -467,7 +467,6 @@ void DhcpcdQt::notify(QString &title, QString &msg,
 #endif
 }
 
-
 void DhcpcdQt::closeEvent(QCloseEvent *event)
 {
 
index 568ce42e7d72737ab962b1e6794ba7cea51b5111..16767c3f0874ea54f3456e921b2a613f8f47a239 100644 (file)
@@ -75,7 +75,7 @@ DhcpcdWi::~DhcpcdWi()
                pingTimer->deleteLater();
                pingTimer = NULL;
        }
-       
+
        dhcpcd_wi_scans_free(scans);
 }
 
@@ -95,7 +95,7 @@ bool DhcpcdWi::setScans(DHCPCD_WI_SCAN *scans)
 {
        bool changed = false;
 
-       if (menu) {
+       if (menu && menu->isVisible()) {
                QList<DhcpcdSsidMenu*> lst;
                DHCPCD_WI_SCAN *scan;
                DHCPCD_IF *i;
@@ -174,15 +174,29 @@ void DhcpcdWi::createMenuItem(QMenu *menu, DHCPCD_WI_SCAN *scan,
 
 void DhcpcdWi::createMenu1(QMenu *menu)
 {
+       DHCPCD_IF *i;
        DHCPCD_WI_SCAN *scan;
+       QAction *before;
+
+       i = dhcpcd_wpa_if(wpa);
+       for (scan = scans; scan; scan = scan->next) {
+               before = NULL;
+               if (dhcpcd_wi_associated(i, scan)) {
+                       QList<DhcpcdSsidMenu*> lst;
 
-       for (scan = scans; scan; scan = scan->next)
-               createMenuItem(menu, scan);
+                       lst = menu->findChildren<DhcpcdSsidMenu*>();
+                       if (!lst.empty())
+                               before = lst.at(0);
+               }
+               createMenuItem(menu, scan, before);
+       }
 }
 
 void DhcpcdWi::createMenu(QMenu *menu)
 {
 
+       if (this->menu && this->menu != menu)
+               this->menu->deleteLater();
        this->menu = menu;
        createMenu1(menu);
 }
@@ -193,6 +207,8 @@ QMenu *DhcpcdWi::createIfMenu(QMenu *parent)
        QIcon icon;
 
        ifp = dhcpcd_wpa_if(wpa);
+       if (this->menu)
+               this->menu->deleteLater();
        menu = new DhcpcdIfMenu(ifp, parent);
        icon = DhcpcdQt::getIcon("devices", "network-wireless");
        menu->setIcon(icon);