aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt
diff options
context:
space:
mode:
Diffstat (limited to 'ui/qt')
-rw-r--r--ui/qt/extcap_argument.cpp59
-rw-r--r--ui/qt/extcap_argument.h4
-rw-r--r--ui/qt/extcap_options_dialog.cpp86
-rw-r--r--ui/qt/extcap_options_dialog.h1
-rw-r--r--ui/qt/extcap_options_dialog.ui19
5 files changed, 164 insertions, 5 deletions
diff --git a/ui/qt/extcap_argument.cpp b/ui/qt/extcap_argument.cpp
index 0c06107f3e..3200a7e1d6 100644
--- a/ui/qt/extcap_argument.cpp
+++ b/ui/qt/extcap_argument.cpp
@@ -40,9 +40,12 @@
#include <QStandardItem>
#include <QStandardItemModel>
#include <QItemSelectionModel>
+#include <QRegExp>
#include <glib.h>
#include <log.h>
+
+#include <extcap.h>
#include <epan/prefs.h>
#include <color_utils.h>
@@ -57,6 +60,7 @@ QWidget * ExtArgSelector::createEditor(QWidget * parent)
{
int counter = 0;
int selected = -1;
+ QString stored = _argument->storeval ? QString(_argument->storeval) : QString();
boxSelection = new QComboBox(parent);
@@ -67,7 +71,10 @@ QWidget * ExtArgSelector::createEditor(QWidget * parent)
while ( iter != values.constEnd() )
{
boxSelection->addItem((*iter).value(), (*iter).call());
- if ( (*iter).isDefault() )
+
+ if ( ! _argument->storeval && (*iter).isDefault() )
+ selected = counter;
+ else if ( _argument->storeval && stored.compare((*iter).call()) == 0 )
selected = counter;
counter++;
@@ -135,7 +142,7 @@ QWidget * ExtArgRadio::createEditor(QWidget * parent)
ExtcapValueList::const_iterator iter = values.constBegin();
while ( iter != values.constEnd() )
- {
+ {
QRadioButton * radio = new QRadioButton((*iter).value());
QString callString = (*iter).call();
callStrings->append(callString);
@@ -219,6 +226,15 @@ QWidget * ExtArgBool::createEditor(QWidget * parent)
if ( _argument->tooltip != NULL )
boolBox->setToolTip(QString().fromUtf8(_argument->tooltip));
+ if ( _argument->storeval )
+ {
+ QRegExp regexp(EXTCAP_BOOLEAN_REGEX);
+
+ bool savedstate = ( regexp.indexIn(QString(_argument->storeval[0]), 0) != -1 );
+ if ( savedstate != state )
+ state = savedstate;
+ }
+
boolBox->setCheckState(state ? Qt::Checked : Qt::Unchecked );
connect (boolBox, SIGNAL(stateChanged(int)), SLOT(onIntChanged(int)));
@@ -244,6 +260,13 @@ QString ExtArgBool::value()
return QString(boolBox->checkState() == Qt::Checked ? "true" : "false");
}
+QString ExtArgBool::prefValue()
+{
+ if ( boolBox == NULL )
+ return QString("false");
+ return QString(boolBox->checkState() == Qt::Checked ? "true" : "false");
+}
+
bool ExtArgBool::isValid()
{
/* A bool is allways valid, but the base function checks on string length,
@@ -279,8 +302,17 @@ ExtArgText::ExtArgText(extcap_arg * argument) :
QWidget * ExtArgText::createEditor(QWidget * parent)
{
+ QString storeValue;
QString text = defaultValue();
+ if ( _argument->storeval )
+ {
+ QString storeValue = _argument->storeval;
+
+ if ( storeValue.length() > 0 && storeValue.compare(text) != 0 )
+ text = storeValue.trimmed();
+ }
+
textBox = new QLineEdit(text, parent);
if ( _argument->tooltip != NULL )
@@ -334,7 +366,17 @@ ExtArgNumber::ExtArgNumber(extcap_arg * argument) :
QWidget * ExtArgNumber::createEditor(QWidget * parent)
{
+ QString storeValue;
QString text = defaultValue();
+
+ if ( _argument->storeval )
+ {
+ QString storeValue = _argument->storeval;
+
+ if ( storeValue.length() > 0 && storeValue.compare(text) != 0 )
+ text = storeValue;
+ }
+
textBox = (QLineEdit *)ExtArgText::createEditor(parent);
textBox->disconnect(SIGNAL(textChanged(QString)));
@@ -525,6 +567,10 @@ QString ExtcapArgument::value()
return QString();
}
+QString ExtcapArgument::prefValue()
+{
+ return value();
+}
bool ExtcapArgument::isValid()
{
@@ -544,10 +590,17 @@ QString ExtcapArgument::defaultValue()
if ( str != 0 )
return QString(str);
}
-
return QString();
}
+QString ExtcapArgument::prefKey()
+{
+ if ( ! _argument->save )
+ return QString();
+
+ return QString(_argument->call).replace("-", "");
+}
+
bool ExtcapArgument::isRequired()
{
if ( _argument != NULL )
diff --git a/ui/qt/extcap_argument.h b/ui/qt/extcap_argument.h
index c83111a2d3..2d605d2881 100644
--- a/ui/qt/extcap_argument.h
+++ b/ui/qt/extcap_argument.h
@@ -98,6 +98,9 @@ public:
bool isValid();
bool isRequired();
+ QString prefKey();
+ virtual QString prefValue();
+
static ExtcapArgument * create(extcap_arg * argument = 0);
Q_SIGNALS:
@@ -189,6 +192,7 @@ public:
virtual QString value();
virtual bool isValid();
virtual QString defaultValue();
+ virtual QString prefValue();
private:
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 <epan/prefs.h>
+#include <ui/preference_utils.h>
+
+#include <ui/qt/wireshark_application.h>
+
#include <ui/qt/extcap_argument.h>
#include <ui/qt/extcap_argument_file.h>
#include <ui/qt/extcap_argument_multiselect.h>
@@ -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<ExtArgBool *>((*iter)) != NULL)
+ {
+ value = ((ExtArgBool *)*iter)->prefValue();
+ }
+ else if ( dynamic_cast<ExtArgRadio *>((*iter)) != NULL)
+ {
+ value = ((ExtArgRadio *)*iter)->prefValue();
+ }
+ else if ( dynamic_cast<ExtArgSelector *>((*iter)) != NULL)
+ {
+ value = ((ExtArgSelector *)*iter)->prefValue();
+ }
+ else if ( dynamic_cast<ExtArgMultiSelect *>((*iter)) != NULL)
+ {
+ value = ((ExtArgMultiSelect *)*iter)->prefValue();
+ }
+ else if ( dynamic_cast<ExtcapArgumentFileSelection *>((*iter)) != NULL)
+ {
+ value = ((ExtcapArgumentFileSelection *)*iter)->prefValue();
+ }
+ else if ( dynamic_cast<ExtArgNumber *>((*iter)) != NULL)
+ {
+ value = ((ExtArgNumber *)*iter)->prefValue();
+ }
+ else if ( dynamic_cast<ExtArgText *>((*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 */
/*
diff --git a/ui/qt/extcap_options_dialog.h b/ui/qt/extcap_options_dialog.h
index eb0761df8e..3ca859ed35 100644
--- a/ui/qt/extcap_options_dialog.h
+++ b/ui/qt/extcap_options_dialog.h
@@ -70,6 +70,7 @@ private:
ExtcapArgumentList extcapArguments;
bool saveOptionToCaptureInfo();
+ void storeValues();
};
#endif /* HAVE_EXTCAP */
diff --git a/ui/qt/extcap_options_dialog.ui b/ui/qt/extcap_options_dialog.ui
index d22380aee3..edd6c96c8c 100644
--- a/ui/qt/extcap_options_dialog.ui
+++ b/ui/qt/extcap_options_dialog.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>600</width>
- <height>55</height>
+ <height>92</height>
</rect>
</property>
<property name="minimumSize">
@@ -21,6 +21,23 @@
<layout class="QVBoxLayout" name="verticalLayout"/>
</item>
<item>
+ <widget class="Line" name="line">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="checkSaveOnStart">
+ <property name="text">
+ <string>Save parameter on capture start</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>