Qt: Move generic methods to utils
Move the utils for checking for the last used directory and storing it out of ProfileDialog, as they are not Profiles specific
This commit is contained in:
parent
91c0669fb7
commit
fd7716542c
|
@ -682,6 +682,8 @@ void ProfileDialog::finishImport(QFileInfo fi, int count, int skipped, QStringLi
|
|||
if (skipped > 0)
|
||||
msg.append(tr(", %Ln profile(s) skipped", "", skipped));
|
||||
}
|
||||
QMessageBox msgBox(icon, tr("Importing profiles"), msg, QMessageBox::Ok, this);
|
||||
msgBox.exec();
|
||||
|
||||
storeLastDir(fi.absolutePath());
|
||||
|
||||
|
@ -695,50 +697,9 @@ void ProfileDialog::finishImport(QFileInfo fi, int count, int skipped, QStringLi
|
|||
pd_ui_->profileTreeView->selectRow(idx.isValid() ? idx.row() : 0);
|
||||
}
|
||||
|
||||
QMessageBox msgBox(icon, tr("Importing profiles"), msg, QMessageBox::Ok, this);
|
||||
msgBox.exec();
|
||||
|
||||
updateWidgets();
|
||||
}
|
||||
|
||||
QString ProfileDialog::lastOpenDir()
|
||||
{
|
||||
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_last_open_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;
|
||||
}
|
||||
|
||||
QDir ld(result);
|
||||
if (ld.exists())
|
||||
return result;
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
void ProfileDialog::storeLastDir(QString dir)
|
||||
{
|
||||
if (mainApp && dir.length() > 0)
|
||||
mainApp->setLastOpenDir(qUtf8Printable(dir));
|
||||
}
|
||||
|
||||
void ProfileDialog::resetTreeView()
|
||||
{
|
||||
if (model_)
|
||||
|
|
|
@ -64,8 +64,6 @@ private:
|
|||
void updateWidgets();
|
||||
void resetTreeView();
|
||||
|
||||
QString lastOpenDir();
|
||||
void storeLastDir(QString dir);
|
||||
void finishImport(QFileInfo fi, int count, int skipped, QStringList import);
|
||||
|
||||
private slots:
|
||||
|
|
|
@ -17,12 +17,16 @@
|
|||
#include <epan/range.h>
|
||||
#include <epan/to_str.h>
|
||||
#include <epan/value_string.h>
|
||||
#include <epan/prefs.h>
|
||||
|
||||
#include <ui/recent.h>
|
||||
#include <ui/last_open_dir.h>
|
||||
#include "ui/ws_ui_util.h"
|
||||
|
||||
#include <wsutil/str_util.h>
|
||||
|
||||
#include <ui/qt/main_application.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QDateTime>
|
||||
|
@ -295,3 +299,41 @@ QString make_filter_based_on_rtpstream_id(QVector<rtpstream_id_t *> stream_ids)
|
|||
return filter;
|
||||
}
|
||||
|
||||
QString lastOpenDir()
|
||||
{
|
||||
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_last_open_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;
|
||||
}
|
||||
|
||||
QDir ld(result);
|
||||
if (ld.exists())
|
||||
return result;
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
void storeLastDir(QString dir)
|
||||
{
|
||||
if (mainApp && dir.length() > 0)
|
||||
mainApp->setLastOpenDir(qUtf8Printable(dir));
|
||||
}
|
||||
|
||||
|
|
|
@ -253,6 +253,21 @@ void qvector_rtpstream_ids_free(QVector<rtpstream_id_t *> stream_ids);
|
|||
*/
|
||||
QString make_filter_based_on_rtpstream_id(QVector<rtpstream_id_t *> stream_ids);
|
||||
|
||||
/**
|
||||
* @brief Return the last directory that had been opened.
|
||||
*
|
||||
* This can be influenced by prefs.gui_fileopen_style which will allow to either
|
||||
* open the real last dir or have the user set one specifically.
|
||||
*
|
||||
* @return a reference to that directory.
|
||||
*/
|
||||
QString lastOpenDir();
|
||||
|
||||
/**
|
||||
* @brief Store the directory as last directory being used
|
||||
*/
|
||||
void storeLastDir(QString dir);
|
||||
|
||||
#endif /* __QT_UI_UTILS__H__ */
|
||||
|
||||
// XXX Add a routine to fetch the HWND corresponding to a widget using QPlatformIntegration
|
||||
|
|
Loading…
Reference in New Issue