#include <QTextLayout>
// To do:
-// - Add recent settings and context menu items to show/hide the offset,
-// and ASCII/EBCDIC.
+// - Add recent settings and context menu items to show/hide the offset.
// - Add a UTF-8 and possibly UTF-xx option to the ASCII display.
-// - Add "copy bytes as" context menu items.
// - Move more common metrics to DataPrinter.
Q_DECLARE_METATYPE(bytes_view_type)
-Q_DECLARE_METATYPE(packet_char_enc)
+Q_DECLARE_METATYPE(bytes_encoding_type)
Q_DECLARE_METATYPE(DataPrinter::DumpType)
ByteViewText::ByteViewText(const QByteArray &data, packet_char_enc encoding, QWidget *parent) :
void ByteViewText::createContextMenu()
{
- QActionGroup * format_actions_ = new QActionGroup(this);
QAction *action;
- QActionGroup * copyEntries = DataPrinter::copyActions(this);
- ctx_menu_.addActions(copyEntries->actions());
+ QActionGroup * copy_actions = DataPrinter::copyActions(this);
+ ctx_menu_.addActions(copy_actions->actions());
ctx_menu_.addSeparator();
- action = format_actions_->addAction(tr("Show bytes as hexadecimal"));
+ QActionGroup * format_actions = new QActionGroup(this);
+ action = format_actions->addAction(tr("Show bytes as hexadecimal"));
action->setData(qVariantFromValue(BYTES_HEX));
action->setCheckable(true);
if (recent.gui_bytes_view == BYTES_HEX) {
action->setChecked(true);
}
- action = format_actions_->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as bits"));
+ action = format_actions->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as bits"));
action->setData(qVariantFromValue(BYTES_BITS));
action->setCheckable(true);
if (recent.gui_bytes_view == BYTES_BITS) {
action->setChecked(true);
}
- ctx_menu_.addActions(format_actions_->actions());
- connect(format_actions_, SIGNAL(triggered(QAction*)), this, SLOT(setHexDisplayFormat(QAction*)));
+ ctx_menu_.addActions(format_actions->actions());
+ connect(format_actions, SIGNAL(triggered(QAction*)), this, SLOT(setHexDisplayFormat(QAction*)));
ctx_menu_.addSeparator();
- QActionGroup * encoding_actions_ = new QActionGroup(this);
- action = encoding_actions_->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as ASCII"));
- action->setData(qVariantFromValue(PACKET_CHAR_ENC_CHAR_ASCII));
+ QActionGroup * encoding_actions = new QActionGroup(this);
+ action = encoding_actions->addAction(tr("Show text based on packet"));
+ action->setData(qVariantFromValue(BYTES_ENC_FROM_PACKET));
action->setCheckable(true);
- if (encoding_ == PACKET_CHAR_ENC_CHAR_ASCII) {
+ if (recent.gui_bytes_encoding == BYTES_ENC_FROM_PACKET) {
action->setChecked(true);
}
- action = encoding_actions_->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as EBCDIC"));
- action->setData(qVariantFromValue(PACKET_CHAR_ENC_CHAR_EBCDIC));
+ action = encoding_actions->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as ASCII"));
+ action->setData(qVariantFromValue(BYTES_ENC_ASCII));
action->setCheckable(true);
- if (encoding_ == PACKET_CHAR_ENC_CHAR_EBCDIC) {
+ if (recent.gui_bytes_encoding == BYTES_ENC_ASCII) {
+ action->setChecked(true);
+ }
+ action = encoding_actions->addAction(tr(UTF8_HORIZONTAL_ELLIPSIS "as EBCDIC"));
+ action->setData(qVariantFromValue(BYTES_ENC_EBCDIC));
+ action->setCheckable(true);
+ if (recent.gui_bytes_encoding == BYTES_ENC_EBCDIC) {
action->setChecked(true);
}
- ctx_menu_.addActions(encoding_actions_->actions());
- connect(encoding_actions_, SIGNAL(triggered(QAction*)), this, SLOT(setCharacterEncoding(QAction*)));
+ ctx_menu_.addActions(encoding_actions->actions());
+ connect(encoding_actions, SIGNAL(triggered(QAction*)), this, SLOT(setCharacterEncoding(QAction*)));
}
bool ByteViewText::isEmpty() const
bool in_non_printable = false;
int np_start = 0;
int np_len = 0;
+ guchar c;
+
for (int tvb_pos = offset; tvb_pos <= max_tvb_pos; tvb_pos++) {
/* insert a space every separator_interval_ bytes */
if ((tvb_pos != offset) && ((tvb_pos % separator_interval_) == 0)) {
}
}
- guchar c = (encoding_ == PACKET_CHAR_ENC_CHAR_EBCDIC) ?
- EBCDIC_to_ASCII1(data_[tvb_pos]) :
- data_[tvb_pos];
+ if (recent.gui_bytes_encoding != BYTES_ENC_EBCDIC && encoding_ == PACKET_CHAR_ENC_CHAR_ASCII) {
+ c = data_[tvb_pos];
+ } else {
+ c = EBCDIC_to_ASCII1(data_[tvb_pos]);
+ }
if (g_ascii_isprint(c)) {
line += c;
return;
}
- encoding_ = action->data().value<packet_char_enc>();
+ recent.gui_bytes_encoding = action->data().value<bytes_encoding_type>();
viewport()->update();
}
#define RECENT_GUI_SECONDS_FORMAT "gui.seconds_format"
#define RECENT_GUI_ZOOM_LEVEL "gui.zoom_level"
#define RECENT_GUI_BYTES_VIEW "gui.bytes_view"
+#define RECENT_GUI_BYTES_ENCODING "gui.bytes_encoding"
#define RECENT_GUI_GEOMETRY_MAIN_X "gui.geometry_main_x"
#define RECENT_GUI_GEOMETRY_MAIN_Y "gui.geometry_main_y"
#define RECENT_GUI_GTK_GEOMETRY_MAIN_X "gui.gtk.geometry_main_x"
{ 0, NULL }
};
+static const value_string bytes_view_type_values[] = {
+ { BYTES_HEX, "HEX" },
+ { BYTES_BITS, "BITS" },
+ { 0, NULL }
+};
+
+static const value_string bytes_encoding_type_values[] = {
+ { BYTES_ENC_FROM_PACKET, "FROM_PACKET" },
+ { BYTES_ENC_ASCII, "ASCII" },
+ { BYTES_ENC_EBCDIC, "EBCDIC" },
+ { 0, NULL }
+};
+
static void
free_col_width_data(gpointer data, gpointer user_data _U_)
{
fprintf(rf, RECENT_GUI_ZOOM_LEVEL ": %d\n",
recent.gui_zoom_level);
- fprintf(rf, "\n# Bytes view.\n");
- fprintf(rf, "# A decimal number.\n");
- fprintf(rf, RECENT_GUI_BYTES_VIEW ": %d\n",
+ write_recent_enum(rf, "Bytes view display type",
+ RECENT_GUI_BYTES_VIEW, bytes_view_type_values,
recent.gui_bytes_view);
+ write_recent_enum(rf, "Bytes view text encoding",
+ RECENT_GUI_BYTES_ENCODING, bytes_encoding_type_values,
+ recent.gui_bytes_encoding);
+
fprintf(rf, "\n# Main window upper (or leftmost) pane size.\n");
fprintf(rf, "# Decimal number.\n");
if (recent.gui_geometry_main_upper_pane != 0) {
return PREFS_SET_SYNTAX_ERR; /* number was bad */
recent.gui_zoom_level = (gint)num;
} else if (strcmp(key, RECENT_GUI_BYTES_VIEW) == 0) {
- num = strtol(value, &p, 0);
- if (p == value || *p != '\0')
- return PREFS_SET_SYNTAX_ERR; /* number was bad */
- recent.gui_bytes_view = (bytes_view_type)num;
+ recent.gui_bytes_view =
+ (bytes_view_type)str_to_val(value, bytes_view_type_values, BYTES_HEX);
+ } else if (strcmp(key, RECENT_GUI_BYTES_ENCODING) == 0) {
+ recent.gui_bytes_encoding =
+ (bytes_encoding_type)str_to_val(value, bytes_encoding_type_values, BYTES_ENC_FROM_PACKET);
} else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_MAXIMIZED) == 0) {
parse_recent_boolean(value, &recent.gui_geometry_main_maximized);
} else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_UPPER_PANE) == 0) {
recent.gui_seconds_format = TS_SECONDS_DEFAULT;
recent.gui_zoom_level = 0;
recent.gui_bytes_view = BYTES_HEX;
+ recent.gui_bytes_encoding = BYTES_ENC_FROM_PACKET;
/* pane size of zero will autodetect */
recent.gui_geometry_main_upper_pane = 0;