From: Marco Pesenti Gritti Date: Wed, 5 Jan 2005 10:48:33 +0000 (+0000) Subject: Implement "Save a copy..." menu item X-Git-Tag: EVINCE_0_1_0~21 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=ac441ddbd092eb55a71966c253833d8273a78f7c;p=evince.git Implement "Save a copy..." menu item 2005-01-05 Marco Pesenti Gritti * backend/ev-document.c: (ev_document_save): * backend/ev-document.h: * data/evince-ui.xml: * pdf/xpdf/pdf-document.cc: * shell/ev-window.c: (save_error_dialog), (ev_window_cmd_save_as): Implement "Save a copy..." menu item --- diff --git a/ChangeLog b/ChangeLog index 2f57ed08..0bf53936 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-01-05 Marco Pesenti Gritti + + * backend/ev-document.c: (ev_document_save): + * backend/ev-document.h: + * data/evince-ui.xml: + * pdf/xpdf/pdf-document.cc: + * shell/ev-window.c: (save_error_dialog), (ev_window_cmd_save_as): + + Implement "Save a copy..." menu item + 2005-01-05 Marco Pesenti Gritti * shell/ev-view.c: (ev_view_zoom): diff --git a/backend/ev-document.c b/backend/ev-document.c index e80f95fc..2306a21a 100644 --- a/backend/ev-document.c +++ b/backend/ev-document.c @@ -86,6 +86,15 @@ ev_document_load (EvDocument *document, return iface->load (document, uri, error); } +gboolean +ev_document_save (EvDocument *document, + const char *uri, + GError **error) +{ + EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); + return iface->save (document, uri, error); +} + char * ev_document_get_title (EvDocument *document) { diff --git a/backend/ev-document.h b/backend/ev-document.h index 84b9e979..c0a4b46c 100644 --- a/backend/ev-document.h +++ b/backend/ev-document.h @@ -49,6 +49,9 @@ struct _EvDocumentIface gboolean (* load) (EvDocument *document, const char *uri, GError **error); + gboolean (* save) (EvDocument *document, + const char *uri, + GError **error); int (* get_n_pages) (EvDocument *document); void (* set_page) (EvDocument *document, int page); @@ -75,6 +78,9 @@ GType ev_document_get_type (void); gboolean ev_document_load (EvDocument *document, const char *uri, GError **error); +gboolean ev_document_save (EvDocument *document, + const char *uri, + GError **error); char *ev_document_get_title (EvDocument *document); int ev_document_get_n_pages (EvDocument *document); void ev_document_set_page (EvDocument *document, diff --git a/data/evince-ui.xml b/data/evince-ui.xml index be37be0c..8452c689 100644 --- a/data/evince-ui.xml +++ b/data/evince-ui.xml @@ -2,9 +2,11 @@ - + + + - + diff --git a/pdf/xpdf/pdf-document.cc b/pdf/xpdf/pdf-document.cc index 76229dbc..ed3b5054 100644 --- a/pdf/xpdf/pdf-document.cc +++ b/pdf/xpdf/pdf-document.cc @@ -197,6 +197,25 @@ pdf_document_load (EvDocument *document, return TRUE; } +static gboolean +pdf_document_save (EvDocument *document, + const char *uri, + GError **error) +{ + PdfDocument *pdf_document = PDF_DOCUMENT (document); + char *filename; + gboolean retval = FALSE; + + filename = g_filename_from_uri (uri, NULL, error); + if (filename != NULL) { + GString *fname = new GString (filename); + + retval = pdf_document->doc->saveAs (fname); + } + + return retval; +} + static int pdf_document_get_n_pages (EvDocument *document) { @@ -975,6 +994,7 @@ static void pdf_document_document_iface_init (EvDocumentIface *iface) { iface->load = pdf_document_load; + iface->save = pdf_document_save; iface->get_n_pages = pdf_document_get_n_pages; iface->set_page = pdf_document_set_page; iface->get_page = pdf_document_get_page; diff --git a/shell/ev-window.c b/shell/ev-window.c index 007ca889..5b1375cc 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -348,6 +348,119 @@ ev_window_cmd_file_open (GtkAction *action, EvWindow *ev_window) ev_application_open (EV_APP, NULL); } +/* FIXME +static gboolean +overwrite_existing_file (GtkWindow *window, const gchar *file_name) +{ + GtkWidget *msgbox; + gchar *utf8_file_name; + AtkObject *obj; + gint ret; + + utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL); + msgbox = gtk_message_dialog_new ( + window, + (GtkDialogFlags)GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + _("A file named \"%s\" already exists."), + utf8_file_name); + g_free (utf8_file_name); + + gtk_message_dialog_format_secondary_text ( + GTK_MESSAGE_DIALOG (msgbox), + _("Do you want to replace it with the one you are saving?")); + + gtk_dialog_add_button (GTK_DIALOG (msgbox), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); + + gtk_dialog_add_button (GTK_DIALOG (msgbox), + _("_Replace"), GTK_RESPONSE_YES); + + gtk_dialog_set_default_response (GTK_DIALOG (msgbox), + GTK_RESPONSE_CANCEL); + + obj = gtk_widget_get_accessible (msgbox); + + if (GTK_IS_ACCESSIBLE (obj)) + atk_object_set_name (obj, _("Question")); + + ret = gtk_dialog_run (GTK_DIALOG (msgbox)); + gtk_widget_destroy (msgbox); + + return (ret == GTK_RESPONSE_YES); +} +*/ + +static void +save_error_dialog (GtkWindow *window, const gchar *file_name) +{ + GtkWidget *error_dialog; + + error_dialog = gtk_message_dialog_new ( + window, + (GtkDialogFlags)GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + _("The file could not be saved as \"%s\"."), + file_name); + + /* Easy way to make the text bold while keeping the string + * above free from pango markup (FIXME ?) */ + gtk_message_dialog_format_secondary_text ( + GTK_MESSAGE_DIALOG (error_dialog), " "); + + gtk_dialog_run (GTK_DIALOG (error_dialog)); + gtk_widget_destroy (error_dialog); +} + +static void +ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window) +{ + GtkWidget *fc; + GtkFileFilter *pdf_filter, *all_filter; + gchar *uri = NULL; + + fc = gtk_file_chooser_dialog_new ( + _("Save a Copy"), + NULL, GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_OK, + NULL); + gtk_window_set_modal (GTK_WINDOW (fc), TRUE); + + pdf_filter = gtk_file_filter_new (); + gtk_file_filter_set_name (pdf_filter, _("PDF Documents")); + gtk_file_filter_add_mime_type (pdf_filter, "application/pdf"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), pdf_filter); + + all_filter = gtk_file_filter_new (); + gtk_file_filter_set_name (all_filter, _("All Files")); + gtk_file_filter_add_pattern (all_filter, "*"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), all_filter); + gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (fc), pdf_filter); + + gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK); + + gtk_widget_show (fc); + + while (gtk_dialog_run (GTK_DIALOG (fc)) == GTK_RESPONSE_OK) { + uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (fc)); + +/* FIXME + if (g_file_test (uri, G_FILE_TEST_EXISTS) && + !overwrite_existing_file (GTK_WINDOW (fc), uri)) + continue; +*/ + + if (ev_document_save (ev_window->priv->document, uri, NULL)) + break; + else + save_error_dialog (GTK_WINDOW (fc), uri); + } + gtk_widget_destroy (fc); +} + static gboolean using_postscript_printer (GnomePrintConfig *config) { @@ -1112,7 +1225,10 @@ static GtkActionEntry entries[] = { { "FileOpen", GTK_STOCK_OPEN, N_("_Open"), "O", N_("Open a file"), G_CALLBACK (ev_window_cmd_file_open) }, - { "FilePrint", GTK_STOCK_PRINT, N_("_Print"), "P", + { "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy..."), NULL, + N_("Save the current document with a new filename"), + G_CALLBACK (ev_window_cmd_save_as) }, + { "FilePrint", GTK_STOCK_PRINT, N_("_Print"), "P", N_("Print this document"), G_CALLBACK (ev_window_cmd_file_print) }, { "FileCloseWindow", GTK_STOCK_CLOSE, N_("_Close"), "W",