diff options
author | Gerald Combs <gerald@wireshark.org> | 2017-07-26 10:10:09 -0700 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2017-07-27 11:41:10 +0000 |
commit | f86f54eb9070effb6216861749523d3a32932d47 (patch) | |
tree | eb872f287dfbdb39af367686b8d3c0c1e9027afa | |
parent | ea233921b46b3eeda51865bb5306919b16202872 (diff) |
Qt: SimpleDialog fixes and updates.
Add WiresharkApplication::mainWindow and use it to move the C
simple_dialog routines to simple_dialog.cpp.
In SimpleDialog, make sure our checkbox is initialized. Don't store our
parent widget (which might go away) in a static variable, just use
wsApp->mainWindow(). Make sure we use check boxes only in Qt 5.2 or
later.
Bug: 13275
Change-Id: I72a9715c59f2efd50f722197f416179e87bb6a8b
Reviewed-on: https://code.wireshark.org/review/22805
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
-rw-r--r-- | ui/qt/main_window.cpp | 87 | ||||
-rw-r--r-- | ui/qt/simple_dialog.cpp | 103 | ||||
-rw-r--r-- | ui/qt/simple_dialog.h | 6 | ||||
-rw-r--r-- | ui/qt/wireshark_application.cpp | 13 | ||||
-rw-r--r-- | ui/qt/wireshark_application.h | 1 |
5 files changed, 118 insertions, 92 deletions
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 <epan/plugin_if.h> #include <epan/export_object.h> -#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<QAction *> actions = parent_menu->actions(); QList<QAction *>::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 <wsutil/utf8_entities.h> #include <ui/qt/utils/qt_ui_utils.h> #include "wireshark_application.h" +#if (QT_VERSION > QT_VERSION_CHECK(5, 2, 0)) +#include <QCheckBox> +#endif #include <QMessageBox> #include <QRegExp> #include <QTextCodec> @@ -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<QString,QString> 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 <QFontInfo> #include <QLibraryInfo> #include <QLocale> +#include <QMainWindow> #include <QMutableListIterator> #include <QSocketNotifier> #include <QThread> @@ -462,6 +463,18 @@ void WiresharkApplication::applyCustomColorsFromRecent() } } +// Return the first top-level QMainWindow. +QWidget *WiresharkApplication::mainWindow() +{ + foreach (QWidget *tlw, topLevelWidgets()) { + QMainWindow *tlmw = qobject_cast<QMainWindow *>(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; |