~ubuntu-branches/ubuntu/precise/evolution/precise

« back to all changes in this revision

Viewing changes to widgets/misc/e-web-view.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2011-06-24 00:27:53 UTC
  • mfrom: (1.1.80 upstream)
  • Revision ID: james.westby@ubuntu.com-20110624002753-2vh1vjavlya7r103
Tags: 3.1.2-0ubuntu1
* New upstream release 3.1.2.
* debian/control: adjust Build-Depends to match new upstream requirements for
  the new release.
* debian/control: update evolution and evolution-dev Depends to require the
  right versions of e-d-s (>= 3.1, << 3.2), and drop libunique-3.0-dev.
* debian/control,
  debian/evolution.install: remove groupwise-features from the plugin list,
  it's now split out into a separate module.
* debian/patches/03_lpi.patch: refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 * You should have received a copy of the GNU Lesser General Public
15
15
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
16
16
 *
17
 
 *
18
 
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
19
 
 *
20
17
 */
21
18
 
 
19
#ifdef HAVE_CONFIG_H
 
20
#include <config.h>
 
21
#endif
 
22
 
22
23
#include "e-web-view.h"
23
24
 
24
 
#include <config.h>
25
25
#include <string.h>
26
26
#include <glib/gi18n-lib.h>
27
27
 
28
28
#include <camel/camel.h>
29
29
 
30
30
#include <e-util/e-util.h>
 
31
#include <e-util/e-alert-dialog.h>
 
32
#include <e-util/e-alert-sink.h>
31
33
#include <e-util/e-extensible.h>
32
34
#include <e-util/e-plugin-ui.h>
33
35
 
34
36
#include "e-popup-action.h"
35
37
#include "e-selectable.h"
36
38
 
 
39
#define E_WEB_VIEW_GET_PRIVATE(obj) \
 
40
        (G_TYPE_INSTANCE_GET_PRIVATE \
 
41
        ((obj), E_TYPE_WEB_VIEW, EWebViewPrivate))
 
42
 
37
43
typedef struct _EWebViewRequest EWebViewRequest;
38
44
 
39
45
struct _EWebViewPrivate {
40
46
        GList *requests;
41
47
        GtkUIManager *ui_manager;
42
48
        gchar *selected_uri;
 
49
        GdkPixbufAnimation *cursor_image;
43
50
 
44
51
        GtkAction *open_proxy;
45
52
        GtkAction *print_proxy;
77
84
        PROP_PASTE_TARGET_LIST,
78
85
        PROP_PRINT_PROXY,
79
86
        PROP_SAVE_AS_PROXY,
80
 
        PROP_SELECTED_URI
 
87
        PROP_SELECTED_URI,
 
88
        PROP_CURSOR_IMAGE
81
89
};
82
90
 
83
91
enum {
110
118
"    <placeholder name='custom-actions-2'>"
111
119
"      <menuitem action='uri-copy'/>"
112
120
"      <menuitem action='mailto-copy'/>"
 
121
"      <menuitem action='image-copy'/>"
113
122
"    </placeholder>"
114
123
"    <placeholder name='custom-actions-3'/>"
115
124
"    <separator/>"
118
127
"</ui>";
119
128
 
120
129
/* Forward Declarations */
 
130
static void e_web_view_alert_sink_init (EAlertSinkInterface *interface);
121
131
static void e_web_view_selectable_init (ESelectableInterface *interface);
122
132
 
123
133
G_DEFINE_TYPE_WITH_CODE (
127
137
        G_IMPLEMENT_INTERFACE (
128
138
                E_TYPE_EXTENSIBLE, NULL)
129
139
        G_IMPLEMENT_INTERFACE (
 
140
                E_TYPE_ALERT_SINK,
 
141
                e_web_view_alert_sink_init)
 
142
        G_IMPLEMENT_INTERFACE (
130
143
                E_TYPE_SELECTABLE,
131
144
                e_web_view_selectable_init))
132
145
 
368
381
        gtk_clipboard_store (clipboard);
369
382
}
370
383
 
 
384
static void
 
385
action_image_copy_cb (GtkAction *action,
 
386
                    EWebView *web_view)
 
387
{
 
388
        GtkClipboard *clipboard;
 
389
        GdkPixbufAnimation *animation;
 
390
        GdkPixbuf *pixbuf;
 
391
 
 
392
        clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
 
393
        animation = e_web_view_get_cursor_image (web_view);
 
394
        g_return_if_fail (animation != NULL);
 
395
 
 
396
        pixbuf = gdk_pixbuf_animation_get_static_image (animation);
 
397
        if (!pixbuf)
 
398
                return;
 
399
 
 
400
        gtk_clipboard_set_image (clipboard, pixbuf);
 
401
        gtk_clipboard_store (clipboard);
 
402
}
 
403
 
