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/>
18
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
22
23
#include "e-web-view.h"
25
25
#include <string.h>
26
26
#include <glib/gi18n-lib.h>
28
28
#include <camel/camel.h>
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>
34
36
#include "e-popup-action.h"
35
37
#include "e-selectable.h"
39
#define E_WEB_VIEW_GET_PRIVATE(obj) \
40
(G_TYPE_INSTANCE_GET_PRIVATE \
41
((obj), E_TYPE_WEB_VIEW, EWebViewPrivate))
37
43
typedef struct _EWebViewRequest EWebViewRequest;
39
45
struct _EWebViewPrivate {
41
47
GtkUIManager *ui_manager;
42
48
gchar *selected_uri;
49
GdkPixbufAnimation *cursor_image;
44
51
GtkAction *open_proxy;
45
52
GtkAction *print_proxy;
368
381
gtk_clipboard_store (clipboard);
385
action_image_copy_cb (GtkAction *action,
388
GtkClipboard *clipboard;
389
GdkPixbufAnimation *animation;
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);
396
pixbuf = gdk_pixbuf_animation_get_static_image (animation);
400
gtk_clipboard_set_image (clipboard, pixbuf);
401
gtk_clipboard_store (clipboard);
371
404
static GtkActionEntry uri_entries[] = {
433
476
gboolean event_handled = FALSE;
434
477
gchar *uri = NULL;
480
GdkPixbufAnimation *anim;
483
frame = GTK_HTML (web_view);
485
anim = gtk_html_get_image_at (frame, event->x, event->y);
486
e_web_view_set_cursor_image (web_view, anim);
488
g_object_unref (anim);
436
491
if (event != NULL && event->button != 3)
712
778
priv->paste_target_list = NULL;
781
if (priv->cursor_image != NULL) {
782
g_object_unref (priv->cursor_image);
783
priv->cursor_image = NULL;
715
786
/* Chain up to parent's dispose() method. */
716
787
G_OBJECT_CLASS (parent_class)->dispose (object);
733
804
G_OBJECT_CLASS (parent_class)->finalize (object);
808
web_view_constructed (GObject *object)
813
settings = g_settings_new ("org.gnome.desktop.lockdown");
816
settings, "disable-printing",
817
object, "disable-printing",
818
G_SETTINGS_BIND_GET);
821
settings, "disable-save-to-disk",
822
object, "disable-save-to-disk",
823
G_SETTINGS_BIND_GET);
825
g_object_unref (settings);
828
/* Chain up to parent's constructed() method. */
829
G_OBJECT_CLASS (parent_class)->constructed (object);
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;
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;
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);
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);
1005
1108
group_name = "selection";
1006
1109
visible = have_selection;
1007
1110
action_group = e_web_view_get_action_group (web_view, group_name);
1130
web_view_submit_alert (EAlertSink *alert_sink,
1133
GtkIconInfo *icon_info;
1137
const gchar *icon_name = NULL;
1138
const gchar *filename;
1142
GError *error = NULL;
1144
web_view = E_WEB_VIEW (alert_sink);
1146
parent = gtk_widget_get_toplevel (GTK_WIDGET (web_view));
1147
parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
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";
1156
case GTK_MESSAGE_WARNING:
1157
icon_name = "dialog-warning";
1160
case GTK_MESSAGE_ERROR:
1161
icon_name = "dialog-error";
1165
dialog = e_alert_dialog_new (parent, alert);
1166
gtk_dialog_run (GTK_DIALOG (dialog));
1167
gtk_widget_destroy (dialog);
1171
gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &size, NULL);
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);
1178
filename = gtk_icon_info_get_filename (icon_info);
1179
icon_uri = g_filename_to_uri (filename, NULL, &error);
1181
if (error != NULL) {
1182
g_warning ("%s", error->message);
1183
g_clear_error (&error);
1186
buffer = g_string_sized_new (512);
1192
"<meta http-equiv=\"content-type\""
1193
" content=\"text/html; charset=utf-8\">"
1199
"<table bgcolor='#000000' width='100%'"
1200
" cellpadding='1' cellspacing='0'>"
1203
"<table bgcolor='#dddddd' width='100%' cellpadding='6'>"
1206
g_string_append_printf (
1212
"<td align='left' width='100%%'>"
1218
e_alert_get_primary_text (alert),
1219
e_alert_get_secondary_text (alert));
1230
e_web_view_load_string (web_view, buffer->str);
1232
g_string_free (buffer, TRUE);
1234
gtk_icon_info_free (icon_info);
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;
1125
1338
widget_class = GTK_WIDGET_CLASS (class);
1126
1339
widget_class->button_press_event = web_view_button_press_event;
1278
1491
G_PARAM_READWRITE));
1493
g_object_class_install_property (
1496
g_param_spec_object (
1498
"Image animation at the mouse cursor",
1500
GDK_TYPE_PIXBUF_ANIMATION,
1501
G_PARAM_READWRITE));
1280
1503
signals[COPY_CLIPBOARD] = g_signal_new (
1281
1504
"copy-clipboard",
1282
1505
G_TYPE_FROM_CLASS (class),
1375
1604
const gchar *id;
1376
1605
GError *error = NULL;
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);
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);
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);
1654
gtk_action_group_add_actions (
1655
action_group, image_entries,
1656
G_N_ELEMENTS (image_entries), web_view);
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");
1982
GdkPixbufAnimation *
1983
e_web_view_get_cursor_image (EWebView *web_view)
1985
g_return_val_if_fail (E_IS_WEB_VIEW (web_view), NULL);
1987
return web_view->priv->cursor_image;
1991
e_web_view_set_cursor_image (EWebView *web_view,
1992
GdkPixbufAnimation *image)
1994
g_return_if_fail (E_IS_WEB_VIEW (web_view));
1997
g_object_ref (image);
1999
if (web_view->priv->cursor_image != NULL)
2000
g_object_unref (web_view->priv->cursor_image);
2002
web_view->priv->cursor_image = image;
2004
g_object_notify (G_OBJECT (web_view), "cursor-image");
1746
2008
e_web_view_get_open_proxy (EWebView *web_view)