diff options
author | Gerald Combs <gerald@wireshark.org> | 2015-10-01 10:18:56 -0700 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2015-10-01 21:11:47 +0000 |
commit | 77a918188267f8f45bc9f51aa81bb24ee27765c5 (patch) | |
tree | e20d4a2747646ad7076f17bb168a5f0c709d06ce /ui/qt/supported_protocols_dialog.cpp | |
parent | cf3d279e046053aa39846f108ad4769189211bda (diff) | |
download | wireshark-77a918188267f8f45bc9f51aa81bb24ee27765c5.tar.gz |
Add the supported protocols internals dialog.
Includes a bonus search field.
Change-Id: I0b101b725d531a59c8a2fdbfbf4690b507135546
Reviewed-on: https://code.wireshark.org/review/10731
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui/qt/supported_protocols_dialog.cpp')
-rw-r--r-- | ui/qt/supported_protocols_dialog.cpp | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/ui/qt/supported_protocols_dialog.cpp b/ui/qt/supported_protocols_dialog.cpp new file mode 100644 index 0000000000..0a1930794d --- /dev/null +++ b/ui/qt/supported_protocols_dialog.cpp @@ -0,0 +1,136 @@ +/* supported_protocols_dialog.cpp + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "supported_protocols_dialog.h" +#include "ui_supported_protocols_dialog.h" + +#include "config.h" + +#include <glib.h> + +#include <epan/proto.h> + +#include <QTreeWidgetItem> +#include <QElapsedTimer> + +#include "wireshark_application.h" + +enum { name_col_, filter_col_, type_col_, descr_col_ }; + +SupportedProtocolsDialog::SupportedProtocolsDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SupportedProtocolsDialog), + field_count_(0) +{ + ui->setupUi(this); + setWindowTitle(wsApp->windowTitleString(tr("Supported Protocols"))); + + // XXX Use recent settings instead + if (parent) resize(parent->width() * 3 / 4, parent->height()); + + // Some of our names are unreasonably long. + int one_em = fontMetrics().height(); + ui->protoTreeWidget->setColumnWidth(name_col_, one_em * 15); + ui->protoTreeWidget->setColumnWidth(filter_col_, one_em * 10); + ui->protoTreeWidget->setColumnWidth(type_col_, one_em * 12); + ui->protoTreeWidget->setColumnWidth(descr_col_, one_em * 30); + + QTimer::singleShot(0, this, SLOT(fillTree())); +} + +SupportedProtocolsDialog::~SupportedProtocolsDialog() +{ + delete ui; +} + +void SupportedProtocolsDialog::updateStatistics() +{ + QLocale locale = QLocale::system(); + QString hint = tr("%1 protocols, %2 fields.") + .arg(locale.toString(ui->protoTreeWidget->topLevelItemCount())) + .arg(locale.toString(field_count_)); + ui->hintLabel->setText(hint); +} + +void SupportedProtocolsDialog::fillTree() +{ + void *proto_cookie; + QList <QTreeWidgetItem *> proto_list; + + for (int proto_id = proto_get_first_protocol(&proto_cookie); proto_id != -1; + proto_id = proto_get_next_protocol(&proto_cookie)) { + protocol_t *protocol = find_protocol_by_id(proto_id); + QTreeWidgetItem *proto_ti = new QTreeWidgetItem(); + proto_ti->setText(name_col_, proto_get_protocol_short_name(protocol)); + proto_ti->setText(filter_col_, proto_get_protocol_filter_name(proto_id)); + // type_col_ empty + proto_ti->setText(descr_col_, proto_get_protocol_long_name(protocol)); + proto_ti->setData(name_col_, Qt::UserRole, proto_id); + proto_list << proto_ti; + } + + updateStatistics(); + ui->protoTreeWidget->invisibleRootItem()->addChildren(proto_list); + ui->protoTreeWidget->sortByColumn(name_col_, Qt::AscendingOrder); + + foreach (QTreeWidgetItem *proto_ti, proto_list) { + void *field_cookie; + int proto_id = proto_ti->data(name_col_, Qt::UserRole).toInt(); + QList <QTreeWidgetItem *> field_list; + for (header_field_info *hfinfo = proto_get_first_protocol_field(proto_id, &field_cookie); hfinfo != NULL; + hfinfo = proto_get_next_protocol_field(proto_id, &field_cookie)) { + if (hfinfo->same_name_prev_id != -1) continue; + + QTreeWidgetItem *field_ti = new QTreeWidgetItem(); + field_ti->setText(name_col_, hfinfo->name); + field_ti->setText(filter_col_, hfinfo->abbrev); + field_ti->setText(type_col_, ftype_pretty_name(hfinfo->type)); + field_ti->setText(descr_col_, hfinfo->blurb); + field_list << field_ti; + + field_count_++; + if (field_count_ % 1000 == 0) updateStatistics(); + } + std::sort(field_list.begin(), field_list.end()); + proto_ti->addChildren(field_list); + } + + updateStatistics(); + ui->protoTreeWidget->sortByColumn(name_col_, Qt::AscendingOrder); +} + +// Copied from DisplayFilterExpressionDialog +void SupportedProtocolsDialog::on_searchLineEdit_textChanged(const QString &search_re) +{ + QTreeWidgetItemIterator it(ui->protoTreeWidget); + QRegExp regex(search_re, Qt::CaseInsensitive); + while (*it) { + bool hidden = true; + if (search_re.isEmpty() || (*it)->text(0).contains(regex)) { + hidden = false; + } + (*it)->setHidden(hidden); + if (!hidden && (*it)->parent()) { + (*it)->parent()->setHidden(false); + } + ++it; + } +} |