+ switch (ev_link_action_get_action_type (action)) {
+ case EV_LINK_ACTION_TYPE_GOTO_DEST: {
+ EvLinkDest *dest;
+
+ dest = ev_link_action_get_dest (action);
+ if (!dest)
+ return;
+
+ ev_window_cmd_file_open_copy_at_dest (window, dest);
+ }
+ break;
+ case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
+ launch_external_uri (window, action);
+ break;
+ case EV_LINK_ACTION_TYPE_LAUNCH:
+ launch_action (window, action);
+ break;
+ case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
+ open_remote_link (window, action);
+ break;
+ case EV_LINK_ACTION_TYPE_NAMED:
+ do_action_named (window, action);
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+}
+
+static void
+ev_view_popup_cmd_open_link (GtkAction *action, EvWindow *window)
+{
+ ev_view_handle_link (EV_VIEW (window->priv->view), window->priv->link);
+}
+
+static void
+ev_view_popup_cmd_open_link_new_window (GtkAction *action, EvWindow *window)
+{
+ EvLinkAction *ev_action = NULL;
+ EvLinkDest *dest;
+
+ ev_action = ev_link_get_action (window->priv->link);
+ if (!ev_action)
+ return;
+
+ dest = ev_link_action_get_dest (ev_action);
+ if (!dest)
+ return;
+
+ ev_window_cmd_file_open_copy_at_dest (window, dest);
+}
+
+static void
+ev_view_popup_cmd_copy_link_address (GtkAction *action, EvWindow *window)
+{
+ GtkClipboard *clipboard;
+ EvLinkAction *ev_action;
+ const gchar *uri;
+
+ ev_action = ev_link_get_action (window->priv->link);
+ if (!ev_action)
+ return;
+
+ uri = ev_link_action_get_uri (ev_action);
+
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window),
+ GDK_SELECTION_CLIPBOARD);
+ gtk_clipboard_set_text (clipboard, uri, -1);
+}
+
+static void
+image_save_dialog_response_cb (GtkWidget *fc,
+ gint response_id,
+ EvWindow *ev_window)
+{
+ GtkWidget *format_chooser;
+ GnomeVFSURI *target_uri;
+ gchar *uri;
+ gchar *uri_extension;
+ gchar *filename;
+ gchar *file_format;
+ gboolean is_local;
+ GError *error = NULL;
+ guint format;
+
+ if (response_id != GTK_RESPONSE_OK) {
+ gtk_widget_destroy (fc);
+ return;
+ }
+
+ format_chooser = gtk_file_chooser_get_extra_widget (GTK_FILE_CHOOSER (fc));
+
+ uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
+ format = egg_file_format_chooser_get_format (EGG_FILE_FORMAT_CHOOSER (format_chooser), uri);
+ uri_extension = egg_file_format_chooser_append_extension (EGG_FILE_FORMAT_CHOOSER (format_chooser),
+ uri, format);
+ file_format = (char *)egg_file_format_chooser_get_format_data (EGG_FILE_FORMAT_CHOOSER (format_chooser),
+ format);
+ target_uri = gnome_vfs_uri_new (uri_extension);
+ is_local = gnome_vfs_uri_is_local (target_uri);
+
+ if (is_local) {
+ filename = g_filename_from_uri (uri_extension, NULL, NULL);
+ } else {
+ filename = ev_tmp_filename ("saveimage");
+ }
+
+ g_free (uri);
+ g_free (uri_extension);
+
+ gdk_pixbuf_save (ev_image_get_pixbuf (ev_window->priv->image),
+ filename, file_format, &error, NULL);
+
+ if (error) {
+ ev_window_error_message (GTK_WINDOW (ev_window),
+ _("The image could not be saved."),
+ error);
+ g_error_free (error);
+ g_free (filename);
+ gnome_vfs_uri_unref (target_uri);
+ gtk_widget_destroy (fc);
+
+ return;
+ }
+
+ if (!is_local) {
+ GnomeVFSURI *source_uri;
+ gchar *local_uri;
+
+ local_uri = g_filename_to_uri (filename, NULL, NULL);
+ source_uri = gnome_vfs_uri_new (local_uri);
+ g_free (local_uri);
+ ev_window_save_remote (ev_window, source_uri, target_uri);
+ gnome_vfs_uri_unref (source_uri);
+ }
+
+ g_free (filename);
+ gnome_vfs_uri_unref (target_uri);
+ gtk_widget_destroy (fc);
+}
+
+static void
+ev_view_popup_cmd_save_image_as (GtkAction *action, EvWindow *window)
+{
+ GtkWidget *fc, *format_chooser;
+ GtkFileFilter *filter;
+
+ if (!window->priv->image)
+ return;
+
+ fc = gtk_file_chooser_dialog_new (_("Save Image"),
+ GTK_WINDOW (window),
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_OK,
+ NULL);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
+ gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (fc), FALSE);
+ gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
+
+ format_chooser = egg_file_format_chooser_new ();
+ egg_file_format_chooser_add_pixbuf_formats (EGG_FILE_FORMAT_CHOOSER (format_chooser),
+ 0, NULL);
+
+ gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (fc), format_chooser);
+
+ g_signal_connect (fc, "response",
+ G_CALLBACK (image_save_dialog_response_cb),
+ window);
+
+ gtk_widget_show (fc);
+}
+
+static void
+ev_view_popup_cmd_copy_image (GtkAction *action, EvWindow *window)
+{
+ GtkClipboard *clipboard;
+
+ if (!window->priv->image)
+ return;
+
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window),
+ GDK_SELECTION_CLIPBOARD);
+ gtk_clipboard_set_image (clipboard,
+ ev_image_get_pixbuf (window->priv->image));
+}
+
+static void
+ev_attachment_popup_cmd_open_attachment (GtkAction *action, EvWindow *window)
+{
+ GList *l;
+
+ if (!window->priv->attach_list)
+ return;
+
+ for (l = window->priv->attach_list; l && l->data; l = g_list_next (l)) {
+ EvAttachment *attachment;
+ GError *error = NULL;
+
+ attachment = (EvAttachment *) l->data;
+
+ ev_attachment_open (attachment, &error);
+
+ if (error) {
+ ev_window_error_message (GTK_WINDOW (window),
+ _("Unable to open attachment"),
+ error);
+ g_error_free (error);
+ }
+ }
+}
+
+static void
+attachment_save_dialog_response_cb (GtkWidget *fc,
+ gint response_id,
+ EvWindow *ev_window)
+{
+ GnomeVFSURI *target_uri;
+ gchar *uri;
+ GList *l;
+ GtkFileChooserAction fc_action;
+ gboolean is_dir;
+ gboolean is_local;
+
+ if (response_id != GTK_RESPONSE_OK) {
+ gtk_widget_destroy (fc);
+ return;
+ }
+
+ uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
+ target_uri = gnome_vfs_uri_new (uri);
+ g_object_get (G_OBJECT (fc), "action", &fc_action, NULL);
+ is_dir = (fc_action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+ is_local = gnome_vfs_uri_is_local (target_uri);
+
+ for (l = ev_window->priv->attach_list; l && l->data; l = g_list_next (l)) {
+ EvAttachment *attachment;
+ gchar *filename;
+ GError *error = NULL;
+
+ attachment = (EvAttachment *) l->data;
+
+ if (is_local) {
+ if (is_dir) {
+ filename = g_strjoin ("/", uri,
+ ev_attachment_get_name (attachment),
+ NULL);
+ } else {
+ filename = g_strdup (uri);
+ }
+ } else {
+ filename = ev_tmp_filename ("saveattachment");
+ }
+
+ ev_attachment_save (attachment, filename, &error);
+
+ if (error) {
+ ev_window_error_message (GTK_WINDOW (ev_window),
+ _("The attachment could not be saved."),
+ error);
+ g_error_free (error);
+ g_free (filename);
+
+ continue;
+ }
+
+ if (!is_local) {
+ GnomeVFSURI *src_uri;
+ GnomeVFSURI *dest_uri;
+ gchar *local_uri;
+
+ if (is_dir) {
+ const gchar *name = ev_attachment_get_name (attachment);
+
+ dest_uri = gnome_vfs_uri_append_file_name (target_uri,
+ name);
+ } else {
+ dest_uri = gnome_vfs_uri_ref (target_uri);
+ }
+
+ local_uri = g_filename_to_uri (filename, NULL, NULL);
+ src_uri = gnome_vfs_uri_new (local_uri);
+ g_free (local_uri);
+ ev_window_save_remote (ev_window, src_uri, dest_uri);
+ gnome_vfs_uri_unref (src_uri);
+ gnome_vfs_uri_unref (dest_uri);
+ }
+
+ g_free (filename);