diff --git a/rtgui/dynamicprofile.cc b/rtgui/dynamicprofile.cc index d1a5a0177..27d4f0178 100644 --- a/rtgui/dynamicprofile.cc +++ b/rtgui/dynamicprofile.cc @@ -229,19 +229,16 @@ bool storeDynamicProfileRules(const std::vector &rules) PartialProfile *loadDynamicProfile(const ImageMetaData *im) { PartialProfile *ret = new PartialProfile(true, true); - std::vector rules; - if (loadDynamicProfileRules(rules)) { - for (auto &rule : rules) { - if (rule.matches(im)) { - printf("found matching profile %s\n", - rule.profilepath.c_str()); - const PartialProfile *p = - profileStore.getProfile(rule.profilepath); - if (p != nullptr) { - p->applyTo(ret->pparams); - } else { - printf("ERROR loading matching profile\n"); - } + for (auto &rule : profileStore.getDynamicProfileRules()) { + if (rule.matches(im)) { + printf("found matching profile %s\n", + rule.profilepath.c_str()); + const PartialProfile *p = + profileStore.getProfile(rule.profilepath); + if (p != nullptr) { + p->applyTo(ret->pparams); + } else { + printf("ERROR loading matching profile\n"); } } } diff --git a/rtgui/dynamicprofilepanel.cc b/rtgui/dynamicprofilepanel.cc index 2d8ba638a..bd7665c36 100644 --- a/rtgui/dynamicprofilepanel.cc +++ b/rtgui/dynamicprofilepanel.cc @@ -308,11 +308,8 @@ DynamicProfilePanel::DynamicProfilePanel(): show_all_children(); - std::vector rules; - if (loadDynamicProfileRules(rules)) { - for (auto &r : rules) { - add_rule(r); - } + for (auto &r : profileStore.getDynamicProfileRules()) { + add_rule(r); } } @@ -514,13 +511,15 @@ void DynamicProfilePanel::on_button_edit() void DynamicProfilePanel::save() { - std::vector rules; + auto &rules = profileStore.getDynamicProfileRules(); + rules.clear(); int serial = 1; for (auto row : treemodel_->children()) { rules.emplace_back(to_rule(row, serial++)); } if (!storeDynamicProfileRules(rules)) { printf("Error in saving dynamic profile rules\n"); + rules.clear(); } else { printf("Saved %d dynamic profile rules\n", int(rules.size())); } diff --git a/rtgui/profilestore.cc b/rtgui/profilestore.cc index 31b490ce1..7eaf50b77 100644 --- a/rtgui/profilestore.cc +++ b/rtgui/profilestore.cc @@ -42,6 +42,7 @@ bool ProfileStore::init () storeState = STORESTATE_BEINGINITIALIZED; parseMutex = new MyMutex(); _parseProfiles (); + loadDynamicProfileRules(dynamicRules); storeState = STORESTATE_INITIALIZED; } diff --git a/rtgui/profilestore.h b/rtgui/profilestore.h index 5e5591e15..022652287 100644 --- a/rtgui/profilestore.h +++ b/rtgui/profilestore.h @@ -29,6 +29,7 @@ #include "threadutils.h" #include "paramsedited.h" #include "guiutils.h" +#include "dynamicprofile.h" /** @brief This will implement callback functions for the ProfileStore @@ -161,6 +162,9 @@ private: /** List of the client of this store */ std::list listeners; + /** cache for dynamic profile rules */ + std::vector dynamicRules; + /** @brief Method to recursively parse a profile folder with a level depth arbitrarily limited to 3 * * @param realPath current full path of the scanned directory ; e.g.: ~/MyProfiles/ @@ -203,7 +207,12 @@ public: { return internalDynamicEntry; } - + + std::vector &getDynamicProfileRules() + { + return dynamicRules; + } + void addListener(ProfileStoreListener *listener); void removeListener(ProfileStoreListener *listener);