summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/capture.c26
-rw-r--r--ui/gtk/Makefile.common1
-rw-r--r--ui/gtk/capture_dlg.c2
-rw-r--r--ui/gtk/capture_if_details_dlg_win32.c8
-rw-r--r--ui/gtk/color_dlg.c2
-rw-r--r--ui/gtk/main.c2
-rw-r--r--ui/gtk/main_airpcap_toolbar.c10
-rw-r--r--ui/gtk/manual_addr_resolv.c2
-rw-r--r--ui/gtk/prefs_dlg.c4
-rw-r--r--ui/gtk/proto_dlg.c3
-rw-r--r--ui/gtk/simple_dialog.c16
-rw-r--r--ui/gtk/simple_dialog.h109
-rw-r--r--ui/qt/CMakeLists.txt4
-rw-r--r--ui/qt/Makefile.common5
-rw-r--r--ui/qt/Wireshark.pro4
-rw-r--r--ui/qt/main.cpp4
-rw-r--r--ui/qt/main_window.cpp63
-rw-r--r--ui/qt/simple_dialog.cpp266
-rw-r--r--ui/qt/simple_dialog.h (renamed from ui/qt/simple_dialog_qt.h)32
-rw-r--r--ui/qt/simple_dialog_qt.cpp268
-rw-r--r--ui/simple_dialog.h57
21 files changed, 512 insertions, 376 deletions
diff --git a/ui/capture.c b/ui/capture.c
index 6ae268e90b..d2dcdfd953 100644
--- a/ui/capture.c
+++ b/ui/capture.c
@@ -174,7 +174,7 @@ capture_start(capture_options *capture_opts, capture_session *cap_session, void(
capture_opts->save_file = NULL;
}
- g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Start failed!");
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Start failed.");
cap_session->state = CAPTURE_STOPPED;
} else {
/* the capture child might not respond shortly after bringing it up */
@@ -295,18 +295,18 @@ capture_input_read_all(capture_session *cap_session, gboolean is_tempfile,
/* if we didn't capture even a single packet, close the file again */
if(cf_get_packet_count((capture_file *)cap_session->cf) == 0 && !capture_opts->restart) {
simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK,
-"%sNo packets captured!%s\n"
+"%sNo packets captured.%s\n"
"\n"
-"As no data was captured, closing the %scapture file!\n"
+"As no data was captured, closing the %scapture file.\n"
"\n"
"\n"
-"Help about capturing can be found at:\n"
+"Help about capturing can be found at\n"
"\n"
" http://wiki.wireshark.org/CaptureSetup"
#ifdef _WIN32
"\n\n"
"Wireless (Wi-Fi/WLAN):\n"
-"Try to switch off promiscuous mode in the Capture Options!"
+"Try to switch off promiscuous mode in the Capture Options"
#endif
"",
simple_dialog_primary_start(), simple_dialog_primary_end(),
@@ -326,7 +326,7 @@ capture_input_new_file(capture_session *cap_session, gchar *new_file)
int err;
if(cap_session->state == CAPTURE_PREPARING) {
- g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture started!");
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture started");
}
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "File: \"%s\"", new_file);
@@ -516,7 +516,7 @@ capture_input_cfilter_error_message(capture_session *cap_session, guint i,
/* Did the user try a display filter? */
if (dfilter_compile(interface_opts.cfilter, &rfcode) && rfcode != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
- "%sInvalid capture filter \"%s\" for interface %s!%s\n"
+ "%sInvalid capture filter \"%s\" for interface %s.%s\n"
"\n"
"That string looks like a valid display filter; however, it isn't a valid\n"
"capture filter (%s).\n"
@@ -530,7 +530,7 @@ capture_input_cfilter_error_message(capture_session *cap_session, guint i,
dfilter_free(rfcode);
} else {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
- "%sInvalid capture filter \"%s\" for interface %s!%s\n"
+ "%sInvalid capture filter \"%s\" for interface %s.%s\n"
"\n"
"That string isn't a valid capture filter (%s).\n"
"See the User's Guide for a description of the capture filter syntax.",
@@ -552,7 +552,7 @@ capture_input_closed(capture_session *cap_session, gchar *msg)
int err;
int packet_count_save;
- g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture stopped!");
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture stopped.");
g_assert(cap_session->state == CAPTURE_PREPARING || cap_session->state == CAPTURE_RUNNING);
if (msg != NULL)
@@ -585,18 +585,18 @@ capture_input_closed(capture_session *cap_session, gchar *msg)
case CF_READ_OK:
if ((packet_count_save == 0) && !capture_opts->restart) {
simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK,
- "%sNo packets captured!%s\n"
+ "%sNo packets captured.%s\n"
"\n"
- "As no data was captured, closing the %scapture file!\n"
+ "As no data was captured, closing the %scapture file.\n"
"\n"
"\n"
- "Help about capturing can be found at:\n"
+ "Help about capturing can be found at\n"
"\n"
" http://wiki.wireshark.org/CaptureSetup"
#ifdef _WIN32
"\n\n"
"Wireless (Wi-Fi/WLAN):\n"
- "Try to switch off promiscuous mode in the Capture Options!"
+ "Try to switch off promiscuous mode in the Capture Options."
#endif
"",
simple_dialog_primary_start(), simple_dialog_primary_end(),
diff --git a/ui/gtk/Makefile.common b/ui/gtk/Makefile.common
index c2a0a726e1..5238d7d27e 100644
--- a/ui/gtk/Makefile.common
+++ b/ui/gtk/Makefile.common
@@ -305,6 +305,7 @@ noinst_HEADERS = \
sctp_stat_gtk.h \
service_response_time_table.h \
time_shift_dlg.h \
+ simple_dialog.h \
stock_icons.h \
summary_dlg.h \
supported_protos_dlg.h \
diff --git a/ui/gtk/capture_dlg.c b/ui/gtk/capture_dlg.c
index 7a299d047c..da8839e361 100644
--- a/ui/gtk/capture_dlg.c
+++ b/ui/gtk/capture_dlg.c
@@ -47,7 +47,6 @@
#include "ui/preference_utils.h"
#include "ui/recent.h"
#include "ui/recent_utils.h"
-#include "ui/simple_dialog.h"
#include "ui/util.h"
#include "ui/gtk/main.h"
@@ -67,6 +66,7 @@
#include "ui/gtk/menus.h"
#include "ui/gtk/prefs_dlg.h"
#include "ui/gtk/main_80211_toolbar.h"
+#include "simple_dialog.h"
#include "ui/gtk/keys.h"
diff --git a/ui/gtk/capture_if_details_dlg_win32.c b/ui/gtk/capture_if_details_dlg_win32.c
index 55a561888b..197b364e26 100644
--- a/ui/gtk/capture_if_details_dlg_win32.c
+++ b/ui/gtk/capture_if_details_dlg_win32.c
@@ -30,15 +30,15 @@
#include <gtk/gtk.h>
-#include <epan/value_string.h>
-#include <epan/addr_resolv.h>
+#include "epan/value_string.h"
+#include "epan/addr_resolv.h"
-#include <wsutil/str_util.h>
+#include "wsutil/str_util.h"
#include "../file.h"
#include "ui/capture.h"
-#include "ui/simple_dialog.h"
+#include "simple_dialog.h"
#include "ui/gtk/main.h"
#include "ui/gtk/dlg_utils.h"
diff --git a/ui/gtk/color_dlg.c b/ui/gtk/color_dlg.c
index aca38411ca..5f9edb3f60 100644
--- a/ui/gtk/color_dlg.c
+++ b/ui/gtk/color_dlg.c
@@ -34,7 +34,7 @@
#include "../color_filters.h"
#include "../file.h"
-#include "ui/simple_dialog.h"
+#include "simple_dialog.h"
#include "ui/gtk/main.h"
#include "ui/gtk/color_utils.h"
diff --git a/ui/gtk/main.c b/ui/gtk/main.c
index 322c5dcb12..510b85fc92 100644
--- a/ui/gtk/main.c
+++ b/ui/gtk/main.c
@@ -119,7 +119,6 @@
#include "ui/recent.h"
#include "ui/recent_utils.h"
#include "ui/software_update.h"
-#include "ui/simple_dialog.h"
#include "ui/ui_util.h"
#include "ui/util.h"
@@ -192,6 +191,7 @@
#include "ui/gtk/filter_expression_save_dlg.h"
#include "ui/gtk/conversations_table.h"
#include "ui/gtk/hostlist_table.h"
+#include "simple_dialog.h"
#include "ui/gtk/old-gtk-compat.h"
diff --git a/ui/gtk/main_airpcap_toolbar.c b/ui/gtk/main_airpcap_toolbar.c
index d6b1361dea..eec3a2e871 100644
--- a/ui/gtk/main_airpcap_toolbar.c
+++ b/ui/gtk/main_airpcap_toolbar.c
@@ -31,19 +31,19 @@
#include <gtk/gtk.h>
#include "ui/gtk/old-gtk-compat.h"
-#include <epan/epan.h>
-#include <epan/frequency-utils.h>
+#include "epan/epan.h"
+#include "epan/frequency-utils.h"
#include "ui/recent.h"
-#include "ui/simple_dialog.h"
+#include "simple_dialog.h"
#include "main.h"
#include "main_airpcap_toolbar.h"
#include "keys.h"
-#include <caputils/airpcap.h>
-#include <caputils/airpcap_loader.h>
+#include "caputils/airpcap.h"
+#include "caputils/airpcap_loader.h"
#include "airpcap_dlg.h"
#include "airpcap_gui_utils.h"
diff --git a/ui/gtk/manual_addr_resolv.c b/ui/gtk/manual_addr_resolv.c
index e2bb976f83..a55899017b 100644
--- a/ui/gtk/manual_addr_resolv.c
+++ b/ui/gtk/manual_addr_resolv.c
@@ -28,7 +28,6 @@
#include <gtk/gtk.h>
#include "epan/addr_resolv.h"
-#include "ui/simple_dialog.h"
#include "ui/gtk/dlg_utils.h"
#include "ui/gtk/gui_utils.h"
@@ -38,6 +37,7 @@
#include "ui/gtk/manual_addr_resolv.h"
#include "ui/gtk/old-gtk-compat.h"
#include "ui/gtk/packet_win.h"
+#include "simple_dialog.h"
GtkWidget *man_addr_resolv_dlg = NULL;
diff --git a/ui/gtk/prefs_dlg.c b/ui/gtk/prefs_dlg.c
index 3dc299e26d..769b24505a 100644
--- a/ui/gtk/prefs_dlg.c
+++ b/ui/gtk/prefs_dlg.c
@@ -34,9 +34,8 @@
#include <epan/epan_dissect.h>
#include <epan/print.h>
-#include "../file.h"
+#include "file.h"
#include "ui/preference_utils.h"
-#include "ui/simple_dialog.h"
#include "ui/gtk/main.h"
#include "ui/gtk/prefs_column.h"
@@ -56,6 +55,7 @@
#include "ui/gtk/file_dlg.h"
#include "ui/gtk/dlg_utils.h"
#include "ui/gtk/packet_win.h"
+#include "simple_dialog.h"
#ifdef HAVE_LIBPCAP
#ifdef _WIN32
diff --git a/ui/gtk/proto_dlg.c b/ui/gtk/proto_dlg.c
index 41724ead36..e9c2ac1b1d 100644
--- a/ui/gtk/proto_dlg.c
+++ b/ui/gtk/proto_dlg.c
@@ -36,13 +36,12 @@
#include "ui/util.h"
-#include "ui/simple_dialog.h"
-
#include "ui/gtk/main.h"
#include "ui/gtk/gui_utils.h"
#include "ui/gtk/dlg_utils.h"
#include "ui/gtk/proto_dlg.h"
#include "ui/gtk/help_dlg.h"
+#include "simple_dialog.h"
static gboolean proto_delete_event_cb(GtkWidget *, GdkEvent *, gpointer);
static void proto_ok_cb(GtkWidget *, gpointer);
diff --git a/ui/gtk/simple_dialog.c b/ui/gtk/simple_dialog.c
index 8498f312c2..a2f61522ea 100644
--- a/ui/gtk/simple_dialog.c
+++ b/ui/gtk/simple_dialog.c
@@ -25,16 +25,16 @@
#include <gtk/gtk.h>
-#include <epan/strutil.h>
+#include "epan/strutil.h"
-#include "ui/simple_dialog.h"
+#include "simple_dialog.h"
-#include "ui/gtk/gtkglobals.h"
-#include "ui/gtk/dlg_utils.h"
-#include "ui/gtk/gui_utils.h"
-#include "ui/gtk/stock_icons.h"
+#include "gtkglobals.h"
+#include "dlg_utils.h"
+#include "gui_utils.h"
+#include "stock_icons.h"
-#include "ui/gtk/old-gtk-compat.h"
+#include "old-gtk-compat.h"
static void simple_dialog_cancel_cb(GtkWidget *, gpointer);
@@ -298,7 +298,7 @@ display_queued_messages(void)
* ... : Argument list for msg_format
*/
-gpointer
+static gpointer
vsimple_dialog(ESD_TYPE_E type, gint btn_mask, const gchar *msg_format, va_list ap)
{
gchar *message;
diff --git a/ui/gtk/simple_dialog.h b/ui/gtk/simple_dialog.h
new file mode 100644
index 0000000000..f805e959fe
--- /dev/null
+++ b/ui/gtk/simple_dialog.h
@@ -0,0 +1,109 @@
+/* simple_dialog.h
+ * Definitions for alert box routines with toolkit-independent APIs but
+ * toolkit-dependent implementations.
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __SIMPLE_DIALOG_H__
+#define __SIMPLE_DIALOG_H__
+
+#include "ui/simple_dialog.h"
+
+/** @file
+ * Simple dialog box.
+ * @ingroup dialog_group
+ */
+
+/** Callback function type for simple_dialog_set_cb() */
+typedef void (* simple_dialog_cb_t) (gpointer dialog, gint btn, gpointer data);
+
+/** Set the callback function for the dialog, called when a button was pressed.
+ *
+ * @param dialog the dialog from simple_dialog()
+ * @param callback_fct the callback function to set
+ * @param data data to be passed to the callback function
+ */
+extern void simple_dialog_set_cb(gpointer dialog, simple_dialog_cb_t callback_fct, gpointer data);
+
+/** Close the dialog, useful for "no button" dialogs.
+ *
+ * @param dialog the dialog to close from simple_dialog()
+ */
+extern void simple_dialog_close(gpointer dialog);
+
+/** Add a check button to the dialog (e.g. "Don't show this message again")
+ *
+ * @param dialog the dialog from simple_dialog()
+ * @param text the text to display
+ */
+extern void simple_dialog_check_set(gpointer dialog, const gchar *text);
+
+/** Get the check buttons state.
+ *
+ * @param dialog the dialog from simple_dialog()
+ * @return current button state (TRUE is checked)
+ */
+extern gboolean simple_dialog_check_get(gpointer dialog);
+
+/**
+ * Display all queued messages.
+ * If a routine is called to display a dialog before there are any windows
+ * open, information to use to display the dialog is queued up. This
+ * routine should be called once there are windows open, so that the queued
+ * up dialogs are displayed on top of those windows.
+ */
+extern void display_queued_messages(void);
+
+/*
+ * Alert box, with optional "don't show this message again" variable
+ * and checkbox, and optional secondary text.
+ */
+extern void simple_message_box(ESD_TYPE_E type, gboolean *notagain,
+ const char *secondary_msg,
+ const char *msg_format, ...) G_GNUC_PRINTF(4, 5);
+
+/*
+ * Error alert box, taking a format and a va_list argument.
+ */
+extern void vsimple_error_message_box(const char *msg_format, va_list ap);
+
+/*
+ * Error alert box, taking a format and a list of arguments.
+ */
+extern void simple_error_message_box(const char *msg_format, ...);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __SIMPLE_DIALOG_H__ */
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt
index bacb144fb9..295b41bd05 100644
--- a/ui/qt/CMakeLists.txt
+++ b/ui/qt/CMakeLists.txt
@@ -88,7 +88,7 @@ set(WIRESHARK_QT_HEADERS
search_frame.h
sequence_diagram.h
sequence_dialog.h
- simple_dialog_qt.h
+ simple_dialog.h
splash_overlay.h
stats_tree_dialog.h
summary_dialog.h
@@ -184,7 +184,7 @@ set(WIRESHARK_QT_SRC
search_frame.cpp
sequence_diagram.cpp
sequence_dialog.cpp
- simple_dialog_qt.cpp
+ simple_dialog.cpp
splash_overlay.cpp
sparkline_delegate.cpp
stock_icon.cpp
diff --git a/ui/qt/Makefile.common b/ui/qt/Makefile.common
index 9e9941e8e1..1c3f67b37e 100644
--- a/ui/qt/Makefile.common
+++ b/ui/qt/Makefile.common
@@ -70,6 +70,7 @@ NODIST_GENERATED_HEADER_FILES = \
ui_stats_tree_dialog.h \
ui_search_frame.h \
ui_sequence_dialog.h \
+ ui_simple_dialog.h \
ui_splash_overlay.h \
ui_summary_dialog.h \
ui_tcp_stream_dialog.h \
@@ -180,7 +181,7 @@ MOC_HDRS = \
sctp_graph_byte_dialog.h \
sequence_diagram.h \
sequence_dialog.h \
- simple_dialog_qt.h \
+ simple_dialog.h \
sparkline_delegate.h \
splash_overlay.h \
stats_tree_dialog.h \
@@ -372,7 +373,7 @@ WIRESHARK_QT_SRC = \
search_frame.cpp \
sequence_diagram.cpp \
sequence_dialog.cpp \
- simple_dialog_qt.cpp \
+ simple_dialog.cpp \
sparkline_delegate.cpp \
splash_overlay.cpp \
stats_tree_dialog.cpp \
diff --git a/ui/qt/Wireshark.pro b/ui/qt/Wireshark.pro
index c01681ff42..0bcdc85b5b 100644
--- a/ui/qt/Wireshark.pro
+++ b/ui/qt/Wireshark.pro
@@ -573,7 +573,7 @@ HEADERS += \
related_packet_delegate.h \
sequence_diagram.h \
sequence_dialog.h \
- simple_dialog_qt.h \
+ simple_dialog.h \
sparkline_delegate.h \
syntax_line_edit.h \
time_shift_dialog.h \
@@ -654,7 +654,7 @@ SOURCES += \
search_frame.cpp \
sequence_diagram.cpp \
sequence_dialog.cpp \
- simple_dialog_qt.cpp \
+ simple_dialog.cpp \
sparkline_delegate.cpp \
splash_overlay.cpp \
stats_tree_dialog.cpp \
diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp
index 7281105bc0..82dc1d09fd 100644
--- a/ui/qt/main.cpp
+++ b/ui/qt/main.cpp
@@ -21,8 +21,9 @@
#include "config.h"
-#include "wireshark_application.h"
+#include "simple_dialog.h"
#include "main_window.h"
+#include "wireshark_application.h"
#include <ctype.h>
#include "globals.h"
@@ -799,6 +800,7 @@ int main(int argc, char *argv[])
// Init the main window (and splash)
main_w = new(MainWindow);
main_w->show();
+ SimpleDialog::displayQueuedMessages(main_w);
// We may not need a queued connection here but it would seem to make sense
// to force the issue.
main_w->connect(&ws_app, SIGNAL(openCaptureFile(QString&,QString&,unsigned int)),
diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp
index ce51981129..9ca45f6bf4 100644
--- a/ui/qt/main_window.cpp
+++ b/ui/qt/main_window.cpp
@@ -49,6 +49,7 @@
#include "export_dissection_dialog.h"
#include "import_text_dialog.h"
#include "proto_tree.h"
+#include "simple_dialog.h"
#include "stock_icon.h"
#include "wireshark_application.h"
@@ -80,6 +81,68 @@ void pipe_input_set_handler(gint source, gpointer user_data, int *child_process,
gbl_cur_main_window_->setPipeInputHandler(source, user_data, child_process, input_cb);
}
+gpointer
+simple_dialog(ESD_TYPE_E type, gint btn_mask, const gchar *msg_format, ...)
+{
+ va_list ap;
+
+ va_start(ap, msg_format);
+ SimpleDialog sd(gbl_cur_main_window_, type, btn_mask, msg_format, ap);
+ va_end(ap);
+
+ sd.exec();
+ return NULL;
+}
+
+/*
+ * Alert box, with optional "don't show this message again" variable
+ * and checkbox, and optional secondary text.
+ */
+void
+simple_message_box(ESD_TYPE_E type, gboolean *notagain,
+ const char *secondary_msg, const char *msg_format, ...)
+{
+ if (notagain && *notagain) {
+ return;
+ }
+
+ va_list ap;
+
+ va_start(ap, msg_format);
+ SimpleDialog sd(gbl_cur_main_window_, type, ESD_BTN_OK, msg_format, ap);
+ va_end(ap);
+
+ sd.setDetailedText(secondary_msg);
+
+#if (QT_VERSION > QT_VERSION_CHECK(5, 2, 0))
+ QCheckBox *cb = new QCheckBox();
+ if (notagain) {
+ cb->setChecked(true);
+ cb->setText(QObject::tr("Don't show this message again."));
+ sd.setCheckBox(cb);
+ }
+#endif
+
+ sd.exec();
+
+#if (QT_VERSION > QT_VERSION_CHECK(5, 2, 0))
+ if (notagain) {
+ *notagain = cb->isChecked();
+ }
+#endif
+}
+
+/*
+ * Error alert box, taking a format and a va_list argument.
+ */
+void
+vsimple_error_message_box(const char *msg_format, va_list ap)
+{
+ SimpleDialog sd(NULL, ESD_TYPE_ERROR, ESD_BTN_OK, msg_format, ap);
+ sd.exec();
+}
+
+
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
main_ui_(new Ui::MainWindow),
diff --git a/ui/qt/simple_dialog.cpp b/ui/qt/simple_dialog.cpp
new file mode 100644
index 0000000000..9f6335fd20
--- /dev/null
+++ b/ui/qt/simple_dialog.cpp
@@ -0,0 +1,266 @@
+/* simple_dialog.cpp
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "simple_dialog.h"
+
+#include "epan/strutil.h"
+
+#include "ui/utf8_entities.h"
+
+#include "qt_ui_utils.h"
+
+#include <QMessageBox>
+#include <QTextCodec>
+
+/* Simple dialog function - Displays a dialog box with the supplied message
+ * text.
+ *
+ * This is meant to be used as a backend for the functions defined in
+ * ui/simple_dialog.h. Qt code should use QMessageBox directly.
+ *
+ * Args:
+ * type : One of ESD_TYPE_*.
+ * btn_mask : The value passed in determines which buttons are displayed.
+ * msg_format : Sprintf-style format of the text displayed in the dialog.
+ * ... : Argument list for msg_format
+ */
+
+QList<MessagePair> message_queue_;
+ESD_TYPE_E max_severity_ = ESD_TYPE_INFO;
+
+const char *primary_delimiter_ = "\uffff";
+
+const char *
+simple_dialog_primary_start(void) {
+ return primary_delimiter_;
+}
+
+const char *
+simple_dialog_primary_end(void) {
+ return primary_delimiter_;
+}
+
+char *
+simple_dialog_format_message(const char *msg)
+{
+ char *str;
+
+ if (msg) {
+ str = xml_escape(msg);
+ } else {
+ str = NULL;
+ }
+ return str;
+}
+
+/*
+ * Error alert box, taking a format and a list of arguments.
+ */
+void
+simple_error_message_box(const char *msg_format, ...)
+{
+ va_list ap;
+
+ va_start(ap, msg_format);
+ vsimple_error_message_box(msg_format, ap);
+ va_end(ap);
+}
+
+#include <QDebug>
+SimpleDialog::SimpleDialog(QWidget *parent, ESD_TYPE_E type, int btn_mask, const char *msg_format, va_list ap) :
+ QMessageBox(parent)
+{
+ gchar *vmessage;
+ QString message;
+
+ vmessage = g_strdup_vprintf(msg_format, ap);
+ message = QTextCodec::codecForLocale()->toUnicode(vmessage);
+ g_free(vmessage);
+
+ MessagePair msg_pair = splitMessage(message);
+ QString primary = msg_pair.first;
+ QString secondary = msg_pair.second;
+
+ if (primary.isEmpty()) {
+ return;
+ }
+
+ if (!parent) {
+ message_queue_ << msg_pair;
+ if (type > max_severity_) {
+ max_severity_ = type;
+ }
+ return;
+ }
+
+ switch(type) {
+ case ESD_TYPE_ERROR:
+ setIcon(QMessageBox::Critical);
+ break;
+ case ESD_TYPE_WARN:
+ setIcon(QMessageBox::Warning);
+ break;
+ case ESD_TYPE_CONFIRMATION:
+ setIcon(QMessageBox::Question);
+ break;
+ case ESD_TYPE_INFO:
+ default:
+ setIcon(QMessageBox::Information);
+ break;
+ }
+
+ if (btn_mask & ESD_BTN_OK) {
+ addButton(QMessageBox::Ok);
+ }
+ if (btn_mask & ESD_BTN_CANCEL) {
+ addButton(QMessageBox::Cancel);
+ }
+ if (btn_mask & ESD_BTN_YES) {
+ addButton(QMessageBox::Yes);
+ }
+ if (btn_mask & ESD_BTN_NO) {
+ addButton(QMessageBox::No);
+ }
+// if (btn_mask & ESD_BTN_CLEAR) {
+// addButton(QMessageBox::);
+// }
+ if (btn_mask & ESD_BTN_SAVE) {
+ addButton(QMessageBox::Save);
+ }
+ if (btn_mask & ESD_BTN_DONT_SAVE) {
+ addButton(QMessageBox::Discard);
+ }
+// if (btn_mask & ESD_BTN_QUIT_DONT_SAVE) {
+// addButton(QMessageBox::);
+// }
+
+ setText(primary);
+ setInformativeText(secondary);
+}
+
+SimpleDialog::~SimpleDialog()
+{
+}
+
+void SimpleDialog::displayQueuedMessages(QWidget *parent)
+{
+ if (message_queue_.isEmpty()) {
+ return;
+ }
+
+ QMessageBox mb(parent);
+
+ switch(max_severity_) {
+ case ESD_TYPE_ERROR:
+ mb.setIcon(QMessageBox::Critical);
+ break;
+ case ESD_TYPE_WARN:
+ mb.setIcon(QMessageBox::Warning);
+ break;
+ case ESD_TYPE_CONFIRMATION:
+ mb.setIcon(QMessageBox::Question);
+ break;
+ case ESD_TYPE_INFO:
+ default:
+ mb.setIcon(QMessageBox::Information);
+ break;
+ }
+
+ mb.addButton(QMessageBox::Ok);
+
+ if (message_queue_.length() > 1) {
+ QStringList msg_details;
+ QString first_primary = message_queue_[0].first;
+ first_primary.append(UTF8_HORIZONTAL_ELLIPSIS);
+
+ mb.setText(tr("Multiple problems found"));
+ mb.setInformativeText(first_primary);
+
+ foreach (MessagePair msg_pair, message_queue_) {
+ msg_details << msg_pair.first;
+ if (!msg_pair.second.isEmpty()) {
+ msg_details.append(msg_pair.second);
+ }
+ }
+ mb.setDetailedText(msg_details.join("\n\n"));
+ } else {
+ mb.setText(message_queue_[0].first);
+ mb.setInformativeText(message_queue_[0].second);
+ }
+
+ message_queue_.clear();
+ max_severity_ = ESD_TYPE_INFO;
+
+ mb.exec();
+}
+
+int SimpleDialog::exec()
+{
+ if (!parentWidget()) {
+ return 0;
+ }
+
+ switch (QMessageBox::exec()) {
+ case QMessageBox::Ok:
+ return ESD_BTN_OK;
+ case QMessageBox::Yes:
+ return ESD_BTN_YES;
+ case QMessageBox::No:
+ return ESD_BTN_NO;
+ case QMessageBox::Save:
+ return ESD_BTN_SAVE;
+ case QMessageBox::Discard:
+ return ESD_BTN_DONT_SAVE;
+ case QMessageBox::Cancel: // XXX Should OK be the default?
+ default:
+ return ESD_BTN_CANCEL;
+ }
+}
+
+const MessagePair SimpleDialog::splitMessage(QString &message) const
+{
+ if (message.startsWith(primary_delimiter_)) {
+ QStringList parts = message.split(primary_delimiter_, QString::SkipEmptyParts);
+ switch (parts.length()) {
+ case 0:
+ return MessagePair(QString(), QString());
+ case 1:
+ return MessagePair(parts[0], QString());
+ default:
+ QString first = parts.takeFirst();
+ return MessagePair(first, parts.join(" "));
+ }
+ }
+ return MessagePair(message, QString());
+}
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
diff --git a/ui/qt/simple_dialog_qt.h b/ui/qt/simple_dialog.h
index 7646658fc4..98ab98598a 100644
--- a/ui/qt/simple_dialog_qt.h
+++ b/ui/qt/simple_dialog.h
@@ -1,4 +1,4 @@
-/* simple_dialog_qt.h
+/* simple_dialog.h
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
@@ -19,24 +19,38 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef SIMPLE_DIALOG_QT_H
-#define SIMPLE_DIALOG_QT_H
+#ifndef SIMPLE_DIALOG_H
+#define SIMPLE_DIALOG_H
-#include <QErrorMessage>
+#include "config.h"
-class SimpleDialog : public QErrorMessage
+#include <stdio.h>
+
+#include <glib.h>
+
+#include "ui/simple_dialog.h"
+
+#include <QMessageBox>
+
+typedef QPair<QString,QString> MessagePair;
+
+class SimpleDialog : public QMessageBox
{
Q_OBJECT
-public:
- explicit SimpleDialog(QWidget *parent = 0);
-signals:
+public:
+ explicit SimpleDialog(QWidget *parent, ESD_TYPE_E type, int btn_mask, const char *msg_format, va_list ap);
+ ~SimpleDialog();
+ static void displayQueuedMessages(QWidget *parent = 0);
public slots:
+ int exec();
+private:
+ const MessagePair splitMessage(QString &message) const;
};
-#endif // SIMPLE_DIALOG_QT_H
+#endif // SIMPLE_DIALOG_H
/*
* Editor modelines
diff --git a/ui/qt/simple_dialog_qt.cpp b/ui/qt/simple_dialog_qt.cpp
deleted file mode 100644
index a45fb12bba..0000000000
--- a/ui/qt/simple_dialog_qt.cpp
+++ /dev/null
@@ -1,268 +0,0 @@
-/* simple_dialog_qt.cpp
- *
- * Wireshark - Network traffic analyzer
- * By Gerald Combs <gerald@wireshark.org>
- * Copyright 1998 Gerald Combs
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include "config.h"
-
-#include <stdio.h>
-
-#include <glib.h>
-
-#include <epan/strutil.h>
-
-#include "ui/simple_dialog.h"
-
-#include "simple_dialog_qt.h"
-
-#include <QMessageBox>
-
-/* Simple dialog function - Displays a dialog box with the supplied message
- * text.
- *
- * Args:
- * type : One of ESD_TYPE_*.
- * btn_mask : The value passed in determines which buttons are displayed.
- * msg_format : Sprintf-style format of the text displayed in the dialog.
- * ... : Argument list for msg_format
- */
-
-gpointer
-vsimple_dialog(ESD_TYPE_E type, gint btn_mask, const gchar *msg_format, va_list ap)
-{
-
- gchar *vmessage;
- gchar *message;
- SimpleDialog *dlg = NULL;
-// queued_message_t *queued_message;
-// GtkWidget *win;
-// GdkWindowState state = 0;
-
- /* Format the message. */
- vmessage = g_strdup_vprintf(msg_format, ap);
-
- /* convert character encoding from locale to UTF8 (using iconv) */
- message = g_locale_to_utf8(vmessage, -1, NULL, NULL, NULL);
- g_free(vmessage);
-
- g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: vsimple_dialog t: %d bm: %d m: %s", type, btn_mask, message);
-
-
-// if (top_level != NULL) {
-// state = gdk_window_get_state(top_level->window);
-// }
-
-// /* If we don't yet have a main window or it's iconified, don't show the
-// dialog. If showing up a dialog, while main window is iconified, program
-// will become unresponsive! */
-// if (top_level == NULL || state & GDK_WINDOW_STATE_ICONIFIED) {
-
-// queued_message = g_malloc(sizeof (queued_message_t));
-// queued_message->type = type;
-// queued_message->btn_mask = btn_mask;
-// queued_message->message = message;
-// message_queue = g_slist_append(message_queue, queued_message);
-// return NULL;
-// }
-
-// /*
-// * Do we have any queued up messages? If so, pop them up.
-// */
-// display_queued_messages();
-
-// win = display_simple_dialog(type, btn_mask, message);
-
- g_free(message);
-
- return dlg;
-}
-
-gpointer
-simple_dialog(ESD_TYPE_E type, gint btn_mask, const gchar *msg_format, ...)
-{
- va_list ap;
- gpointer ret;
-
- va_start(ap, msg_format);
- ret = vsimple_dialog(type, btn_mask, msg_format, ap);
- va_end(ap);
- return ret;
-}
-
-const char *
-simple_dialog_primary_start(void) {
- return "";
-}
-
-const char *
-simple_dialog_primary_end(void) {
- return "";
-}
-
-char *
-simple_dialog_format_message(const char *msg)
-{
- char *str;
-
- if (msg) {
- str = xml_escape(msg);
- } else {
- str = NULL;
- }
- return str;
-}
-
-void simple_dialog_set_cb(gpointer dialog, simple_dialog_cb_t callback_fct, gpointer data)
-{
- g_log(NULL, G_LOG_LEVEL_DEBUG, "FIX: simple_dialog_set_cb d: %p cf: %p d: %p", dialog, callback_fct, data);
-
-// g_object_set_data(G_OBJECT(GTK_WIDGET(dialog)), CALLBACK_FCT_KEY, callback_fct);
-// g_object_set_data(G_OBJECT(GTK_WIDGET(dialog)), CALLBACK_DATA_KEY, data);
-}
-
-
-SimpleDialog::SimpleDialog(QWidget *parent) :
- QErrorMessage(parent)
-{
-}
-
-static void
-do_simple_message_box(ESD_TYPE_E type, gboolean *notagain,
- const char *secondary_msg, const char *msg_format,
- va_list ap)
-{
- QMessageBox *msg_dialog;
- gchar *message;
-
- if (notagain != NULL) {
- if (*notagain) {
- /*
- * The user had checked the "Don't show this message again" checkbox
- * in the past; don't bother showing it.
- */
- return;
- }
- }
-
- /*
- * XXX - this should be passed the main window.
- * Also, this should be set to window modal by setting its window
- * modality to Qt::WindowModal, so it shows up as a sheet in
- * OS X.
- */
- msg_dialog = new QMessageBox(NULL);
- switch (type) {
-
- case ESD_TYPE_INFO:
- msg_dialog->setIcon(QMessageBox::Information);
- break;
-
- case ESD_TYPE_WARN:
- msg_dialog->setIcon(QMessageBox::Warning);
- break;
-
- case ESD_TYPE_ERROR:
- msg_dialog->setIcon(QMessageBox::Critical);
- break;
-
- default:
- g_assert_not_reached();
- return;
- }
-
- /* Format the message. */
- message = g_strdup_vprintf(msg_format, ap);
- msg_dialog->setText(message);
- g_free(message);
-
- /* Add the secondary text. */
- if (secondary_msg != NULL)
- msg_dialog->setInformativeText(secondary_msg);
-
-#if 0
- if (notagain != NULL) {
- checkbox = gtk_check_button_new_with_label("Don't show this message again.");
- gtk_container_set_border_width(GTK_CONTAINER(checkbox), 12);
- gtk_box_pack_start(GTK_BOX(gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(msg_dialog))), checkbox,
- TRUE, TRUE, 0);
- gtk_widget_show(checkbox);
- }
-#endif
-
- msg_dialog->exec();
-#if 0
- if (notagain != NULL) {
- /*
- * OK, did they check the checkbox?
- */
- *notagain = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox));
- }
-#endif
- delete msg_dialog;
-}
-
-/*
- * Alert box, with optional "don't show this message again" variable
- * and checkbox, and optional secondary text.
- */
-void
-simple_message_box(ESD_TYPE_E type, gboolean *notagain,
- const char *secondary_msg, const char *msg_format, ...)
-{
- va_list ap;
-
- va_start(ap, msg_format);
- do_simple_message_box(type, notagain, secondary_msg, msg_format, ap);
- va_end(ap);
-}
-
-/*
- * Error alert box, taking a format and a va_list argument.
- */
-void
-vsimple_error_message_box(const char *msg_format, va_list ap)
-{
- do_simple_message_box(ESD_TYPE_ERROR, NULL, NULL, msg_format, ap);
-}
-
-/*
- * Error alert box, taking a format and a list of arguments.
- */
-void
-simple_error_message_box(const char *msg_format, ...)
-{
- va_list ap;
-
- va_start(ap, msg_format);
- do_simple_message_box(ESD_TYPE_ERROR, NULL, NULL, msg_format, ap);
- va_end(ap);
-}
-
-/*
- * Editor modelines
- *
- * Local Variables:
- * c-basic-offset: 4
- * tab-width: 8
- * indent-tabs-mode: nil
- * End:
- *
- * ex: set shiftwidth=4 tabstop=8 expandtab:
- * :indentSize=4:tabSize=8:noTabs=true:
- */
diff --git a/ui/simple_dialog.h b/ui/simple_dialog.h
index 1b71338f27..8a9604d518 100644
--- a/ui/simple_dialog.h
+++ b/ui/simple_dialog.h
@@ -21,8 +21,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef __DIALOG_H__
-#define __DIALOG_H__
+#ifndef __SIMPLE_DIALOG_UI_H__
+#define __SIMPLE_DIALOG_UI_H__
#ifdef __cplusplus
extern "C" {
@@ -90,48 +90,6 @@ extern gpointer simple_dialog(ESD_TYPE_E type, gint btn_mask,
const gchar *msg_format, ...)
G_GNUC_PRINTF(3, 4);
-/** Create and show a simple dialog using a va_list.
- *
- * @param type type of dialog
- * @param btn_mask the buttons to display
- * @param msg_format printf like message format
- * @param ap parameters
- * @return the newly created dialog
- */
-extern gpointer vsimple_dialog(ESD_TYPE_E type, gint btn_mask,
- const gchar *msg_format, va_list ap);
-
-/** Callback function type for simple_dialog_set_cb() */
-typedef void (* simple_dialog_cb_t) (gpointer dialog, gint btn, gpointer data);
-
-/** Set the callback function for the dialog, called when a button was pressed.
- *
- * @param dialog the dialog from simple_dialog()
- * @param callback_fct the callback function to set
- * @param data data to be passed to the callback function
- */
-extern void simple_dialog_set_cb(gpointer dialog, simple_dialog_cb_t callback_fct, gpointer data);
-
-/** Close the dialog, useful for "no button" dialogs.
- *
- * @param dialog the dialog to close from simple_dialog()
- */
-extern void simple_dialog_close(gpointer dialog);
-
-/** Add a check button to the dialog (e.g. "Don't show this message again")
- *
- * @param dialog the dialog from simple_dialog()
- * @param text the text to display
- */
-extern void simple_dialog_check_set(gpointer dialog, const gchar *text);
-
-/** Get the check buttons state.
- *
- * @param dialog the dialog from simple_dialog()
- * @return current button state (TRUE is checked)
- */
-extern gboolean simple_dialog_check_get(gpointer dialog);
-
/** Surround the primary dialog message text by
* simple_dialog_primary_start() and simple_dialog_primary_end().
* To highlight the first sentence (will take effect on GTK2 only).
@@ -151,15 +109,6 @@ extern const char *simple_dialog_primary_end(void);
*/
extern char *simple_dialog_format_message(const char *msg);
-/**
- * Display all queued messages.
- * If a routine is called to display a dialog before there are any windows
- * open, information to use to display the dialog is queued up. This
- * routine should be called once there are windows open, so that the queued
- * up dialogs are displayed on top of those windows.
- */
-extern void display_queued_messages(void);
-
/*
* Alert box, with optional "don't show this message again" variable
* and checkbox, and optional secondary text.
@@ -182,7 +131,7 @@ extern void simple_error_message_box(const char *msg_format, ...);
}
#endif /* __cplusplus */
-#endif /* __DIALOG_H__ */
+#endif /* __SIMPLE_DIALOG_UI_H__ */
/*
* Editor modelines