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
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>
23 IOGraphAction::IOGraphAction(QObject
*parent
, io_graph_item_unit_t unit
, QString 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
) {
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");
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
) {
96 case FT_RELATIVE_TIME
:
103 QMenu
* IOGraphAction::createMenu(const FieldInformation::HeaderInfo
& headerinfo
, QWidget
* parent
)
105 MainWindow
*mw(nullptr);
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
);
128 connect(graphAction
, &IOGraphAction::openIOGraphDialog
, mw
, &MainWindow::showIOGraphDialog
);
130 submenu
->addAction(graphAction
);