Qt: Add ASCII+EBCDIC actions to the byte view context menu.
authorGerald Combs <gerald@wireshark.org>
Thu, 30 Jun 2016 16:24:57 +0000 (09:24 -0700)
committerAlexis La Goutte <alexis.lagoutte@gmail.com>
Fri, 1 Jul 2016 06:02:31 +0000 (06:02 +0000)
Add actions to switch between ASCII and EBCDIC, similar to the hex and
bits items.

Bug: 5298
Change-Id: Ib601ac6e89411e6482f3e4172726e16a08fdbd2b
Reviewed-on: https://code.wireshark.org/review/16225
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
docbook/release-notes.asciidoc
ui/qt/byte_view_text.cpp
ui/qt/byte_view_text.h

index 43a09df9edb79653bd754bb6f82a526db68d6711..c472fb7a799e9b7011f209d229cabcb5f296248d 100644 (file)
@@ -36,6 +36,7 @@ since version 2.1.0:
 * The Conversations and Endpoints dialogs are more responsive when
   viewing large numbers of items.
 * The RTP player now allows up to 30 minutes of silence frames.
+* Packet bytes can now be displayed as EBCDIC.
 
 The following features are new (or have been significantly updated)
 since version 2.0.0:
index eca83604827911ab8f936815852398ef3cea98e5..bcbd1bbdac446df89efe9ff3fb885c6435b694d1 100644 (file)
@@ -46,6 +46,7 @@
 // QPainter::drawText for each individual character.
 
 Q_DECLARE_METATYPE(bytes_view_type)
+Q_DECLARE_METATYPE(packet_char_enc)
 
 ByteViewText::ByteViewText(QWidget *parent, tvbuff_t *tvb, proto_tree *tree, QTreeWidget *tree_widget, packet_char_enc encoding) :
     QAbstractScrollArea(parent),
@@ -53,8 +54,9 @@ ByteViewText::ByteViewText(QWidget *parent, tvbuff_t *tvb, proto_tree *tree, QTr
     proto_tree_(tree),
     tree_widget_(tree_widget),
     bold_highlight_(false),
-    encoding_(encoding),
     format_actions_(new QActionGroup(this)),
+    encoding_actions_(new QActionGroup(this)),
+    encoding_(encoding),
     hovered_byte_offset(-1),
     p_bound_(0, 0),
     f_bound_(0, 0),
@@ -80,9 +82,25 @@ ByteViewText::ByteViewText(QWidget *parent, tvbuff_t *tvb, proto_tree *tree, QTr
     }
 
     ctx_menu_.addActions(format_actions_->actions());
+    connect(format_actions_, SIGNAL(triggered(QAction*)), this, SLOT(setHexDisplayFormat(QAction*)));
+
     ctx_menu_.addSeparator();
 
-    connect(format_actions_, SIGNAL(triggered(QAction*)), this, SLOT(setHexDisplayFormat(QAction*)));
+    action = encoding_actions_->addAction(tr("Show bytes as ASCII"));
+    action->setData(qVariantFromValue(PACKET_CHAR_ENC_CHAR_ASCII));
+    action->setCheckable(true);
+    if (encoding_ == PACKET_CHAR_ENC_CHAR_ASCII) {
+        action->setChecked(true);
+    }
+    action = encoding_actions_->addAction(tr("Show bytes as EBCDIC"));
+    action->setData(qVariantFromValue(PACKET_CHAR_ENC_CHAR_EBCDIC));
+    action->setCheckable(true);
+    if (encoding_ == PACKET_CHAR_ENC_CHAR_EBCDIC) {
+        action->setChecked(true);
+    }
+
+    ctx_menu_.addActions(encoding_actions_->actions());
+    connect(encoding_actions_, SIGNAL(triggered(QAction*)), this, SLOT(setCharacterEncoding(QAction*)));
 
     setMouseTracking(true);
 
@@ -96,12 +114,6 @@ ByteViewText::~ByteViewText()
     ctx_menu_.clear();
 }
 
-void ByteViewText::setEncoding(packet_char_enc encoding)
-{
-    encoding_ = encoding;
-    viewport()->update();
-}
-
 bool ByteViewText::hasDataSource(const tvbuff_t *ds_tvb) {
     if (ds_tvb != NULL && ds_tvb == tvb_)
         return true;
@@ -579,6 +591,16 @@ void ByteViewText::setHexDisplayFormat(QAction *action)
     viewport()->update();
 }
 
+void ByteViewText::setCharacterEncoding(QAction *action)
+{
+    if (!action) {
+        return;
+    }
+
+    encoding_ = action->data().value<packet_char_enc>();
+    viewport()->update();
+}
+
 /*
  * Editor modelines
  *
index 917813d19e83941cb0a6856e60c50efe06f03031..29ddc2372c71b7a86c08512d45b2ca049a3ff0ac 100644 (file)
@@ -46,7 +46,6 @@ public:
     ~ByteViewText();
 
     bool hasDataSource(const tvbuff_t *ds_tvb = NULL);
-    void setEncoding(packet_char_enc encoding);
     void setFormat(bytes_view_type format);
     void setHighlightStyle(bool bold) { bold_highlight_ = bold; }
     void setProtocolHighlight(int start, int end);
@@ -104,8 +103,9 @@ private:
     gboolean bold_highlight_;
 
     // Data
-    packet_char_enc encoding_;  // ASCII or EBCDIC
     QActionGroup *format_actions_;
+    QActionGroup *encoding_actions_;
+    packet_char_enc encoding_;  // ASCII or EBCDIC
     QMenu ctx_menu_;
 
     // Data highlight
@@ -131,6 +131,8 @@ private:
 
 private slots:
     void setHexDisplayFormat(QAction *action);
+    void setCharacterEncoding(QAction *action);
+
 };
 
 #endif // BYTE_VIEW_TEXT_H