Qt: Add manager for preference dialog
Abstract out the different types of preferences into a visitor and factory pattern to handle the preference dialog. Change-Id: Ia611ec192dcc1ad638a997182cec1ab5bdb7859c Reviewed-on: https://code.wireshark.org/review/25142 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
parent
1e16be7556
commit
1a07d97fd7
|
@ -46,11 +46,17 @@ set(WIRESHARK_WIDGET_HEADERS
|
|||
widgets/overlay_scroll_bar.h
|
||||
widgets/pref_module_view.h
|
||||
widgets/qcustomplot.h
|
||||
widgets/range_syntax_lineedit.h
|
||||
widgets/stock_icon_tool_button.h
|
||||
widgets/syntax_line_edit.h
|
||||
widgets/tabnav_tree_view.h
|
||||
)
|
||||
|
||||
set(WIRESHARK_MANAGER_HEADERS
|
||||
manager/preference_manager.h
|
||||
manager/wireshark_preference.h
|
||||
)
|
||||
|
||||
set(WIRESHARK_UTILS_HEADERS
|
||||
utils/color_utils.h
|
||||
utils/data_printer.h
|
||||
|
@ -272,11 +278,17 @@ set(WIRESHARK_WIDGET_SRCS
|
|||
widgets/overlay_scroll_bar.cpp
|
||||
widgets/pref_module_view.cpp
|
||||
widgets/qcustomplot.cpp
|
||||
widgets/range_syntax_lineedit.cpp
|
||||
widgets/stock_icon_tool_button.cpp
|
||||
widgets/syntax_line_edit.cpp
|
||||
widgets/tabnav_tree_view.cpp
|
||||
)
|
||||
|
||||
set(WIRESHARK_MANAGER_SRCS
|
||||
manager/preference_manager.cpp
|
||||
manager/wireshark_preference.cpp
|
||||
)
|
||||
|
||||
set(WIRESHARK_UTILS_SRCS
|
||||
utils/color_utils.cpp
|
||||
utils/data_printer.cpp
|
||||
|
@ -660,16 +672,20 @@ source_group("ui\\Utils Headers Files" FILES ${WIRESHARK_UTILS_HEADERS})
|
|||
source_group("ui\\Utils Source" FILES ${WIRESHARK_UTILS_SRCS})
|
||||
source_group("ui\\Models Headers" FILES ${WIRESHARK_MODEL_HEADERS})
|
||||
source_group("ui\\Models Source" FILES ${WIRESHARK_MODEL_SRCS})
|
||||
source_group("ui\\Manager Headers" FILES ${WIRESHARK_MANAGER_HEADERS})
|
||||
source_group("ui\\Manager Source" FILES ${WIRESHARK_MANAGER_SRCS})
|
||||
|
||||
add_library(qtui STATIC
|
||||
#Included so that Visual Studio can properly put header files in solution
|
||||
${WIRESHARK_QT_HEADERS}
|
||||
${WIRESHARK_WIDGET_HEADERS}
|
||||
${WIRESHARK_MANAGER_HEADERS}
|
||||
${WIRESHARK_UTILS_HEADERS}
|
||||
${WIRESHARK_MODEL_HEADERS}
|
||||
|
||||
${WIRESHARK_QT_SRC}
|
||||
${WIRESHARK_WIDGET_SRCS}
|
||||
${WIRESHARK_MANAGER_SRCS}
|
||||
${WIRESHARK_UTILS_SRCS}
|
||||
${WIRESHARK_MODEL_SRCS}
|
||||
|
||||
|
|
|
@ -175,11 +175,18 @@ MOC_WIDGET_HDRS = \
|
|||
widgets/label_stack.h \
|
||||
widgets/overlay_scroll_bar.h \
|
||||
widgets/pref_module_view.h \
|
||||
widgets/range_syntax_lineedit.h \
|
||||
widgets/syntax_line_edit.h \
|
||||
widgets/stock_icon_tool_button.h \
|
||||
widgets/tabnav_tree_view.h \
|
||||
widgets/qcustomplot.h
|
||||
|
||||
|
||||
# Files that are general manager classes with
|
||||
MOC_MANAGER_HDRS = \
|
||||
manager/preference_manager.h \
|
||||
manager/wireshark_preference.h
|
||||
|
||||
# Files that are utility classes with multi-purpose, but no widgets
|
||||
MOC_UTILS_HDRS = \
|
||||
utils/color_utils.h \
|
||||
|
@ -351,6 +358,7 @@ MOC_HDRS = \
|
|||
wireshark_dialog.h \
|
||||
wlan_statistics_dialog.h \
|
||||
$(MOC_WIDGET_HDRS) \
|
||||
$(MOC_MANAGER_HDRS) \
|
||||
$(MOC_UTILS_HDRS) \
|
||||
$(MOC_MODELS_HDRS)
|
||||
|
||||
|
@ -516,10 +524,16 @@ WIRESHARK_QT_WIDGET_SRC = \
|
|||
widgets/overlay_scroll_bar.cpp \
|
||||
widgets/pref_module_view.cpp \
|
||||
widgets/stock_icon_tool_button.cpp \
|
||||
widgets/range_syntax_lineedit.cpp \
|
||||
widgets/syntax_line_edit.cpp \
|
||||
widgets/tabnav_tree_view.cpp \
|
||||
widgets/qcustomplot.cpp
|
||||
|
||||
# Files that are general manager classes with
|
||||
WIRESHARK_QT_MANAGER_SRC = \
|
||||
manager/preference_manager.cpp \
|
||||
manager/wireshark_preference.cpp
|
||||
|
||||
WIRESHARK_QT_UTILS_SRC = \
|
||||
utils/color_utils.cpp \
|
||||
utils/data_printer.cpp \
|
||||
|
@ -676,6 +690,7 @@ WIRESHARK_QT_SRC = \
|
|||
wireshark_dialog.cpp \
|
||||
$(WIRESHARK_QT_WIDGET_SRC) \
|
||||
$(WIRESHARK_QT_UTILS_SRC) \
|
||||
$(WIRESHARK_QT_MANAGER_SRC) \
|
||||
${WIRESHARK_QT_MODELS_SRCS}
|
||||
|
||||
WIRESHARK_QT_TAP_SRC = \
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/* preference_manager.cpp
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <ui/qt/manager/preference_manager.h>
|
||||
#include <ui/qt/manager/wireshark_preference.h>
|
||||
|
||||
#include <QMetaMethod>
|
||||
|
||||
PreferenceFactory::~PreferenceFactory() {}
|
||||
|
||||
QMap<int, PreferenceFactory *> PreferenceManager::factories;
|
||||
|
||||
PreferenceManager::PreferenceManager(QObject * parent)
|
||||
: QObject(parent)
|
||||
{}
|
||||
|
||||
PreferenceManager::~PreferenceManager()
|
||||
{
|
||||
/* As this is a singleton, this is the point, where we can clear the registry */
|
||||
PreferenceManager::factories.clear();
|
||||
}
|
||||
|
||||
PreferenceManager * PreferenceManager::instance()
|
||||
{
|
||||
static PreferenceManager* _inst = 0;
|
||||
if ( ! _inst )
|
||||
_inst = new PreferenceManager();
|
||||
|
||||
return _inst;
|
||||
}
|
||||
|
||||
void PreferenceManager::registerType(int pref, PreferenceFactory * factory)
|
||||
{
|
||||
Q_ASSERT(pref >= 0);
|
||||
|
||||
if ( PreferenceManager::factories.contains(pref) || ! factory )
|
||||
return;
|
||||
|
||||
PreferenceManager::factories[pref] = factory;
|
||||
}
|
||||
|
||||
WiresharkPreference * PreferenceManager::getPreference(PrefsItem * pref)
|
||||
{
|
||||
if ( ! pref )
|
||||
return Q_NULLPTR;
|
||||
|
||||
int key = pref->getPrefType();
|
||||
if ( ! PreferenceManager::factories.contains(key) )
|
||||
return Q_NULLPTR;
|
||||
|
||||
/* All actions are parented with this manager, to clear the objects together with the manager */
|
||||
WiresharkPreference * wspref = qobject_cast<WiresharkPreference *>(PreferenceManager::factories[key]->create(this));
|
||||
if ( wspref )
|
||||
wspref->setPrefsItem(pref);
|
||||
|
||||
return wspref;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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:
|
||||
*/
|
|
@ -0,0 +1,80 @@
|
|||
/* preference_manager.h
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*/
|
||||
|
||||
#ifndef PREFERENCE_MANAGER_H
|
||||
#define PREFERENCE_MANAGER_H
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QMetaObject>
|
||||
#include <QHash>
|
||||
#include <QActionGroup>
|
||||
|
||||
#include <ui/qt/models/pref_models.h>
|
||||
#include <ui/qt/capture_file.h>
|
||||
|
||||
class PreferenceFactory;
|
||||
class WiresharkPreference;
|
||||
|
||||
class PreferenceManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static PreferenceManager* instance();
|
||||
virtual ~PreferenceManager();
|
||||
|
||||
void registerType(int pref, PreferenceFactory * factory);
|
||||
void reuseType(int pref, int reuseFor);
|
||||
WiresharkPreference * getPreference(PrefsItem * item);
|
||||
|
||||
protected:
|
||||
explicit PreferenceManager(QObject * parent = Q_NULLPTR);
|
||||
|
||||
private:
|
||||
static QMap<int, PreferenceFactory*> factories;
|
||||
};
|
||||
|
||||
class PreferenceFactory : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual ~PreferenceFactory();
|
||||
virtual WiresharkPreference * create(QObject * parent = Q_NULLPTR) = 0;
|
||||
};
|
||||
|
||||
#define REGISTER_PREFERENCE_TYPE(pref_id, preference_class) \
|
||||
class preference_class##pref_id##Factory : public PreferenceFactory { \
|
||||
public: \
|
||||
preference_class##pref_id##Factory() \
|
||||
{ \
|
||||
PreferenceManager::instance()->registerType(pref_id, this); \
|
||||
} \
|
||||
virtual WiresharkPreference *create(QObject * parent) { \
|
||||
WiresharkPreference * newPrefHandler = new preference_class(parent); \
|
||||
return newPrefHandler; \
|
||||
} \
|
||||
}; \
|
||||
static preference_class##pref_id##Factory global_##preference_class##pref_id##Factory;
|
||||
|
||||
#endif // PREFERENCE_MANAGER_H
|
||||
|
||||
/*
|
||||
* 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:
|
||||
*/
|
|
@ -0,0 +1,241 @@
|
|||
/* wireshark_preference.cpp
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <epan/prefs.h>
|
||||
#include <epan/prefs-int.h>
|
||||
|
||||
#include <ui/qt/manager/wireshark_preference.h>
|
||||
#include <ui/qt/manager/preference_manager.h>
|
||||
#include <ui/qt/widgets/range_syntax_lineedit.h>
|
||||
#include <ui/qt/wireshark_application.h>
|
||||
#include <ui/qt/uat_dialog.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QLineEdit>
|
||||
#include <QComboBox>
|
||||
#include <QColorDialog>
|
||||
|
||||
WiresharkPreference::WiresharkPreference(QObject * parent) : QObject(parent)
|
||||
{}
|
||||
|
||||
QWidget * WiresharkPreference::editor(QWidget * /*parent*/, const QStyleOptionViewItem &/*option*/, const QModelIndex &/*index*/)
|
||||
{
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
|
||||
void WiresharkPreference::setData(QWidget */*editor*/, const QModelIndex &/*index*/) {}
|
||||
void WiresharkPreference::setModelData(QWidget */*editor*/, QAbstractItemModel */*model*/, const QModelIndex &/*index*/) {}
|
||||
|
||||
void WiresharkPreference::setPrefsItem(PrefsItem * item)
|
||||
{
|
||||
_prefsItem = item;
|
||||
}
|
||||
|
||||
PrefsItem * WiresharkPreference::prefsItem() const
|
||||
{
|
||||
return _prefsItem;
|
||||
}
|
||||
|
||||
class BoolPreference : public WiresharkPreference
|
||||
{
|
||||
public:
|
||||
BoolPreference(QObject * parent = Q_NULLPTR) : WiresharkPreference(parent) {}
|
||||
virtual QWidget * editor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index)
|
||||
{
|
||||
((QAbstractItemModel*)index.model())->setData(index, QString("BOOL"), Qt::EditRole);
|
||||
return WiresharkPreference::editor(parent, option, index);
|
||||
};
|
||||
};
|
||||
REGISTER_PREFERENCE_TYPE(PREF_BOOL, BoolPreference);
|
||||
|
||||
class StringPreference : public WiresharkPreference
|
||||
{
|
||||
public:
|
||||
StringPreference(QObject * parent = Q_NULLPTR) : WiresharkPreference(parent) {}
|
||||
virtual QWidget * editor(QWidget *parent, const QStyleOptionViewItem &/*option*/, const QModelIndex &/*index*/)
|
||||
{
|
||||
return new QLineEdit(parent);
|
||||
};
|
||||
|
||||
virtual void setData(QWidget *editor, const QModelIndex &index)
|
||||
{
|
||||
QLineEdit* line = static_cast<QLineEdit*>(editor);
|
||||
line->setText(index.model()->data(index, Qt::DisplayRole).toString());
|
||||
};
|
||||
|
||||
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index)
|
||||
{
|
||||
QLineEdit* line = static_cast<QLineEdit*>(editor);
|
||||
model->setData(index, line->text(), Qt::EditRole);
|
||||
};
|
||||
};
|
||||
REGISTER_PREFERENCE_TYPE(PREF_STRING, StringPreference);
|
||||
|
||||
class UIntPreference : public StringPreference
|
||||
{
|
||||
public:
|
||||
UIntPreference(QObject * parent = Q_NULLPTR) : StringPreference(parent) {}
|
||||
};
|
||||
REGISTER_PREFERENCE_TYPE(PREF_UINT, UIntPreference);
|
||||
REGISTER_PREFERENCE_TYPE(PREF_DECODE_AS_UINT, UIntPreference);
|
||||
|
||||
class EnumPreference : public WiresharkPreference
|
||||
{
|
||||
public:
|
||||
EnumPreference(QObject * parent = Q_NULLPTR) : WiresharkPreference(parent) {}
|
||||
virtual QWidget * editor(QWidget *parent, const QStyleOptionViewItem &/*option*/, const QModelIndex &/*index*/)
|
||||
{
|
||||
return new QComboBox(parent);
|
||||
};
|
||||
|
||||
virtual void setData(QWidget *editor, const QModelIndex &index)
|
||||
{
|
||||
QComboBox* combo = static_cast<QComboBox*>(editor);
|
||||
const enum_val_t *ev;
|
||||
PrefsItem* pref = VariantPointer<PrefsItem>::asPtr(index.model()->data(index, Qt::UserRole));
|
||||
for (ev = prefs_get_enumvals(pref->getPref()); ev && ev->description; ev++) {
|
||||
combo->addItem(ev->description, QVariant(ev->value));
|
||||
if (prefs_get_enum_value(pref->getPref(), pref_stashed) == ev->value)
|
||||
combo->setCurrentIndex(combo->count() - 1);
|
||||
}
|
||||
};
|
||||
|
||||
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index)
|
||||
{
|
||||
QComboBox* combo = static_cast<QComboBox*>(editor);
|
||||
model->setData(index, combo->itemData(combo->currentIndex()), Qt::EditRole);
|
||||
};
|
||||
};
|
||||
REGISTER_PREFERENCE_TYPE(PREF_ENUM, EnumPreference);
|
||||
|
||||
class RangePreference : public WiresharkPreference
|
||||
{
|
||||
public:
|
||||
RangePreference(QObject * parent = Q_NULLPTR) : WiresharkPreference(parent) {}
|
||||
virtual QWidget * editor(QWidget *parent, const QStyleOptionViewItem &/*option*/, const QModelIndex &/*index*/)
|
||||
{
|
||||
return new RangeSyntaxLineEdit(parent);
|
||||
};
|
||||
|
||||
virtual void setData(QWidget *editor, const QModelIndex &index)
|
||||
{
|
||||
RangeSyntaxLineEdit* syntax = static_cast<RangeSyntaxLineEdit*>(editor);
|
||||
syntax->setText(index.model()->data(index, Qt::DisplayRole).toString());
|
||||
};
|
||||
|
||||
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index)
|
||||
{
|
||||
RangeSyntaxLineEdit* syntax = static_cast<RangeSyntaxLineEdit*>(editor);
|
||||
model->setData(index, syntax->text(), Qt::EditRole);
|
||||
};
|
||||
};
|
||||
REGISTER_PREFERENCE_TYPE(PREF_RANGE, RangePreference);
|
||||
REGISTER_PREFERENCE_TYPE(PREF_DECODE_AS_RANGE, RangePreference);
|
||||
|
||||
class ColorPreference : public WiresharkPreference
|
||||
{
|
||||
public:
|
||||
ColorPreference(QObject * parent = Q_NULLPTR) : WiresharkPreference(parent) {}
|
||||
virtual QWidget * editor(QWidget * parent, const QStyleOptionViewItem &option, const QModelIndex &index)
|
||||
{
|
||||
QColorDialog color_dlg;
|
||||
color_t color = *prefs_get_color_value(prefsItem()->getPref(), pref_stashed);
|
||||
|
||||
color_dlg.setCurrentColor(QColor(
|
||||
color.red >> 8,
|
||||
color.green >> 8,
|
||||
color.blue >> 8
|
||||
));
|
||||
if (color_dlg.exec() == QDialog::Accepted)
|
||||
((QAbstractItemModel*)index.model())->setData(index, color_dlg.currentColor().name(), Qt::EditRole);
|
||||
|
||||
return WiresharkPreference::editor(parent, option, index);
|
||||
};
|
||||
};
|
||||
REGISTER_PREFERENCE_TYPE(PREF_COLOR, ColorPreference);
|
||||
|
||||
class SaveFilePreference : public WiresharkPreference
|
||||
{
|
||||
public:
|
||||
SaveFilePreference(QObject * parent = Q_NULLPTR) : WiresharkPreference(parent) {}
|
||||
virtual QWidget * editor(QWidget * parent, const QStyleOptionViewItem &option, const QModelIndex &index)
|
||||
{
|
||||
QString filename = QFileDialog::getSaveFileName(parent, wsApp->windowTitleString(prefs_get_title(prefsItem()->getPref())),
|
||||
index.model()->data(index, Qt::DisplayRole).toString());
|
||||
if (!filename.isEmpty()) {
|
||||
((QAbstractItemModel*)index.model())->setData(index, QDir::toNativeSeparators(filename), Qt::EditRole);
|
||||
}
|
||||
return WiresharkPreference::editor(parent, option, index);
|
||||
};
|
||||
};
|
||||
REGISTER_PREFERENCE_TYPE(PREF_SAVE_FILENAME, SaveFilePreference);
|
||||
|
||||
class OpenFilePreference : public WiresharkPreference
|
||||
{
|
||||
public:
|
||||
OpenFilePreference(QObject * parent = Q_NULLPTR) : WiresharkPreference(parent) {}
|
||||
virtual QWidget * editor(QWidget * parent, const QStyleOptionViewItem &option, const QModelIndex &index)
|
||||
{
|
||||
QString filename = QFileDialog::getOpenFileName(parent, wsApp->windowTitleString(prefs_get_title(prefsItem()->getPref())),
|
||||
index.model()->data(index, Qt::DisplayRole).toString());
|
||||
if (!filename.isEmpty()) {
|
||||
((QAbstractItemModel*)index.model())->setData(index, QDir::toNativeSeparators(filename), Qt::EditRole);
|
||||
}
|
||||
return WiresharkPreference::editor(parent, option, index);
|
||||
};
|
||||
};
|
||||
REGISTER_PREFERENCE_TYPE(PREF_OPEN_FILENAME, OpenFilePreference);
|
||||
|
||||
class DirNamePreference : public WiresharkPreference
|
||||
{
|
||||
public:
|
||||
DirNamePreference(QObject * parent = Q_NULLPTR) : WiresharkPreference(parent) {}
|
||||
virtual QWidget * editor(QWidget * parent, const QStyleOptionViewItem &option, const QModelIndex &index)
|
||||
{
|
||||
QString filename = QFileDialog::getExistingDirectory(parent, wsApp->windowTitleString(prefs_get_title(prefsItem()->getPref())),
|
||||
index.model()->data(index, Qt::DisplayRole).toString());
|
||||
if (!filename.isEmpty()) {
|
||||
((QAbstractItemModel*)index.model())->setData(index, QDir::toNativeSeparators(filename), Qt::EditRole);
|
||||
}
|
||||
return WiresharkPreference::editor(parent, option, index);
|
||||
};
|
||||
};
|
||||
REGISTER_PREFERENCE_TYPE(PREF_DIRNAME, DirNamePreference);
|
||||
|
||||
class UatPreference : public WiresharkPreference
|
||||
{
|
||||
public:
|
||||
UatPreference(QObject * parent = Q_NULLPTR) : WiresharkPreference(parent) {}
|
||||
virtual QWidget * editor(QWidget * parent, const QStyleOptionViewItem &option, const QModelIndex &index)
|
||||
{
|
||||
if (prefsItem()->getPrefGUIType() == GUI_ALL || prefsItem()->getPrefGUIType() == GUI_QT) {
|
||||
UatDialog uat_dlg(parent, prefs_get_uat_value(prefsItem()->getPref()));
|
||||
uat_dlg.exec();
|
||||
}
|
||||
return WiresharkPreference::editor(parent, option, index);
|
||||
};
|
||||
};
|
||||
REGISTER_PREFERENCE_TYPE(PREF_UAT, UatPreference);
|
||||
|
||||
|
||||
/*
|
||||
* 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:
|
||||
*/
|
|
@ -0,0 +1,39 @@
|
|||
/* wireshark_preference.h
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*/
|
||||
|
||||
#ifndef WIRESHARK_PREFERENCE_H
|
||||
#define WIRESHARK_PREFERENCE_H
|
||||
|
||||
#include <ui/qt/models/pref_models.h>
|
||||
|
||||
#include <QStyleOptionViewItem>
|
||||
#include <QModelIndex>
|
||||
#include <QWidget>
|
||||
|
||||
class WiresharkPreference : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Q_INVOKABLE WiresharkPreference(QObject * parent = Q_NULLPTR);
|
||||
|
||||
virtual QWidget * editor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index);
|
||||
virtual void setData(QWidget *editor, const QModelIndex &index);
|
||||
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index);
|
||||
|
||||
void setPrefsItem(PrefsItem *);
|
||||
|
||||
protected:
|
||||
PrefsItem * prefsItem() const;
|
||||
|
||||
private:
|
||||
PrefsItem * _prefsItem;
|
||||
|
||||
};
|
||||
|
||||
#endif // WIRESHARK_PREFERENCE_H
|
|
@ -11,43 +11,8 @@
|
|||
#include <ui/qt/models/pref_delegate.h>
|
||||
#include <epan/prefs-int.h>
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QFileDialog>
|
||||
#include <QLineEdit>
|
||||
#include <QColorDialog>
|
||||
|
||||
#include "uat_dialog.h"
|
||||
#include "wireshark_application.h"
|
||||
|
||||
#include <ui/qt/widgets/editor_file_dialog.h>
|
||||
|
||||
RangeSyntaxLineEdit::RangeSyntaxLineEdit(QWidget *parent)
|
||||
: SyntaxLineEdit(parent),
|
||||
maxRange_(0xFFFFFFFF)
|
||||
{
|
||||
connect(this, SIGNAL(textChanged(QString)), this, SLOT(checkRange(QString)));
|
||||
}
|
||||
|
||||
void RangeSyntaxLineEdit::checkRange(QString range)
|
||||
{
|
||||
if (range.isEmpty()) {
|
||||
setSyntaxState(SyntaxLineEdit::Empty);
|
||||
return;
|
||||
}
|
||||
|
||||
range_t *newrange;
|
||||
convert_ret_t ret = range_convert_str(NULL, &newrange, range.toUtf8().constData(), maxRange_);
|
||||
|
||||
if (ret == CVT_NO_ERROR) {
|
||||
setSyntaxState(SyntaxLineEdit::Valid);
|
||||
wmem_free(NULL, newrange);
|
||||
} else {
|
||||
setSyntaxState(SyntaxLineEdit::Invalid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include <ui/qt/manager/preference_manager.h>
|
||||
#include <ui/qt/manager/wireshark_preference.h>
|
||||
|
||||
AdvancedPrefDelegate::AdvancedPrefDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
||||
{
|
||||
|
@ -76,185 +41,42 @@ QWidget *AdvancedPrefDelegate::createEditor(QWidget *parent, const QStyleOptionV
|
|||
break;
|
||||
case AdvancedPrefsModel::colValue:
|
||||
pref = indexToPref(index);
|
||||
switch(pref->getPrefType())
|
||||
{
|
||||
case PREF_DECODE_AS_UINT:
|
||||
case PREF_UINT:
|
||||
{
|
||||
QLineEdit* editor = new QLineEdit(parent);
|
||||
#if 0
|
||||
//XXX - Do we want some help handling formatting the number?
|
||||
editor->setInputMask("0000000009;");
|
||||
#endif
|
||||
return editor;
|
||||
}
|
||||
case PREF_BOOL:
|
||||
//Setting any non-NULL value will invert boolean value
|
||||
((QAbstractItemModel*)index.model())->setData(index, QString("BOOL"), Qt::EditRole);
|
||||
break;
|
||||
case PREF_ENUM:
|
||||
{
|
||||
QComboBox* editor = new QComboBox(parent);
|
||||
return editor;
|
||||
}
|
||||
case PREF_STRING:
|
||||
{
|
||||
//Separated from UINT in case formatting needs to be applied to UINT
|
||||
QLineEdit* editor = new QLineEdit(parent);
|
||||
return editor;
|
||||
}
|
||||
case PREF_DECODE_AS_RANGE:
|
||||
case PREF_RANGE:
|
||||
{
|
||||
RangeSyntaxLineEdit *editor = new RangeSyntaxLineEdit(parent);
|
||||
return editor;
|
||||
}
|
||||
case PREF_UAT:
|
||||
{
|
||||
if (pref->getPrefGUIType() == GUI_ALL || pref->getPrefGUIType() == GUI_QT) {
|
||||
UatDialog uat_dlg(parent, prefs_get_uat_value(pref->getPref()));
|
||||
uat_dlg.exec();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PREF_SAVE_FILENAME:
|
||||
filename = QFileDialog::getSaveFileName(parent, wsApp->windowTitleString(prefs_get_title(pref->getPref())),
|
||||
index.model()->data(index, Qt::DisplayRole).toString());
|
||||
if (!filename.isEmpty()) {
|
||||
((QAbstractItemModel*)index.model())->setData(index, QDir::toNativeSeparators(filename), Qt::EditRole);
|
||||
}
|
||||
break;
|
||||
case PREF_OPEN_FILENAME:
|
||||
filename = QFileDialog::getOpenFileName(parent, wsApp->windowTitleString(prefs_get_title(pref->getPref())),
|
||||
index.model()->data(index, Qt::DisplayRole).toString());
|
||||
if (!filename.isEmpty()) {
|
||||
((QAbstractItemModel*)index.model())->setData(index, QDir::toNativeSeparators(filename), Qt::EditRole);
|
||||
}
|
||||
break;
|
||||
case PREF_DIRNAME:
|
||||
filename = QFileDialog::getExistingDirectory(parent, wsApp->windowTitleString(prefs_get_title(pref->getPref())),
|
||||
index.model()->data(index, Qt::DisplayRole).toString());
|
||||
if (!filename.isEmpty()) {
|
||||
((QAbstractItemModel*)index.model())->setData(index, QDir::toNativeSeparators(filename), Qt::EditRole);
|
||||
}
|
||||
break;
|
||||
case PREF_COLOR:
|
||||
{
|
||||
QColorDialog color_dlg;
|
||||
color_t color = *prefs_get_color_value(pref->getPref(), pref_stashed);
|
||||
|
||||
color_dlg.setCurrentColor(QColor(
|
||||
color.red >> 8,
|
||||
color.green >> 8,
|
||||
color.blue >> 8
|
||||
));
|
||||
if (color_dlg.exec() == QDialog::Accepted) {
|
||||
((QAbstractItemModel*)index.model())->setData(index, color_dlg.currentColor().name(), Qt::EditRole);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
WiresharkPreference * wspref = PreferenceManager::instance()->getPreference(pref);
|
||||
if ( wspref )
|
||||
return wspref->editor(parent, option, index);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
|
||||
void AdvancedPrefDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||
{
|
||||
PrefsItem* pref = indexToPref(index);
|
||||
|
||||
switch(pref->getPrefType())
|
||||
WiresharkPreference * wspref = PreferenceManager::instance()->getPreference(pref);
|
||||
if ( wspref )
|
||||
{
|
||||
case PREF_DECODE_AS_UINT:
|
||||
case PREF_UINT:
|
||||
{
|
||||
QLineEdit* line = static_cast<QLineEdit*>(editor);
|
||||
line->setText(index.model()->data(index, Qt::DisplayRole).toString());
|
||||
}
|
||||
break;
|
||||
case PREF_ENUM:
|
||||
{
|
||||
QComboBox* combo = static_cast<QComboBox*>(editor);
|
||||
const enum_val_t *ev;
|
||||
PrefsItem* pref = VariantPointer<PrefsItem>::asPtr(index.model()->data(index, Qt::UserRole));
|
||||
for (ev = prefs_get_enumvals(pref->getPref()); ev && ev->description; ev++) {
|
||||
combo->addItem(ev->description, QVariant(ev->value));
|
||||
if (prefs_get_enum_value(pref->getPref(), pref_stashed) == ev->value)
|
||||
combo->setCurrentIndex(combo->count() - 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PREF_STRING:
|
||||
{
|
||||
QLineEdit* line = static_cast<QLineEdit*>(editor);
|
||||
line->setText(index.model()->data(index, Qt::DisplayRole).toString());
|
||||
}
|
||||
break;
|
||||
case PREF_DECODE_AS_RANGE:
|
||||
case PREF_RANGE:
|
||||
{
|
||||
RangeSyntaxLineEdit* syntax = static_cast<RangeSyntaxLineEdit*>(editor);
|
||||
syntax->setText(index.model()->data(index, Qt::DisplayRole).toString());
|
||||
}
|
||||
break;
|
||||
case PREF_UAT:
|
||||
case PREF_SAVE_FILENAME:
|
||||
case PREF_OPEN_FILENAME:
|
||||
case PREF_DIRNAME:
|
||||
case PREF_COLOR:
|
||||
//Handled by the dialogs created
|
||||
break;
|
||||
default:
|
||||
//Ensure any new preference types are handled
|
||||
Q_ASSERT(FALSE);
|
||||
break;
|
||||
wspref->setData(editor, index);
|
||||
return;
|
||||
}
|
||||
|
||||
Q_ASSERT(FALSE);
|
||||
}
|
||||
|
||||
void AdvancedPrefDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
PrefsItem* pref = indexToPref(index);
|
||||
switch(pref->getPrefType())
|
||||
|
||||
WiresharkPreference * wspref = PreferenceManager::instance()->getPreference(pref);
|
||||
if ( wspref )
|
||||
{
|
||||
case PREF_DECODE_AS_UINT:
|
||||
case PREF_UINT:
|
||||
case PREF_STRING:
|
||||
{
|
||||
QLineEdit* line = static_cast<QLineEdit*>(editor);
|
||||
model->setData(index, line->text(), Qt::EditRole);
|
||||
break;
|
||||
}
|
||||
case PREF_ENUM:
|
||||
{
|
||||
QComboBox* combo = static_cast<QComboBox*>(editor);
|
||||
model->setData(index, combo->itemData(combo->currentIndex()), Qt::EditRole);
|
||||
}
|
||||
break;
|
||||
case PREF_DECODE_AS_RANGE:
|
||||
case PREF_RANGE:
|
||||
{
|
||||
RangeSyntaxLineEdit* syntax = static_cast<RangeSyntaxLineEdit*>(editor);
|
||||
model->setData(index, syntax->text(), Qt::EditRole);
|
||||
break;
|
||||
}
|
||||
case PREF_UAT:
|
||||
//do nothing because UAT values aren't shown in table
|
||||
break;
|
||||
case PREF_SAVE_FILENAME:
|
||||
case PREF_OPEN_FILENAME:
|
||||
case PREF_DIRNAME:
|
||||
case PREF_COLOR:
|
||||
//do nothing, dialog signals will update table
|
||||
pref = NULL;
|
||||
break;
|
||||
default:
|
||||
//Ensure any new preference types are handled
|
||||
Q_ASSERT(FALSE);
|
||||
break;
|
||||
wspref->setModelData(editor, model, index);
|
||||
return;
|
||||
}
|
||||
|
||||
Q_ASSERT(FALSE);
|
||||
}
|
||||
|
||||
/* * Editor modelines
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include <config.h>
|
||||
|
||||
#include <ui/qt/models/pref_models.h>
|
||||
#include <ui/qt/widgets/syntax_line_edit.h>
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QModelIndex>
|
||||
|
@ -36,19 +35,17 @@ private:
|
|||
PrefsItem* indexToPref(const QModelIndex &index) const;
|
||||
};
|
||||
|
||||
//Utility class for range preferences
|
||||
class RangeSyntaxLineEdit : public SyntaxLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RangeSyntaxLineEdit(QWidget *parent = 0);
|
||||
void setMaxRange(unsigned int max) {maxRange_ = max;}
|
||||
|
||||
public slots:
|
||||
void checkRange(QString range);
|
||||
|
||||
private:
|
||||
unsigned int maxRange_;
|
||||
};
|
||||
|
||||
#endif // PREF_DELEGATE_H
|
||||
|
||||
/*
|
||||
* 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:
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/* range_syntax_lineedit.cpp
|
||||
* Delegates for editing prefereneces.
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*/
|
||||
|
||||
#include <ui/qt/widgets/range_syntax_lineedit.h>
|
||||
|
||||
#include <epan/range.h>
|
||||
|
||||
RangeSyntaxLineEdit::RangeSyntaxLineEdit(QWidget *parent)
|
||||
: SyntaxLineEdit(parent),
|
||||
maxRange_(0xFFFFFFFF)
|
||||
{
|
||||
connect(this, SIGNAL(textChanged(QString)), this, SLOT(checkRange(QString)));
|
||||
}
|
||||
|
||||
void RangeSyntaxLineEdit::setMaxRange(unsigned int max)
|
||||
{
|
||||
maxRange_ = max;
|
||||
}
|
||||
|
||||
void RangeSyntaxLineEdit::checkRange(QString range)
|
||||
{
|
||||
if (range.isEmpty()) {
|
||||
setSyntaxState(SyntaxLineEdit::Empty);
|
||||
return;
|
||||
}
|
||||
|
||||
range_t *newrange;
|
||||
convert_ret_t ret = range_convert_str(NULL, &newrange, range.toUtf8().constData(), maxRange_);
|
||||
|
||||
if (ret == CVT_NO_ERROR) {
|
||||
setSyntaxState(SyntaxLineEdit::Valid);
|
||||
wmem_free(NULL, newrange);
|
||||
} else {
|
||||
setSyntaxState(SyntaxLineEdit::Invalid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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:
|
||||
*/
|
|
@ -0,0 +1,45 @@
|
|||
/* range_syntax_lineedit.h
|
||||
* Delegates for editing prefereneces.
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*/
|
||||
|
||||
#ifndef RANGE_SYNTAX_LINEEDIT_H
|
||||
#define RANGE_SYNTAX_LINEEDIT_H
|
||||
|
||||
#include <ui/qt/widgets/syntax_line_edit.h>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class RangeSyntaxLineEdit : public SyntaxLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RangeSyntaxLineEdit(QWidget *parent = 0);
|
||||
void setMaxRange(unsigned int max);
|
||||
|
||||
public slots:
|
||||
void checkRange(QString range);
|
||||
|
||||
private:
|
||||
unsigned int maxRange_;
|
||||
};
|
||||
|
||||
#endif // RANGE_SYNTAX_LINEEDIT_H
|
||||
|
||||
/*
|
||||
* 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:
|
||||
*/
|
Loading…
Reference in New Issue