summaryrefslogtreecommitdiff
path: root/ui/gtk/simple_dialog.c
diff options
context:
space:
mode:
authorGerald Combs <gerald@zing.org>2016-06-18 12:13:15 -0700
committerAnders Broman <a.broman58@gmail.com>2016-06-20 01:25:17 +0000
commit66bb67c6749b01bb41895e341f8d837efa950f79 (patch)
treefc8b579ec8cbf06ee74aa7ddd4bc29aad1855202 /ui/gtk/simple_dialog.c
parente3289a87943bf1aca8b1bbdeda63f1d011f11985 (diff)
downloadwireshark-66bb67c6749b01bb41895e341f8d837efa950f79.tar.gz
GTK+: Truncate simple_message_box messages.
In do_simple_message_box, build our primary message using g_string_vprintf instead of g_strdup_vprintf. Truncate both the primary and secondary messages so that we end up with merely annoyingly wide dialogs instead of insanely wide ones. Bug: 9761 Change-Id: I93ff76344c0da7d97cce5180ed9ecf9349190f6f Reviewed-on: https://code.wireshark.org/review/16005 Reviewed-by: Michael Mann <mmann78@netscape.net> Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/gtk/simple_dialog.c')
-rw-r--r--ui/gtk/simple_dialog.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/ui/gtk/simple_dialog.c b/ui/gtk/simple_dialog.c
index 7f5297ce19..8effc6195e 100644
--- a/ui/gtk/simple_dialog.c
+++ b/ui/gtk/simple_dialog.c
@@ -26,6 +26,8 @@
#include "epan/strutil.h"
+#include "wsutil/utf8_entities.h"
+
#include "simple_dialog.h"
#include "gtkglobals.h"
@@ -413,13 +415,15 @@ simple_dialog_format_message(const char *msg)
return str;
}
+#define MAX_MESSAGE_LEN 200
+#define MAX_SECONDARY_MESSAGE_LEN 500
static void
do_simple_message_box(ESD_TYPE_E type, gboolean *notagain,
const char *secondary_msg, const char *msg_format,
va_list ap)
{
GtkMessageType gtk_message_type;
- gchar *message;
+ GString *message = g_string_new("");
GtkWidget *msg_dialog;
GtkWidget *checkbox = NULL;
@@ -454,16 +458,34 @@ do_simple_message_box(ESD_TYPE_E type, gboolean *notagain,
}
/* Format the message. */
- message = g_strdup_vprintf(msg_format, ap);
+ g_string_vprintf(message, msg_format, ap);
+
+ if (g_utf8_strlen(message->str, message->len) > MAX_MESSAGE_LEN) {
+ const gchar *end = message->str + MAX_MESSAGE_LEN;
+ g_utf8_validate(message->str, MAX_MESSAGE_LEN, &end);
+ g_string_truncate(message, end - message->str);
+ g_string_append(message, UTF8_HORIZONTAL_ELLIPSIS);
+ }
+
msg_dialog = gtk_message_dialog_new(GTK_WINDOW(top_level),
(GtkDialogFlags)(GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT),
gtk_message_type,
GTK_BUTTONS_OK,
- "%s", message);
- g_free(message);
- if (secondary_msg != NULL)
+ "%s", message->str);
+
+ if (secondary_msg != NULL) {
+ g_string_overwrite(message, 0, secondary_msg);
+ if (g_utf8_strlen(message->str, message->len) > MAX_SECONDARY_MESSAGE_LEN) {
+ const gchar *end = message->str + MAX_SECONDARY_MESSAGE_LEN;
+ g_utf8_validate(message->str, MAX_SECONDARY_MESSAGE_LEN, &end);
+ g_string_truncate(message, end - message->str);
+ g_string_append(message, UTF8_HORIZONTAL_ELLIPSIS);
+ }
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msg_dialog),
- "%s", secondary_msg);
+ "%s", message->str);
+ }
+
+ g_string_free(message, TRUE);
if (notagain != NULL) {
checkbox = gtk_check_button_new_with_label("Don't show this message again.");