Reserve space for the assoicated icon.
authorRoy Marples <roy@marples.name>
Fri, 21 Nov 2014 21:59:28 +0000 (21:59 +0000)
committerRoy Marples <roy@marples.name>
Fri, 21 Nov 2014 21:59:28 +0000 (21:59 +0000)
Set scans on interface status change as may have lost / gained assoc.

src/dhcpcd-qt/dhcpcd-qt.cpp
src/dhcpcd-qt/dhcpcd-qt.h
src/dhcpcd-qt/dhcpcd-ssidmenuwidget.cpp

index dcf874b8ef94e6063751c93c54e4600373101317..143e841cba0452b4a592a39fb7357994da120ba6 100644 (file)
@@ -270,6 +270,19 @@ void DhcpcdQt::ifCallback(DHCPCD_IF *i)
        }
 
        updateOnline(false);
+
+       if (i->wireless) {
+               for (auto &wi : *wis) {
+                       DHCPCD_WPA *wpa = wi->getWpa();
+                       if (dhcpcd_wpa_if(wpa) == i) {
+                               DHCPCD_WI_SCAN *scans;
+
+                               scans = dhcpcd_wi_scans(i);
+                               processScans(wi, scans);
+                       }
+               }
+       }
+       
 }
 
 void DhcpcdQt::dhcpcd_if_cb(DHCPCD_IF *i, void *d)
@@ -289,9 +302,37 @@ DhcpcdWi *DhcpcdQt::findWi(DHCPCD_WPA *wpa)
        return NULL;
 }
 
+void DhcpcdQt::processScans(DhcpcdWi *wi, DHCPCD_WI_SCAN *scans)
+{
+       DHCPCD_WI_SCAN *s1, *s2;
+
+       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';
+                       }
+                       txt += s1->ssid;
+               }
+       }
+       if (!txt.isEmpty() &&
+           (ssidMenu == NULL || !ssidMenu->isVisible()))
+               notify(title, txt);
+
+       wi->setScans(scans);
+       if (ssidMenu && ssidMenu->isVisible())
+               ssidMenu->popup(ssidMenuPos);
+}
+
 void DhcpcdQt::scanCallback(DHCPCD_WPA *wpa)
 {
-       DHCPCD_WI_SCAN *scans, *s1, *s2;
+       DHCPCD_WI_SCAN *scans;
        int fd = dhcpcd_wpa_get_fd(wpa);
        DhcpcdWi *wi;
 
@@ -320,32 +361,10 @@ void DhcpcdQt::scanCallback(DHCPCD_WPA *wpa)
        if (wi == NULL) {
                wi = new DhcpcdWi(this, wpa);
                wis->append(wi);
-       } else {
-               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';
-                               }
-                               txt += s1->ssid;
-                       }
-               }
-               if (!txt.isEmpty() &&
-                   (ssidMenu == NULL || !ssidMenu->isVisible()))
-               {
-                       qDebug("%s", qPrintable(txt));
-                       notify(title, txt);
-               }
-       }
+               wi->setScans(scans);
+       } else
+               processScans(wi, scans);
 
-       if (wi->setScans(scans) && ssidMenu->isVisible())
-               ssidMenu->popup(ssidMenuPos);
 }
 
 void DhcpcdQt::dhcpcd_wpa_scan_cb(DHCPCD_WPA *wpa, void *d)
index 17f115128b823051c09f0f733b49cc2af5413a51..1a96c36e5e396291da6c6747ae7f0712668061ae 100644 (file)
@@ -103,6 +103,7 @@ private:
        QDialog *about;
        QDialog *preferences;
 
+       void processScans(DhcpcdWi *wi, DHCPCD_WI_SCAN *scans);
        void addSsidMenu(QMenu *&menu, DHCPCD_IF *ifp, DhcpcdWi *&wi);
        void createSsidMenu();
 
index db23494550d215d43551c821d5ffdf5f37116095..90934547adfdd62fb4153276d3d22d9d74a7a76e 100644 (file)
@@ -48,9 +48,12 @@ DhcpcdSsidMenuWidget::DhcpcdSsidMenuWidget(QWidget *parent,
        QHBoxLayout *layout = new QHBoxLayout(this);
        layout->setContentsMargins(1, 1, 1, 1);
        selicon = new QLabel(this);
+       selicon->setMinimumSize(16, 16);
        layout->addWidget(selicon);
 
        ssid = new QLabel(this);
+       ssid->setSizePolicy(QSizePolicy::MinimumExpanding,
+           QSizePolicy::MinimumExpanding);
        layout->addWidget(ssid);
 
        encicon = new QLabel(this);
@@ -92,7 +95,8 @@ void DhcpcdSsidMenuWidget::setScan(DHCPCD_WI_SCAN *scan)
                icon = DhcpcdQt::getIcon("actions", "dialog-ok-apply");
                picon = icon.pixmap(16, 16);
                selicon->setPixmap(picon);
-       }
+       } else
+               selicon->setPixmap(NULL);
        ssid->setText(scan->ssid);
        if (scan->flags[0] == '\0')
                icon = DhcpcdQt::getIcon("status", "dialog-warning");