summaryrefslogtreecommitdiff
path: root/ui/qt/module_preferences_scroll_area.cpp
diff options
context:
space:
mode:
authorAhmad Fatoum <ahmad@a3f.at>2017-04-14 11:33:57 +0200
committerPeter Wu <peter@lekensteyn.nl>2017-04-17 10:51:10 +0000
commitb478df61f54f08e0279d83e2cc11313fbdf28758 (patch)
tree99585c43e985315c471038eb5a95e3368e9e4a73 /ui/qt/module_preferences_scroll_area.cpp
parentf63ad23ef9036a60e78e5efd45936aae1705d5ac (diff)
downloadwireshark-b478df61f54f08e0279d83e2cc11313fbdf28758.tar.gz
Qt: Provide both file save and open preferences
This is a breaking change. prefs_register_filename_preference hasn't been differentiating between files to be saved and ones to be opened. On GTK, a neutral dialog is used, so no problems there. On Qt, a save dialog has been always used, even in dissectors that were reading configuration files without modification. prefs_register_filename_preference now takes an argument to indicate whether UI could be a save dialog with a warning on overwriting a file, or whether it's a general purpose open file dialog. Qt now does this. Previously no warning was shown on overwriting a file, so it may be used for opening files too without irritating the user. This has been changed, as non-destructive reads should now use the open dialog. Dissectors were changed accordingly. Change-Id: I9087fefa5ee7ca58de0775d4fe2c0fdcfa3a3018 Reviewed-on: https://code.wireshark.org/review/21086 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'ui/qt/module_preferences_scroll_area.cpp')
-rw-r--r--ui/qt/module_preferences_scroll_area.cpp34
1 files changed, 27 insertions, 7 deletions
diff --git a/ui/qt/module_preferences_scroll_area.cpp b/ui/qt/module_preferences_scroll_area.cpp
index e4829c928c..0ff2589f0a 100644
--- a/ui/qt/module_preferences_scroll_area.cpp
+++ b/ui/qt/module_preferences_scroll_area.cpp
@@ -189,7 +189,8 @@ pref_show(pref_t *pref, gpointer layout_ptr)
vb->addLayout(hb);
break;
}
- case PREF_FILENAME:
+ case PREF_SAVE_FILENAME:
+ case PREF_OPEN_FILENAME:
case PREF_DIRNAME:
{
QLabel *label = new QLabel(prefs_get_title(pref));
@@ -260,7 +261,8 @@ ModulePreferencesScrollArea::ModulePreferencesScrollArea(module_t *module, QWidg
connect(le, SIGNAL(textEdited(QString)), this, SLOT(uintLineEditTextEdited(QString)));
break;
case PREF_STRING:
- case PREF_FILENAME:
+ case PREF_SAVE_FILENAME:
+ case PREF_OPEN_FILENAME:
case PREF_DIRNAME:
connect(le, SIGNAL(textEdited(QString)), this, SLOT(stringLineEditTextEdited(QString)));
break;
@@ -308,8 +310,11 @@ ModulePreferencesScrollArea::ModulePreferencesScrollArea(module_t *module, QWidg
case PREF_UAT:
connect(pb, SIGNAL(pressed()), this, SLOT(uatPushButtonPressed()));
break;
- case PREF_FILENAME:
- connect(pb, SIGNAL(pressed()), this, SLOT(filenamePushButtonPressed()));
+ case PREF_SAVE_FILENAME:
+ connect(pb, SIGNAL(pressed()), this, SLOT(saveFilenamePushButtonPressed()));
+ break;
+ case PREF_OPEN_FILENAME:
+ connect(pb, SIGNAL(pressed()), this, SLOT(openFilenamePushButtonPressed()));
break;
case PREF_DIRNAME:
connect(pb, SIGNAL(pressed()), this, SLOT(dirnamePushButtonPressed()));
@@ -483,7 +488,7 @@ void ModulePreferencesScrollArea::uatPushButtonPressed()
uat_dlg.exec();
}
-void ModulePreferencesScrollArea::filenamePushButtonPressed()
+void ModulePreferencesScrollArea::saveFilenamePushButtonPressed()
{
QPushButton *filename_pb = qobject_cast<QPushButton*>(sender());
if (!filename_pb) return;
@@ -492,9 +497,24 @@ void ModulePreferencesScrollArea::filenamePushButtonPressed()
if (!pref) return;
QString filename = QFileDialog::getSaveFileName(this, wsApp->windowTitleString(prefs_get_title(pref)),
- prefs_get_string_value(pref, pref_stashed), QString(), NULL,
- QFileDialog::DontConfirmOverwrite);
+ prefs_get_string_value(pref, pref_stashed));
+
+ if (!filename.isEmpty()) {
+ prefs_set_string_value(pref, QDir::toNativeSeparators(filename).toStdString().c_str(), pref_stashed);
+ updateWidgets();
+ }
+}
+
+void ModulePreferencesScrollArea::openFilenamePushButtonPressed()
+{
+ QPushButton *filename_pb = qobject_cast<QPushButton*>(sender());
+ if (!filename_pb) return;
+
+ pref_t *pref = VariantPointer<pref_t>::asPtr(filename_pb->property(pref_prop_));
+ if (!pref) return;
+ QString filename = QFileDialog::getOpenFileName(this, wsApp->windowTitleString(prefs_get_title(pref)),
+ prefs_get_string_value(pref, pref_stashed));
if (!filename.isEmpty()) {
prefs_set_string_value(pref, QDir::toNativeSeparators(filename).toStdString().c_str(), pref_stashed);
updateWidgets();