diff --git a/ui/qt/capture_file_properties_dialog.cpp b/ui/qt/capture_file_properties_dialog.cpp index 1cb3d4741c..5e52a0f461 100644 --- a/ui/qt/capture_file_properties_dialog.cpp +++ b/ui/qt/capture_file_properties_dialog.cpp @@ -33,6 +33,7 @@ #include "wireshark_application.h" #include +#include #include // To do: @@ -48,6 +49,8 @@ CaptureFilePropertiesDialog::CaptureFilePropertiesDialog(QWidget &parent, Captur // XXX Use recent settings instead resize(parent.width() * 2 / 3, parent.height()); + ui->detailsTextEdit->setAcceptRichText(true); + QPushButton *button = ui->buttonBox->button(QDialogButtonBox::Reset); if (button) { button->setText(tr("Refresh")); @@ -64,7 +67,7 @@ CaptureFilePropertiesDialog::CaptureFilePropertiesDialog(QWidget &parent, Captur } setWindowSubtitle(tr("Capture File Properties")); - updateWidgets(); + QTimer::singleShot(0, this, SLOT(updateWidgets())); } /* @@ -98,10 +101,13 @@ void CaptureFilePropertiesDialog::updateWidgets() save_bt->setEnabled(enable); ui->commentsTextEdit->setEnabled(enable); - ui->detailsTextEdit->setHtml(summaryToHtml()); + fillDetails(); ui->commentsTextEdit->setText(cf_read_shb_comment(cap_file_.capFile())); } +static const QString section_tmpl_ = "

%1

\n"; +static const QString para_tmpl_ = "

%1

\n"; + QString CaptureFilePropertiesDialog::summaryToHtml() { summary_tally summary; @@ -111,13 +117,11 @@ QString CaptureFilePropertiesDialog::summaryToHtml() memset(&summary, 0, sizeof(summary_tally)); - QString section_tmpl; QString table_begin, table_end; QString table_row_begin, table_ul_row_begin, table_row_end; QString table_vheader_tmpl, table_hheader20_tmpl, table_hheader25_tmpl; QString table_data_tmpl; - section_tmpl = "

%1

\n"; table_begin = "

\n"; table_end = "

\n"; table_row_begin = "\n"; @@ -145,7 +149,7 @@ QString CaptureFilePropertiesDialog::summaryToHtml() QString unknown = tr("Unknown"); // File Section - out << section_tmpl.arg(tr("File")); + out << section_tmpl_.arg(tr("File")); out << table_begin; out << table_row_begin @@ -194,7 +198,7 @@ QString CaptureFilePropertiesDialog::summaryToHtml() if (summary.packet_count_ts == summary.packet_count && summary.packet_count >= 1) { - out << section_tmpl.arg(tr("Time")); + out << section_tmpl_.arg(tr("Time")); out << table_begin; // start time @@ -234,7 +238,7 @@ QString CaptureFilePropertiesDialog::summaryToHtml() } // Capture Section - out << section_tmpl.arg(tr("Capture")); + out << section_tmpl_.arg(tr("Capture")); out << table_begin; QString capture_hardware(unknown); @@ -269,7 +273,7 @@ QString CaptureFilePropertiesDialog::summaryToHtml() // capture interfaces info if (summary.ifaces->len > 0) { - out << section_tmpl.arg(tr("Interfaces")); + out << section_tmpl_.arg(tr("Interfaces")); out << table_begin; out << table_ul_row_begin @@ -326,7 +330,7 @@ QString CaptureFilePropertiesDialog::summaryToHtml() } // Statistics Section - out << section_tmpl.arg(tr("Statistics")); + out << section_tmpl_.arg(tr("Statistics")); out << table_begin; out << table_ul_row_begin @@ -480,6 +484,60 @@ QString CaptureFilePropertiesDialog::summaryToHtml() return summary_str; } +void CaptureFilePropertiesDialog::fillDetails() +{ + if (!cap_file_.isValid()) return; + + ui->detailsTextEdit->clear(); + + QTextCursor cursor = ui->detailsTextEdit->textCursor(); + QString summary = summaryToHtml(); + cursor.insertHtml(summary); + cursor.insertBlock(); // Work around rendering oddity. + + QString file_comments = cf_read_shb_comment(cap_file_.capFile()); + 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 + file_comments_html = section_tmpl_.arg(tr("File Comment")); + file_comments_html += para_tmpl_.arg(comment_escaped); + + cursor.insertBlock(); + cursor.insertHtml(file_comments_html); + } + + if (cap_file_.capFile()->packet_comment_count > 0) { + cursor.insertBlock(); + cursor.insertHtml(section_tmpl_.arg(tr("Packet Comments"))); + + for (guint32 framenum = 1; framenum <= cap_file_.capFile()->count ; framenum++) { + frame_data *fdata = frame_data_sequence_find(cap_file_.capFile()->frames, framenum); + char *pkt_comment = cf_get_comment(cap_file_.capFile(), fdata); + + if (pkt_comment) { + QString frame_comment_html = tr("

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 += "

\n"; + cursor.insertBlock(); + cursor.insertHtml(frame_comment_html); + } + } + } + ui->detailsTextEdit->verticalScrollBar()->setValue(0); +} + void CaptureFilePropertiesDialog::changeEvent(QEvent* event) { if (0 != event) @@ -513,6 +571,7 @@ void CaptureFilePropertiesDialog::on_buttonBox_accepted() gchar *str = qstring_strdup(ui->commentsTextEdit->toPlainText()); cf_update_capture_comment(cap_file_.capFile(), str); emit captureCommentChanged(); + fillDetails(); } } diff --git a/ui/qt/capture_file_properties_dialog.h b/ui/qt/capture_file_properties_dialog.h index d4159ff576..c8df9b2afa 100644 --- a/ui/qt/capture_file_properties_dialog.h +++ b/ui/qt/capture_file_properties_dialog.h @@ -70,6 +70,7 @@ private: Ui::CaptureFilePropertiesDialog *ui; QString summaryToHtml(); + void fillDetails(); private slots: void updateWidgets();