Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
preference_manager.h
1 /* preference_manager.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9 
10 #ifndef PREFERENCE_MANAGER_H
11 #define PREFERENCE_MANAGER_H
12 
13 #include <config.h>
14 
15 #include <QObject>
16 #include <QMetaObject>
17 #include <QHash>
18 #include <QActionGroup>
19 
20 #include <ui/qt/models/pref_models.h>
21 #include <ui/qt/capture_file.h>
22 
23 class PreferenceFactory;
25 
26 class PreferenceManager : public QObject
27 {
28  Q_OBJECT
29 
30 public:
31  static PreferenceManager* instance();
32  virtual ~PreferenceManager();
33 
34  void registerType(int pref, PreferenceFactory * factory);
35  void reuseType(int pref, int reuseFor);
36  WiresharkPreference * getPreference(PrefsItem * item);
37 
38 protected:
39  explicit PreferenceManager(QObject * parent = Q_NULLPTR);
40 
41 private:
42  static QMap<int, PreferenceFactory*> & factories();
43 };
44 
45 class PreferenceFactory : public QObject
46 {
47  Q_OBJECT
48 public:
49  virtual ~PreferenceFactory();
50  virtual WiresharkPreference * create(QObject * parent = Q_NULLPTR) = 0;
51 };
52 
53 #define REGISTER_PREFERENCE_TYPE(pref_id, preference_class) \
54  class preference_class##pref_id##Factory : public PreferenceFactory { \
55  public: \
56  preference_class##pref_id##Factory() \
57  { \
58  PreferenceManager::instance()->registerType(pref_id, this); \
59  } \
60  virtual WiresharkPreference *create(QObject * parent) { \
61  WiresharkPreference * newPrefHandler = new preference_class(parent); \
62  return newPrefHandler; \
63  } \
64  }; \
65  static preference_class##pref_id##Factory global_##preference_class##pref_id##Factory;
66 
67 #endif // PREFERENCE_MANAGER_H
68 
69 /*
70  * Editor modelines
71  *
72  * Local Variables:
73  * c-basic-offset: 4
74  * tab-width: 8
75  * indent-tabs-mode: nil
76  * End:
77  *
78  * ex: set shiftwidth=4 tabstop=8 expandtab:
79  * :indentSize=4:tabSize=8:noTabs=true:
80  */
Definition: preference_manager.h:45
Definition: pref_models.h:22
Definition: wireshark_preference.h:19
Definition: preference_manager.h:26