• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegraphics API Reference
  • KDE Home
  • Contact Us
 

libs/libkexiv2/libkexiv2

  • sources
  • kde-4.14
  • kdegraphics
  • libs
  • libkexiv2
  • libkexiv2
kexiv2comments.cpp
Go to the documentation of this file.
1 
28 // Local includes
29 
30 #include "kexiv2_p.h"
31 #include "kexiv2.h"
32 
33 namespace KExiv2Iface
34 {
35 
36 bool KExiv2::canWriteComment(const QString& filePath)
37 {
38  try
39  {
40  Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open((const char*)
41  (QFile::encodeName(filePath)));
42 
43  Exiv2::AccessMode mode = image->checkMode(Exiv2::mdComment);
44  return (mode == Exiv2::amWrite || mode == Exiv2::amReadWrite);
45  }
46  catch( Exiv2::Error& e )
47  {
48  std::string s(e.what());
49  kError() << "Cannot check Comment access mode using Exiv2 (Error #"
50  << e.code() << ": " << s.c_str() << ")";
51  }
52  catch(...)
53  {
54  kError() << "Default exception from Exiv2";
55  }
56 
57  return false;
58 }
59 
60 bool KExiv2::hasComments() const
61 {
62  return !d->imageComments().empty();
63 }
64 
65 bool KExiv2::clearComments() const
66 {
67  return setComments(QByteArray());
68 }
69 
70 QByteArray KExiv2::getComments() const
71 {
72  return QByteArray(d->imageComments().data(), d->imageComments().size());
73 }
74 
75 QString KExiv2::getCommentsDecoded() const
76 {
77  return d->detectEncodingAndDecode(d->imageComments());
78 }
79 
80 bool KExiv2::setComments(const QByteArray& data) const
81 {
82  d->imageComments() = std::string(data.data(), data.size());
83  return true;
84 }
85 
86 QString KExiv2::detectLanguageAlt(const QString& value, QString& lang)
87 {
88  // Ex. from an Xmp tag Xmp.tiff.copyright: "lang="x-default" (c) Gilles Caulier 2007"
89 
90  if (value.size() > 6 && value.startsWith(QString("lang=\"")))
91  {
92  int pos = value.indexOf(QString("\""), 6);
93  if (pos != -1)
94  {
95  lang = value.mid(6, pos-6);
96  return (value.mid(pos+2));
97  }
98  }
99 
100  lang.clear();
101  return value;
102 }
103 
104 } // NameSpace KExiv2Iface
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
KExiv2Iface::KExiv2::getComments
QByteArray getComments() const
Return a Qt byte array copy of Comments container get from current image.
Definition: kexiv2comments.cpp:70
QByteArray
KExiv2Iface::KExiv2::hasComments
bool hasComments() const
Return 'true' if metadata container in memory as Comments.
Definition: kexiv2comments.cpp:60
QString::size
int size() const
KExiv2Iface::KExiv2::Private::imageComments
const std::string & imageComments() const
Definition: kexiv2_p.h:165
QString::clear
void clear()
KExiv2Iface::KExiv2::canWriteComment
static bool canWriteComment(const QString &filePath)
Return 'true' if Comments can be written in file.
Definition: kexiv2comments.cpp:36
KExiv2Iface::KExiv2::getCommentsDecoded
QString getCommentsDecoded() const
Return a Qt string object of Comments from current image decoded using the 'detectEncodingAndDecode()...
Definition: kexiv2comments.cpp:75
KExiv2Iface::KExiv2::detectLanguageAlt
static QString detectLanguageAlt(const QString &value, QString &lang)
Language Alternative autodetection.
Definition: kexiv2comments.cpp:86
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QString
KExiv2Iface::KExiv2::Private::detectEncodingAndDecode
QString detectEncodingAndDecode(const std::string &value) const
Charset autodetection to convert a string to a QString.
KExiv2Iface::KExiv2::setComments
bool setComments(const QByteArray &data) const
Set the Comments data using a Qt byte array.
Definition: kexiv2comments.cpp:80
QString::mid
QString mid(int position, int n) const
KExiv2Iface::KExiv2::clearComments
bool clearComments() const
Clear the Comments metadata container in memory.
Definition: kexiv2comments.cpp:65
kexiv2_p.h
===========================================================This file is a part of digiKam project htt...
QByteArray::data
char * data()
QByteArray::size
int size() const
kexiv2.h
===========================================================This file is a part of digiKam project htt...
QFile::encodeName
QByteArray encodeName(const QString &fileName)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:19:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libs/libkexiv2/libkexiv2

Skip menu "libs/libkexiv2/libkexiv2"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegraphics API Reference

Skip menu "kdegraphics API Reference"
  •     libkdcraw
  •     libkexiv2
  •     libkipi
  •     libksane
  • okular

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal