From 11324a72578a748582196f3c0431e3a56894f5f5 Mon Sep 17 00:00:00 2001 From: Jeff Morriss Date: Mon, 21 Mar 2016 21:39:17 -0400 Subject: Push initial directory code up into CaptureFileDialog. That way each (CaptureFileDialog) user doesn't have to (remember to) check the preference, etc., to figure out what directory to start in. Change-Id: Ifa60e1ef9dbd11689a3f72906997cf3ed8ce259c Reviewed-on: https://code.wireshark.org/review/14550 Petri-Dish: Jeff Morriss Tested-by: Petri Dish Buildbot Reviewed-by: Alexis La Goutte Reviewed-by: Michael Mann --- ui/qt/capture_file_dialog.cpp | 33 +++++++++++++++++++----- ui/qt/main_window.cpp | 60 ------------------------------------------- ui/qt/main_window_slots.cpp | 20 --------------- 3 files changed, 26 insertions(+), 87 deletions(-) (limited to 'ui/qt') diff --git a/ui/qt/capture_file_dialog.cpp b/ui/qt/capture_file_dialog.cpp index 3b659557f8..55cf12648c 100644 --- a/ui/qt/capture_file_dialog.cpp +++ b/ui/qt/capture_file_dialog.cpp @@ -32,14 +32,11 @@ #include #include "file.h" -#include "../../epan/addr_resolv.h" -#include "../../epan/prefs.h" -#include "../../wsutil/filesystem.h" -#include "../../wsutil/nstime.h" +#include "epan/addr_resolv.h" +#include "wsutil/filesystem.h" +#include "wsutil/nstime.h" #include "ui/all_files_wildcard.h" -#include - #include #include #include @@ -52,6 +49,8 @@ #endif // Q_OS_WIN #include +#include "epan/prefs.h" +#include #ifdef Q_OS_WIN // All of these routines are required by file_dlg_win32.c. @@ -100,8 +99,28 @@ CaptureFileDialog::CaptureFileDialog(QWidget *parent, capture_file *cf, QString file_type_(-1) #endif { + switch (prefs.gui_fileopen_style) { + case FO_STYLE_LAST_OPENED: + /* The user has specified that we should start out in the last directory + * we looked in. If we've already opened a file, use its containing + * directory, if we could determine it, as the directory, otherwise + * use the "last opened" directory saved in the preferences file if + * there was one. + */ + setDirectory(wsApp->lastOpenDir()); + break; + + case FO_STYLE_SPECIFIED: + /* The user has specified that we should always start out in a + * specified directory; if they've specified that directory, + * start out by showing the files in that dir. + */ + if (prefs.gui_fileopen_dir[0] != '\0') + setDirectory(prefs.gui_fileopen_dir); + break; + } + #if !defined(Q_OS_WIN) - setDirectory(wsApp->lastOpenDir()); // Add extra widgets // https://wiki.qt.io/Qt_project_org_faq#How_can_I_add_widgets_to_my_QFileDialog_instance.3F setOption(QFileDialog::DontUseNativeDialog, true); diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 8789776c2c..3019748093 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -1013,26 +1013,6 @@ void MainWindow::mergeCaptureFile() char *in_filenames[2]; char *tmpname; - switch (prefs.gui_fileopen_style) { - - case FO_STYLE_LAST_OPENED: - /* The user has specified that we should start out in the last directory - we looked in. If we've already opened a file, use its containing - directory, if we could determine it, as the directory, otherwise - use the "last opened" directory saved in the preferences file if - there was one. */ - /* This is now the default behaviour in file_selection_new() */ - break; - - case FO_STYLE_SPECIFIED: - /* The user has specified that we should always start out in a - specified directory; if they've specified that directory, - start out by showing the files in that dir. */ - if (prefs.gui_fileopen_dir[0] != '\0') - merge_dlg.setDirectory(prefs.gui_fileopen_dir); - break; - } - if (merge_dlg.merge(file_name)) { gchar *err_msg; @@ -1257,26 +1237,6 @@ void MainWindow::saveAsCaptureFile(capture_file *cf, bool must_support_comments, for (;;) { CaptureFileDialog save_as_dlg(this, cf); - switch (prefs.gui_fileopen_style) { - - case FO_STYLE_LAST_OPENED: - /* The user has specified that we should start out in the last directory - we looked in. If we've already opened a file, use its containing - directory, if we could determine it, as the directory, otherwise - use the "last opened" directory saved in the preferences file if - there was one. */ - /* This is now the default behaviour in file_selection_new() */ - break; - - case FO_STYLE_SPECIFIED: - /* The user has specified that we should always start out in a - specified directory; if they've specified that directory, - start out by showing the files in that dir. */ - if (prefs.gui_fileopen_dir[0] != '\0') - save_as_dlg.setDirectory(prefs.gui_fileopen_dir); - break; - } - /* If the file has comments, does the format the user selected support them? If not, ask the user whether they want to discard the comments or choose a different format. */ @@ -1377,26 +1337,6 @@ void MainWindow::exportSelectedPackets() { for (;;) { CaptureFileDialog esp_dlg(this, capture_file_.capFile()); - switch (prefs.gui_fileopen_style) { - - case FO_STYLE_LAST_OPENED: - /* The user has specified that we should start out in the last directory - we looked in. If we've already opened a file, use its containing - directory, if we could determine it, as the directory, otherwise - use the "last opened" directory saved in the preferences file if - there was one. */ - /* This is now the default behaviour in file_selection_new() */ - break; - - case FO_STYLE_SPECIFIED: - /* The user has specified that we should always start out in a - specified directory; if they've specified that directory, - start out by showing the files in that dir. */ - if (prefs.gui_fileopen_dir[0] != '\0') - esp_dlg.setDirectory(prefs.gui_fileopen_dir); - break; - } - /* If the file has comments, does the format the user selected support them? If not, ask the user whether they want to discard the comments or choose a different format. */ diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 7bed427c2b..f535e70634 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -176,26 +176,6 @@ bool MainWindow::openCaptureFile(QString cf_path, QString read_filter, unsigned if (cf_path.isEmpty()) { CaptureFileDialog open_dlg(this, capture_file_.capFile(), read_filter); - switch (prefs.gui_fileopen_style) { - - case FO_STYLE_LAST_OPENED: - /* The user has specified that we should start out in the last directory - we looked in. If we've already opened a file, use its containing - directory, if we could determine it, as the directory, otherwise - use the "last opened" directory saved in the preferences file if - there was one. */ - /* This is now the default behaviour in file_selection_new() */ - break; - - case FO_STYLE_SPECIFIED: - /* The user has specified that we should always start out in a - specified directory; if they've specified that directory, - start out by showing the files in that dir. */ - if (prefs.gui_fileopen_dir[0] != '\0') - open_dlg.setDirectory(prefs.gui_fileopen_dir); - break; - } - if (open_dlg.open(file_name, type)) { cf_path = file_name; } else { -- cgit v1.2.3