2015-04-28 08:26:46 +00:00
|
|
|
/* extcap_argument.cpp
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <extcap_argument.h>
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QIntValidator>
|
|
|
|
#include <QDoubleValidator>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QButtonGroup>
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QRadioButton>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QMargins>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QStandardItem>
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QItemSelectionModel>
|
2015-12-29 06:57:36 +00:00
|
|
|
#include <QRegExp>
|
2015-12-29 14:35:43 +00:00
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include <log.h>
|
2015-12-29 06:57:36 +00:00
|
|
|
|
|
|
|
#include <extcap.h>
|
2015-12-29 14:35:43 +00:00
|
|
|
#include <epan/prefs.h>
|
2015-12-29 06:57:36 +00:00
|
|
|
#include <epan/prefs-int.h>
|
2015-12-29 14:35:43 +00:00
|
|
|
#include <color_utils.h>
|
2015-04-28 08:26:46 +00:00
|
|
|
|
|
|
|
#include <extcap_parser.h>
|
|
|
|
#include <extcap_argument_file.h>
|
2015-12-29 13:50:55 +00:00
|
|
|
#include <extcap_argument_multiselect.h>
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
ExtArgSelector::ExtArgSelector(extcap_arg * argument) :
|
|
|
|
ExtcapArgument(argument), boxSelection(0) {}
|
|
|
|
|
|
|
|
QWidget * ExtArgSelector::createEditor(QWidget * parent)
|
2015-04-28 08:26:46 +00:00
|
|
|
{
|
2015-12-29 14:35:43 +00:00
|
|
|
int counter = 0;
|
|
|
|
int selected = -1;
|
2016-09-10 23:16:24 +00:00
|
|
|
const char *prefval = _argument->pref_valptr ? *_argument->pref_valptr : NULL;
|
|
|
|
QString stored(prefval ? prefval : "");
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
boxSelection = new QComboBox(parent);
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
if ( values.length() > 0 )
|
|
|
|
{
|
|
|
|
ExtcapValueList::const_iterator iter = values.constBegin();
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
while ( iter != values.constEnd() )
|
2015-04-28 08:26:46 +00:00
|
|
|
{
|
2015-12-29 14:35:43 +00:00
|
|
|
boxSelection->addItem((*iter).value(), (*iter).call());
|
2015-12-29 06:57:36 +00:00
|
|
|
|
2016-09-10 23:16:24 +00:00
|
|
|
if ( !prefval && (*iter).isDefault() )
|
2015-12-29 06:57:36 +00:00
|
|
|
selected = counter;
|
2016-09-10 23:16:24 +00:00
|
|
|
else if ( prefval && stored.compare((*iter).call()) == 0 )
|
2015-12-29 14:35:43 +00:00
|
|
|
selected = counter;
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
counter++;
|
|
|
|
++iter;
|
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
if ( selected > -1 && selected < boxSelection->count() )
|
|
|
|
boxSelection->setCurrentIndex(selected);
|
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
connect ( boxSelection, SIGNAL(currentIndexChanged(int)), SLOT(onIntChanged(int)) );
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
return boxSelection;
|
|
|
|
}
|
2015-12-29 13:50:55 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
bool ExtArgSelector::isValid()
|
|
|
|
{
|
|
|
|
bool valid = true;
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
if ( value().length() == 0 && isRequired() )
|
|
|
|
valid = false;
|
|
|
|
|
|
|
|
QString lblInvalidColor = ColorUtils::fromColorT(prefs.gui_text_invalid).name();
|
|
|
|
QString cmbBoxStyle("QComboBox { background-color: %1; } ");
|
|
|
|
boxSelection->setStyleSheet( cmbBoxStyle.arg(valid ? QString("") : lblInvalidColor) );
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ExtArgSelector::value()
|
|
|
|
{
|
|
|
|
if ( boxSelection == 0 )
|
|
|
|
return QString();
|
2015-04-28 08:26:46 +00:00
|
|
|
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
|
2015-12-29 14:35:43 +00:00
|
|
|
QVariant data = boxSelection->currentData();
|
2015-04-28 08:26:46 +00:00
|
|
|
#else
|
2015-12-29 14:35:43 +00:00
|
|
|
QVariant data = boxSelection->itemData(boxSelection->currentIndex());
|
2015-04-28 08:26:46 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
return data.toString();
|
|
|
|
}
|
2015-12-29 13:50:55 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
ExtArgRadio::ExtArgRadio(extcap_arg * argument) :
|
|
|
|
ExtcapArgument(argument), selectorGroup(0), callStrings(0) {}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
QWidget * ExtArgRadio::createEditor(QWidget * parent)
|
2015-04-28 08:26:46 +00:00
|
|
|
{
|
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
int count = 0;
|
|
|
|
bool anyChecked = false;
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
selectorGroup = new QButtonGroup(parent);
|
|
|
|
QWidget * radioButtons = new QWidget;
|
|
|
|
QVBoxLayout * vrLayout = new QVBoxLayout();
|
|
|
|
QMargins margins = vrLayout->contentsMargins();
|
|
|
|
vrLayout->setContentsMargins(0, 0, 0, margins.bottom());
|
|
|
|
if ( callStrings != 0 )
|
|
|
|
delete callStrings;
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
callStrings = new QList<QString>();
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
if ( values.length() > 0 )
|
|
|
|
{
|
|
|
|
ExtcapValueList::const_iterator iter = values.constBegin();
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
while ( iter != values.constEnd() )
|
2015-12-29 06:57:36 +00:00
|
|
|
{
|
2015-12-29 14:35:43 +00:00
|
|
|
QRadioButton * radio = new QRadioButton((*iter).value());
|
|
|
|
QString callString = (*iter).call();
|
|
|
|
callStrings->append(callString);
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
if ( (*iter).isDefault() )
|
2015-12-29 14:35:43 +00:00
|
|
|
{
|
|
|
|
radio->setChecked(true);
|
|
|
|
anyChecked = true;
|
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
connect(radio, SIGNAL(clicked(bool)), SLOT(onBoolChanged(bool)));
|
|
|
|
selectorGroup->addButton(radio, count);
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
vrLayout->addWidget(radio);
|
|
|
|
count++;
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
++iter;
|
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
}
|
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
/* No default was provided, and not saved value exists */
|
|
|
|
if ( anyChecked == false && count > 0 )
|
|
|
|
((QRadioButton*)(selectorGroup->button(0)))->setChecked(true);
|
|
|
|
|
|
|
|
radioButtons->setLayout(vrLayout);
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
return radioButtons;
|
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
QString ExtArgRadio::value()
|
|
|
|
{
|
|
|
|
int idx = 0;
|
|
|
|
if ( selectorGroup == 0 || callStrings == 0 )
|
2015-04-28 08:26:46 +00:00
|
|
|
return QString();
|
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
idx = selectorGroup->checkedId();
|
|
|
|
if ( idx > -1 && callStrings->length() > idx )
|
|
|
|
return callStrings->takeAt(idx);
|
2015-12-29 13:50:55 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
return QString();
|
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
bool ExtArgRadio::isValid()
|
2015-04-28 08:26:46 +00:00
|
|
|
{
|
2015-12-29 14:35:43 +00:00
|
|
|
bool valid = true;
|
|
|
|
int idx = 0;
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
if ( isRequired() )
|
2015-04-28 08:26:46 +00:00
|
|
|
{
|
2015-12-29 14:35:43 +00:00
|
|
|
if ( selectorGroup == 0 || callStrings == 0 )
|
|
|
|
valid = false;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
idx = selectorGroup->checkedId();
|
|
|
|
if ( idx == -1 || callStrings->length() <= idx )
|
|
|
|
valid = false;
|
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
}
|
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
/* If nothing is selected, but a selection is required, the only thing that
|
|
|
|
* can be marked is the label */
|
|
|
|
QString lblInvalidColor = ColorUtils::fromColorT(prefs.gui_text_invalid).name();
|
|
|
|
_label->setStyleSheet ( label_style.arg(valid ? QString("") : lblInvalidColor) );
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
return valid;
|
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
ExtArgBool::ExtArgBool(extcap_arg * argument) :
|
|
|
|
ExtcapArgument(argument), boolBox(0) {}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
QWidget * ExtArgBool::createLabel(QWidget * parent)
|
|
|
|
{
|
|
|
|
return new QWidget(parent);
|
|
|
|
}
|
2015-12-29 13:50:55 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
QWidget * ExtArgBool::createEditor(QWidget * parent)
|
|
|
|
{
|
2016-01-28 09:41:38 +00:00
|
|
|
bool state = defaultBool();
|
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
boolBox = new QCheckBox(QString().fromUtf8(_argument->display), parent);
|
|
|
|
if ( _argument->tooltip != NULL )
|
|
|
|
boolBox->setToolTip(QString().fromUtf8(_argument->tooltip));
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2016-09-10 23:16:24 +00:00
|
|
|
const char *prefval = _argument->pref_valptr ? *_argument->pref_valptr : NULL;
|
|
|
|
if ( prefval )
|
2015-12-29 06:57:36 +00:00
|
|
|
{
|
|
|
|
QRegExp regexp(EXTCAP_BOOLEAN_REGEX);
|
|
|
|
|
2016-09-10 23:16:24 +00:00
|
|
|
bool savedstate = ( regexp.indexIn(QString(prefval[0]), 0) != -1 );
|
2015-12-29 06:57:36 +00:00
|
|
|
if ( savedstate != state )
|
|
|
|
state = savedstate;
|
|
|
|
}
|
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
boolBox->setCheckState(state ? Qt::Checked : Qt::Unchecked );
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
connect (boolBox, SIGNAL(stateChanged(int)), SLOT(onIntChanged(int)));
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
return boolBox;
|
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
QString ExtArgBool::call()
|
|
|
|
{
|
|
|
|
if ( boolBox == NULL )
|
|
|
|
return QString("");
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
if ( _argument->arg_type == EXTCAP_ARG_BOOLEAN )
|
|
|
|
return ExtcapArgument::call();
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
return QString(boolBox->checkState() == Qt::Checked ? _argument->call : "");
|
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
QString ExtArgBool::value()
|
|
|
|
{
|
|
|
|
if ( boolBox == NULL || _argument->arg_type == EXTCAP_ARG_BOOLFLAG )
|
|
|
|
return QString();
|
|
|
|
return QString(boolBox->checkState() == Qt::Checked ? "true" : "false");
|
|
|
|
}
|
2015-12-29 13:50:55 +00:00
|
|
|
|
2015-12-29 06:57:36 +00:00
|
|
|
QString ExtArgBool::prefValue()
|
|
|
|
{
|
|
|
|
if ( boolBox == NULL )
|
|
|
|
return QString("false");
|
|
|
|
return QString(boolBox->checkState() == Qt::Checked ? "true" : "false");
|
|
|
|
}
|
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
bool ExtArgBool::isValid()
|
|
|
|
{
|
|
|
|
/* A bool is allways valid, but the base function checks on string length,
|
|
|
|
* which will fail with boolflags */
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
bool ExtArgBool::defaultBool()
|
2015-04-28 08:26:46 +00:00
|
|
|
{
|
2016-01-28 09:41:38 +00:00
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
if ( _argument )
|
|
|
|
{
|
2015-12-29 06:57:36 +00:00
|
|
|
if ( extcap_complex_get_bool(_argument->default_complex) == (gboolean)TRUE )
|
|
|
|
result = true;
|
2016-01-28 09:41:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2015-12-29 13:50:55 +00:00
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
QString ExtArgBool::defaultValue()
|
|
|
|
{
|
|
|
|
return defaultBool() ? QString("true") : QString("false");
|
2015-12-29 14:35:43 +00:00
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
ExtArgText::ExtArgText(extcap_arg * argument) :
|
|
|
|
ExtcapArgument(argument), textBox(0)
|
|
|
|
{
|
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
QWidget * ExtArgText::createEditor(QWidget * parent)
|
|
|
|
{
|
2015-12-29 06:57:36 +00:00
|
|
|
QString storeValue;
|
2016-01-28 09:41:38 +00:00
|
|
|
QString text = defaultValue();
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2016-09-10 23:16:24 +00:00
|
|
|
if ( _argument->pref_valptr && *_argument->pref_valptr)
|
2015-12-29 06:57:36 +00:00
|
|
|
{
|
2016-09-10 23:16:24 +00:00
|
|
|
QString storeValue(*_argument->pref_valptr);
|
2015-12-29 06:57:36 +00:00
|
|
|
|
|
|
|
if ( storeValue.length() > 0 && storeValue.compare(text) != 0 )
|
|
|
|
text = storeValue.trimmed();
|
|
|
|
}
|
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
textBox = new QLineEdit(text, parent);
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
if ( _argument->tooltip != NULL )
|
|
|
|
textBox->setToolTip(QString().fromUtf8(_argument->tooltip));
|
2015-12-29 13:50:55 +00:00
|
|
|
|
2016-01-18 11:01:14 +00:00
|
|
|
if (_argument->arg_type == EXTCAP_ARG_PASSWORD)
|
|
|
|
textBox->setEchoMode(QLineEdit::Password);
|
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
connect(textBox , SIGNAL(textChanged(QString)), SLOT(onStringChanged(QString)));
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
return textBox;
|
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
QString ExtArgText::value()
|
|
|
|
{
|
|
|
|
if ( textBox == 0 )
|
|
|
|
return QString();
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
return textBox->text();
|
|
|
|
}
|
2015-12-29 13:50:55 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
bool ExtArgText::isValid()
|
|
|
|
{
|
|
|
|
bool valid = true;
|
|
|
|
|
|
|
|
if ( isRequired() && value().length() == 0 )
|
|
|
|
valid = false;
|
2015-12-29 13:50:55 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
/* validation should only be checked if there is a value. if the argument
|
|
|
|
* must be present (isRequired) the check above will handle that */
|
|
|
|
if ( valid && _argument->regexp != NULL && value().length() > 0)
|
2015-04-28 08:26:46 +00:00
|
|
|
{
|
2015-12-29 14:35:43 +00:00
|
|
|
QString regexp = QString().fromUtf8(_argument->regexp);
|
|
|
|
if ( regexp.length() > 0 )
|
2015-04-28 08:26:46 +00:00
|
|
|
{
|
2015-12-29 14:35:43 +00:00
|
|
|
QRegExp expr(regexp);
|
|
|
|
if ( ! expr.isValid() || expr.indexIn(value(), 0) == -1 )
|
|
|
|
valid = false;
|
2015-04-28 08:26:46 +00:00
|
|
|
}
|
2015-12-29 14:35:43 +00:00
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
QString lblInvalidColor = ColorUtils::fromColorT(prefs.gui_text_invalid).name();
|
|
|
|
QString txtStyle("QLineEdit { background-color: %1; } ");
|
|
|
|
textBox->setStyleSheet( txtStyle.arg(valid ? QString("") : lblInvalidColor) );
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExtArgNumber::ExtArgNumber(extcap_arg * argument) :
|
|
|
|
ExtArgText(argument) {}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
QWidget * ExtArgNumber::createEditor(QWidget * parent)
|
2015-04-28 08:26:46 +00:00
|
|
|
{
|
2015-12-29 06:57:36 +00:00
|
|
|
QString storeValue;
|
2016-01-28 09:41:38 +00:00
|
|
|
QString text = defaultValue();
|
2015-12-29 06:57:36 +00:00
|
|
|
|
2016-09-10 23:16:24 +00:00
|
|
|
if ( _argument->pref_valptr && *_argument->pref_valptr)
|
2015-12-29 06:57:36 +00:00
|
|
|
{
|
2016-09-10 23:16:24 +00:00
|
|
|
QString storeValue(*_argument->pref_valptr);
|
2015-12-29 06:57:36 +00:00
|
|
|
|
|
|
|
if ( storeValue.length() > 0 && storeValue.compare(text) != 0 )
|
|
|
|
text = storeValue;
|
|
|
|
}
|
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
textBox = (QLineEdit *)ExtArgText::createEditor(parent);
|
|
|
|
textBox->disconnect(SIGNAL(textChanged(QString)));
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
if ( _argument->arg_type == EXTCAP_ARG_INTEGER || _argument->arg_type == EXTCAP_ARG_UNSIGNED )
|
2015-04-28 08:26:46 +00:00
|
|
|
{
|
2015-12-29 14:35:43 +00:00
|
|
|
QIntValidator * textValidator = new QIntValidator(parent);
|
|
|
|
if ( _argument->range_start != NULL )
|
2016-01-28 09:41:38 +00:00
|
|
|
{
|
|
|
|
int val = 0;
|
|
|
|
if ( _argument->arg_type == EXTCAP_ARG_INTEGER )
|
|
|
|
val = extcap_complex_get_int(_argument->range_start);
|
|
|
|
else if ( _argument->arg_type == EXTCAP_ARG_UNSIGNED )
|
|
|
|
{
|
2016-05-10 20:36:41 +00:00
|
|
|
guint tmp = extcap_complex_get_uint(_argument->range_start);
|
|
|
|
if ( tmp > G_MAXINT )
|
2016-01-28 09:41:38 +00:00
|
|
|
{
|
|
|
|
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Defined value for range_start of %s exceeds valid integer range", _argument->call );
|
|
|
|
val = G_MAXINT;
|
|
|
|
}
|
2016-05-10 20:36:41 +00:00
|
|
|
else
|
|
|
|
val = (gint)tmp;
|
2016-01-28 09:41:38 +00:00
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
textValidator->setBottom(val);
|
|
|
|
}
|
2015-12-29 14:35:43 +00:00
|
|
|
if ( _argument->arg_type == EXTCAP_ARG_UNSIGNED && textValidator->bottom() < 0 )
|
2016-01-28 09:41:38 +00:00
|
|
|
{
|
|
|
|
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "%s sets negative bottom range for unsigned value, setting to 0", _argument->call );
|
2015-12-29 14:35:43 +00:00
|
|
|
textValidator->setBottom(0);
|
2016-01-28 09:41:38 +00:00
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
if ( _argument->range_end != NULL )
|
2016-01-28 09:41:38 +00:00
|
|
|
{
|
|
|
|
int val = 0;
|
|
|
|
if ( _argument->arg_type == EXTCAP_ARG_INTEGER )
|
|
|
|
val = extcap_complex_get_int(_argument->range_end);
|
|
|
|
else if ( _argument->arg_type == EXTCAP_ARG_UNSIGNED )
|
|
|
|
{
|
2016-05-10 20:36:41 +00:00
|
|
|
guint tmp = extcap_complex_get_uint(_argument->range_end);
|
|
|
|
if ( tmp > G_MAXINT )
|
2016-01-28 09:41:38 +00:00
|
|
|
{
|
|
|
|
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Defined value for range_end of %s exceeds valid integer range", _argument->call );
|
|
|
|
val = G_MAXINT;
|
|
|
|
}
|
2016-05-10 20:36:41 +00:00
|
|
|
else
|
|
|
|
val = (gint)tmp;
|
2016-01-28 09:41:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
textValidator->setTop(val);
|
|
|
|
}
|
2015-12-29 14:35:43 +00:00
|
|
|
textBox->setValidator(textValidator);
|
|
|
|
}
|
|
|
|
else if ( _argument->arg_type == EXTCAP_ARG_DOUBLE )
|
|
|
|
{
|
|
|
|
QDoubleValidator * textValidator = new QDoubleValidator(parent);
|
|
|
|
if ( _argument->range_start != NULL )
|
|
|
|
textValidator->setBottom(extcap_complex_get_double(_argument->range_start));
|
|
|
|
if ( _argument->range_end != NULL )
|
|
|
|
textValidator->setTop(extcap_complex_get_double(_argument->range_end));
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
textBox->setValidator(textValidator);
|
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
textBox->setText(text.trimmed());
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
connect(textBox, SIGNAL(textChanged(QString)), SLOT(onStringChanged(QString)));
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
return textBox;
|
|
|
|
}
|
2015-12-29 13:50:55 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
QString ExtArgNumber::defaultValue()
|
|
|
|
{
|
|
|
|
QString result;
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
if ( _argument != 0 )
|
2015-04-28 08:26:46 +00:00
|
|
|
{
|
2015-12-29 14:35:43 +00:00
|
|
|
if ( _argument->arg_type == EXTCAP_ARG_DOUBLE )
|
|
|
|
result = QString::number(extcap_complex_get_double(_argument->default_complex));
|
|
|
|
else if ( _argument->arg_type == EXTCAP_ARG_INTEGER )
|
|
|
|
result = QString::number(extcap_complex_get_int(_argument->default_complex));
|
|
|
|
else if ( _argument->arg_type == EXTCAP_ARG_UNSIGNED )
|
|
|
|
result = QString::number(extcap_complex_get_uint(_argument->default_complex));
|
|
|
|
else if ( _argument->arg_type == EXTCAP_ARG_LONG )
|
|
|
|
result = QString::number(extcap_complex_get_long(_argument->default_complex));
|
|
|
|
else
|
2016-01-28 09:41:38 +00:00
|
|
|
{
|
|
|
|
QString defValue = ExtcapArgument::defaultValue();
|
|
|
|
result = defValue.length() > 0 ? defValue : QString();
|
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
}
|
2015-12-29 13:50:55 +00:00
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
return result;
|
|
|
|
}
|
2015-04-28 08:26:46 +00:00
|
|
|
|
|
|
|
ExtcapValue::~ExtcapValue() {}
|
|
|
|
|
|
|
|
void ExtcapValue::setChildren(ExtcapValueList children)
|
|
|
|
{
|
|
|
|
ExtcapValueList::iterator iter = children.begin();
|
|
|
|
while ( iter != children.end() )
|
|
|
|
{
|
|
|
|
(*iter)._depth = _depth + 1;
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
_children.append(children);
|
|
|
|
}
|
|
|
|
|
2015-12-29 06:57:36 +00:00
|
|
|
ExtcapArgument::ExtcapArgument(QObject *parent) :
|
|
|
|
QObject(parent), _argument(0), _label(0),
|
|
|
|
label_style(QString("QLabel { color: %1; }"))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-28 08:26:46 +00:00
|
|
|
ExtcapArgument::ExtcapArgument(extcap_arg * argument, QObject *parent) :
|
2016-01-28 09:41:38 +00:00
|
|
|
QObject(parent), _argument(argument), _label(0),
|
2015-12-29 14:35:43 +00:00
|
|
|
label_style(QString("QLabel { color: %1; }"))
|
2015-04-28 08:26:46 +00:00
|
|
|
{
|
|
|
|
if ( _argument->values != 0 )
|
|
|
|
{
|
|
|
|
ExtcapValueList elements = loadValues(QString(""));
|
|
|
|
if ( elements.length() > 0 )
|
|
|
|
values.append(elements);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-29 06:57:36 +00:00
|
|
|
ExtcapArgument::ExtcapArgument(const ExtcapArgument &obj) :
|
|
|
|
QObject(obj.parent()), _argument(obj._argument), _label(0),
|
|
|
|
label_style(QString("QLabel { color: %1; }"))
|
|
|
|
{
|
|
|
|
if ( _argument->values != 0 )
|
|
|
|
{
|
|
|
|
ExtcapValueList elements = loadValues(QString(""));
|
|
|
|
if ( elements.length() > 0 )
|
|
|
|
values.append(elements);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 08:26:46 +00:00
|
|
|
ExtcapValueList ExtcapArgument::loadValues(QString parent)
|
|
|
|
{
|
2015-12-29 06:57:36 +00:00
|
|
|
if (_argument == 0 || _argument->values == 0 )
|
2015-04-28 08:26:46 +00:00
|
|
|
return ExtcapValueList();
|
|
|
|
|
|
|
|
GList * walker = 0;
|
|
|
|
extcap_value * v;
|
|
|
|
ExtcapValueList elements;
|
|
|
|
|
|
|
|
for (walker = g_list_first((GList *)(_argument->values)); walker != NULL ; walker = walker->next)
|
|
|
|
{
|
|
|
|
v = (extcap_value *) walker->data;
|
|
|
|
if (v == NULL || v->display == NULL || v->call == NULL )
|
|
|
|
break;
|
|
|
|
|
|
|
|
QString valParent(v->parent == 0 ? "" : QString().fromUtf8(v->parent));
|
|
|
|
|
|
|
|
if ( parent.compare(valParent) == 0 )
|
|
|
|
{
|
|
|
|
|
|
|
|
QString display = QString().fromUtf8(v->display);
|
|
|
|
QString call = QString().fromUtf8(v->call);
|
|
|
|
|
|
|
|
ExtcapValue element = ExtcapValue(display, call,
|
|
|
|
v->enabled == (gboolean)TRUE, v->is_default == (gboolean)TRUE);
|
|
|
|
|
|
|
|
element.setChildren(this->loadValues(call));
|
|
|
|
elements.append(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return elements;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExtcapArgument::~ExtcapArgument() {
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget * ExtcapArgument::createLabel(QWidget * parent)
|
|
|
|
{
|
|
|
|
if ( _argument == 0 || _argument->display == 0 )
|
|
|
|
return 0;
|
|
|
|
|
2015-12-29 14:35:43 +00:00
|
|
|
QString lblInvalidColor = ColorUtils::fromColorT(prefs.gui_text_invalid).name();
|
|
|
|
|
2015-04-28 08:26:46 +00:00
|
|
|
QString text = QString().fromUtf8(_argument->display);
|
|
|
|
|
2015-12-29 06:57:36 +00:00
|
|
|
if ( _label == 0 )
|
|
|
|
_label = new QLabel(text, parent);
|
|
|
|
else
|
|
|
|
_label->setText(text);
|
2015-12-29 14:35:43 +00:00
|
|
|
|
|
|
|
_label->setProperty("isRequired", QString(isRequired() ? "true" : "false"));
|
|
|
|
|
|
|
|
_label->setStyleSheet ( label_style.arg(QString("")) );
|
|
|
|
|
2015-04-28 08:26:46 +00:00
|
|
|
if ( _argument->tooltip != 0 )
|
2015-12-29 14:35:43 +00:00
|
|
|
_label->setToolTip(QString().fromUtf8(_argument->tooltip));
|
2015-04-28 08:26:46 +00:00
|
|
|
|
2015-12-29 06:57:36 +00:00
|
|
|
return (QWidget *)_label;
|
2015-04-28 08:26:46 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 22:13:24 +00:00
|
|
|
QWidget * ExtcapArgument::createEditor(QWidget *)
|
2015-04-28 08:26:46 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ExtcapArgument::call()
|
|
|
|
{
|
|
|
|
return QString(_argument->call);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ExtcapArgument::value()
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2015-12-29 06:57:36 +00:00
|
|
|
QString ExtcapArgument::prefValue()
|
|
|
|
{
|
|
|
|
return value();
|
|
|
|
}
|
2015-12-29 13:50:55 +00:00
|
|
|
|
2015-12-29 06:57:36 +00:00
|
|
|
void ExtcapArgument::resetValue()
|
|
|
|
{
|
2016-09-10 23:16:24 +00:00
|
|
|
// XXX consider using the preferences API which can store the default value
|
|
|
|
// and put that here instead of an empty value.
|
|
|
|
if (_argument->pref_valptr) {
|
|
|
|
g_free(*_argument->pref_valptr);
|
|
|
|
*_argument->pref_valptr = NULL;
|
|
|
|
}
|
2015-12-29 06:57:36 +00:00
|
|
|
}
|
|
|
|
|
2015-12-29 13:50:55 +00:00
|
|
|
bool ExtcapArgument::isValid()
|
|
|
|
{
|
2015-12-29 14:35:43 +00:00
|
|
|
/* Unrequired arguments are always valid, except if validity checks fail,
|
|
|
|
* which must be checked in an derived class, not here */
|
|
|
|
if ( ! isRequired() )
|
|
|
|
return true;
|
|
|
|
|
2015-12-29 13:50:55 +00:00
|
|
|
return value().length() > 0;
|
|
|
|
}
|
|
|
|
|
2015-04-28 08:26:46 +00:00
|
|
|
QString ExtcapArgument::defaultValue()
|
|
|
|
{
|
2016-01-28 09:41:38 +00:00
|
|
|
if ( _argument != 0 && _argument->default_complex != 0)
|
2015-04-28 08:26:46 +00:00
|
|
|
{
|
2016-01-28 09:41:38 +00:00
|
|
|
gchar * str = extcap_get_complex_as_string(_argument->default_complex);
|
|
|
|
if ( str != 0 )
|
|
|
|
return QString(str);
|
2015-04-28 08:26:46 +00:00
|
|
|
}
|
2016-01-28 09:41:38 +00:00
|
|
|
return QString();
|
2015-04-28 08:26:46 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 11:14:15 +00:00
|
|
|
QString ExtcapArgument::prefKey(const QString & device_name)
|
2015-12-29 06:57:36 +00:00
|
|
|
{
|
2015-12-29 06:57:36 +00:00
|
|
|
struct preference * pref = NULL;
|
|
|
|
|
|
|
|
if ( _argument == 0 || ! _argument->save )
|
2015-12-29 06:57:36 +00:00
|
|
|
return QString();
|
|
|
|
|
2015-12-29 06:57:36 +00:00
|
|
|
pref = extcap_pref_for_argument(device_name.toStdString().c_str(), _argument);
|
|
|
|
if ( pref != NULL )
|
|
|
|
return QString(pref->name);
|
|
|
|
|
|
|
|
return QString();
|
2015-12-29 06:57:36 +00:00
|
|
|
}
|
|
|
|
|
2015-12-29 13:50:55 +00:00
|
|
|
bool ExtcapArgument::isRequired()
|
|
|
|
{
|
|
|
|
if ( _argument != NULL )
|
|
|
|
return _argument->is_required;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-12-29 13:57:53 +00:00
|
|
|
bool ExtcapArgument::fileExists()
|
|
|
|
{
|
|
|
|
if ( _argument != NULL )
|
|
|
|
return _argument->fileexists;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-12-29 13:50:55 +00:00
|
|
|
bool ExtcapArgument::isDefault()
|
|
|
|
{
|
|
|
|
if ( value().compare(defaultValue()) == 0 )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-28 09:41:38 +00:00
|
|
|
ExtcapArgument * ExtcapArgument::create(extcap_arg * argument)
|
2015-04-28 08:26:46 +00:00
|
|
|
{
|
|
|
|
if ( argument == 0 || argument->display == 0 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ExtcapArgument * result = 0;
|
|
|
|
|
2016-01-18 11:01:14 +00:00
|
|
|
if ( argument->arg_type == EXTCAP_ARG_STRING || argument->arg_type == EXTCAP_ARG_PASSWORD )
|
2015-04-28 08:26:46 +00:00
|
|
|
result = new ExtArgText(argument);
|
|
|
|
else if ( argument->arg_type == EXTCAP_ARG_INTEGER || argument->arg_type == EXTCAP_ARG_LONG ||
|
|
|
|
argument->arg_type == EXTCAP_ARG_UNSIGNED || argument->arg_type == EXTCAP_ARG_DOUBLE )
|
|
|
|
result = new ExtArgNumber(argument);
|
|
|
|
else if ( argument->arg_type == EXTCAP_ARG_BOOLEAN || argument->arg_type == EXTCAP_ARG_BOOLFLAG )
|
|
|
|
result = new ExtArgBool(argument);
|
|
|
|
else if ( argument->arg_type == EXTCAP_ARG_SELECTOR )
|
|
|
|
result = new ExtArgSelector(argument);
|
|
|
|
else if ( argument->arg_type == EXTCAP_ARG_RADIO )
|
|
|
|
result = new ExtArgRadio(argument);
|
|
|
|
else if ( argument->arg_type == EXTCAP_ARG_FILESELECT )
|
|
|
|
result = new ExtcapArgumentFileSelection(argument);
|
|
|
|
else if ( argument->arg_type == EXTCAP_ARG_MULTICHECK )
|
|
|
|
result = new ExtArgMultiSelect(argument);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* For everything else, we just print the label */
|
|
|
|
result = new ExtcapArgument(argument);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-12-29 13:50:55 +00:00
|
|
|
/* The following is a necessity, because Q_Object does not do well with multiple inheritances */
|
|
|
|
void ExtcapArgument::onStringChanged(QString)
|
|
|
|
{
|
|
|
|
emit valueChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtcapArgument::onIntChanged(int)
|
|
|
|
{
|
|
|
|
if ( isValid() )
|
|
|
|
emit valueChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtcapArgument::onBoolChanged(bool)
|
|
|
|
{
|
|
|
|
emit valueChanged();
|
|
|
|
}
|
|
|
|
|
2015-04-28 08:26:46 +00:00
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|