371
404
static GtkActionEntry uri_entries[] = {
372
405
 
373
406
        { "uri-copy",
405
438
          G_CALLBACK (action_send_message_cb) }
406
439
};
407
440
 
 
441
static GtkActionEntry image_entries[] = {
 
442
 
 
443
        { "image-copy",
 
444
          GTK_STOCK_COPY,
 
445
          N_("_Copy Image"),
 
446
          NULL,
 
447
          N_("Copy the image to the clipboard"),
 
448
          G_CALLBACK (action_image_copy_cb) }
 
449
};
 
450
 
408
451
static GtkActionEntry selection_entries[] = {
409
452
 
410
453
        { "copy-clipboard",
433
476
        gboolean event_handled = FALSE;
434
477
        gchar *uri = NULL;
435
478
 
 
479
        if (event) {
 
480
                GdkPixbufAnimation *anim;
 
481
 
 
482
                if (frame == NULL)
 
483
                        frame = GTK_HTML (web_view);
 
484
 
 
485
                anim = gtk_html_get_image_at (frame, event->x, event->y);
 
486
                e_web_view_set_cursor_image (web_view, anim);
 
487
                if (anim != NULL)
 
488
                        g_object_unref (anim);
 
489
        }
 
490
 
436
491
        if (event != NULL && event->button != 3)
437
492
                return FALSE;
438
493
 
575
630
                                E_WEB_VIEW (object),
576
631
                                g_value_get_string (value));
577
632
                        return;
 
633
                case PROP_CURSOR_IMAGE:
 
634
                        e_web_view_set_cursor_image (
 
635
                                E_WEB_VIEW (object),
 
636
                                g_value_get_object (value));
 
637
                        return;
578
638
        }
579
639
 
580
640
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
670
730
                                value, e_web_view_get_selected_uri (
671
731
                                E_WEB_VIEW (object)));
672
732
                        return;
 
733
 
 
734
                case PROP_CURSOR_IMAGE:
 
735
                        g_value_set_object (
 
736
                                value, e_web_view_get_cursor_image (
 
737
                                E_WEB_VIEW (object)));
 
738
                        return;
673
739
        }
674
740
 
675
741
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
680
746
{
681
747
        EWebViewPrivate *priv;
682
748
 
683
 
        priv = E_WEB_VIEW (object)->priv;
 
749
        priv = E_WEB_VIEW_GET_PRIVATE (object);
684
750
 
685
751
        if (priv->ui_manager != NULL) {
686
752
                g_object_unref (priv->ui_manager);
712
778
                priv->paste_target_list = NULL;
713
779
        }
714
780
 
 
781
        if (priv->cursor_image != NULL) {
 
782
                g_object_unref (priv->cursor_image);
 
783
                priv->cursor_image = NULL;
 
784
        }
 
785
 
715
786
        /* Chain up to parent's dispose() method. */
716
787
        G_OBJECT_CLASS (parent_class)->dispose (object);
717
788
}
721
792
{
722
793
        EWebViewPrivate *priv;
723
794
 
724
 
        priv = E_WEB_VIEW (object)->priv;
 
795
        priv = E_WEB_VIEW_GET_PRIVATE (object);
725
796
 
726
797
        /* All URI requests should be complete or cancelled by now. */
727
798
        if (priv->requests != NULL)
733
804
        G_OBJECT_CLASS (parent_class)->finalize (object);
734
805
}
735
806
 
 
807
static void
 
808
web_view_constructed (GObject *object)
 
809
{
 
810
#ifndef G_OS_WIN32
 
811
        GSettings *settings;
 
812
 
 
813
        settings = g_settings_new ("org.gnome.desktop.lockdown");
 
814
 
 
815
        g_settings_bind (
 
816
                settings, "disable-printing",
 
817
                object, "disable-printing",
 
818
                G_SETTINGS_BIND_GET);
 
819
 
 
820
        g_settings_bind (
 
821
                settings, "disable-save-to-disk",
 
822
                object, "disable-save-to-disk",
 
823
                G_SETTINGS_BIND_GET);
 
824
 
 
825
        g_object_unref (settings);
 
826
#endif
 
827
 
 
828
        /* Chain up to parent's constructed() method. */
 
829
        G_OBJECT_CLASS (parent_class)->constructed (object);
 
830
}
 
831
 
736
832
static gboolean
737
833
web_view_button_press_event (GtkWidget *widget,
738
834
                             GdkEventButton *event)
963
1059
        gboolean scheme_is_http = FALSE;
964
1060
        gboolean scheme_is_mailto = FALSE;
965
1061
        gboolean uri_is_valid = FALSE;
 
1062
        gboolean has_cursor_image;
966
1063
        gboolean visible;
967
1064
        const gchar *group_name;
968
1065
        const gchar *uri;
969
1066
 
970
1067
        uri = e_web_view_get_selected_uri (web_view);
