aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2017-07-24 10:55:56 -0700
committerAnders Broman <a.broman58@gmail.com>2017-07-25 04:56:10 +0000
commitc6ed05ec73e1b1e22ea890fc95ec5e067726cbe8 (patch)
tree5c65e91184ae47b90b3d3315276f257f64d07fec
parent17f72a0b2273e8c45296711d2454997e74e2734c (diff)
Qt: Make SimpleDialog a plain, non-QObject class.
Don't assume that the application is initialized when we create a SimpleDialog. Bug: 13275 Change-Id: Ieeb52430500570db88463069833855c3789f686b Reviewed-on: https://code.wireshark.org/review/22778 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: Anders Broman <a.broman58@gmail.com>
-rw-r--r--ui/qt/CMakeLists.txt1
-rw-r--r--ui/qt/Makefile.am2
-rw-r--r--ui/qt/simple_dialog.cpp54
-rw-r--r--ui/qt/simple_dialog.h20
-rw-r--r--wireshark-qt.cpp2
5 files changed, 49 insertions, 30 deletions
diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt
index a2fb5d402b..25efdca73d 100644
--- a/ui/qt/CMakeLists.txt
+++ b/ui/qt/CMakeLists.txt
@@ -155,7 +155,6 @@ set(WIRESHARK_QT_HEADERS
sequence_diagram.h
sequence_dialog.h
show_packet_bytes_dialog.h
- simple_dialog.h
splash_overlay.h
stats_tree_dialog.h
service_response_time_dialog.h
diff --git a/ui/qt/Makefile.am b/ui/qt/Makefile.am
index 0acd5a527a..b044fb8057 100644
--- a/ui/qt/Makefile.am
+++ b/ui/qt/Makefile.am
@@ -286,7 +286,6 @@ MOC_HDRS = \
sequence_dialog.h \
service_response_time_dialog.h \
show_packet_bytes_dialog.h \
- simple_dialog.h \
simple_statistics_dialog.h \
sparkline_delegate.h \
splash_overlay.h \
@@ -625,6 +624,7 @@ noinst_HEADERS = \
packet_list_record.h \
qcustomplot.h \
qt_ui_utils.h \
+ simple_dialog.h \
stock_icon.h \
tango_colors.h \
variant_pointer.h
diff --git a/ui/qt/simple_dialog.cpp b/ui/qt/simple_dialog.cpp
index e1578ad026..167a2b245e 100644
--- a/ui/qt/simple_dialog.cpp
+++ b/ui/qt/simple_dialog.cpp
@@ -80,7 +80,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) :
- QMessageBox(parent)
+ message_box_(0)
{
gchar *vmessage;
QString message;
@@ -89,11 +89,6 @@ SimpleDialog::SimpleDialog(QWidget *parent, ESD_TYPE_E type, int btn_mask, const
message = QTextCodec::codecForLocale()->toUnicode(vmessage);
g_free(vmessage);
- setTextFormat(Qt::PlainText);
-#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
- setTextInteractionFlags(Qt::TextSelectableByMouse);
-#endif
-
MessagePair msg_pair = splitMessage(message);
// Remove leading and trailing whitespace along with excessive newline runs.
QString primary = msg_pair.first.trimmed();
@@ -109,53 +104,60 @@ SimpleDialog::SimpleDialog(QWidget *parent, ESD_TYPE_E type, int btn_mask, const
if (type > max_severity_) {
max_severity_ = type;
}
- setText(QString());
return;
}
+ message_box_ = new QMessageBox(parent);
+ message_box_->setTextFormat(Qt::PlainText);
+#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
+ message_box_->setTextInteractionFlags(Qt::TextSelectableByMouse);
+#endif
+
+
switch(type) {
case ESD_TYPE_ERROR:
- setIcon(QMessageBox::Critical);
+ message_box_->setIcon(QMessageBox::Critical);
break;
case ESD_TYPE_WARN:
- setIcon(QMessageBox::Warning);
+ message_box_->setIcon(QMessageBox::Warning);
break;
case ESD_TYPE_CONFIRMATION:
- setIcon(QMessageBox::Question);
+ message_box_->setIcon(QMessageBox::Question);
break;
case ESD_TYPE_INFO:
default:
- setIcon(QMessageBox::Information);
+ message_box_->setIcon(QMessageBox::Information);
break;
}
if (btn_mask & ESD_BTN_OK) {
- addButton(QMessageBox::Ok);
+ message_box_->addButton(QMessageBox::Ok);
}
if (btn_mask & ESD_BTN_CANCEL) {
- addButton(QMessageBox::Cancel);
+ message_box_->addButton(QMessageBox::Cancel);
}
if (btn_mask & ESD_BTN_YES) {
- addButton(QMessageBox::Yes);
+ message_box_->addButton(QMessageBox::Yes);
}
if (btn_mask & ESD_BTN_NO) {
- addButton(QMessageBox::No);
+ message_box_->addButton(QMessageBox::No);
}
// if (btn_mask & ESD_BTN_CLEAR) {
// addButton(QMessageBox::);
// }
if (btn_mask & ESD_BTN_SAVE) {
- addButton(QMessageBox::Save);
+ message_box_->addButton(QMessageBox::Save);
}
if (btn_mask & ESD_BTN_DONT_SAVE) {
- addButton(QMessageBox::Discard);
+ message_box_->addButton(QMessageBox::Discard);
}
// if (btn_mask & ESD_BTN_QUIT_DONT_SAVE) {
// addButton(QMessageBox::);
// }
- setText(primary);
- setInformativeText(secondary);
+
+ message_box_->setText(primary);
+ message_box_->setInformativeText(secondary);
}
SimpleDialog::~SimpleDialog()
@@ -197,7 +199,7 @@ void SimpleDialog::displayQueuedMessages(QWidget *parent)
QString first_primary = message_queue_[0].first;
first_primary.append(UTF8_HORIZONTAL_ELLIPSIS);
- mb.setText(tr("Multiple problems found"));
+ mb.setText(QObject::tr("Multiple problems found"));
mb.setInformativeText(first_primary);
foreach (MessagePair msg_pair, message_queue_) {
@@ -220,11 +222,19 @@ void SimpleDialog::displayQueuedMessages(QWidget *parent)
int SimpleDialog::exec()
{
- if (!parentWidget() || text().isEmpty()) {
+ if (!message_box_) {
return 0;
}
- switch (QMessageBox::exec()) {
+ message_box_->setDetailedText(detailed_text_);
+ message_box_->setCheckBox(check_box_);
+
+ int status = message_box_->exec();
+ delete message_box_;
+ message_box_ = 0;
+ detailed_text_ = QString();
+
+ switch (status) {
case QMessageBox::Ok:
return ESD_BTN_OK;
case QMessageBox::Yes:
diff --git a/ui/qt/simple_dialog.h b/ui/qt/simple_dialog.h
index 2185a9c0dd..1ef62d828a 100644
--- a/ui/qt/simple_dialog.h
+++ b/ui/qt/simple_dialog.h
@@ -30,24 +30,32 @@
#include "ui/simple_dialog.h"
-#include <QMessageBox>
+#include <QPair>
+#include <QString>
typedef QPair<QString,QString> MessagePair;
-class SimpleDialog : public QMessageBox
-{
- Q_OBJECT
+class QCheckBox;
+class QMessageBox;
+class QWidget;
+// This might be constructed before Qt is initialized and must be a plain, non-Qt object.
+class SimpleDialog
+{
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:
+ static void displayQueuedMessages(QWidget *parent = 0);
+ void setDetailedText(QString text) { detailed_text_ = text; }
+ void setCheckBox(QCheckBox *cb) { check_box_ = cb; }
int exec();
private:
const MessagePair splitMessage(QString &message) const;
+ QString detailed_text_;
+ QCheckBox *check_box_;
+ QMessageBox *message_box_;
};
#endif // SIMPLE_DIALOG_H
diff --git a/wireshark-qt.cpp b/wireshark-qt.cpp
index 7e4d597c7a..9ad4305686 100644
--- a/wireshark-qt.cpp
+++ b/wireshark-qt.cpp
@@ -107,6 +107,8 @@
#include "caputils/capture-pcap-util.h"
+#include <QMessageBox>
+
#ifdef _WIN32
# include "caputils/capture-wpcap.h"
# include "caputils/capture_wpcap_packet.h"