aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/models/decode_as_model.h
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2017-07-14 15:21:37 -0400
committerMichael Mann <mmann78@netscape.net>2017-09-16 11:11:50 +0000
commitd992e85fe8e9192cb730abf8796336d3b6d6fd50 (patch)
tree8dc40c70e01bdf3855f3e6950079bb0e28d622a5 /ui/qt/models/decode_as_model.h
parentc98a7363dafdb1a261068a3e7312e66dcdf2c329 (diff)
Refactor Decode As dialog to use a model/delegate
The model provides a lot more flexibility and abstracting the data from the view (dialog) Noticeable changes from user perspective: 1. Value column doesn't always have a combobox. If registered decode as structure doesn't support multiple values, a simple edit box is used. 2. Existing value will always be a choice (default) in the Value combobox. 3. Duplicate values in Value combobox have been removed (for things like UDP port where source port and dest. port are same) 4. When adding/copying a decode as item, only first column (table) is editable, not the whole column. 5. Separator always present in Current protocol column to distinguish "none" from rest of protocols. 6. "Current" protocol defaults to "default value" when first added to the list instead of "none". Noticeable changes from developer perspective: 1. Code is much more spread out, but most new additions (like DCE/RPC support) should be limited to the model class (maybe delegate). The dialog class probably won't change much anymore. 2. decode_as_dialog.ui is much less useful because information is provided through model and delegate. Change-Id: I70a667cab2c07d251ab370430bc51e5c1f4a3a02 Reviewed-on: https://code.wireshark.org/review/22625 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'ui/qt/models/decode_as_model.h')
-rw-r--r--ui/qt/models/decode_as_model.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/ui/qt/models/decode_as_model.h b/ui/qt/models/decode_as_model.h
new file mode 100644
index 0000000000..d2990a8867
--- /dev/null
+++ b/ui/qt/models/decode_as_model.h
@@ -0,0 +1,106 @@
+/* decode_as_model.h
+ * Data model for Decode As records.
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef DECODE_AS_MODEL_H
+#define DECODE_AS_MODEL_H
+
+#include <config.h>
+#include <glib.h>
+
+#include <QAbstractItemModel>
+#include <QList>
+
+#include "cfile.h"
+
+#include <epan/packet.h>
+
+class DecodeAsItem
+{
+public:
+ DecodeAsItem();
+ virtual ~DecodeAsItem();
+
+ const gchar* tableName_;
+ const gchar* tableUIName_;
+
+ //save our sanity and not have to worry about memory management
+ //between (lack of) persistent data in GUI and underlying data
+ uint selectorUint_;
+ QString selectorString_;
+
+ QString default_proto_;
+ QString current_proto_;
+ dissector_handle_t dissector_handle_;
+};
+
+class DecodeAsModel : public QAbstractTableModel
+{
+ Q_OBJECT
+
+public:
+ DecodeAsModel(QObject *parent, capture_file *cf = NULL);
+
+ enum DecodeAsColumn {
+ colTable = 0,
+ colSelector,
+ colType,
+ colDefault, // aka "initial"
+ colProtocol, // aka "current"
+ colDecodeAsMax //not used
+ };
+
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+ QVariant data(const QModelIndex &index, int role) const;
+ QVariant headerData(int section, Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const;
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+
+ bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
+ void fillTable();
+
+ void setDissectorHandle(const QModelIndex &index, dissector_handle_t dissector_handle);
+
+ bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
+ bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
+ bool copyRow(int dst_row, int src_row);
+
+ static QString entryString(const gchar *table_name, gpointer value);
+
+ void applyChanges();
+
+protected:
+ static void buildChangedList(const gchar *table_name, ftenum_t selector_type,
+ gpointer key, gpointer value, gpointer user_data);
+ static void buildDceRpcChangedList(gpointer data, gpointer user_data);
+ static void gatherChangedEntries(const gchar *table_name, ftenum_t selector_type,
+ gpointer key, gpointer value, gpointer user_data);
+
+
+private:
+ capture_file *cap_file_;
+ QList<DecodeAsItem *> decode_as_items_;
+ QList<QPair<const char *, guint32> > changed_uint_entries_;
+ QList<QPair<const char *, const char *> > changed_string_entries_;
+};
+
+#endif // DECODE_AS_MODEL_H