1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/* 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.
*/
// warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4267)
#endif
#include "supported_protocols_dialog.h"
#include <ui_supported_protocols_dialog.h>
#include "config.h"
#include <algorithm>
#include <glib.h>
#include <epan/proto.h>
#include <QTreeWidgetItem>
#include <QElapsedTimer>
#include "wireshark_application.h"
#ifdef _MSC_VER
#pragma warning(pop)
#endif
enum { name_col_, filter_col_, type_col_, descr_col_ };
SupportedProtocolsDialog::SupportedProtocolsDialog(QWidget *parent) :
GeometryStateDialog(parent),
ui(new Ui::SupportedProtocolsDialog),
field_count_(0)
{
ui->setupUi(this);
if (parent) loadGeometry(parent->width() * 3 / 4, parent->height());
setWindowTitle(wsApp->windowTitleString(tr("Supported Protocols")));
// 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);
wsApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers, 1);
}
// Nearly identical to DisplayFilterExpressionDialog::fillTree.
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_ % 10000 == 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;
}
}
|