2 * Copyright (C) 2021 - The Geeqie Team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "image-load-external.h"
23 #include <gdk-pixbuf/gdk-pixbuf.h>
24 #include <glib-object.h>
28 #include "image-load.h"
31 #include "ui-fileops.h"
36 struct ImageLoaderExternal : public ImageLoaderBackend
39 ~ImageLoaderExternal() override;
41 void init(AreaUpdatedCb area_updated_cb, SizePreparedCb size_prepared_cb, AreaPreparedCb area_prepared_cb, gpointer data) override;
42 gboolean write(const guchar *buf, gsize &chunk_size, gsize count, GError **error) override;
43 GdkPixbuf *get_pixbuf() override;
44 gchar *get_format_name() override;
45 gchar **get_format_mime_types() override;
48 AreaUpdatedCb area_updated_cb;
54 gboolean ImageLoaderExternal::write(const guchar *, gsize &chunk_size, gsize count, GError **)
56 auto il = static_cast<ImageLoader *>(data);
59 gchar *tilde_filename;
61 tilde_filename = expand_tilde(options->external_preview.extract);
63 randname = g_strdup("/tmp/geeqie_external_preview_XXXXXX");
66 cmd_line = g_strdup_printf("\"%s\" \"%s\" \"%s\"" , tilde_filename, il->fd->path, randname);
70 pixbuf = gdk_pixbuf_new_from_file(randname, nullptr);
72 area_updated_cb(nullptr, 0, 0, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), data);
75 unlink_file(randname);
77 g_free(tilde_filename);
83 void ImageLoaderExternal::init(AreaUpdatedCb area_updated_cb, SizePreparedCb, AreaPreparedCb, gpointer data)
85 this->area_updated_cb = area_updated_cb;
89 GdkPixbuf *ImageLoaderExternal::get_pixbuf()
94 gchar *ImageLoaderExternal::get_format_name()
96 return g_strdup("external");
99 gchar **ImageLoaderExternal::get_format_mime_types()
101 static const gchar *mime[] = {"application/octet-stream", nullptr};
102 return g_strdupv(const_cast<gchar **>(mime));
105 ImageLoaderExternal::~ImageLoaderExternal()
107 if (pixbuf) g_object_unref(pixbuf);
112 std::unique_ptr<ImageLoaderBackend> get_image_loader_backend_external()
114 return std::make_unique<ImageLoaderExternal>();
117 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */