Commit 332789ff authored by Tomas Popela's avatar Tomas Popela Committed by Milan Crha

Bug 751588 - Port to WebKit2

parent 76c34f7d
......@@ -71,6 +71,7 @@ SUBDIRS = \
mail \
calendar \
art \
web-extensions \
plugins \
modules \
$(MAINT_SUBDIR) \
......
......@@ -995,7 +995,7 @@ fill_in_email (EContactEditor *editor)
email_location = eab_get_email_type_index (attr);
slot = get_ui_slot (attr);
if (slot < 1)
slot = EMAIL_SLOTS + 1; //add at the end
slot = EMAIL_SLOTS + 1; /* add at the end */
gtk_list_store_append (data_store, &iter);
gtk_list_store_set (data_store, &iter,
......@@ -2103,7 +2103,7 @@ fill_in_im (EContactEditor *editor)
slot = get_ui_slot (attr);
if (slot < 0)
slot = IM_SLOTS + 1; //attach at the end
slot = IM_SLOTS + 1; /* attach at the end */
gtk_list_store_append (data_store, &iter);
gtk_list_store_set (data_store, &iter,
......
......@@ -28,7 +28,7 @@
#include <string.h>
#include <glib/gi18n.h>
#include <webkit/webkit.h>
#include <webkit2/webkit2.h>
#include "e-contact-map.h"
#include "eab-contact-formatter.h"
......@@ -386,19 +386,31 @@ contact_display_object_requested (WebKitWebView *web_view,
#endif
static void
contact_display_load_status_changed (WebKitWebView *web_view,
GParamSpec *pspec,
contact_display_load_changed (WebKitWebView *web_view,
WebKitLoadEvent load_event,
gpointer user_data)
{
WebKitLoadStatus load_status;
WebKitDOMDocument *document;
GDBusProxy *web_extension;
GVariant* result;
load_status = webkit_web_view_get_load_status (web_view);
if (load_status != WEBKIT_LOAD_FINISHED)
if (load_event != WEBKIT_LOAD_FINISHED)
return;
document = webkit_web_view_get_dom_document (web_view);
eab_contact_formatter_bind_dom (document);
web_extension = e_web_view_get_web_extension_proxy (E_WEB_VIEW (web_view));
if (web_extension) {
result = g_dbus_proxy_call_sync (
web_extension,
"EABContactFormatterBindDOM",
g_variant_new (
"(t)",
webkit_web_view_get_page_id (web_view)),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL, /* cancellable */
NULL);
if (result)
g_variant_unref (result);
}
}
static void
......@@ -514,15 +526,12 @@ eab_contact_display_init (EABContactDisplay *display)
G_CALLBACK (contact_display_object_requested), display);
#endif
e_signal_connect_notify (
web_view, "notify::load-status",
G_CALLBACK (contact_display_load_status_changed), NULL);
web_view, "notify::load-changed",
G_CALLBACK (contact_display_load_changed), NULL);
g_signal_connect (
web_view, "style-updated",
G_CALLBACK (load_contact), NULL);
e_web_view_install_request_handler (E_WEB_VIEW (display), E_TYPE_FILE_REQUEST);
e_web_view_install_request_handler (E_WEB_VIEW (display), E_TYPE_STOCK_REQUEST);
action_group = gtk_action_group_new ("internal-mailto");
gtk_action_group_set_translation_domain (action_group, domain);
gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
......
......@@ -1383,64 +1383,3 @@ eab_contact_formatter_format_contact (EABContactFormatter *formatter,
else
render_compact (formatter, contact, output_buffer);
}
static void
collapse_contacts_list (WebKitDOMEventTarget *event_target,
WebKitDOMEvent *event,
gpointer user_data)
{
WebKitDOMDocument *document;
WebKitDOMElement *list;
gchar *id, *list_id;
gchar *imagesdir, *src;
gboolean hidden;
document = user_data;
id = webkit_dom_element_get_id (WEBKIT_DOM_ELEMENT (event_target));
list_id = g_strconcat ("list-", id, NULL);
list = webkit_dom_document_get_element_by_id (document, list_id);
g_free (id);
g_free (list_id);
if (list == NULL)
return;
imagesdir = g_filename_to_uri (EVOLUTION_IMAGESDIR, NULL, NULL);
hidden = webkit_dom_html_element_get_hidden (WEBKIT_DOM_HTML_ELEMENT (list));
if (hidden)
src = g_strdup_printf ("evo-file://%s/minus.png", imagesdir);
else
src = g_strdup_printf ("evo-file://%s/plus.png", imagesdir);
webkit_dom_html_element_set_hidden (
WEBKIT_DOM_HTML_ELEMENT (list), !hidden);
webkit_dom_html_image_element_set_src (
WEBKIT_DOM_HTML_IMAGE_ELEMENT (event_target), src);
g_free (src);
g_free (imagesdir);
}
void
eab_contact_formatter_bind_dom (WebKitDOMDocument *document)
{
WebKitDOMNodeList *nodes;
gulong ii, length;
nodes = webkit_dom_document_get_elements_by_class_name (
document, "_evo_collapse_button");
length = webkit_dom_node_list_get_length (nodes);
for (ii = 0; ii < length; ii++) {
WebKitDOMNode *node;
node = webkit_dom_node_list_item (nodes, ii);
webkit_dom_event_target_add_event_listener (
WEBKIT_DOM_EVENT_TARGET (node), "click",
G_CALLBACK (collapse_contacts_list), FALSE, document);
}
g_object_unref (nodes);
}
......@@ -75,7 +75,6 @@ void eab_contact_formatter_format_contact
(EABContactFormatter *formatter,
EContact *contact,
GString *output_buffer);
void eab_contact_formatter_bind_dom (WebKitDOMDocument *document);
G_END_DECLS
......
......@@ -177,17 +177,7 @@ ecep_attachments_attachment_loaded_cb (EAttachment *attachment,
}
if (!e_attachment_load_finish (attachment, result, &error)) {
GtkTreeRowReference *reference;
reference = e_attachment_get_reference (attachment);
if (gtk_tree_row_reference_valid (reference)) {
GtkTreeModel *model;
model = gtk_tree_row_reference_get_model (reference);
e_attachment_store_remove_attachment (
E_ATTACHMENT_STORE (model), attachment);
}
g_signal_emit_by_name (attachment, "load-failed", NULL);
/* Ignore cancellations. */
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
......
......@@ -1639,17 +1639,18 @@ find_enabled_identity (ESourceRegistry *registry,
return mail_identity;
}
static void
setup_from (ECalComponentItipMethod method,
static gchar *
get_identity_uid_for_from (EShell *shell,
ECalComponentItipMethod method,
ECalComponent *comp,
ECalClient *cal_client,
EComposerHeaderTable *table)
ECalClient *cal_client)
{
EClientCache *client_cache;
ESourceRegistry *registry;
ESource *source = NULL;
gchar *identity_uid = NULL;
client_cache = e_composer_header_table_ref_client_cache (table);
client_cache = e_shell_get_client_cache (shell);
registry = e_client_cache_ref_registry (client_cache);
/* always use organizer's email when user is an organizer */
......@@ -1673,16 +1674,14 @@ setup_from (ECalComponentItipMethod method,
}
if (source != NULL) {
const gchar *uid;
uid = e_source_get_uid (source);
e_composer_header_table_set_identity_uid (table, uid);
identity_uid = g_strdup (e_source_get_uid (source));
g_object_unref (source);
}
g_object_unref (client_cache);
g_object_unref (registry);
return identity_uid;
}
typedef struct {
......@@ -1771,83 +1770,64 @@ itip_send_component_begin (ItipSendComponentData *isc,
}
}
typedef struct _CreateComposerData {
gchar *identity_uid;
EDestination **destinations;
gchar *subject;
gchar *ical_string;
gchar *content_type;
gchar *event_body_text;
GSList *attachments_list;
ECalComponent *comp;
gboolean show_only;
} CreateComposerData;
static void
itip_send_component_complete (ItipSendComponentData *isc)
itip_send_component_composer_created_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
GSettings *settings;
EMsgComposer *composer;
CreateComposerData *ccd = user_data;
EComposerHeaderTable *table;
EDestination **destinations;
ECalComponent *comp = NULL;
icalcomponent *top_level = NULL;
icaltimezone *default_zone;
gchar *ical_string = NULL;
gchar *content_type = NULL;
gchar *subject = NULL;
EMsgComposer *composer;
GSettings *settings;
gboolean use_24hour_format;
GError *error = NULL;
g_return_if_fail (isc != NULL);
g_return_if_fail (ccd != NULL);
if (isc->completed)
composer = e_msg_composer_new_finish (result, &error);
if (error) {
g_warning ("%s: Failed to create msg composer: %s", G_STRFUNC, error->message);
g_clear_error (&error);
return;
isc->success = FALSE;
}
settings = e_util_ref_settings ("org.gnome.evolution.calendar");
use_24hour_format = g_settings_get_boolean (settings, "use-24hour-format");
g_object_unref (settings);
default_zone = calendar_config_get_icaltimezone ();
/* Tidy up the comp */
comp = comp_compliant (
isc->registry, isc->method, isc->send_comp, isc->cal_client,
isc->zones, default_zone, isc->strip_alarms);
if (comp == NULL)
goto cleanup;
/* Recipients */
destinations = comp_to_list (
isc->registry, isc->method, comp, isc->users, FALSE,
isc->only_new_attendees ? g_object_get_data (
G_OBJECT (isc->send_comp), "new-attendees") : NULL);
if (isc->method != E_CAL_COMPONENT_METHOD_PUBLISH) {
if (destinations == NULL) {
/* We sent them all via the server */
isc->success = TRUE;
goto cleanup;
}
}
/* Subject information */
subject = comp_subject (isc->registry, isc->method, comp);
composer = e_msg_composer_new (e_shell_get_default ());
table = e_msg_composer_get_header_table (composer);
setup_from (isc->method, isc->send_comp, isc->cal_client, table);
e_composer_header_table_set_subject (table, subject);
e_composer_header_table_set_destinations_to (table, destinations);
if (ccd->identity_uid)
e_composer_header_table_set_identity_uid (table, ccd->identity_uid);
e_destination_freev (destinations);
e_composer_header_table_set_subject (table, ccd->subject);
e_composer_header_table_set_destinations_to (table, ccd->destinations);
/* Content type */
content_type = comp_content_type (comp, isc->method);
top_level = comp_toplevel_with_zones (isc->method, comp, isc->cal_client, isc->zones);
ical_string = icalcomponent_as_ical_string_r (top_level);
if (e_cal_component_get_vtype (comp) == E_CAL_COMPONENT_EVENT) {
e_msg_composer_set_body (composer, ical_string, content_type);
if (e_cal_component_get_vtype (ccd->comp) == E_CAL_COMPONENT_EVENT) {
if (ccd->event_body_text)
e_msg_composer_set_body_text (composer, ccd->event_body_text, TRUE);
else
e_msg_composer_set_body (composer, ccd->ical_string, ccd->content_type);
} else {
CamelMimePart *attachment;
const gchar *filename;
gchar *description;
gchar *body;
filename = comp_filename (comp);
description = comp_description (comp, use_24hour_format);
filename = comp_filename (ccd->comp);
description = comp_description (ccd->comp, use_24hour_format);
body = camel_text_to_html (description, CAMEL_MIME_FILTER_TOHTML_PRE, 0);
e_msg_composer_set_body_text (composer, body, TRUE);
......@@ -1855,8 +1835,8 @@ itip_send_component_complete (ItipSendComponentData *isc)
attachment = camel_mime_part_new ();
camel_mime_part_set_content (
attachment, ical_string,
strlen (ical_string), content_type);
attachment, ccd->ical_string,
strlen (ccd->ical_string), ccd->content_type);
if (filename != NULL && *filename != '\0')
camel_mime_part_set_filename (attachment, filename);
if (description != NULL && *description != '\0')
......@@ -1868,23 +1848,89 @@ itip_send_component_complete (ItipSendComponentData *isc)
g_free (description);
}
append_cal_attachments (composer, comp, isc->attachments_list);
isc->attachments_list = NULL;
append_cal_attachments (composer, ccd->comp, ccd->attachments_list);
ccd->attachments_list = NULL;
if (isc->method == E_CAL_COMPONENT_METHOD_PUBLISH && !isc->users)
if (ccd->show_only)
gtk_widget_show (GTK_WIDGET (composer));
else
e_msg_composer_send (composer);
e_destination_freev (ccd->destinations);
g_clear_object (&ccd->comp);
g_free (ccd->identity_uid);
g_free (ccd->subject);
g_free (ccd->ical_string);
g_free (ccd->content_type);
g_free (ccd->event_body_text);
g_free (ccd);
}
static void
itip_send_component_complete (ItipSendComponentData *isc)
{
CreateComposerData *ccd;
EDestination **destinations;
ECalComponent *comp = NULL;
EShell *shell;
icalcomponent *top_level = NULL;
icaltimezone *default_zone;
g_return_if_fail (isc != NULL);
if (isc->completed)
return;
isc->success = FALSE;
default_zone = calendar_config_get_icaltimezone ();
/* Tidy up the comp */
comp = comp_compliant (
isc->registry, isc->method, isc->send_comp, isc->cal_client,
isc->zones, default_zone, isc->strip_alarms);
if (comp == NULL)
goto cleanup;
/* Recipients */
destinations = comp_to_list (
isc->registry, isc->method, comp, isc->users, FALSE,
isc->only_new_attendees ? g_object_get_data (
G_OBJECT (isc->send_comp), "new-attendees") : NULL);
if (isc->method != E_CAL_COMPONENT_METHOD_PUBLISH) {
if (destinations == NULL) {
/* We sent them all via the server */
isc->success = TRUE;
goto cleanup;
}
}
shell = e_shell_get_default ();
top_level = comp_toplevel_with_zones (isc->method, comp, isc->cal_client, isc->zones);
ccd = g_new0 (CreateComposerData, 1);
ccd->identity_uid = get_identity_uid_for_from (shell, isc->method, isc->send_comp, isc->cal_client);
ccd->destinations = destinations;
ccd->subject = comp_subject (isc->registry, isc->method, comp);
ccd->ical_string = icalcomponent_as_ical_string_r (top_level);
ccd->content_type = comp_content_type (comp, isc->method);
ccd->event_body_text = NULL;
ccd->attachments_list = isc->attachments_list;
ccd->comp = comp;
ccd->show_only = isc->method == E_CAL_COMPONENT_METHOD_PUBLISH && !isc->users;
isc->attachments_list = NULL;
comp = NULL;
e_msg_composer_new (shell, itip_send_component_composer_created_cb, ccd);
isc->success = TRUE;
cleanup:
g_clear_object (&comp);
if (top_level != NULL)
icalcomponent_free (top_level);
g_free (content_type);
g_free (subject);
g_free (ical_string);
}
static void
......@@ -2119,15 +2165,11 @@ reply_to_calendar_comp (ESourceRegistry *registry,
GSList *attachments_list)
{
EShell *shell;
EMsgComposer *composer;
EComposerHeaderTable *table;
EDestination **destinations;
ECalComponent *comp = NULL;
icalcomponent *top_level = NULL;
icaltimezone *default_zone;
gchar *subject = NULL;
gchar *ical_string = NULL;
gboolean retval = FALSE;
CreateComposerData *ccd;
g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), FALSE);
......@@ -2143,24 +2185,15 @@ reply_to_calendar_comp (ESourceRegistry *registry,
if (comp == NULL)
goto cleanup;
/* Recipients */
destinations = comp_to_list (
registry, method, comp, NULL, reply_all, NULL);
/* Subject information */
subject = comp_subject (registry, method, comp);
composer = e_msg_composer_new (shell);
table = e_msg_composer_get_header_table (composer);
setup_from (method, send_comp, cal_client, table);
e_composer_header_table_set_subject (table, subject);
e_composer_header_table_set_destinations_to (table, destinations);
e_destination_freev (destinations);
top_level = comp_toplevel_with_zones (method, comp, cal_client, zones);
ical_string = icalcomponent_as_ical_string_r (top_level);
ccd = g_new0 (CreateComposerData, 1);
ccd->identity_uid = get_identity_uid_for_from (shell, method, send_comp, cal_client);
ccd->destinations = comp_to_list (registry, method, comp, NULL, reply_all, NULL);
ccd->subject = comp_subject (registry, method, comp);
ccd->ical_string = icalcomponent_as_ical_string_r (top_level);
ccd->comp = comp;
ccd->show_only = TRUE;
if (e_cal_component_get_vtype (comp) == E_CAL_COMPONENT_EVENT) {
......@@ -2268,11 +2301,12 @@ reply_to_calendar_comp (ESourceRegistry *registry,
g_string_append (body, html_description);
g_free (html_description);
e_msg_composer_set_body_text (composer, body->str, TRUE);
g_string_free (body, TRUE);
ccd->event_body_text = g_string_free (body, FALSE);
}
gtk_widget_show (GTK_WIDGET (composer));
comp = NULL;
e_msg_composer_new (shell, itip_send_component_composer_created_cb, ccd);
retval = TRUE;
......@@ -2283,8 +2317,6 @@ reply_to_calendar_comp (ESourceRegistry *registry,
if (top_level != NULL)
icalcomponent_free (top_level);
g_free (subject);
g_free (ical_string);
return retval;
}
......
......@@ -64,41 +64,58 @@ action_close_cb (GtkAction *action,
gtk_widget_destroy (GTK_WIDGET (composer));
}
static void
action_new_message_composer_created_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
EMsgComposer *composer;
GError *error = NULL;
composer = e_msg_composer_new_finish (result, &error);
if (error) {
g_warning ("%s: Failed to create msg composer: %s", G_STRFUNC, error->message);
g_clear_error (&error);
} else {
gtk_widget_show (GTK_WIDGET (composer));
}
}
static void
action_new_message_cb (GtkAction *action,
EMsgComposer *composer)
{
EMsgComposer *new_composer;
EShell *shell;
shell = e_msg_composer_get_shell (composer);
new_composer = e_msg_composer_new (shell);
gtk_widget_show (GTK_WIDGET (new_composer));
e_msg_composer_new (shell, action_new_message_composer_created_cb, NULL);
}
static void
action_pgp_encrypt_cb (GtkToggleAction *action,
EMsgComposer *composer)
composer_set_content_editor_changed (EMsgComposer *composer)
{
EHTMLEditor *editor;
EHTMLEditorView *view;
EContentEditor *cnt_editor;
editor = e_msg_composer_get_editor (composer);
view = e_html_editor_get_view (editor);
e_html_editor_view_set_changed (view, TRUE);
cnt_editor = e_html_editor_get_content_editor (editor);
e_content_editor_set_changed (cnt_editor, TRUE);
}
static void
action_pgp_sign_cb (GtkToggleAction *action,
action_pgp_encrypt_cb (GtkToggleAction *action,
EMsgComposer *composer)
{
EHTMLEditor *editor;
EHTMLEditorView *view;
composer_set_content_editor_changed (composer);
}
editor = e_msg_composer_get_editor (composer);
view = e_html_editor_get_view (editor);
e_html_editor_view_set_changed (view, TRUE);
static void
action_pgp_sign_cb (GtkToggleAction *action,
EMsgComposer *composer)
{
composer_set_content_editor_changed (composer);
}
static void
......@@ -150,7 +167,6 @@ action_save_cb (GtkAction *action,
EMsgComposer *composer)
{
EHTMLEditor *editor;
EHTMLEditorView *view;
const gchar *filename;
gint fd;
GError *error = NULL;
......@@ -195,8 +211,7 @@ action_save_cb (GtkAction *action,
return;
}
view = e_html_editor_get_view (editor);
e_html_editor_view_set_changed (view, TRUE);
composer_set_content_editor_changed (composer);
}
static void
......@@ -256,37 +271,14 @@ static void
action_smime_encrypt_cb (GtkToggleAction *action,
EMsgComposer *composer)
{
EHTMLEditor *editor;
EHTMLEditorView *view;
editor = e_msg_composer_get_editor (composer);
view = e_html_editor_get_view (editor);
e_html_editor_view_set_changed (view, TRUE);
composer_set_content_editor_changed (composer);
}