コード例 #1
0
void SyntaxLineEdit::checkDisplayFilter(QString filter)
{
    if (filter.isEmpty()) {
        setSyntaxState(SyntaxLineEdit::Empty);
        return;
    }

    dfilter_t *dfp = NULL;
    gchar *err_msg;
    if (dfilter_compile(filter.toUtf8().constData(), &dfp, &err_msg)) {
        GPtrArray *depr = NULL;
        if (dfp) {
            depr = dfilter_deprecated_tokens(dfp);
        }
        if (depr) {
            // You keep using that word. I do not think it means what you think it means.
            setSyntaxState(SyntaxLineEdit::Deprecated);
            /*
             * We're being lazy and only printing the first "problem" token.
             * Would it be better to print all of them?
             */
            syntax_error_message_ = tr("\"%1\" may have unexpected results (see the User's Guide)")
                    .arg((const char *) g_ptr_array_index(depr, 0));
        } else {
            setSyntaxState(SyntaxLineEdit::Valid);
        }
    } else {
        setSyntaxState(SyntaxLineEdit::Invalid);
        syntax_error_message_ = QString::fromUtf8(err_msg);
        g_free(err_msg);
    }
    dfilter_free(dfp);
}
コード例 #2
0
void CaptureFilterEdit::setFilterSyntaxState(QString filter, bool valid, QString err_msg)
{
    if (filter.compare(text()) == 0) { // The user hasn't changed the filter
        if (valid) {
            setSyntaxState(text().isEmpty() ? Empty : Valid);
        } else {
            setSyntaxState(Invalid);
            emit pushFilterSyntaxStatus(err_msg);
        }
    }

#ifdef HAVE_LIBPCAP
    if (syntaxState() != Invalid) {
        if (bookmark_button_) {
            bookmark_button_->setEnabled(true);
        }
        if (apply_button_) {
            apply_button_->setEnabled(true);
        }
        valid = true;
        g_free(global_capture_opts.default_options.cfilter);
        if (filter.isEmpty()) {
            global_capture_opts.default_options.cfilter = NULL;
        } else {
            global_capture_opts.default_options.cfilter = qstring_strdup(filter);
        }

        if (global_capture_opts.num_selected > 0) {
            interface_t device;

            for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) {
                device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
                if (!device.selected) {
                    continue;
                }
//                if (device.active_dlt == -1) {
//                    simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "The link type of interface %s was not specified.", device.name);
//                    continue;  /* Programming error: somehow managed to select an "unsupported" entry */
//                }
                g_array_remove_index(global_capture_opts.all_ifaces, i);
                device.cfilter = qstring_strdup(filter);
                g_array_insert_val(global_capture_opts.all_ifaces, i, device);
//                update_filter_string(device.name, filter_text);
            }
        }
    }
