From bf2c24a48fe54874766d450061f3a78b0927373a Mon Sep 17 00:00:00 2001 From: Adam Reichold Date: Mon, 11 Jan 2016 23:42:59 +0100 Subject: [PATCH] Limit CLUT file search by wall time instead of number of directories and files. --- rtgui/filmsimulation.cc | 46 ++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/rtgui/filmsimulation.cc b/rtgui/filmsimulation.cc index da765ef7a..d20638fd2 100644 --- a/rtgui/filmsimulation.cc +++ b/rtgui/filmsimulation.cc @@ -1,4 +1,7 @@ #include "filmsimulation.h" + +#include + #include "options.h" #include "../rtengine/clutstore.h" #include "../rtengine/safegtk.h" @@ -6,6 +9,31 @@ using namespace rtengine; using namespace rtengine::procparams; +namespace +{ + +bool confirmToContinue (const std::chrono::system_clock::time_point& startedAt, + std::chrono::system_clock::time_point& continuedAt) +{ + const auto now = std::chrono::system_clock::now (); + const auto searchingFor = std::chrono::duration_cast (now-continuedAt); + + if (searchingFor >= std::chrono::seconds (5)) { + + const auto message = Glib::ustring::compose ("Searching CLUT files for %1 seconds now...\nDo you wish to continue?", searchingFor.count ()); + + Gtk::MessageDialog dialog (message, false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO, true); + if (dialog.run () != Gtk::RESPONSE_YES) { + return false; + } + } + + continuedAt = now; + return true; +} + +} + typedef std::vector Strings; FilmSimulation::FilmSimulation() @@ -163,6 +191,9 @@ int ClutComboBox::parseDir (const Glib::ustring& path) return 0; } + const auto startedAt = std::chrono::system_clock::now (); + auto continuedAt = startedAt; + // Build menu of limited directory structure using breadth-first search using Dirs = std::vector>; Dirs dirs; @@ -171,9 +202,6 @@ int ClutComboBox::parseDir (const Glib::ustring& path) Dirs currDirs; Dirs nextDirs; - constexpr auto maxDirCount = 128, maxDirDepth = 4; - auto dirCount = 0, dirDepth = 0; - currDirs.emplace_back (path, Gtk::TreeModel::Row ()); while (!currDirs.empty ()) { @@ -200,7 +228,8 @@ int ClutComboBox::parseDir (const Glib::ustring& path) } catch (Glib::Exception&) {} dirs.push_back (std::move (dir)); - if (++dirCount > maxDirCount) { + + if (!confirmToContinue (startedAt, continuedAt)) { m_model->clear (); return 0; } @@ -208,17 +237,12 @@ int ClutComboBox::parseDir (const Glib::ustring& path) currDirs.clear (); currDirs.swap (nextDirs); - if (++dirDepth > maxDirDepth) { - m_model->clear (); - return 0; - } } } // Fill menu structure with CLUT files Strings entries; - constexpr auto maxFileCount = 4096; auto fileCount = 0; for (const auto& dir : dirs) { @@ -257,7 +281,9 @@ int ClutComboBox::parseDir (const Glib::ustring& path) newRow[m_columns.label] = name; newRow[m_columns.clutFilename] = entry; - if (++fileCount > maxFileCount) { + ++fileCount; + + if (!confirmToContinue (startedAt, continuedAt)) { m_model->clear (); return 0; }