KExiv2

kexiv2comments.cpp
Go to the documentation of this file.
1 
28 // Local includes
29 
30 #include "kexiv2_p.h"
31 #include "kexiv2.h"
32 #include "libkexiv2_debug.h"
33 
34 namespace KExiv2Iface
35 {
36 
37 bool KExiv2::canWriteComment(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::mdComment);
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 Comment 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::hasComments() const
62 {
63  return !d->imageComments().empty();
64 }
65 
67 {
68  return setComments(QByteArray());
69 }
70 
72 {
73  return QByteArray(d->imageComments().data(), d->imageComments().size());
74 }
75 
77 {
78  return d->detectEncodingAndDecode(d->imageComments());
79 }
80 
81 bool KExiv2::setComments(const QByteArray& data) const
82 {
83  d->imageComments() = std::string(data.data(), data.size());
84  return true;
85 }
86 
88 {
89  // Ex. from an Xmp tag Xmp.tiff.copyright: "lang="x-default" (c) Gilles Caulier 2007"
90 
91  if (value.size() > 6 && value.startsWith(QString::fromLatin1("lang=\"")))
92  {
93  int pos = value.indexOf(QString::fromLatin1("\""), 6);
94 
95  if (pos != -1)
96  {
97  lang = value.mid(6, pos-6);
98  return (value.mid(pos+2));
99  }
100  }
101 
102  lang.clear();
103  return value;
104 }
105 
106 } // NameSpace KExiv2Iface
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
KExiv2Iface.
Definition: kexiv2.cpp:36
QByteArray getComments() const
Return a Qt byte array copy of Comments container get from current image.
bool hasComments() const
Return &#39;true&#39; if metadata container in memory as Comments.
int size() const const
void clear()
static bool canWriteComment(const QString &filePath)
Return &#39;true&#39; if Comments can be written in file.
QString getCommentsDecoded() const
Return a Qt string object of Comments from current image decoded using the &#39;detectEncodingAndDecode()...
static QString detectLanguageAlt(const QString &value, QString &lang)
Language Alternative autodetection.
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
bool setComments(const QByteArray &data) const
Set the Comments data using a Qt byte array.
QString mid(int position, int n) const const
bool clearComments() const
Clear the Comments metadata container in memory.
char * data()
QString fromLatin1(const char *str, int size)
int size() const const
===========================================================This file is a part of KDE project ...
QByteArray encodeName(const QString &fileName)
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.