#endif // HAVE_LIBPCAP

    emit captureFilterSyntaxChanged(valid);
}
コード例 #3
0
void SyntaxLineEdit::checkFieldName(QString field)
{
    if (field.isEmpty()) {
        setSyntaxState(SyntaxLineEdit::Empty);
        return;
    }

    char invalid_char = proto_check_field_name(field.toUtf8().constData());
    if (invalid_char) {
        setSyntaxState(SyntaxLineEdit::Invalid);
    } else {
        checkDisplayFilter(field);
    }
}
コード例 #4
0
void SyntaxLineEdit::checkInteger(QString number)
{
    if (number.isEmpty()) {
        setSyntaxState(SyntaxLineEdit::Empty);
        return;
    }

    bool ok;
    text().toInt(&ok);
    if (ok) {
        setSyntaxState(SyntaxLineEdit::Valid);
    } else {
        setSyntaxState(SyntaxLineEdit::Invalid);
    }
}
コード例 #5
0
SyntaxLineEdit::SyntaxLineEdit(QWidget *parent) :
    QLineEdit(parent)
{
    state_style_sheet_ = QString(
            "SyntaxLineEdit[syntaxState=\"%1\"] {"
            "  color: #%4;"
            "  background-color: #%5;"
            "}"

            "SyntaxLineEdit[syntaxState=\"%2\"] {"
            "  color: #%4;"
            "  background-color: #%6;"
            "}"

            "SyntaxLineEdit[syntaxState=\"%3\"] {"
            "  color: #%4;"
            "  background-color: #%7;"
            "}"
            )
            .arg(Invalid)
            .arg(Deprecated)
            .arg(Valid)
            .arg(ws_syntax_invalid_foreground, 6, 16, QChar('0'))   // Foreground
            .arg(ws_syntax_invalid_background, 6, 16, QChar('0')) // Invalid
            .arg(ws_syntax_deprecated_background, 6, 16, QChar('0'))      // Deprecated
            .arg(ws_syntax_valid_background, 6, 16, QChar('0'))   // Valid
            ;
    setStyleSheet(tr(""));
    setSyntaxState();
}
コード例 #6
0
void DisplayFilterEdit::checkFilter(const QString& text)
{
    dfilter_t *dfp;
    guchar c;

    clear_button_->setVisible(!text.isEmpty());

    popFilterSyntaxStatus();

    if (field_name_only_ && (c = proto_check_field_name(text.toUtf8().constData()))) {
        setSyntaxState(Invalid);
        emit pushFilterSyntaxStatus(QString().sprintf("Illegal character in field name: '%c'", c));
    } else if (dfilter_compile(text.toUtf8().constData(), &dfp)) {
        GPtrArray *depr = NULL;
        if (dfp != NULL) {
            depr = dfilter_deprecated_tokens(dfp);
        }
        if (text.isEmpty()) {
            setSyntaxState(Empty);
        } else if (depr) {
            /* You keep using that word. I do not think it means what you think it means. */
            setSyntaxState(Deprecated);
            /*
             * We're being lazy and only printing the first "problem" token.
             * Would it be better to print all of them?
             */
            emit pushFilterSyntaxWarning(QString().sprintf("\"%s\" may have unexpected results (see the User's Guide)",
                                                          (const char *) g_ptr_array_index(depr, 0)));
        } else {
            setSyntaxState(Valid);
        }
        dfilter_free(dfp);
    } else {
        setSyntaxState(Invalid);
        QString invalidMsg(tr("Invalid filter"));
        if (dfilter_error_msg) {
            invalidMsg.append(QString().sprintf(": %s", dfilter_error_msg));
        }
        emit pushFilterSyntaxStatus(invalidMsg);
    }

    bookmark_button_->setEnabled(syntaxState() == Valid || syntaxState() == Deprecated);
    if (apply_button_) {
        apply_button_->setEnabled(SyntaxState() != Invalid);
    }
}
コード例 #7
0
void CaptureFilterEdit::checkFilter(const QString& filter)
{
    setSyntaxState(Busy);
    popFilterSyntaxStatus();
    bool empty = filter.isEmpty();

    setConflict(false);
    if (bookmark_button_) {
        bool match = false;

        for (GList *cf_item = get_filter_list_first(CFILTER_LIST); cf_item; cf_item = g_list_next(cf_item)) {
            if (!cf_item->data) continue;
            filter_def *cf_def = (filter_def *) cf_item->data;
            if (!cf_def->name || !cf_def->strval) continue;

            if (filter.compare(cf_def->strval) == 0) {
                match = true;
            }
        }

        if (match) {
            bookmark_button_->setStockIcon("x-filter-matching-bookmark");
            if (remove_action_) {
                remove_action_->setData(text());
                remove_action_->setVisible(true);
            }
        } else {
            bookmark_button_->setStockIcon("x-capture-filter-bookmark");
            if (remove_action_) {
                remove_action_->setVisible(false);
            }
        }

        enable_save_action_ = (!match && !filter.isEmpty());
        if (save_action_) {
            save_action_->setEnabled(false);
        }
    }

    if (apply_button_) {
        apply_button_->setEnabled(false);
    }

    if (clear_button_) {
        clear_button_->setVisible(!empty);
    }

    if (empty) {
        setFilterSyntaxState(filter, Empty, QString());
    } else {
        syntax_worker_->checkFilter(filter);
    }
}
コード例 #8
0
void SyntaxLineEdit::checkCustomColumn(QString fields)
{
    if (fields.isEmpty()) {
        setSyntaxState(SyntaxLineEdit::Empty);
        return;
    }

    gchar **splitted_fields = g_regex_split_simple(COL_CUSTOM_PRIME_REGEX,
                fields.toUtf8().constData(), G_REGEX_ANCHORED, G_REGEX_MATCH_ANCHORED);

    for (guint i = 0; i < g_strv_length(splitted_fields); i++) {
        if (splitted_fields[i] && *splitted_fields[i]) {
            if (proto_check_field_name(splitted_fields[i]) != 0) {
                setSyntaxState(SyntaxLineEdit::Invalid);
                g_strfreev(splitted_fields);
                return;
            }
        }
    }
    g_strfreev(splitted_fields);

    checkDisplayFilter(fields);
}
コード例 #9
0
SyntaxLineEdit::SyntaxLineEdit(QWidget *parent) :
    QLineEdit(parent),
    completer_(NULL),
    completion_model_(NULL)
{
    // Try to matche QLineEdit's placeholder text color (which sets the
    // alpha channel to 50%, which doesn't work in style sheets).
    // Setting the foreground color lets us avoid yet another background
    // color preference and should hopefully make things easier to
    // distinguish for color blind folk.
    busy_fg_ = ColorUtils::alphaBlend(palette().text(), palette().base(), 0.5);

    setSyntaxState();
    setMaxLength(std::numeric_limits<quint32>::max());
}
コード例 #10
0
void CaptureFilterEdit::checkFilter(const QString& text)
{
    setSyntaxState(Empty);
    popFilterSyntaxStatus();
    bool empty = text.isEmpty();

    bookmark_button_->setEnabled(false);
    if (apply_button_) {
        apply_button_->setEnabled(false);
    }

    if (empty) {
        clear_button_->setVisible(false);
        setFilterSyntaxState(text, true, QString());
    } else {
        clear_button_->setVisible(true);
        syntax_worker_->checkFilter(text);
    }
}
コード例 #11
0
void CaptureFilterEdit::setFilterSyntaxState(QString filter, int state, QString err_msg)
{
    if (filter.compare(text()) == 0) { // The user hasn't changed the filter
        setSyntaxState((SyntaxState)state);
        if (!err_msg.isEmpty()) {
            emit pushFilterSyntaxStatus(err_msg);
        }
    }

    bool valid = (state != Invalid);

    if (valid) {
        if (save_action_) {
            save_action_->setEnabled(enable_save_action_);
        }
        if (apply_button_) {
            apply_button_->setEnabled(true);
        }
    }

    emit captureFilterSyntaxChanged(valid);
}
コード例 #12
0
void CaptureFilterEdit::checkFilter(const QString& filter)
{
    setSyntaxState(Busy);
    popFilterSyntaxStatus();
    bool empty = filter.isEmpty();

    if (bookmark_button_) {
        bookmark_button_->setEnabled(false);
    }

    if (apply_button_) {
        apply_button_->setEnabled(false);
    }

    if (clear_button_) {
        clear_button_->setVisible(!empty);
    }

    if (empty) {
        setFilterSyntaxState(filter, Empty, QString());
    } else {
        syntax_worker_->checkFilter(filter);
    }
}
コード例 #13
0
ファイル: syntax_line_edit.cpp プロジェクト: jelmer/wireshark
SyntaxLineEdit::SyntaxLineEdit(QWidget *parent) :
    QLineEdit(parent)
{
    setSyntaxState();
}