Qt: Allow creating new files in extcap fileselect
If mustexist property is absent or set to false, allow the user to specify the filename. Add Clear button next to file selection. Previously cancelling file selection when mustexist was false would clear the entry. However, if mustexist was true, there was no easy way to clear the entry. Change-Id: I367756fb868b4040a7203f1eb8c92b6bfaf29901 Reviewed-on: https://code.wireshark.org/review/35643 Petri-Dish: Tomasz Moń <desowin@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
parent
d7bbe384f5
commit
c129c28d3a
|
@ -46,13 +46,15 @@ QWidget * ExtcapArgumentFileSelection::createEditor(QWidget * parent)
|
|||
{
|
||||
QString text = defaultValue();
|
||||
QString buttonText(UTF8_HORIZONTAL_ELLIPSIS);
|
||||
QString buttonClearText(tr("Clear"));
|
||||
|
||||
QWidget * fileWidget = new QWidget(parent);
|
||||
QHBoxLayout * editLayout = new QHBoxLayout();
|
||||
QMargins margins = editLayout->contentsMargins();
|
||||
editLayout->setContentsMargins(0, 0, 0, margins.bottom());
|
||||
fileWidget->setContentsMargins(margins.left(), margins.right(), 0, margins.bottom());
|
||||
QPushButton * button = new QPushButton(buttonText, fileWidget);
|
||||
QPushButton * buttonSelect = new QPushButton(buttonText, fileWidget);
|
||||
QPushButton * buttonClear = new QPushButton(buttonClearText, fileWidget);
|
||||
|
||||
textBox = new QLineEdit(text, parent);
|
||||
textBox->setReadOnly(true);
|
||||
|
@ -70,13 +72,15 @@ QWidget * ExtcapArgumentFileSelection::createEditor(QWidget * parent)
|
|||
if (_argument->tooltip != NULL)
|
||||
{
|
||||
textBox->setToolTip(QString().fromUtf8(_argument->tooltip));
|
||||
button->setToolTip(QString().fromUtf8(_argument->tooltip));
|
||||
buttonSelect->setToolTip(QString().fromUtf8(_argument->tooltip));
|
||||
}
|
||||
|
||||
connect(button, SIGNAL(clicked()), (QObject *)this, SLOT(openFileDialog()));
|
||||
connect(buttonSelect, SIGNAL(clicked()), (QObject *)this, SLOT(openFileDialog()));
|
||||
connect(buttonClear, SIGNAL(clicked()), (QObject *)this, SLOT(clearFilename()));
|
||||
|
||||
editLayout->addWidget(textBox);
|
||||
editLayout->addWidget(button);
|
||||
editLayout->addWidget(buttonSelect);
|
||||
editLayout->addWidget(buttonClear);
|
||||
|
||||
fileWidget->setLayout(editLayout);
|
||||
|
||||
|
@ -107,17 +111,36 @@ void ExtcapArgumentFileSelection::openFileDialog()
|
|||
fileExt.prepend(";;").prepend(givenExt);
|
||||
}
|
||||
|
||||
filename = WiresharkFileDialog::getOpenFileName((QWidget *)(textBox->parent()),
|
||||
QString().fromUtf8(_argument->display) + " " + tr("Open File"),
|
||||
workingDir.absolutePath(), fileExt);
|
||||
if (fileExists())
|
||||
{
|
||||
/* UI should check that the file exists */
|
||||
filename = WiresharkFileDialog::getOpenFileName((QWidget*)(textBox->parent()),
|
||||
QString().fromUtf8(_argument->display) + " " + tr("Open File"),
|
||||
workingDir.absolutePath(), fileExt);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* File might or might not exist. Actual overwrite handling is extcap specific
|
||||
* (e.g. boolflag argument if user wants to always overwrite the file)
|
||||
*/
|
||||
filename = WiresharkFileDialog::getSaveFileName((QWidget*)(textBox->parent()),
|
||||
QString().fromUtf8(_argument->display) + " " + tr("Select File"),
|
||||
workingDir.absolutePath(), fileExt, nullptr, QFileDialog::Option::DontConfirmOverwrite);
|
||||
}
|
||||
|
||||
if (! fileExists() || QFileInfo(filename).exists())
|
||||
if (! filename.isEmpty() && (! fileExists() || QFileInfo(filename).exists()))
|
||||
{
|
||||
textBox->setText(filename);
|
||||
emit valueChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void ExtcapArgumentFileSelection::clearFilename()
|
||||
{
|
||||
textBox->clear();
|
||||
emit valueChanged();
|
||||
}
|
||||
|
||||
bool ExtcapArgumentFileSelection::isValid()
|
||||
{
|
||||
bool valid = false;
|
||||
|
|
|
@ -37,7 +37,8 @@ protected:
|
|||
private slots:
|
||||
/* opens the file dialog */
|
||||
void openFileDialog();
|
||||
|
||||
/* clears previously entered filename */
|
||||
void clearFilename();
|
||||
};
|
||||
|
||||
#endif /* UI_QT_EXTCAP_ARGUMENT_FILE_H_ */
|
||||
|
|
Loading…
Reference in New Issue