forked from osmocom/wireshark
Qt: Use uniform interface display name
Use common function to generate the interface display name, both when scanning for interfaces (scan_local_interfaces()) and when changing Comment in the Manage Interfaces dialog. Change-Id: I3260208856563aaf387ce397d4ae61bddcc89b4f Reviewed-on: https://code.wireshark.org/review/12362 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
3f3de12a88
commit
631172f2f4
|
@ -599,6 +599,48 @@ get_iface_list_string(capture_options *capture_opts, guint32 style)
|
|||
return iface_list_string;
|
||||
}
|
||||
|
||||
gchar *
|
||||
get_iface_display_name(const gchar *description, const if_info_t *if_info)
|
||||
{
|
||||
if (description && description[0]) {
|
||||
/* We have a user-supplied description. */
|
||||
#ifdef _WIN32
|
||||
gchar *if_string = if_info->friendly_name ? if_info->friendly_name : if_info->name;
|
||||
return g_strdup_printf("%s: %s", description, if_string);
|
||||
#else
|
||||
return g_strdup_printf("%s: %s", description, if_info->name);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (if_info->friendly_name) {
|
||||
/* We have a friendly name from the OS. */
|
||||
#ifdef _WIN32
|
||||
/*
|
||||
* On Windows, if we have a friendly name, just show it,
|
||||
* don't show the name, as that's a string made out of
|
||||
* the device GUID, and not at all friendly.
|
||||
*/
|
||||
return g_strdup_printf("%s", if_info->friendly_name);
|
||||
#else
|
||||
/*
|
||||
* On UN*X, if we have a friendly name, show it along
|
||||
* with the interface name; the interface name is short
|
||||
* and somewhat friendly, and many UN*X users are used
|
||||
* to interface names, so we should show it.
|
||||
*/
|
||||
return g_strdup_printf("%s: %s", if_info->friendly_name, if_info->name);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (if_info->vendor_description) {
|
||||
/* We have a device description from libpcap. */
|
||||
return g_strdup_printf("%s: %s", if_info->vendor_description, if_info->name);
|
||||
}
|
||||
|
||||
/* No additional descriptions found. */
|
||||
return g_strdup(if_info->name);
|
||||
}
|
||||
|
||||
#endif /* HAVE_LIBPCAP */
|
||||
|
||||
/*
|
||||
|
|
|
@ -175,6 +175,15 @@ extern void set_active_dlt(interface_t *device, int global_default_dlt);
|
|||
|
||||
extern GString *get_iface_list_string(capture_options *capture_opts, guint32 style);
|
||||
|
||||
/** Get the interface display name to present in the interfaces list.
|
||||
*
|
||||
* @param description A user-specified capture device description
|
||||
* @param if_info The if_info for the interface
|
||||
*
|
||||
* @return A interface display name (must be g_free'd later)
|
||||
*/
|
||||
extern gchar *get_iface_display_name(const gchar *description, const if_info_t *if_info);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
|
|
@ -64,7 +64,6 @@ scan_local_interfaces(void (*update_cb)(void))
|
|||
{
|
||||
GList *if_entry, *lt_entry, *if_list;
|
||||
if_info_t *if_info, temp;
|
||||
char *if_string;
|
||||
gchar *descr;
|
||||
if_capabilities_t *caps=NULL;
|
||||
gint linktype_count;
|
||||
|
@ -141,42 +140,9 @@ scan_local_interfaces(void (*update_cb)(void))
|
|||
#endif
|
||||
/* Is this interface hidden and, if so, should we include it anyway? */
|
||||
|
||||
/* Do we have a user-supplied description? */
|
||||
descr = capture_dev_user_descr_find(if_info->name);
|
||||
if (descr != NULL) {
|
||||
/* Yes, we have a user-supplied description; use it. */
|
||||
if_string = g_strdup_printf("%s: %s", descr, if_info->name);
|
||||
g_free(descr);
|
||||
} else {
|
||||
/* No, we don't have a user-supplied description; did we get
|
||||
one from the OS or libpcap? */
|
||||
if (if_info->friendly_name != NULL) {
|
||||
/* We have a friendly name from the OS, use it */
|
||||
#ifdef _WIN32
|
||||
/*
|
||||
* On Windows, if we have a friendly name, just show it,
|
||||
* don't show the name, as that's a string made out of
|
||||
* the device GUID, and not at all friendly.
|
||||
*/
|
||||
if_string = g_strdup_printf("%s", if_info->friendly_name);
|
||||
#else
|
||||
/*
|
||||
* On UN*X, if we have a friendly name, show it along
|
||||
* with the interface name; the interface name is short
|
||||
* and somewhat friendly, and many UN*X users are used
|
||||
* to interface names, so we should show it.
|
||||
*/
|
||||
if_string = g_strdup_printf("%s: %s", if_info->friendly_name, if_info->name);
|
||||
#endif
|
||||
} else if (if_info->vendor_description != NULL) {
|
||||
/* We have a device description from libpcap - use it. */
|
||||
if_string = g_strdup_printf("%s: %s", if_info->vendor_description, if_info->name);
|
||||
} else {
|
||||
/* No. */
|
||||
if_string = g_strdup(if_info->name);
|
||||
}
|
||||
}
|
||||
device.display_name = if_string;
|
||||
device.display_name = get_iface_display_name(descr, if_info);
|
||||
g_free(descr);
|
||||
device.selected = FALSE;
|
||||
if (prefs_is_capture_device_hidden(if_info->name)) {
|
||||
device.hidden = TRUE;
|
||||
|
|
|
@ -389,14 +389,7 @@ void ManageInterfacesDialog::saveLocalCommentChanges(QTreeWidgetItem* item)
|
|||
}
|
||||
|
||||
g_free(device.display_name);
|
||||
// XXX The GTK+ UI uses the raw device name instead of the friendly name.
|
||||
// This seems to make more sense.
|
||||
gchar *if_string = device.friendly_name ? device.friendly_name : device.name;
|
||||
if (comment.isEmpty()) {
|
||||
device.display_name = g_strdup(if_string);
|
||||
} else {
|
||||
device.display_name = qstring_strdup(QString("%1: %2").arg(comment).arg(if_string));
|
||||
}
|
||||
device.display_name = get_iface_display_name(comment.toUtf8().constData(), &device.if_info);
|
||||
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
|
||||
g_array_insert_val(global_capture_opts.all_ifaces, i, device);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue