aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Knall <rknall@gmail.com>2022-11-01 17:40:49 +0000
committerA Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2022-11-01 18:12:07 +0000
commitfd7716542c38a1b49cbc98206e61384de31440e8 (patch)
tree75b060a03c82bb6f9a405be760493fbd37cf7752
parent91c0669fb7d2dcf0910dd0e2784400044030e8dc (diff)
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
-rw-r--r--ui/qt/profile_dialog.cpp43
-rw-r--r--ui/qt/profile_dialog.h2
-rw-r--r--ui/qt/utils/qt_ui_utils.cpp42
-rw-r--r--ui/qt/utils/qt_ui_utils.h15
4 files changed, 59 insertions, 43 deletions
diff --git a/ui/qt/profile_dialog.cpp b/ui/qt/profile_dialog.cpp
index 76f6b3c779..c9aa55bcd7 100644
--- a/ui/qt/profile_dialog.cpp
+++ b/ui/qt/profile_dialog.cpp
@@ -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_)
diff --git a/ui/qt/profile_dialog.h b/ui/qt/profile_dialog.h
index 9030ec1bcc..d42594f0ff 100644
--- a/ui/qt/profile_dialog.h
+++ b/ui/qt/profile_dialog.h
@@ -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:
diff --git a/ui/qt/utils/qt_ui_utils.cpp b/ui/qt/utils/qt_ui_utils.cpp
index 1d211c2c7a..9879fcbca5 100644
--- a/ui/qt/utils/qt_ui_utils.cpp
+++ b/ui/qt/utils/qt_ui_utils.cpp
@@ -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));
+}
+
diff --git a/ui/qt/utils/qt_ui_utils.h b/ui/qt/utils/qt_ui_utils.h
index 3e98fcac0e..2fd66a8c62 100644
--- a/ui/qt/utils/qt_ui_utils.h
+++ b/ui/qt/utils/qt_ui_utils.h
@@ -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