summaryrefslogtreecommitdiffstats
path: root/ui/qt/manager/preference_manager.cpp
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/preference_manager.cpp
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/preference_manager.cpp')
-rw-r--r--ui/qt/manager/preference_manager.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/ui/qt/manager/preference_manager.cpp b/ui/qt/manager/preference_manager.cpp
new file mode 100644
index 00000000..28cfe42a
--- /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;
+}