2015-06-17 00:24:19 +00:00
|
|
|
/* protocol_preferences_menu.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>
|
|
|
|
#include <epan/proto.h>
|
|
|
|
|
|
|
|
#include <ui/preference_utils.h>
|
2015-10-04 17:10:29 +00:00
|
|
|
#include <wsutil/utf8_entities.h>
|
2015-06-17 00:24:19 +00:00
|
|
|
|
|
|
|
#include "protocol_preferences_menu.h"
|
|
|
|
|
2015-07-27 23:17:44 +00:00
|
|
|
#include "enabled_protocols_dialog.h"
|
2015-06-17 15:41:41 +00:00
|
|
|
#include "qt_ui_utils.h"
|
2015-06-17 00:24:19 +00:00
|
|
|
#include "uat_dialog.h"
|
|
|
|
#include "wireshark_application.h"
|
|
|
|
|
|
|
|
// To do:
|
|
|
|
// - Elide really long items?
|
2015-06-17 15:41:41 +00:00
|
|
|
// - Handle PREF_FILENAME and PREF_DIRNAME.
|
|
|
|
// - Handle color prefs.
|
2015-06-17 00:24:19 +00:00
|
|
|
|
2015-06-17 15:41:41 +00:00
|
|
|
class BoolPreferenceAction : public QAction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BoolPreferenceAction(pref_t *pref) :
|
|
|
|
QAction(NULL),
|
|
|
|
pref_(pref)
|
|
|
|
{
|
|
|
|
setText(pref_->title);
|
|
|
|
setCheckable(true);
|
|
|
|
setChecked(*pref->varp.boolp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setBoolValue() {
|
|
|
|
*pref_->varp.boolp = isChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
pref_t *pref_;
|
|
|
|
};
|
2015-06-17 00:24:19 +00:00
|
|
|
|
|
|
|
class EnumPreferenceAction : public QAction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
EnumPreferenceAction(pref_t *pref, const char *title, int enumval, QActionGroup *ag) :
|
|
|
|
QAction(NULL),
|
|
|
|
pref_(pref),
|
|
|
|
enumval_(enumval)
|
|
|
|
{
|
|
|
|
setText(title);
|
|
|
|
setActionGroup(ag);
|
|
|
|
setCheckable(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool setEnumValue() {
|
|
|
|
if (*pref_->varp.enump != enumval_) {
|
|
|
|
*pref_->varp.enump = enumval_;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
pref_t *pref_;
|
|
|
|
int enumval_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class UatPreferenceAction : public QAction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UatPreferenceAction(pref_t *pref) :
|
|
|
|
QAction(NULL),
|
|
|
|
pref_(pref)
|
|
|
|
{
|
|
|
|
setText(QString("%1" UTF8_HORIZONTAL_ELLIPSIS).arg(pref_->title));
|
|
|
|
}
|
|
|
|
|
|
|
|
void showUatDialog() {
|
|
|
|
UatDialog uat_dlg(parentWidget(), pref_->varp.uat);
|
|
|
|
uat_dlg.exec();
|
2015-08-26 18:24:29 +00:00
|
|
|
// Emitting PacketDissectionChanged directly from a QDialog can cause
|
|
|
|
// problems on OS X.
|
|
|
|
wsApp->flushAppSignals();
|
2015-06-17 00:24:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
pref_t *pref_;
|
|
|
|
};
|
|
|
|
|
2015-06-17 15:41:41 +00:00
|
|
|
// Preference requires an external editor (PreferenceEditorFrame)
|
|
|
|
class EditorPreferenceAction : public QAction
|
2015-06-17 00:24:19 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-06-17 15:41:41 +00:00
|
|
|
EditorPreferenceAction(pref_t *pref) :
|
2015-06-17 00:24:19 +00:00
|
|
|
QAction(NULL),
|
|
|
|
pref_(pref)
|
|
|
|
{
|
|
|
|
QString title = pref_->title;
|
|
|
|
|
|
|
|
switch(pref_->type) {
|
|
|
|
case PREF_UINT:
|
|
|
|
{
|
|
|
|
int base = 10;
|
|
|
|
switch(pref_->info.base) {
|
|
|
|
case 8:
|
|
|
|
base = 8;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
base = 16;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
title.append(QString(": %1" UTF8_HORIZONTAL_ELLIPSIS).arg(QString::number(*pref->varp.uint, base)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PREF_STRING:
|
|
|
|
title.append(QString(": %1" UTF8_HORIZONTAL_ELLIPSIS).arg(*pref->varp.string));
|
|
|
|
break;
|
2015-06-17 15:41:41 +00:00
|
|
|
case PREF_RANGE:
|
|
|
|
title.append(QString(": %1" UTF8_HORIZONTAL_ELLIPSIS).arg(range_to_qstring(*pref->varp.range)));
|
2015-06-17 00:24:19 +00:00
|
|
|
break;
|
|
|
|
default:
|
2015-06-17 15:41:41 +00:00
|
|
|
// We shouldn't be here.
|
2015-06-17 00:24:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
setText(title);
|
|
|
|
}
|
2015-06-17 15:41:41 +00:00
|
|
|
pref_t *pref() { return pref_; }
|
2015-06-17 00:24:19 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
pref_t *pref_;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
// Preference callback
|
|
|
|
|
|
|
|
static guint
|
|
|
|
add_prefs_menu_item(pref_t *pref, gpointer menu_ptr)
|
|
|
|
{
|
|
|
|
ProtocolPreferencesMenu *pp_menu = static_cast<ProtocolPreferencesMenu *>(menu_ptr);
|
|
|
|
if (!pp_menu) return 1;
|
|
|
|
|
|
|
|
pp_menu->addMenuItem(pref);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ProtocolPreferencesMenu::ProtocolPreferencesMenu()
|
|
|
|
{
|
|
|
|
setTitle(tr("Protocol Preferences"));
|
|
|
|
setModule(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolPreferencesMenu::setModule(const char *module_name)
|
|
|
|
{
|
|
|
|
QAction *action;
|
|
|
|
int proto_id = -1;
|
2015-07-27 23:17:44 +00:00
|
|
|
|
|
|
|
if (module_name) {
|
|
|
|
proto_id = proto_get_id_by_filter_name(module_name);
|
|
|
|
}
|
2015-06-17 00:24:19 +00:00
|
|
|
|
|
|
|
clear();
|
|
|
|
module_name_.clear();
|
|
|
|
module_ = NULL;
|
|
|
|
|
2015-07-27 23:17:44 +00:00
|
|
|
protocol_ = find_protocol_by_id(proto_id);
|
2015-07-31 23:52:37 +00:00
|
|
|
const QString long_name = proto_get_protocol_long_name(protocol_);
|
|
|
|
const QString short_name = proto_get_protocol_short_name(protocol_);
|
2015-07-27 23:17:44 +00:00
|
|
|
if (!module_name || proto_id < 0 || !protocol_) {
|
2015-06-17 00:24:19 +00:00
|
|
|
action = addAction(tr("No protocol preferences available"));
|
|
|
|
action->setDisabled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-31 23:52:37 +00:00
|
|
|
QAction *disable_action = new QAction(tr("Disable %1" UTF8_HORIZONTAL_ELLIPSIS).arg(short_name), this);
|
2015-07-27 23:17:44 +00:00
|
|
|
connect(disable_action, SIGNAL(triggered(bool)), this, SLOT(disableProtocolTriggered()));
|
|
|
|
|
2015-06-17 00:24:19 +00:00
|
|
|
module_ = prefs_find_module(module_name);
|
|
|
|
if (!module_ || !prefs_is_registered_protocol(module_name)) {
|
2015-07-31 23:52:37 +00:00
|
|
|
action = addAction(tr("%1 has no preferences").arg(long_name));
|
2015-06-17 00:24:19 +00:00
|
|
|
action->setDisabled(true);
|
2015-07-27 23:17:44 +00:00
|
|
|
addSeparator();
|
|
|
|
addAction(disable_action);
|
2015-06-17 00:24:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
module_name_ = module_name;
|
|
|
|
|
2015-07-31 23:52:37 +00:00
|
|
|
action = addAction(tr("Open %1 preferences" UTF8_HORIZONTAL_ELLIPSIS).arg(long_name));
|
2015-06-17 00:24:19 +00:00
|
|
|
action->setData(QString(module_name));
|
2015-06-17 15:41:41 +00:00
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(modulePreferencesTriggered()));
|
2015-06-17 00:24:19 +00:00
|
|
|
addSeparator();
|
|
|
|
|
|
|
|
prefs_pref_foreach(module_, add_prefs_menu_item, this);
|
2015-07-27 23:17:44 +00:00
|
|
|
|
|
|
|
if (!actions().last()->isSeparator()) {
|
|
|
|
addSeparator();
|
|
|
|
}
|
|
|
|
addAction(disable_action);
|
2015-06-17 00:24:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolPreferencesMenu::addMenuItem(preference *pref)
|
|
|
|
{
|
|
|
|
switch (pref->type) {
|
2015-06-17 15:41:41 +00:00
|
|
|
case PREF_BOOL:
|
|
|
|
{
|
|
|
|
BoolPreferenceAction *bpa = new BoolPreferenceAction(pref);
|
|
|
|
addAction(bpa);
|
|
|
|
connect(bpa, SIGNAL(triggered(bool)), this, SLOT(boolPreferenceTriggered()));
|
|
|
|
break;
|
|
|
|
}
|
2015-06-17 00:24:19 +00:00
|
|
|
case PREF_ENUM:
|
|
|
|
{
|
|
|
|
QActionGroup *ag = new QActionGroup(this);
|
|
|
|
QMenu *enum_menu = addMenu(pref->title);
|
|
|
|
for (const enum_val_t *enum_valp = pref->info.enum_info.enumvals; enum_valp->name; enum_valp++) {
|
|
|
|
EnumPreferenceAction *epa = new EnumPreferenceAction(pref, enum_valp->description, enum_valp->value, ag);
|
|
|
|
if (*pref->varp.enump == enum_valp->value) {
|
|
|
|
epa->setChecked(true);
|
|
|
|
}
|
|
|
|
enum_menu->addAction(epa);
|
|
|
|
connect(epa, SIGNAL(triggered(bool)), this, SLOT(enumPreferenceTriggered()));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-06-17 15:41:41 +00:00
|
|
|
case PREF_UINT:
|
|
|
|
case PREF_STRING:
|
|
|
|
case PREF_RANGE:
|
|
|
|
{
|
|
|
|
EditorPreferenceAction *epa = new EditorPreferenceAction(pref);
|
|
|
|
addAction(epa);
|
|
|
|
connect(epa, SIGNAL(triggered(bool)), this, SLOT(editorPreferenceTriggered()));
|
|
|
|
break;
|
|
|
|
}
|
2015-06-17 00:24:19 +00:00
|
|
|
case PREF_UAT:
|
|
|
|
{
|
|
|
|
UatPreferenceAction *upa = new UatPreferenceAction(pref);
|
|
|
|
addAction(upa);
|
|
|
|
connect(upa, SIGNAL(triggered(bool)), this, SLOT(uatPreferenceTriggered()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PREF_CUSTOM:
|
|
|
|
case PREF_STATIC_TEXT:
|
|
|
|
case PREF_OBSOLETE:
|
|
|
|
break;
|
|
|
|
default:
|
2015-06-17 15:41:41 +00:00
|
|
|
// A type we currently don't handle (e.g. PREF_FILENAME). Just open
|
|
|
|
// the prefs dialog.
|
|
|
|
QString title = QString("%1" UTF8_HORIZONTAL_ELLIPSIS).arg(pref->title);
|
|
|
|
QAction *mpa = addAction(title);
|
|
|
|
connect(mpa, SIGNAL(triggered(bool)), this, SLOT(modulePreferencesTriggered()));
|
2015-06-17 00:24:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-27 23:17:44 +00:00
|
|
|
void ProtocolPreferencesMenu::disableProtocolTriggered()
|
|
|
|
{
|
|
|
|
EnabledProtocolsDialog enable_proto_dialog(this);
|
|
|
|
enable_proto_dialog.selectProtocol(protocol_);
|
|
|
|
hide();
|
|
|
|
enable_proto_dialog.exec();
|
|
|
|
}
|
|
|
|
|
2015-06-17 15:41:41 +00:00
|
|
|
void ProtocolPreferencesMenu::modulePreferencesTriggered()
|
2015-06-17 00:24:19 +00:00
|
|
|
{
|
|
|
|
if (!module_name_.isEmpty()) {
|
|
|
|
emit showProtocolPreferences(module_name_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 15:41:41 +00:00
|
|
|
void ProtocolPreferencesMenu::editorPreferenceTriggered()
|
|
|
|
{
|
|
|
|
EditorPreferenceAction *epa = static_cast<EditorPreferenceAction *>(QObject::sender());
|
|
|
|
if (!epa) return;
|
|
|
|
|
|
|
|
if (epa->pref() && module_) {
|
|
|
|
emit editProtocolPreference(epa->pref(), module_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 00:24:19 +00:00
|
|
|
void ProtocolPreferencesMenu::boolPreferenceTriggered()
|
|
|
|
{
|
2015-06-17 15:41:41 +00:00
|
|
|
BoolPreferenceAction *bpa = static_cast<BoolPreferenceAction *>(QObject::sender());
|
|
|
|
if (!bpa) return;
|
2015-06-17 00:24:19 +00:00
|
|
|
|
2015-06-17 15:41:41 +00:00
|
|
|
bpa->setBoolValue();
|
2015-06-17 00:24:19 +00:00
|
|
|
|
|
|
|
prefs_apply(module_);
|
|
|
|
if (!prefs.gui_use_pref_save) {
|
|
|
|
prefs_main_write();
|
|
|
|
}
|
|
|
|
|
|
|
|
wsApp->emitAppSignal(WiresharkApplication::PacketDissectionChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolPreferencesMenu::enumPreferenceTriggered()
|
|
|
|
{
|
|
|
|
EnumPreferenceAction *epa = static_cast<EnumPreferenceAction *>(QObject::sender());
|
|
|
|
if (!epa) return;
|
|
|
|
|
|
|
|
if (epa->setEnumValue()) { // Changed
|
|
|
|
prefs_apply(module_);
|
|
|
|
if (!prefs.gui_use_pref_save) {
|
|
|
|
prefs_main_write();
|
|
|
|
}
|
|
|
|
|
|
|
|
wsApp->emitAppSignal(WiresharkApplication::PacketDissectionChanged);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolPreferencesMenu::uatPreferenceTriggered()
|
|
|
|
{
|
|
|
|
UatPreferenceAction *upa = static_cast<UatPreferenceAction *>(QObject::sender());
|
|
|
|
if (!upa) return;
|
|
|
|
|
|
|
|
upa->showUatDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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:
|
|
|
|
*/
|