1 /* interface_toolbar.cpp
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "interface_toolbar.h"
27 #include <ui/qt/widgets/interface_toolbar_lineedit.h>
28 #include "simple_dialog.h"
29 #include "ui/main_statusbar.h"
30 #include <ui_interface_toolbar.h>
32 #include "capture_opts.h"
33 #include "ui/capture_globals.h"
34 #include "sync_pipe.h"
35 #include "wsutil/file_util.h"
39 #include <QDesktopServices>
41 #include <QPushButton>
45 static const char *interface_type_property = "control_type";
46 static const char *interface_role_property = "control_role";
48 // From interface control protocol.
49 enum InterfaceControlCommand {
50 commandControlInitialized = 0,
51 commandControlSet = 1,
52 commandControlAdd = 2,
53 commandControlRemove = 3,
54 commandControlEnable = 4,
55 commandControlDisable = 5,
56 commandStatusMessage = 6,
57 commandInformationMessage = 7,
58 commandWarningMessage = 8,
59 commandErrorMessage = 9,
63 // - Move control pipe handling to extcap
65 InterfaceToolbar::InterfaceToolbar(QWidget *parent, const iface_toolbar *toolbar) :
67 ui(new Ui::InterfaceToolbar),
68 help_link_(toolbar->help),
73 // Fill inn interfaces list and initialize default interface values
74 for (GList *walker = toolbar->ifnames; walker; walker = walker->next)
76 QString ifname((gchar *)walker->data);
77 interface_[ifname].reader_thread = NULL;
78 interface_[ifname].out_fd = -1;
79 interface_[ifname].log_dialog = NULL;
82 initializeControls(toolbar);
85 foreach (QWidget *w, findChildren<QWidget *>())
87 w->setAttribute(Qt::WA_MacSmallSize, true);
93 ui->horizontalSpacer->changeSize(0,0, QSizePolicy::Fixed, QSizePolicy::Fixed);
99 InterfaceToolbar::~InterfaceToolbar()
101 foreach (QString ifname, interface_.keys())
103 if (interface_[ifname].log_dialog)
105 interface_[ifname].log_dialog->close();
112 void InterfaceToolbar::initializeControls(const iface_toolbar *toolbar)
114 for (GList *walker = toolbar->controls; walker; walker = walker->next)
116 iface_toolbar_control *control = (iface_toolbar_control *)walker->data;
118 if (control_widget_.contains(control->num))
120 // Already have a widget with this number
124 QWidget *widget = NULL;
125 switch (control->ctrl_type)
127 case INTERFACE_TYPE_BOOLEAN:
128 widget = createCheckbox(control);
131 case INTERFACE_TYPE_BUTTON:
132 widget = createButton(control);
135 case INTERFACE_TYPE_SELECTOR:
136 widget = createSelector(control);
139 case INTERFACE_TYPE_STRING:
140 widget = createString(control);
150 widget->setProperty(interface_type_property, control->ctrl_type);
151 widget->setProperty(interface_role_property, control->ctrl_role);
152 control_widget_[control->num] = widget;
157 void InterfaceToolbar::setDefaultValue(int num, const QByteArray &value)
159 foreach (QString ifname, interface_.keys())
161 // Adding default value to all interfaces
162 interface_[ifname].value[num] = value;
164 default_value_[num] = value;
167 QWidget *InterfaceToolbar::createCheckbox(iface_toolbar_control *control)
169 QCheckBox *checkbox = new QCheckBox(QString().fromUtf8(control->display));
170 checkbox->setToolTip(QString().fromUtf8(control->tooltip));
172 if (control->default_value.boolean)
174 checkbox->setCheckState(Qt::Checked);
175 QByteArray default_value(1, 1);
176 setDefaultValue(control->num, default_value);
179 connect(checkbox, SIGNAL(stateChanged(int)), this, SLOT(onCheckBoxChanged(int)));
181 ui->leftLayout->addWidget(checkbox);
186 QWidget *InterfaceToolbar::createButton(iface_toolbar_control *control)
188 QPushButton *button = new QPushButton(QString().fromUtf8((gchar *)control->display));
189 button->setMaximumHeight(27);
190 button->setToolTip(QString().fromUtf8(control->tooltip));
192 switch (control->ctrl_role)
194 case INTERFACE_ROLE_CONTROL:
195 setDefaultValue(control->num, (gchar *)control->display);
196 connect(button, SIGNAL(pressed()), this, SLOT(onControlButtonPressed()));
199 case INTERFACE_ROLE_HELP:
200 connect(button, SIGNAL(pressed()), this, SLOT(onHelpButtonPressed()));
201 if (help_link_.isEmpty())
203 // No help URL provided
208 case INTERFACE_ROLE_LOGGER:
209 connect(button, SIGNAL(pressed()), this, SLOT(onLogButtonPressed()));
212 case INTERFACE_ROLE_RESTORE:
213 connect(button, SIGNAL(pressed()), this, SLOT(onRestoreButtonPressed()));
221 ui->rightLayout->addWidget(button);
226 QWidget *InterfaceToolbar::createSelector(iface_toolbar_control *control)
228 QLabel *label = new QLabel(QString().fromUtf8(control->display));
229 label->setToolTip(QString().fromUtf8(control->tooltip));
230 QComboBox *combobox = new QComboBox();
231 combobox->setToolTip(QString().fromUtf8(control->tooltip));
232 combobox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
234 for (GList *walker = control->values; walker; walker = walker->next)
236 iface_toolbar_value *val = (iface_toolbar_value *)walker->data;
237 QString value = QString().fromUtf8((gchar *)val->value);
243 QString display = QString().fromUtf8((gchar *)val->display);
244 QByteArray interface_value;
246 interface_value.append(value);
247 if (display.isEmpty())
253 interface_value.append('\0' + display);
255 combobox->addItem(display, value);
258 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
259 combobox->setCurrentText(display);
261 int new_index = combobox->findText(display);
264 combobox->setCurrentIndex(new_index);
267 setDefaultValue(control->num, value.toUtf8());
269 foreach (QString ifname, interface_.keys())
271 // Adding values to all interfaces
272 interface_[ifname].list[control->num].append(interface_value);
274 default_list_[control->num].append(interface_value);
277 connect(combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxChanged(int)));
279 ui->leftLayout->addWidget(label);
280 ui->leftLayout->addWidget(combobox);
281 label_widget_[control->num] = label;
286 QWidget *InterfaceToolbar::createString(iface_toolbar_control *control)
288 QLabel *label = new QLabel(QString().fromUtf8(control->display));
289 label->setToolTip(QString().fromUtf8(control->tooltip));
290 InterfaceToolbarLineEdit *lineedit = new InterfaceToolbarLineEdit(NULL, control->validation, control->is_required);
291 lineedit->setToolTip(QString().fromUtf8(control->tooltip));
292 lineedit->setPlaceholderText(QString().fromUtf8(control->placeholder));
294 if (control->default_value.string)
296 lineedit->setText(QString().fromUtf8(control->default_value.string));
297 setDefaultValue(control->num, control->default_value.string);
300 connect(lineedit, SIGNAL(editedTextApplied()), this, SLOT(onLineEditChanged()));
302 ui->leftLayout->addWidget(label);
303 ui->leftLayout->addWidget(lineedit);
304 label_widget_[control->num] = label;
310 void InterfaceToolbar::setWidgetValue(QWidget *widget, int command, QByteArray payload)
312 if (QComboBox *combobox = dynamic_cast<QComboBox *>(widget))
314 combobox->blockSignals(true);
317 case commandControlSet:
319 int idx = combobox->findData(payload);
322 combobox->setCurrentIndex(idx);
327 case commandControlAdd:
331 if (payload.contains('\0'))
333 // The payload contains "value\0display"
334 QList<QByteArray> values = payload.split('\0');
340 value = display = payload;
343 int idx = combobox->findData(value);
346 // The value already exists, update item text
347 combobox->setItemText(idx, display);
351 combobox->addItem(display, value);
356 case commandControlRemove:
358 if (payload.size() == 0)
364 int idx = combobox->findData(payload);
367 combobox->removeItem(idx);
376 combobox->blockSignals(false);
378 else if (InterfaceToolbarLineEdit *lineedit = dynamic_cast<InterfaceToolbarLineEdit *>(widget))
380 // We don't block signals here because changes are applied with enter or apply button,
381 // and we want InterfaceToolbarLineEdit to always syntax check the text.
384 case commandControlSet:
385 lineedit->setText(payload);
386 lineedit->disableApplyButton();
393 else if (QCheckBox *checkbox = dynamic_cast<QCheckBox *>(widget))
395 checkbox->blockSignals(true);
398 case commandControlSet:
400 Qt::CheckState state = Qt::Unchecked;
401 if (payload.size() > 0 && payload.at(0) != 0)
405 checkbox->setCheckState(state);
412 checkbox->blockSignals(false);
414 else if (QPushButton *button = dynamic_cast<QPushButton *>(widget))
416 if ((command == commandControlSet) &&
417 widget->property(interface_role_property).toInt() == INTERFACE_ROLE_CONTROL)
419 button->setText(payload);
424 void InterfaceToolbar::setInterfaceValue(QString ifname, QWidget *widget, int num, int command, QByteArray payload)
426 if (dynamic_cast<QComboBox *>(widget))
430 case commandControlSet:
431 if (interface_[ifname].value[num] != payload)
433 interface_[ifname].value_changed[num] = false;
435 foreach (QByteArray entry, interface_[ifname].list[num])
437 if (entry == payload || entry.startsWith(payload + '\0'))
439 interface_[ifname].value[num] = payload;
444 case commandControlAdd:
445 interface_[ifname].list[num].append(payload);
448 case commandControlRemove:
449 if (payload.size() == 0)
451 interface_[ifname].value[num].clear();
452 interface_[ifname].list[num].clear();
456 foreach (QByteArray entry, interface_[ifname].list[num])
458 if (entry == payload || entry.startsWith(payload + '\0'))
460 interface_[ifname].list[num].removeAll(entry);
470 else if (dynamic_cast<InterfaceToolbarLineEdit *>(widget))
474 case commandControlSet:
475 if (interface_[ifname].value[num] != payload)
477 interface_[ifname].value_changed[num] = false;
479 interface_[ifname].value[num] = payload;
486 else if ((widget->property(interface_type_property).toInt() == INTERFACE_TYPE_BUTTON) &&
487 (widget->property(interface_role_property).toInt() == INTERFACE_ROLE_LOGGER))
489 if (command == commandControlSet)
491 if (interface_[ifname].log_dialog)
493 interface_[ifname].log_dialog->clearText();
495 interface_[ifname].log_text.clear();
497 if (command == commandControlSet || command == commandControlAdd)
499 if (interface_[ifname].log_dialog)
501 interface_[ifname].log_dialog->appendText(payload);
503 interface_[ifname].log_text.append(payload);
506 else if (widget->property(interface_role_property).toInt() == INTERFACE_ROLE_CONTROL)
508 // QCheckBox or QPushButton
511 case commandControlSet:
512 if (interface_[ifname].value[num] != payload)
514 interface_[ifname].value_changed[num] = false;
516 interface_[ifname].value[num] = payload;
525 void InterfaceToolbar::controlReceived(QString ifname, int num, int command, QByteArray payload)
529 case commandControlSet:
530 case commandControlAdd:
531 case commandControlRemove:
532 if (control_widget_.contains(num))
534 QWidget *widget = control_widget_[num];
535 setInterfaceValue(ifname, widget, num, command, payload);
537 if (ifname.compare(ui->interfacesComboBox->currentText()) == 0)
539 setWidgetValue(widget, command, payload);
544 case commandControlEnable:
545 case commandControlDisable:
546 if (control_widget_.contains(num))
548 QWidget *widget = control_widget_[num];
549 if (widget->property(interface_role_property).toInt() == INTERFACE_ROLE_CONTROL)
551 bool enable = (command == commandControlEnable ? true : false);
552 interface_[ifname].widget_disabled[num] = !enable;
554 if (ifname.compare(ui->interfacesComboBox->currentText()) == 0)
556 widget->setEnabled(enable);
557 if (label_widget_.contains(num))
559 label_widget_[num]->setEnabled(enable);
566 case commandStatusMessage:
567 statusbar_push_temporary_msg("%s", payload.data());
570 case commandInformationMessage:
571 simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, "%s", payload.data());
574 case commandWarningMessage:
575 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, "%s", payload.data());
578 case commandErrorMessage:
579 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", payload.data());
583 // Unknown commands are silently ignored
588 void InterfaceToolbar::controlSend(QString ifname, int num, int command, const QByteArray &payload = QByteArray())
590 if (payload.length() > 65535)
596 if (ifname.isEmpty() || interface_[ifname].out_fd == -1)
598 // Does not have a control out channel
602 ssize_t payload_length = payload.length() + 2;
603 unsigned char high_nibble = (payload_length >> 16) & 0xFF;
604 unsigned char mid_nibble = (payload_length >> 8) & 0xFF;
605 unsigned char low_nibble = (payload_length >> 0) & 0xFF;
609 ba.append(SP_TOOLBAR_CTRL);
610 ba.append(high_nibble);
611 ba.append(mid_nibble);
612 ba.append(low_nibble);
617 if (ws_write(interface_[ifname].out_fd, ba.data(), ba.length()) != ba.length())
619 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
620 "Unable to send control message:\n%s.",
625 void InterfaceToolbar::onControlButtonPressed()
627 const QString &ifname = ui->interfacesComboBox->currentText();
628 QPushButton *button = static_cast<QPushButton *>(sender());
629 int num = control_widget_.key(button);
631 controlSend(ifname, num, commandControlSet);
634 void InterfaceToolbar::onCheckBoxChanged(int state)
636 const QString &ifname = ui->interfacesComboBox->currentText();
637 QCheckBox *checkbox = static_cast<QCheckBox *>(sender());
638 int num = control_widget_.key(checkbox);
640 QByteArray payload(1, state == Qt::Unchecked ? 0 : 1);
641 controlSend(ifname, num, commandControlSet, payload);
642 interface_[ifname].value[num] = payload;
643 interface_[ifname].value_changed[num] = true;
646 void InterfaceToolbar::onComboBoxChanged(int idx)
648 const QString &ifname = ui->interfacesComboBox->currentText();
649 QComboBox *combobox = static_cast<QComboBox *>(sender());
650 int num = control_widget_.key(combobox);
651 QString value = combobox->itemData(idx).toString();
653 QByteArray payload(value.toUtf8());
654 controlSend(ifname, num, commandControlSet, payload);
655 interface_[ifname].value[num] = payload;
656 interface_[ifname].value_changed[num] = true;
659 void InterfaceToolbar::onLineEditChanged()
661 const QString &ifname = ui->interfacesComboBox->currentText();
662 InterfaceToolbarLineEdit *lineedit = static_cast<InterfaceToolbarLineEdit *>(sender());
663 int num = control_widget_.key(lineedit);
665 QByteArray payload(lineedit->text().toUtf8());
666 controlSend(ifname, num, commandControlSet, payload);
667 interface_[ifname].value[num] = payload;
668 interface_[ifname].value_changed[num] = true;
671 void InterfaceToolbar::onLogButtonPressed()
673 const QString &ifname = ui->interfacesComboBox->currentText();
675 if (!interface_[ifname].log_dialog)
677 QPushButton *button = static_cast<QPushButton *>(sender());
678 interface_[ifname].log_dialog = new FunnelTextDialog(ifname + " " + button->text());
679 connect(interface_[ifname].log_dialog, SIGNAL(accepted()), this, SLOT(closeLog()));
680 connect(interface_[ifname].log_dialog, SIGNAL(rejected()), this, SLOT(closeLog()));
682 interface_[ifname].log_dialog->setText(interface_[ifname].log_text);
685 interface_[ifname].log_dialog->show();
686 interface_[ifname].log_dialog->raise();
687 interface_[ifname].log_dialog->activateWindow();
690 void InterfaceToolbar::onHelpButtonPressed()
692 QUrl help_url(help_link_);
694 if (help_url.scheme().compare("file") != 0)
696 QDesktopServices::openUrl(help_url);
700 void InterfaceToolbar::closeLog()
702 FunnelTextDialog *log_dialog = static_cast<FunnelTextDialog *>(sender());
704 foreach (QString ifname, interface_.keys())
706 if (interface_[ifname].log_dialog == log_dialog)
708 interface_[ifname].log_dialog = NULL;
714 void InterfaceToolbar::startReaderThread(QString ifname, void *control_in)
716 QThread *thread = new QThread;
717 InterfaceToolbarReader *reader = new InterfaceToolbarReader(ifname, control_in);
718 reader->moveToThread(thread);
720 connect(thread, SIGNAL(started()), reader, SLOT(loop()));
721 connect(reader, SIGNAL(finished()), thread, SLOT(quit()));
722 connect(reader, SIGNAL(finished()), reader, SLOT(deleteLater()));
723 connect(thread, SIGNAL(finished()), reader, SLOT(deleteLater()));
724 connect(reader, SIGNAL(received(QString, int, int, QByteArray)),
725 this, SLOT(controlReceived(QString, int, int, QByteArray)));
727 interface_[ifname].reader_thread = thread;
732 void InterfaceToolbar::startCapture(GArray *ifaces)
734 if (!ifaces || ifaces->len == 0)
738 const QString &selected_ifname = ui->interfacesComboBox->currentText();
739 QString first_capturing_ifname;
740 bool selected_found = false;
742 for (guint i = 0; i < ifaces->len; i++)
744 interface_options *interface_opts = &g_array_index(ifaces, interface_options, i);
745 QString ifname(interface_opts->name);
747 if (!interface_.contains(ifname))
748 // This interface is not for us
751 if (first_capturing_ifname.isEmpty())
752 first_capturing_ifname = ifname;
754 if (ifname.compare(selected_ifname) == 0)
755 selected_found = true;
757 if (interface_[ifname].out_fd != -1)
758 // Already have control channels for this interface
761 // Open control out channel
763 startReaderThread(ifname, interface_opts->extcap_control_in_h);
764 interface_[ifname].out_fd = _open_osfhandle((intptr_t)interface_opts->extcap_control_out_h, O_APPEND | O_BINARY);
766 startReaderThread(ifname, interface_opts->extcap_control_in);
767 interface_[ifname].out_fd = ws_open(interface_opts->extcap_control_out, O_WRONLY | O_BINARY, 0);
769 sendChangedValues(ifname);
770 controlSend(ifname, 0, commandControlInitialized);
773 if (!selected_found && !first_capturing_ifname.isEmpty())
775 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
776 ui->interfacesComboBox->setCurrentText(first_capturing_ifname);
778 int new_index = ui->interfacesComboBox->findText(first_capturing_ifname);
781 ui->interfacesComboBox->setCurrentIndex(new_index);
789 #endif // HAVE_EXTCAP
792 void InterfaceToolbar::stopCapture()
794 foreach (QString ifname, interface_.keys())
796 if (interface_[ifname].reader_thread)
798 #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
799 interface_[ifname].reader_thread->requestInterruption();
801 interface_[ifname].reader_thread = NULL;
804 if (interface_[ifname].out_fd != -1)
807 ws_close (interface_[ifname].out_fd);
809 interface_[ifname].out_fd = -1;
812 foreach (int num, control_widget_.keys())
814 // Reset disabled property for all widgets
815 interface_[ifname].widget_disabled[num] = false;
817 QWidget *widget = control_widget_[num];
818 if ((widget->property(interface_type_property).toInt() == INTERFACE_TYPE_BUTTON) &&
819 (widget->property(interface_role_property).toInt() == INTERFACE_ROLE_CONTROL))
821 // Reset default value for control buttons
822 interface_[ifname].value[num] = default_value_[num];
824 if (ifname.compare(ui->interfacesComboBox->currentText()) == 0)
826 setWidgetValue(widget, commandControlSet, default_value_[num]);
835 void InterfaceToolbar::sendChangedValues(QString ifname)
837 // Send all values which has changed
838 foreach (int num, control_widget_.keys())
840 QWidget *widget = control_widget_[num];
841 if ((interface_[ifname].value_changed[num]) &&
842 (widget->property(interface_type_property).toInt() != INTERFACE_TYPE_BUTTON) &&
843 (widget->property(interface_role_property).toInt() == INTERFACE_ROLE_CONTROL))
845 controlSend(ifname, num, commandControlSet, interface_[ifname].value[num]);
850 void InterfaceToolbar::onRestoreButtonPressed()
852 const QString &ifname = ui->interfacesComboBox->currentText();
854 // Set default values to all widgets and interfaces
855 foreach (int num, control_widget_.keys())
857 QWidget *widget = control_widget_[num];
858 if (default_list_[num].size() > 0)
860 // This is a QComboBox. Clear list and add new entries.
861 setWidgetValue(widget, commandControlRemove, QByteArray());
862 interface_[ifname].list[num].clear();
864 foreach (QByteArray value, default_list_[num])
866 setWidgetValue(widget, commandControlAdd, value);
867 interface_[ifname].list[num].append(value);
871 switch (widget->property(interface_role_property).toInt())
873 case INTERFACE_ROLE_CONTROL:
874 setWidgetValue(widget, commandControlSet, default_value_[num]);
875 interface_[ifname].value[num] = default_value_[num];
876 interface_[ifname].value_changed[num] = false;
879 case INTERFACE_ROLE_LOGGER:
880 if (interface_[ifname].log_dialog)
882 interface_[ifname].log_dialog->clearText();
884 interface_[ifname].log_text.clear();
893 bool InterfaceToolbar::hasInterface(QString ifname)
895 return interface_.contains(ifname);
898 void InterfaceToolbar::updateWidgets()
900 const QString &ifname = ui->interfacesComboBox->currentText();
901 bool is_capturing = (interface_[ifname].out_fd == -1 ? false : true);
903 foreach (int num, control_widget_.keys())
905 QWidget *widget = control_widget_[num];
906 bool widget_enabled = true;
908 if (ifname.isEmpty() &&
909 (widget->property(interface_role_property).toInt() != INTERFACE_ROLE_HELP))
911 // No interface selected, disable all but Help button
912 widget_enabled = false;
914 else if (!is_capturing &&
915 (widget->property(interface_type_property).toInt() == INTERFACE_TYPE_BUTTON) &&
916 (widget->property(interface_role_property).toInt() == INTERFACE_ROLE_CONTROL))
918 widget_enabled = false;
920 else if (widget->property(interface_role_property).toInt() == INTERFACE_ROLE_CONTROL)
922 widget_enabled = !interface_[ifname].widget_disabled[num];
925 widget->setEnabled(widget_enabled);
926 if (label_widget_.contains(num))
928 label_widget_[num]->setEnabled(widget_enabled);
932 foreach (int num, control_widget_.keys())
934 QWidget *widget = control_widget_[num];
935 if ((widget->property(interface_type_property).toInt() == INTERFACE_TYPE_BUTTON) &&
936 (widget->property(interface_role_property).toInt() == INTERFACE_ROLE_RESTORE))
938 widget->setEnabled(!is_capturing);
943 void InterfaceToolbar::interfaceListChanged()
946 const QString &selected_ifname = ui->interfacesComboBox->currentText();
947 bool keep_selected = false;
949 ui->interfacesComboBox->blockSignals(true);
950 ui->interfacesComboBox->clear();
952 for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++)
954 interface_t *device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
958 if (interface_.keys().contains(device->name))
960 ui->interfacesComboBox->addItem(device->name);
961 if (selected_ifname.compare(device->name) == 0)
963 // Keep selected interface
964 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
965 ui->interfacesComboBox->setCurrentText(device->name);
967 int new_index = ui->interfacesComboBox->findText(device->name);
970 ui->interfacesComboBox->setCurrentIndex(new_index);
973 keep_selected = true;
978 ui->interfacesComboBox->blockSignals(false);
982 // Select the first interface
983 on_interfacesComboBox_currentIndexChanged(ui->interfacesComboBox->currentText());
990 void InterfaceToolbar::on_interfacesComboBox_currentIndexChanged(const QString &ifname)
992 foreach (int num, control_widget_.keys())
994 QWidget *widget = control_widget_[num];
995 if (interface_[ifname].list[num].size() > 0)
997 // This is a QComboBox. Clear list and add new entries.
998 setWidgetValue(widget, commandControlRemove, QByteArray());
1000 foreach (QByteArray value, interface_[ifname].list[num])
1002 setWidgetValue(widget, commandControlAdd, value);
1006 if (widget->property(interface_role_property).toInt() == INTERFACE_ROLE_CONTROL)
1008 setWidgetValue(widget, commandControlSet, interface_[ifname].value[num]);
1021 * indent-tabs-mode: nil
1024 * ex: set shiftwidth=4 tabstop=8 expandtab:
1025 * :indentSize=4:tabSize=8:noTabs=true: