Improve some sieve-related translations
[claws.git] / src / plugins / dillo / dillo_viewer.c
blobf90d54b39b414633e85005090502d32f7d743f07
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2012 the Claws Mail Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #include "claws-features.h"
23 #endif
25 #include <unistd.h>
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 #include <gtk/gtk.h>
30 #include <gtk/gtkx.h>
31 #include <gdk/gdkx.h>
33 #include "common/claws.h"
34 #include "common/version.h"
35 #include "plugin.h"
36 #include "file-utils.h"
37 #include "utils.h"
38 #include "mimeview.h"
39 #include "addr_compl.h"
41 #include "dillo_prefs.h"
43 #define PLUGIN_NAME (_("Dillo HTML Viewer"))
45 typedef struct _DilloViewer DilloViewer;
47 struct _DilloViewer
49 MimeViewer mimeviewer;
50 GtkWidget *widget;
51 GtkWidget *socket;
52 gchar *filename;
55 static MimeViewerFactory dillo_viewer_factory;
57 static GtkWidget *dillo_get_widget(MimeViewer *_viewer)
59 DilloViewer *viewer = (DilloViewer *) _viewer;
61 debug_print("dillo_get_widget\n");
63 return GTK_WIDGET(viewer->widget);
66 static gboolean socket_destroy_cb(GObject *object, gpointer data)
68 DilloViewer *viewer = (DilloViewer *) data;
69 debug_print("Destroyed dillo socket %p\n", viewer->socket);
70 viewer->socket = NULL;
71 return FALSE;
74 static gboolean load_images(DilloViewer *viewer)
76 MessageView *messageview = ((MimeViewer *)viewer)->mimeview
77 ? ((MimeViewer *)viewer)->mimeview->messageview
78 : NULL;
79 MsgInfo *msginfo = NULL;
80 gchar *ab_folderpath = NULL;
82 if (messageview == NULL)
83 return FALSE;
85 msginfo = messageview->msginfo;
87 if (msginfo == NULL)
88 return FALSE;
90 /* don't load remote images, period. */
91 if (dillo_prefs.local)
92 return FALSE;
94 /* don't do whitelisting -> load images */
95 if (!dillo_prefs.whitelist_ab)
96 return TRUE;
98 if (*dillo_prefs.whitelist_ab_folder != '\0' &&
99 strcasecmp(dillo_prefs.whitelist_ab_folder, _("Any")) != 0)
100 ab_folderpath = dillo_prefs.whitelist_ab_folder;
102 start_address_completion(ab_folderpath);
104 /* do whitelisting -> check sender */
105 if (found_in_addressbook(msginfo->from)) {
106 end_address_completion();
107 return TRUE;
110 end_address_completion();
111 return FALSE;
114 static void dillo_show_mimepart(MimeViewer *_viewer,
115 const gchar *infile,
116 MimeInfo *partinfo)
118 DilloViewer *viewer = (DilloViewer *) _viewer;
119 GdkWindow *gdkwin;
121 debug_print("dillo_show_mimepart\n");
123 if (viewer->filename != NULL) {
124 claws_unlink(viewer->filename);
125 g_free(viewer->filename);
128 viewer->filename = procmime_get_tmp_file_name(partinfo);
130 if (!(procmime_get_part(viewer->filename, partinfo) < 0)) {
131 gchar *cmd;
133 if (viewer->socket)
134 gtk_widget_destroy(viewer->socket);
135 viewer->socket = gtk_socket_new();
136 debug_print("Adding dillo socket %p", viewer->socket);
137 gtk_container_add(GTK_CONTAINER(viewer->widget),
138 viewer->socket);
139 gtk_widget_realize(viewer->socket);
140 gtk_widget_show(viewer->socket);
141 g_signal_connect(G_OBJECT(viewer->socket), "destroy",
142 G_CALLBACK(socket_destroy_cb), viewer);
144 gdkwin = gtk_widget_get_window(viewer->socket);
145 cmd = g_strdup_printf("dillo %s%s-x %d \"%s\"",
146 (!load_images(viewer) ? "-l " : ""),
147 (dillo_prefs.full ? "-f " : ""),
148 (gint) GDK_WINDOW_XID(gdkwin),
149 viewer->filename);
151 execute_command_line(cmd, TRUE, NULL);
152 g_free(cmd);
156 static void dillo_clear_viewer(MimeViewer *_viewer)
158 DilloViewer *viewer = (DilloViewer *) _viewer;
160 debug_print("dillo_clear_viewer\n");
161 debug_print("Removing dillo socket %p\n", viewer->socket);
163 if (viewer->socket) {
164 gtk_widget_destroy(viewer->socket);
168 static void dillo_destroy_viewer(MimeViewer *_viewer)
170 DilloViewer *viewer = (DilloViewer *) _viewer;
172 debug_print("dillo_destroy_viewer\n");
174 if (viewer->socket) {
175 gtk_widget_destroy(viewer->socket);
178 g_object_unref(GTK_WIDGET(viewer->widget));
179 claws_unlink(viewer->filename);
180 g_free(viewer->filename);
181 g_free(viewer);
184 static MimeViewer *dillo_viewer_create(void)
186 DilloViewer *viewer;
188 debug_print("dillo_viewer_create\n");
190 viewer = g_new0(DilloViewer, 1);
191 viewer->mimeviewer.factory = &dillo_viewer_factory;
192 viewer->mimeviewer.get_widget = dillo_get_widget;
193 viewer->mimeviewer.show_mimepart = dillo_show_mimepart;
194 viewer->mimeviewer.clear_viewer = dillo_clear_viewer;
195 viewer->mimeviewer.destroy_viewer = dillo_destroy_viewer;
196 viewer->mimeviewer.get_selection = NULL;
197 viewer->widget = gtk_event_box_new();
199 gtk_widget_show(viewer->widget);
200 g_object_ref(viewer->widget);
202 viewer->filename = NULL;
204 return (MimeViewer *) viewer;
207 static gchar *content_types[] =
208 {"text/html", NULL};
210 static MimeViewerFactory dillo_viewer_factory =
212 content_types,
215 dillo_viewer_create,
218 gint plugin_init(gchar **error)
220 gchar *dillo_path = NULL;
221 if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
222 VERSION_NUMERIC, PLUGIN_NAME, error))
223 return -1;
225 if ((dillo_path = g_find_program_in_path("dillo")) == NULL) {
226 *error = g_strdup(_("Can't find the dillo executable in PATH. Is it installed?"));
227 return -1;
229 g_free(dillo_path);
231 dillo_prefs_init();
233 mimeview_register_viewer_factory(&dillo_viewer_factory);
235 return 0;
238 gboolean plugin_done(void)
240 mimeview_unregister_viewer_factory(&dillo_viewer_factory);
242 dillo_prefs_done();
243 return TRUE;
246 const gchar *plugin_name(void)
248 return PLUGIN_NAME;
251 const gchar *plugin_desc(void)
253 return _("This plugin renders HTML mail using the Dillo "
254 "web browser.\n"
255 "\n"
256 "Options can be found in /Configuration/Preferences/Plugins/Dillo Browser");
259 const gchar *plugin_type(void)
261 return "GTK3";
264 const gchar *plugin_licence(void)
266 return "GPL3+";
269 const gchar *plugin_version(void)
271 return VERSION;
274 struct PluginFeature *plugin_provides(void)
276 static struct PluginFeature features[] =
277 { {PLUGIN_MIMEVIEWER, "text/html"},
278 {PLUGIN_NOTHING, NULL}};
279 return features;