2015-06-17 15:41:41 +00:00
|
|
|
/* preference_editor_frame.h
|
|
|
|
*
|
|
|
|
* 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/prefs.h>
|
|
|
|
#include <epan/prefs-int.h>
|
2016-10-07 20:25:01 +00:00
|
|
|
#include <epan/decode_as.h>
|
2015-06-17 15:41:41 +00:00
|
|
|
|
|
|
|
#include <ui/preference_utils.h>
|
2016-10-07 20:25:01 +00:00
|
|
|
#include <ui/simple_dialog.h>
|
2015-06-17 15:41:41 +00:00
|
|
|
|
|
|
|
#include "preference_editor_frame.h"
|
2015-06-25 16:17:03 +00:00
|
|
|
#include <ui_preference_editor_frame.h>
|
2015-06-17 15:41:41 +00:00
|
|
|
|
2017-07-25 14:15:18 +00:00
|
|
|
#include <ui/qt/utils/qt_ui_utils.h>
|
2016-02-25 09:15:32 +00:00
|
|
|
#include <wsutil/utf8_entities.h>
|
2015-06-17 15:41:41 +00:00
|
|
|
|
2015-09-04 19:49:11 +00:00
|
|
|
#include "wireshark_application.h"
|
|
|
|
|
2015-12-01 14:41:44 +00:00
|
|
|
#include <QPushButton>
|
2017-09-18 17:20:50 +00:00
|
|
|
#include <QKeyEvent>
|
2015-12-01 14:41:44 +00:00
|
|
|
|
2015-06-17 15:41:41 +00:00
|
|
|
// To do:
|
2017-04-14 09:33:57 +00:00
|
|
|
// - Handle PREF_SAVE_FILENAME, PREF_OPEN_FILENAME and PREF_DIRNAME.
|
2015-06-17 15:41:41 +00:00
|
|
|
|
|
|
|
PreferenceEditorFrame::PreferenceEditorFrame(QWidget *parent) :
|
|
|
|
AccordionFrame(parent),
|
|
|
|
ui(new Ui::PreferenceEditorFrame),
|
|
|
|
module_(NULL),
|
2015-09-04 19:49:11 +00:00
|
|
|
pref_(NULL),
|
2015-11-26 15:26:38 +00:00
|
|
|
new_uint_(0),
|
|
|
|
new_str_(""),
|
2015-09-04 19:49:11 +00:00
|
|
|
new_range_(NULL)
|
2015-06-17 15:41:41 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2016-02-18 19:48:23 +00:00
|
|
|
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
foreach (QWidget *w, findChildren<QWidget *>()) {
|
|
|
|
w->setAttribute(Qt::WA_MacSmallSize, true);
|
|
|
|
}
|
|
|
|
#endif
|
2015-06-17 15:41:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PreferenceEditorFrame::~PreferenceEditorFrame()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreferenceEditorFrame::editPreference(preference *pref, pref_module *module)
|
|
|
|
{
|
|
|
|
pref_ = pref;
|
|
|
|
module_ = module;
|
|
|
|
|
|
|
|
if (!pref || !module) {
|
|
|
|
hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-25 09:15:32 +00:00
|
|
|
ui->modulePreferencesToolButton->setText(tr("Open %1 preferences" UTF8_HORIZONTAL_ELLIPSIS).arg(module_->title));
|
2015-06-17 15:41:41 +00:00
|
|
|
|
|
|
|
pref_stash(pref_, NULL);
|
2017-01-07 13:52:23 +00:00
|
|
|
ui->preferenceTitleLabel->setText(QString("%1:").arg(prefs_get_title(pref)));
|
2015-06-17 15:41:41 +00:00
|
|
|
|
|
|
|
// Convert the pref description from plain text to rich text.
|
2017-01-07 13:52:23 +00:00
|
|
|
QString description = html_escape(prefs_get_description(pref));
|
2015-06-17 15:41:41 +00:00
|
|
|
description.replace('\n', "<br>");
|
|
|
|
QString tooltip = QString("<span>%1</span>").arg(description);
|
|
|
|
ui->preferenceTitleLabel->setToolTip(tooltip);
|
|
|
|
ui->preferenceLineEdit->setToolTip(tooltip);
|
|
|
|
|
|
|
|
ui->preferenceLineEdit->clear();
|
|
|
|
ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Empty);
|
2017-01-25 19:28:34 +00:00
|
|
|
disconnect(ui->preferenceLineEdit, 0, 0, 0);
|
2015-06-17 15:41:41 +00:00
|
|
|
|
|
|
|
bool show = false;
|
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
switch (prefs_get_type(pref_)) {
|
2015-06-17 15:41:41 +00:00
|
|
|
case PREF_UINT:
|
2017-01-25 09:38:49 +00:00
|
|
|
case PREF_DECODE_AS_UINT:
|
2017-01-25 19:28:34 +00:00
|
|
|
connect(ui->preferenceLineEdit, SIGNAL(textChanged(QString)),
|
2015-06-17 15:41:41 +00:00
|
|
|
this, SLOT(uintLineEditTextEdited(QString)));
|
|
|
|
show = true;
|
|
|
|
break;
|
|
|
|
case PREF_STRING:
|
2017-01-25 19:28:34 +00:00
|
|
|
connect(ui->preferenceLineEdit, SIGNAL(textChanged(QString)),
|
2015-06-17 15:41:41 +00:00
|
|
|
this, SLOT(stringLineEditTextEdited(QString)));
|
|
|
|
show = true;
|
|
|
|
break;
|
|
|
|
case PREF_RANGE:
|
2017-01-25 09:38:49 +00:00
|
|
|
case PREF_DECODE_AS_RANGE:
|
2017-01-25 19:28:34 +00:00
|
|
|
connect(ui->preferenceLineEdit, SIGNAL(textChanged(QString)),
|
2015-06-17 15:41:41 +00:00
|
|
|
this, SLOT(rangeLineEditTextEdited(QString)));
|
|
|
|
show = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show) {
|
|
|
|
ui->preferenceLineEdit->setText(gchar_free_to_qstring(prefs_pref_to_str(pref_, pref_stashed)).remove(QRegExp("\n\t")));
|
|
|
|
animatedShow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreferenceEditorFrame::uintLineEditTextEdited(const QString &new_str)
|
|
|
|
{
|
|
|
|
if (new_str.isEmpty()) {
|
2017-01-07 13:52:23 +00:00
|
|
|
new_uint_ = prefs_get_uint_value_real(pref_, pref_stashed);
|
2015-06-17 15:41:41 +00:00
|
|
|
ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Empty);
|
2015-12-01 14:41:44 +00:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
2015-06-17 15:41:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok;
|
2015-09-04 19:49:11 +00:00
|
|
|
uint new_uint = new_str.toUInt(&ok, 0);
|
2015-06-17 15:41:41 +00:00
|
|
|
if (ok) {
|
|
|
|
new_uint_ = new_uint;
|
|
|
|
ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Valid);
|
|
|
|
} else {
|
2017-01-07 13:52:23 +00:00
|
|
|
new_uint_ = prefs_get_uint_value_real(pref_, pref_stashed);
|
2015-06-17 15:41:41 +00:00
|
|
|
ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Invalid);
|
|
|
|
}
|
2015-12-01 14:41:44 +00:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok);
|
2015-06-17 15:41:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreferenceEditorFrame::stringLineEditTextEdited(const QString &new_str)
|
|
|
|
{
|
|
|
|
new_str_ = new_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreferenceEditorFrame::rangeLineEditTextEdited(const QString &new_str)
|
|
|
|
{
|
|
|
|
range_t *new_range = NULL;
|
|
|
|
|
2017-01-07 13:52:23 +00:00
|
|
|
convert_ret_t ret = range_convert_str(NULL, &new_range, new_str.toUtf8().constData(), prefs_get_max_value(pref_));
|
2016-12-22 20:12:27 +00:00
|
|
|
wmem_free(NULL, new_range_);
|
2015-06-17 15:41:41 +00:00
|
|
|
new_range_ = new_range;
|
|
|
|
|
|
|
|
if (ret == CVT_NO_ERROR) {
|
|
|
|
if (new_str.isEmpty()) {
|
|
|
|
ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Empty);
|
|
|
|
} else {
|
|
|
|
ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Valid);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Invalid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-08 20:35:11 +00:00
|
|
|
void PreferenceEditorFrame::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
ui->preferenceLineEdit->setFocus();
|
|
|
|
ui->preferenceLineEdit->selectAll();
|
|
|
|
|
|
|
|
AccordionFrame::showEvent(event);
|
|
|
|
}
|
|
|
|
|
2015-06-17 15:41:41 +00:00
|
|
|
void PreferenceEditorFrame::on_modulePreferencesToolButton_clicked()
|
|
|
|
{
|
|
|
|
if (module_) {
|
|
|
|
QString module_name = module_->name;
|
|
|
|
emit showProtocolPreferences(module_name);
|
|
|
|
}
|
2016-02-19 18:25:36 +00:00
|
|
|
on_buttonBox_rejected();
|
2015-06-17 15:41:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreferenceEditorFrame::on_preferenceLineEdit_returnPressed()
|
|
|
|
{
|
2015-12-01 14:41:44 +00:00
|
|
|
if (ui->buttonBox->button(QDialogButtonBox::Ok)->isEnabled()) {
|
|
|
|
on_buttonBox_accepted();
|
2015-06-17 15:41:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-01 14:41:44 +00:00
|
|
|
void PreferenceEditorFrame::on_buttonBox_accepted()
|
2015-06-17 15:41:41 +00:00
|
|
|
{
|
|
|
|
bool apply = false;
|
2017-01-07 13:52:23 +00:00
|
|
|
switch(prefs_get_type(pref_)) {
|
2015-06-17 15:41:41 +00:00
|
|
|
case PREF_UINT:
|
2017-01-25 09:38:49 +00:00
|
|
|
case PREF_DECODE_AS_UINT:
|
2017-01-07 13:52:23 +00:00
|
|
|
apply = prefs_set_uint_value(pref_, new_uint_, pref_stashed);
|
2015-06-17 15:41:41 +00:00
|
|
|
break;
|
|
|
|
case PREF_STRING:
|
2017-01-07 13:52:23 +00:00
|
|
|
apply = prefs_set_string_value(pref_, new_str_.toStdString().c_str(), pref_stashed);
|
2015-06-17 15:41:41 +00:00
|
|
|
break;
|
|
|
|
case PREF_RANGE:
|
2017-01-25 09:38:49 +00:00
|
|
|
case PREF_DECODE_AS_RANGE:
|
2017-01-07 13:52:23 +00:00
|
|
|
apply = prefs_set_range_value(pref_, new_range_, pref_stashed);
|
2015-06-17 15:41:41 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (apply && module_) {
|
2016-10-07 20:25:01 +00:00
|
|
|
pref_unstash_data_t unstashed_data;
|
|
|
|
|
|
|
|
unstashed_data.module = module_;
|
|
|
|
unstashed_data.handle_decode_as = TRUE;
|
|
|
|
|
|
|
|
pref_unstash(pref_, &unstashed_data);
|
2015-06-17 15:41:41 +00:00
|
|
|
prefs_apply(module_);
|
|
|
|
if (!prefs.gui_use_pref_save) {
|
2016-10-07 20:25:01 +00:00
|
|
|
gchar* err = NULL;
|
|
|
|
|
2015-06-17 15:41:41 +00:00
|
|
|
prefs_main_write();
|
2016-10-07 20:25:01 +00:00
|
|
|
|
|
|
|
if (save_decode_as_entries(&err) < 0)
|
|
|
|
{
|
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err);
|
|
|
|
g_free(err);
|
|
|
|
}
|
2015-06-17 15:41:41 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-01 14:41:44 +00:00
|
|
|
on_buttonBox_rejected();
|
2015-09-04 19:49:11 +00:00
|
|
|
// Emit signals once UI is hidden
|
|
|
|
if (apply) {
|
|
|
|
wsApp->emitAppSignal(WiresharkApplication::PacketDissectionChanged);
|
|
|
|
wsApp->emitAppSignal(WiresharkApplication::PreferencesChanged);
|
|
|
|
}
|
2015-06-17 15:41:41 +00:00
|
|
|
}
|
|
|
|
|
2015-12-01 14:41:44 +00:00
|
|
|
void PreferenceEditorFrame::on_buttonBox_rejected()
|
2015-06-17 15:41:41 +00:00
|
|
|
{
|
|
|
|
pref_ = NULL;
|
|
|
|
module_ = NULL;
|
2016-12-22 20:12:27 +00:00
|
|
|
wmem_free(NULL, new_range_);
|
2015-06-17 15:41:41 +00:00
|
|
|
new_range_ = NULL;
|
|
|
|
animatedHide();
|
|
|
|
}
|
|
|
|
|
2017-09-18 17:20:50 +00:00
|
|
|
void PreferenceEditorFrame::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->preferenceLineEdit->syntaxState() == SyntaxLineEdit::Invalid) {
|
|
|
|
emit pushFilterSyntaxStatus(tr("Invalid value."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-24 18:17:55 +00:00
|
|
|
|
|
|
|
AccordionFrame::keyPressEvent(event);
|
2017-09-18 17:20:50 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 15:41:41 +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:
|
|
|
|
*/
|