56
57
#include <glib/gi18n.h>
57
58
#include <gtk/gtk.h>
58
59
#include <libnotify/notify.h>
60
#include <libsoup/soup.h>
59
61
#include <string.h>
63
#include <webkit2/webkit2.h>
60
65
#include <webkit/webkit.h>
63
69
window_cmd_file_print (GtkAction *action,
263
269
dialog = ephy_file_chooser_new (_("Open"),
264
270
GTK_WIDGET (window),
265
271
GTK_FILE_CHOOSER_ACTION_OPEN,
266
EPHY_PREFS_STATE_OPEN_DIR,
267
272
EPHY_FILE_FILTER_ALL_SUPPORTED);
269
274
g_signal_connect (dialog, "response",
276
281
get_suggested_filename (EphyWebView *view)
278
char *suggested_filename;
283
char *suggested_filename = NULL;
279
284
const char *mimetype;
286
WebKitURIResponse *response;
280
288
WebKitWebFrame *frame;
281
289
WebKitWebDataSource *data_source;
282
291
WebKitWebResource *web_resource;
294
web_resource = webkit_web_view_get_main_resource (WEBKIT_WEB_VIEW (view));
295
response = webkit_web_resource_get_response (web_resource);
296
mimetype = webkit_uri_response_get_mime_type (response);
284
298
frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view));
285
299
data_source = webkit_web_frame_get_data_source (frame);
286
300
web_resource = webkit_web_data_source_get_main_resource (data_source);
287
301
mimetype = webkit_web_resource_get_mime_type (web_resource);
289
304
if ((g_ascii_strncasecmp (mimetype, "text/html", 9)) == 0)
291
/* Web Title will be used as suggested filename*/
306
/* Web Title will be used as suggested filename */
308
suggested_filename = g_strconcat (ephy_web_view_get_title (view), ".mhtml", NULL);
292
310
suggested_filename = g_strconcat (ephy_web_view_get_title (view), ".html", NULL);
296
SoupURI *soup_uri = soup_uri_new (webkit_web_resource_get_uri (web_resource));
297
suggested_filename = g_path_get_basename (soup_uri->path);
298
soup_uri_free (soup_uri);
316
suggested_filename = g_strdup (webkit_uri_response_get_suggested_filename (response));
318
WebKitNetworkResponse *response;
320
response = webkit_web_frame_get_network_response (frame);
321
suggested_filename = g_strdup (webkit_network_response_get_suggested_filename (response));
324
if (!suggested_filename)
326
SoupURI *soup_uri = soup_uri_new (webkit_web_resource_get_uri (web_resource));
327
suggested_filename = g_path_get_basename (soup_uri->path);
328
soup_uri_free (soup_uri);
301
332
return suggested_filename;
316
347
dialog = ephy_file_chooser_new (_("Save"),
317
348
GTK_WIDGET (window),
318
349
GTK_FILE_CHOOSER_ACTION_SAVE,
319
EPHY_PREFS_STATE_SAVE_DIR,
320
350
EPHY_FILE_FILTER_NONE);
322
352
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
324
354
view = ephy_embed_get_web_view (embed);
325
suggested_filename = get_suggested_filename (view);
355
suggested_filename = ephy_sanitize_filename (get_suggested_filename (view));
327
357
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), suggested_filename);
328
358
g_free (suggested_filename);
364
394
g_object_unref (snapshot);
399
download_finished_cb (WebKitDownload *download,
400
EphyApplicationDialogData *data)
404
filename = g_filename_from_uri (webkit_download_get_destination (download), NULL, NULL);
405
gtk_image_set_from_file (GTK_IMAGE (data->image), filename);
410
download_failed_cb (WebKitDownload *download,
412
EphyApplicationDialogData *data)
414
g_signal_handlers_disconnect_by_func (download, download_finished_cb, data);
415
/* Something happened, default to a page snapshot. */
416
take_page_snapshot_and_set_image (data);
368
420
download_status_changed_cb (WebKitDownload *download,
369
421
GParamSpec *spec,
370
422
EphyApplicationDialogData *data)
372
424
WebKitDownloadStatus status = webkit_download_get_status (download);
373
const char *destination;
377
429
case WEBKIT_DOWNLOAD_STATUS_FINISHED:
378
destination = g_filename_from_uri (webkit_download_get_destination_uri (download),
430
filename = g_filename_from_uri (webkit_download_get_destination_uri (download),
380
gtk_image_set_from_file (GTK_IMAGE (data->image), destination);
432
gtk_image_set_from_file (GTK_IMAGE (data->image), filename);
382
435
case WEBKIT_DOWNLOAD_STATUS_ERROR:
383
436
case WEBKIT_DOWNLOAD_STATUS_CANCELLED:
393
447
download_icon_and_set_image (EphyApplicationDialogData *data)
395
450
WebKitNetworkRequest *request;
396
452
WebKitDownload *download;
397
453
char *destination, *destination_uri, *tmp_filename;
456
download = webkit_web_context_download_uri (webkit_web_context_get_default (),
399
459
request = webkit_network_request_new (data->icon_href);
400
460
download = webkit_download_new (request);
401
461
g_object_unref (request);
403
464
tmp_filename = ephy_file_tmp_filename ("ephy-download-XXXXXX", NULL);
404
465
destination = g_build_filename (ephy_file_tmp_dir (), tmp_filename, NULL);
405
466
destination_uri = g_filename_to_uri (destination, NULL, NULL);
468
webkit_download_set_destination (download, destination_uri);
406
470
webkit_download_set_destination_uri (download, destination_uri);
407
472
g_free (destination);
408
473
g_free (destination_uri);
409
474
g_free (tmp_filename);
477
g_signal_connect (download, "finished",
478
G_CALLBACK (download_finished_cb), data);
479
g_signal_connect (download, "failed",
480
G_CALLBACK (download_failed_cb), data);
411
482
g_signal_connect (download, "notify::status",
412
483
G_CALLBACK (download_status_changed_cb), data);
414
webkit_download_start (download);
485
webkit_download_start (download);
418
490
fill_default_application_image (EphyApplicationDialogData *data)
493
/* TODO: DOM Bindindgs */
420
495
WebKitDOMDocument *document;
421
496
WebKitDOMNodeList *links;
422
497
gulong length, i;
501
576
EphyApplicationDialogData *data)
578
const char *app_name;
504
579
char *desktop_file;
506
581
NotifyNotification *notification;
507
gboolean profile_exists;
509
583
if (response == GTK_RESPONSE_OK) {
510
profile_dir = ephy_web_application_get_profile_directory (gtk_entry_get_text (GTK_ENTRY (data->entry)));
513
profile_exists = g_file_test (profile_dir, G_FILE_TEST_IS_DIR);
514
g_free (profile_dir);
584
app_name = gtk_entry_get_text (GTK_ENTRY (data->entry));
586
if (ephy_web_application_exists (app_name))
518
if (confirm_web_application_overwrite (GTK_WINDOW (dialog),
519
gtk_entry_get_text (GTK_ENTRY (data->entry))))
520
ephy_web_application_delete (gtk_entry_get_text (GTK_ENTRY (data->entry)));
588
if (confirm_web_application_overwrite (GTK_WINDOW (dialog), app_name))
589
ephy_web_application_delete (app_name);
525
594
/* Create Web Application, including a new profile and .desktop file. */
526
desktop_file = ephy_web_application_create (data->view,
527
gtk_entry_get_text (GTK_ENTRY (data->entry)),
595
desktop_file = ephy_web_application_create (webkit_web_view_get_uri (WEBKIT_WEB_VIEW (data->view)),
528
597
gtk_image_get_pixbuf (GTK_IMAGE (data->image)));
529
598
if (desktop_file)
530
599
message = g_strdup_printf (_("The application '%s' is ready to be used"),
531
gtk_entry_get_text (GTK_ENTRY (data->entry)));
533
602
message = g_strdup_printf (_("The application '%s' could not be created"),
534
gtk_entry_get_text (GTK_ENTRY (data->entry)));
536
605
notification = notify_notification_new (message,
722
window_cmd_file_quit (GtkAction *action,
725
if (ephy_session_close_all_windows (EPHY_SESSION (ephy_shell_get_session (ephy_shell))))
726
g_application_quit (g_application_get_default ());
730
window_cmd_file_new_window (GtkAction *action,
733
ephy_shell_new_tab (ephy_shell, NULL, NULL, NULL,
734
EPHY_NEW_TAB_IN_NEW_WINDOW | EPHY_NEW_TAB_HOME_PAGE);
653
738
window_cmd_edit_undo (GtkAction *action,
654
739
EphyWindow *window)
695
784
embed = gtk_widget_get_ancestor (widget, EPHY_TYPE_EMBED);
788
webkit_web_view_execute_editing_command (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (EPHY_EMBED (embed)), "Redo");
698
790
webkit_web_view_redo (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (EPHY_EMBED (embed)));
715
808
embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
716
809
g_return_if_fail (embed != NULL);
812
webkit_web_view_execute_editing_command (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed), WEBKIT_EDITING_COMMAND_CUT);
718
814
webkit_web_view_cut_clipboard (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed));
736
833
embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
737
834
g_return_if_fail (embed != NULL);
836
webkit_web_view_execute_editing_command (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed), WEBKIT_EDITING_COMMAND_COPY);
739
838
webkit_web_view_copy_clipboard (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed));
757
857
embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
758
858
g_return_if_fail (embed != NULL);
861
webkit_web_view_execute_editing_command (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed), WEBKIT_EDITING_COMMAND_PASTE);
760
863
webkit_web_view_paste_clipboard (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed));
804
908
(EPHY_EMBED_CONTAINER (window));
805
909
g_return_if_fail (embed != NULL);
912
webkit_web_view_execute_editing_command (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed), "SelectAll");
807
914
webkit_web_view_select_all (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed));
950
window_cmd_edit_bookmarks (GtkAction *action,
955
bwindow = ephy_shell_get_bookmarks_editor (ephy_shell);
956
gtk_window_present (GTK_WINDOW (bwindow));
960
window_cmd_edit_history (GtkAction *action,
965
hwindow = ephy_shell_get_history_window (ephy_shell);
966
gtk_window_present (GTK_WINDOW (hwindow));
970
window_cmd_edit_preferences (GtkAction *action,
975
dialog = EPHY_DIALOG (ephy_shell_get_prefs_dialog (ephy_shell));
977
ephy_dialog_show (dialog);
981
window_cmd_edit_personal_data (GtkAction *action,
986
dialog = EPHY_PDM_DIALOG (ephy_shell_get_pdm_dialog (ephy_shell));
987
/* FIXME?: pdm_dialog_open is supposed to scroll to the host passed
988
* as second parameters in the cookies tab. Honestly I think this
989
* has been broken for a while. In any case it's probably not
990
* relevant here, although we could get the host of the last active
991
* ephy window, I guess. */
992
pdm_dialog_open (dialog, NULL);
842
996
window_cmd_view_fullscreen (GtkAction *action,
843
997
EphyWindow *window)
845
999
if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
847
GtkWidget *toolbar_editor;
848
toolbar_editor = GTK_WIDGET (g_object_get_data (G_OBJECT (window),
849
"EphyToolbarEditor"));
850
if (toolbar_editor != NULL)
852
/* We don't want the toolbar editor to show
853
* while in fullscreen.
855
gtk_dialog_response (GTK_DIALOG (toolbar_editor),
856
GTK_RESPONSE_DELETE_EVENT);
858
1000
gtk_window_fullscreen (GTK_WINDOW (window));
862
1002
gtk_window_unfullscreen (GTK_WINDOW (window));
897
1036
EPHY_NEW_TAB_JUMP | EPHY_NEW_TAB_IN_EXISTING_WINDOW | EPHY_NEW_TAB_APPEND_AFTER);
1038
/* TODO: View Source */
899
1040
webkit_web_view_set_view_source_mode
900
1041
(EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (new_embed), TRUE);
901
1042
webkit_web_view_load_uri
902
1043
(EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (new_embed), uri);
1127
get_main_resource_data_cb (WebKitWebResource *resource, GAsyncResult *result, GOutputStream *ostream)
1132
GError *error = NULL;
1134
data = webkit_web_resource_get_data_finish (resource, result, &data_length, &error);
1136
g_warning ("Unable to get main resource data: %s", error->message);
1137
g_error_free (error);
1141
/* We create a new GString here because we need to make sure
1142
* we keep writing in case of partial writes */
1143
data_str = g_string_new_len ((gchar *)data, data_length);
1146
g_output_stream_write_async (ostream,
1147
data_str->str, data_str->len,
1148
G_PRIORITY_DEFAULT, NULL,
1149
(GAsyncReadyCallback)save_temp_source_write_cb,
984
1155
save_temp_source_replace_cb (GFile *file, GAsyncResult *result, EphyEmbed *embed)
986
1157
EphyWebView *view;
1159
WebKitWebResource *resource;
987
1161
WebKitWebFrame *frame;
988
1162
WebKitWebDataSource *data_source;
989
1163
GString *const_data;
991
1166
GFileOutputStream *ostream;
992
1167
GError *error = NULL;
1016
1191
g_object_ref (embed),
1017
1192
g_object_unref);
1195
resource = webkit_web_view_get_main_resource (WEBKIT_WEB_VIEW (view));
1196
webkit_web_resource_get_data (resource, NULL,
1197
(GAsyncReadyCallback)get_main_resource_data_cb,
1019
1200
frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view));
1020
1201
data_source = webkit_web_frame_get_data_source (frame);
1021
1202
const_data = webkit_web_data_source_get_data (data_source);
1082
1264
address = ephy_web_view_get_address (ephy_embed_get_web_view (embed));
1267
/* TODO: View Source */
1084
1269
if (g_settings_get_boolean (EPHY_SETTINGS_MAIN,
1085
1270
EPHY_PREFS_INTERNAL_VIEW_SOURCE))
1087
1272
view_source_embedded (address, embed);
1091
1277
user_time = gtk_get_current_event_time ();
1125
1311
"51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA")
1128
char *licence, *comments;
1314
char *licence = NULL, *comments = NULL;
1129
1315
GKeyFile *key_file;
1130
1316
GError *error = NULL;
1131
1317
char **list, **authors, **contributors, **past_authors, **artists, **documenters;
1203
1389
g_key_file_free (key_file);
1205
comments = g_strdup_printf (_("Lets you view web pages and find information on the internet.\n"
1392
comments = g_strdup_printf (_("A simple, clean, beautiful view of the web.\n"
1393
"Powered by WebKit %d.%d.%d"),
1394
webkit_get_major_version (),
1395
webkit_get_minor_version (),
1396
webkit_get_micro_version ());
1398
comments = g_strdup_printf (_("A simple, clean, beautiful view of the web.\n"
1206
1399
"Powered by WebKit %d.%d.%d"),
1207
1400
webkit_major_version (),
1208
1401
webkit_minor_version (),
1209
1402
webkit_micro_version ());
1211
1405
licence = g_strjoin ("\n\n",
1212
1406
_(licence_part[0]),
1250
1444
window_cmd_tabs_next (GtkAction *action,
1251
1445
EphyWindow *window)
1256
nb = GTK_NOTEBOOK (ephy_window_get_notebook (window));
1449
nb = ephy_window_get_notebook (window);
1257
1450
g_return_if_fail (nb != NULL);
1259
g_signal_emit_by_name (nb, "change-current-page", 1, &handled);
1452
ephy_notebook_next_page (EPHY_NOTEBOOK (nb));
1263
1456
window_cmd_tabs_previous (GtkAction *action,
1264
1457
EphyWindow *window)
1269
nb = GTK_NOTEBOOK (ephy_window_get_notebook (window));
1461
nb = ephy_window_get_notebook (window);
1270
1462
g_return_if_fail (nb != NULL);
1272
g_signal_emit_by_name (nb, "change-current-page", -1, &handled);
1464
ephy_notebook_prev_page (EPHY_NOTEBOOK (nb));