Update the simple dialog code.

Rename simple_dialog_qt.{cpp,h} to simple_dialog.{cpp,h}. Make it a
subclass of QMessageBox. Queue messages at startup similar to GTK+.

Move the GTK+-specific simple_dialog declarations to
gtk/simple_dialog.h.

Don't yell at the user so much. Replace exclamation points with periods.

Change-Id: I1cc771106222d5e06f1f52d67ac29d6dc367cce4
Reviewed-on: https://code.wireshark.org/review/4288
Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
Gerald Combs 2014-09-24 14:06:23 -07:00
parent 2ee45fe2da
commit ea6fa049c9
24 changed files with 537 additions and 401 deletions

View File

@ -2579,7 +2579,7 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
if ((use_threads == FALSE) &&
(capture_opts->ifaces->len > 1)) {
g_snprintf(errmsg, (gulong) errmsg_len,
"Using threads is required for capturing on multiple interfaces!");
"Using threads is required for capturing on multiple interfaces.");
return FALSE;
}
@ -2648,7 +2648,7 @@ capture_loop_open_input(capture_options *capture_opts, loop_data *ld,
"\n"
"Nonetheless, the capture is started.\n",
interface_opts.buffer_size, DEFAULT_CAPTURE_BUFFER_SIZE);
report_capture_error("Couldn't set the capture buffer size!",
report_capture_error("Couldn't set the capture buffer size.",
sync_secondary_msg_str);
g_free(sync_secondary_msg_str);
}
@ -2845,7 +2845,7 @@ capture_loop_init_output(capture_options *capture_opts, loop_data *ld, char *err
if ((capture_opts->use_pcapng == FALSE) &&
(capture_opts->ifaces->len > 1)) {
g_snprintf(errmsg, errmsg_len,
"Using PCAPNG is required for capturing on multiple interfaces! Use the -n option.");
"Using PCAPNG is required for capturing on multiple interfaces. Use the -n option.");
return FALSE;
}
@ -3589,7 +3589,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
gettimeofday(&upd_time, NULL);
#endif
start_time = create_timestamp();
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture loop running!");
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture loop running.");
/* WOW, everything is prepared! */
/* please fasten your seat belts, we will enter now the actual capture loop */
@ -3895,7 +3895,7 @@ capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct
/* close the input file (pcap or capture pipe) */
capture_loop_close_input(&global_ld);
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture loop stopped!");
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_INFO, "Capture loop stopped.");
/* ok, if the write and the close were successful. */
return write_ok && close_ok;
@ -4290,7 +4290,7 @@ main(int argc, char *argv[])
#ifdef DEBUG_CHILD_DUMPCAP
if ((debug_log = ws_fopen("dumpcap_debug_log.tmp","w")) == NULL) {
fprintf (stderr, "Unable to open debug log file !\n");
fprintf (stderr, "Unable to open debug log file .\n");
exit (1);
}
#endif
@ -5078,7 +5078,7 @@ report_cfilter_error(capture_options *capture_opts, guint i, const char *errmsg)
*/
interface_opts = g_array_index(capture_opts->ifaces, interface_options, i);
cmdarg_err(
"Invalid capture filter \"%s\" for interface '%s'!\n"
"Invalid capture filter \"%s\" for interface '%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.",

18
file.c
View File

@ -692,9 +692,9 @@ cf_read(capture_file *cf, gboolean reloading)
}
CATCH(OutOfMemoryError) {
simple_message_box(ESD_TYPE_ERROR, NULL,
"Some infos / workarounds can be found at:\n"
"More information and workarounds can be found at\n"
"http://wiki.wireshark.org/KnownBugs/OutOfMemory",
"Sorry, but Wireshark has run out of memory and has to terminate now!");
"Sorry, but Wireshark has run out of memory and has to terminate now.");
#if 0
/* Could we close the current capture and free up memory from that? */
#else
@ -758,7 +758,7 @@ cf_read(capture_file *cf, gboolean reloading)
"\n"
"As a lot of packets from the original file will be missing,\n"
"remember to be careful when saving the current content to a file.\n",
"File loading was cancelled!");
"File loading was cancelled.");
return CF_READ_ERROR;
}
@ -878,9 +878,9 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err)
}
CATCH(OutOfMemoryError) {
simple_message_box(ESD_TYPE_ERROR, NULL,
"Some infos / workarounds can be found at:\n"
"More information and workarounds can be found at\n"
"http://wiki.wireshark.org/KnownBugs/OutOfMemory",
"Sorry, but Wireshark has run out of memory and has to terminate now!");
"Sorry, but Wireshark has run out of memory and has to terminate now.");
#if 0
/* Could we close the current capture and free up memory from that? */
return CF_READ_ABORTED;
@ -1753,7 +1753,7 @@ cf_read_record_r(capture_file *cf, const frame_data *fdata,
const modified_frame_data *frame = (const modified_frame_data *) g_tree_lookup(cf->edited_frames, GINT_TO_POINTER(fdata->num));
if (!frame) {
simple_error_message_box("fdata->file_off == -1, but can't find modified frame!");
simple_error_message_box("fdata->file_off == -1, but can't find modified frame.");
return FALSE;
}
@ -2117,7 +2117,7 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb
so we can't select it. */
simple_message_box(ESD_TYPE_INFO, NULL,
"The capture file is probably not fully dissected.",
"End of capture exceeded!");
"End of capture exceeded.");
}
}
}
@ -3710,7 +3710,7 @@ find_packet(capture_file *cf,
so we can't select it. */
simple_message_box(ESD_TYPE_INFO, NULL,
"The capture file is probably not fully dissected.",
"End of capture exceeded!");
"End of capture exceeded.");
return FALSE;
}
return TRUE; /* success */
@ -3743,7 +3743,7 @@ cf_goto_frame(capture_file *cf, guint fnumber)
so we can't select it. */
simple_message_box(ESD_TYPE_INFO, NULL,
"The capture file is probably not fully dissected.",
"End of capture exceeded!");
"End of capture exceeded.");
return FALSE;
}
return TRUE; /* we got to that packet */

