diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 50c7cbc991..653ff4cf4f 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -39,7 +39,6 @@ DIAG_ON(frame-larger-than=) #include #include -#include "ui/commandline.h" #include "ui/iface_toolbar.h" #ifdef HAVE_LIBPCAP @@ -237,92 +236,6 @@ static void mainwindow_remove_toolbar(const gchar *menu_title) } } -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 = NULL; - if (notagain) { - cb = new QCheckBox(); - 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 && cb) { - *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) -{ -#ifdef HAVE_LIBPCAP - // We want to quit after reading the capture file, hence - // we don't actually open the error dialog. - if (global_commandline_info.quit_after_cap) - exit(0); -#endif - - SimpleDialog sd(gbl_cur_main_window_, ESD_TYPE_ERROR, ESD_BTN_OK, msg_format, ap); - sd.exec(); -} - -/* - * Warning alert box, taking a format and a va_list argument. - */ -void -vsimple_warning_message_box(const char *msg_format, va_list ap) -{ -#ifdef HAVE_LIBPCAP - // We want to quit after reading the capture file, hence - // we don't actually open the error dialog. - if (global_commandline_info.quit_after_cap) - exit(0); -#endif - - SimpleDialog sd(gbl_cur_main_window_, ESD_TYPE_WARN, ESD_BTN_OK, msg_format, ap); - sd.exec(); -} - QMenu* MainWindow::findOrAddMenu(QMenu *parent_menu, QString& menu_text) { QList actions = parent_menu->actions(); QList::const_iterator i; diff --git a/ui/qt/simple_dialog.cpp b/ui/qt/simple_dialog.cpp index 7256666acc..b50093c389 100644 --- a/ui/qt/simple_dialog.cpp +++ b/ui/qt/simple_dialog.cpp @@ -21,13 +21,21 @@ #include "simple_dialog.h" +#include "file.h" + #include "epan/strutil.h" +#include "epan/prefs.h" + +#include "ui/commandline.h" #include #include #include "wireshark_application.h" +#if (QT_VERSION > QT_VERSION_CHECK(5, 2, 0)) +#include +#endif #include #include #include @@ -66,6 +74,92 @@ simple_dialog_format_message(const char *msg) return g_strdup(msg); } +gpointer +simple_dialog(ESD_TYPE_E type, gint btn_mask, const gchar *msg_format, ...) +{ + va_list ap; + + va_start(ap, msg_format); + SimpleDialog sd(wsApp->mainWindow(), 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(wsApp->mainWindow(), 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 = NULL; + if (notagain) { + cb = new QCheckBox(); + 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 && cb) { + *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) +{ +#ifdef HAVE_LIBPCAP + // We want to quit after reading the capture file, hence + // we don't actually open the error dialog. + if (global_commandline_info.quit_after_cap) + exit(0); +#endif + + SimpleDialog sd(wsApp->mainWindow(), ESD_TYPE_ERROR, ESD_BTN_OK, msg_format, ap); + sd.exec(); +} + +/* + * Warning alert box, taking a format and a va_list argument. + */ +void +vsimple_warning_message_box(const char *msg_format, va_list ap) +{ +#ifdef HAVE_LIBPCAP + // We want to quit after reading the capture file, hence + // we don't actually open the error dialog. + if (global_commandline_info.quit_after_cap) + exit(0); +#endif + + SimpleDialog sd(wsApp->mainWindow(), ESD_TYPE_WARN, ESD_BTN_OK, msg_format, ap); + sd.exec(); +} + /* * Error alert box, taking a format and a list of arguments. */ @@ -80,6 +174,7 @@ simple_error_message_box(const char *msg_format, ...) } SimpleDialog::SimpleDialog(QWidget *parent, ESD_TYPE_E type, int btn_mask, const char *msg_format, va_list ap) : + check_box_(0), message_box_(0) { gchar *vmessage; @@ -170,11 +265,7 @@ void SimpleDialog::displayQueuedMessages(QWidget *parent) return; } - // Use last parent if not set - static QWidget *parent_w = NULL; - if (parent) parent_w = parent; - - QMessageBox mb(parent_w); + QMessageBox mb(parent ? parent : wsApp->mainWindow()); switch(max_severity_) { case ESD_TYPE_ERROR: @@ -227,7 +318,9 @@ int SimpleDialog::exec() } message_box_->setDetailedText(detailed_text_); +#if (QT_VERSION > QT_VERSION_CHECK(5, 2, 0)) message_box_->setCheckBox(check_box_); +#endif int status = message_box_->exec(); delete message_box_; diff --git a/ui/qt/simple_dialog.h b/ui/qt/simple_dialog.h index 1ef62d828a..e5213b74a2 100644 --- a/ui/qt/simple_dialog.h +++ b/ui/qt/simple_dialog.h @@ -35,7 +35,9 @@ typedef QPair MessagePair; +#if (QT_VERSION > QT_VERSION_CHECK(5, 2, 0)) class QCheckBox; +#endif class QMessageBox; class QWidget; @@ -48,13 +50,17 @@ public: static void displayQueuedMessages(QWidget *parent = 0); void setDetailedText(QString text) { detailed_text_ = text; } +#if (QT_VERSION > QT_VERSION_CHECK(5, 2, 0)) void setCheckBox(QCheckBox *cb) { check_box_ = cb; } +#endif int exec(); private: const MessagePair splitMessage(QString &message) const; QString detailed_text_; +#if (QT_VERSION > QT_VERSION_CHECK(5, 2, 0)) QCheckBox *check_box_; +#endif QMessageBox *message_box_; }; diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp index 5ad617f477..e0fb241143 100644 --- a/ui/qt/wireshark_application.cpp +++ b/ui/qt/wireshark_application.cpp @@ -89,6 +89,7 @@ #include #include #include +#include #include #include #include @@ -462,6 +463,18 @@ void WiresharkApplication::applyCustomColorsFromRecent() } } +// Return the first top-level QMainWindow. +QWidget *WiresharkApplication::mainWindow() +{ + foreach (QWidget *tlw, topLevelWidgets()) { + QMainWindow *tlmw = qobject_cast(tlw); + if (tlmw && tlmw->isVisible()) { + return tlmw; + } + } + return 0; +} + void WiresharkApplication::storeCustomColorsInRecent() { if (QColorDialog::customCount()) { diff --git a/ui/qt/wireshark_application.h b/ui/qt/wireshark_application.h index fc81bc5333..43dc0fce83 100644 --- a/ui/qt/wireshark_application.h +++ b/ui/qt/wireshark_application.h @@ -130,6 +130,7 @@ public: bool softwareUpdateCanShutdown(); void softwareUpdateShutdownRequest(); #endif + QWidget *mainWindow(); QTranslator translator; QTranslator translatorQt;