diff options
Diffstat (limited to 'ui/qt')
-rw-r--r-- | ui/qt/capture_file_properties_dialog.cpp | 13 | ||||
-rw-r--r-- | ui/qt/module_preferences_scroll_area.cpp | 13 | ||||
-rw-r--r-- | ui/qt/preference_editor_frame.cpp | 12 | ||||
-rw-r--r-- | ui/qt/qt_ui_utils.cpp | 14 | ||||
-rw-r--r-- | ui/qt/qt_ui_utils.h | 9 | ||||
-rw-r--r-- | ui/qt/sequence_dialog.cpp | 11 | ||||
-rw-r--r-- | ui/qt/tap_parameter_dialog.cpp | 26 |
7 files changed, 34 insertions, 64 deletions
diff --git a/ui/qt/capture_file_properties_dialog.cpp b/ui/qt/capture_file_properties_dialog.cpp index a910dde540..474e0edf57 100644 --- a/ui/qt/capture_file_properties_dialog.cpp +++ b/ui/qt/capture_file_properties_dialog.cpp @@ -516,12 +516,7 @@ void CaptureFilePropertiesDialog::fillDetails() if (!file_comments.isEmpty()) { QString file_comments_html; - QString comment_escaped; -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - comment_escaped = Qt::escape(file_comments); -#else - comment_escaped = file_comments.toHtmlEscaped(); -#endif + QString comment_escaped = html_escape(file_comments); file_comments_html = section_tmpl_.arg(tr("File Comment")); file_comments_html += para_tmpl_.arg(comment_escaped); @@ -541,11 +536,7 @@ void CaptureFilePropertiesDialog::fillDetails() QString frame_comment_html = tr("<p>Frame %1: ").arg(framenum); QString raw_comment = pkt_comment; -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - frame_comment_html += Qt::escape(raw_comment); -#else - frame_comment_html += raw_comment.toHtmlEscaped(); -#endif + frame_comment_html += html_escape(raw_comment); frame_comment_html += "</p>\n"; cursor.insertBlock(); cursor.insertHtml(frame_comment_html); diff --git a/ui/qt/module_preferences_scroll_area.cpp b/ui/qt/module_preferences_scroll_area.cpp index 1c6840b1e3..3af4899b96 100644 --- a/ui/qt/module_preferences_scroll_area.cpp +++ b/ui/qt/module_preferences_scroll_area.cpp @@ -42,10 +42,6 @@ #include <QRadioButton> #include <QScrollBar> #include <QSpacerItem> -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) -// Qt::escape -#include <QTextDocument> -#endif Q_DECLARE_METATYPE(pref_t *) @@ -63,7 +59,7 @@ static const QString title_to_shortcut(const char *title) { extern "C" { // Callbacks prefs routines -/* show a single preference on the GtkGrid of a preference page */ +/* Add a single preference to the QVBoxLayout of a preference page */ static guint pref_show(pref_t *pref, gpointer layout_ptr) { @@ -72,12 +68,7 @@ pref_show(pref_t *pref, gpointer layout_ptr) if (!pref || !vb) return 0; // Convert the pref description from plain text to rich text. - QString description; -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - description = Qt::escape(pref->description); -#else - description = QString(pref->description).toHtmlEscaped(); -#endif + QString description = html_escape(pref->description); description.replace('\n', "<br>"); QString tooltip = QString("<span>%1</span>").arg(description); diff --git a/ui/qt/preference_editor_frame.cpp b/ui/qt/preference_editor_frame.cpp index 0e196c0a8a..8cacdf5f21 100644 --- a/ui/qt/preference_editor_frame.cpp +++ b/ui/qt/preference_editor_frame.cpp @@ -38,11 +38,6 @@ #include <QPushButton> -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) -// Qt::escape -#include <QTextDocument> -#endif - // To do: // - Handle PREF_FILENAME and PREF_DIRNAME. @@ -85,12 +80,7 @@ void PreferenceEditorFrame::editPreference(preference *pref, pref_module *module ui->preferenceTitleLabel->setText(QString("%1:").arg(pref->title)); // Convert the pref description from plain text to rich text. - QString description; -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - description = Qt::escape(pref->description); -#else - description = QString(pref->description).toHtmlEscaped(); -#endif + QString description = html_escape(pref->description); description.replace('\n', "<br>"); QString tooltip = QString("<span>%1</span>").arg(description); ui->preferenceTitleLabel->setToolTip(tooltip); diff --git a/ui/qt/qt_ui_utils.cpp b/ui/qt/qt_ui_utils.cpp index 70d0834218..071592cc21 100644 --- a/ui/qt/qt_ui_utils.cpp +++ b/ui/qt/qt_ui_utils.cpp @@ -47,6 +47,11 @@ #include <QUrl> #include <QUuid> +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) +// Qt::escape +#include <QTextDocument> +#endif + /* Make the format_size_flags_e enum usable in C++ */ format_size_flags_e operator|(format_size_flags_e lhs, format_size_flags_e rhs) { return (format_size_flags_e) ((int)lhs| (int)rhs); @@ -176,6 +181,15 @@ const QString time_t_to_qstring(time_t ti_time) return time_str; } +QString html_escape(const QString plain_string) { +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + return Qt::escape(plain_string); +#else + return plain_string.toHtmlEscaped(); +#endif +} + + void smooth_font_size(QFont &font) { QFontDatabase fdb; #if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) diff --git a/ui/qt/qt_ui_utils.h b/ui/qt/qt_ui_utils.h index 3509b33130..3eb159c5f9 100644 --- a/ui/qt/qt_ui_utils.h +++ b/ui/qt/qt_ui_utils.h @@ -171,6 +171,14 @@ const QString file_size_to_qstring(const gint64 size); */ const QString time_t_to_qstring(time_t ti_time); +/** Escape HTML metacharacters in a string. + * + * @param plain_string String to convert. + * + * @return A QString with escaped metacharacters. + */ +QString html_escape(const QString plain_string); + /** * Round the current size of a font up to its next "smooth" size. * If a smooth size can't be found the font is left unchanged. @@ -211,6 +219,7 @@ void desktop_show_in_folder(const QString file_path); * screens, false otherwise. */ bool rect_on_screen(const QRect &rect); + #endif /* __QT_UI_UTILS__H__ */ // XXX Add a routine to fetch the HWND corresponding to a widget using QPlatformIntegration diff --git a/ui/qt/sequence_dialog.cpp b/ui/qt/sequence_dialog.cpp index be598d85e7..8dcbb2ac8f 100644 --- a/ui/qt/sequence_dialog.cpp +++ b/ui/qt/sequence_dialog.cpp @@ -29,6 +29,7 @@ #include "color_utils.h" #include "progress_frame.h" +#include "qt_ui_utils.h" #include "sequence_diagram.h" #include "wireshark_application.h" @@ -36,10 +37,6 @@ #include <QFileDialog> #include <QFontMetrics> #include <QPoint> -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) -// Qt::escape -#include <QTextDocument> -#endif // To do: // - Resize or show + hide the Time and Comment axes, possibly via one of @@ -324,11 +321,7 @@ void SequenceDialog::mouseMoved(QMouseEvent *event) seq_analysis_item_t *sai = seq_diagram_->itemForPosY(event->pos().y()); if (sai) { packet_num_ = sai->frame_number; -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QString raw_comment = Qt::escape(sai->comment); -#else - QString raw_comment = QString(sai->comment).toHtmlEscaped(); -#endif + QString raw_comment = html_escape(sai->comment); hint = QString("Packet %1: %2").arg(packet_num_).arg(raw_comment); } } diff --git a/ui/qt/tap_parameter_dialog.cpp b/ui/qt/tap_parameter_dialog.cpp index 5f4b63850c..6b4888fc88 100644 --- a/ui/qt/tap_parameter_dialog.cpp +++ b/ui/qt/tap_parameter_dialog.cpp @@ -46,16 +46,13 @@ #include "wsutil/file_util.h" #include "progress_frame.h" +#include "qt_ui_utils.h" #include "wireshark_application.h" #include <QClipboard> #include <QContextMenuEvent> #include <QMessageBox> #include <QFileDialog> -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) -// Qt::escape -#include <QTextDocument> -#endif // The GTK+ counterpart uses tap_param_dlg, which we don't use. If we // need tap parameters we should probably create a TapParameterDialog @@ -306,22 +303,12 @@ QByteArray TapParameterDialog::getTreeAsString(st_format_type format) { // XXX What's a useful format? This mostly conforms to DocBook. ba.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); - QString title; -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - title = Qt::escape(windowSubtitle()); -#else - title = QString(windowSubtitle()).toHtmlEscaped(); -#endif + QString title = html_escape(windowSubtitle()); QString xml_header = QString("<table>\n<title>%1</title>\n").arg(title); ba.append(xml_header.toUtf8()); ba.append("<thead>\n<row>\n"); for (int col = 0; col < ui->statsTreeWidget->columnCount(); col++) { - title = ui->statsTreeWidget->headerItem()->text(col); -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - title = Qt::escape(title); -#else - title = title.toHtmlEscaped(); -#endif + title = html_escape(ui->statsTreeWidget->headerItem()->text(col)); title = QString(" <entry>%1</entry>\n").arg(title); ba.append(title.toUtf8()); } @@ -385,12 +372,7 @@ QByteArray TapParameterDialog::getTreeAsString(st_format_type format) { line = "<row>\n"; foreach (QVariant var, tid) { - QString entry; - #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - entry = Qt::escape(var.toString()); - #else - entry = var.toString().toHtmlEscaped(); - #endif + QString entry = html_escape(var.toString()); line.append(QString(" <entry>%1</entry>\n").arg(entry)); } line.append("</row>\n"); |