Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
enabled_protocols_model.h
1 /* enabled_protocols_model.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 ENABLED_PROTOCOLS_MODEL_H
11 #define ENABLED_PROTOCOLS_MODEL_H
12 
13 #include <config.h>
14 
15 #include <ui/qt/models/tree_model_helpers.h>
16 
17 #include <epan/proto.h>
18 
19 #include <QAbstractItemModel>
20 #include <QSortFilterProxyModel>
21 
22 class EnabledProtocolItem : public ModelHelperTreeItem<EnabledProtocolItem>
23 {
24 public:
25  EnabledProtocolItem(QString name, QString description, bool enabled, EnabledProtocolItem* parent);
26  virtual ~EnabledProtocolItem();
27 
28  QString name() const {return name_;}
29  QString description() const {return description_;}
30  bool enabled() const {return enabled_;}
31  void setEnabled(bool enable) {enabled_ = enable;}
32 
33  bool applyValue();
34 
35 protected:
36  virtual void applyValuePrivate(gboolean value) = 0;
37 
38  QString name_;
39  QString description_;
40  bool enabled_;
41  bool enabledInit_; //value that model starts with to determine change
42 };
43 
44 class EnabledProtocolsModel : public QAbstractItemModel
45 {
46  Q_OBJECT
47 
48 public:
49  explicit EnabledProtocolsModel(QObject * parent = Q_NULLPTR);
50  virtual ~EnabledProtocolsModel();
51 
52  enum EnabledProtocolsColumn {
53  colProtocol = 0,
54  colDescription,
55  colLast
56  };
57 
58  QModelIndex index(int row, int column,
59  const QModelIndex & = QModelIndex()) const;
60  QModelIndex parent(const QModelIndex &) const;
61  Qt::ItemFlags flags(const QModelIndex &index) const;
62  QVariant data(const QModelIndex &index, int role) const;
63  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
64 
65  QVariant headerData(int section, Qt::Orientation orientation,
66  int role = Qt::DisplayRole) const;
67 
68  int rowCount(const QModelIndex &parent = QModelIndex()) const;
69  int columnCount(const QModelIndex &parent = QModelIndex()) const;
70 
71  void populate();
72  void invertEnabled();
73  void enableAll();
74  void disableAll();
75 
76  void applyChanges(bool writeChanges = true);
77  static void disableProtocol(struct _protocol *protocol);
78 
79 protected:
80  static void saveChanges(bool writeChanges = true);
81 
82 private:
83  EnabledProtocolItem* root_;
84 };
85 
86 class EnabledProtocolsProxyModel : public QSortFilterProxyModel
87 {
88  Q_OBJECT
89 public:
90 
91  explicit EnabledProtocolsProxyModel(QObject * parent = Q_NULLPTR);
92 
93  virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
94 
95  void setFilter(const QString& filter);
96 
97 protected:
98  bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
99  bool filterAcceptItem(EnabledProtocolItem& item) const;
100 
101 private:
102 
103  QString filter_;
104 };
105 
106 #endif // ENABLED_PROTOCOLS_MODEL_H
107 
108 /*
109  * Editor modelines
110  *
111  * Local Variables:
112  * c-basic-offset: 4
113  * tab-width: 8
114  * indent-tabs-mode: nil
115  * End:
116  *
117  * ex: set shiftwidth=4 tabstop=8 expandtab:
118  * :indentSize=4:tabSize=8:noTabs=true:
119  */
Definition: enabled_protocols_model.h:22
Definition: tree_model_helpers.h:22
Definition: enabled_protocols_model.h:86
Definition: enabled_protocols_model.h:44
Definition: proto.c:312