summaryrefslogtreecommitdiffstats
path: root/ui/qt/manager
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:34:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:34:10 +0000
commite4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc (patch)
tree68cb5ef9081156392f1dd62a00c6ccc1451b93df /ui/qt/manager
parentInitial commit. (diff)
downloadwireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.tar.xz
wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.zip
Adding upstream version 4.2.2.upstream/4.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ui/qt/manager')
-rw-r--r--ui/qt/manager/preference_manager.cpp70
-rw-r--r--ui/qt/manager/preference_manager.h64
-rw-r--r--ui/qt/manager/wireshark_preference.cpp248
-rw-r--r--ui/qt/manager/wireshark_preference.h38
4 files changed, 420 insertions, 0 deletions
diff --git a/ui/qt/manager/preference_manager.cpp b/ui/qt/manager/preference_manager.cpp
new file mode 100644
index 0000000..28cfe42
--- /dev/null
+++ b/ui/qt/manager/preference_manager.cpp
@@ -0,0 +1,70 @@
+/* preference_manager.cpp
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#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()
+{
+ static QMap<int, PreferenceFactory *> inst = QMap<int, PreferenceFactory *>();
+ return inst;
+}
+
+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));
+ WiresharkPreference * wspref = PreferenceManager::factories()[key]->create(this);
+ if (wspref)
+ wspref->setPrefsItem(pref);
+
+ return wspref;
+}
diff --git a/ui/qt/manager/preference_manager.h b/ui/qt/manager/preference_manager.h
new file mode 100644
index 0000000..030e0fa
--- /dev/null
+++ b/ui/qt/manager/preference_manager.h
@@ -0,0 +1,64 @@
+/** @file
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#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
+{
+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
+{
+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
diff --git a/ui/qt/manager/wireshark_preference.cpp b/ui/qt/manager/wireshark_preference.cpp
new file mode 100644
index 0000000..cca87c7
--- /dev/null
+++ b/ui/qt/manager/wireshark_preference.cpp
@@ -0,0 +1,248 @@
+/* wireshark_preference.cpp
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#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/widgets/wireshark_file_dialog.h"
+#include <ui/qt/main_application.h>
+#include <ui/qt/uat_dialog.h>
+
+#include <QDir>
+#include <QLineEdit>
+#include <QComboBox>
+#include <QColorDialog>
+
+WiresharkPreference::WiresharkPreference(QObject * parent) : QObject(parent), _prefsItem(NULL)
+{}
+
+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)
+ {
+ const_cast<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)
+REGISTER_PREFERENCE_TYPE(PREF_CUSTOM, StringPreference)
+
+class PasswordPreference : public StringPreference
+{
+public:
+ PasswordPreference(QObject * parent = Q_NULLPTR) : StringPreference(parent) {}
+ virtual QWidget * editor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index)
+ {
+ QLineEdit *le = static_cast<QLineEdit *>(StringPreference::editor(parent, option, index));
+
+ le->setEchoMode(QLineEdit::PasswordEchoOnEdit);
+ return le;
+ }
+};
+REGISTER_PREFERENCE_TYPE(PREF_PASSWORD, PasswordPreference)
+
+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 = new QColorDialog(parent);
+ color_dlg->setWindowModality(Qt::ApplicationModal);
+ color_dlg->show();
+ return color_dlg;
+ }
+
+ virtual void setData(QWidget *editor, const QModelIndex &index)
+ {
+ QColorDialog* color_dlg = static_cast<QColorDialog*>(editor);
+ QColor color = QColor("#" + index.model()->data(index, Qt::DisplayRole).toString());
+ color_dlg->setCurrentColor(color);
+ }
+
+ virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index)
+ {
+ QColorDialog* color_dlg = static_cast<QColorDialog*>(editor);
+ if (color_dlg->result() == QDialog::Accepted) {
+ model->setData(index, color_dlg->currentColor().name(), Qt::EditRole);
+ }
+ }
+};
+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 = WiresharkFileDialog::getSaveFileName(parent, mainApp->windowTitleString(prefs_get_title(prefsItem()->getPref())),
+ index.model()->data(index, Qt::DisplayRole).toString());
+ if (!filename.isEmpty()) {
+ const_cast<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 = WiresharkFileDialog::getOpenFileName(parent, mainApp->windowTitleString(prefs_get_title(prefsItem()->getPref())),
+ index.model()->data(index, Qt::DisplayRole).toString());
+ if (!filename.isEmpty()) {
+ const_cast<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 = WiresharkFileDialog::getExistingDirectory(parent, mainApp->windowTitleString(prefs_get_title(prefsItem()->getPref())),
+ index.model()->data(index, Qt::DisplayRole).toString());
+ if (!filename.isEmpty()) {
+ const_cast<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)
+ {
+ 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)
diff --git a/ui/qt/manager/wireshark_preference.h b/ui/qt/manager/wireshark_preference.h
new file mode 100644
index 0000000..a71939d
--- /dev/null
+++ b/ui/qt/manager/wireshark_preference.h
@@ -0,0 +1,38 @@
+/** @file
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#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
+{
+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