Kerberos: add kerberos_inject_longterm_key() helper function
[wireshark-sm.git] / ui / qt / resolved_addresses_dialog.cpp
blobe450729481e9e18c0897c551c34276be682d29b8
1 /* resolved_addresses_dialog.cpp
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
10 #include "resolved_addresses_dialog.h"
11 #include <ui_resolved_addresses_dialog.h>
13 #include "config.h"
15 #include "file.h"
17 #include "epan/addr_resolv.h"
18 #include <wiretap/wtap.h>
20 #include <QMenu>
21 #include <QPushButton>
22 #include <QTextCursor>
23 #include <QSortFilterProxyModel>
25 #include "capture_file.h"
26 #include "main_application.h"
28 #include <ui/qt/models/astringlist_list_model.h>
29 #include <ui/qt/models/resolved_addresses_models.h>
31 const QString no_entries_ = QObject::tr("No entries.");
32 const QString entry_count_ = QObject::tr("%1 entries.");
34 ResolvedAddressesDialog::ResolvedAddressesDialog(QWidget *parent, QString captureFile, wtap* wth) :
35 GeometryStateDialog(parent),
36 ui(new Ui::ResolvedAddressesDialog),
37 file_name_(tr("[no file]"))
39 ui->setupUi(this);
40 setAttribute(Qt::WA_DeleteOnClose, true);
42 QStringList title_parts = QStringList() << tr("Resolved Addresses");
44 copy_bt_ = ui->buttonBox->addButton(tr("Copy"), QDialogButtonBox::ActionRole);
46 save_bt_ = ui->buttonBox->addButton(tr("Save as…"), QDialogButtonBox::ActionRole);
47 connect(save_bt_, &QPushButton::clicked, this, &ResolvedAddressesDialog::saveAs);
49 if (!captureFile.isEmpty()) {
50 file_name_ = captureFile;
51 title_parts << file_name_;
53 setWindowTitle(mainApp->windowTitleString(title_parts));
55 ui->plainTextEdit->setFont(mainApp->monospaceFont());
56 ui->plainTextEdit->setReadOnly(true);
57 ui->plainTextEdit->setWordWrapMode(QTextOption::NoWrap);
59 if (wth) {
60 // might return null
61 wtap_block_t nrb_hdr;
64 * XXX - support multiple NRBs.
66 nrb_hdr = wtap_file_get_nrb(wth);
67 if (nrb_hdr != NULL) {
68 char *str;
71 * XXX - support multiple comments.
73 if (wtap_block_get_nth_string_option_value(nrb_hdr, OPT_COMMENT, 0, &str) == WTAP_OPTTYPE_SUCCESS) {
74 comment_ = str;
79 fillBlocks();
81 ethSortModel = new AStringListListSortFilterProxyModel(this);
82 ethTypeModel = new AStringListListSortFilterProxyModel(this);
83 EthernetAddressModel * ethModel = new EthernetAddressModel(this);
84 ethSortModel->setSourceModel(ethModel);
85 ethSortModel->setColumnsToFilter(QList<int>() << 1 << 2);
86 ethSortModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
87 ethTypeModel->setSourceModel(ethSortModel);
88 ethTypeModel->setColumnToFilter(0);
89 ethTypeModel->setColumnToHide(0);
90 ui->tblAddresses->setModel(ethTypeModel);
91 ui->tblAddresses->resizeColumnsToContents();
92 ui->tblAddresses->sortByColumn(1, Qt::AscendingOrder);
93 ui->cmbDataType->addItems(ethModel->filterValues());
95 portSortModel = new AStringListListSortFilterProxyModel(this);
96 portTypeModel = new AStringListListSortFilterProxyModel(this);
97 PortsModel * portModel = new PortsModel(this);
98 portSortModel->setSourceModel(portModel);
99 portSortModel->setColumnAsNumeric(PORTS_COL_PORT);
100 portSortModel->setColumnsToFilter(QList<int>() << PORTS_COL_NAME << PORTS_COL_PROTOCOL);
101 portSortModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
102 portTypeModel->setSourceModel(portSortModel);
103 portTypeModel->setColumnToFilter(PORTS_COL_PROTOCOL);
104 portTypeModel->setColumnAsNumeric(PORTS_COL_PORT);
105 ui->tblPorts->setModel(portTypeModel);
106 ui->tblPorts->resizeColumnsToContents();
107 ui->tblPorts->sortByColumn(PORTS_COL_PORT, Qt::AscendingOrder);
108 ui->cmbPortFilterType->addItems(portModel->filterValues());
110 tabChanged(ui->tabWidget->currentIndex());
111 connect(ui->tabWidget, &QTabWidget::currentChanged, this, &ResolvedAddressesDialog::tabChanged);
114 ResolvedAddressesDialog::~ResolvedAddressesDialog()
116 delete ui;
119 void ResolvedAddressesDialog::tabChanged(int index)
121 QWidget *currentTab = ui->tabWidget->widget(index);
122 ResolvedAddressesView *addressView = nullptr;
123 if (currentTab != nullptr) {
124 addressView = currentTab->findChild<ResolvedAddressesView*>();
125 if (addressView != nullptr) {
126 QMenu* oldMenu = copy_bt_->menu();
127 copy_bt_->setMenu(addressView->createCopyMenu(false, copy_bt_));
128 if (oldMenu != nullptr) {
129 delete oldMenu;
133 foreach (QAbstractButton *button, ui->buttonBox->buttons()) {
134 if (ui->buttonBox->buttonRole(button) == QDialogButtonBox::ActionRole) {
135 button->setEnabled(addressView != nullptr);
140 void ResolvedAddressesDialog::on_cmbDataType_currentIndexChanged(int index)
142 if (! ethSortModel)
143 return;
145 QString filter = ui->cmbDataType->itemText(index);
146 if (index == 0)
148 filter.clear();
149 ethTypeModel->setFilterType(AStringListListSortFilterProxyModel::FilterNone, 0);
151 else
152 ethTypeModel->setFilterType(AStringListListSortFilterProxyModel::FilterByEquivalent, 0);
153 ethTypeModel->setFilter(filter);
156 void ResolvedAddressesDialog::on_txtSearchFilter_textChanged(QString)
158 QString filter = ui->txtSearchFilter->text();
159 if (!ethSortModel || (!filter.isEmpty() && filter.length() < 3))
160 return;
162 ethSortModel->setFilter(filter);
165 void ResolvedAddressesDialog::on_cmbPortFilterType_currentIndexChanged(int index)
167 if (! portSortModel)
168 return;
170 QString filter = ui->cmbPortFilterType->itemText(index);
171 if (index == 0)
173 filter.clear();
174 portTypeModel->setFilterType(AStringListListSortFilterProxyModel::FilterNone, PORTS_COL_PROTOCOL);
176 else
177 portTypeModel->setFilterType(AStringListListSortFilterProxyModel::FilterByEquivalent, PORTS_COL_PROTOCOL);
178 portTypeModel->setFilter(filter);
181 void ResolvedAddressesDialog::on_txtPortFilter_textChanged(QString val)
183 if (! portSortModel)
184 return;
186 portSortModel->setFilter(val);
189 void ResolvedAddressesDialog::changeEvent(QEvent *event)
191 if (0 != event)
193 switch (event->type())
195 case QEvent::LanguageChange:
196 ui->retranslateUi(this);
197 fillBlocks();
198 break;
199 default:
200 break;
203 QDialog::changeEvent(event);
206 void ResolvedAddressesDialog::fillBlocks()
208 setUpdatesEnabled(false);
209 ui->plainTextEdit->clear();
211 QString lines;
212 ui->plainTextEdit->appendPlainText(tr("# Resolved addresses found in %1").arg(file_name_));
214 if (ui->actionComment->isChecked()) {
215 lines = "\n";
216 lines.append(tr("# Comments\n#\n# "));
217 if (!comment_.isEmpty()) {
218 lines.append("\n\n");
219 lines.append(comment_);
220 lines.append("\n");
221 } else {
222 lines.append(no_entries_);
224 ui->plainTextEdit->appendPlainText(lines);
227 ui->plainTextEdit->moveCursor(QTextCursor::Start);
228 setUpdatesEnabled(true);
231 void ResolvedAddressesDialog::saveAs()
233 QWidget *currentTab = ui->tabWidget->currentWidget();
234 if (currentTab == nullptr) {
235 return;
238 ResolvedAddressesView *addressView = currentTab->findChild<ResolvedAddressesView*>();
239 if (addressView == nullptr) {
240 return;
243 addressView->saveAs();