From f66cb9f7efa7b230de211d8d0ff54c1d0213933d Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 29 Jan 2019 03:09:18 +0100 Subject: Qt: move method to apply/undo UAT changes to UatModel UatModel could be constructed with a name instead of an epan_uat type. To allow those users to save/revert the uat, make sure to expose a method that does not require access to the underlying epan_uat type. Change-Id: I1d1a5811c1025bd9c2a2ea1722f460e6ac33b9aa Reviewed-on: https://code.wireshark.org/review/31793 Petri-Dish: Peter Wu Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu --- ui/qt/uat_dialog.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'ui/qt/uat_dialog.cpp') diff --git a/ui/qt/uat_dialog.cpp b/ui/qt/uat_dialog.cpp index bd2ebe1f5d..98088c8d83 100644 --- a/ui/qt/uat_dialog.cpp +++ b/ui/qt/uat_dialog.cpp @@ -344,18 +344,12 @@ void UatDialog::applyChanges() void UatDialog::acceptChanges() { - if (!uat_) return; - - if (uat_->changed) { - gchar *err = NULL; + if (!uat_model_) return; - if (!uat_save(uat_, &err)) { - report_failure("Error while saving %s: %s", uat_->name, err); - g_free(err); - } - - if (uat_->post_update_cb) { - uat_->post_update_cb(); + QString error; + if (uat_model_->applyChanges(error)) { + if (!error.isEmpty()) { + report_failure("%s", qPrintable(error)); } applyChanges(); } @@ -363,15 +357,22 @@ void UatDialog::acceptChanges() void UatDialog::rejectChanges() { - if (!uat_) return; + if (!uat_model_) return; - if (uat_->changed) { - gchar *err = NULL; - uat_clear(uat_); - if (!uat_load(uat_, NULL, &err)) { - report_failure("Error while loading %s: %s", uat_->name, err); - g_free(err); + QString error; + if (uat_model_->revertChanges(error)) { + if (!error.isEmpty()) { + report_failure("%s", qPrintable(error)); } + // Why do we have to trigger a redissection? If the original UAT is + // restored and dissectors only apply changes after the post_update_cb + // method is invoked, then it should not be necessary to trigger + // redissection. One potential exception is when something modifies the + // UAT file after Wireshark has started, but this behavior is not + // supported and causes potentially unnecessary redissection whenever + // the preferences dialog is closed. + // XXX audit all UAT providers and check whether it is safe to remove + // the next call (that is, when their update_cb has no side-effects). applyChanges(); } } -- cgit v1.2.3