static void save_file_failed_error (ScreenshotDialog *dialog, GError *error) { GtkWidget *toplevel; GtkWidget *error_dialog; char *folder; toplevel = screenshot_dialog_get_toplevel (dialog); screenshot_dialog_set_busy (dialog, FALSE); /* we had an error, display a dialog to the user and let him choose * another name/location to save the screenshot. */ folder = screenshot_dialog_get_folder (dialog); error_dialog = gtk_message_dialog_new (GTK_WINDOW (toplevel), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Error while saving screenshot")); /* translators: first %s is the folder URI, second %s is the VFS error */ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error_dialog), _("Impossible to save the screenshot " "to %s.\n Error was %s.\n Please choose another " "location and retry."), folder, error->message); gtk_widget_show (error_dialog); g_signal_connect (error_dialog, "response", G_CALLBACK (error_dialog_response_cb), dialog); g_free (folder); }
static void screenshot_save_to_file (ScreenshotApplication *self) { GFile *target_file; if (self->priv->dialog != NULL) screenshot_dialog_set_busy (self->priv->dialog, TRUE); target_file = g_file_new_for_uri (self->priv->save_uri); if (self->priv->should_overwrite) { g_file_replace_async (target_file, NULL, FALSE, G_FILE_CREATE_NONE, G_PRIORITY_DEFAULT, NULL, save_file_create_ready_cb, self); } else { g_file_create_async (target_file, G_FILE_CREATE_NONE, G_PRIORITY_DEFAULT, NULL, save_file_create_ready_cb, self); } g_object_unref (target_file); }
static void save_callback (TransferResult result, char *error_message, gpointer data) { ScreenshotDialog *dialog = data; GtkWidget *toplevel; toplevel = screenshot_dialog_get_toplevel (dialog); screenshot_dialog_set_busy (dialog, FALSE); if (result == TRANSFER_OK) { save_folder_to_gconf (dialog); set_recent_entry (dialog); gtk_widget_destroy (toplevel); /* we're done, stop the mainloop now */ gtk_main_quit (); } else if (result == TRANSFER_OVERWRITE || result == TRANSFER_CANCELLED) { /* user has canceled the overwrite dialog or the transfer itself, let him * choose another name. */ screenshot_dialog_focus_entry (dialog); } else /* result == TRANSFER_ERROR */ { /* we had an error, display a dialog to the user and let him choose * another name/location to save the screenshot. */ GtkWidget *error_dialog; char *uri; uri = screenshot_dialog_get_uri (dialog); error_dialog = gtk_message_dialog_new (GTK_WINDOW (toplevel), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Error while saving screenshot"), NULL); /* translators: first %s is the file path, second %s is the VFS error */ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error_dialog), _("Impossible to save the screenshot " "to %s.\n Error was %s.\n Please choose another " "location and retry."), uri, error_message); gtk_widget_show (error_dialog); g_signal_connect (error_dialog, "response", G_CALLBACK (error_dialog_response_cb), dialog); g_free (uri); } }
static void screenshot_dialog_response_cb (GtkDialog *d, gint response_id, ScreenshotDialog *dialog) { char *uri; if (response_id == GTK_RESPONSE_HELP) { display_help (GTK_WINDOW (d)); } else if (response_id == GTK_RESPONSE_OK) { uri = screenshot_dialog_get_uri (dialog); if (temporary_file == NULL) { save_immediately = TRUE; screenshot_dialog_set_busy (dialog, TRUE); } else { /* we've saved the temporary file, lets try to copy it to the * correct location. */ try_to_save (dialog, uri); } g_free (uri); } else if (response_id == SCREENSHOT_RESPONSE_COPY) { GtkClipboard *clipboard; GdkPixbuf *screenshot; clipboard = gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (d)), GDK_SELECTION_CLIPBOARD); screenshot = screenshot_dialog_get_screenshot (dialog); gtk_clipboard_set_image (clipboard, screenshot); } else /* dialog was canceled */ { gtk_widget_destroy (GTK_WIDGET (d)); gtk_main_quit (); } }
static void try_to_save (ScreenshotDialog *dialog) { gchar *target_uri; GFile *target_file; screenshot_dialog_set_busy (dialog, TRUE); target_uri = screenshot_dialog_get_uri (dialog); target_file = g_file_new_for_uri (target_uri); g_file_create_async (target_file, G_FILE_CREATE_NONE, G_PRIORITY_DEFAULT, NULL, save_file_create_ready_cb, dialog); g_object_unref (target_file); g_free (target_uri); }
static void try_to_save (ScreenshotDialog *dialog, const char *target) { GFile *source_file, *target_file; g_assert (temporary_file); screenshot_dialog_set_busy (dialog, TRUE); source_file = g_file_new_for_path (temporary_file); target_file = g_file_new_for_uri (target); screenshot_xfer_uri (source_file, target_file, screenshot_dialog_get_toplevel (dialog), save_callback, dialog); /* screenshot_xfer_uri () holds a ref, so we can unref now */ g_object_unref (source_file); g_object_unref (target_file); }
static void save_pixbuf_handle_error (ScreenshotApplication *self, GError *error) { if (!g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "Unity") || screenshot_config->interactive) { ScreenshotDialog *dialog = self->priv->dialog; screenshot_dialog_set_busy (dialog, FALSE); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS) && !self->priv->should_overwrite) { gchar *folder = screenshot_dialog_get_folder (dialog); gchar *folder_uri = g_path_get_basename (folder); gchar *folder_name = g_uri_unescape_string (folder_uri, NULL); gchar *file_name = screenshot_dialog_get_filename (dialog); gchar *detail = g_strdup_printf (_("A file named \"%s\" already exists in \"%s\""), file_name, folder_name); gint response; response = screenshot_show_dialog (GTK_WINDOW (dialog->dialog), GTK_MESSAGE_WARNING, GTK_BUTTONS_YES_NO, _("Overwrite existing file?"), detail); g_free (folder); g_free (folder_name); g_free (folder_uri); g_free (file_name); g_free (detail); if (response == GTK_RESPONSE_YES) { self->priv->should_overwrite = TRUE; screenshot_save_to_file (self); return; } } else { screenshot_show_dialog (GTK_WINDOW (dialog->dialog), GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Unable to capture a screenshot"), _("Error creating file. Please choose another location and retry.")); } gtk_widget_grab_focus (dialog->filename_entry); } else { g_critical ("Unable to save the screenshot: %s", error->message); screenshot_play_sound_effect ("dialog-error", _("Unable to capture a screenshot")); g_application_release (G_APPLICATION (self)); if (screenshot_config->file != NULL) exit (EXIT_FAILURE); } }