From 927ffaa794d5fb24e0b4f3fba08c4c31f4dd7d63 Mon Sep 17 00:00:00 2001 From: Roland Knall Date: Tue, 29 Dec 2015 07:57:36 +0100 Subject: extcap: Add Save functionality to options dialog This patch creates the functionality of saving all parameters for extcap devices in the general preference section. For now, multiselect and fileselect do not save their values but patches for this will be provided in the future Also, all preferences are stored as strings to make handling easier. This might change in the future, but for the first version it will stick. Restore to Defaults is not implemented as of yet, and will be in a future version, once the preference storing is finalized Bug: 11666 Change-Id: I178346405146d2e43f4f3481c05c92c0b3595af5 Reviewed-on: https://code.wireshark.org/review/13451 Petri-Dish: Roland Knall Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall --- ui/qt/extcap_options_dialog.cpp | 86 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) (limited to 'ui/qt/extcap_options_dialog.cpp') diff --git a/ui/qt/extcap_options_dialog.cpp b/ui/qt/extcap_options_dialog.cpp index f36d4afbd8..ed7a0150e4 100644 --- a/ui/qt/extcap_options_dialog.cpp +++ b/ui/qt/extcap_options_dialog.cpp @@ -54,6 +54,11 @@ #include "qt_ui_utils.h" +#include +#include + +#include + #include #include #include @@ -68,6 +73,7 @@ ExtcapOptionsDialog::ExtcapOptionsDialog(QWidget *parent) : setWindowTitle(wsApp->windowTitleString(tr("Extcap Interface Options"))); + ui->checkSaveOnStart->setCheckState(prefs.extcap_save_on_start ? Qt::Checked : Qt::Unchecked); ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Start")); } @@ -118,6 +124,12 @@ ExtcapOptionsDialog::~ExtcapOptionsDialog() void ExtcapOptionsDialog::on_buttonBox_accepted() { if (saveOptionToCaptureInfo()) { + /* Starting a new capture with those values */ + prefs.extcap_save_on_start = ui->checkSaveOnStart->checkState() == Qt::Checked; + + if ( prefs.extcap_save_on_start ) + storeValues(); + accept(); } } @@ -281,7 +293,7 @@ bool ExtcapOptionsDialog::saveOptionToCaptureInfo() device = g_array_index(global_capture_opts.all_ifaces, interface_t, device_idx); global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, device_idx); - ret_args = g_hash_table_new(g_str_hash, g_str_equal); + ret_args = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); ExtcapArgumentList::const_iterator iter; @@ -301,6 +313,7 @@ bool ExtcapOptionsDialog::saveOptionToCaptureInfo() gchar * call_string = g_strdup(call.toStdString().c_str()); gchar * value_string = g_strdup(value.toStdString().c_str()); + g_hash_table_insert(ret_args, call_string, value_string ); } @@ -313,6 +326,77 @@ bool ExtcapOptionsDialog::saveOptionToCaptureInfo() return true; } +void ExtcapOptionsDialog::storeValues() +{ + GHashTable * entries = g_hash_table_new(g_str_hash, g_str_equal); + ExtcapArgumentList::const_iterator iter; + + QString value; + + /* All arguments are being iterated, to ensure, that any error handling catches all arguments */ + for(iter = extcapArguments.constBegin(); iter != extcapArguments.constEnd(); ++iter) + { + ExtcapArgument * argument = (ExtcapArgument *)(*iter); + + /* The dynamic casts are necessary, because we come here using the Signal/Slot system + * of Qt, and -in short- Q_OBJECT classes cannot be multiple inherited. Another possibility + * would be to use Q_INTERFACE, but this causes way more nightmares, and we really just + * need here an explicit cast for the check functionality */ + if ( dynamic_cast((*iter)) != NULL) + { + value = ((ExtArgBool *)*iter)->prefValue(); + } + else if ( dynamic_cast((*iter)) != NULL) + { + value = ((ExtArgRadio *)*iter)->prefValue(); + } + else if ( dynamic_cast((*iter)) != NULL) + { + value = ((ExtArgSelector *)*iter)->prefValue(); + } + else if ( dynamic_cast((*iter)) != NULL) + { + value = ((ExtArgMultiSelect *)*iter)->prefValue(); + } + else if ( dynamic_cast((*iter)) != NULL) + { + value = ((ExtcapArgumentFileSelection *)*iter)->prefValue(); + } + else if ( dynamic_cast((*iter)) != NULL) + { + value = ((ExtArgNumber *)*iter)->prefValue(); + } + else if ( dynamic_cast((*iter)) != NULL) + { + value = ((ExtArgText *)*iter)->prefValue(); + } + else + value = (*iter)->prefValue(); + + QString prefKey = QString("%1.%2").arg(device_name).arg(argument->prefKey()); + if ( prefKey.length() > 0 ) + { + gchar * key = g_strdup(prefKey.toStdString().c_str()); + gchar * val = g_strdup(value.length() == 0 ? " " : value.toStdString().c_str()); + + /* Setting the internally stored value for the preference to the new value */ + (*iter)->argument()->storeval = g_strdup(val); + + g_hash_table_insert(entries, key, val); + } + } + + if ( g_hash_table_size(entries) > 0 ) + { + if ( prefs_store_ext_multiple("extcap", entries) ) + { + wsApp->emitAppSignal(WiresharkApplication::PacketDissectionChanged); + wsApp->emitAppSignal(WiresharkApplication::PreferencesChanged); + } + } +} + + #endif /* HAVE_LIBPCAP */ /* -- cgit v1.2.3