2015-01-01 19:41:03 +00:00
|
|
|
/* column_editor_frame.cpp
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <epan/column-info.h>
|
|
|
|
#include <epan/column.h>
|
2015-09-12 12:06:12 +00:00
|
|
|
#include <epan/prefs.h>
|
|
|
|
|
|
|
|
#include <ui/preference_utils.h>
|
2015-01-01 19:41:03 +00:00
|
|
|
|
|
|
|
#include "column_editor_frame.h"
|
2015-06-25 16:17:03 +00:00
|
|
|
#include <ui_column_editor_frame.h>
|
2015-01-01 19:41:03 +00:00
|
|
|
|
2015-12-01 14:41:44 +00:00
|
|
|
#include <QPushButton>
|
2015-01-01 19:41:03 +00:00
|
|
|
#include <QComboBox>
|
2017-09-17 16:57:25 +00:00
|
|
|
#include <QKeyEvent>
|
2015-01-01 19:41:03 +00:00
|
|
|
|
|
|
|
ColumnEditorFrame::ColumnEditorFrame(QWidget *parent) :
|
|
|
|
AccordionFrame(parent),
|
|
|
|
ui(new Ui::ColumnEditorFrame),
|
|
|
|
cur_column_(-1)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
foreach (QWidget *w, findChildren<QWidget *>()) {
|
|
|
|
w->setAttribute(Qt::WA_MacSmallSize, true);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (int i = 0; i < NUM_COL_FMTS; i++) {
|
|
|
|
ui->typeComboBox->addItem(col_format_desc(i), QVariant(i));
|
|
|
|
}
|
2017-09-17 17:40:44 +00:00
|
|
|
|
|
|
|
connect(ui->fieldsNameLineEdit, SIGNAL(textChanged(QString)),
|
|
|
|
ui->fieldsNameLineEdit, SLOT(checkCustomColumn(QString)));
|
2015-01-01 19:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ColumnEditorFrame::~ColumnEditorFrame()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2017-09-17 16:52:10 +00:00
|
|
|
bool ColumnEditorFrame::syntaxIsValid(void)
|
|
|
|
{
|
|
|
|
// Fields must be a valid filter.
|
|
|
|
// Occurrence must be empty or valid.
|
|
|
|
return ((ui->fieldsNameLineEdit->syntaxState() == SyntaxLineEdit::Valid) &&
|
|
|
|
(ui->occurrenceLineEdit->syntaxState() != SyntaxLineEdit::Invalid));
|
|
|
|
}
|
|
|
|
|
2015-11-10 21:19:27 +00:00
|
|
|
void ColumnEditorFrame::setFields(int index)
|
|
|
|
{
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
if (index == COL_CUSTOM) {
|
2015-12-11 08:34:08 +00:00
|
|
|
ui->fieldsNameLineEdit->setText(saved_fields_);
|
|
|
|
ui->fieldsNameLineEdit->checkCustomColumn(saved_fields_);
|
2015-11-10 21:19:27 +00:00
|
|
|
ui->occurrenceLineEdit->setText(saved_occurrence_);
|
|
|
|
ui->occurrenceLineEdit->checkInteger(saved_occurrence_);
|
2017-09-17 16:52:10 +00:00
|
|
|
ok = syntaxIsValid();
|
2015-11-10 21:19:27 +00:00
|
|
|
} else {
|
2015-12-11 08:34:08 +00:00
|
|
|
ui->fieldsNameLineEdit->clear();
|
|
|
|
ui->fieldsNameLineEdit->setSyntaxState(SyntaxLineEdit::Empty);
|
2015-11-10 21:19:27 +00:00
|
|
|
ui->occurrenceLineEdit->clear();
|
|
|
|
ui->occurrenceLineEdit->setSyntaxState(SyntaxLineEdit::Empty);
|
|
|
|
}
|
2015-12-01 14:41:44 +00:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok);
|
2015-11-10 21:19:27 +00:00
|
|
|
}
|
|
|
|
|
2015-01-01 19:41:03 +00:00
|
|
|
void ColumnEditorFrame::editColumn(int column)
|
|
|
|
{
|
|
|
|
cur_column_ = column;
|
|
|
|
ui->titleLineEdit->setText(get_column_title(column));
|
2015-12-11 08:34:08 +00:00
|
|
|
saved_fields_ = get_column_custom_fields(column);
|
2015-11-10 21:19:27 +00:00
|
|
|
saved_occurrence_ = QString::number(get_column_custom_occurrence(column));
|
2015-01-01 19:41:03 +00:00
|
|
|
ui->typeComboBox->setCurrentIndex(get_column_format(column));
|
2015-11-10 21:19:27 +00:00
|
|
|
setFields(ui->typeComboBox->currentIndex());
|
2015-01-01 19:41:03 +00:00
|
|
|
}
|
|
|
|
|
2017-11-08 20:10:42 +00:00
|
|
|
void ColumnEditorFrame::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
ui->titleLineEdit->setFocus();
|
|
|
|
ui->titleLineEdit->selectAll();
|
|
|
|
|
|
|
|
AccordionFrame::showEvent(event);
|
|
|
|
}
|
|
|
|
|
2015-01-01 19:41:03 +00:00
|
|
|
void ColumnEditorFrame::on_typeComboBox_activated(int index)
|
|
|
|
{
|
2015-11-10 21:19:27 +00:00
|
|
|
setFields(index);
|
2015-01-01 19:41:03 +00:00
|
|
|
}
|
|
|
|
|
2015-12-11 08:34:08 +00:00
|
|
|
void ColumnEditorFrame::on_fieldsNameLineEdit_textEdited(const QString &fields)
|
2015-01-01 19:41:03 +00:00
|
|
|
{
|
2015-12-11 08:34:08 +00:00
|
|
|
ui->fieldsNameLineEdit->checkCustomColumn(fields);
|
2015-01-01 19:41:03 +00:00
|
|
|
if (ui->typeComboBox->currentIndex() != COL_CUSTOM) {
|
|
|
|
ui->typeComboBox->setCurrentIndex(COL_CUSTOM);
|
|
|
|
ui->occurrenceLineEdit->setText(saved_occurrence_);
|
|
|
|
}
|
|
|
|
|
2017-09-17 16:52:10 +00:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(syntaxIsValid());
|
2015-01-01 19:41:03 +00:00
|
|
|
|
2015-12-11 08:34:08 +00:00
|
|
|
saved_fields_ = fields;
|
2015-01-01 19:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ColumnEditorFrame::on_occurrenceLineEdit_textEdited(const QString &occurrence)
|
|
|
|
{
|
|
|
|
ui->occurrenceLineEdit->checkInteger(occurrence);
|
|
|
|
if (ui->typeComboBox->currentIndex() != COL_CUSTOM) {
|
|
|
|
ui->typeComboBox->setCurrentIndex(COL_CUSTOM);
|
2015-12-11 08:34:08 +00:00
|
|
|
ui->fieldsNameLineEdit->setText(saved_fields_);
|
2015-01-01 19:41:03 +00:00
|
|
|
}
|
|
|
|
|
2017-09-17 16:52:10 +00:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(syntaxIsValid());
|
2015-01-01 19:41:03 +00:00
|
|
|
|
|
|
|
saved_occurrence_ = occurrence;
|
|
|
|
}
|
|
|
|
|
2015-12-01 14:41:44 +00:00
|
|
|
void ColumnEditorFrame::on_buttonBox_rejected()
|
2015-01-01 19:41:03 +00:00
|
|
|
{
|
|
|
|
cur_column_ = -1;
|
|
|
|
animatedHide();
|
|
|
|
}
|
|
|
|
|
2015-12-01 14:41:44 +00:00
|
|
|
void ColumnEditorFrame::on_buttonBox_accepted()
|
2015-01-01 19:41:03 +00:00
|
|
|
{
|
|
|
|
QByteArray col_str;
|
|
|
|
if (cur_column_ >= 0) {
|
|
|
|
col_str = ui->titleLineEdit->text().toUtf8();
|
|
|
|
set_column_title(cur_column_, col_str.constData());
|
|
|
|
set_column_format(cur_column_, ui->typeComboBox->currentIndex());
|
|
|
|
if (ui->typeComboBox->currentIndex() == COL_CUSTOM) {
|
2015-12-11 08:34:08 +00:00
|
|
|
col_str = ui->fieldsNameLineEdit->text().toUtf8();
|
|
|
|
set_column_custom_fields(cur_column_, col_str.constData());
|
2015-01-01 19:41:03 +00:00
|
|
|
if (!ui->occurrenceLineEdit->text().isEmpty()) {
|
|
|
|
set_column_custom_occurrence(cur_column_, ui->occurrenceLineEdit->text().toInt());
|
|
|
|
}
|
|
|
|
}
|
2015-09-12 12:06:12 +00:00
|
|
|
if (!prefs.gui_use_pref_save) {
|
|
|
|
prefs_main_write();
|
|
|
|
}
|
2015-01-01 19:41:03 +00:00
|
|
|
emit columnEdited();
|
|
|
|
}
|
2015-12-01 14:41:44 +00:00
|
|
|
|
|
|
|
on_buttonBox_rejected();
|
2015-01-01 19:41:03 +00:00
|
|
|
}
|
|
|
|
|
2017-09-17 16:57:25 +00:00
|
|
|
void ColumnEditorFrame::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
if (event->modifiers() == Qt::NoModifier) {
|
|
|
|
if (event->key() == Qt::Key_Escape) {
|
|
|
|
on_buttonBox_rejected();
|
|
|
|
} else if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
|
|
|
|
if (ui->buttonBox->button(QDialogButtonBox::Ok)->isEnabled()) {
|
|
|
|
on_buttonBox_accepted();
|
|
|
|
} else if (ui->fieldsNameLineEdit->syntaxState() == SyntaxLineEdit::Empty) {
|
|
|
|
emit pushFilterSyntaxStatus(tr("Missing fields."));
|
|
|
|
} else if (ui->fieldsNameLineEdit->syntaxState() != SyntaxLineEdit::Valid) {
|
|
|
|
emit pushFilterSyntaxStatus(tr("Invalid fields."));
|
|
|
|
} else if (ui->occurrenceLineEdit->syntaxState() == SyntaxLineEdit::Invalid) {
|
|
|
|
emit pushFilterSyntaxStatus(tr("Invalid occurrence value."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-24 18:17:55 +00:00
|
|
|
|
|
|
|
AccordionFrame::keyPressEvent(event);
|
2017-09-17 16:57:25 +00:00
|
|
|
}
|
|
|
|
|
2015-01-01 19:41:03 +00:00
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|