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/>.
22 #include "claws-features.h"
28 #include <glib/gi18n.h>
33 #include "common/claws.h"
34 #include "common/version.h"
36 #include "file-utils.h"
39 #include "addr_compl.h"
41 #include "dillo_prefs.h"
43 #define PLUGIN_NAME (_("Dillo HTML Viewer"))
45 typedef struct _DilloViewer DilloViewer
;
49 MimeViewer mimeviewer
;
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
;
74 static gboolean
load_images(DilloViewer
*viewer
)
76 MessageView
*messageview
= ((MimeViewer
*)viewer
)->mimeview
77 ? ((MimeViewer
*)viewer
)->mimeview
->messageview
79 MsgInfo
*msginfo
= NULL
;
80 gchar
*ab_folderpath
= NULL
;
82 if (messageview
== NULL
)
85 msginfo
= messageview
->msginfo
;
90 /* don't load remote images, period. */
91 if (dillo_prefs
.local
)
94 /* don't do whitelisting -> load images */
95 if (!dillo_prefs
.whitelist_ab
)
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();
110 end_address_completion();
114 static void dillo_show_mimepart(MimeViewer
*_viewer
,
118 DilloViewer
*viewer
= (DilloViewer
*) _viewer
;
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)) {
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
),
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
),
151 execute_command_line(cmd
, TRUE
, NULL
);
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
);
184 static MimeViewer
*dillo_viewer_create(void)
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
[] =
210 static MimeViewerFactory dillo_viewer_factory
=
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
))
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?"));
233 mimeview_register_viewer_factory(&dillo_viewer_factory
);
238 gboolean
plugin_done(void)
240 mimeview_unregister_viewer_factory(&dillo_viewer_factory
);
246 const gchar
*plugin_name(void)
251 const gchar
*plugin_desc(void)
253 return _("This plugin renders HTML mail using the Dillo "
256 "Options can be found in /Configuration/Preferences/Plugins/Dillo Browser");
259 const gchar
*plugin_type(void)
264 const gchar
*plugin_licence(void)
269 const gchar
*plugin_version(void)
274 struct PluginFeature
*plugin_provides(void)
276 static struct PluginFeature features
[] =
277 { {PLUGIN_MIMEVIEWER
, "text/html"},
278 {PLUGIN_NOTHING
, NULL
}};