コード例 #1
0
void CaptureInterfacesDialog::tableItemClicked(QTableWidgetItem * item)
{
    Q_UNUSED(item)

    interface_t device;
    guint i;
    global_capture_opts.num_selected = 0;

    QString filter = ui->allFilterComboBox->currentText();
    QList<QTableWidgetItem*> selected = ui->tbInterfaces->selectedItems();
    for (int row = 0; row < ui->tbInterfaces->rowCount(); row++)
    {
        QTableWidgetItem *it = ui->tbInterfaces->item(row, INTERFACE);
        QString interface_name = it->text();

        for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
            device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
            if (interface_name.compare(device.display_name)) {
                continue;
            } else {
                break;
            }
        }
        if (selected.contains(it)) {
            device.selected = true;
            global_capture_opts.num_selected++;
        } else {
            device.selected = false;
        }
        global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
        g_array_insert_val(global_capture_opts.all_ifaces, i, device);

        start_bt_->setEnabled((global_capture_opts.num_selected > 0)? true: false);

        if (filter.compare(QString(""))) {
            emit interfacesChanged();
        }
        emit setSelectedInterfaces();
    }
}
コード例 #2
0
void CaptureInterfacesDialog::tableSelected()
{
    interface_t device;

    if (!ui->tbInterfaces->selectedItems().size()) {
        for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
            device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
            device.selected = false;
            device.locked = true;
            global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
            g_array_insert_val(global_capture_opts.all_ifaces, i, device);
        }
        global_capture_opts.num_selected = 0;
        start_bt_->setEnabled(false);
        emit setSelectedInterfaces();
        for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
            device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
            device.locked = false;
            global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
            g_array_insert_val(global_capture_opts.all_ifaces, i, device);
        }
    }
    updateWidgets();
}
コード例 #3
0
void InterfaceTree::display()
{
#ifdef HAVE_LIBPCAP
    interface_t device;
#if HAVE_EXTCAP
    QIcon extcap_icon(StockIcon("x-capture-options"));
#endif

    setDisabled(false);
    clear();

    if (global_capture_opts.all_ifaces->len == 0) {
        // Error,or just no interfaces?
        QTreeWidgetItem *ti = new QTreeWidgetItem();
        QLabel *err_label;

        if (global_capture_opts.ifaces_err == 0) {
            err_label = new QLabel("No interfaces found");
        } else {
            err_label = new QLabel(global_capture_opts.ifaces_err_info);
        }
        err_label->setWordWrap(true);

        setColumnCount(1);
        addTopLevelItem(ti);
        setItemWidget(ti, 0, err_label);
        resizeColumnToContents(0);
        return;
    }

    /* when no interfaces were available initially and an update of the
       interface list called this function, the column count is set to 1
       reset it to ensure that the interface list is properly displayed */
    resetColumnCount();

    // List physical interfaces first. Alternatively we could sort them by
    // traffic, interface name, or most recently used.
    QList<QTreeWidgetItem *> phys_ifaces;
    QList<QTreeWidgetItem *> virt_ifaces;

    for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
        device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);

        /* Continue if capture device is hidden */
        if (device.hidden) {
            continue;
        }

        InterfaceTreeWidgetItem *ti = new InterfaceTreeWidgetItem();
        ti->setText(IFTREE_COL_NAME, QString().fromUtf8(device.display_name));
        ti->setData(IFTREE_COL_NAME, Qt::UserRole, QString(device.name));
        ti->setData(IFTREE_COL_STATS, Qt::UserRole, qVariantFromValue(&ti->points));
#if HAVE_EXTCAP
        if (device.if_info.type == IF_EXTCAP) {
            if (extcap_has_configuration((const char *)(device.name), FALSE)) {
                ti->setIcon(IFTREE_COL_EXTCAP, extcap_icon);
                ti->setData(IFTREE_COL_EXTCAP, Qt::UserRole, QString(device.if_info.extcap));

                if (!(device.external_cap_args_settings != 0 &&
                      g_hash_table_size(device.external_cap_args_settings) > 0))
                {
                    QFont ti_font = ti->font(IFTREE_COL_NAME);
                    ti_font.setItalic(true);
                    ti->setFont(IFTREE_COL_NAME, ti_font);
                }
            }
            virt_ifaces << ti;
        } else
#endif
        {
            phys_ifaces << ti;
        }

        // XXX Need to handle interfaces passed from the command line.
        if (strstr(prefs.capture_device, device.name) != NULL) {
            device.selected = TRUE;
            global_capture_opts.num_selected++;
            global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
            g_array_insert_val(global_capture_opts.all_ifaces, i, device);
        }
    }

    if (!phys_ifaces.isEmpty()) addTopLevelItems(phys_ifaces);
    if (!virt_ifaces.isEmpty()) addTopLevelItems(virt_ifaces);
    setSelectedInterfaces();

    // XXX Add other device information
    resizeColumnToContents(IFTREE_COL_NAME);
    resizeColumnToContents(IFTREE_COL_STATS);

#if HAVE_EXTCAP
    resizeColumnToContents(IFTREE_COL_EXTCAP);
#endif

#else
    QTreeWidgetItem *ti = new QTreeWidgetItem();

    clear();
    setColumnCount(1);
    ti->setText(0, tr("Interface information not available"));
    addTopLevelItem(ti);
    resizeColumnToContents(0);
#endif // HAVE_LIBPCAP
}