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
14namespace KExiv2Iface
15{
16
17bool KExiv2::canWriteComment(const QString& filePath)
18{
19 try
20 {
21#if EXIV2_TEST_VERSION(0,28,0)
22 Exiv2::Image::UniquePtr image
23#else
24 Exiv2::Image::AutoPtr image
25#endif
26 = Exiv2::ImageFactory::open((const char*)
27 (QFile::encodeName(filePath).constData()));
28
29 Exiv2::AccessMode mode = image->checkMode(Exiv2::mdComment);
30 return (mode == Exiv2::amWrite || mode == Exiv2::amReadWrite);
31 }
32 catch( Exiv2::Error& e )
33 {
34 std::string s(e.what());
35 qCCritical(LIBKEXIV2_LOG) << "Cannot check Comment access mode using Exiv2 (Error #"
36#if EXIV2_TEST_VERSION(0,28,0)
37 << Exiv2::Error(e.code()).what()
38#else
39 << e.code() << ": " << s.c_str()
40#endif
41 << ")";
42 }
43 catch(...)
44 {
45 qCCritical(LIBKEXIV2_LOG) << "Default exception from Exiv2";
46 }
47
48 return false;
49}
50
52{
53 return !d->imageComments().empty();
54}
55
57{
58 return setComments(QByteArray());
59}
60
62{
63 return QByteArray(d->imageComments().data(), d->imageComments().size());
64}
65
67{
68 return d->detectEncodingAndDecode(d->imageComments());
69}
70
71bool KExiv2::setComments(const QByteArray& data) const
72{
73 d->imageComments() = std::string(data.data(), data.size());
74 return true;
75}
76
78{
79 // Ex. from an Xmp tag Xmp.tiff.copyright: "lang="x-default" (c) Gilles Caulier 2007"
80
81 if (value.size() > 6 && value.startsWith(QString::fromLatin1("lang=\"")))
82 {
83 int pos = value.indexOf(QString::fromLatin1("\""), 6);
84
85 if (pos != -1)
86 {
87 lang = value.mid(6, pos-6);
88 return (value.mid(pos+2));
89 }
90 }
91
92 lang.clear();
93 return value;
94}
95
96} // NameSpace KExiv2Iface
bool clearComments() const
Clear the Comments metadata container in memory.
static bool canWriteComment(const QString &filePath)
Return 'true' if Comments can be written in file.
QString getCommentsDecoded() const
Return a Qt string object of Comments from current image decoded using the 'detectEncodingAndDecode()...
bool setComments(const QByteArray &data) const
Set the Comments data using a Qt byte array.
static QString detectLanguageAlt(const QString &value, QString &lang)
Language Alternative autodetection.
bool hasComments() const
Return 'true' if metadata container in memory as Comments.
QByteArray getComments() const
Return a Qt byte array copy of Comments container get from current image.
KExiv2Iface - Exiv2 library interface.
Definition kexiv2.cpp:17
char * data()
qsizetype size() const const
QByteArray encodeName(const QString &fileName)
void clear()
QString fromLatin1(QByteArrayView str)
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
QString mid(qsizetype position, qsizetype n) const const
qsizetype size() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:02 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.