Fix #201: Geeqie to pop to top of current windows when open up with -r
[geeqie.git] / src / exiv2.cc
index 97f0894..49b8e07 100644 (file)
@@ -1,12 +1,21 @@
 /*
- * Geeqie
- * Copyright (C) 2008 - 2012 The Geeqie Team
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: Vladimir Nadvornik
  *
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include "config.h"
@@ -16,6 +25,7 @@
 #include <exiv2/image.hpp>
 #include <exiv2/exif.hpp>
 #include <iostream>
+#include <string>
 
 // EXIV2_TEST_VERSION is defined in Exiv2 0.15 and newer.
 #ifndef EXIV2_TEST_VERSION
@@ -160,6 +170,7 @@ protected:
        unsigned char *cp_data_;
        guint cp_length_;
        gboolean valid_;
+       gchar *pathl_;
 
        Exiv2::ExifData emptyExifData_;
        Exiv2::IptcData emptyIptcData_;
@@ -182,10 +193,10 @@ public:
                cp_length_ = 0;
                valid_ = TRUE;
 
-               gchar *pathl = path_from_utf8(path);
+               pathl_ = path_from_utf8(path);
                try
                        {
-                       image_ = Exiv2::ImageFactory::open(pathl);
+                       image_ = Exiv2::ImageFactory::open(pathl_);
 //                     g_assert (image.get() != 0);
                        image_->readMetadata();
 
@@ -219,12 +230,12 @@ public:
                        {
                        valid_ = FALSE;
                        }
-               g_free(pathl);
        }
 
        virtual ~_ExifDataOriginal()
        {
                if (cp_data_) g_free(cp_data_);
+               if (pathl_) g_free(pathl_);
        }
 
        virtual Exiv2::Image *image()
@@ -1130,9 +1141,9 @@ guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width,
 
        if (!exif->image()) return NULL;
 
-       const char* path = exif->image()->io().path().c_str();
+       std::string const path = exif->image()->io().path();
        /* given image pathname, first do simple (and fast) file extension test */
-       gboolean is_raw = filter_file_class(path, FORMAT_CLASS_RAWIMAGE);
+       gboolean is_raw = filter_file_class(path.c_str(), FORMAT_CLASS_RAWIMAGE);
 
        if (!is_raw && requested_width == 0) return NULL;
 
@@ -1232,10 +1243,10 @@ extern "C" guchar *exif_get_preview(ExifData *exif, guint *data_len, gint reques
        if (!exif) return NULL;
        if (!exif->image()) return NULL;
 
-       const char* path = exif->image()->io().path().c_str();
+       std::string const path = exif->image()->io().path();
 
        /* given image pathname, first do simple (and fast) file extension test */
-       if (!filter_file_class(path, FORMAT_CLASS_RAWIMAGE)) return NULL;
+       if (!filter_file_class(path.c_str(), FORMAT_CLASS_RAWIMAGE)) return NULL;
 
        try {
                struct stat st;
@@ -1246,9 +1257,9 @@ extern "C" guchar *exif_get_preview(ExifData *exif, guint *data_len, gint reques
 
                RawFile rf(exif->image()->io());
                offset = rf.preview_offset();
-               DEBUG_1("%s: offset %lu", path, offset);
+               DEBUG_1("%s: offset %lu", path.c_str(), offset);
 
-               fd = open(path, O_RDONLY);
+               fd = open(path.c_str(), O_RDONLY);
                if (fd == -1)
                        {
                        return NULL;