diff options
author | Pascal Quantin <pascal.quantin@gmail.com> | 2015-12-17 20:41:46 +0100 |
---|---|---|
committer | Stig Bjørlykke <stig@bjorlykke.org> | 2015-12-18 06:46:46 +0000 |
commit | 47a4c8f395280bd78bbc733424bb409c00d2c390 (patch) | |
tree | e6b840827e5ba3eb0b3921e5b1c481b63a802488 /ui | |
parent | e1ed7598ee2cc884d28a05533d9060b56ceb7976 (diff) | |
download | wireshark-47a4c8f395280bd78bbc733424bb409c00d2c390.tar.gz |
Qt: use recent.gui_bytes_view preference to remember bits / byte view
While we are at it, let's centralize bytes_view_type definition
Bug: 11903
Change-Id: I606c779a8efaea668db1b440d3ae0336e6e3fc67
Reviewed-on: https://code.wireshark.org/review/12706
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gtk/bytes_view.c | 2 | ||||
-rw-r--r-- | ui/gtk/main_menubar.c | 4 | ||||
-rw-r--r-- | ui/gtk/packet_panes.c | 2 | ||||
-rw-r--r-- | ui/gtk/packet_panes.h | 7 | ||||
-rw-r--r-- | ui/qt/byte_view_text.cpp | 23 | ||||
-rw-r--r-- | ui/qt/byte_view_text.h | 8 | ||||
-rw-r--r-- | ui/recent.c | 4 | ||||
-rw-r--r-- | ui/recent.h | 7 |
8 files changed, 29 insertions, 28 deletions
diff --git a/ui/gtk/bytes_view.c b/ui/gtk/bytes_view.c index 4e3a95780f..911c771838 100644 --- a/ui/gtk/bytes_view.c +++ b/ui/gtk/bytes_view.c @@ -39,7 +39,7 @@ #include <epan/charsets.h> #include <epan/packet.h> -#include "packet_panes.h" +#include "ui/recent.h" #define MARGIN 2 #define REFRESH_TIMEOUT 10 diff --git a/ui/gtk/main_menubar.c b/ui/gtk/main_menubar.c index f2b87383c2..f9a124e795 100644 --- a/ui/gtk/main_menubar.c +++ b/ui/gtk/main_menubar.c @@ -1606,9 +1606,9 @@ static const GtkRadioActionEntry main_menu_bar_radio_view_time_fileformat_prec_e static void select_bytes_view_cb (GtkRadioAction *action, GtkRadioAction *current _U_, gpointer user_data _U_) { - gint value; + bytes_view_type value; - value = gtk_radio_action_get_current_value (action); + value = (bytes_view_type)gtk_radio_action_get_current_value (action); /* Fix me */ select_bytes_view( NULL, NULL, value); } diff --git a/ui/gtk/packet_panes.c b/ui/gtk/packet_panes.c index 42f75b94a2..241292b0cc 100644 --- a/ui/gtk/packet_panes.c +++ b/ui/gtk/packet_panes.c @@ -1430,7 +1430,7 @@ proto_tree_draw(proto_tree *protocol_tree, GtkWidget *tree_view) } void -select_bytes_view (GtkWidget *w _U_, gpointer data _U_, gint view) +select_bytes_view (GtkWidget *w _U_, gpointer data _U_, bytes_view_type view) { if (recent.gui_bytes_view != view) { recent.gui_bytes_view = view; diff --git a/ui/gtk/packet_panes.h b/ui/gtk/packet_panes.h index db079be8bd..0aca2c72cd 100644 --- a/ui/gtk/packet_panes.h +++ b/ui/gtk/packet_panes.h @@ -24,6 +24,7 @@ #ifndef __PACKET_PANES_H__ #define __PACKET_PANES_H__ +#include "ui/recent.h" #include <epan/addr_resolv.h> /** @file @@ -215,11 +216,7 @@ extern void collapse_all_tree(proto_tree *protocol_tree, GtkWidget *tree_view); */ extern gboolean tree_view_select(GtkWidget *widget, GdkEventButton *event); -typedef enum { - BYTES_HEX, - BYTES_BITS -} bytes_view_type; -extern void select_bytes_view (GtkWidget *widget, gpointer data, gint view); +extern void select_bytes_view (GtkWidget *widget, gpointer data, bytes_view_type view); /** init the expert colors */ extern void proto_draw_colors_init(void); diff --git a/ui/qt/byte_view_text.cpp b/ui/qt/byte_view_text.cpp index 85566c1680..6355732940 100644 --- a/ui/qt/byte_view_text.cpp +++ b/ui/qt/byte_view_text.cpp @@ -28,6 +28,7 @@ #include "color_utils.h" #include "wireshark_application.h" +#include "ui/recent.h" #include <QActionGroup> #include <QMouseEvent> @@ -36,7 +37,7 @@ // To do: // - Add recent settings and context menu items to show/hide the offset, -// hex/bits, and ASCII/EBCDIC. +// and ASCII/EBCDIC. // - Add a UTF-8 and possibly UTF-xx option to the ASCII display. // - Add "copy bytes as" context menu items. @@ -53,7 +54,6 @@ ByteViewText::ByteViewText(QWidget *parent, tvbuff_t *tvb, proto_tree *tree, QTr tree_widget_(tree_widget), bold_highlight_(false), encoding_(encoding), - format_(BYTES_HEX), format_actions_(new QActionGroup(this)), p_bound_(0, 0), f_bound_(0, 0), @@ -61,17 +61,22 @@ ByteViewText::ByteViewText(QWidget *parent, tvbuff_t *tvb, proto_tree *tree, QTr show_offset_(true), show_hex_(true), show_ascii_(true), - row_width_(16) + row_width_(recent.gui_bytes_view == BYTES_HEX ? 16 : 8) { QAction *action; action = format_actions_->addAction(tr("Show bytes as hexadecimal")); action->setData(qVariantFromValue(BYTES_HEX)); action->setCheckable(true); - action->setChecked(true); + if (recent.gui_bytes_view == BYTES_HEX) { + action->setChecked(true); + } action = format_actions_->addAction(tr("Show bytes 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()); ctx_menu_.addSeparator(); @@ -177,7 +182,7 @@ void ByteViewText::paintEvent(QPaintEvent *) int sep_width = (i / separator_interval_) * font_width_; if (show_hex_) { // Hittable pixels extend 1/2 space on either side of the hex digits - int pixels_per_byte = (format_ == BYTES_HEX ? 3 : 9) * font_width_; + int pixels_per_byte = (recent.gui_bytes_view == BYTES_HEX ? 3 : 9) * font_width_; int hex_x = offsetPixels() + margin_ + sep_width + (i * pixels_per_byte) - (font_width_ / 2); for (int j = 0; j <= pixels_per_byte; j++) { x_pos_to_column_[hex_x + j] = i; @@ -340,7 +345,7 @@ void ByteViewText::drawOffsetLine(QPainter &painter, const guint offset, const i text += ' '; } - switch (format_) { + switch (recent.gui_bytes_view) { case BYTES_HEX: text += hexchars[(pd[tvb_pos] & 0xf0) >> 4]; text += hexchars[pd[tvb_pos] & 0x0f]; @@ -475,7 +480,7 @@ int ByteViewText::offsetPixels() int ByteViewText::hexPixels() { if (show_hex_) { - int digits_per_byte = format_ == BYTES_HEX ? 3 : 9; + int digits_per_byte = recent.gui_bytes_view == BYTES_HEX ? 3 : 9; return (((row_width_ * digits_per_byte) + ((row_width_ - 1) / separator_interval_)) * font_width_) + one_em_; } return 0; @@ -530,8 +535,8 @@ void ByteViewText::setHexDisplayFormat(QAction *action) return; } - format_ = action->data().value<bytes_view_type>(); - row_width_ = format_ == BYTES_HEX ? 16 : 8; + recent.gui_bytes_view = action->data().value<bytes_view_type>(); + row_width_ = recent.gui_bytes_view == BYTES_HEX ? 16 : 8; viewport()->update(); } diff --git a/ui/qt/byte_view_text.h b/ui/qt/byte_view_text.h index 74898ece49..89e3e6674d 100644 --- a/ui/qt/byte_view_text.h +++ b/ui/qt/byte_view_text.h @@ -29,6 +29,7 @@ #include <epan/tvbuff.h> #include "proto_tree.h" +#include "ui/recent.h" #include <QAbstractScrollArea> #include <QMenu> @@ -37,12 +38,6 @@ class QActionGroup; // XXX - Is there any reason we shouldn't add ByteViewImage, etc? -// XXX Copied from gtk/packet_panes.h -typedef enum { - BYTES_HEX, - BYTES_BITS -} bytes_view_type; - class ByteViewText : public QAbstractScrollArea { Q_OBJECT @@ -107,7 +102,6 @@ private: // Data packet_char_enc encoding_; // ASCII or EBCDIC - bytes_view_type format_; // bytes in hex or bytes as bits QActionGroup *format_actions_; QMenu ctx_menu_; diff --git a/ui/recent.c b/ui/recent.c index 56bc280aef..54cafe6af8 100644 --- a/ui/recent.c +++ b/ui/recent.c @@ -994,7 +994,7 @@ read_set_recent_pair_static(gchar *key, const gchar *value, num = strtol(value, &p, 0); if (p == value || *p != '\0') return PREFS_SET_SYNTAX_ERR; /* number was bad */ - recent.gui_bytes_view = (gint)num; + recent.gui_bytes_view = (bytes_view_type)num; } 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) { @@ -1246,7 +1246,7 @@ recent_read_profile_static(char **rf_path_return, int *rf_errno_return) recent.gui_time_precision = TS_PREC_AUTO; recent.gui_seconds_format = TS_SECONDS_DEFAULT; recent.gui_zoom_level = 0; - recent.gui_bytes_view = 0; + recent.gui_bytes_view = BYTES_HEX; /* pane size of zero will autodetect */ recent.gui_geometry_main_upper_pane = 0; diff --git a/ui/recent.h b/ui/recent.h index 4daf917878..9b2052d7c8 100644 --- a/ui/recent.h +++ b/ui/recent.h @@ -63,6 +63,11 @@ typedef struct _col_width_data { #define COLUMN_XALIGN_CENTER 'C' #define COLUMN_XALIGN_RIGHT 'R' +typedef enum { + BYTES_HEX, + BYTES_BITS +} bytes_view_type; + /** Recent settings. */ typedef struct recent_settings_tag { gboolean main_toolbar_show; @@ -78,7 +83,7 @@ typedef struct recent_settings_tag { gint gui_time_precision; ts_seconds_type gui_seconds_format; gint gui_zoom_level; - gint gui_bytes_view; + bytes_view_type gui_bytes_view; gint gui_geometry_main_x; gint gui_geometry_main_y; |