Limit CLUT file search by wall time instead of number of directories and files.
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
#include "filmsimulation.h"
|
#include "filmsimulation.h"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "../rtengine/clutstore.h"
|
#include "../rtengine/clutstore.h"
|
||||||
#include "../rtengine/safegtk.h"
|
#include "../rtengine/safegtk.h"
|
||||||
@@ -6,6 +9,31 @@
|
|||||||
using namespace rtengine;
|
using namespace rtengine;
|
||||||
using namespace rtengine::procparams;
|
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<std::chrono::seconds> (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<Glib::ustring> Strings;
|
typedef std::vector<Glib::ustring> Strings;
|
||||||
|
|
||||||
FilmSimulation::FilmSimulation()
|
FilmSimulation::FilmSimulation()
|
||||||
@@ -163,6 +191,9 @@ int ClutComboBox::parseDir (const Glib::ustring& path)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto startedAt = std::chrono::system_clock::now ();
|
||||||
|
auto continuedAt = startedAt;
|
||||||
|
|
||||||
// Build menu of limited directory structure using breadth-first search
|
// Build menu of limited directory structure using breadth-first search
|
||||||
using Dirs = std::vector<std::pair<Glib::ustring, Gtk::TreeModel::Row>>;
|
using Dirs = std::vector<std::pair<Glib::ustring, Gtk::TreeModel::Row>>;
|
||||||
Dirs dirs;
|
Dirs dirs;
|
||||||
@@ -171,9 +202,6 @@ int ClutComboBox::parseDir (const Glib::ustring& path)
|
|||||||
Dirs currDirs;
|
Dirs currDirs;
|
||||||
Dirs nextDirs;
|
Dirs nextDirs;
|
||||||
|
|
||||||
constexpr auto maxDirCount = 128, maxDirDepth = 4;
|
|
||||||
auto dirCount = 0, dirDepth = 0;
|
|
||||||
|
|
||||||
currDirs.emplace_back (path, Gtk::TreeModel::Row ());
|
currDirs.emplace_back (path, Gtk::TreeModel::Row ());
|
||||||
|
|
||||||
while (!currDirs.empty ()) {
|
while (!currDirs.empty ()) {
|
||||||
@@ -200,7 +228,8 @@ int ClutComboBox::parseDir (const Glib::ustring& path)
|
|||||||
} catch (Glib::Exception&) {}
|
} catch (Glib::Exception&) {}
|
||||||
|
|
||||||
dirs.push_back (std::move (dir));
|
dirs.push_back (std::move (dir));
|
||||||
if (++dirCount > maxDirCount) {
|
|
||||||
|
if (!confirmToContinue (startedAt, continuedAt)) {
|
||||||
m_model->clear ();
|
m_model->clear ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -208,17 +237,12 @@ int ClutComboBox::parseDir (const Glib::ustring& path)
|
|||||||
|
|
||||||
currDirs.clear ();
|
currDirs.clear ();
|
||||||
currDirs.swap (nextDirs);
|
currDirs.swap (nextDirs);
|
||||||
if (++dirDepth > maxDirDepth) {
|
|
||||||
m_model->clear ();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill menu structure with CLUT files
|
// Fill menu structure with CLUT files
|
||||||
Strings entries;
|
Strings entries;
|
||||||
|
|
||||||
constexpr auto maxFileCount = 4096;
|
|
||||||
auto fileCount = 0;
|
auto fileCount = 0;
|
||||||
|
|
||||||
for (const auto& dir : dirs) {
|
for (const auto& dir : dirs) {
|
||||||
@@ -257,7 +281,9 @@ int ClutComboBox::parseDir (const Glib::ustring& path)
|
|||||||
newRow[m_columns.label] = name;
|
newRow[m_columns.label] = name;
|
||||||
newRow[m_columns.clutFilename] = entry;
|
newRow[m_columns.clutFilename] = entry;
|
||||||
|
|
||||||
if (++fileCount > maxFileCount) {
|
++fileCount;
|
||||||
|
|
||||||
|
if (!confirmToContinue (startedAt, continuedAt)) {
|
||||||
m_model->clear ();
|
m_model->clear ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user