Kerberos: add kerberos_inject_longterm_key() helper function
[wireshark-sm.git] / ui / qt / io_graph_action.cpp
blob32c64adb189a2e288fb5bf3cffa74f92dfe22f37
1 /* @file
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 "io_graph_action.h"
12 #include <ui/qt/main_application.h>
13 #include <ui/qt/main_window.h>
14 #include <ui/qt/io_graph_dialog.h>
15 #include <ui/qt/utils/field_information.h>
17 #include <ui/io_graph_item.h>
19 #include <wsutil/filesystem.h>
21 #include <QMenu>
23 IOGraphAction::IOGraphAction(QObject *parent, io_graph_item_unit_t unit, QString field) :
24 QAction(parent),
25 unit_(unit),
26 field_(field)
28 setText(unitName(unit));
29 connect(this, &QAction::triggered, [&](){ emit openIOGraphDialog(unit_, field_); });
32 const QString IOGraphAction::unitName(io_graph_item_unit_t unit) {
33 switch (unit) {
34 case IOG_ITEM_UNIT_PACKETS:
35 if (is_packet_configuration_namespace()) {
36 return QObject::tr("PACKETS");
38 return QObject::tr("EVENTS");
39 case IOG_ITEM_UNIT_BYTES:
40 return QObject::tr("BYTES");
41 case IOG_ITEM_UNIT_BITS:
42 return QObject::tr("BITS");
43 case IOG_ITEM_UNIT_CALC_FRAMES:
44 return QObject::tr("COUNT FRAMES");
45 case IOG_ITEM_UNIT_CALC_FIELDS:
46 return QObject::tr("COUNT FIELDS");
47 case IOG_ITEM_UNIT_CALC_SUM:
48 return QObject::tr("SUM");
49 case IOG_ITEM_UNIT_CALC_MAX:
50 return QObject::tr("MAX");
51 case IOG_ITEM_UNIT_CALC_MIN:
52 return QObject::tr("MIN");
53 case IOG_ITEM_UNIT_CALC_AVERAGE:
54 return QObject::tr("AVERAGE");
55 case IOG_ITEM_UNIT_CALC_THROUGHPUT:
56 return QObject::tr("THROUGHPUT");
57 case IOG_ITEM_UNIT_CALC_LOAD:
58 return QObject::tr("LOAD");
59 default:
60 return QObject::tr("UNKNOWN");
64 QList<io_graph_item_unit_t> IOGraphAction::unitTypes(const FieldInformation::HeaderInfo& headerinfo)
66 static const QList<io_graph_item_unit_t> simple_types_ = QList<io_graph_item_unit_t>()
67 << IOG_ITEM_UNIT_CALC_FRAMES
68 << IOG_ITEM_UNIT_CALC_FIELDS;
70 static const QList<io_graph_item_unit_t> number_types_ = QList<io_graph_item_unit_t>()
71 << IOG_ITEM_UNIT_CALC_SUM
72 << IOG_ITEM_UNIT_CALC_FRAMES
73 << IOG_ITEM_UNIT_CALC_FIELDS
74 << IOG_ITEM_UNIT_CALC_MAX
75 << IOG_ITEM_UNIT_CALC_MIN
76 << IOG_ITEM_UNIT_CALC_THROUGHPUT
77 << IOG_ITEM_UNIT_CALC_AVERAGE;
79 static const QList<io_graph_item_unit_t> time_types_ = QList<io_graph_item_unit_t>(number_types_)
80 << IOG_ITEM_UNIT_CALC_LOAD;
82 switch (headerinfo.type) {
83 case FT_UINT8:
84 case FT_UINT16:
85 case FT_UINT24:
86 case FT_UINT32:
87 case FT_UINT64:
88 case FT_INT8:
89 case FT_INT16:
90 case FT_INT24:
91 case FT_INT32:
92 case FT_INT64:
93 case FT_FLOAT:
94 case FT_DOUBLE:
95 return number_types_;
96 case FT_RELATIVE_TIME:
97 return time_types_;
98 default:
99 return simple_types_;
103 QMenu * IOGraphAction::createMenu(const FieldInformation::HeaderInfo& headerinfo, QWidget * parent)
105 MainWindow *mw(nullptr);
106 if (mainApp)
108 QWidget * mainWin = mainApp->mainWindow();
109 if (qobject_cast<MainWindow *>(mainWin)) {
110 mw = qobject_cast<MainWindow *>(mainWin);
114 QString title("I/O Graph");
115 QMenu * submenu = new QMenu(title, parent);
117 int one_em = submenu->fontMetrics().height();
118 QString prep_text = QStringLiteral("%1: %2").arg(title).arg(headerinfo.abbreviation);
119 prep_text = submenu->fontMetrics().elidedText(prep_text, Qt::ElideRight, one_em * 40);
120 QAction * comment = submenu->addAction(prep_text);
121 comment->setEnabled(false);
122 submenu->addSeparator();
124 IOGraphAction *graphAction;
125 for (const auto &unit : IOGraphAction::unitTypes(headerinfo)) {
126 graphAction = new IOGraphAction(submenu, unit, headerinfo.abbreviation);
127 if (mw) {
128 connect(graphAction, &IOGraphAction::openIOGraphDialog, mw, &MainWindow::showIOGraphDialog);
130 submenu->addAction(graphAction);
133 return submenu;