Some minor cleanups

This commit is contained in:
Flössie 2017-02-14 20:49:10 +01:00
parent 6bcac40306
commit 9b5ffaf4aa
2 changed files with 51 additions and 49 deletions

View File

@ -307,10 +307,10 @@ std::shared_ptr<rtengine::HaldCLUT> rtengine::CLUTStore::getClut(const Glib::ust
{ {
std::shared_ptr<rtengine::HaldCLUT> result; std::shared_ptr<rtengine::HaldCLUT> result;
Glib::ustring full_filename = filename; const Glib::ustring full_filename =
if ( !Glib::path_is_absolute(full_filename) ) { !Glib::path_is_absolute(filename)
full_filename = Glib::build_filename(options.clutsDir, filename); ? Glib::ustring(Glib::build_filename(options.clutsDir, filename))
} : filename;
if (!cache.get(full_filename, result)) { if (!cache.get(full_filename, result)) {
std::unique_ptr<rtengine::HaldCLUT> clut(new rtengine::HaldCLUT); std::unique_ptr<rtengine::HaldCLUT> clut(new rtengine::HaldCLUT);

View File

@ -11,45 +11,45 @@ using namespace rtengine::procparams;
namespace namespace
{ {
Glib::ustring stripPrefixDir(const Glib::ustring &filename, Glib::ustring stripPrefixDir(const Glib::ustring& filename, const Glib::ustring& dir)
Glib::ustring dir)
{ {
if (!Glib::str_has_suffix(dir, G_DIR_SEPARATOR_S)) { const Glib::ustring full_dir =
dir += G_DIR_SEPARATOR_S; !Glib::str_has_suffix(dir, G_DIR_SEPARATOR_S)
} ? dir + G_DIR_SEPARATOR_S
if (Glib::str_has_prefix(filename, dir)) { : dir;
return filename.substr(dir.size()); return
} Glib::str_has_prefix(filename, full_dir)
return filename; ? filename.substr(full_dir.size())
: filename;
} }
bool notifySlowParseDir (const std::chrono::system_clock::time_point& startedAt) bool notifySlowParseDir (const std::chrono::system_clock::time_point& startedAt)
{ {
static enum enum Decision {
{ UNDECIDED,
Undecided, CANCEL,
Cancel, CONTINUE
Continue };
}
decision = Undecided;
if (decision == Cancel) { static Decision decision = UNDECIDED;
if (decision == CANCEL) {
return false; return false;
} else if (decision == Continue) { } else if (decision == CONTINUE) {
return true; return true;
} }
const auto now = std::chrono::system_clock::now (); const auto now = std::chrono::system_clock::now();
if (now - startedAt < std::chrono::seconds (10)) { if (now - startedAt < std::chrono::seconds(10)) {
return true; return true;
} }
Gtk::MessageDialog dialog (M ("TP_FILMSIMULATION_SLOWPARSEDIR"), false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO, true); Gtk::MessageDialog dialog(M("TP_FILMSIMULATION_SLOWPARSEDIR"), false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO, true);
if (dialog.run () == Gtk::RESPONSE_YES) { if (dialog.run() == Gtk::RESPONSE_YES) {
decision = Cancel; decision = CANCEL;
return false; return false;
} else { } else {
decision = Continue; decision = CONTINUE;
return true; return true;
} }
} }
@ -123,37 +123,40 @@ void FilmSimulation::read( const rtengine::procparams::ProcParams* pp, const Par
{ {
//copypasted from lensprofile.cc & sharpening.cc //copypasted from lensprofile.cc & sharpening.cc
disableListener(); disableListener();
updateDisable( true ); updateDisable(true);
setEnabled (pp->filmSimulation.enabled); setEnabled(pp->filmSimulation.enabled);
if ( !pp->filmSimulation.clutFilename.empty() ) { if (!pp->filmSimulation.clutFilename.empty()) {
Glib::ustring full_filename(pp->filmSimulation.clutFilename); m_clutComboBox->setSelectedClut(
if ( !Glib::path_is_absolute(full_filename) ) { !Glib::path_is_absolute(pp->filmSimulation.clutFilename)
full_filename = Glib::build_filename(options.clutsDir, ? Glib::ustring(Glib::build_filename(options.clutsDir, pp->filmSimulation.clutFilename))
full_filename); : pp->filmSimulation.clutFilename
} );
m_clutComboBox->setSelectedClut( full_filename );
} }
m_strength->setValue( pp->filmSimulation.strength ); m_strength->setValue(pp->filmSimulation.strength);
if (pedited) { if (pedited) {
set_inconsistent (multiImage && !pedited->filmSimulation.enabled); set_inconsistent (multiImage && !pedited->filmSimulation.enabled);
m_strength->setEditedState (pedited->filmSimulation.strength ? Edited : UnEdited); m_strength->setEditedState(
pedited->filmSimulation.strength
? Edited
: UnEdited
);
if ( !pedited->filmSimulation.clutFilename ) { if (!pedited->filmSimulation.clutFilename) {
m_clutComboBox->setSelectedClut("NULL"); m_clutComboBox->setSelectedClut("NULL");
} }
} }
if ( !get_inconsistent() && !pp->filmSimulation.enabled ) { if (!get_inconsistent() && !pp->filmSimulation.enabled) {
if (options.clutCacheSize == 1) { if (options.clutCacheSize == 1) {
CLUTStore::getInstance().clearCache(); CLUTStore::getInstance().clearCache();
} }
} }
updateDisable( false ); updateDisable(false);
enableListener(); enableListener();
} }
@ -164,18 +167,17 @@ void FilmSimulation::updateDisable( bool value )
void FilmSimulation::write( rtengine::procparams::ProcParams* pp, ParamsEdited* pedited ) void FilmSimulation::write( rtengine::procparams::ProcParams* pp, ParamsEdited* pedited )
{ {
if ( pedited ) { if (pedited) {
pedited->filmSimulation.enabled = !get_inconsistent(); pedited->filmSimulation.enabled = !get_inconsistent();
pedited->filmSimulation.strength = m_strength->getEditedState (); pedited->filmSimulation.strength = m_strength->getEditedState();
pedited->filmSimulation.clutFilename = m_clutComboBox->getSelectedClut() != "NULL"; pedited->filmSimulation.clutFilename = m_clutComboBox->getSelectedClut() != "NULL";
} }
pp->filmSimulation.enabled = getEnabled(); pp->filmSimulation.enabled = getEnabled();
Glib::ustring clutFName = m_clutComboBox->getSelectedClut(); const Glib::ustring clutFName = m_clutComboBox->getSelectedClut();
if ( clutFName != "NULL" ) { // We do not want to set "NULL" in clutFilename, even if "unedited" if (clutFName != "NULL") { // We do not want to set "NULL" in clutFilename, even if "unedited"
pp->filmSimulation.clutFilename = stripPrefixDir(clutFName, pp->filmSimulation.clutFilename = stripPrefixDir(clutFName, options.clutsDir);
options.clutsDir);
} }
pp->filmSimulation.strength = m_strength->getValue(); pp->filmSimulation.strength = m_strength->getValue();