diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2020-07-02 13:45:42 +0200 |
---|---|---|
committer | Stig Bjørlykke <stig@bjorlykke.org> | 2020-07-03 06:12:48 +0000 |
commit | daebdc4b1a1deed04a76b3d8162f021409dfe45a (patch) | |
tree | 997574fe5ff5f400f2560ddccb787c50ed775853 /ui | |
parent | a6d8a2c1181e50b3471ef4321e8ed501ab210fe5 (diff) |
Qt: Handle filenames in preference editor frame
Add support for handling PREF_SAVE_FILENAME, PREF_OPEN_FILENAME and
PREF_DIRNAME in a preference editor frame.
Change-Id: Ie9d1cc08bc79a0adefff344fd0d117405f86475c
Reviewed-on: https://code.wireshark.org/review/37669
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/qt/preference_editor_frame.cpp | 39 | ||||
-rw-r--r-- | ui/qt/preference_editor_frame.h | 1 | ||||
-rw-r--r-- | ui/qt/preference_editor_frame.ui | 7 | ||||
-rw-r--r-- | ui/qt/protocol_preferences_menu.cpp | 7 |
4 files changed, 48 insertions, 6 deletions
diff --git a/ui/qt/preference_editor_frame.cpp b/ui/qt/preference_editor_frame.cpp index 557f180069..a74c993386 100644 --- a/ui/qt/preference_editor_frame.cpp +++ b/ui/qt/preference_editor_frame.cpp @@ -22,6 +22,7 @@ #include <ui_preference_editor_frame.h> #include <ui/qt/utils/qt_ui_utils.h> +#include <ui/qt/widgets/wireshark_file_dialog.h> #include <wsutil/utf8_entities.h> #include "wireshark_application.h" @@ -29,9 +30,6 @@ #include <QPushButton> #include <QKeyEvent> -// To do: -// - Handle PREF_SAVE_FILENAME, PREF_OPEN_FILENAME and PREF_DIRNAME. - PreferenceEditorFrame::PreferenceEditorFrame(QWidget *parent) : AccordionFrame(parent), ui(new Ui::PreferenceEditorFrame), @@ -48,6 +46,8 @@ PreferenceEditorFrame::PreferenceEditorFrame(QWidget *parent) : w->setAttribute(Qt::WA_MacSmallSize, true); } #endif + + connect(ui->preferenceBrowseButton, &QPushButton::clicked, this, &PreferenceEditorFrame::browsePushButtonClicked); } PreferenceEditorFrame::~PreferenceEditorFrame() @@ -82,6 +82,7 @@ void PreferenceEditorFrame::editPreference(preference *pref, pref_module *module disconnect(ui->preferenceLineEdit, 0, 0, 0); bool show = false; + bool browse_button = false; switch (prefs_get_type(pref_)) { case PREF_UINT: @@ -90,6 +91,11 @@ void PreferenceEditorFrame::editPreference(preference *pref, pref_module *module this, SLOT(uintLineEditTextEdited(QString))); show = true; break; + case PREF_SAVE_FILENAME: + case PREF_OPEN_FILENAME: + case PREF_DIRNAME: + browse_button = true; + // Fallthrough case PREF_STRING: connect(ui->preferenceLineEdit, SIGNAL(textChanged(QString)), this, SLOT(stringLineEditTextEdited(QString))); @@ -107,6 +113,7 @@ void PreferenceEditorFrame::editPreference(preference *pref, pref_module *module if (show) { ui->preferenceLineEdit->setText(gchar_free_to_qstring(prefs_pref_to_str(pref_, pref_stashed)).remove(QRegExp("\n\t"))); + ui->preferenceBrowseButton->setHidden(!browse_button); animatedShow(); } } @@ -137,6 +144,29 @@ void PreferenceEditorFrame::stringLineEditTextEdited(const QString &new_str) new_str_ = new_str; } +void PreferenceEditorFrame::browsePushButtonClicked() +{ + QString caption = wsApp->windowTitleString(prefs_get_title(pref_)); + QString dir = prefs_get_string_value(pref_, pref_stashed); + QString filename; + + switch (prefs_get_type(pref_)) { + case PREF_SAVE_FILENAME: + filename = WiresharkFileDialog::getSaveFileName(this, caption, dir); + break; + case PREF_OPEN_FILENAME: + filename = WiresharkFileDialog::getOpenFileName(this, caption, dir); + break; + case PREF_DIRNAME: + filename = WiresharkFileDialog::getExistingDirectory(this, caption, dir); + break; + } + + if (!filename.isEmpty()) { + ui->preferenceLineEdit->setText(filename); + } +} + void PreferenceEditorFrame::rangeLineEditTextEdited(const QString &new_str) { range_t *new_range = NULL; @@ -189,6 +219,9 @@ void PreferenceEditorFrame::on_buttonBox_accepted() apply = prefs_set_uint_value(pref_, new_uint_, pref_stashed); break; case PREF_STRING: + case PREF_SAVE_FILENAME: + case PREF_OPEN_FILENAME: + case PREF_DIRNAME: apply = prefs_set_string_value(pref_, new_str_.toStdString().c_str(), pref_stashed); break; case PREF_RANGE: diff --git a/ui/qt/preference_editor_frame.h b/ui/qt/preference_editor_frame.h index 970387f202..22ce71289a 100644 --- a/ui/qt/preference_editor_frame.h +++ b/ui/qt/preference_editor_frame.h @@ -43,6 +43,7 @@ private slots: void uintLineEditTextEdited(const QString &new_str); void stringLineEditTextEdited(const QString &new_str); void rangeLineEditTextEdited(const QString &new_str); + void browsePushButtonClicked(); void on_modulePreferencesToolButton_clicked(); void on_preferenceLineEdit_returnPressed(); diff --git a/ui/qt/preference_editor_frame.ui b/ui/qt/preference_editor_frame.ui index 2def3bcd9a..6b8900e2ab 100644 --- a/ui/qt/preference_editor_frame.ui +++ b/ui/qt/preference_editor_frame.ui @@ -64,6 +64,13 @@ </widget> </item> <item> + <widget class="QPushButton" name="preferenceBrowseButton"> + <property name="text"> + <string>Browse…</string> + </property> + </widget> + </item> + <item> <spacer name="horizontalSpacer"> <property name="orientation"> <enum>Qt::Horizontal</enum> diff --git a/ui/qt/protocol_preferences_menu.cpp b/ui/qt/protocol_preferences_menu.cpp index fc4fe41431..58a908b665 100644 --- a/ui/qt/protocol_preferences_menu.cpp +++ b/ui/qt/protocol_preferences_menu.cpp @@ -27,7 +27,6 @@ // To do: // - Elide really long items? -// - Handle PREF_SAVE_FILENAME, PREF_OPEN_FILENAME and PREF_DIRNAME. // - Handle color prefs. class BoolPreferenceAction : public QAction @@ -222,6 +221,9 @@ void ProtocolPreferencesMenu::addMenuItem(preference *pref) } case PREF_UINT: case PREF_STRING: + case PREF_SAVE_FILENAME: + case PREF_OPEN_FILENAME: + case PREF_DIRNAME: case PREF_RANGE: case PREF_DECODE_AS_UINT: case PREF_DECODE_AS_RANGE: @@ -243,8 +245,7 @@ void ProtocolPreferencesMenu::addMenuItem(preference *pref) case PREF_OBSOLETE: break; default: - // A type we currently don't handle (e.g. PREF_SAVE_FILENAME). Just open - // the prefs dialog. + // A type we currently don't handle. Just open the prefs dialog. QString title = QString("%1" UTF8_HORIZONTAL_ELLIPSIS).arg(prefs_get_title(pref)); QAction *mpa = addAction(title); connect(mpa, SIGNAL(triggered(bool)), this, SLOT(modulePreferencesTriggered())); |