Make the code that handles the file open dialog style common code.
Move it from a some dialog boxes' code to get_open_dialog_initial_dir().
This commit is contained in:
parent
46a97fe111
commit
7a82a9707c
|
@ -45,7 +45,6 @@
|
|||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "epan/prefs.h"
|
||||
#include <ui/qt/utils/qt_ui_utils.h>
|
||||
#include <main_application.h>
|
||||
|
||||
|
@ -64,27 +63,7 @@ CaptureFileDialog::CaptureFileDialog(QWidget *parent, capture_file *cf) :
|
|||
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 in which we opened a file.
|
||||
*
|
||||
* The open dialog initial directory will be that directory
|
||||
* unless we've never opened a file, in which case it will
|
||||
* be the user's personal data file directory.
|
||||
*/
|
||||
setDirectory(mainApp->openDialogInitialDir());
|
||||
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;
|
||||
}
|
||||
setDirectory(mainApp->openDialogInitialDir());
|
||||
|
||||
#if !defined(Q_OS_WIN)
|
||||
// Add extra widgets
|
||||
|
|
|
@ -366,20 +366,7 @@ void CaptureOptionsDialog::on_capturePromModeCheckBox_toggled(bool checked)
|
|||
|
||||
void CaptureOptionsDialog::browseButtonClicked()
|
||||
{
|
||||
const char *open_dir = NULL;
|
||||
|
||||
switch (prefs.gui_fileopen_style) {
|
||||
|
||||
case FO_STYLE_LAST_OPENED:
|
||||
open_dir = get_open_dialog_initial_dir();
|
||||
break;
|
||||
|
||||
case FO_STYLE_SPECIFIED:
|
||||
if (prefs.gui_fileopen_dir[0] != '\0')
|
||||
open_dir = prefs.gui_fileopen_dir;
|
||||
break;
|
||||
}
|
||||
QString file_name = WiresharkFileDialog::getSaveFileName(this, tr("Specify a Capture File"), open_dir);
|
||||
QString file_name = WiresharkFileDialog::getSaveFileName(this, tr("Specify a Capture File"), get_open_dialog_initial_dir());
|
||||
ui->filenameLineEdit->setText(file_name);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include <QPushButton>
|
||||
#endif // Q_OS_WIN
|
||||
|
||||
#include <epan/prefs.h>
|
||||
#include "main_application.h"
|
||||
|
||||
#if !defined(Q_OS_WIN)
|
||||
|
@ -58,27 +57,7 @@ ExportDissectionDialog::ExportDissectionDialog(QWidget *parent, capture_file *ca
|
|||
{
|
||||
setWindowTitle(mainApp->windowTitleString(tr("Export Packet Dissections")));
|
||||
|
||||
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(mainApp->openDialogInitialDir());
|
||||
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;
|
||||
}
|
||||
setDirectory(mainApp->openDialogInitialDir());
|
||||
|
||||
#if !defined(Q_OS_WIN)
|
||||
// Add extra widgets
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
#include "wiretap/wtap.h"
|
||||
#include "wiretap/pcap-encap.h"
|
||||
|
||||
#include <epan/prefs.h>
|
||||
|
||||
#include "ui/text_import_scanner.h"
|
||||
#include "ui/util.h"
|
||||
#include "ui/alert_box.h"
|
||||
|
@ -606,26 +604,7 @@ void ImportTextDialog::on_textFileBrowseButton_clicked()
|
|||
if (ti_ui_->textFileLineEdit->text().length() > 0) {
|
||||
open_dir = ti_ui_->textFileLineEdit->text();
|
||||
} else {
|
||||
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() */
|
||||
open_dir = get_open_dialog_initial_dir();
|
||||
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_dir = prefs.gui_fileopen_dir;
|
||||
break;
|
||||
}
|
||||
open_dir = get_open_dialog_initial_dir();
|
||||
}
|
||||
|
||||
QString file_name = WiresharkFileDialog::getOpenFileName(this, mainApp->windowTitleString(tr("Import Text File")), open_dir);
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include <epan/range.h>
|
||||
#include <epan/to_str.h>
|
||||
#include <epan/value_string.h>
|
||||
#include <epan/prefs.h>
|
||||
|
||||
#include <ui/recent.h>
|
||||
#include <ui/util.h>
|
||||
|
@ -25,8 +24,6 @@
|
|||
|
||||
#include <wsutil/str_util.h>
|
||||
|
||||
#include <ui/qt/main_application.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QDateTime>
|
||||
|
@ -310,27 +307,7 @@ QString openDialogInitialDir()
|
|||
{
|
||||
QString result;
|
||||
|
||||
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() */
|
||||
result = QString(get_open_dialog_initial_dir());
|
||||
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')
|
||||
result = QString(prefs.gui_fileopen_dir);
|
||||
break;
|
||||
}
|
||||
|
||||
result = QString(get_open_dialog_initial_dir());
|
||||
QDir ld(result);
|
||||
if (ld.exists())
|
||||
return result;
|
||||
|
|
42
ui/util.c
42
ui/util.c
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "epan/address.h"
|
||||
#include "epan/addr_resolv.h"
|
||||
#include "epan/prefs.h"
|
||||
#include "epan/strutil.h"
|
||||
|
||||
#include <wsutil/filesystem.h>
|
||||
|
@ -377,14 +378,37 @@ const char *
|
|||
get_open_dialog_initial_dir(void)
|
||||
{
|
||||
const char *initial_dir;
|
||||
/*
|
||||
* If we have a "last directory in which a file was opened", use
|
||||
* that.
|
||||
*
|
||||
* If not, use the user's personal data file directory.
|
||||
*/
|
||||
initial_dir = get_last_open_dir();
|
||||
if (initial_dir == NULL)
|
||||
initial_dir = get_persdatafile_dir();
|
||||
|
||||
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 have a "last directory in which a file was opened", use that.
|
||||
|
||||
If not, use the user's personal data file directory. */
|
||||
/* This is now the default behaviour in file_selection_new() */
|
||||
initial_dir = get_last_open_dir();
|
||||
if (initial_dir == NULL)
|
||||
initial_dir = get_persdatafile_dir();
|
||||
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, otherwise use
|
||||
the user's personal data file directory. */
|
||||
if (prefs.gui_fileopen_dir[0] != '\0')
|
||||
initial_dir = prefs.gui_fileopen_dir;
|
||||
else
|
||||
initial_dir = get_persdatafile_dir();
|
||||
break;
|
||||
|
||||
default:
|
||||
ws_assert_not_reached();
|
||||
initial_dir = NULL;
|
||||
break;
|
||||
}
|
||||
return initial_dir;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue