diff options
Diffstat (limited to 'ui/qt')
-rw-r--r-- | ui/qt/CMakeLists.txt | 4 | ||||
-rw-r--r-- | ui/qt/Makefile.am | 2 | ||||
-rw-r--r-- | ui/qt/Makefile.common | 6 | ||||
-rw-r--r-- | ui/qt/Wireshark.pro | 4 | ||||
-rw-r--r-- | ui/qt/qt_ui_utils.cpp | 7 | ||||
-rw-r--r-- | ui/qt/qt_ui_utils.h | 9 | ||||
-rw-r--r-- | ui/qt/stats_tree_dialog.cpp | 200 | ||||
-rw-r--r-- | ui/qt/stats_tree_dialog.h | 24 | ||||
-rw-r--r-- | ui/qt/tap_parameter_dialog.cpp | 218 | ||||
-rw-r--r-- | ui/qt/tap_parameter_dialog.h | 85 | ||||
-rw-r--r-- | ui/qt/tap_parameter_dialog.ui (renamed from ui/qt/stats_tree_dialog.ui) | 10 |
11 files changed, 383 insertions, 186 deletions
diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt index 60b93f8f77..8a534b9bca 100644 --- a/ui/qt/CMakeLists.txt +++ b/ui/qt/CMakeLists.txt @@ -104,6 +104,7 @@ set(WIRESHARK_QT_HEADERS splash_overlay.h stats_tree_dialog.h syntax_line_edit.h + tap_parameter_dialog.h tcp_stream_dialog.h time_shift_dialog.h traffic_table_dialog.h @@ -220,6 +221,7 @@ set(WIRESHARK_QT_SRC sparkline_delegate.cpp stock_icon.cpp syntax_line_edit.cpp + tap_parameter_dialog.cpp tcp_stream_dialog.cpp time_shift_dialog.cpp traffic_table_dialog.cpp @@ -308,7 +310,7 @@ set(WIRESHARK_QT_UI search_frame.ui sequence_dialog.ui splash_overlay.ui - stats_tree_dialog.ui + tap_parameter_dialog.ui tcp_stream_dialog.ui time_shift_dialog.ui traffic_table_dialog.ui diff --git a/ui/qt/Makefile.am b/ui/qt/Makefile.am index 678b58a4a3..a0e2bc7055 100644 --- a/ui/qt/Makefile.am +++ b/ui/qt/Makefile.am @@ -224,7 +224,7 @@ sctp_graph_byte_dialog.cpp sctp_graph_byte_dialog.h: ui_sctp_graph_byte_dialog.h splash_overlay.cpp splash_overlay.h: ui_splash_overlay.h -stats_tree_dialog.cpp stats_tree_dialog.h: ui_stats_tree_dialog.h +tap_parameter_dialog.cpp tap_parameter_dialog.h: ui_tap_parameter_dialog.h tcp_stream_dialog.cpp: ui_tcp_stream_dialog.h diff --git a/ui/qt/Makefile.common b/ui/qt/Makefile.common index a93f3ebcea..a0396784a9 100644 --- a/ui/qt/Makefile.common +++ b/ui/qt/Makefile.common @@ -78,10 +78,10 @@ NODIST_GENERATED_HEADER_FILES = \ ui_sctp_graph_dialog.h \ ui_sctp_graph_arwnd_dialog.h \ ui_sctp_graph_byte_dialog.h \ - ui_stats_tree_dialog.h \ ui_search_frame.h \ ui_sequence_dialog.h \ ui_splash_overlay.h \ + ui_tap_parameter_dialog.h \ ui_tcp_stream_dialog.h \ ui_time_shift_dialog.h \ ui_traffic_table_dialog.h \ @@ -209,6 +209,7 @@ MOC_HDRS = \ splash_overlay.h \ stats_tree_dialog.h \ syntax_line_edit.h \ + tap_parameter_dialog.h \ tcp_stream_dialog.h \ time_shift_dialog.h \ traffic_table_dialog.h \ @@ -274,7 +275,7 @@ UI_FILES = \ search_frame.ui \ sequence_dialog.ui \ splash_overlay.ui \ - stats_tree_dialog.ui \ + tap_parameter_dialog.ui \ tcp_stream_dialog.ui \ time_shift_dialog.ui \ traffic_table_dialog.ui \ @@ -422,6 +423,7 @@ WIRESHARK_QT_SRC = \ stats_tree_dialog.cpp \ stock_icon.cpp \ syntax_line_edit.cpp \ + tap_parameter_dialog.cpp \ tcp_stream_dialog.cpp \ time_shift_dialog.cpp \ traffic_table_dialog.cpp \ diff --git a/ui/qt/Wireshark.pro b/ui/qt/Wireshark.pro index 2dd409fae2..4267e98601 100644 --- a/ui/qt/Wireshark.pro +++ b/ui/qt/Wireshark.pro @@ -257,7 +257,7 @@ FORMS += \ search_frame.ui \ sequence_dialog.ui \ splash_overlay.ui \ - stats_tree_dialog.ui \ + tap_parameter_dialog.ui \ tcp_stream_dialog.ui \ time_shift_dialog.ui \ traffic_table_dialog.ui \ @@ -321,6 +321,7 @@ HEADERS += $$HEADERS_WS_C \ splash_overlay.h \ stats_tree_dialog.h \ tango_colors.h \ + tap_parameter_dialog.h \ tcp_stream_dialog.h \ traffic_table_dialog.h \ uat_dialog.h \ @@ -700,6 +701,7 @@ SOURCES += \ stats_tree_dialog.cpp \ stock_icon.cpp \ syntax_line_edit.cpp \ + tap_parameter_dialog.cpp \ tcp_stream_dialog.cpp \ time_shift_dialog.cpp \ traffic_table_dialog.cpp \ diff --git a/ui/qt/qt_ui_utils.cpp b/ui/qt/qt_ui_utils.cpp index c1dd0b6051..de59926253 100644 --- a/ui/qt/qt_ui_utils.cpp +++ b/ui/qt/qt_ui_utils.cpp @@ -58,6 +58,13 @@ QString gchar_free_to_qstring(gchar *glib_string) { return qt_string; } +QByteArray gstring_free_to_qbytearray(GString *glib_gstring) +{ + QByteArray qt_ba(glib_gstring->str); + g_string_free(glib_gstring, TRUE); + return qt_ba; +} + const QString address_to_qstring(const _address *address) { QString address_qstr = QString(); diff --git a/ui/qt/qt_ui_utils.h b/ui/qt/qt_ui_utils.h index 66b198e9d8..8043234fc0 100644 --- a/ui/qt/qt_ui_utils.h +++ b/ui/qt/qt_ui_utils.h @@ -69,6 +69,15 @@ gchar *qstring_strdup(QString q_string); */ QString gchar_free_to_qstring(gchar *glib_string); +/** Transfer ownership of a GLib character string to a newly constructed QByteArray + * + * @param glib_string A string allocated with g_malloc() or NULL. Will be + * freed. + * + * @return A QByteArray instance created from the input string. + */ +QByteArray gstring_free_to_qbytearray(GString *glib_gstring); + /** Convert an address to a QString using address_to_str(). * * @param address A pointer to an address. diff --git a/ui/qt/stats_tree_dialog.cpp b/ui/qt/stats_tree_dialog.cpp index 8d5dd34fa2..2152058bd3 100644 --- a/ui/qt/stats_tree_dialog.cpp +++ b/ui/qt/stats_tree_dialog.cpp @@ -20,37 +20,20 @@ */ #include "stats_tree_dialog.h" -#include "ui_stats_tree_dialog.h" #include "file.h" #include "epan/stats_tree_priv.h" -#include "ui/last_open_dir.h" -#include "ui/utf8_entities.h" +#include "qt_ui_utils.h" -#include "wsutil/file_util.h" - -#include "wireshark_application.h" - -#include <QClipboard> +#include <QHeaderView> #include <QMessageBox> #include <QTreeWidget> #include <QTreeWidgetItemIterator> -#include <QFileDialog> - -// The GTK+ counterpart uses tap_param_dlg, which we don't use. If we -// need tap parameters we should probably create a TapParameterDialog -// class based on WiresharkDialog and subclass it here. - -// To do: -// - Add help -// - Update to match bug 9452 / r53657 const int item_col_ = 0; -const int expand_all_threshold_ = 100; // Arbitrary - Q_DECLARE_METATYPE(stat_node *) class StatsTreeWidgetItem : public QTreeWidgetItem @@ -67,19 +50,18 @@ public: result = stats_tree_sort_compare(thisnode, othernode, treeWidget()->sortColumn(), order==Qt::DescendingOrder); if (order==Qt::DescendingOrder) { - result= -result; + result = -result; } return result < 0; } }; + StatsTreeDialog::StatsTreeDialog(QWidget &parent, CaptureFile &cf, const char *cfg_abbr) : - WiresharkDialog(parent, cf), - ui(new Ui::StatsTreeDialog), + TapParameterDialog(parent, cf), st_(NULL), st_cfg_(NULL) { - ui->setupUi(this); st_cfg_ = stats_tree_get_cfg_by_abbr(cfg_abbr); memset(&cfg_pr_, 0, sizeof(struct _tree_cfg_pres)); @@ -88,19 +70,6 @@ StatsTreeDialog::StatsTreeDialog(QWidget &parent, CaptureFile &cf, const char *c tr("Unable to find configuration for %1.").arg(cfg_abbr)); QMetaObject::invokeMethod(this, "reject", Qt::QueuedConnection); } - - ui->statsTreeWidget->addAction(ui->actionCopyToClipboard); - ui->statsTreeWidget->addAction(ui->actionSaveAs); - ui->statsTreeWidget->setContextMenuPolicy(Qt::ActionsContextMenu); - - QPushButton *button; - button = ui->buttonBox->addButton(tr("Copy"), QDialogButtonBox::ActionRole); - connect(button, SIGNAL(clicked()), this, SLOT(on_actionCopyToClipboard_triggered())); - - button = ui->buttonBox->addButton(tr("Save as..."), QDialogButtonBox::ActionRole); - connect(button, SIGNAL(clicked()), this, SLOT(on_actionSaveAs_triggered())); - - fillTree(); } StatsTreeDialog::~StatsTreeDialog() @@ -108,7 +77,31 @@ StatsTreeDialog::~StatsTreeDialog() if (st_) { stats_tree_free(st_); } - delete ui; +} + +// Adds a node to the QTreeWidget +// Note: We're passing QTreeWidgetItem pointers as st_node_pres pointers +void StatsTreeDialog::setupNode(stat_node* node) +{ + if (!node || !node->st || !node->st->cfg || !node->st->cfg->pr + || !node->st->cfg->pr->st_dlg) return; + StatsTreeDialog *st_dlg = node->st->cfg->pr->st_dlg; + + QTreeWidgetItem *ti = new StatsTreeWidgetItem(), *parent = NULL; + + ti->setText(item_col_, node->name); + ti->setData(item_col_, Qt::UserRole, qVariantFromValue(node)); + node->pr = (st_node_pres *) ti; + if (node->parent && node->parent->pr) { + parent = (QTreeWidgetItem *) node->parent->pr; + parent->setExpanded(true); + } + if (parent) { + parent->addChild(ti); + } else { + st_dlg->statsTreeWidget()->addTopLevelItem(ti); + } + st_dlg->statsTreeWidget()->resizeColumnToContents(item_col_); } void StatsTreeDialog::fillTree() @@ -130,20 +123,20 @@ void StatsTreeDialog::fillTree() if (st_) { stats_tree_free(st_); } - st_ = stats_tree_new(st_cfg_, NULL, ui->displayFilterLineEdit->text().toUtf8().constData()); + st_ = stats_tree_new(st_cfg_, NULL, displayFilter()); // Add number of columns for this stats_tree QStringList headerLabels; for (int count = 0; count<st_->num_columns; count++) { headerLabels.push_back(stats_tree_get_column_name(count)); } - ui->statsTreeWidget->setColumnCount(headerLabels.count()); - ui->statsTreeWidget->setHeaderLabels(headerLabels); + statsTreeWidget()->setColumnCount(headerLabels.count()); + statsTreeWidget()->setHeaderLabels(headerLabels); resize(st_->num_columns*80+80, height()); for (int count = 0; count<st_->num_columns; count++) { headerLabels.push_back(stats_tree_get_column_name(count)); } - ui->statsTreeWidget->setSortingEnabled(false); + statsTreeWidget()->setSortingEnabled(false); error_string = register_tap_listener(st_cfg_->tapname, st_, @@ -162,7 +155,7 @@ void StatsTreeDialog::fillTree() cf_retap_packets(cap_file_.capFile()); drawTreeItems(st_); - ui->statsTreeWidget->setSortingEnabled(true); + statsTreeWidget()->setSortingEnabled(true); remove_tap_listener(st_); st_cfg_->pr = NULL; @@ -173,41 +166,16 @@ void StatsTreeDialog::resetTap(void *st_ptr) stats_tree *st = (stats_tree *) st_ptr; if (!st || !st->cfg || !st->cfg->pr || !st->cfg->pr->st_dlg) return; - st->cfg->pr->st_dlg->ui->statsTreeWidget->clear(); + st->cfg->pr->st_dlg->statsTreeWidget()->clear(); st->cfg->init(st); } -// Adds a node to the QTreeWidget -// Note: We're passing QTreeWidgetItem pointers as st_node_pres pointers -void StatsTreeDialog::setupNode(stat_node* node) -{ - if (!node || !node->st || !node->st->cfg || !node->st->cfg->pr - || !node->st->cfg->pr->st_dlg) return; - StatsTreeDialog *st_dlg = node->st->cfg->pr->st_dlg; - - QTreeWidgetItem *ti = new StatsTreeWidgetItem(), *parent = NULL; - - ti->setText(item_col_, node->name); - ti->setData(item_col_, Qt::UserRole, qVariantFromValue(node)); - node->pr = (st_node_pres *) ti; - if (node->parent && node->parent->pr) { - parent = (QTreeWidgetItem *) node->parent->pr; - parent->setExpanded(true); - } - if (parent) { - parent->addChild(ti); - } else { - st_dlg->ui->statsTreeWidget->addTopLevelItem(ti); - } - st_dlg->ui->statsTreeWidget->resizeColumnToContents(item_col_); -} - void StatsTreeDialog::drawTreeItems(void *st_ptr) { stats_tree *st = (stats_tree *) st_ptr; if (!st || !st->cfg || !st->cfg->pr || !st->cfg->pr->st_dlg) return; - StatsTreeDialog *st_dlg = st->cfg->pr->st_dlg; - QTreeWidgetItemIterator iter(st_dlg->ui->statsTreeWidget); + TapParameterDialog *st_dlg = st->cfg->pr->st_dlg; + QTreeWidgetItemIterator iter(st_dlg->statsTreeWidget()); int node_count = 0; while (*iter) { @@ -225,101 +193,19 @@ void StatsTreeDialog::drawTreeItems(void *st_ptr) node_count++; ++iter; } - if (node_count < expand_all_threshold_) { - st_dlg->ui->statsTreeWidget->expandAll(); - } - for (int count = 0; count<st->num_columns; count++) { - st_dlg->ui->statsTreeWidget->resizeColumnToContents(count); - } + st_dlg->drawTreeItems(); } -void StatsTreeDialog::updateWidgets() +QByteArray StatsTreeDialog::getTreeAsString(st_format_type format) { - if (file_closed_) { - ui->displayFilterLineEdit->setEnabled(false); - ui->applyFilterButton->setEnabled(false); - } -} - -void StatsTreeDialog::on_applyFilterButton_clicked() -{ - fillTree(); -} - -void StatsTreeDialog::on_actionCopyToClipboard_triggered() -{ - GString* s= stats_tree_format_as_str(st_ ,ST_FORMAT_PLAIN, ui->statsTreeWidget->sortColumn(), - ui->statsTreeWidget->header()->sortIndicatorOrder()==Qt::DescendingOrder); - wsApp->clipboard()->setText(s->str); - g_string_free(s,TRUE); -} - -void StatsTreeDialog::on_actionSaveAs_triggered() -{ - QString selectedFilter; - st_format_type file_type; - const char *file_ext; - FILE *f; GString *str_tree; - bool success= false; - int last_errno; - - QFileDialog SaveAsDialog(this, wsApp->windowTitleString(tr("Save Statistics As" UTF8_HORIZONTAL_ELLIPSIS)), - get_last_open_dir()); - SaveAsDialog.setNameFilter(tr("Plain text file (*.txt);;" - "Comma separated values (*.csv);;" - "XML document (*.xml);;" - "YAML document (*.yaml)")); - SaveAsDialog.selectNameFilter(tr("Plain text file (*.txt)")); - SaveAsDialog.setAcceptMode(QFileDialog::AcceptSave); - if (!SaveAsDialog.exec()) { - return; - } - selectedFilter= SaveAsDialog.selectedNameFilter(); - if (selectedFilter.contains("*.yaml", Qt::CaseInsensitive)) { - file_type= ST_FORMAT_YAML; - file_ext = ".yaml"; - } - else if (selectedFilter.contains("*.xml", Qt::CaseInsensitive)) { - file_type= ST_FORMAT_XML; - file_ext = ".xml"; - } - else if (selectedFilter.contains("*.csv", Qt::CaseInsensitive)) { - file_type= ST_FORMAT_CSV; - file_ext = ".csv"; - } - else { - file_type= ST_FORMAT_PLAIN; - file_ext = ".txt"; - } - - // Get selected filename and add extension of necessary - QString file_name = SaveAsDialog.selectedFiles()[0]; - if (!file_name.endsWith(file_ext, Qt::CaseInsensitive)) { - file_name.append(file_ext); - } // produce output in selected format using current sort information - str_tree=stats_tree_format_as_str(st_ ,file_type, ui->statsTreeWidget->sortColumn(), - ui->statsTreeWidget->header()->sortIndicatorOrder()==Qt::DescendingOrder); - - // actually save the file - f= ws_fopen (file_name.toUtf8().constData(),"w"); - last_errno= errno; - if (f) { - if (fputs(str_tree->str, f)!=EOF) { - success= true; - } - last_errno= errno; - fclose(f); - } - if (!success) { - QMessageBox::warning(this, tr("Error saving file %1").arg(file_name), - g_strerror (last_errno)); - } + str_tree = stats_tree_format_as_str(st_, format, statsTreeWidget()->sortColumn(), + statsTreeWidget()->header()->sortIndicatorOrder()==Qt::DescendingOrder); - g_string_free(str_tree, TRUE); + return gstring_free_to_qbytearray(str_tree); } extern "C" { diff --git a/ui/qt/stats_tree_dialog.h b/ui/qt/stats_tree_dialog.h index 8e040338b9..59cf812a15 100644 --- a/ui/qt/stats_tree_dialog.h +++ b/ui/qt/stats_tree_dialog.h @@ -22,24 +22,19 @@ #ifndef STATS_TREE_DIALOG_H #define STATS_TREE_DIALOG_H +#include "tap_parameter_dialog.h" + #include <config.h> #include <glib.h> #include "epan/stats_tree_priv.h" -#include "wireshark_dialog.h" - -namespace Ui { -class StatsTreeDialog; -class StatsTreeWidgetItem; -} - struct _tree_cfg_pres { class StatsTreeDialog* st_dlg; }; -class StatsTreeDialog : public WiresharkDialog +class StatsTreeDialog : public TapParameterDialog { Q_OBJECT @@ -48,24 +43,15 @@ public: ~StatsTreeDialog(); static void setupNode(stat_node* node); -public slots: - private: - Ui::StatsTreeDialog *ui; - struct _tree_cfg_pres cfg_pr_; stats_tree *st_; stats_tree_cfg *st_cfg_; - void fillTree(); + virtual void fillTree(); static void resetTap(void *st_ptr); static void drawTreeItems(void *st_ptr); - -private slots: - void updateWidgets(); - void on_applyFilterButton_clicked(); - void on_actionCopyToClipboard_triggered(); - void on_actionSaveAs_triggered(); + virtual QByteArray getTreeAsString(st_format_type format); }; #endif // STATS_TREE_DIALOG_H diff --git a/ui/qt/tap_parameter_dialog.cpp b/ui/qt/tap_parameter_dialog.cpp new file mode 100644 index 0000000000..3201abda2c --- /dev/null +++ b/ui/qt/tap_parameter_dialog.cpp @@ -0,0 +1,218 @@ +/* tap_parameter_dialog.cpp + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* + * @file Tap parameter dialog class + * + * Base class for statistics dialogs. Subclasses must implement: + * - fillTree. Called when the dialog is first displayed and when a display + * filter is applied. In most cases the subclass should clear the tree and + * retap packets here. + * - getTreeAsString. + */ + +#include "tap_parameter_dialog.h" +#include "ui_tap_parameter_dialog.h" + +#include <errno.h> + +#include "ui/last_open_dir.h" +#include "ui/utf8_entities.h" + +#include "wsutil/file_util.h" + +#include "wireshark_application.h" + +#include <QClipboard> +#include <QMessageBox> +#include <QFileDialog> + +// The GTK+ counterpart uses tap_param_dlg, which we don't use. If we +// need tap parameters we should probably create a TapParameterDialog +// class based on WiresharkDialog and subclass it here. + +// To do: +// - Add help +// - Update to match bug 9452 / r53657 + +const int expand_all_threshold_ = 100; // Arbitrary + +TapParameterDialog::TapParameterDialog(QWidget &parent, CaptureFile &cf, int help_topic) : + WiresharkDialog(parent, cf), + ui(new Ui::TapParameterDialog), + help_topic_(help_topic) +{ + ui->setupUi(this); + + // XXX Use recent settings instead + resize(parent.width(), parent.height() * 3 / 4); + + ui->statsTreeWidget->addAction(ui->actionCopyToClipboard); + ui->statsTreeWidget->addAction(ui->actionSaveAs); + ui->statsTreeWidget->setContextMenuPolicy(Qt::ActionsContextMenu); + + QPushButton *button; + button = ui->buttonBox->addButton(tr("Copy"), QDialogButtonBox::ActionRole); + connect(button, SIGNAL(clicked()), this, SLOT(on_actionCopyToClipboard_triggered())); + + button = ui->buttonBox->addButton(tr("Save as..."), QDialogButtonBox::ActionRole); + connect(button, SIGNAL(clicked()), this, SLOT(on_actionSaveAs_triggered())); + + if (help_topic_ < 1) { + ui->buttonBox->button(QDialogButtonBox::Help)->hide(); + } +} + +TapParameterDialog::~TapParameterDialog() +{ + delete ui; +} + +QTreeWidget *TapParameterDialog::statsTreeWidget() +{ + return ui->statsTreeWidget; +} + +const char *TapParameterDialog::displayFilter() +{ + return ui->displayFilterLineEdit->text().toUtf8().constData(); +} + +//QByteArray TapParameterDialog::getTreeAsString(st_format_type format) +//{ +// // XXX Iterate over the tree and build a QByteArray +//} + +void TapParameterDialog::drawTreeItems() +{ + if (ui->statsTreeWidget->model()->rowCount() < expand_all_threshold_) { + ui->statsTreeWidget->expandAll(); + } + + for (int col = 0; col < ui->statsTreeWidget->columnCount(); col++) { + ui->statsTreeWidget->resizeColumnToContents(col); + } +} + +void TapParameterDialog::showEvent(QShowEvent *) +{ + fillTree(); +} + +void TapParameterDialog::updateWidgets() +{ + if (file_closed_) { + ui->displayFilterLineEdit->setEnabled(false); + ui->applyFilterButton->setEnabled(false); + } +} + +void TapParameterDialog::on_applyFilterButton_clicked() +{ + fillTree(); +} + +void TapParameterDialog::on_actionCopyToClipboard_triggered() +{ + wsApp->clipboard()->setText(getTreeAsString(ST_FORMAT_PLAIN)); +} + +void TapParameterDialog::on_actionSaveAs_triggered() +{ + QString selectedFilter; + st_format_type format; + const char *file_ext; + FILE *f; + bool success = false; + int last_errno; + + QFileDialog SaveAsDialog(this, wsApp->windowTitleString(tr("Save Statistics As" UTF8_HORIZONTAL_ELLIPSIS)), + get_last_open_dir()); + SaveAsDialog.setNameFilter(tr("Plain text file (*.txt);;" + "Comma separated values (*.csv);;" + "XML document (*.xml);;" + "YAML document (*.yaml)")); + SaveAsDialog.selectNameFilter(tr("Plain text file (*.txt)")); + SaveAsDialog.setAcceptMode(QFileDialog::AcceptSave); + if (!SaveAsDialog.exec()) { + return; + } + selectedFilter= SaveAsDialog.selectedNameFilter(); + if (selectedFilter.contains("*.yaml", Qt::CaseInsensitive)) { + format = ST_FORMAT_YAML; + file_ext = ".yaml"; + } + else if (selectedFilter.contains("*.xml", Qt::CaseInsensitive)) { + format = ST_FORMAT_XML; + file_ext = ".xml"; + } + else if (selectedFilter.contains("*.csv", Qt::CaseInsensitive)) { + format = ST_FORMAT_CSV; + file_ext = ".csv"; + } + else { + format = ST_FORMAT_PLAIN; + file_ext = ".txt"; + } + + // Get selected filename and add extension of necessary + QString file_name = SaveAsDialog.selectedFiles()[0]; + if (!file_name.endsWith(file_ext, Qt::CaseInsensitive)) { + file_name.append(file_ext); + } + + QByteArray tree_as_ba = getTreeAsString(format); + + // actually save the file + f = ws_fopen (file_name.toUtf8().constData(),"w"); + last_errno= errno; + if (f) { + if (fputs(tree_as_ba.data(), f)!=EOF) { + success= true; + } + last_errno= errno; + fclose(f); + } + if (!success) { + QMessageBox::warning(this, tr("Error saving file %1").arg(file_name), + g_strerror (last_errno)); + } +} + +void TapParameterDialog::on_buttonBox_helpRequested() +{ + if (help_topic_ > 0) { + wsApp->helpTopicAction((topic_action_e) help_topic_); + } +} + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/qt/tap_parameter_dialog.h b/ui/qt/tap_parameter_dialog.h new file mode 100644 index 0000000000..857c3f1006 --- /dev/null +++ b/ui/qt/tap_parameter_dialog.h @@ -0,0 +1,85 @@ +/* tap_parameter_dialog.h + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef TAP_PARAMETER_DIALOG_H +#define TAP_PARAMETER_DIALOG_H + +#include "config.h" + +#include <glib.h> + +#include <epan/stat_groups.h> + +#include "wireshark_dialog.h" + +class QTreeWidget; + +namespace Ui { +class TapParameterDialog; +} + +class TapParameterDialog : public WiresharkDialog +{ + Q_OBJECT + +public: + explicit TapParameterDialog(QWidget &parent, CaptureFile &cf, int help_topic = 0); + ~TapParameterDialog(); + + QTreeWidget *statsTreeWidget(); + void drawTreeItems(); + +public slots: + +protected: + void showEvent(QShowEvent *); + const char *displayFilter(); + +private: + Ui::TapParameterDialog *ui; + int help_topic_; + + // Called by the constructor. The subclass should tap packets here. + virtual void fillTree() = 0; + virtual QByteArray getTreeAsString(st_format_type format) = 0; + +private slots: + void updateWidgets(); + void on_applyFilterButton_clicked(); + void on_actionCopyToClipboard_triggered(); + void on_actionSaveAs_triggered(); + void on_buttonBox_helpRequested(); +}; + +#endif // TAP_PARAMETER_DIALOG_H + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/qt/stats_tree_dialog.ui b/ui/qt/tap_parameter_dialog.ui index 61836ca567..6e1f1b9625 100644 --- a/ui/qt/stats_tree_dialog.ui +++ b/ui/qt/tap_parameter_dialog.ui @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>StatsTreeDialog</class> - <widget class="QDialog" name="StatsTreeDialog"> + <class>TapParameterDialog</class> + <widget class="QDialog" name="TapParameterDialog"> <property name="geometry"> <rect> <x>0</x> @@ -74,7 +74,7 @@ <string>Save as...</string> </property> <property name="toolTip"> - <string>Save the stats_tree data in various formats</string> + <string>Save the displayed data in various formats</string> </property> <property name="shortcut"> <string>Ctrl+S</string> @@ -92,7 +92,7 @@ <connection> <sender>buttonBox</sender> <signal>accepted()</signal> - <receiver>StatsTreeDialog</receiver> + <receiver>TapParameterDialog</receiver> <slot>accept()</slot> <hints> <hint type="sourcelabel"> @@ -108,7 +108,7 @@ <connection> <sender>buttonBox</sender> <signal>rejected()</signal> - <receiver>StatsTreeDialog</receiver> + <receiver>TapParameterDialog</receiver> <slot>reject()</slot> <hints> <hint type="sourcelabel"> |