971
1068
        have_selection = e_web_view_is_selection_active (web_view);
 
1069
        has_cursor_image = e_web_view_get_cursor_image (web_view) != NULL;
972
1070
 
973
1071
        /* Parse the URI early so we know if the actions will work. */
974
1072
        if (uri != NULL) {
1002
1100
        action_group = e_web_view_get_action_group (web_view, group_name);
1003
1101
        gtk_action_group_set_visible (action_group, visible);
1004
1102
 
 
1103
        group_name = "image";
 
1104
        visible = has_cursor_image;
 
1105
        action_group = e_web_view_get_action_group (web_view, group_name);
 
1106
        gtk_action_group_set_visible (action_group, visible);
 
1107
 
1005
1108
        group_name = "selection";
1006
1109
        visible = have_selection;
1007
1110
        action_group = e_web_view_get_action_group (web_view, group_name);
1024
1127
}
1025
1128
 
1026
1129
static void
 
1130
web_view_submit_alert (EAlertSink *alert_sink,
 
1131
                       EAlert *alert)
 
1132
{
 
1133
        GtkIconInfo *icon_info;
 
1134
        EWebView *web_view;
 
1135
        GtkWidget *dialog;
 
1136
        GString *buffer;
 
1137
        const gchar *icon_name = NULL;
 
1138
        const gchar *filename;
 
1139
        gpointer parent;
 
1140
        gchar *icon_uri;
 
1141
        gint size = 0;
 
1142
        GError *error = NULL;
 
1143
 
 
1144
        web_view = E_WEB_VIEW (alert_sink);
 
1145
 
 
1146
        parent = gtk_widget_get_toplevel (GTK_WIDGET (web_view));
 
1147
        parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
 
1148
 
 
1149
        /* We use equivalent named icons instead of stock IDs,
 
1150
         * since it's easier to get the filename of the icon. */
 
1151
        switch (e_alert_get_message_type (alert)) {
 
1152
                case GTK_MESSAGE_INFO:
 
1153
                        icon_name = "dialog-information";
 
1154
                        break;
 
1155
 
 
1156
                case GTK_MESSAGE_WARNING:
 
1157
                        icon_name = "dialog-warning";
 
1158
                        break;
 
1159
 
 
1160
                case GTK_MESSAGE_ERROR:
 
1161
                        icon_name = "dialog-error";
 
1162
                        break;
 
1163
 
 
1164
                default:
 
1165
                        dialog = e_alert_dialog_new (parent, alert);
 
1166
                        gtk_dialog_run (GTK_DIALOG (dialog));
 
1167
                        gtk_widget_destroy (dialog);
 
1168
                        return;
 
1169
        }
 
1170
 
 
1171
        gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &size, NULL);
 
1172
 
 
1173
        icon_info = gtk_icon_theme_lookup_icon (
 
1174
                gtk_icon_theme_get_default (),
 
1175
                icon_name, size, GTK_ICON_LOOKUP_NO_SVG);
 
1176
        g_return_if_fail (icon_info != NULL);
 
1177
 
 
1178
        filename = gtk_icon_info_get_filename (icon_info);
 
1179
        icon_uri = g_filename_to_uri (filename, NULL, &error);
 
1180
 
 
1181
        if (error != NULL) {
 
1182
                g_warning ("%s", error->message);
 
1183
                g_clear_error (&error);
 
1184
        }
 
1185
 
 
1186
        buffer = g_string_sized_new (512);
 
1187
 
 
1188
        g_string_append (
 
1189
                buffer,
 
1190
                "<html>"
 
1191
                "<head>"
 
1192
                "<meta http-equiv=\"content-type\""
 
1193
                " content=\"text/html; charset=utf-8\">"
 
1194
                "</head>"
 
1195
                "<body>");
 
1196
 
 
1197
        g_string_append (
 
1198
                buffer,
 
1199
                "<table bgcolor='#000000' width='100%'"
 
1200
                " cellpadding='1' cellspacing='0'>"
 
1201
                "<tr>"
 
1202
                "<td>"
 
1203
                "<table bgcolor='#dddddd' width='100%' cellpadding='6'>"
 
1204
                "<tr>");
 
1205
 
 
1206
        g_string_append_printf (
 
1207
                buffer,
 
1208
                "<tr>"
 
1209
                "<td valign='top'>"
 
1210
                "<img src='%s'/>"
 
1211
                "</td>"
 
1212
                "<td align='left' width='100%%'>"
 
1213
                "<h3>%s</h3>"
 
1214
                "%s"
 
1215
                "</td>"
 
1216
                "</tr>",
 
1217
                icon_uri,
 
1218
                e_alert_get_primary_text (alert),
 
1219
                e_alert_get_secondary_text (alert));
 
