From 38858414737fc47e183c48b451d38587d4d7c53b Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Thu, 1 Aug 2019 22:12:23 +0300 Subject: [PATCH] mug: quick & dirty port to webkit2gtk3 --- configure.ac | 12 ++-- toys/mug/Makefile.am | 5 +- toys/mug/mu-msg-body-view.c | 110 ++++++++++++++--------------------- toys/mug/mu-msg-body-view.h | 3 +- toys/mug/mu-msg-view.c | 18 +++--- toys/mug/mug-msg-list-view.c | 12 ++-- toys/mug/mug.c | 2 +- 7 files changed, 69 insertions(+), 93 deletions(-) diff --git a/configure.ac b/configure.ac index 597966d3..b7647ec4 100644 --- a/configure.ac +++ b/configure.ac @@ -197,11 +197,13 @@ AM_CONDITIONAL(HAVE_GTK,[test "x$have_gtk" = "xyes"]) # webkit? needed for the fancy web widget # use --disable-webkit to disable it, even if you have it +# +# and note this is just a toy, not for distribution. AC_ARG_ENABLE([webkit],AS_HELP_STRING([--disable-webkit],[Disable webkit])) AS_IF([test "x$enable_webkit" != "xno"],[ - PKG_CHECK_MODULES(WEBKIT,webkitgtk-3.0 >= 1.8.0,[have_webkit=yes],[have_webkit=no]) + PKG_CHECK_MODULES(WEBKIT,webkit2gtk-4.0 >= 2.0, [have_webkit=yes],[have_webkit=no]) AS_IF([test "x$have_webkit" = "xyes"],[ - webkit_version="$($PKG_CONFIG --modversion webkitgtk-3.0)"]) + webkit_version="$($PKG_CONFIG --modversion webkit2gtk-4.0)"]) ]) AM_CONDITIONAL(HAVE_WEBKIT, [test "x$have_webkit" = "xyes"]) AM_CONDITIONAL(BUILD_GUI,[test "x$have_webkit" = "xyes" -a "x$have_gtk" = "xyes"]) @@ -288,7 +290,7 @@ echo "Json-Glib version : $json_glib_version" AM_COND_IF([BUILD_GUI],[ echo "GTK+ version : $gtk_version" -echo "Webkit version : $webkit_version" +echo "Webkit2/GTK+ version : $webkit_version" ]) AM_COND_IF([BUILD_GUILE],[ @@ -299,10 +301,6 @@ if test "x$build_mu4e" = "xyes"; then echo "Emacs version : $emacs_version" fi -#AM_COND_IF([BUILD_PERL],[ -#echo "Perl interface version : $perl_version" -#]) - echo echo "Have wordexp : $ac_cv_header_wordexp_h" echo "Build mu4e emacs frontend : $build_mu4e" diff --git a/toys/mug/Makefile.am b/toys/mug/Makefile.am index e0b6881b..c29fbd04 100644 --- a/toys/mug/Makefile.am +++ b/toys/mug/Makefile.am @@ -1,4 +1,4 @@ -## Copyright (C) 2008-2017 Dirk-Jan C. Binnema +## Copyright (C) 2008-2019 Dirk-Jan C. Binnema ## ## 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 @@ -36,6 +36,9 @@ AM_CFLAGS= \ AM_CXXFLAGS=$(WARN_CXXFLAGS) +# +# Distributors: this is a _toy_, not for distribution. the "noinst_" says enough +# noinst_PROGRAMS= \ mug diff --git a/toys/mug/mu-msg-body-view.c b/toys/mug/mu-msg-body-view.c index c98fa9af..28b37e18 100644 --- a/toys/mug/mu-msg-body-view.c +++ b/toys/mug/mu-msg-body-view.c @@ -16,10 +16,7 @@ ** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ** */ -#include -#include -#include -#include + #include "mu-msg-body-view.h" #include @@ -46,10 +43,11 @@ enum { struct _MuMsgBodyViewPrivate { - WebKitWebSettings *_settings; + WebKitSettings *_settings; MuMsg *_msg; ViewMode _view_mode; }; + #define MU_MSG_BODY_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ MU_TYPE_MSG_BODY_VIEW, \ MuMsgBodyViewPrivate)) @@ -136,62 +134,54 @@ save_file_for_cid (MuMsg *msg, const char* cid) static gboolean -on_navigation_policy_decision_requested (MuMsgBodyView *self, WebKitWebFrame *frame, - WebKitNetworkRequest *request, - WebKitWebNavigationAction *nav_action, - WebKitWebPolicyDecision *policy_decision, +on_navigation_policy_decision_requested (MuMsgBodyView *self, + WebKitPolicyDecision *decision, + WebKitPolicyDecisionType decision_type, gpointer data) { - const char* uri; - WebKitWebNavigationReason reason; + /* const char* uri; */ - uri = webkit_network_request_get_uri (request); - reason = webkit_web_navigation_action_get_reason (nav_action); + /* uri = webkit_network_request_get_uri (request); */ - /* if it wasn't a user click, don't the navigation */ - if (reason != WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED) { - webkit_web_policy_decision_ignore (policy_decision); + /* XXX if it wasn't a user click, don't navigate */ + if (decision_type != WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION) { + webkit_policy_decision_ignore (decision); return TRUE; } - /* we handle links clicked ourselves, no need for navigation */ - webkit_web_policy_decision_ignore (policy_decision); - /* if there are 'cmd:" links in the body text of - * mu-internal messages (ie., notification from mu, not real - * e-mail messages), we emit the 'action requested' - * signal. this allows e.g triggering a database refresh from - * a Refresh link - */ - if (g_ascii_strncasecmp (uri, "cmd:", 4) == 0) { - if (self->_priv->_view_mode == VIEW_MODE_NOTE) { - g_signal_emit (G_OBJECT(self), - signals[ACTION_REQUESTED], 0, - uri + 4); - } - return TRUE; - } + /* /\* if there are 'cmd:" links in the body text of */ + /* * mu-internal messages (ie., notification from mu, not real */ + /* * e-mail messages), we emit the 'action requested' */ + /* * signal. this allows e.g triggering a database refresh from */ + /* * a Refresh link */ + /* *\/ */ + /* if (g_ascii_strncasecmp (uri, "cmd:", 4) == 0) { */ + /* if (self->_priv->_view_mode == VIEW_MODE_NOTE) { */ + /* g_signal_emit (G_OBJECT(self), */ + /* signals[ACTION_REQUESTED], 0, */ + /* uri + 4); */ + /* } */ + /* return TRUE; */ + /* } */ - /* don't try to play files on our local file system, this is not something - * external content should do.*/ - if (!mu_util_is_local_file(uri)) - mu_util_play (uri, FALSE, TRUE, NULL); + /* /\* don't try to play files on our local file system, this is not something */ + /* * external content should do.*\/ */ + /* if (!mu_util_is_local_file(uri)) */ + /* mu_util_play (uri, FALSE, TRUE, NULL); */ return TRUE; } - - static void -on_resource_request_starting (MuMsgBodyView *self, WebKitWebFrame *frame, - WebKitWebResource *resource, WebKitNetworkRequest *request, - WebKitNetworkResponse *response, gpointer data) +on_resource_load_started (MuMsgBodyView *self, WebKitWebResource *resource, + WebKitURIRequest *request, gpointer data) { - const char* uri; - MuMsg *msg; + const char* uri; + MuMsg *msg; msg = self->_priv->_msg; - uri = webkit_network_request_get_uri (request); + uri = webkit_uri_request_get_uri (request); /* g_warning ("%s: %s", __func__, uri); */ @@ -201,7 +191,7 @@ on_resource_request_starting (MuMsgBodyView *self, WebKitWebFrame *frame, if (filepath) { gchar *fileuri; fileuri = g_strdup_printf ("file://%s", filepath); - webkit_network_request_set_uri (request, fileuri); + webkit_uri_request_set_uri (request, fileuri); g_free (fileuri); g_free (filepath); } @@ -276,24 +266,18 @@ mu_msg_body_view_init (MuMsgBodyView *obj) obj->_priv->_msg = NULL; obj->_priv->_view_mode = VIEW_MODE_NONE; - obj->_priv->_settings = webkit_web_settings_new (); + obj->_priv->_settings = webkit_settings_new (); g_object_set (G_OBJECT(obj->_priv->_settings), - "enable-scripts", FALSE, + "enable-javascript", FALSE, "auto-load-images", TRUE, "enable-plugins", FALSE, NULL); - webkit_web_view_set_settings (WEBKIT_WEB_VIEW(obj), - obj->_priv->_settings); - webkit_web_view_set_editable (WEBKIT_WEB_VIEW(obj), FALSE); + webkit_web_view_set_settings (WEBKIT_WEB_VIEW(obj), obj->_priv->_settings); /* to support cid: */ - g_signal_connect (obj, "resource-request-starting", - G_CALLBACK (on_resource_request_starting), NULL); - /* handle navigation requests */ - g_signal_connect (obj, "navigation-policy-decision-requested", - G_CALLBACK (on_navigation_policy_decision_requested), NULL); - /* handle right-button clicks */ + g_signal_connect (obj, "resource-load-started", + G_CALLBACK (on_resource_load_started), NULL); g_signal_connect (obj, "button-press-event", G_CALLBACK(on_button_press_event), NULL); } @@ -324,11 +308,9 @@ set_html (MuMsgBodyView *self, const char* html) { g_return_if_fail (MU_IS_MSG_BODY_VIEW(self)); - webkit_web_view_load_string (WEBKIT_WEB_VIEW(self), - html ? html : "", - "text/html", - "utf-8", - ""); + webkit_web_view_load_html (WEBKIT_WEB_VIEW(self), + html ? html : "", + NULL); } static void @@ -336,11 +318,7 @@ set_text (MuMsgBodyView *self, const char* txt) { g_return_if_fail (MU_IS_MSG_BODY_VIEW(self)); - webkit_web_view_load_string (WEBKIT_WEB_VIEW(self), - txt ? txt : "", - "text/plain", - "utf-8", - ""); + webkit_web_view_load_plain_text (WEBKIT_WEB_VIEW(self), txt ? txt : ""); } void diff --git a/toys/mug/mu-msg-body-view.h b/toys/mug/mu-msg-body-view.h index 60e2bd03..f8659f8f 100644 --- a/toys/mug/mu-msg-body-view.h +++ b/toys/mug/mu-msg-body-view.h @@ -20,7 +20,7 @@ #ifndef __MU_MSG_BODY_VIEW_H__ #define __MU_MSG_BODY_VIEW_H__ -#include +#include #include G_BEGIN_DECLS @@ -67,4 +67,3 @@ void mu_msg_body_view_set_message_source (MuMsgBodyView *self, MuMsg *msg); G_END_DECLS #endif /* __MU_MSG_BODY_VIEW_H__ */ - diff --git a/toys/mug/mu-msg-view.c b/toys/mug/mu-msg-view.c index 8b4fa88f..b2b19ced 100644 --- a/toys/mug/mu-msg-view.c +++ b/toys/mug/mu-msg-view.c @@ -146,18 +146,20 @@ mu_msg_view_init (MuMsgView *self) GTK_ORIENTATION_VERTICAL); self->_priv = MU_MSG_VIEW_GET_PRIVATE(self); - self->_priv->_msg = NULL; - self->_priv->_headers = mu_msg_header_view_new (); - self->_priv->_attach = mu_msg_attach_view_new (); - self->_priv->_attachexpander = gtk_expander_new_with_mnemonic + + self->_priv->_msg = NULL; + self->_priv->_headers = mu_msg_header_view_new (); + self->_priv->_attach = mu_msg_attach_view_new (); + self->_priv->_attachexpander = gtk_expander_new_with_mnemonic ("_Attachments"); - gtk_container_add (GTK_CONTAINER(self->_priv->_attachexpander), + + gtk_container_add (GTK_CONTAINER(self->_priv->_attachexpander), self->_priv->_attach); g_signal_connect (self->_priv->_attach, "attach-activated", G_CALLBACK(on_attach_activated), self); - self->_priv->_body = mu_msg_body_view_new (); + self->_priv->_body = mu_msg_body_view_new (); g_signal_connect (self->_priv->_body, "action-requested", G_CALLBACK(on_body_action_requested), @@ -167,10 +169,6 @@ mu_msg_view_init (MuMsgView *self) FALSE, FALSE, 2); gtk_box_pack_start (GTK_BOX(self), self->_priv->_attachexpander, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX(self), - gtk_separator_new(GTK_ORIENTATION_HORIZONTAL), - TRUE,TRUE,0); - gtk_box_pack_start (GTK_BOX(self), self->_priv->_body, TRUE, TRUE, 2); } diff --git a/toys/mug/mug-msg-list-view.c b/toys/mug/mug-msg-list-view.c index 5110622a..99eaea9f 100644 --- a/toys/mug/mug-msg-list-view.c +++ b/toys/mug/mug-msg-list-view.c @@ -1,6 +1,6 @@ /* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/ /* -** Copyright (C) 2008-2013 Dirk-Jan C. Binnema +** Copyright (C) 2008-2019 Dirk-Jan C. Binnema ** ** 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 @@ -309,10 +309,10 @@ static MugError mu_result_to_mug_error (MuError r) { switch (r) { - case MU_ERROR_XAPIAN_DIR_NOT_ACCESSIBLE: - return MUG_ERROR_XAPIAN_DIR; - case MU_ERROR_XAPIAN_VERSION_MISMATCH: - return MUG_ERROR_XAPIAN_NOT_UPTODATE; + /* case MU_ERROR_XAPIAN_DIR_NOT_ACCESSIBLE: */ + /* return MUG_ERROR_XAPIAN_DIR; */ + /* case MU_ERROR_XAPIAN_VERSION_MISMATCH: */ + /* return MUG_ERROR_XAPIAN_NOT_UPTODATE; */ case MU_ERROR_XAPIAN_QUERY: return MUG_ERROR_QUERY; default: @@ -330,7 +330,7 @@ run_query (const char *xpath, const char *query, MugMsgListView * self) MuQueryFlags qflags; err = NULL; - if (! (store = mu_store_new_read_only (xpath, &err)) || + if (! (store = mu_store_new_readable (xpath, &err)) || ! (xapian = mu_query_new (store, &err))) { if (store) mu_store_unref (store); diff --git a/toys/mug/mug.c b/toys/mug/mug.c index c6b15052..eab0ac06 100644 --- a/toys/mug/mug.c +++ b/toys/mug/mug.c @@ -26,7 +26,7 @@ #include /* for memset */ #include -#include +#include #include #include