diff --git a/ui/qt/main_welcome.cpp b/ui/qt/main_welcome.cpp index 3074f84f89..0393dbc68e 100644 --- a/ui/qt/main_welcome.cpp +++ b/ui/qt/main_welcome.cpp @@ -404,7 +404,7 @@ void MainWelcome::updateRecentFiles() { } int row = recent_files_->count(); - while (row > 0 && row > (int) prefs.gui_recent_files_count_max) { + while (row > 0 && (row > (int) prefs.gui_recent_files_count_max || row > rfRow)) { row--; delete recent_files_->item(row); } @@ -464,8 +464,8 @@ void MainWelcome::showRecentContextMenu(QPoint pos) recent_ctx_menu_->clear(); QString cf_path = li->data(Qt::UserRole).toString(); - QAction *show_action = recent_ctx_menu_->addAction(show_in_str_); + QAction *show_action = recent_ctx_menu_->addAction(show_in_str_); show_action->setData(cf_path); connect(show_action, SIGNAL(triggered(bool)), this, SLOT(showRecentFolder())); @@ -473,6 +473,12 @@ void MainWelcome::showRecentContextMenu(QPoint pos) copy_action->setData(cf_path); connect(copy_action, SIGNAL(triggered(bool)), this, SLOT(copyRecentPath())); + recent_ctx_menu_->addSeparator(); + + QAction *remove_action = recent_ctx_menu_->addAction(tr("Remove")); + remove_action->setData(cf_path); + connect(remove_action, SIGNAL(triggered(bool)), this, SLOT(removeRecentPath())); + recent_ctx_menu_->exec(recent_files_->mapToGlobal(pos)); } @@ -496,6 +502,17 @@ void MainWelcome::copyRecentPath() wsApp->clipboard()->setText(cf_path); } +void MainWelcome::removeRecentPath() +{ + QAction *ria = qobject_cast(sender()); + if (!ria) return; + + QString cf_path = ria->data().toString(); + if (cf_path.isEmpty()) return; + + wsApp->removeRecentItem(cf_path); +} + /* * Editor modelines * diff --git a/ui/qt/main_welcome.h b/ui/qt/main_welcome.h index 1c142cc1eb..40ae2f0bdd 100644 --- a/ui/qt/main_welcome.h +++ b/ui/qt/main_welcome.h @@ -88,6 +88,7 @@ private slots: void showRecentContextMenu(QPoint pos); void showRecentFolder(); void copyRecentPath(); + void removeRecentPath(); }; #endif // MAIN_WELCOME_H diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp index 13ed4d9be4..41de756f35 100644 --- a/ui/qt/wireshark_application.cpp +++ b/ui/qt/wireshark_application.cpp @@ -1052,6 +1052,33 @@ void WiresharkApplication::addRecentItem(const QString filename, qint64 size, bo itemStatusFinished(filename, size, accessible); } +void WiresharkApplication::removeRecentItem(const QString &filename) +{ + QMutableListIterator rii(recent_items_); + + while (rii.hasNext()) { + recent_item_status *ri = rii.next(); +#ifdef _WIN32 + /* Do a case insensitive compare on win32 */ + if (ri->filename.compare(filename, Qt::CaseInsensitive) == 0) { +#else + /* Do a case sensitive compare on UN*Xes. + * + * XXX - on UN*Xes such as macOS, where you can use pathconf() + * to check whether a given file system is case-sensitive or + * not, we should check whether this particular file system + * is case-sensitive and do the appropriate comparison. + */ + if (ri->filename.compare(filename) == 0) { +#endif + rii.remove(); + delete(ri); + } + } + + emit updateRecentItemStatus(NULL, 0, false); +} + static void switchTranslator(QTranslator& myTranslator, const QString& filename, const QString& searchPath) { diff --git a/ui/qt/wireshark_application.h b/ui/qt/wireshark_application.h index b2adf0a052..0d486ee3d2 100644 --- a/ui/qt/wireshark_application.h +++ b/ui/qt/wireshark_application.h @@ -98,6 +98,7 @@ public: struct _e_prefs * readConfigurationFiles(char **gdp_path, char **dp_path, bool reset); QList recentItems() const; void addRecentItem(const QString filename, qint64 size, bool accessible); + void removeRecentItem(const QString &filename); QDir lastOpenDir(); void setLastOpenDir(const char *dir_name); void setLastOpenDir(QString *dir_str);