diff options
author | Tomasz Moń <desowin@gmail.com> | 2020-01-04 21:05:21 +0100 |
---|---|---|
committer | Roland Knall <rknall@gmail.com> | 2020-02-15 15:43:32 +0000 |
commit | c129c28d3af90b152b9f4b52975f9bcfecd998de (patch) | |
tree | 3a240d930af330304c9260f886018f52f1406471 | |
parent | d7bbe384f51b99b03694db811f48cf5a098ad65c (diff) |
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>
-rw-r--r-- | ui/qt/extcap_argument_file.cpp | 39 | ||||
-rw-r--r-- | ui/qt/extcap_argument_file.h | 3 |
2 files changed, 33 insertions, 9 deletions
diff --git a/ui/qt/extcap_argument_file.cpp b/ui/qt/extcap_argument_file.cpp index cc3bc6fa12..880c51fb89 100644 --- a/ui/qt/extcap_argument_file.cpp +++ b/ui/qt/extcap_argument_file.cpp @@ -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; diff --git a/ui/qt/extcap_argument_file.h b/ui/qt/extcap_argument_file.h index 8fe005e9f3..22b5e5f437 100644 --- a/ui/qt/extcap_argument_file.h +++ b/ui/qt/extcap_argument_file.h @@ -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_ */ |