1 // vim: set tabstop=4 shiftwidth=4 noexpandtab:
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.
22 #include "exiv2imageloader.h"
31 #include <exiv2/error.hpp>
32 #include <exiv2/types.hpp>
39 struct Exiv2ImageLoaderPrivate
{
40 Exiv2::Image::AutoPtr mImage
;
41 QString mErrorMessage
;
45 Exiv2ImageLoader::Exiv2ImageLoader()
46 : d(new Exiv2ImageLoaderPrivate
) {
50 Exiv2ImageLoader::~Exiv2ImageLoader() {
55 bool Exiv2ImageLoader::load(const QByteArray
& data
) {
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
63 } catch (const std::exception
& error
) {
64 d
->mErrorMessage
= error
.what();
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();
76 QString
Exiv2ImageLoader::errorMessage() const {
77 return d
->mErrorMessage
;
81 Exiv2::Image::AutoPtr
Exiv2ImageLoader::popImage() {