View File

@ -2119,11 +2119,11 @@ main(int argc, char *argv[])
}
CATCH(OutOfMemoryError) {
fprintf(stderr,
"Out Of Memory!\n"
"Out Of Memory.\n"
"\n"
"Sorry, but TShark has to terminate now!\n"
"Sorry, but TShark has to terminate now.\n"
"\n"
"Some infos / workarounds can be found at:\n"
"More information and workarounds can be found at\n"
"http://wiki.wireshark.org/KnownBugs/OutOfMemory\n");
err = ENOMEM;
}
@ -2552,11 +2552,11 @@ capture(void)
}
CATCH(OutOfMemoryError) {
fprintf(stderr,
"Out Of Memory!\n"
"Out Of Memory.\n"
"\n"
"Sorry, but TShark has to terminate now!\n"
"Sorry, but TShark has to terminate now.\n"
"\n"
"Some infos / workarounds can be found at:\n"
"More information and workarounds can be found at\n"
"http://wiki.wireshark.org/KnownBugs/OutOfMemory\n");
exit(1);
}
@ -2586,7 +2586,7 @@ capture_input_cfilter_error_message(capture_session *cap_session, guint i, char
if (dfilter_compile(interface_opts.cfilter, &rfcode) && rfcode != NULL) {
cmdarg_err(
"Invalid capture filter \"%s\" for interface '%s'!\n"
"Invalid capture filter \"%s\" for interface '%s'.\n"
"\n"
"That string looks like a valid display filter; however, it isn't a valid\n"
"capture filter (%s).\n"
@ -2599,7 +2599,7 @@ capture_input_cfilter_error_message(capture_session *cap_session, guint i, char
dfilter_free(rfcode);
} else {
cmdarg_err(
"Invalid capture filter \"%s\" for interface '%s'!\n"
"Invalid capture filter \"%s\" for interface '%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.",
@ -2618,7 +2618,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);

View File

@ -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(),

View File

@ -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 \

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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;

109
ui/gtk/simple_dialog.h Normal file
View File

@ -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:
*/

View File

@ -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

View File

@ -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 \

View File

@ -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 \

View File

@ -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)),

View File

@ -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),

266
ui/qt/simple_dialog.cpp Normal file
View File

@ -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:
*/

View File

@ -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

View File

@ -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:
*/

View File

@ -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