KExiv2

kexiv2iptc.cpp
Go to the documentation of this file.
1 
28 // Local includes
29 
30 #include "kexiv2.h"
31 #include "kexiv2_p.h"
32 #include "libkexiv2_debug.h"
33 
34 namespace KExiv2Iface
35 {
36 
37 bool KExiv2::canWriteIptc(const QString& filePath)
38 {
39  try
40  {
41  Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open((const char*)
42  (QFile::encodeName(filePath).constData()));
43 
44  Exiv2::AccessMode mode = image->checkMode(Exiv2::mdIptc);
45  return (mode == Exiv2::amWrite || mode == Exiv2::amReadWrite);
46  }
47  catch(Exiv2::Error& e)
48  {
49  std::string s(e.what());
50  qCCritical(LIBKEXIV2_LOG) << "Cannot check Iptc access mode using Exiv2 (Error #"
51  << e.code() << ": " << s.c_str() << ")";
52  }
53  catch(...)
54  {
55  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
56  }
57 
58  return false;
59 }
60 
61 bool KExiv2::hasIptc() const
62 {
63  return !d->iptcMetadata().empty();
64 }
65 
66 bool KExiv2::clearIptc() const
67 {
68  try
69  {
70  d->iptcMetadata().clear();
71  return true;
72  }
73  catch(Exiv2::Error& e)
74  {
75  d->printExiv2ExceptionError(QString::fromLatin1("Cannot clear Iptc data using Exiv2 "), e);
76  }
77  catch(...)
78  {
79  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
80  }
81 
82  return false;
83 }
84 
85 QByteArray KExiv2::getIptc(bool addIrbHeader) const
86 {
87  try
88  {
89  if (!d->iptcMetadata().empty())
90  {
91  Exiv2::IptcData& iptc = d->iptcMetadata();
92  Exiv2::DataBuf c2;
93 
94  if (addIrbHeader)
95  {
96  c2 = Exiv2::Photoshop::setIptcIrb(nullptr, 0, iptc);
97  }
98  else
99  {
100  c2 = Exiv2::IptcParser::encode(d->iptcMetadata());
101  }
102 
103  QByteArray data((const char*)c2.pData_, c2.size_);
104  return data;
105 
106  }
107  }
108  catch(Exiv2::Error& e)
109  {
110  if (!d->filePath.isEmpty())
111  {
112  qCCritical(LIBKEXIV2_LOG) << "From file " << d->filePath.toLatin1().constData();
113  }
114 
115  d->printExiv2ExceptionError(QString::fromLatin1("Cannot get Iptc data using Exiv2 "), e);
116  }
117  catch(...)
118  {
119  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
120  }
121 
122  return QByteArray();
123 }
124 
125 bool KExiv2::setIptc(const QByteArray& data) const
126 {
127  try
128  {
129  if (!data.isEmpty())
130  {
131  Exiv2::IptcParser::decode(d->iptcMetadata(), (const Exiv2::byte*)data.data(), data.size());
132  return (!d->iptcMetadata().empty());
133  }
134  }
135  catch(Exiv2::Error& e)
136  {
137  if (!d->filePath.isEmpty())
138  {
139  qCCritical(LIBKEXIV2_LOG) << "From file " << d->filePath.toLatin1().constData();
140  }
141 
142  d->printExiv2ExceptionError(QString::fromLatin1("Cannot set Iptc data using Exiv2 "), e);
143  }
144  catch(...)
145  {
146  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
147  }
148 
149  return false;
150 }
151 
152 KExiv2::MetaDataMap KExiv2::getIptcTagsDataList(const QStringList& iptcKeysFilter, bool invertSelection) const
153 {
154  if (d->iptcMetadata().empty())
155  return MetaDataMap();
156 
157  try
158  {
159  Exiv2::IptcData iptcData = d->iptcMetadata();
160  iptcData.sortByKey();
161 
162  QString ifDItemName;
163  MetaDataMap metaDataMap;
164 
165  for (Exiv2::IptcData::iterator md = iptcData.begin(); md != iptcData.end(); ++md)
166  {
167  QString key = QString::fromLocal8Bit(md->key().c_str());
168 
169  // Decode the tag value with a user friendly output.
170  std::ostringstream os;
171  os << *md;
172 
173  QString value;
174 
175  if (key == QString::fromLatin1("Iptc.Envelope.CharacterSet"))
176  {
177  value = QString::fromLatin1(iptcData.detectCharset());
178  }
179  else
180  {
181  value = QString::fromUtf8(os.str().c_str());
182  }
183 
184  // To make a string just on one line.
186 
187  // Some Iptc key are redondancy. check if already one exist...
188  MetaDataMap::iterator it = metaDataMap.find(key);
189 
190  // We apply a filter to get only the Iptc tags that we need.
191 
192  if (!iptcKeysFilter.isEmpty())
193  {
194  if (!invertSelection)
195  {
196  if (iptcKeysFilter.contains(key.section(QString::fromLatin1("."), 1, 1)))
197  {
198  if (it == metaDataMap.end())
199  {
200  metaDataMap.insert(key, value);
201  }
202  else
203  {
204  QString v = *it;
205  v.append(QString::fromLatin1(", "));
206  v.append(value);
207  metaDataMap.insert(key, v);
208  }
209  }
210  }
211  else
212  {
213  if (!iptcKeysFilter.contains(key.section(QString::fromLatin1("."), 1, 1)))
214  {
215  if (it == metaDataMap.end())
216  {
217  metaDataMap.insert(key, value);
218  }
219  else
220  {
221  QString v = *it;
222  v.append(QString::fromLatin1(", "));
223  v.append(value);
224  metaDataMap.insert(key, v);
225  }
226  }
227  }
228  }
229  else // else no filter at all.
230  {
231  if (it == metaDataMap.end())
232  {
233  metaDataMap.insert(key, value);
234  }
235  else
236  {
237  QString v = *it;
238  v.append(QString::fromLatin1(", "));
239  v.append(value);
240  metaDataMap.insert(key, v);
241  }
242  }
243 
244  }
245 
246  return metaDataMap;
247  }
248  catch (Exiv2::Error& e)
249  {
250  d->printExiv2ExceptionError(QString::fromLatin1("Cannot parse Iptc metadata using Exiv2 "), e);
251  }
252  catch(...)
253  {
254  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
255  }
256 
257  return MetaDataMap();
258 }
259 
260 QString KExiv2::getIptcTagTitle(const char* iptcTagName)
261 {
262  try
263  {
264  std::string iptckey(iptcTagName);
265  Exiv2::IptcKey ik(iptckey);
266  return QString::fromLocal8Bit( Exiv2::IptcDataSets::dataSetTitle(ik.tag(), ik.record()) );
267  }
268  catch (Exiv2::Error& e)
269  {
270  d->printExiv2ExceptionError(QString::fromLatin1("Cannot get metadata tag title using Exiv2 "), e);
271  }
272  catch(...)
273  {
274  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
275  }
276 
277  return QString();
278 }
279 
280 QString KExiv2::getIptcTagDescription(const char* iptcTagName)
281 {
282  try
283  {
284  std::string iptckey(iptcTagName);
285  Exiv2::IptcKey ik(iptckey);
286  return QString::fromLocal8Bit( Exiv2::IptcDataSets::dataSetDesc(ik.tag(), ik.record()) );
287  }
288  catch (Exiv2::Error& e)
289  {
290  d->printExiv2ExceptionError(QString::fromLatin1("Cannot get metadata tag description using Exiv2 "), e);
291  }
292  catch(...)
293  {
294  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
295  }
296 
297  return QString();
298 }
299 
300 bool KExiv2::removeIptcTag(const char* iptcTagName, bool setProgramName) const
301 {
302  if (!setProgramId(setProgramName))
303  return false;
304 
305  try
306  {
307  Exiv2::IptcData::iterator it = d->iptcMetadata().begin();
308  int i = 0;
309 
310  while(it != d->iptcMetadata().end())
311  {
312  QString key = QString::fromLocal8Bit(it->key().c_str());
313 
314  if (key == QString::fromLatin1(iptcTagName))
315  {
316  it = d->iptcMetadata().erase(it);
317  ++i;
318  }
319  else
320  {
321  ++it;
322  }
323  };
324 
325  if (i > 0)
326  return true;
327  }
328  catch(Exiv2::Error& e)
329  {
330  d->printExiv2ExceptionError(QString::fromLatin1("Cannot remove Iptc tag using Exiv2 "), e);
331  }
332  catch(...)
333  {
334  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
335  }
336 
337  return false;
338 }
339 
340 bool KExiv2::setIptcTagData(const char* iptcTagName, const QByteArray& data, bool setProgramName) const
341 {
342  if (data.isEmpty())
343  return false;
344 
345  if (!setProgramId(setProgramName))
346  return false;
347 
348  try
349  {
350  Exiv2::DataValue val((Exiv2::byte *)data.data(), data.size());
351  d->iptcMetadata()[iptcTagName] = val;
352  return true;
353  }
354  catch(Exiv2::Error& e)
355  {
356  d->printExiv2ExceptionError(QString::fromLatin1("Cannot set Iptc tag data into image using Exiv2 "), e);
357  }
358  catch(...)
359  {
360  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
361  }
362 
363  return false;
364 }
365 
366 QByteArray KExiv2::getIptcTagData(const char* iptcTagName) const
367 {
368  try
369  {
370  Exiv2::IptcKey iptcKey(iptcTagName);
371  Exiv2::IptcData iptcData(d->iptcMetadata());
372  Exiv2::IptcData::iterator it = iptcData.findKey(iptcKey);
373 
374  if (it != iptcData.end())
375  {
376  char* const s = new char[(*it).size()];
377  (*it).copy((Exiv2::byte*)s, Exiv2::bigEndian);
378  QByteArray data(s, (*it).size());
379  delete [] s;
380  return data;
381  }
382  }
383  catch(Exiv2::Error& e)
384  {
385  d->printExiv2ExceptionError(QString::fromLatin1("Cannot find Iptc key '%1' into image using Exiv2 ").arg(QString::fromLatin1(iptcTagName)), e);
386  }
387  catch(...)
388  {
389  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
390  }
391 
392  return QByteArray();
393 }
394 
395 QString KExiv2::getIptcTagString(const char* iptcTagName, bool escapeCR) const
396 {
397  try
398  {
399  Exiv2::IptcKey iptcKey(iptcTagName);
400  Exiv2::IptcData iptcData(d->iptcMetadata());
401  Exiv2::IptcData::iterator it = iptcData.findKey(iptcKey);
402 
403  if (it != iptcData.end())
404  {
405  std::ostringstream os;
406  os << *it;
407  QString tagValue(QString::fromLatin1(os.str().c_str()));
408 
409  if (escapeCR)
410  tagValue.replace(QString::fromLatin1("\n"), QString::fromLatin1(" "));
411 
412  return tagValue;
413  }
414  }
415  catch(Exiv2::Error& e)
416  {
417  d->printExiv2ExceptionError(QString::fromLatin1("Cannot find Iptc key '%1' into image using Exiv2 ").arg(QString::fromLatin1(iptcTagName)), e);
418  }
419  catch(...)
420  {
421  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
422  }
423 
424  return QString();
425 }
426 
427 bool KExiv2::setIptcTagString(const char* iptcTagName, const QString& value, bool setProgramName) const
428 {
429  if (!setProgramId(setProgramName))
430  return false;
431 
432  try
433  {
434  d->iptcMetadata()[iptcTagName] = std::string(value.toUtf8().constData());
435 
436  // Make sure we have set the charset to UTF-8
437  d->iptcMetadata()["Iptc.Envelope.CharacterSet"] = "\33%G";
438  return true;
439  }
440  catch(Exiv2::Error& e)
441  {
442  d->printExiv2ExceptionError(QString::fromLatin1("Cannot set Iptc tag string into image using Exiv2 "), e);
443  }
444  catch(...)
445  {
446  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
447  }
448 
449  return false;
450 }
451 
452 QStringList KExiv2::getIptcTagsStringList(const char* iptcTagName, bool escapeCR) const
453 {
454  try
455  {
456  if (!d->iptcMetadata().empty())
457  {
459  Exiv2::IptcData iptcData(d->iptcMetadata());
460 
461  for (Exiv2::IptcData::iterator it = iptcData.begin(); it != iptcData.end(); ++it)
462  {
463  QString key = QString::fromLocal8Bit(it->key().c_str());
464 
465  if (key == QString::fromLatin1(iptcTagName))
466  {
467  QString tagValue = QString::fromUtf8(it->toString().c_str());
468 
469  if (escapeCR)
470  tagValue.replace(QString::fromLatin1("\n"), QString::fromLatin1(" "));
471 
472  values.append(tagValue);
473  }
474  }
475 
476  return values;
477  }
478  }
479  catch(Exiv2::Error& e)
480  {
481  d->printExiv2ExceptionError(QString::fromLatin1("Cannot find Iptc key '%1' into image using Exiv2 ").arg(QString::fromLatin1(iptcTagName)), e);
482  }
483  catch(...)
484  {
485  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
486  }
487 
488  return QStringList();
489 }
490 
491 bool KExiv2::setIptcTagsStringList(const char* iptcTagName, int maxSize,
492  const QStringList& oldValues, const QStringList& newValues,
493  bool setProgramName) const
494 {
495  if (!setProgramId(setProgramName))
496  return false;
497 
498  try
499  {
500  QStringList oldvals = oldValues;
501  QStringList newvals = newValues;
502 
503  qCDebug(LIBKEXIV2_LOG) << d->filePath.toLatin1().constData() << " : " << iptcTagName
504  << " => " << newvals.join(QString::fromLatin1(",")).toLatin1().constData();
505 
506  // Remove all old values.
507  Exiv2::IptcData iptcData(d->iptcMetadata());
508  Exiv2::IptcData::iterator it = iptcData.begin();
509 
510  while(it != iptcData.end())
511  {
512  QString key = QString::fromLocal8Bit(it->key().c_str());
513  QString val = QString::fromUtf8(it->toString().c_str());
514 
515  // Also remove new values to avoid duplicates. They will be added again below.
516  if ( key == QString::fromLatin1(iptcTagName) &&
517  (oldvals.contains(val) || newvals.contains(val))
518  )
519  it = iptcData.erase(it);
520  else
521  ++it;
522  };
523 
524  // Add new values.
525 
526  Exiv2::IptcKey iptcTag(iptcTagName);
527 
528  for (QStringList::iterator it = newvals.begin(); it != newvals.end(); ++it)
529  {
530  QString key = *it;
531  key.truncate(maxSize);
532 
533  Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::string);
534  val->read(key.toUtf8().constData());
535  iptcData.add(iptcTag, val.get());
536  }
537 
538  d->iptcMetadata() = iptcData;
539 
540  // Make sure character set is UTF-8
541  setIptcTagString("Iptc.Envelope.CharacterSet", QString::fromLatin1("\33%G"), false);
542 
543  return true;
544  }
545  catch(Exiv2::Error& e)
546  {
547  d->printExiv2ExceptionError(QString::fromLatin1("Cannot set Iptc key '%1' into image using Exiv2 ").arg(QString::fromLatin1(iptcTagName)), e);
548  }
549  catch(...)
550  {
551  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
552  }
553 
554  return false;
555 }
556 
558 {
559  try
560  {
561  if (!d->iptcMetadata().empty())
562  {
563  QStringList keywords;
564  Exiv2::IptcData iptcData(d->iptcMetadata());
565 
566  for (Exiv2::IptcData::iterator it = iptcData.begin(); it != iptcData.end(); ++it)
567  {
568  QString key = QString::fromLocal8Bit(it->key().c_str());
569 
570  if (key == QString::fromLatin1("Iptc.Application2.Keywords"))
571  {
572  QString val = QString::fromUtf8(it->toString().c_str());
573  keywords.append(val);
574  }
575  }
576 
577  qCDebug(LIBKEXIV2_LOG) << d->filePath << " ==> Read Iptc Keywords: " << keywords;
578 
579  return keywords;
580  }
581  }
582  catch(Exiv2::Error& e)
583  {
584  d->printExiv2ExceptionError(QString::fromLatin1("Cannot get Iptc Keywords from image using Exiv2 "), e);
585  }
586  catch(...)
587  {
588  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
589  }
590 
591  return QStringList();
592 }
593 
594 bool KExiv2::setIptcKeywords(const QStringList& oldKeywords, const QStringList& newKeywords,
595  bool setProgramName) const
596 {
597  if (!setProgramId(setProgramName))
598  return false;
599 
600  try
601  {
602  QStringList oldkeys = oldKeywords;
603  QStringList newkeys = newKeywords;
604 
605  qCDebug(LIBKEXIV2_LOG) << d->filePath << " ==> New Iptc Keywords: " << newkeys;
606 
607  // Remove all old keywords.
608  Exiv2::IptcData iptcData(d->iptcMetadata());
609  Exiv2::IptcData::iterator it = iptcData.begin();
610 
611  while(it != iptcData.end())
612  {
613  QString key = QString::fromLocal8Bit(it->key().c_str());
614  QString val = QString::fromUtf8(it->toString().c_str());
615 
616  // Also remove new keywords to avoid duplicates. They will be added again below.
617  if ( key == QString::fromLatin1("Iptc.Application2.Keywords") &&
618  (oldKeywords.contains(val) || newKeywords.contains(val))
619  )
620  it = iptcData.erase(it);
621  else
622  ++it;
623  };
624 
625  // Add new keywords. Note that Keywords Iptc tag is limited to 64 char but can be redondant.
626 
627  Exiv2::IptcKey iptcTag("Iptc.Application2.Keywords");
628 
629  for (QStringList::iterator it = newkeys.begin(); it != newkeys.end(); ++it)
630  {
631  QString key = *it;
632  key.truncate(64);
633 
634  Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::string);
635  val->read(key.toUtf8().constData());
636  iptcData.add(iptcTag, val.get());
637  }
638 
639  d->iptcMetadata() = iptcData;
640 
641  // Make sure character set is UTF-8
642  setIptcTagString("Iptc.Envelope.CharacterSet", QString::fromLatin1("\33%G"), false);
643 
644  return true;
645  }
646  catch(Exiv2::Error& e)
647  {
648  d->printExiv2ExceptionError(QString::fromLatin1("Cannot set Iptc Keywords into image using Exiv2 "), e);
649  }
650  catch(...)
651  {
652  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
653  }
654 
655  return false;
656 }
657 
659 {
660  try
661  {
662  if (!d->iptcMetadata().empty())
663  {
664  QStringList subjects;
665  Exiv2::IptcData iptcData(d->iptcMetadata());
666 
667  for (Exiv2::IptcData::iterator it = iptcData.begin(); it != iptcData.end(); ++it)
668  {
669  QString key = QString::fromLocal8Bit(it->key().c_str());
670 
671  if (key == QString::fromLatin1("Iptc.Application2.Subject"))
672  {
673  QString val(QString::fromLatin1(it->toString().c_str()));
674  subjects.append(val);
675  }
676  }
677 
678  return subjects;
679  }
680  }
681  catch(Exiv2::Error& e)
682  {
683  d->printExiv2ExceptionError(QString::fromLatin1("Cannot get Iptc Subjects from image using Exiv2 "), e);
684  }
685  catch(...)
686  {
687  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
688  }
689 
690  return QStringList();
691 }
692 
693 bool KExiv2::setIptcSubjects(const QStringList& oldSubjects, const QStringList& newSubjects,
694  bool setProgramName) const
695 {
696  if (!setProgramId(setProgramName))
697  return false;
698 
699  try
700  {
701  QStringList oldDef = oldSubjects;
702  QStringList newDef = newSubjects;
703 
704  // Remove all old subjects.
705  Exiv2::IptcData iptcData(d->iptcMetadata());
706  Exiv2::IptcData::iterator it = iptcData.begin();
707 
708  while(it != iptcData.end())
709  {
710  QString key = QString::fromLocal8Bit(it->key().c_str());
711  QString val = QString::fromUtf8(it->toString().c_str());
712 
713  if (key == QString::fromLatin1("Iptc.Application2.Subject") && oldDef.contains(val))
714  it = iptcData.erase(it);
715  else
716  ++it;
717  };
718 
719  // Add new subjects. Note that Keywords Iptc tag is limited to 236 char but can be redondant.
720 
721  Exiv2::IptcKey iptcTag("Iptc.Application2.Subject");
722 
723  for (QStringList::iterator it = newDef.begin(); it != newDef.end(); ++it)
724  {
725  QString key = *it;
726  key.truncate(236);
727 
728  Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::string);
729  val->read(key.toUtf8().constData());
730  iptcData.add(iptcTag, val.get());
731  }
732 
733  d->iptcMetadata() = iptcData;
734 
735  // Make sure character set is UTF-8
736  setIptcTagString("Iptc.Envelope.CharacterSet", QString::fromLatin1("\33%G"), false);
737 
738  return true;
739  }
740  catch(Exiv2::Error& e)
741  {
742  d->printExiv2ExceptionError(QString::fromLatin1("Cannot set Iptc Subjects into image using Exiv2 "), e);
743  }
744  catch(...)
745  {
746  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
747  }
748 
749  return false;
750 }
751 
753 {
754  try
755  {
756  if (!d->iptcMetadata().empty())
757  {
758  QStringList subCategories;
759  Exiv2::IptcData iptcData(d->iptcMetadata());
760 
761  for (Exiv2::IptcData::iterator it = iptcData.begin(); it != iptcData.end(); ++it)
762  {
763  QString key = QString::fromLocal8Bit(it->key().c_str());
764 
765  if (key == QString::fromLatin1("Iptc.Application2.SuppCategory"))
766  {
767  QString val(QString::fromLatin1(it->toString().c_str()));
768  subCategories.append(val);
769  }
770  }
771 
772  return subCategories;
773  }
774  }
775  catch(Exiv2::Error& e)
776  {
777  d->printExiv2ExceptionError(QString::fromLatin1("Cannot get Iptc Sub Categories from image using Exiv2 "), e);
778  }
779  catch(...)
780  {
781  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
782  }
783 
784  return QStringList();
785 }
786 
787 bool KExiv2::setIptcSubCategories(const QStringList& oldSubCategories, const QStringList& newSubCategories,
788  bool setProgramName) const
789 {
790  if (!setProgramId(setProgramName))
791  return false;
792 
793  try
794  {
795  QStringList oldkeys = oldSubCategories;
796  QStringList newkeys = newSubCategories;
797 
798  // Remove all old Sub Categories.
799  Exiv2::IptcData iptcData(d->iptcMetadata());
800  Exiv2::IptcData::iterator it = iptcData.begin();
801 
802  while(it != iptcData.end())
803  {
804  QString key = QString::fromLocal8Bit(it->key().c_str());
805  QString val = QString::fromUtf8(it->toString().c_str());
806 
807  if (key == QString::fromLatin1("Iptc.Application2.SuppCategory") && oldSubCategories.contains(val))
808  it = iptcData.erase(it);
809  else
810  ++it;
811  };
812 
813  // Add new Sub Categories. Note that SubCategories Iptc tag is limited to 32
814  // characters but can be redondant.
815 
816  Exiv2::IptcKey iptcTag("Iptc.Application2.SuppCategory");
817 
818  for (QStringList::iterator it = newkeys.begin(); it != newkeys.end(); ++it)
819  {
820  QString key = *it;
821  key.truncate(32);
822 
823  Exiv2::Value::AutoPtr val = Exiv2::Value::create(Exiv2::string);
824  val->read(key.toUtf8().constData());
825  iptcData.add(iptcTag, val.get());
826  }
827 
828  d->iptcMetadata() = iptcData;
829 
830  // Make sure character set is UTF-8
831  setIptcTagString("Iptc.Envelope.CharacterSet", QString::fromLatin1("\33%G"), false);
832 
833  return true;
834  }
835  catch(Exiv2::Error& e)
836  {
837  d->printExiv2ExceptionError(QString::fromLatin1("Cannot set Iptc Sub Categories into image using Exiv2 "), e);
838  }
839  catch(...)
840  {
841  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
842  }
843 
844  return false;
845 }
846 
848 {
849  try
850  {
852  tags << Exiv2::IptcDataSets::envelopeRecordList()
853  << Exiv2::IptcDataSets::application2RecordList();
854 
855  TagsMap tagsMap;
856 
857  for (QList<const Exiv2::DataSet*>::iterator it = tags.begin(); it != tags.end(); ++it)
858  {
859  do
860  {
861  QString key = QLatin1String( Exiv2::IptcKey( (*it)->number_, (*it)->recordId_ ).key().c_str() );
863  values << QString::fromLatin1((*it)->name_) << QString::fromLatin1((*it)->title_) << QString::fromLatin1((*it)->desc_);
864  tagsMap.insert(key, values);
865  ++(*it);
866  }
867  while((*it)->number_ != 0xffff);
868  }
869 
870  return tagsMap;
871  }
872  catch(Exiv2::Error& e)
873  {
874  d->printExiv2ExceptionError(QString::fromLatin1("Cannot get Iptc Tags list using Exiv2 "), e);
875  }
876  catch(...)
877  {
878  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
879  }
880 
881  return TagsMap();
882 }
883 
884 } // NameSpace KExiv2Iface
KExiv2::MetaDataMap getIptcTagsDataList(const QStringList &iptcKeysFilter=QStringList(), bool invertSelection=false) const
Return a map of Iptc tags name/value found in metadata sorted by Iptc keys given by &#39;iptcKeysFilter&#39;...
Definition: kexiv2iptc.cpp:152
QString getIptcTagString(const char *iptcTagName, bool escapeCR=true) const
Get an Iptc tag content like a string.
Definition: kexiv2iptc.cpp:395
QString & append(QChar ch)
QStringList getIptcKeywords() const
Return a strings list of Iptc keywords from image.
Definition: kexiv2iptc.cpp:557
KExiv2Iface.
Definition: kexiv2.cpp:36
void truncate(int position)
KExiv2::TagsMap getIptcTagsList() const
Return a map of all standard Iptc tags supported by Exiv2.
Definition: kexiv2iptc.cpp:847
bool setIptcTagData(const char *iptcTagName, const QByteArray &data, bool setProgramName=true) const
Set an Iptc tag content using a bytes array.
Definition: kexiv2iptc.cpp:340
QStringList getIptcSubCategories() const
Return a strings list of Iptc sub-categories from image.
Definition: kexiv2iptc.cpp:752
bool contains(const QString &str, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString join(const QString &separator) const const
bool hasIptc() const
Return &#39;true&#39; if metadata container in memory as Iptc.
Definition: kexiv2iptc.cpp:61
bool setIptc(const QByteArray &data) const
Set the Iptc data using a Qt byte array.
Definition: kexiv2iptc.cpp:125
QVector< V > values(const QMultiHash< K, V > &c)
QStringList getIptcTagsStringList(const char *iptcTagName, bool escapeCR=true) const
Returns a strings list with of multiple Iptc tags from the image.
Definition: kexiv2iptc.cpp:452
QByteArray getIptcTagData(const char *iptcTagName) const
Get an Iptc tag content as a bytes array.
Definition: kexiv2iptc.cpp:366
QString fromLocal8Bit(const char *str, int size)
void append(const T &value)
QString fromUtf8(const char *str, int size)
bool setIptcSubCategories(const QStringList &oldSubCategories, const QStringList &newSubCategories, bool setProgramName=true) const
Set Iptc sub-categories using a list of strings defined by &#39;newSubCategories&#39; parameter.
Definition: kexiv2iptc.cpp:787
bool setIptcTagsStringList(const char *iptcTagName, int maxSize, const QStringList &oldValues, const QStringList &newValues, bool setProgramName=true) const
Set multiple Iptc tags contents using a strings list.
Definition: kexiv2iptc.cpp:491
bool isEmpty() const const
QString getIptcTagDescription(const char *iptcTagName)
Return the Iptc Tag description or a null string.
Definition: kexiv2iptc.cpp:280
QMap< QString, QString > MetaDataMap
A map used to store Tags Key and Tags Value.
Definition: kexiv2.h:128
const char * constData() const const
QMap::iterator end()
QList::iterator end()
bool removeIptcTag(const char *iptcTagName, bool setProgramName=true) const
Remove the all instance of Iptc tags &#39;iptcTagName&#39; from Iptc metadata.
Definition: kexiv2iptc.cpp:300
bool setIptcTagString(const char *iptcTagName, const QString &value, bool setProgramName=true) const
Set an Iptc tag content using a string.
Definition: kexiv2iptc.cpp:427
virtual bool setProgramId(bool on=true) const
Re-implement this method to set automatically the Program Name and Program Version information in Exi...
Definition: kexiv2.cpp:529
QString & replace(int position, int n, QChar after)
static bool canWriteIptc(const QString &filePath)
Return &#39;true&#39; if Iptc can be written in file.
Definition: kexiv2iptc.cpp:37
QMap< QString, QStringList > TagsMap
A map used to store Tags Key and a list of Tags properties :
Definition: kexiv2.h:141
QByteArray toLatin1() const const
bool setIptcKeywords(const QStringList &oldKeywords, const QStringList &newKeywords, bool setProgramName=true) const
Set Iptc keywords using a list of strings defined by &#39;newKeywords&#39; parameter.
Definition: kexiv2iptc.cpp:594
char * data()
QString section(QChar sep, int start, int end, QString::SectionFlags flags) const const
QString getIptcTagTitle(const char *iptcTagName)
Return the Iptc Tag title or a null string.
Definition: kexiv2iptc.cpp:260
QString fromLatin1(const char *str, int size)
bool setIptcSubjects(const QStringList &oldSubjects, const QStringList &newSubjects, bool setProgramName=true) const
Set Iptc subjects using a list of strings defined by &#39;newSubjects&#39; parameter.
Definition: kexiv2iptc.cpp:693
QMap::iterator insert(const Key &key, const T &value)
QStringList getIptcSubjects() const
Return a strings list of Iptc subjects from image.
Definition: kexiv2iptc.cpp:658
int size() const const
QMap::iterator find(const Key &key)
QList::iterator begin()
QByteArray getIptc(bool addIrbHeader=false) const
Return a Qt byte array copy of Iptc container get from current image.
Definition: kexiv2iptc.cpp:85
===========================================================This file is a part of KDE project ...
QByteArray encodeName(const QString &fileName)
bool clearIptc() const
Clear the Iptc metadata container in memory.
Definition: kexiv2iptc.cpp:66
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Nov 26 2020 22:35:13 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.