/*
* Claws Mail -- A GTK+ based, lightweight, and fast e-mail client
* == Fancy Plugin ==
- * Copyright(C) 1999-2013 the Claws Mail Team
- * This file Copyright (C) 2009-2013 Salvatore De Paolis
+ * Copyright(C) 1999-2015 the Claws Mail Team
+ * This file Copyright (C) 2009-2014 Salvatore De Paolis
* <iwkse@claws-mail.org> and the Claws Mail Team
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
+ *
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write tothe Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <alertpanel.h>
#include <printing.h>
-
+#include <webkit/webkithittestresult.h>
static void
load_start_cb (WebKitWebView *view, gint progress, FancyViewer *viewer);
"enable-plugins", viewer->override_prefs_plugins,
"enable-java-applet", viewer->override_prefs_java,
"enable-dns-prefetching", viewer->override_prefs_remote_content,
+ "user-stylesheet-uri", viewer->override_stylesheet,
#ifdef G_OS_WIN32
"default-font-family", "Arial",
"cursive-font-family", "Comic Sans MS",
"sans-serif-font-family", "Arial",
"serif-font-family", "Times New Roman",
#endif
- NULL);
+ NULL);
webkit_web_view_set_settings(viewer->view, viewer->settings);
}
viewer->override_prefs_scripts = fancy_prefs.enable_scripts;
viewer->override_prefs_plugins = fancy_prefs.enable_plugins;
viewer->override_prefs_java = fancy_prefs.enable_java;
+ viewer->override_stylesheet = g_strconcat("file://", fancy_prefs.stylesheet, NULL);
g_signal_handlers_block_by_func(G_OBJECT(viewer->enable_images),
fancy_auto_load_images_activated, viewer);
: NULL;
MimeInfo *partinfo = viewer->to_load;
- messageview->updating = TRUE;
+ if (messageview) {
+ messageview->updating = TRUE;
+ NoticeView *noticeview = messageview->noticeview;
+ noticeview_hide(noticeview);
+ }
if (viewer->filename != NULL) {
g_unlink(viewer->filename);
viewer->filename = NULL;
}
- if (messageview) {
- NoticeView *noticeview = messageview->noticeview;
- noticeview_hide(noticeview);
- }
if (partinfo)
viewer->filename = procmime_get_tmp_file_name(partinfo);
debug_print("filename: %s\n", viewer->filename);
}
else {
const gchar *charset = NULL;
- if (_viewer && _viewer->mimeview &&
- _viewer->mimeview->messageview->forced_charset)
+ if (messageview && messageview->forced_charset)
charset = _viewer->mimeview->messageview->forced_charset;
else
charset = procmime_mimeinfo_get_parameter(partinfo, "charset");
{
FancyViewer *viewer = (FancyViewer *) _viewer;
- if (viewer->tag > 0) {
- gtk_timeout_remove(viewer->tag);
- viewer->tag = -1;
- if (viewer->loading) {
- viewer->stop_previous = TRUE;
- }
- }
-
- viewer->tag = g_timeout_add(5, (GSourceFunc)fancy_show_mimepart_real, viewer);
+ g_timeout_add(5, (GSourceFunc)fancy_show_mimepart_real, viewer);
return FALSE;
}
}
if ((err = procmime_get_part(filename, partinfo)) < 0)
alertpanel_error(_("Couldn't save the part of multipart message: %s"),
- strerror(-err));
+ g_strerror(-err));
gchar *file_uri = g_filename_to_uri(filename, NULL, NULL);
webkit_network_request_set_uri(request, file_uri);
g_free(file_uri);
webkit_network_request_set_uri(request, "about:blank");
}
else
- debug_print("Starting request of %d %s\n", strlen(uri), uri);
+ debug_print("Starting request of %zu %s\n", strlen(uri), uri);
}
static gboolean fancy_text_search(MimeViewer *_viewer, gboolean backward,
static gboolean release_button_cb (WebKitWebView *view, GdkEvent *ev,
FancyViewer *viewer)
{
+ gint type, x, y;
+ WebKitHitTestResult *result;
+
if (ev->button.button == 1 && viewer->cur_link && viewer->override_prefs_external) {
+ result = webkit_web_view_get_hit_test_result(view, (GdkEventButton *)ev);
+ g_object_get(G_OBJECT(result),
+ "context", &type,
+ "x", &x, "y", &y,
+ NULL);
+
+ /* If the link we are hovering over is also part of a text
+ * selection, we only want to open it if this button release
+ * is part of a simple click, not a press-drag-release chain. */
+ if (type & WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION
+ && (x != viewer->click_x || y != viewer->click_y))
+ return FALSE;
+
open_uri(viewer->cur_link, prefs_common_get_uri_cmd());
return TRUE;
}
return FALSE;
}
+
+static gboolean press_button_cb (WebKitWebView *view, GdkEvent *ev,
+ FancyViewer *viewer)
+{
+ gint type;
+ WebKitHitTestResult *result =
+ webkit_web_view_get_hit_test_result(view, (GdkEventButton *)ev);
+
+ g_object_get(G_OBJECT(result),
+ "context", &type,
+ "x", &viewer->click_x, "y", &viewer->click_y,
+ NULL);
+
+#if WEBKIT_CHECK_VERSION(1,5,1)
+ viewer->doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(viewer->view));
+ viewer->window = webkit_dom_document_get_default_view (viewer->doc);
+ viewer->selection = webkit_dom_dom_window_get_selection (viewer->window);
+ if (viewer->selection == NULL)
+ return FALSE;
+
+ if (type & WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION)
+ return FALSE;
+
+ webkit_dom_dom_selection_empty(viewer->selection);
+#else
+# error "How do you clear webkit selection before 1.5.1? Can't find any API docs that old."
+#endif
+ return FALSE;
+}
+
static void zoom_100_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer)
{
gtk_widget_grab_focus(widget);
viewer->settings = webkit_web_settings_new();
g_object_set(viewer->settings, "user-agent", "Fancy Viewer", NULL);
viewer->scrollwin = gtk_scrolled_window_new(NULL, NULL);
- viewer->tag = -1;
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(viewer->scrollwin),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(viewer->scrollwin),
G_CALLBACK(resource_request_starting_cb), viewer);
g_signal_connect(G_OBJECT(viewer->view), "populate-popup",
G_CALLBACK(populate_popup_cb), viewer);
+ g_signal_connect(G_OBJECT(viewer->view), "button-press-event",
+ G_CALLBACK(press_button_cb), viewer);
g_signal_connect(G_OBJECT(viewer->view), "button-release-event",
G_CALLBACK(release_button_cb), viewer);
g_signal_connect(G_OBJECT(viewer->ev_zoom_100), "button-press-event",
gchar *directory = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
"fancy", NULL);
if (!is_dir_exist(directory))
- make_dir (directory);
+ if (make_dir (directory) < 0) {
+ g_free(directory);
+ return -1;
+ }
g_free(directory);
fancy_prefs_init();