From 75c46e80bf2e6db3d59be99e63ac0d4243c5878e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Fri, 5 Oct 2018 08:33:24 +0200 Subject: [PATCH] Qt: Add copy from another profile in UAT dialogs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a new button to UAT dialogs to copy entries from another profile. Change-Id: I641ba764d8738f738466529d74d4a21ff13075a0 Reviewed-on: https://code.wireshark.org/review/30028 Petri-Dish: Stig Bjørlykke Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu Petri-Dish: Peter Wu Reviewed-by: Stig Bjørlykke --- epan/dissectors/packet-dof.c | 6 +++--- epan/uat.c | 2 +- epan/uat.h | 3 ++- epan/uat_load.l | 10 ++++++++-- ui/qt/io_graph_dialog.cpp | 2 +- ui/qt/models/uat_model.cpp | 7 +++++++ ui/qt/models/uat_model.h | 1 + ui/qt/sctp_chunk_statistics_dialog.cpp | 2 +- ui/qt/uat_dialog.cpp | 26 ++++++++++++++++++++++++-- ui/qt/uat_dialog.h | 1 + ui/qt/uat_frame.cpp | 2 +- 11 files changed, 50 insertions(+), 12 deletions(-) diff --git a/epan/dissectors/packet-dof.c b/epan/dissectors/packet-dof.c index 90eb267ccd..1049b4cd8f 100644 --- a/epan/dissectors/packet-dof.c +++ b/epan/dissectors/packet-dof.c @@ -10960,9 +10960,9 @@ static void dof_register(void) "A table of secrets for different identities.", identsecret_uat); - uat_load(secmode_uat, &uat_load_err); - uat_load(seckey_uat, &uat_load_err); - uat_load(identsecret_uat, &uat_load_err); + uat_load(secmode_uat, NULL, &uat_load_err); + uat_load(seckey_uat, NULL, &uat_load_err); + uat_load(identsecret_uat, NULL, &uat_load_err); } static void dof_handoff(void) diff --git a/epan/uat.c b/epan/uat.c index 13b9854798..43315e9419 100644 --- a/epan/uat.c +++ b/epan/uat.c @@ -529,7 +529,7 @@ void uat_load_all(void) { if (!u->loaded) { err = NULL; - if (!uat_load(u, &err)) { + if (!uat_load(u, NULL, &err)) { report_failure("Error loading table '%s': %s",u->name,err); g_free(err); } diff --git a/epan/uat.h b/epan/uat.h index f0426ce1ec..89fba7ed6e 100644 --- a/epan/uat.h +++ b/epan/uat.h @@ -301,12 +301,13 @@ void uat_cleanup(void); /** Populate a uat using its file. * * @param uat_in Pointer to a uat. Must not be NULL. + * @param filename Filename to load, NULL to fetch from current profile. * @param err Upon failure, points to an error string. * * @return TRUE on success, FALSE on failure. */ WS_DLL_PUBLIC -gboolean uat_load(uat_t* uat_in, char** err); +gboolean uat_load(uat_t* uat_in, const gchar *filename, char** err); /** Create or update a single uat entry using a string. * diff --git a/epan/uat_load.l b/epan/uat_load.l index 981a362139..1aceb6a703 100644 --- a/epan/uat_load.l +++ b/epan/uat_load.l @@ -357,13 +357,19 @@ comment #[^\n]*\n DIAG_ON_FLEX gboolean -uat_load(uat_t *uat, char **errx) +uat_load(uat_t *uat, const gchar *filename, char **errx) { - gchar *fname = uat_get_actual_filename(uat, FALSE); + gchar *fname; FILE *in; yyscan_t scanner; uat_load_scanner_state_t state; + if (filename) { + fname = g_strdup(filename); + } else { + fname = uat_get_actual_filename(uat, FALSE); + } + if (!fname) { UAT_UPDATE(uat); diff --git a/ui/qt/io_graph_dialog.cpp b/ui/qt/io_graph_dialog.cpp index 132e3574ff..3adf01dda7 100644 --- a/ui/qt/io_graph_dialog.cpp +++ b/ui/qt/io_graph_dialog.cpp @@ -1134,7 +1134,7 @@ void IOGraphDialog::loadProfileGraphs() io_graph_fields); char* err = NULL; - if (!uat_load(iog_uat_, &err)) { + if (!uat_load(iog_uat_, NULL, &err)) { report_failure("Error while loading %s: %s. Default graph values will be used", iog_uat_->name, err); g_free(err); uat_clear(iog_uat_); diff --git a/ui/qt/models/uat_model.cpp b/ui/qt/models/uat_model.cpp index a5adcdde78..e482bb6d37 100644 --- a/ui/qt/models/uat_model.cpp +++ b/ui/qt/models/uat_model.cpp @@ -44,6 +44,13 @@ void UatModel::loadUat(epan_uat * uat) } } +void UatModel::reloadUat() +{ + beginResetModel(); + loadUat(uat_); + endResetModel(); +} + Qt::ItemFlags UatModel::flags(const QModelIndex &index) const { if (!index.isValid()) diff --git a/ui/qt/models/uat_model.h b/ui/qt/models/uat_model.h index 489992c26b..d7ffa62d4f 100644 --- a/ui/qt/models/uat_model.h +++ b/ui/qt/models/uat_model.h @@ -44,6 +44,7 @@ public: bool copyRow(int dst_row, int src_row); bool moveRow(int src_row, int dst_row); + void reloadUat(); bool hasErrors() const; void clearAll(); diff --git a/ui/qt/sctp_chunk_statistics_dialog.cpp b/ui/qt/sctp_chunk_statistics_dialog.cpp index e2f37a8011..aa35c01207 100644 --- a/ui/qt/sctp_chunk_statistics_dialog.cpp +++ b/ui/qt/sctp_chunk_statistics_dialog.cpp @@ -297,7 +297,7 @@ void SCTPChunkStatisticsDialog::on_actionChunkTypePreferences_triggered() uat_t *uat = prefs_get_uat_value(pref); uat_clear(uat); - if (!uat_load(uat, &err)) { + if (!uat_load(uat, NULL, &err)) { /* XXX - report this through the GUI */ g_log(NULL, G_LOG_LEVEL_WARNING, "Error loading table '%s': %s", uat->name, err); g_free(err); diff --git a/ui/qt/uat_dialog.cpp b/ui/qt/uat_dialog.cpp index 607c3ef8ef..c0318f6b36 100644 --- a/ui/qt/uat_dialog.cpp +++ b/ui/qt/uat_dialog.cpp @@ -16,11 +16,13 @@ #include "ui/help_url.h" #include +#include #include #include #include #include +#include #include @@ -39,6 +41,12 @@ UatDialog::UatDialog(QWidget *parent, epan_uat *uat) : ok_button_ = ui->buttonBox->button(QDialogButtonBox::Ok); help_button_ = ui->buttonBox->button(QDialogButtonBox::Help); + if (uat->from_profile) { + QPushButton *copy_button = new CopyFromProfileButton(uat->filename); + ui->buttonBox->addButton(copy_button, QDialogButtonBox::ApplyRole); + connect(copy_button->menu(), SIGNAL(triggered(QAction *)), this, SLOT(copyFromProfile(QAction *))); + } + #ifdef Q_OS_MAC ui->newToolButton->setAttribute(Qt::WA_MacSmallSize, true); ui->deleteToolButton->setAttribute(Qt::WA_MacSmallSize, true); @@ -77,6 +85,20 @@ UatDialog::~UatDialog() delete uat_model_; } +void UatDialog::copyFromProfile(QAction *action) +{ + QString filename = action->data().toString(); + + gchar *err = NULL; + if (uat_load(uat_, filename.toUtf8().constData(), &err)) { + uat_->changed = TRUE; + uat_model_->reloadUat(); + } else { + report_failure("Error while loading %s: %s", uat_->name, err); + g_free(err); + } +} + void UatDialog::setUat(epan_uat *uat) { QString title(tr("Unknown User Accessible Table")); @@ -152,7 +174,7 @@ void UatDialog::modelRowsRemoved() void UatDialog::modelRowsReset() { ui->deleteToolButton->setEnabled(false); - ui->clearToolButton->setEnabled(false); + ui->clearToolButton->setEnabled(uat_model_->rowCount() != 0); ui->copyToolButton->setEnabled(false); ui->moveUpToolButton->setEnabled(false); ui->moveDownToolButton->setEnabled(false); @@ -344,7 +366,7 @@ void UatDialog::rejectChanges() if (uat_->changed) { gchar *err = NULL; uat_clear(uat_); - if (!uat_load(uat_, &err)) { + if (!uat_load(uat_, NULL, &err)) { report_failure("Error while loading %s: %s", uat_->name, err); g_free(err); } diff --git a/ui/qt/uat_dialog.h b/ui/qt/uat_dialog.h index 66bde76abf..7bce5434dc 100644 --- a/ui/qt/uat_dialog.h +++ b/ui/qt/uat_dialog.h @@ -38,6 +38,7 @@ public: void setUat(struct epan_uat *uat = NULL); private slots: + void copyFromProfile(QAction *action); void modelDataChanged(const QModelIndex &topLeft); void modelRowsRemoved(); void modelRowsReset(); diff --git a/ui/qt/uat_frame.cpp b/ui/qt/uat_frame.cpp index ed0e5f8916..14b222d07b 100644 --- a/ui/qt/uat_frame.cpp +++ b/ui/qt/uat_frame.cpp @@ -145,7 +145,7 @@ void UatFrame::rejectChanges() if (uat_->changed) { gchar *err = NULL; uat_clear(uat_); - if (!uat_load(uat_, &err)) { + if (!uat_load(uat_, NULL, &err)) { report_failure("Error while loading %s: %s", uat_->name, err); g_free(err); }