libkipi from trunk (KDE 4.3) : add support of kipi host settings "file timestamp...
[kdegraphics.git] / gwenview / lib / exiv2imageloader.cpp
blob383f93781f75a5fbb54f13ee8564e352f127d843
1 // vim: set tabstop=4 shiftwidth=4 noexpandtab:
2 /*
3 Gwenview: an image viewer
4 Copyright 2007 Aurélien Gâteau <aurelien.gateau@free.fr>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 // Self
22 #include "exiv2imageloader.h"
24 // Qt
25 #include <QByteArray>
26 #include <QString>
28 // KDE
30 // Exiv2
31 #include <exiv2/error.hpp>
32 #include <exiv2/types.hpp>
34 // Local
36 namespace Gwenview {
39 struct Exiv2ImageLoaderPrivate {
40 Exiv2::Image::AutoPtr mImage;
41 QString mErrorMessage;
45 Exiv2ImageLoader::Exiv2ImageLoader()
46 : d(new Exiv2ImageLoaderPrivate) {
50 Exiv2ImageLoader::~Exiv2ImageLoader() {
51 delete d;
55 bool Exiv2ImageLoader::load(const QByteArray& data) {
56 try {
57 d->mImage = Exiv2::ImageFactory::open((unsigned char*)data.constData(), data.size());
58 d->mImage->readMetadata();
59 #if EXIV2_VERSION >= EXIV2_MAKE_VERSION(0, 14, 0)
60 // For some unknown reason, trying to catch Exiv2::Error fails with Exiv2
61 // >=0.14. For now, just catch std::exception. I would welcome any
62 // explanation.
63 } catch (const std::exception& error) {
64 d->mErrorMessage = error.what();
65 #else
66 // In libexiv2 0.12, Exiv2::Error::what() returns an std::string.
67 } catch (const Exiv2::Error& error) {
68 d->mErrorMessage = error.what().c_str();
69 #endif
70 return false;
72 return true;
76 QString Exiv2ImageLoader::errorMessage() const {
77 return d->mErrorMessage;
81 Exiv2::Image::AutoPtr Exiv2ImageLoader::popImage() {
82 return d->mImage;
86 } // namespace