+static void
+image_save_dialog_response_cb (GtkWidget *fc,
+ gint response_id,
+ EvWindow *ev_window)
+{
+ gchar *uri;
+ gchar *filename;
+ GError *error = NULL;
+
+ if (response_id != GTK_RESPONSE_OK) {
+ gtk_widget_destroy (fc);
+ return;
+ }
+
+ uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
+ filename = g_filename_from_uri (uri, NULL, NULL);
+ g_free (uri);
+
+ /* FIXME: allow saving in other image formats than png */
+ gdk_pixbuf_save (ev_image_get_pixbuf (ev_window->priv->image),
+ filename, "png", &error, NULL);
+
+ if (error) {
+ ev_window_error_dialog (GTK_WINDOW (ev_window),
+ _("The image could not be saved."),
+ error);
+ g_error_free (error);
+ }
+
+ g_free (filename);
+
+ gtk_widget_destroy (fc);
+}
+
+static void
+ev_view_popup_cmd_save_image_as (GtkAction *action, EvWindow *window)
+{
+ GtkWidget *fc;
+ 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_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
+
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("Images"));
+ gtk_file_filter_add_pixbuf_formats (filter);
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), filter);
+
+ 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_dialog (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)
+{
+ gchar *uri;
+ GList *l;
+ GtkFileChooserAction fc_action;
+ gboolean is_dir;
+
+ if (response_id != GTK_RESPONSE_OK) {
+ gtk_widget_destroy (fc);
+ return;
+ }
+
+ uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc));
+
+ g_object_get (G_OBJECT (fc), "action", &fc_action, NULL);
+ is_dir = (fc_action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+
+ 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_dir) {
+ filename = g_strjoin ("/", uri,
+ ev_attachment_get_name (attachment),
+ NULL);
+ } else {
+ filename = g_strdup (uri);
+ }
+
+ ev_attachment_save (attachment, filename, &error);
+ g_free (filename);
+
+ if (error) {
+ ev_window_error_dialog (GTK_WINDOW (ev_window),
+ _("The attachment could not be saved."),
+ error);
+ g_error_free (error);
+ }
+ }
+
+ g_free (uri);
+
+ gtk_widget_destroy (fc);
+}
+
+static void
+ev_attachment_popup_cmd_save_attachment_as (GtkAction *action, EvWindow *window)
+{
+ GtkWidget *fc;
+ EvAttachment *attachment = NULL;
+
+ if (!window->priv->attach_list)
+ return;
+
+ if (g_list_length (window->priv->attach_list) == 1)
+ attachment = (EvAttachment *) window->priv->attach_list->data;
+
+ fc = gtk_file_chooser_dialog_new (
+ _("Save Attachment"),
+ GTK_WINDOW (window),
+ attachment ? GTK_FILE_CHOOSER_ACTION_SAVE : GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ 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_do_overwrite_confirmation (GTK_FILE_CHOOSER (fc), TRUE);
+
+ if (attachment)
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc),
+ ev_attachment_get_name (attachment));
+
+ g_signal_connect (fc, "response",
+ G_CALLBACK (attachment_save_dialog_response_cb),
+ window);
+
+ gtk_widget_show (fc);
+}
+