Fix a garbage condition
[dhcpcd-ui] / src / dhcpcd-qt / dhcpcd-preferences.cpp
index bf4a3327d241c83e6509800b26ed32861af7ad14..3d8b6dff3a42197a8f6b74312c72c8d789a8bd6d 100644 (file)
@@ -132,7 +132,7 @@ DhcpcdPreferences::DhcpcdPreferences(DhcpcdQt *parent)
        layout->addWidget(buttons);
 
        QIcon wired = DhcpcdQt::getIcon("devices", "network-wired");
-       what->addItem(wired, tr("Interface"));
+       what->addItem(wired, tr("interface"));
        QIcon wireless = DhcpcdQt::getIcon("devices", "network-wireless");
        what->addItem(wireless, tr("SSID"));
 
@@ -171,6 +171,8 @@ void DhcpcdPreferences::closeEvent(QCloseEvent *e)
 
 void DhcpcdPreferences::listBlocks(const QString &txt)
 {
+       char **list, **lp;
+       QIcon icon;
 
        /* clear and then disconnect so we trigger a save */
        blocks->clear();
@@ -179,20 +181,25 @@ void DhcpcdPreferences::listBlocks(const QString &txt)
        free(eWhat);
        eWhat = strdup(txt.toLower().toAscii());
 
-       if (txt == "Interface") {
-               DHCPCD_IF *i;
+       list = dhcpcd_config_blocks(parent->getConnection(),
+           txt.toLower().toAscii());
+
+       if (txt == "interface") {
+               char **ifaces, **i;
 
                blocks->addItem(tr("Select an interface"));
-               for (i = dhcpcd_interfaces(parent->getConnection());
-                   i; i = i->next)
-               {
-                       if (strcmp(i->type, "link") == 0) {
-                               QIcon icon = DhcpcdQt::getIcon("devices",
-                                   i->wireless ?
-                                   "network-wireless" : "network-wired");
-                               blocks->addItem(icon, i->ifname);
+               ifaces = dhcpcd_interface_names_sorted(parent->getConnection());
+               for (i = ifaces; i && *i; i++) {
+                       for (lp = list; lp && *lp; lp++) {
+                               if (strcmp(*i, *lp) == 0)
+                                       break;
                        }
+                       icon = DhcpcdQt::getIcon("actions",
+                           lp && *lp ?
+                           "document-save" : "document-new");
+                       blocks->addItem(icon, *i);
                }
+               dhcpcd_freev(ifaces);
        } else {
                QList<DhcpcdWi *> *wis = parent->getWis();
 
@@ -202,17 +209,20 @@ void DhcpcdPreferences::listBlocks(const QString &txt)
                        DhcpcdWi *wi = wis->at(i);
 
                        for (scan = wi->getScans(); scan; scan = scan->next) {
-                               QIcon icon;
-
-                               icon = DhcpcdQt::getIcon(
-                                   scan->flags[0] == '\0' ?"devices" :"status",
-                                   scan->flags[0] == '\0' ?"network-wireless" :
-                                       "network-wireless-encrypted");
+                               for (lp = list; lp && *lp; lp++) {
+                                       if (strcmp(scan->ssid, *lp) == 0)
+                                               break;
+                               }
+                               icon = DhcpcdQt::getIcon("actions",
+                                   lp && *lp ?
+                                   "document-save" : "document-new");
                                blocks->addItem(icon, scan->ssid);
                        }
                }
        }
 
+       dhcpcd_freev(list);
+
        /* Now make the 1st item unselectable and reconnect */
        qobject_cast<QStandardItemModel *>
            (blocks->model())->item(0)->setEnabled(false);
@@ -341,6 +351,7 @@ bool DhcpcdPreferences::writeConfig(bool *cancel)
                *cancel = true;
                return false;
        case QMessageBox::Discard:
+               *cancel = true;
                return true;
        default:
                break;