metadata: fixed glitches in importing IPTC tags

(cherry picked from commit 3d03f654e22ca01f058492eab2c8fcbc564dc1b9)
This commit is contained in:
Alberto Griggio
2021-11-16 23:21:40 -08:00
committed by Lawrence Lee
parent f2248dce9d
commit 2ce81cccc5
2 changed files with 373 additions and 346 deletions

View File

@@ -198,6 +198,7 @@ void Exiv2Metadata::do_merge_xmp(Exiv2::Image *dst, bool keep_all) const
Exiv2::IptcData iptc; Exiv2::IptcData iptc;
Exiv2::copyXmpToIptc(xmp, iptc); Exiv2::copyXmpToIptc(xmp, iptc);
Exiv2::moveXmpToExif(xmp, exif); Exiv2::moveXmpToExif(xmp, exif);
std::unordered_set<std::string> seen;
if (!keep_all) { if (!keep_all) {
remove_unwanted(exif); remove_unwanted(exif);
@@ -207,10 +208,18 @@ void Exiv2Metadata::do_merge_xmp(Exiv2::Image *dst, bool keep_all) const
dst->exifData()[datum.key()] = datum; dst->exifData()[datum.key()] = datum;
} }
for (auto &datum : iptc) { for (auto &datum : iptc) {
if (seen.insert(datum.key()).second) {
dst->iptcData()[datum.key()] = datum; dst->iptcData()[datum.key()] = datum;
} else {
dst->iptcData().add(datum);
}
} }
for (auto &datum : xmp) { for (auto &datum : xmp) {
if (seen.insert(datum.key()).second) {
dst->xmpData()[datum.key()] = datum; dst->xmpData()[datum.key()] = datum;
} else {
dst->xmpData().add(datum);
}
} }
} catch (std::exception &exc) { } catch (std::exception &exc) {
if (settings->verbose) { if (settings->verbose) {

View File

@@ -455,7 +455,7 @@ IPTCPanel::IPTCPanel():
province->set_max_length(32); province->set_max_length(32);
country->set_max_length(64); country->set_max_length(64);
title->set_max_length(64); title->set_max_length(64);
dateCreated->set_max_length (8); dateCreated->set_max_length(10);
transReference->set_max_length(32); transReference->set_max_length(32);
show_all(); show_all();
@@ -518,15 +518,16 @@ void IPTCPanel::notifyListener ()
} }
} }
void IPTCPanel::addKeyWord() void IPTCPanel::addKeyWord()
{ {
keyword->get_entry()->select_region(0, keyword->get_entry()->get_text().size()); keyword->get_entry()->select_region(0, keyword->get_entry()->get_text().size());
for (unsigned int i = 0; i < keywords->size(); i++) for (unsigned int i = 0; i < keywords->size(); i++) {
if (keywords->get_text(i) == keyword->get_entry()->get_text()) { if (keywords->get_text(i) == keyword->get_entry()->get_text()) {
return; return;
} }
}
keywords->append(keyword->get_entry()->get_text()); keywords->append(keyword->get_entry()->get_text());
keyword->prepend(keyword->get_entry()->get_text()); keyword->prepend(keyword->get_entry()->get_text());
@@ -549,9 +550,9 @@ void IPTCPanel::addKeyWord ()
updateChangeList(); updateChangeList();
} }
void IPTCPanel::delKeyWord() void IPTCPanel::delKeyWord()
{ {
std::vector<int> selection = keywords->get_selected(); std::vector<int> selection = keywords->get_selected();
if (!selection.empty()) { if (!selection.empty()) {
@@ -634,14 +635,23 @@ void IPTCPanel::updateChangeList ()
(*changeList)[HEADLINE].push_back(headline->get_text()); (*changeList)[HEADLINE].push_back(headline->get_text());
(*changeList)[INSTRUCTIONS].push_back(instructions->get_text()); (*changeList)[INSTRUCTIONS].push_back(instructions->get_text());
std::set<Glib::ustring> sset;
sset.clear();
for (unsigned int i = 0; i < keywords->size(); i++) { for (unsigned int i = 0; i < keywords->size(); i++) {
(*changeList)[KEYWORDS].push_back (keywords->get_text (i)); sset.insert(keywords->get_text(i));
}
for (auto &s : sset) {
(*changeList)[KEYWORDS].push_back(s);
} }
(*changeList)[CATEGORY].push_back(category->get_entry()->get_text()); (*changeList)[CATEGORY].push_back(category->get_entry()->get_text());
sset.clear();
for (unsigned int i = 0; i < suppCategories->size(); i++) { for (unsigned int i = 0; i < suppCategories->size(); i++) {
(*changeList)[SUPPLEMENTAL_CATEGORIES].push_back (suppCategories->get_text (i)); sset.insert(suppCategories->get_text(i));
}
for (auto &s : sset) {
(*changeList)[SUPPLEMENTAL_CATEGORIES].push_back(s);
} }
(*changeList)[CREATOR].push_back(creator->get_text()); (*changeList)[CREATOR].push_back(creator->get_text());
@@ -659,9 +669,9 @@ void IPTCPanel::updateChangeList ()
notifyListener(); notifyListener();
} }
void IPTCPanel::applyChangeList() void IPTCPanel::applyChangeList()
{ {
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
conns[i].block(true); conns[i].block(true);
} }
@@ -696,17 +706,25 @@ void IPTCPanel::applyChangeList ()
headline->set_text(i->second.at(0)); headline->set_text(i->second.at(0));
} else if (i->first == INSTRUCTIONS && !i->second.empty()) { } else if (i->first == INSTRUCTIONS && !i->second.empty()) {
instructions->set_text(i->second.at(0)); instructions->set_text(i->second.at(0));
} else if (i->first == KEYWORDS) } else if (i->first == KEYWORDS) {
std::set<Glib::ustring> sset;
for (unsigned int j = 0; j < i->second.size(); j++) { for (unsigned int j = 0; j < i->second.size(); j++) {
keywords->append (i->second.at(j)); sset.insert(i->second[j]);
} }
else if (i->first == CATEGORY && !i->second.empty()) { for (auto &s : sset) {
keywords->append(s);
}
} else if (i->first == CATEGORY && !i->second.empty()) {
category->get_entry()->set_text(i->second.at(0)); category->get_entry()->set_text(i->second.at(0));
} else if (i->first == SUPPLEMENTAL_CATEGORIES) } else if (i->first == SUPPLEMENTAL_CATEGORIES) {
std::set<Glib::ustring> sset;
for (unsigned int j = 0; j < i->second.size(); j++) { for (unsigned int j = 0; j < i->second.size(); j++) {
suppCategories->append (i->second.at(j)); sset.insert(i->second[j]);
} }
else if (i->first == CREATOR && !i->second.empty()) { for (auto &s : sset) {
suppCategories->append(s);
}
} else if (i->first == CREATOR && !i->second.empty()) {
creator->set_text(i->second.at(0)); creator->set_text(i->second.at(0));
} else if (i->first == CREATOR_JOB_TITLE && !i->second.empty()) { } else if (i->first == CREATOR_JOB_TITLE && !i->second.empty()) {
creatorJobTitle->set_text(i->second.at(0)); creatorJobTitle->set_text(i->second.at(0));