aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Knall <rknall@gmail.com>2019-09-03 17:11:25 +0200
committerAnders Broman <a.broman58@gmail.com>2019-09-04 06:45:00 +0000
commitd56ad090fb13e3e88f16eead6afc629d0341f677 (patch)
tree05e4972813e640b465a67aaf926992409e397714
parentc2a7214845ba72fee39fe82f143edcccb6e54156 (diff)
Qt: in EnabledProtocolsDialog handle protocol type
Allow a selection of the list based on the protocol type. That way one can easily enable/disable for instance just heuristic protocols Change-Id: I1ee8df5d9887c764272ec55b33703855c0c91f5a Reviewed-on: https://code.wireshark.org/review/34442 Reviewed-by: Roland Knall <rknall@gmail.com> Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--docbook/release-notes.adoc2
-rw-r--r--ui/qt/enabled_protocols_dialog.cpp15
-rw-r--r--ui/qt/enabled_protocols_dialog.h1
-rw-r--r--ui/qt/enabled_protocols_dialog.ui10
-rw-r--r--ui/qt/models/enabled_protocols_model.cpp141
-rw-r--r--ui/qt/models/enabled_protocols_model.h33
6 files changed, 157 insertions, 45 deletions
diff --git a/docbook/release-notes.adoc b/docbook/release-notes.adoc
index 6448c560c1..3c9b7b2817 100644
--- a/docbook/release-notes.adoc
+++ b/docbook/release-notes.adoc
@@ -58,7 +58,7 @@ since version 3.0.0:
* Editcap can now split files on floating point intervals.
* Windows .msi packages are now https://support.microsoft.com/en-us/help/4472027/2019-sha-2-code-signing-support-requirement-for-windows-and-wsus[signed using SHA-2].
.exe installers are still dual-signed using SHA-1 and SHA-2.
-* "Enable Protocols" Dialog now only enables/disables and inverts protocols based on the set filter selection
+* "Enable Protocols" Dialog now only enables/disables and inverts protocols based on the set filter selection. Also the protocol type (standard or heuristic) may be choosen as filter value
// === Removed Features and Support
diff --git a/ui/qt/enabled_protocols_dialog.cpp b/ui/qt/enabled_protocols_dialog.cpp
index a9fdd94c86..3c69ad1c39 100644
--- a/ui/qt/enabled_protocols_dialog.cpp
+++ b/ui/qt/enabled_protocols_dialog.cpp
@@ -39,6 +39,10 @@ EnabledProtocolsDialog::EnabledProtocolsDialog(QWidget *parent) :
ui->cmbSearchType->addItem(tr("Only Protocols"), qVariantFromValue(EnabledProtocolsProxyModel::OnlyProtocol));
ui->cmbSearchType->addItem(tr("Only Description"), qVariantFromValue(EnabledProtocolsProxyModel::OnlyDescription));
+ ui->cmbProtocolType->addItem(tr("any protocol"), qVariantFromValue(EnabledProtocolItem::Any));
+ ui->cmbProtocolType->addItem(tr("non-heuristic protocols"), qVariantFromValue(EnabledProtocolItem::Standard));
+ ui->cmbProtocolType->addItem(tr("heuristic protocols"), qVariantFromValue(EnabledProtocolItem::Heuristic));
+
QTimer::singleShot(0, this, SLOT(fillTree()));
}
@@ -78,12 +82,16 @@ void EnabledProtocolsDialog::on_disable_all_button__clicked()
void EnabledProtocolsDialog::searchFilterChange()
{
EnabledProtocolsProxyModel::SearchType type = EnabledProtocolsProxyModel::EveryWhere;
+ EnabledProtocolItem::EnableProtocolType protocol = EnabledProtocolItem::Any;
QString search_re = ui->search_line_edit_->text();
if ( ui->cmbSearchType->currentData().canConvert<EnabledProtocolsProxyModel::SearchType>() )
type = ui->cmbSearchType->currentData().value<EnabledProtocolsProxyModel::SearchType>();
- proxyModel_->setFilter(search_re, type);
+ if ( ui->cmbProtocolType->currentData().canConvert<EnabledProtocolItem::EnableProtocolType>() )
+ protocol = ui->cmbProtocolType->currentData().value<EnabledProtocolItem::EnableProtocolType>();
+
+ proxyModel_->setFilter(search_re, type, protocol);
/* If items are filtered out, then filtered back in, the tree remains collapsed
Force an expansion */
ui->protocol_tree_->expandAll();
@@ -99,6 +107,11 @@ void EnabledProtocolsDialog::on_cmbSearchType_currentIndexChanged(int)
searchFilterChange();
}
+void EnabledProtocolsDialog::on_cmbProtocolType_currentIndexChanged(int)
+{
+ searchFilterChange();
+}
+
void EnabledProtocolsDialog::on_buttonBox_accepted()
{
enabled_protocols_model_->applyChanges();
diff --git a/ui/qt/enabled_protocols_dialog.h b/ui/qt/enabled_protocols_dialog.h
index e5a88d2f5e..69d6f7aa85 100644
--- a/ui/qt/enabled_protocols_dialog.h
+++ b/ui/qt/enabled_protocols_dialog.h
@@ -32,6 +32,7 @@ private slots:
void on_disable_all_button__clicked();
void on_search_line_edit__textChanged(const QString &);
void on_cmbSearchType_currentIndexChanged(int);
+ void on_cmbProtocolType_currentIndexChanged(int);
void on_buttonBox_accepted();
void on_buttonBox_helpRequested();
void fillTree();
diff --git a/ui/qt/enabled_protocols_dialog.ui b/ui/qt/enabled_protocols_dialog.ui
index 1c3baf20c5..5c81c3d33c 100644
--- a/ui/qt/enabled_protocols_dialog.ui
+++ b/ui/qt/enabled_protocols_dialog.ui
@@ -29,6 +29,16 @@
<item>
<widget class="QComboBox" name="cmbSearchType"/>
</item>
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>in</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="cmbProtocolType"/>
+ </item>
</layout>
</item>
<item>
diff --git a/ui/qt/models/enabled_protocols_model.cpp b/ui/qt/models/enabled_protocols_model.cpp
index a1f5907283..5f14d8f97b 100644
--- a/ui/qt/models/enabled_protocols_model.cpp
+++ b/ui/qt/models/enabled_protocols_model.cpp
@@ -43,8 +43,9 @@ class HeuristicTreeItem : public EnabledProtocolItem
public:
HeuristicTreeItem(heur_dtbl_entry_t *heuristic, EnabledProtocolItem* parent)
: EnabledProtocolItem(heuristic->short_name, heuristic->display_name, heuristic->enabled, parent),
- heuristic_(heuristic)
+ heuristic_table_(heuristic)
{
+ type_ = EnabledProtocolItem::Heuristic;
}
virtual ~HeuristicTreeItem() {}
@@ -52,11 +53,11 @@ public:
protected:
virtual void applyValuePrivate(gboolean value)
{
- heuristic_->enabled = value;
+ heuristic_table_->enabled = value;
}
private:
- heur_dtbl_entry_t *heuristic_;
+ heur_dtbl_entry_t *heuristic_table_;
};
@@ -65,7 +66,8 @@ EnabledProtocolItem::EnabledProtocolItem(QString name, QString description, bool
name_(name),
description_(description),
enabled_(enabled),
- enabledInit_(enabled)
+ enabledInit_(enabled),
+ type_(EnabledProtocolItem::Standard)
{
}
@@ -73,6 +75,11 @@ EnabledProtocolItem::~EnabledProtocolItem()
{
}
+EnabledProtocolItem::EnableProtocolType EnabledProtocolItem::type() const
+{
+ return type_;
+}
+
bool EnabledProtocolItem::applyValue()
{
if (enabledInit_ != enabled_) {
@@ -225,7 +232,13 @@ QVariant EnabledProtocolsModel::data(const QModelIndex &index, int role) const
break;
}
break;
+ case DATA_PROTOCOL_TYPE:
+ return qVariantFromValue(item->type());
+ break;
+ default:
+ break;
}
+
return QVariant();
}
@@ -325,11 +338,10 @@ void EnabledProtocolsModel::saveChanges(bool writeChanges)
}
-
-
EnabledProtocolsProxyModel::EnabledProtocolsProxyModel(QObject * parent)
: QSortFilterProxyModel(parent),
type_(EnabledProtocolsProxyModel::EveryWhere),
+protocolType_(EnabledProtocolItem::Any),
filter_()
{}
@@ -355,51 +367,102 @@ bool EnabledProtocolsProxyModel::lessThan(const QModelIndex &left, const QModelI
return false;
}
-bool EnabledProtocolsProxyModel::filterAcceptItem(EnabledProtocolItem& item) const
+Qt::ItemFlags EnabledProtocolsProxyModel::flags(const QModelIndex &index) const
{
- QRegExp regex(filter_, Qt::CaseInsensitive);
+ Qt::ItemFlags flags = Qt::NoItemFlags;
+ if ( index.isValid() )
+ {
+ QModelIndex source = mapToSource(index);
+ if ( filterAcceptsSelf(source.row(), source.parent() ) )
+ {
+ flags = Qt::ItemIsEnabled;
+ flags |= Qt::ItemIsSelectable;
+ flags |= Qt::ItemIsUserCheckable;
+ }
+ }
- if (item.name().contains(regex) && type_ != OnlyDescription)
+ return flags;
+}
+
+bool EnabledProtocolsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
+{
+ if ( filterAcceptsSelf(sourceRow, sourceParent) )
return true;
- if (item.description().contains(regex) && type_ != OnlyProtocol)
+#if 0
+ QModelIndex parent = sourceParent;
+ while ( parent.isValid() )
+ {
+ if ( filterAcceptsSelf(parent.row(), parent.parent()) )
+ return true;
+ parent = parent.parent();
+ }
+#endif
+
+ if ( filterAcceptsChild(sourceRow, sourceParent) )
return true;
return false;
}
-bool EnabledProtocolsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
+bool EnabledProtocolsProxyModel::filterAcceptsSelf(int sourceRow, const QModelIndex &sourceParent) const
{
QModelIndex nameIdx = sourceModel()->index(sourceRow, EnabledProtocolsModel::colProtocol, sourceParent);
+ if ( ! nameIdx.isValid() )
+ return false;
EnabledProtocolItem* item = static_cast<EnabledProtocolItem*>(nameIdx.internalPointer());
- if (item == NULL)
- return true;
+ if (! item)
+ return false;
- if (!filter_.isEmpty()) {
- if (filterAcceptItem(*item))
- return true;
+ QRegExp regex(filter_, Qt::CaseInsensitive);
- if (!nameIdx.parent().isValid())
+ if ( protocolType_ == EnabledProtocolItem::Any || protocolType_ == item->type() )
+ {
+ if ( ! filter_.isEmpty() )
{
- EnabledProtocolItem* child_item;
- for (int row = 0; row < item->childCount(); row++)
- {
- child_item = item->child(row);
- if ((child_item != NULL) && (filterAcceptItem(*child_item)))
- return true;
- }
+ if ( item->name().contains(regex) && type_ != OnlyDescription)
+ return true;
+
+ if (item->description().contains(regex) && type_ != OnlyProtocol)
+ return true;
}
+ else
+ return true;
+ }
+ return false;
+}
+
+bool EnabledProtocolsProxyModel::filterAcceptsChild(int sourceRow, const QModelIndex &sourceParent) const
+{
+ QModelIndex item = sourceModel()->index(sourceRow, EnabledProtocolsModel::colProtocol, sourceParent);
+ if ( ! item.isValid() )
return false;
+
+ int childCount = item.model()->rowCount(item);
+ if ( childCount == 0 )
+ return false;
+
+ for ( int i = 0; i < childCount; i++ )
+ {
+ if ( filterAcceptsSelf(i, item) )
+ return true;
+#if 0
+ /* Recursive search disabled for performance reasons */
+ if ( filterAcceptsChild(i, item) )
+ return true;
+#endif
}
- return true;
+ return false;
}
-void EnabledProtocolsProxyModel::setFilter(const QString& filter, EnabledProtocolsProxyModel::SearchType type)
+void EnabledProtocolsProxyModel::setFilter(const QString& filter, EnabledProtocolsProxyModel::SearchType type,
+ EnabledProtocolItem::EnableProtocolType protocolType)
{
filter_ = filter;
type_ = type;
+ protocolType_ = protocolType;
invalidateFilter();
}
@@ -415,15 +478,23 @@ void EnabledProtocolsProxyModel::setItemsEnable(EnabledProtocolsProxyModel::Enab
{
QModelIndex idx = index(row, EnabledProtocolsModel::colProtocol, parent);
- Qt::CheckState enable = idx.data(Qt::CheckStateRole).value<Qt::CheckState>();
- if ( enableType == Enable )
- enable = Qt::Checked;
- else if ( enableType == Disable )
- enable = Qt::Unchecked;
- else
- enable = enable == Qt::Checked ? Qt::Unchecked : Qt::Checked;
-
- sourceModel()->setData(mapToSource(idx), qVariantFromValue(enable), Qt::CheckStateRole);
+ QModelIndex sIdx = mapToSource(idx);
+ if ( sIdx.isValid() )
+ {
+ EnabledProtocolItem* item = static_cast<EnabledProtocolItem*>(sIdx.internalPointer());
+ if ( item && ( protocolType_ == EnabledProtocolItem::Any || protocolType_ == item->type() ) )
+ {
+ Qt::CheckState enable = idx.data(Qt::CheckStateRole).value<Qt::CheckState>();
+ if ( enableType == Enable )
+ enable = Qt::Checked;
+ else if ( enableType == Disable )
+ enable = Qt::Unchecked;
+ else
+ enable = enable == Qt::Checked ? Qt::Unchecked : Qt::Checked;
+
+ sourceModel()->setData(mapToSource(idx), qVariantFromValue(enable), Qt::CheckStateRole);
+ }
+ }
setItemsEnable(enableType, idx);
}
diff --git a/ui/qt/models/enabled_protocols_model.h b/ui/qt/models/enabled_protocols_model.h
index 89cf3baa7f..f1dd386c17 100644
--- a/ui/qt/models/enabled_protocols_model.h
+++ b/ui/qt/models/enabled_protocols_model.h
@@ -21,7 +21,15 @@
class EnabledProtocolItem : public ModelHelperTreeItem<EnabledProtocolItem>
{
+ Q_GADGET
public:
+ enum EnableProtocolType{
+ Any,
+ Standard,
+ Heuristic
+ };
+ Q_ENUM(EnableProtocolType)
+
EnabledProtocolItem(QString name, QString description, bool enabled, EnabledProtocolItem* parent);
virtual ~EnabledProtocolItem();
@@ -30,6 +38,8 @@ public:
bool enabled() const {return enabled_;}
void setEnabled(bool enable) {enabled_ = enable;}
+ EnableProtocolType type() const;
+
bool applyValue();
protected:
@@ -39,6 +49,7 @@ protected:
QString description_;
bool enabled_;
bool enabledInit_; //value that model starts with to determine change
+ EnableProtocolType type_;
};
class EnabledProtocolsModel : public QAbstractItemModel
@@ -56,7 +67,8 @@ public:
};
enum EnableProtocolData {
- DATA_ENABLE = Qt::UserRole
+ DATA_ENABLE = Qt::UserRole,
+ DATA_PROTOCOL_TYPE
};
QModelIndex index(int row, int column,
@@ -97,12 +109,6 @@ public:
};
Q_ENUM(SearchType)
- explicit EnabledProtocolsProxyModel(QObject * parent = Q_NULLPTR);
-
- virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
-
- void setFilter(const QString& filter, EnabledProtocolsProxyModel::SearchType type);
-
enum EnableType
{
Enable,
@@ -110,15 +116,26 @@ public:
Invert
};
+ explicit EnabledProtocolsProxyModel(QObject * parent = Q_NULLPTR);
+
+ virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
+ virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
+
+ void setFilter(const QString& filter, EnabledProtocolsProxyModel::SearchType type,
+ EnabledProtocolItem::EnableProtocolType protocolType);
+
void setItemsEnable(EnabledProtocolsProxyModel::EnableType enable, QModelIndex parent = QModelIndex());
protected:
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
- bool filterAcceptItem(EnabledProtocolItem& item) const;
private:
EnabledProtocolsProxyModel::SearchType type_;
+ EnabledProtocolItem::EnableProtocolType protocolType_;
QString filter_;
+
+ bool filterAcceptsSelf(int sourceRow, const QModelIndex &sourceParent) const;
+ bool filterAcceptsChild(int sourceRow, const QModelIndex &sourceParent) const;
};
#endif // ENABLED_PROTOCOLS_MODEL_H