Kerberos: add kerberos_inject_longterm_key() helper function
[wireshark-sm.git] / ui / qt / credentials_dialog.cpp
blob810e0c81b1c7fb8d51d18b9e76509ce544375fee
1 /*
2 * credentials_dialog.c
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
13 #include <config.h>
15 #include "file.h"
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>
25 #include <QClipboard>
26 #include <QMessageBox>
27 #include <QPushButton>
28 #include <QTextCursor>
29 #include <QSortFilterProxyModel>
31 class CredentialsUrlDelegate : public UrlLinkDelegate
33 public:
35 CredentialsUrlDelegate(QObject * parent) : UrlLinkDelegate(parent) {}
37 virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
39 bool ok = false;
40 int val = index.data(Qt::UserRole).toInt(&ok);
41 if (!ok || val <= 0)
42 QStyledItemDelegate::paint(painter, option, index);
43 else
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)
53 ui->setupUi(this);
54 loadGeometry();
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);
79 cf.retapPackets();
82 CredentialsDialog::~CredentialsDialog()
84 delete ui;
87 void CredentialsDialog::tapReset(void *tapdata)
89 CredentialsDialog * d = (CredentialsDialog*) tapdata;
90 d->model_->clear();
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)
102 if (!idx.isValid())
103 return;
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());
113 #else
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());
119 #endif