Fix missing translation
[geeqie.git] / src / image-load-external.cc
1 /*
2  * Copyright (C) 2021 - The Geeqie Team
3  *
4  * Author: Colin Clark
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 #include "image-load-external.h"
22
23 #include <config.h>
24
25 #include "filedata.h"
26 #include "image-load.h"
27 #include "misc.h"
28 #include "options.h"
29 #include "ui-fileops.h"
30
31 struct ImageLoaderExternal {
32         ImageLoaderBackendCbAreaUpdated area_updated_cb;
33         ImageLoaderBackendCbSize size_cb;
34         ImageLoaderBackendCbAreaPrepared area_prepared_cb;
35         gpointer data;
36         GdkPixbuf *pixbuf;
37         guint requested_width;
38         guint requested_height;
39         gboolean abort;
40 };
41
42 static gboolean image_loader_external_load(gpointer loader, const guchar *, gsize, GError **)
43 {
44         auto ld = static_cast<ImageLoaderExternal *>(loader);
45         auto il = static_cast<ImageLoader *>(ld->data);
46         gchar *cmd_line;
47         gchar *randname;
48         gchar *tilde_filename;
49
50         tilde_filename = expand_tilde(options->external_preview.extract);
51
52         randname = g_strdup("/tmp/geeqie_external_preview_XXXXXX");
53         g_mkstemp(randname);
54
55         cmd_line = g_strdup_printf("\"%s\" \"%s\" \"%s\"" , tilde_filename, il->fd->path, randname);
56
57         runcmd(cmd_line);
58
59         ld->pixbuf = gdk_pixbuf_new_from_file(randname, nullptr);
60
61         ld->area_updated_cb(loader, 0, 0, gdk_pixbuf_get_width(ld->pixbuf), gdk_pixbuf_get_height(ld->pixbuf), ld->data);
62
63         g_free(cmd_line);
64         unlink_file(randname);
65         g_free(randname);
66         g_free(tilde_filename);
67
68         return TRUE;
69 }
70
71 static gpointer image_loader_external_new(ImageLoaderBackendCbAreaUpdated area_updated_cb, ImageLoaderBackendCbSize size_cb, ImageLoaderBackendCbAreaPrepared area_prepared_cb, gpointer data)
72 {
73         auto loader = g_new0(ImageLoaderExternal, 1);
74         loader->area_updated_cb = area_updated_cb;
75         loader->size_cb = size_cb;
76         loader->area_prepared_cb = area_prepared_cb;
77         loader->data = data;
78         return loader;
79 }
80
81 static void image_loader_external_set_size(gpointer loader, int width, int height)
82 {
83         auto ld = static_cast<ImageLoaderExternal *>(loader);
84         ld->requested_width = width;
85         ld->requested_height = height;
86 }
87
88 static GdkPixbuf* image_loader_external_get_pixbuf(gpointer loader)
89 {
90         auto ld = static_cast<ImageLoaderExternal *>(loader);
91         return ld->pixbuf;
92 }
93
94 static gchar* image_loader_external_get_format_name(gpointer)
95 {
96         return g_strdup("external");
97 }
98
99 static gchar** image_loader_external_get_format_mime_types(gpointer)
100 {
101         static const gchar *mime[] = {"application/octet-stream", nullptr};
102         return g_strdupv(const_cast<gchar **>(mime));
103 }
104
105 static gboolean image_loader_external_close(gpointer, GError **)
106 {
107         return TRUE;
108 }
109
110 static void image_loader_external_abort(gpointer loader)
111 {
112         auto ld = static_cast<ImageLoaderExternal *>(loader);
113         ld->abort = TRUE;
114 }
115
116 static void image_loader_external_free(gpointer loader)
117 {
118         auto ld = static_cast<ImageLoaderExternal *>(loader);
119         if (ld->pixbuf) g_object_unref(ld->pixbuf);
120         g_free(ld);
121 }
122
123 void image_loader_backend_set_external(ImageLoaderBackend *funcs)
124 {
125         funcs->loader_new = image_loader_external_new;
126         funcs->set_size = image_loader_external_set_size;
127         funcs->load = image_loader_external_load;
128         funcs->write = nullptr;
129         funcs->get_pixbuf = image_loader_external_get_pixbuf;
130         funcs->close = image_loader_external_close;
131         funcs->abort = image_loader_external_abort;
132         funcs->free = image_loader_external_free;
133         funcs->get_format_name = image_loader_external_get_format_name;
134         funcs->get_format_mime_types = image_loader_external_get_format_mime_types;
135 }
136
137
138 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */