aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorJohn Thacker <johnthacker@gmail.com>2023-11-14 23:05:40 -0500
committerAndersBroman <a.broman58@gmail.com>2023-11-15 08:57:36 +0000
commitbee7b2cb8e4d61681617e274d2c1ac7d0bbc6f6f (patch)
tree9c3cf76d5a67d8fa4db0fac1f3f2f773dbe8ec78 /ui
parent8988d21d265effc3c014bce496406d780bb253c8 (diff)
Qt: Fix Recent Files Max Count at startup
The recent files are read from recent_common in main.cpp, which happens before the prefs are read. (This is largely unavoidable, as we need some things in recent first, notably the last used preference Configuration Profile.) That means we add the recent files before we've read the preference that determines the maximum number of recent files, so it still has its initial value of 10 - the number of files in recent_common will be whatever value the last used Configuration Profile had for the preference, and could be greater (or lesser) than 10. It could also be different than the value for the preference after the preferences are loaded, if Wireshark is started with command line options like -C, -o, or -P. Add a parameter so that on initial startup, when recent_common is read, we add all the files to the list heedless of the pref value. Add connections so that the Menu and the Welcome Page list update the list of recent files whenever the Preferences are changed (including from changing Configuration Profiles), because that might change the max number of recent files. Add a few guards for putting too many items in the recent common file or the menu, for when the preference changes so that the maximum count is lower than it was previously. Fix #16782
Diffstat (limited to 'ui')
-rw-r--r--ui/logray/logray_main_window.cpp5
-rw-r--r--ui/logray/logray_main_window_slots.cpp9
-rw-r--r--ui/qt/main_application.cpp17
-rw-r--r--ui/qt/welcome_page.cpp1
-rw-r--r--ui/qt/wireshark_main_window.cpp5
-rw-r--r--ui/qt/wireshark_main_window_slots.cpp9
-rw-r--r--ui/recent.c2
-rw-r--r--ui/recent_utils.h13
8 files changed, 44 insertions, 17 deletions
diff --git a/ui/logray/logray_main_window.cpp b/ui/logray/logray_main_window.cpp
index 7cadc58d0a..d24f95baad 100644
--- a/ui/logray/logray_main_window.cpp
+++ b/ui/logray/logray_main_window.cpp
@@ -395,6 +395,7 @@ LograyMainWindow::LograyMainWindow(QWidget *parent) :
connect(mainApp, SIGNAL(preferencesChanged()), this, SLOT(updateTitlebar()));
connect(mainApp, SIGNAL(updateRecentCaptureStatus(const QString &, qint64, bool)), this, SLOT(updateRecentCaptures()));
+ connect(mainApp, SIGNAL(preferencesChanged()), this, SLOT(updateRecentCaptures()));
updateRecentCaptures();
#if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN)
@@ -1500,7 +1501,7 @@ bool LograyMainWindow::saveAsCaptureFile(capture_file *cf, bool must_support_com
cf->unsaved_changes = false; //we just saved so we signal that we have no unsaved changes
updateForUnsavedChanges(); // we update the title bar to remove the *
/* Add this filename to the list of recent files in the "Recent Files" submenu */
- add_menu_recent_capture_file(qUtf8Printable(file_name));
+ add_menu_recent_capture_file(qUtf8Printable(file_name), false);
return true;
case CF_WRITE_ERROR:
@@ -1642,7 +1643,7 @@ void LograyMainWindow::exportSelectedPackets() {
if (discard_comments)
packet_list_->redrawVisiblePackets();
/* Add this filename to the list of recent files in the "Recent Files" submenu */
- add_menu_recent_capture_file(qUtf8Printable(file_name));
+ add_menu_recent_capture_file(qUtf8Printable(file_name), false);
goto cleanup;
case CF_WRITE_ERROR:
diff --git a/ui/logray/logray_main_window_slots.cpp b/ui/logray/logray_main_window_slots.cpp
index 143284ce3c..812f78720a 100644
--- a/ui/logray/logray_main_window_slots.cpp
+++ b/ui/logray/logray_main_window_slots.cpp
@@ -737,7 +737,7 @@ void LograyMainWindow::captureFileReadStarted(const QString &action) {
void LograyMainWindow::captureFileReadFinished() {
if (!capture_file_.capFile()->is_tempfile && capture_file_.capFile()->filename) {
/* Add this filename to the list of recent files in the "Recent Files" submenu */
- add_menu_recent_capture_file(capture_file_.capFile()->filename);
+ add_menu_recent_capture_file(capture_file_.capFile()->filename, false);
/* Remember folder for next Open dialog and save it in recent */
mainApp->setLastOpenDirFromFilename(capture_file_.capFile()->filename);
@@ -1024,6 +1024,13 @@ void LograyMainWindow::updateRecentCaptures() {
dock_menu_->insertAction(NULL, rda);
connect(rda, SIGNAL(triggered()), ra, SLOT(trigger()));
#endif
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+ if (recentMenu->actions().count() == static_cast<int>(prefs.gui_recent_files_count_max)) {
+#else
+ if (recentMenu->actions().count() == static_cast<qsizetype>(prefs.gui_recent_files_count_max)) {
+#endif
+ break;
+ }
}
if (recentMenu->actions().count() > 0) {
diff --git a/ui/qt/main_application.cpp b/ui/qt/main_application.cpp
index 265d5eb95f..ffd30f1e6b 100644
--- a/ui/qt/main_application.cpp
+++ b/ui/qt/main_application.cpp
@@ -162,7 +162,7 @@ topic_action(topic_action_e action)
* https://stackoverflow.com/questions/437212/how-do-you-register-a-most-recently-used-list-with-windows-in-preparation-for-win
*/
extern "C" void
-add_menu_recent_capture_file(const gchar *cf_name) {
+add_menu_recent_capture_file(const gchar *cf_name, bool force) {
QString normalized_cf_name = QString::fromUtf8(cf_name);
QDir cf_path;
@@ -197,7 +197,7 @@ add_menu_recent_capture_file(const gchar *cf_name) {
*/
ri->filename.compare(normalized_cf_name) == 0 ||
#endif
- cnt >= prefs.gui_recent_files_count_max) {
+ (!force && cnt >= prefs.gui_recent_files_count_max)) {
rii.remove();
delete(ri);
cnt--;
@@ -213,12 +213,15 @@ extern "C" void menu_recent_file_write_all(FILE *rf) {
/* we have to iterate backwards through the children's list,
* so we get the latest item last in the file.
*/
- QListIterator<recent_item_status *> rii(recent_captures_);
- rii.toBack();
- while (rii.hasPrevious()) {
- QString cf_name;
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+ int i = qMin(recent_captures_.size(), (int)(prefs.gui_recent_files_count_max)) - 1;
+#else
+ qsizetype i = qMin(recent_captures_.size(), (qsizetype)prefs.gui_recent_files_count_max) - 1;
+#endif
+ for (; i >= 0; i--) {
+ recent_item_status *ri = recent_captures_.at(i);
/* get capture filename from the menu item label */
- cf_name = rii.previous()->filename;
+ QString cf_name = ri->filename;
if (!cf_name.isNull()) {
fprintf (rf, RECENT_KEY_CAPTURE_FILE ": %s\n", qUtf8Printable(cf_name));
}
diff --git a/ui/qt/welcome_page.cpp b/ui/qt/welcome_page.cpp
index ac37a6d930..4572366fa3 100644
--- a/ui/qt/welcome_page.cpp
+++ b/ui/qt/welcome_page.cpp
@@ -76,6 +76,7 @@ WelcomePage::WelcomePage(QWidget *parent) :
this, SLOT(showRecentContextMenu(QPoint)));
connect(mainApp, SIGNAL(updateRecentCaptureStatus(const QString &, qint64, bool)), this, SLOT(updateRecentCaptures()));
+ connect(mainApp, SIGNAL(preferencesChanged()), this, SLOT(updateRecentCaptures()));
connect(mainApp, SIGNAL(appInitialized()), this, SLOT(appInitialized()));
connect(mainApp, SIGNAL(localInterfaceListChanged()), this, SLOT(interfaceListChanged()));
connect(welcome_ui_->interfaceFrame, SIGNAL(itemSelectionChanged()),
diff --git a/ui/qt/wireshark_main_window.cpp b/ui/qt/wireshark_main_window.cpp
index 64d3574bf1..83cb7e9e2d 100644
--- a/ui/qt/wireshark_main_window.cpp
+++ b/ui/qt/wireshark_main_window.cpp
@@ -419,6 +419,7 @@ WiresharkMainWindow::WiresharkMainWindow(QWidget *parent) :
connect(mainApp, SIGNAL(preferencesChanged()), this, SLOT(updateTitlebar()));
connect(mainApp, SIGNAL(updateRecentCaptureStatus(const QString &, qint64, bool)), this, SLOT(updateRecentCaptures()));
+ connect(mainApp, SIGNAL(preferencesChanged()), this, SLOT(updateRecentCaptures()));
updateRecentCaptures();
#if defined(HAVE_SOFTWARE_UPDATE) && defined(Q_OS_WIN)
@@ -1562,7 +1563,7 @@ bool WiresharkMainWindow::saveAsCaptureFile(capture_file *cf, bool must_support_
cf->unsaved_changes = false; //we just saved so we signal that we have no unsaved changes
updateForUnsavedChanges(); // we update the title bar to remove the *
/* Add this filename to the list of recent files in the "Recent Files" submenu */
- add_menu_recent_capture_file(qUtf8Printable(file_name));
+ add_menu_recent_capture_file(qUtf8Printable(file_name), false);
return true;
case CF_WRITE_ERROR:
@@ -1704,7 +1705,7 @@ void WiresharkMainWindow::exportSelectedPackets() {
if (discard_comments)
packet_list_->redrawVisiblePackets();
/* Add this filename to the list of recent files in the "Recent Files" submenu */
- add_menu_recent_capture_file(qUtf8Printable(file_name));
+ add_menu_recent_capture_file(qUtf8Printable(file_name), false);
goto cleanup;
case CF_WRITE_ERROR:
diff --git a/ui/qt/wireshark_main_window_slots.cpp b/ui/qt/wireshark_main_window_slots.cpp
index a81b1740b9..5a8458ce95 100644
--- a/ui/qt/wireshark_main_window_slots.cpp
+++ b/ui/qt/wireshark_main_window_slots.cpp
@@ -772,7 +772,7 @@ void WiresharkMainWindow::captureFileReadStarted(const QString &action) {
void WiresharkMainWindow::captureFileReadFinished() {
if (!capture_file_.capFile()->is_tempfile && capture_file_.capFile()->filename) {
/* Add this filename to the list of recent files in the "Recent Files" submenu */
- add_menu_recent_capture_file(capture_file_.capFile()->filename);
+ add_menu_recent_capture_file(capture_file_.capFile()->filename, false);
/* Remember folder for next Open dialog and save it in recent */
mainApp->setLastOpenDirFromFilename(capture_file_.capFile()->filename);
@@ -1087,6 +1087,13 @@ void WiresharkMainWindow::updateRecentCaptures() {
dock_menu_->insertAction(NULL, rda);
connect(rda, SIGNAL(triggered()), ra, SLOT(trigger()));
#endif
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+ if (recentMenu->actions().count() == static_cast<int>(prefs.gui_recent_files_count_max)) {
+#else
+ if (recentMenu->actions().count() == static_cast<qsizetype>(prefs.gui_recent_files_count_max)) {
+#endif
+ break;
+ }
}
if (recentMenu->actions().count() > 0) {
diff --git a/ui/recent.c b/ui/recent.c
index 116de9967e..d65ff8d59c 100644
--- a/ui/recent.c
+++ b/ui/recent.c
@@ -1358,7 +1358,7 @@ read_set_recent_pair_dynamic(gchar *key, const gchar *value,
return PREFS_SET_SYNTAX_ERR;
}
if (strcmp(key, RECENT_KEY_CAPTURE_FILE) == 0) {
- add_menu_recent_capture_file(value);
+ add_menu_recent_capture_file(value, true);
} else if (strcmp(key, RECENT_KEY_DISPLAY_FILTER) == 0) {
dfilter_combo_add_recent(value);
} else if (strcmp(key, RECENT_KEY_CAPTURE_FILTER) == 0) {
diff --git a/ui/recent_utils.h b/ui/recent_utils.h
index 711f80d1f1..466555e073 100644
--- a/ui/recent_utils.h
+++ b/ui/recent_utils.h
@@ -17,9 +17,16 @@
extern "C" {
#endif /* __cplusplus */
-/* Add a new recent capture filename to the "Recent Files" submenu
- (duplicates will be ignored) */
-extern void add_menu_recent_capture_file(const gchar *cf_name);
+/** Add a new recent capture filename to the "Recent Files" submenu
+ * (duplicates will be ignored)
+ *
+ * @param cf_name Capture filename to add
+ * @param force If true, then prefs.gui_recent_file_count_max will be
+ * ignored when adding the file. This is for startup, when the recent_common
+ * file is read before the prefs file. (It will be corrected later when
+ * prefs are read.)
+ */
+extern void add_menu_recent_capture_file(const gchar *cf_name, bool force);
/** Write all recent capture filenames to the user's recent file.
* @param rf recent file