2 * Copyright (C) 20018 - 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-collection.h"
27 #include <gdk-pixbuf/gdk-pixbuf.h>
28 #include <glib-object.h>
33 #include "image-load.h"
36 #include "ui-fileops.h"
41 struct ImageLoaderCOLLECTION : public ImageLoaderBackend
44 ~ImageLoaderCOLLECTION() override;
46 void init(AreaUpdatedCb area_updated_cb, SizePreparedCb size_prepared_cb, AreaPreparedCb area_prepared_cb, gpointer data) override;
47 gboolean write(const guchar *buf, gsize &chunk_size, gsize count, GError **error) override;
48 GdkPixbuf *get_pixbuf() override;
49 gchar *get_format_name() override;
50 gchar **get_format_mime_types() override;
53 AreaUpdatedCb area_updated_cb;
59 gboolean ImageLoaderCOLLECTION::write(const guchar *, gsize &chunk_size, gsize count, GError **)
61 auto il = static_cast<ImageLoader *>(data);
63 #define LINE_LENGTH 1000
70 GString *file_names = g_string_new(nullptr);
71 gchar line[LINE_LENGTH];
72 gchar **split_line = nullptr;
76 if (runcmd("which montage >/dev/null 2>&1") == 0)
78 pathl = path_from_utf8(il->fd->path);
79 fp = fopen(pathl, "r");
83 while(fgets(line, LINE_LENGTH, fp) && line_count < options->thumbnails.collection_preview)
85 if (line[0] && line[0] != '#')
87 split_line = g_strsplit(line, "\"", 4);
88 cache_found = cache_find_location(CACHE_TYPE_THUMB, split_line[1]);
91 g_string_append_printf(file_names, "\"%s\" ", cache_found);
98 g_strfreev(split_line);
100 split_line = nullptr;
104 if (file_names->len > 0)
106 randname = g_strdup("/tmp/geeqie_collection_XXXXXX.png");
109 cmd_line = g_strdup_printf("montage %s -geometry %dx%d+1+1 %s >/dev/null 2>&1", file_names->str, options->thumbnails.max_width, options->thumbnails.max_height, randname);
112 pixbuf = gdk_pixbuf_new_from_file(randname, nullptr);
115 area_updated_cb(nullptr, 0, 0, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), data);
125 g_string_free(file_names, TRUE);
132 void ImageLoaderCOLLECTION::init(AreaUpdatedCb area_updated_cb, SizePreparedCb, AreaPreparedCb, gpointer data)
134 this->area_updated_cb = area_updated_cb;
138 GdkPixbuf *ImageLoaderCOLLECTION::get_pixbuf()
143 gchar *ImageLoaderCOLLECTION::get_format_name()
145 return g_strdup("collection");
148 gchar **ImageLoaderCOLLECTION::get_format_mime_types()
150 static const gchar *mime[] = {"image/png", nullptr};
151 return g_strdupv(const_cast<gchar **>(mime));
154 ImageLoaderCOLLECTION::~ImageLoaderCOLLECTION()
156 if (pixbuf) g_object_unref(pixbuf);
161 std::unique_ptr<ImageLoaderBackend> get_image_loader_backend_collection()
163 return std::make_unique<ImageLoaderCOLLECTION>();
166 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */