summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2015-11-22 21:25:15 +0100
committerStig Bjørlykke <stig@bjorlykke.org>2015-11-23 07:40:03 +0000
commite82c37ef4b76e818f82f0ad0db4d5518612da4f2 (patch)
tree3efcc00dc8b32aa1cd6a94c07af908c865e65d75
parenta95eeb3feb7066104c89f6dc0815d9ce5c7fda87 (diff)
downloadwireshark-e82c37ef4b76e818f82f0ad0db4d5518612da4f2.tar.gz
Qt: Set tooltip for packet list header
Added get_column_tooltip() to use common code in GTK and Qt. Change-Id: I2f6ce95e2e129752bbb958a28aec6f42aa81be3d Reviewed-on: https://code.wireshark.org/review/12047 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Reviewed-by: Anders Broman <a.broman58@gmail.com> Reviewed-on: https://code.wireshark.org/review/12055 Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
-rw-r--r--debian/libwireshark6.symbols1
-rw-r--r--epan/column.c36
-rw-r--r--epan/column.h2
-rw-r--r--ui/gtk/packet_list.c23
-rw-r--r--ui/qt/packet_list_model.cpp18
-rw-r--r--ui/qt/packet_list_model.h2
6 files changed, 56 insertions, 26 deletions
diff --git a/debian/libwireshark6.symbols b/debian/libwireshark6.symbols
index 3933072210..7a7fd777c5 100644
--- a/debian/libwireshark6.symbols
+++ b/debian/libwireshark6.symbols
@@ -662,6 +662,7 @@ libwireshark.so.6 libwireshark6 #MINVER#
get_column_format_matches@Base 1.9.1
get_column_resolved@Base 1.9.1
get_column_title@Base 1.9.1
+ get_column_tooltip@Base 2.0.1
get_column_visible@Base 1.9.1
get_column_width_string@Base 1.9.1
get_conversation_address@Base 1.99.0
diff --git a/epan/column.c b/epan/column.c
index 5555d3e0c8..ca482c8127 100644
--- a/epan/column.c
+++ b/epan/column.c
@@ -784,6 +784,42 @@ set_column_custom_occurrence(const gint col, const gint custom_occurrence)
cfmt->custom_occurrence = custom_occurrence;
}
+gchar *
+get_column_tooltip(const gint col)
+{
+ GList *clp = g_list_nth(prefs.col_list, col);
+ fmt_data *cfmt;
+ gchar *tooltip_text;
+
+ if (!clp) /* Invalid column requested */
+ return NULL;
+
+ cfmt = (fmt_data *) clp->data;
+
+ if (cfmt->fmt == COL_CUSTOM) {
+ header_field_info *hfi = proto_registrar_get_byname(cfmt->custom_field);
+ /* Check if this is a valid custom_field */
+ if (hfi != NULL) {
+ if (hfi->parent != -1) {
+ /* Prefix with protocol name */
+ if (cfmt->custom_occurrence != 0) {
+ tooltip_text = g_strdup_printf("%s\n%s (%s#%d)", proto_get_protocol_name(hfi->parent), hfi->name, hfi->abbrev, cfmt->custom_occurrence);
+ } else {
+ tooltip_text = g_strdup_printf("%s\n%s (%s)", proto_get_protocol_name(hfi->parent), hfi->name, hfi->abbrev);
+ }
+ } else {
+ tooltip_text = g_strdup_printf("%s (%s)", hfi->name, hfi->abbrev);
+ }
+ } else {
+ tooltip_text = g_strdup_printf("Unknown Field: %s", get_column_custom_field(col));
+ }
+ } else {
+ tooltip_text = g_strdup(col_format_desc(cfmt->fmt));
+ }
+
+ return tooltip_text;
+}
+
void
build_column_format_array(column_info *cinfo, const gint num_cols, const gboolean reset_fences)
{
diff --git a/epan/column.h b/epan/column.h
index 3061c36e82..af19b07ca2 100644
--- a/epan/column.h
+++ b/epan/column.h
@@ -75,6 +75,8 @@ WS_DLL_PUBLIC
const gchar *get_column_width_string(const gint, const gint);
WS_DLL_PUBLIC
gint get_column_char_width(const gint format);
+WS_DLL_PUBLIC
+gchar *get_column_tooltip(const gint col);
WS_DLL_PUBLIC
void
diff --git a/ui/gtk/packet_list.c b/ui/gtk/packet_list.c
index 7a604ed954..a46562367b 100644
--- a/ui/gtk/packet_list.c
+++ b/ui/gtk/packet_list.c
@@ -656,7 +656,6 @@ create_view_and_model(void)
gint i, col_width;
gdouble value;
gchar *tooltip_text;
- header_field_info *hfi;
gint col_min_width;
gchar *escaped_title;
col_item_t* col_item;
@@ -705,26 +704,7 @@ create_view_and_model(void)
show_cell_data_func,
GINT_TO_POINTER(i),
NULL);
- if (col_item->col_fmt == COL_CUSTOM) {
- hfi = proto_registrar_get_byname(col_item->col_custom_field);
- /* Check if this is a valid custom_field */
- if (hfi != NULL) {
- if (hfi->parent != -1) {
- /* Prefix with protocol name */
- if (col_item->col_custom_occurrence != 0) {
- tooltip_text = g_strdup_printf("%s\n%s (%s#%d)", proto_get_protocol_name(hfi->parent), hfi->name, hfi->abbrev, col_item->col_custom_occurrence);
- } else {
- tooltip_text = g_strdup_printf("%s\n%s (%s)", proto_get_protocol_name(hfi->parent), hfi->name, hfi->abbrev);
- }
- } else {
- tooltip_text = g_strdup_printf("%s (%s)", hfi->name, hfi->abbrev);
- }
- } else {
- tooltip_text = g_strdup_printf("Unknown Field: %s", get_column_custom_field(i));
- }
- } else {
- tooltip_text = g_strdup(col_format_desc(col_item->col_fmt));
- }
+
escaped_title = ws_strdup_escape_char(col_item->col_title, '_');
gtk_tree_view_column_set_title(col, escaped_title);
g_free (escaped_title);
@@ -769,6 +749,7 @@ create_view_and_model(void)
gtk_tree_view_append_column(GTK_TREE_VIEW(packetlist->view), col);
+ tooltip_text = get_column_tooltip(i);
gtk_widget_set_tooltip_text(gtk_tree_view_column_get_button(col), tooltip_text);
g_free(tooltip_text);
g_signal_connect(gtk_tree_view_column_get_button(col), "button_press_event",
diff --git a/ui/qt/packet_list_model.cpp b/ui/qt/packet_list_model.cpp
index 0ee0b662c7..55fdf29494 100644
--- a/ui/qt/packet_list_model.cpp
+++ b/ui/qt/packet_list_model.cpp
@@ -528,20 +528,30 @@ QVariant PacketListModel::data(const QModelIndex &d_index, int role) const
}
QVariant PacketListModel::headerData(int section, Qt::Orientation orientation,
- int role) const
+ int role) const
{
- if (!cap_file_) return QVariant();
+ QVariant data;
+
+ if (!cap_file_) return data;
if (orientation == Qt::Horizontal && section < prefs.num_cols) {
switch (role) {
case Qt::DisplayRole:
- return get_column_title(section);
+ data = get_column_title(section);
+ break;
+ case Qt::ToolTipRole:
+ {
+ gchar *tooltip = get_column_tooltip(section);
+ data = tooltip;
+ g_free (tooltip);
+ break;
+ }
default:
break;
}
}
- return QVariant();
+ return data;
}
void PacketListModel::flushVisibleRows()
diff --git a/ui/qt/packet_list_model.h b/ui/qt/packet_list_model.h
index 6562cebeee..7d67eb3a3d 100644
--- a/ui/qt/packet_list_model.h
+++ b/ui/qt/packet_list_model.h
@@ -58,7 +58,7 @@ public:
int columnCount(const QModelIndex & = QModelIndex()) const;
QVariant data(const QModelIndex &d_index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
+ int role = Qt::DisplayRole | Qt::ToolTipRole) const;
gint appendPacket(frame_data *fdata);
frame_data *getRowFdata(int row);