forked from osmocom/wireshark
Qt: Remove DisplayFilterMimeData
Make the mimetype for the display filter more generic, so that external programs can attach to Wireshark and users can drag and drop display filters to the program Change-Id: Id78b4dff7883e3dab879a31aad07f577d8cc4ee3 Reviewed-on: https://code.wireshark.org/review/34936 Reviewed-by: Roland Knall <rknall@gmail.com> Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl>
This commit is contained in:
parent
05e37a386e
commit
013e87a8fd
|
@ -1381,6 +1381,23 @@ Wireshark uses various mime-types for dragging dropping as well as file formats.
|
|||
This chapter gives an overview over all the mimetypes being used, as well as the
|
||||
data format in which data has to be provided for each individual mimetype.
|
||||
|
||||
If not otherwise stated, the data is encoded as a Json Object.
|
||||
|
||||
==== Display Filter
|
||||
|
||||
**MimeType**: application/vnd.wireshark.displayfilter
|
||||
|
||||
Display filters are being dragged and dropped by utilizing this mime type.
|
||||
|
||||
[source,json]
|
||||
----
|
||||
{
|
||||
"filter": "udp.port == 8080",
|
||||
"field": "udp.port",
|
||||
"description": "UDP Port"
|
||||
}
|
||||
----
|
||||
|
||||
==== Coloring Rules
|
||||
|
||||
**MimeType**: application/vnd.wireshark.coloringrules
|
||||
|
|
|
@ -71,6 +71,8 @@
|
|||
#include <QTimerEvent>
|
||||
#include <QTreeWidget>
|
||||
#include <QWindow>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include "wsutil/file_util.h"
|
||||
|
@ -669,7 +671,7 @@ void PacketList::mouseMoveEvent (QMouseEvent *event)
|
|||
if ( event->buttons() & Qt::LeftButton && curIndex.isValid() && curIndex == mouse_pressed_at_ )
|
||||
{
|
||||
ctx_column_ = curIndex.column();
|
||||
QMimeData * mimeData = nullptr;
|
||||
QMimeData * mimeData = new QMimeData();
|
||||
QWidget * content = nullptr;
|
||||
|
||||
QString filter = getFilterFromRowAndColumn(curIndex);
|
||||
|
@ -688,18 +690,22 @@ void PacketList::mouseMoveEvent (QMouseEvent *event)
|
|||
abbrev = filter;
|
||||
}
|
||||
|
||||
mimeData = new DisplayFilterMimeData(name, abbrev, filter);
|
||||
((DisplayFilterMimeData *)mimeData)->allowPlainText();
|
||||
content = new DragLabel(((DisplayFilterMimeData *)mimeData)->labelText(), this);
|
||||
mimeData->setText(filter);
|
||||
|
||||
QJsonObject filterData;
|
||||
filterData["filter"] = filter;
|
||||
filterData["name"] = abbrev;
|
||||
filterData["description"] = name;
|
||||
QMimeData * mimeData = new QMimeData();
|
||||
|
||||
mimeData->setData(WiresharkMimeData::DisplayFilterMimeType, QJsonDocument(filterData).toJson());
|
||||
content = new DragLabel(QString("%1\n%2").arg(name, abbrev), this);
|
||||
}
|
||||
else
|
||||
{
|
||||
QString text = model()->data(curIndex).toString();
|
||||
if ( ! text.isEmpty() )
|
||||
{
|
||||
mimeData = new QMimeData();
|
||||
mimeData->setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
if ( mimeData )
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
#include <QClipboard>
|
||||
#include <QWindow>
|
||||
#include <QMessageBox>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
// To do:
|
||||
// - Fix "apply as filter" behavior.
|
||||
|
@ -733,14 +735,21 @@ bool ProtoTree::eventFilter(QObject * obj, QEvent * event)
|
|||
|
||||
if ( filter.length() > 0 )
|
||||
{
|
||||
DisplayFilterMimeData * dfmd =
|
||||
new DisplayFilterMimeData(QString(finfo.headerInfo().name), QString(finfo.headerInfo().abbreviation), filter);
|
||||
dfmd->setText(toString(idx));
|
||||
QJsonObject filterData;
|
||||
filterData["filter"] = filter;
|
||||
filterData["name"] = finfo.headerInfo().abbreviation;
|
||||
filterData["description"] = finfo.headerInfo().name;
|
||||
QMimeData * mimeData = new QMimeData();
|
||||
|
||||
mimeData->setData(WiresharkMimeData::DisplayFilterMimeType, QJsonDocument(filterData).toJson());
|
||||
mimeData->setText(toString(idx));
|
||||
|
||||
QDrag * drag = new QDrag(this);
|
||||
drag->setMimeData(dfmd);
|
||||
drag->setMimeData(mimeData);
|
||||
|
||||
DragLabel * content = new DragLabel(dfmd->labelText(), this);
|
||||
QString lblTxt = QString("%1\n%2").arg(finfo.headerInfo().name, finfo.headerInfo().abbreviation);
|
||||
|
||||
DragLabel * content = new DragLabel(lblTxt, this);
|
||||
|
||||
qreal dpr = window()->windowHandle()->devicePixelRatio();
|
||||
QPixmap pixmap(content->size() * dpr);
|
||||
|
|
|
@ -12,44 +12,13 @@
|
|||
const QString WiresharkMimeData::ColoringRulesMimeType = "application/vnd.wireshark.coloringrules";
|
||||
const QString WiresharkMimeData::ColumnListMimeType = "application/vnd.wireshark.columnlist";
|
||||
const QString WiresharkMimeData::FilterListMimeType = "application/vnd.wireshark.filterlist";
|
||||
const QString WiresharkMimeData::DisplayFilterMimeType = "application/vnd.wireshark.displayfilter";
|
||||
|
||||
void WiresharkMimeData::allowPlainText()
|
||||
{
|
||||
setText(labelText());
|
||||
}
|
||||
|
||||
DisplayFilterMimeData::DisplayFilterMimeData(QString description, QString field, QString filter) :
|
||||
WiresharkMimeData(),
|
||||
description_(description),
|
||||
filter_(filter),
|
||||
field_(field)
|
||||
{}
|
||||
|
||||
QString DisplayFilterMimeData::description() const
|
||||
{
|
||||
return description_;
|
||||
}
|
||||
|
||||
QString DisplayFilterMimeData::filter() const
|
||||
{
|
||||
return filter_;
|
||||
}
|
||||
|
||||
QString DisplayFilterMimeData::field() const
|
||||
{
|
||||
return field_;
|
||||
}
|
||||
|
||||
QString DisplayFilterMimeData::labelText() const
|
||||
{
|
||||
return QString("%1\n%2").arg(description_, filter_);
|
||||
}
|
||||
|
||||
void DisplayFilterMimeData::allowPlainText()
|
||||
{
|
||||
setText(filter_);
|
||||
}
|
||||
|
||||
ToolbarEntryMimeData::ToolbarEntryMimeData(QString element, int pos) :
|
||||
WiresharkMimeData(),
|
||||
element_(element),
|
||||
|
|
|
@ -20,27 +20,7 @@ public:
|
|||
static const QString ColoringRulesMimeType;
|
||||
static const QString ColumnListMimeType;
|
||||
static const QString FilterListMimeType;
|
||||
};
|
||||
|
||||
class DisplayFilterMimeData: public WiresharkMimeData {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
DisplayFilterMimeData(QString description, QString field, QString filter);
|
||||
|
||||
QString description() const;
|
||||
QString field() const;
|
||||
QString filter() const;
|
||||
|
||||
QString labelText() const override;
|
||||
void allowPlainText() override;
|
||||
|
||||
private:
|
||||
|
||||
QString description_;
|
||||
QString filter_;
|
||||
QString field_;
|
||||
|
||||
static const QString DisplayFilterMimeType;
|
||||
};
|
||||
|
||||
class ToolbarEntryMimeData: public WiresharkMimeData {
|
||||
|
|
|
@ -40,6 +40,8 @@
|
|||
#include <QDrag>
|
||||
#include <QDropEvent>
|
||||
#include <QMimeData>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
// To do:
|
||||
// - Get rid of shortcuts and replace them with "n most recently applied filters"?
|
||||
|
@ -535,11 +537,11 @@ void DisplayFilterEdit::applyOrPrepareFilter()
|
|||
|
||||
void DisplayFilterEdit::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if ( ! event )
|
||||
if ( ! event || ! event->mimeData() )
|
||||
return;
|
||||
|
||||
if (qobject_cast<const DisplayFilterMimeData *>(event->mimeData()) ||
|
||||
qobject_cast<const ToolbarEntryMimeData *>(event->mimeData())) {
|
||||
if (qobject_cast<const ToolbarEntryMimeData *>(event->mimeData()) ||
|
||||
event->mimeData()->hasFormat(WiresharkMimeData::DisplayFilterMimeType)) {
|
||||
if ( event->source() != this )
|
||||
{
|
||||
event->setDropAction(Qt::CopyAction);
|
||||
|
@ -554,11 +556,11 @@ void DisplayFilterEdit::dragEnterEvent(QDragEnterEvent *event)
|
|||
|
||||
void DisplayFilterEdit::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
if ( ! event )
|
||||
if ( ! event || ! event->mimeData() )
|
||||
return;
|
||||
|
||||
if (qobject_cast<const DisplayFilterMimeData *>(event->mimeData()) ||
|
||||
qobject_cast<const ToolbarEntryMimeData *>(event->mimeData())) {
|
||||
if (qobject_cast<const ToolbarEntryMimeData *>(event->mimeData()) ||
|
||||
event->mimeData()->hasFormat(WiresharkMimeData::DisplayFilterMimeType)) {
|
||||
if ( event->source() != this )
|
||||
{
|
||||
event->setDropAction(Qt::CopyAction);
|
||||
|
@ -573,19 +575,26 @@ void DisplayFilterEdit::dragMoveEvent(QDragMoveEvent *event)
|
|||
|
||||
void DisplayFilterEdit::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if ( ! event )
|
||||
if ( ! event || ! event->mimeData() )
|
||||
return;
|
||||
|
||||
QString filterText = "";
|
||||
if (qobject_cast<const DisplayFilterMimeData *>(event->mimeData())) {
|
||||
const DisplayFilterMimeData * data = qobject_cast<const DisplayFilterMimeData *>(event->mimeData());
|
||||
if ( event->mimeData()->hasFormat(WiresharkMimeData::DisplayFilterMimeType) )
|
||||
{
|
||||
QByteArray jsonData = event->mimeData()->data(WiresharkMimeData::DisplayFilterMimeType);
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
|
||||
if ( ! jsonDoc.isObject() )
|
||||
return;
|
||||
|
||||
if ((QApplication::keyboardModifiers() & Qt::AltModifier))
|
||||
filterText = data->field();
|
||||
else
|
||||
filterText = data->filter();
|
||||
QJsonObject data = jsonDoc.object();
|
||||
|
||||
if ((QApplication::keyboardModifiers() & Qt::AltModifier) && data.contains("field"))
|
||||
filterText = data["field"].toString();
|
||||
else if ( data.contains("filter") )
|
||||
filterText = data["filter"].toString();
|
||||
}
|
||||
else if (qobject_cast<const ToolbarEntryMimeData *>(event->mimeData())) {
|
||||
else if (qobject_cast<const ToolbarEntryMimeData *>(event->mimeData()))
|
||||
{
|
||||
const ToolbarEntryMimeData * data = qobject_cast<const ToolbarEntryMimeData *>(event->mimeData());
|
||||
|
||||
filterText = data->filter();
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include <QMimeData>
|
||||
#include <QMouseEvent>
|
||||
#include <QWindow>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
|
||||
#define drag_drop_toolbar_action_ "drag_drop_toolbar_action_"
|
||||
|
||||
|
@ -146,7 +148,7 @@ bool DragDropToolBar::eventFilter(QObject * obj, QEvent * event)
|
|||
|
||||
void DragDropToolBar::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if ( ! event )
|
||||
if ( ! event || ! event->mimeData() )
|
||||
return;
|
||||
|
||||
if (qobject_cast<const ToolbarEntryMimeData *>(event->mimeData()))
|
||||
|
@ -157,7 +159,7 @@ void DragDropToolBar::dragEnterEvent(QDragEnterEvent *event)
|
|||
} else {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
} else if (qobject_cast<const DisplayFilterMimeData *>(event->mimeData())) {
|
||||
} else if (event->mimeData()->hasFormat(WiresharkMimeData::DisplayFilterMimeType)) {
|
||||
if ( event->source() != this )
|
||||
{
|
||||
event->setDropAction(Qt::CopyAction);
|
||||
|
@ -172,7 +174,7 @@ void DragDropToolBar::dragEnterEvent(QDragEnterEvent *event)
|
|||
|
||||
void DragDropToolBar::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
if ( ! event )
|
||||
if ( ! event || ! event->mimeData() )
|
||||
return;
|
||||
|
||||
if (qobject_cast<const ToolbarEntryMimeData *>(event->mimeData()))
|
||||
|
@ -199,7 +201,7 @@ void DragDropToolBar::dragMoveEvent(QDragMoveEvent *event)
|
|||
} else {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
} else if (qobject_cast<const DisplayFilterMimeData *>(event->mimeData())) {
|
||||
} else if (event->mimeData()->hasFormat(WiresharkMimeData::DisplayFilterMimeType)) {
|
||||
if ( event->source() != this )
|
||||
{
|
||||
event->setDropAction(Qt::CopyAction);
|
||||
|
@ -214,7 +216,7 @@ void DragDropToolBar::dragMoveEvent(QDragMoveEvent *event)
|
|||
|
||||
void DragDropToolBar::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if ( ! event )
|
||||
if ( ! event || ! event->mimeData() )
|
||||
return;
|
||||
|
||||
/* Moving items around */
|
||||
|
@ -242,20 +244,24 @@ void DragDropToolBar::dropEvent(QDropEvent *event)
|
|||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
} else if (qobject_cast<const DisplayFilterMimeData *>(event->mimeData())) {
|
||||
const DisplayFilterMimeData * data = qobject_cast<const DisplayFilterMimeData *>(event->mimeData());
|
||||
|
||||
if ( event->source() != this )
|
||||
} else if (event->mimeData()->hasFormat(WiresharkMimeData::DisplayFilterMimeType)) {
|
||||
QByteArray jsonData = event->mimeData()->data(WiresharkMimeData::DisplayFilterMimeType);
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
|
||||
if ( jsonDoc.isObject() )
|
||||
{
|
||||
event->setDropAction(Qt::CopyAction);
|
||||
event->accept();
|
||||
QJsonObject data = jsonDoc.object();
|
||||
|
||||
emit newFilterDropped(data->description(), data->filter());
|
||||
if ( event->source() != this && data.contains("description") && data.contains("filter") )
|
||||
{
|
||||
event->setDropAction(Qt::CopyAction);
|
||||
event->accept();
|
||||
|
||||
} else {
|
||||
event->acceptProposedAction();
|
||||
emit newFilterDropped(data["description"].toString(), data["filter"].toString());
|
||||
|
||||
} else {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#include <QToolTip>
|
||||
#include <QAction>
|
||||
#include <QInputDialog>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include <packet_list.h>
|
||||
|
||||
|
@ -40,10 +42,10 @@ PacketListHeader::PacketListHeader(Qt::Orientation orientation, capture_file * c
|
|||
|
||||
void PacketListHeader::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if ( ! event )
|
||||
if ( ! event || ! event->mimeData() )
|
||||
return;
|
||||
|
||||
if ( qobject_cast<const DisplayFilterMimeData *>(event->mimeData()) && event->source() != this->parent() )
|
||||
if ( event->mimeData()->hasFormat(WiresharkMimeData::DisplayFilterMimeType) && event->source() != this->parent() )
|
||||
{
|
||||
if ( event->source() != this )
|
||||
{
|
||||
|
@ -59,10 +61,10 @@ void PacketListHeader::dragEnterEvent(QDragEnterEvent *event)
|
|||
|
||||
void PacketListHeader::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
if ( ! event )
|
||||
if ( ! event || ! event->mimeData() )
|
||||
return;
|
||||
|
||||
if (qobject_cast<const DisplayFilterMimeData *>(event->mimeData()))
|
||||
if ( event->mimeData()->hasFormat(WiresharkMimeData::DisplayFilterMimeType) )
|
||||
{
|
||||
if ( event->source() != this )
|
||||
{
|
||||
|
@ -78,14 +80,20 @@ void PacketListHeader::dragMoveEvent(QDragMoveEvent *event)
|
|||
|
||||
void PacketListHeader::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if ( ! event )
|
||||
if ( ! event || ! event->mimeData() )
|
||||
return;
|
||||
|
||||
/* Moving items around */
|
||||
if (qobject_cast<const DisplayFilterMimeData *>(event->mimeData())) {
|
||||
const DisplayFilterMimeData * data = qobject_cast<const DisplayFilterMimeData *>(event->mimeData());
|
||||
if ( event->mimeData()->hasFormat(WiresharkMimeData::DisplayFilterMimeType) )
|
||||
{
|
||||
QByteArray jsonData = event->mimeData()->data(WiresharkMimeData::DisplayFilterMimeType);
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
|
||||
if ( ! jsonDoc.isObject() )
|
||||
return;
|
||||
|
||||
if ( event->source() != this )
|
||||
QJsonObject data = jsonDoc.object();
|
||||
|
||||
if ( event->source() != this && data.contains("description") && data.contains("field") )
|
||||
{
|
||||
event->setDropAction(Qt::CopyAction);
|
||||
event->accept();
|
||||
|
@ -94,7 +102,7 @@ void PacketListHeader::dropEvent(QDropEvent *event)
|
|||
if ( mw )
|
||||
{
|
||||
int idx = logicalIndexAt(event->pos());
|
||||
mw->insertColumn(data->description(), data->field(), idx);
|
||||
mw->insertColumn(data["description"].toString(), data["field"].toString(), idx);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue