diff options
author | Peter Wu <peter@lekensteyn.nl> | 2019-01-29 03:09:18 +0100 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2019-01-29 23:33:46 +0000 |
commit | f66cb9f7efa7b230de211d8d0ff54c1d0213933d (patch) | |
tree | 9ac1de42c40231e620aab1a1069df66debef2230 /ui/qt/uat_dialog.cpp | |
parent | 58ffb7c306c4a8f83b348e3ca5d6d38f6a3ac7cf (diff) |
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 <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'ui/qt/uat_dialog.cpp')
-rw-r--r-- | ui/qt/uat_dialog.cpp | 37 |
1 files changed, 19 insertions, 18 deletions
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(); } } |