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>
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ColumnEditorFrame::~ColumnEditorFrame()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
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_);
|
2015-12-11 08:34:08 +00:00
|
|
|
if ((ui->fieldsNameLineEdit->syntaxState() != SyntaxLineEdit::Valid) ||
|
2015-11-10 21:19:27 +00:00
|
|
|
(ui->occurrenceLineEdit->syntaxState() != SyntaxLineEdit::Valid)) {
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
} 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
|
|
|
}
|
|
|
|
|
|
|
|
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_);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok = true;
|
2015-12-11 08:34:08 +00:00
|
|
|
if ((ui->fieldsNameLineEdit->syntaxState() == SyntaxLineEdit::Invalid) ||
|
2015-11-10 21:19:27 +00:00
|
|
|
((ui->typeComboBox->currentIndex() == COL_CUSTOM) &&
|
|
|
|
(ui->occurrenceLineEdit->syntaxState() == SyntaxLineEdit::Empty)))
|
|
|
|
ok = false;
|
2015-12-01 14:41:44 +00:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool ok = true;
|
2015-11-10 21:19:27 +00:00
|
|
|
if ((ui->occurrenceLineEdit->syntaxState() == SyntaxLineEdit::Invalid) ||
|
|
|
|
((ui->typeComboBox->currentIndex() == COL_CUSTOM) &&
|
|
|
|
(ui->occurrenceLineEdit->syntaxState() == SyntaxLineEdit::Empty)))
|
|
|
|
ok = false;
|
2015-12-01 14:41:44 +00:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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:
|
|
|
|
*/
|