374
385
gtk_widget_show (GTK_WIDGET (dialog));
395
} EphyApplicationDialogData;
398
ephy_application_dialog_data_free (EphyApplicationDialogData *data)
400
g_free (data->icon_href);
401
g_slice_free (EphyApplicationDialogData, data);
405
take_page_snapshot_and_set_image (EphyApplicationDialogData *data)
411
w = h = 128; /* GNOME hi-res icon size. */
413
snapshot = ephy_web_view_get_snapshot (data->view, x, y, w, h);
415
gtk_image_set_from_pixbuf (GTK_IMAGE (data->image), snapshot);
416
g_object_unref (snapshot);
420
download_status_changed_cb (WebKitDownload *download,
422
EphyApplicationDialogData *data)
424
WebKitDownloadStatus status = webkit_download_get_status (download);
425
const char *destination;
429
case WEBKIT_DOWNLOAD_STATUS_FINISHED:
430
destination = g_filename_from_uri (webkit_download_get_destination_uri (download),
432
gtk_image_set_from_file (GTK_IMAGE (data->image), destination);
434
case WEBKIT_DOWNLOAD_STATUS_ERROR:
435
case WEBKIT_DOWNLOAD_STATUS_CANCELLED:
436
/* Something happened, default to a page snapshot. */
437
take_page_snapshot_and_set_image (data);
445
download_icon_and_set_image (EphyApplicationDialogData *data)
447
WebKitNetworkRequest *request;
448
WebKitDownload *download;
449
char *destination, *destination_uri, *tmp_filename;
451
request = webkit_network_request_new (data->icon_href);
452
download = webkit_download_new (request);
453
g_object_unref (request);
455
tmp_filename = ephy_file_tmp_filename ("ephy-download-XXXXXX", NULL);
456
destination = g_build_filename (ephy_file_tmp_dir (), tmp_filename, NULL);
457
destination_uri = g_filename_to_uri (destination, NULL, NULL);
458
webkit_download_set_destination_uri (download, destination_uri);
459
g_free (destination);
460
g_free (destination_uri);
461
g_free (tmp_filename);
463
g_signal_connect (download, "notify::status",
464
G_CALLBACK (download_status_changed_cb), data);
466
webkit_download_start (download);
470
fill_default_application_image (EphyApplicationDialogData *data)
472
WebKitDOMDocument *document;
473
WebKitDOMNodeList *links;
476
document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (data->view));
477
links = webkit_dom_document_get_elements_by_tag_name (document, "link");
478
length = webkit_dom_node_list_get_length (links);
480
for (i = 0; i < length; i++)
483
WebKitDOMNode *node = webkit_dom_node_list_item (links, i);
484
rel = webkit_dom_html_link_element_get_rel (WEBKIT_DOM_HTML_LINK_ELEMENT (node));
485
/* TODO: support more than one possible icon. */
486
if (g_strcmp0 (rel, "apple-touch-icon") == 0 ||
487
g_strcmp0 (rel, "apple-touch-icon-precomposed") == 0)
489
data->icon_href = webkit_dom_html_link_element_get_href (WEBKIT_DOM_HTML_LINK_ELEMENT (node));
490
download_icon_and_set_image (data);
496
/* If we make it here, no "apple-touch-icon" link was
497
* found. Take a snapshot of the page. */
498
take_page_snapshot_and_set_image (data);
502
fill_default_application_title (EphyApplicationDialogData *data)
504
const char *title = ephy_web_view_get_title (data->view);
505
gtk_entry_set_text (GTK_ENTRY (data->entry), title);
509
notify_launch_cb (NotifyNotification *notification,
513
char * desktop_file = user_data;
514
/* A gross hack to be able to launch epiphany from within
515
* Epiphany. Might be a good idea to figure out a better
517
g_unsetenv (EPHY_UUID_ENVVAR);
518
ephy_file_launch_desktop_file (desktop_file, NULL, 0, NULL);
519
g_free (desktop_file);
523
confirm_web_application_overwrite (GtkWindow *parent, const char *title)
525
GtkResponseType response;
528
dialog = gtk_message_dialog_new (parent, 0,
529
GTK_MESSAGE_QUESTION,
531
_("A web application named '%s' already exists. Do you want to replace it?"),
533
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
539
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
540
_("An application with the same name already exists. Replacing it will "
542
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
543
response = gtk_dialog_run (GTK_DIALOG (dialog));
545
gtk_widget_destroy (dialog);
547
return response == GTK_RESPONSE_OK;
551
dialog_save_as_application_response_cb (GtkDialog *dialog,
553
EphyApplicationDialogData *data)
558
NotifyNotification *notification;
559
gboolean profile_exists;
561
if (response == GTK_RESPONSE_OK) {
562
profile_dir = ephy_web_application_get_profile_directory (gtk_entry_get_text (GTK_ENTRY (data->entry)));
563
profile_exists = g_file_test (profile_dir, G_FILE_TEST_IS_DIR);
564
g_free (profile_dir);
568
if (confirm_web_application_overwrite (GTK_WINDOW (dialog),
569
gtk_entry_get_text (GTK_ENTRY (data->entry))))
570
ephy_web_application_delete (gtk_entry_get_text (GTK_ENTRY (data->entry)));
575
/* Create Web Application, including a new profile and .desktop file. */
576
desktop_file = ephy_web_application_create (data->view,
577
gtk_entry_get_text (GTK_ENTRY (data->entry)),
578
gtk_image_get_pixbuf (GTK_IMAGE (data->image)));
580
message = g_strdup_printf (_("The application '%s' is ready to be used"),
581
gtk_entry_get_text (GTK_ENTRY (data->entry)));
583
message = g_strdup_printf (_("The application '%s' could not be created"),
584
gtk_entry_get_text (GTK_ENTRY (data->entry)));
586
notification = notify_notification_new (message,
591
notify_notification_add_action (notification, "launch", _("Launch"),
592
(NotifyActionCallback)notify_launch_cb,
593
g_path_get_basename (desktop_file),
595
notify_notification_set_icon_from_pixbuf (notification, gtk_image_get_pixbuf (GTK_IMAGE (data->image)));
596
g_free (desktop_file);
599
notify_notification_set_timeout (notification, NOTIFY_EXPIRES_DEFAULT);
600
notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW);
601
notify_notification_set_hint (notification, "transient", g_variant_new_boolean (TRUE));
602
notify_notification_show (notification, NULL);
605
ephy_application_dialog_data_free (data);
606
gtk_widget_destroy (GTK_WIDGET (dialog));
610
window_cmd_file_save_as_application (GtkAction *action,
614
GtkWidget *dialog, *box, *image, *entry, *content_area;
616
EphyApplicationDialogData *data;
618
embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
619
g_return_if_fail (embed != NULL);
621
view = EPHY_WEB_VIEW (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed));
623
/* Show dialog with icon, title. */
624
dialog = gtk_dialog_new_with_buttons (_("Create Web Application"),
633
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
634
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
635
gtk_box_set_spacing (GTK_BOX (content_area), 14); /* 14 + 2 * 5 = 24 */
637
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
638
gtk_container_add (GTK_CONTAINER (content_area), box);
640
image = gtk_image_new ();
641
gtk_widget_set_size_request (image, 128, 128);
642
gtk_container_add (GTK_CONTAINER (box), image);
644
entry = gtk_entry_new ();
645
gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
646
gtk_box_pack_end (GTK_BOX (box), entry, FALSE, FALSE, 0);
648
data = g_slice_new0 (EphyApplicationDialogData);
653
fill_default_application_image (data);
654
fill_default_application_title (data);
656
gtk_widget_show_all (dialog);
658
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
659
g_signal_connect (dialog, "response",
660
G_CALLBACK (dialog_save_as_application_response_cb),
662
gtk_widget_show_all (dialog);
378
666
window_cmd_file_work_offline (GtkAction *action,
379
667
EphyWindow *window)