1220
 
 
1221
        g_string_append (
 
1222
                buffer,
 
1223
                "</table>"
 
1224
                "</td>"
 
1225
                "</tr>"
 
1226
                "</table>"
 
1227
                "</body>"
 
1228
                "</html>");
 
1229
 
 
1230
        e_web_view_load_string (web_view, buffer->str);
 
1231
 
 
1232
        g_string_free (buffer, TRUE);
 
1233
 
 
1234
        gtk_icon_info_free (icon_info);
 
1235
        g_free (icon_uri);
 
1236
}
 
1237
 
 
1238
static void
1027
1239
web_view_selectable_update_actions (ESelectable *selectable,
1028
1240
                                    EFocusTracker *focus_tracker,
1029
1241
                                    GdkAtom *clipboard_targets,
1121
1333
        object_class->get_property = web_view_get_property;
1122
1334
        object_class->dispose = web_view_dispose;
1123
1335
        object_class->finalize = web_view_finalize;
 
1336
        object_class->constructed = web_view_constructed;
1124
1337
 
1125
1338
        widget_class = GTK_WIDGET_CLASS (class);
1126
1339
        widget_class->button_press_event = web_view_button_press_event;
1277
1490
                        NULL,
1278
1491
                        G_PARAM_READWRITE));
1279
1492
 
 
1493
        g_object_class_install_property (
 
1494
                object_class,
 
1495
                PROP_CURSOR_IMAGE,
 
1496
                g_param_spec_object (
 
1497
                        "cursor-image",
 
1498
                        "Image animation at the mouse cursor",
 
1499
                        NULL,
 
1500
                        GDK_TYPE_PIXBUF_ANIMATION,
 
1501
                        G_PARAM_READWRITE));
 
1502
 
1280
1503
        signals[COPY_CLIPBOARD] = g_signal_new (
1281
1504
                "copy-clipboard",
1282
1505
                G_TYPE_FROM_CLASS (class),
1355
1578
}
1356
1579
 
1357
1580
static void
 
1581
e_web_view_alert_sink_init (EAlertSinkInterface *interface)
 
1582
{
 
1583
        interface->submit_alert = web_view_submit_alert;
 
1584
}
 
1585
 
 
1586
static void
1358
1587
e_web_view_selectable_init (ESelectableInterface *interface)
1359
1588
{
1360
1589
        interface->update_actions = web_view_selectable_update_actions;
1375
1604
        const gchar *id;
1376
1605
        GError *error = NULL;
1377
1606
 
1378
 
        web_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (
1379
 
                web_view, E_TYPE_WEB_VIEW, EWebViewPrivate);
 
1607
        web_view->priv = E_WEB_VIEW_GET_PRIVATE (web_view);
1380
1608
 
1381
1609
        ui_manager = gtk_ui_manager_new ();
1382
1610
        web_view->priv->ui_manager = ui_manager;
1418
1646
                action_group, mailto_entries,
1419
1647
                G_N_ELEMENTS (mailto_entries), web_view);
1420
1648
 
 
1649
        action_group = gtk_action_group_new ("image");
 
1650
        gtk_action_group_set_translation_domain (action_group, domain);
 
1651
        gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
 
1652
        g_object_unref (action_group);
 
1653
 
 
1654
        gtk_action_group_add_actions (
 
1655
                action_group, image_entries,
 
1656
                G_N_ELEMENTS (image_entries), web_view);
 
1657
 
1421
1658
        action_group = gtk_action_group_new ("selection");
1422
1659
        gtk_action_group_set_translation_domain (action_group, domain);
1423
1660
        gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
1742
1979
        g_object_notify (G_OBJECT (web_view), "selected-uri");
1743
1980
}
1744
1981
 
 
1982
GdkPixbufAnimation *
 
1983
e_web_view_get_cursor_image (EWebView *web_view)
 
1984
{
 
1985
        g_return_val_if_fail (E_IS_WEB_VIEW (web_view), NULL);
 
1986
 
 
1987
        return web_view->priv->cursor_image;
 
1988
}
 
1989
 
 
1990
void
 
1991
e_web_view_set_cursor_image (EWebView *web_view,
 
1992
                             GdkPixbufAnimation *image)
 
1993
{
 
1994
        g_return_if_fail (E_IS_WEB_VIEW (web_view));
 
1995
 
 
1996
        if (image != NULL)
 
1997
                g_object_ref (image);
 
1998
 
 
1999
        if (web_view->priv->cursor_image != NULL)
 
2000
                g_object_unref (web_view->priv->cursor_image);
 
2001
 
 
2002
        web_view->priv->cursor_image = image;
 
2003
 
 
2004
        g_object_notify (G_OBJECT (web_view), "cursor-image");
 
2005
}
 
2006
 
1745
2007
GtkAction *
1746
2008
e_web_view_get_open_proxy (EWebView *web_view)
1747
2009
{