aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2015-07-10 16:15:55 -0700
committerGerald Combs <gerald@wireshark.org>2015-07-11 00:41:01 +0000
commitd564ea9bea6ba07ac601ca555609677b498845dd (patch)
tree1410ba5423017cf45c959e302a30e919475d6c88
parent44408ed5d9f39f49e871f302c97a6044c0fe4e7e (diff)
Qt: Add Colorize Conversation menu items.
Add the "View→Colorize Conversation" menu similar to the GTK+ UI. Add the "Reset" item under the "Colorize Conversation" menu instead of the top-level "View" menu. Make sure the "Reset" shortcut is Ctrl+Space even on OS X. Normally Qt would convert it to Cmd+Space, but that's used by Spotlight. Add StockIcon::colorIcon and use it to create filled square icons. Change-Id: I2af9e26d025cdaf97482422bbb9440e28e18d1ac Reviewed-on: https://code.wireshark.org/review/9595 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Gerald Combs <gerald@wireshark.org>
-rw-r--r--color_filters.c18
-rw-r--r--color_filters.h8
-rw-r--r--ui/qt/io_graph_dialog.cpp6
-rw-r--r--ui/qt/main_window.cpp1
-rw-r--r--ui/qt/main_window.h5
-rw-r--r--ui/qt/main_window.ui118
-rw-r--r--ui/qt/main_window_slots.cpp120
-rw-r--r--ui/qt/stock_icon.cpp28
-rw-r--r--ui/qt/stock_icon.h1
9 files changed, 288 insertions, 17 deletions
diff --git a/color_filters.c b/color_filters.c
index 834c626c26..bf417a93fd 100644
--- a/color_filters.c
+++ b/color_filters.c
@@ -149,7 +149,7 @@ color_filters_set_tmp(guint8 filt_nr, const gchar *filter, gboolean disabled)
gchar *err_msg;
guint8 i;
- /* Go through the tomporary filters and look for the same filter string.
+ /* Go through the temporary filters and look for the same filter string.
* If found, clear it so that a filter can be "moved" up and down the list
*/
for ( i=1 ; i<=10 ; i++ ) {
@@ -194,6 +194,22 @@ color_filters_set_tmp(guint8 filt_nr, const gchar *filter, gboolean disabled)
return;
}
+const color_filter_t *
+color_filters_tmp_color(guint8 filter_num) {
+ gchar *name;
+ color_filter_t *colorf = NULL;
+ GSList *cfl;
+
+ name = g_strdup_printf("%s%02d", CONVERSATION_COLOR_PREFIX, filter_num);
+ cfl = g_slist_find_custom(color_filter_list, name, color_filters_find_by_name_cb);
+ if (cfl) {
+ colorf = (color_filter_t *)cfl->data;
+ }
+ g_free(name);
+
+ return colorf;
+}
+
/* Reset the temporary colorfilters */
void
color_filters_reset_tmp(void)
diff --git a/color_filters.h b/color_filters.h
index 098d1c5833..04aafc87ec 100644
--- a/color_filters.h
+++ b/color_filters.h
@@ -87,6 +87,14 @@ color_filters_enable(gboolean enable);
void
color_filters_set_tmp(guint8 filt_nr, const gchar *filter, gboolean disabled);
+/** Get a temporary color filter.
+ *
+ * @param filter_num A number from 1 to 10 specifying the color to fetch.
+ * @return The corresponding color or NULL.
+ */
+const color_filter_t *
+color_filters_tmp_color(guint8 filter_num);
+
/** Reset the temporary color filters
*
*/
diff --git a/ui/qt/io_graph_dialog.cpp b/ui/qt/io_graph_dialog.cpp
index c25cc846dd..222163fd88 100644
--- a/ui/qt/io_graph_dialog.cpp
+++ b/ui/qt/io_graph_dialog.cpp
@@ -34,6 +34,7 @@
#include "tango_colors.h"
#include "qcustomplot.h"
+#include "stock_icon.h"
#include "syntax_line_edit.h"
#include "wireshark_application.h"
@@ -618,10 +619,7 @@ void IOGraphDialog::panAxes(int x_pixels, int y_pixels)
QIcon IOGraphDialog::graphColorIcon(int color_idx)
{
- int h = fontMetrics().height() * 3 / 4;
- QPixmap pm(h * 2, h);
- pm.fill(colors_[color_idx % colors_.size()]);
- return QIcon(pm);
+ return StockIcon::colorIcon(colors_[color_idx % colors_.size()], QColor(QPalette::Mid).rgb());
}
void IOGraphDialog::toggleTracerStyle(bool force_default)
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp
index 660a6c2aaa..085139cc35 100644
--- a/ui/qt/main_window.cpp
+++ b/ui/qt/main_window.cpp
@@ -239,6 +239,7 @@ MainWindow::MainWindow(QWidget *parent) :
setFeaturesEnabled(false);
connect(wsApp, SIGNAL(appInitialized()), this, SLOT(setFeaturesEnabled()));
connect(wsApp, SIGNAL(appInitialized()), this, SLOT(zoomText()));
+ connect(wsApp, SIGNAL(appInitialized()), this, SLOT(initViewColorizeMenu()));
connect(wsApp, SIGNAL(appInitialized()), this, SLOT(addStatsPluginsToMenu()));
connect(wsApp, SIGNAL(appInitialized()), this, SLOT(addDynamicMenus()));
connect(wsApp, SIGNAL(appInitialized()), this, SLOT(addExternalMenus()));
diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h
index 6e280778ea..9cd6dd5a63 100644
--- a/ui/qt/main_window.h
+++ b/ui/qt/main_window.h
@@ -240,6 +240,8 @@ public slots:
private slots:
// Manually connected slots (no "on_<object>_<signal>").
+ void initViewColorizeMenu();
+
// in main_window_slots.cpp
void startCapture();
void pipeTimeout();
@@ -374,6 +376,9 @@ private slots:
void on_actionViewNormalSize_triggered();
void on_actionViewColorizePacketList_triggered(bool checked);
void on_actionViewColoringRules_triggered();
+ void colorizeConversation(bool create_rule = false);
+ void on_actionViewColorizeResetColorization_triggered();
+ void on_actionViewColorizeNewConversationRule_triggered();
void on_actionViewResizeColumns_triggered();
void openPacketDialog(bool from_reference = false);
diff --git a/ui/qt/main_window.ui b/ui/qt/main_window.ui
index 3938547f2d..292df80960 100644
--- a/ui/qt/main_window.ui
+++ b/ui/qt/main_window.ui
@@ -279,6 +279,24 @@
<addaction name="actionViewNameResolutionNetwork"/>
<addaction name="actionViewNameResolutionTransport"/>
</widget>
+ <widget class="QMenu" name="menuColorize_Conversation">
+ <property name="title">
+ <string>Colorize Conversation</string>
+ </property>
+ <addaction name="actionViewColorizeConversation1"/>
+ <addaction name="actionViewColorizeConversation2"/>
+ <addaction name="actionViewColorizeConversation3"/>
+ <addaction name="actionViewColorizeConversation4"/>
+ <addaction name="actionViewColorizeConversation5"/>
+ <addaction name="actionViewColorizeConversation6"/>
+ <addaction name="actionViewColorizeConversation7"/>
+ <addaction name="actionViewColorizeConversation8"/>
+ <addaction name="actionViewColorizeConversation9"/>
+ <addaction name="actionViewColorizeConversation10"/>
+ <addaction name="separator"/>
+ <addaction name="actionViewColorizeResetColorization"/>
+ <addaction name="actionViewColorizeNewConversationRule"/>
+ </widget>
<addaction name="actionViewMainToolbar"/>
<addaction name="actionViewFilterToolbar"/>
<addaction name="actionViewWirelessToolbar"/>
@@ -299,6 +317,7 @@
<addaction name="separator"/>
<addaction name="actionViewColorizePacketList"/>
<addaction name="actionViewColoringRules"/>
+ <addaction name="menuColorize_Conversation"/>
<addaction name="separator"/>
<addaction name="actionViewResizeColumns"/>
<addaction name="separator"/>
@@ -2417,6 +2436,105 @@
<string>Show each table of resolved addresses as copyable text.</string>
</property>
</action>
+ <action name="actionViewColorizeConversation1">
+ <property name="text">
+ <string>Color &amp;1</string>
+ </property>
+ <property name="toolTip">
+ <string>Mark the current coversation with its own color.</string>
+ </property>
+ </action>
+ <action name="actionViewColorizeConversation2">
+ <property name="text">
+ <string>Color &amp;2</string>
+ </property>
+ <property name="toolTip">
+ <string>Mark the current coversation with its own color.</string>
+ </property>
+ </action>
+ <action name="actionViewColorizeConversation3">
+ <property name="text">
+ <string>Color &amp;3</string>
+ </property>
+ <property name="toolTip">
+ <string>Mark the current coversation with its own color.</string>
+ </property>
+ </action>
+ <action name="actionViewColorizeConversation4">
+ <property name="text">
+ <string>Color &amp;4</string>
+ </property>
+ <property name="toolTip">
+ <string>Mark the current coversation with its own color.</string>
+ </property>
+ </action>
+ <action name="actionViewColorizeConversation5">
+ <property name="text">
+ <string>Color &amp;5</string>
+ </property>
+ <property name="toolTip">
+ <string>Mark the current coversation with its own color.</string>
+ </property>
+ </action>
+ <action name="actionViewColorizeConversation6">
+ <property name="text">
+ <string>Color &amp;6</string>
+ </property>
+ <property name="toolTip">
+ <string>Mark the current coversation with its own color.</string>
+ </property>
+ </action>
+ <action name="actionViewColorizeConversation7">
+ <property name="text">
+ <string>Color &amp;7</string>
+ </property>
+ <property name="toolTip">
+ <string>Mark the current coversation with its own color.</string>
+ </property>
+ </action>
+ <action name="actionViewColorizeConversation8">
+ <property name="text">
+ <string>Color &amp;8</string>
+ </property>
+ <property name="toolTip">
+ <string>Mark the current coversation with its own color.</string>
+ </property>
+ </action>
+ <action name="actionViewColorizeConversation9">
+ <property name="text">
+ <string>Color &amp;9</string>
+ </property>
+ <property name="toolTip">
+ <string>Mark the current coversation with its own color.</string>
+ </property>
+ </action>
+ <action name="actionViewColorizeConversation10">
+ <property name="text">
+ <string>Color 1&amp;0</string>
+ </property>
+ <property name="toolTip">
+ <string>Mark the current coversation with its own color.</string>
+ </property>
+ </action>
+ <action name="actionViewColorizeNewConversationRule">
+ <property name="text">
+ <string>New Conversation Rule...</string>
+ </property>
+ <property name="toolTip">
+ <string>Create a new coloring rule based on this conversation.</string>
+ </property>
+ </action>
+ <action name="actionViewColorizeResetColorization">
+ <property name="text">
+ <string>Reset Colorization</string>
+ </property>
+ <property name="toolTip">
+ <string>Reset colorized conversations.</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+Space</string>
+ </property>
+ </action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp
index 2307537bf9..6de9f2ea5d 100644
--- a/ui/qt/main_window_slots.cpp
+++ b/ui/qt/main_window_slots.cpp
@@ -78,6 +78,7 @@
#include "bluetooth_devices_dialog.h"
#include "capture_file_dialog.h"
#include "capture_file_properties_dialog.h"
+#include "color_utils.h"
#include "coloring_rules_dialog.h"
#include "conversation_dialog.h"
#include "decode_as_dialog.h"
@@ -111,6 +112,7 @@
#include "sctp_graph_dialog.h"
#include "sequence_dialog.h"
#include "stats_tree_dialog.h"
+#include "stock_icon.h"
#include "tap_parameter_dialog.h"
#include "tcp_stream_dialog.h"
#include "time_shift_dialog.h"
@@ -1052,18 +1054,21 @@ void MainWindow::setMenusForSelectedPacket()
main_ui_->actionEditPreviousTimeReference->setEnabled(another_is_time_ref);
main_ui_->actionEditTimeShift->setEnabled(have_frames);
-// set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/ResizeAllColumns",
-// frame_selected);
-// set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/CollapseAll",
-// frame_selected);
-// set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/CollapseAll",
-// frame_selected);
-// set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/ExpandAll",
-// frame_selected);
-// set_menu_sensitivity(ui_manager_tree_view_menu, "/TreeViewPopup/ExpandAll",
-// frame_selected);
-// set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/ColorizeConversation",
-// frame_selected);
+ main_ui_->actionViewColorizeConversation1->setEnabled(frame_selected);
+ main_ui_->actionViewColorizeConversation2->setEnabled(frame_selected);
+ main_ui_->actionViewColorizeConversation3->setEnabled(frame_selected);
+ main_ui_->actionViewColorizeConversation4->setEnabled(frame_selected);
+ main_ui_->actionViewColorizeConversation5->setEnabled(frame_selected);
+ main_ui_->actionViewColorizeConversation6->setEnabled(frame_selected);
+ main_ui_->actionViewColorizeConversation7->setEnabled(frame_selected);
+ main_ui_->actionViewColorizeConversation8->setEnabled(frame_selected);
+ main_ui_->actionViewColorizeConversation9->setEnabled(frame_selected);
+ main_ui_->actionViewColorizeConversation10->setEnabled(frame_selected);
+ main_ui_->actionViewColorizeNewConversationRule->setEnabled(frame_selected);
+
+ main_ui_->actionViewColorizeResetColorization->setEnabled(tmp_color_filters_used());
+
+ main_ui_->actionViewColorizeNewConversationRule->setEnabled(frame_selected);
// set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/ViewMenu/ResetColoring1-10",
// tmp_color_filters_used());
@@ -1422,6 +1427,36 @@ void MainWindow::showPreferenceEditor()
showAccordionFrame(main_ui_->preferenceEditorFrame);
}
+void MainWindow::initViewColorizeMenu()
+{
+ QList<QAction *> cc_actions = QList<QAction *>()
+ << main_ui_->actionViewColorizeConversation1 << main_ui_->actionViewColorizeConversation2
+ << main_ui_->actionViewColorizeConversation3 << main_ui_->actionViewColorizeConversation4
+ << main_ui_->actionViewColorizeConversation5 << main_ui_->actionViewColorizeConversation6
+ << main_ui_->actionViewColorizeConversation7 << main_ui_->actionViewColorizeConversation8
+ << main_ui_->actionViewColorizeConversation9 << main_ui_->actionViewColorizeConversation10;
+
+ guint8 color_num = 1;
+
+ foreach (QAction *cc_action, cc_actions) {
+ cc_action->setData(color_num);
+ connect(cc_action, SIGNAL(triggered()), this, SLOT(colorizeConversation()));
+
+ const color_filter_t *colorf = color_filters_tmp_color(color_num);
+ if (colorf) {
+ QColor bg = ColorUtils::fromColorT(colorf->bg_color);
+ QColor fg = ColorUtils::fromColorT(colorf->fg_color);
+ cc_action->setIcon(StockIcon::colorIcon(bg.rgb(), fg.rgb(), QString::number(color_num)));
+ }
+ color_num++;
+ }
+
+#ifdef Q_OS_MAC
+ // Spotlight uses Cmd+Space
+ main_ui_->actionViewColorizeResetColorization->setShortcut(QKeySequence("Meta+Space"));
+#endif
+}
+
void MainWindow::addStatsPluginsToMenu() {
GList *cfg_list = stats_tree_get_cfg_list();
GList *iter = g_list_first(cfg_list);
@@ -2200,6 +2235,67 @@ void MainWindow::on_actionViewColoringRules_triggered()
coloring_rules_dialog.exec();
}
+// actionViewColorizeConversation1 - 10
+void MainWindow::colorizeConversation(bool create_rule)
+{
+ QAction *cc_action = qobject_cast<QAction *>(sender());
+ if (!cc_action) return;
+
+ if (capture_file_.capFile() && capture_file_.capFile()->current_frame) {
+ packet_info *pi = &capture_file_.capFile()->edt->pi;
+ guint8 cc_num = cc_action->data().toUInt();
+ gchar *filter = NULL;
+
+ const color_conversation_filter_t *color_filter = find_color_conversation_filter("tcp");
+ if ((color_filter != NULL) && (color_filter->is_filter_valid(pi)))
+ filter = color_filter->build_filter_string(pi);
+ if (filter == NULL) {
+ color_filter = find_color_conversation_filter("udp");
+ if ((color_filter != NULL) && (color_filter->is_filter_valid(pi)))
+ filter = color_filter->build_filter_string(pi);
+ }
+ if (filter == NULL) {
+ color_filter = find_color_conversation_filter("ip");
+ if ((color_filter != NULL) && (color_filter->is_filter_valid(pi)))
+ filter = color_filter->build_filter_string(pi);
+ }
+ if (filter == NULL) {
+ color_filter = find_color_conversation_filter("ipv6");
+ if ((color_filter != NULL) && (color_filter->is_filter_valid(pi)))
+ filter = color_filter->build_filter_string(pi);
+ }
+ if (filter == NULL) {
+ color_filter = find_color_conversation_filter("eth");
+ if ((color_filter != NULL) && (color_filter->is_filter_valid(pi)))
+ filter = color_filter->build_filter_string(pi);
+ }
+ if( filter == NULL ) {
+ main_ui_->statusBar->pushTemporaryStatus(tr("Unable to build conversation filter."));
+ return;
+ }
+
+ if (create_rule) {
+ ColoringRulesDialog coloring_rules_dialog(this, filter);
+ coloring_rules_dialog.exec();
+ } else {
+ color_filters_set_tmp(cc_num, filter, FALSE);
+ packet_list_->recolorPackets();
+ main_ui_->actionViewColorizeResetColorization->setEnabled(true);
+ }
+ }
+}
+
+void MainWindow::on_actionViewColorizeResetColorization_triggered()
+{
+ color_filters_reset_tmp();
+ packet_list_->recolorPackets();
+}
+
+void MainWindow::on_actionViewColorizeNewConversationRule_triggered()
+{
+ colorizeConversation(true);
+}
+
void MainWindow::on_actionViewResizeColumns_triggered()
{
for (int col = 0; col < packet_list_->packetListModel()->columnCount(); col++) {
diff --git a/ui/qt/stock_icon.cpp b/ui/qt/stock_icon.cpp
index 86e953e3dd..8c6929fa1a 100644
--- a/ui/qt/stock_icon.cpp
+++ b/ui/qt/stock_icon.cpp
@@ -53,6 +53,8 @@
#include "wireshark_application.h"
#include <QFile>
+#include <QFontMetrics>
+#include <QPainter>
#include <QStyle>
QString path_pfx_ = ":/icons/toolbar/";
@@ -92,6 +94,32 @@ StockIcon::StockIcon(const char *icon_name) :
}
}
+// Create a square icon filled with the specified color.
+QIcon StockIcon::colorIcon(const QRgb bg_color, const QRgb fg_color, const QString glyph)
+{
+ QList<int> sizes = QList<int>() << 12 << 16 << 24 << 32 << 48;
+ QIcon color_icon;
+
+ foreach (int size, sizes) {
+ QPixmap pm(size, size);
+ QPainter painter(&pm);
+ QRect border(0, 0, size - 1, size - 1);
+ painter.setPen(fg_color);
+ painter.setBrush(QColor(bg_color));
+ painter.drawRect(border);
+
+ if (!glyph.isEmpty()) {
+ QFont font(wsApp->font());
+ font.setPointSizeF(size * 2.0 / 3.0);
+ QRectF bounding = painter.boundingRect(pm.rect(), glyph, Qt::AlignHCenter | Qt::AlignVCenter);
+ painter.drawText(bounding, glyph);
+ }
+
+ color_icon.addPixmap(pm);
+ }
+ return color_icon;
+}
+
/*
* Editor modelines
*
diff --git a/ui/qt/stock_icon.h b/ui/qt/stock_icon.h
index 3c83beb7ba..cd6e60f39d 100644
--- a/ui/qt/stock_icon.h
+++ b/ui/qt/stock_icon.h
@@ -40,6 +40,7 @@ class StockIcon : public QIcon
public:
explicit StockIcon(const char *icon_name);
+ static QIcon colorIcon(const QRgb bg_color, const QRgb fg_color, const QString glyph = QString());
};
#endif // STOCK_ICON_H