KExiv2

kexiv2comments.cpp
1 /*
2  SPDX-FileCopyrightText: 2006-2015 Gilles Caulier <caulier dot gilles at gmail dot com>
3  SPDX-FileCopyrightText: 2006-2012 Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
4 
5  SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 // Local includes
9 
10 #include "kexiv2_p.h"
11 #include "kexiv2.h"
12 #include "libkexiv2_debug.h"
13 
14 namespace KExiv2Iface
15 {
16 
17 bool KExiv2::canWriteComment(const QString& filePath)
18 {
19  try
20  {
21  Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open((const char*)
22  (QFile::encodeName(filePath).constData()));
23 
24  Exiv2::AccessMode mode = image->checkMode(Exiv2::mdComment);
25  return (mode == Exiv2::amWrite || mode == Exiv2::amReadWrite);
26  }
27  catch( Exiv2::Error& e )
28  {
29  std::string s(e.what());
30  qCCritical(LIBKEXIV2_LOG) << "Cannot check Comment access mode using Exiv2 (Error #"
31  << e.code() << ": " << s.c_str() << ")";
32  }
33  catch(...)
34  {
35  qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
36  }
37 
38  return false;
39 }
40 
41 bool KExiv2::hasComments() const
42 {
43  return !d->imageComments().empty();
44 }
45 
47 {
48  return setComments(QByteArray());
49 }
50 
52 {
53  return QByteArray(d->imageComments().data(), d->imageComments().size());
54 }
55 
57 {
58  return d->detectEncodingAndDecode(d->imageComments());
59 }
60 
61 bool KExiv2::setComments(const QByteArray& data) const
62 {
63  d->imageComments() = std::string(data.data(), data.size());
64  return true;
65 }
66 
68 {
69  // Ex. from an Xmp tag Xmp.tiff.copyright: "lang="x-default" (c) Gilles Caulier 2007"
70 
71  if (value.size() > 6 && value.startsWith(QString::fromLatin1("lang=\"")))
72  {
73  int pos = value.indexOf(QString::fromLatin1("\""), 6);
74 
75  if (pos != -1)
76  {
77  lang = value.mid(6, pos-6);
78  return (value.mid(pos+2));
79  }
80  }
81 
82  lang.clear();
83  return value;
84 }
85 
86 } // NameSpace KExiv2Iface
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
KExiv2Iface - Exiv2 library interface.
Definition: kexiv2.cpp:16
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
QByteArray encodeName(const QString &fileName)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Dec 7 2021 22:32:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.