4 * Copyright 2019 - Dario Lombardo <lomato@gmail.com>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include "credentials_dialog.h"
18 #include <ui_credentials_dialog.h>
19 #include <ui/tap-credentials.h>
20 #include "main_application.h"
21 #include "ui/qt/widgets/wireshark_file_dialog.h"
22 #include "ui/qt/models/credentials_model.h"
23 #include <ui/qt/models/url_link_delegate.h>
26 #include <QMessageBox>
27 #include <QPushButton>
28 #include <QTextCursor>
29 #include <QSortFilterProxyModel>
31 class CredentialsUrlDelegate
: public UrlLinkDelegate
35 CredentialsUrlDelegate(QObject
* parent
) : UrlLinkDelegate(parent
) {}
37 virtual void paint(QPainter
*painter
, const QStyleOptionViewItem
&option
, const QModelIndex
&index
) const
40 int val
= index
.data(Qt::UserRole
).toInt(&ok
);
42 QStyledItemDelegate::paint(painter
, option
, index
);
44 UrlLinkDelegate::paint(painter
, option
, index
);
49 CredentialsDialog::CredentialsDialog(QWidget
&parent
, CaptureFile
&cf
, PacketList
*packet_list
) :
50 WiresharkDialog(parent
, cf
),
51 ui(new Ui::CredentialsDialog
)
55 packet_list_
= packet_list
;
57 model_
= new CredentialsModel(this);
58 QSortFilterProxyModel
*proxyModel
= new QSortFilterProxyModel(this);
60 proxyModel
->setSourceModel(model_
);
61 ui
->auths
->setModel(proxyModel
);
63 setWindowSubtitle(tr("Credentials"));
65 ui
->auths
->setRootIsDecorated(false);
66 ui
->auths
->setItemDelegateForColumn(CredentialsModel::COL_NUM
, new CredentialsUrlDelegate(this));
67 ui
->auths
->setItemDelegateForColumn(CredentialsModel::COL_USERNAME
, new CredentialsUrlDelegate(this));
69 ui
->auths
->resizeColumnToContents(CredentialsModel::COL_NUM
);
70 ui
->auths
->resizeColumnToContents(CredentialsModel::COL_PROTO
);
71 ui
->auths
->resizeColumnToContents(CredentialsModel::COL_USERNAME
);
73 ui
->auths
->setSortingEnabled(true);
74 ui
->auths
->sortByColumn(CredentialsModel::COL_NUM
, Qt::AscendingOrder
);
76 connect(ui
->auths
, &QTreeView::clicked
, this, &CredentialsDialog::actionGoToPacket
);
78 registerTapListener("credentials", this, "", 0, tapReset
, tapPacket
, Q_NULLPTR
);
82 CredentialsDialog::~CredentialsDialog()
87 void CredentialsDialog::tapReset(void *tapdata
)
89 CredentialsDialog
* d
= (CredentialsDialog
*) tapdata
;
93 tap_packet_status
CredentialsDialog::tapPacket(void *tapdata
, _packet_info
*, epan_dissect
*, const void *data
, tap_flags_t
)
95 CredentialsDialog
* d
= (CredentialsDialog
*) tapdata
;
96 d
->model_
->addRecord((const tap_credential_t
*)data
);
97 return TAP_PACKET_REDRAW
;
100 void CredentialsDialog::actionGoToPacket(const QModelIndex
& idx
)
105 QVariant packet_data
= idx
.data(Qt::UserRole
);
106 QVariant hf_id
= idx
.data(CredentialsModel::ColumnHFID
);
107 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
108 if (!hf_id
.canConvert
<int>())
109 hf_id
= QVariant::fromValue(0);
111 if (packet_data
.canConvert
<int>())
112 packet_list_
->goToPacket(packet_data
.toInt(), hf_id
.toInt());
114 if (!hf_id
.canConvert(QVariant::Int
))
115 hf_id
= QVariant::fromValue(0);
117 if (packet_data
.canConvert(QVariant::Int
))
118 packet_list_
->goToPacket(packet_data
.toInt(), hf_id
.toInt());