]> www.fi.muni.cz Git - evince.git/commitdiff
Implement "Save a copy..." menu item
authorMarco Pesenti Gritti <marco@gnome.org>
Wed, 5 Jan 2005 10:48:33 +0000 (10:48 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Wed, 5 Jan 2005 10:48:33 +0000 (10:48 +0000)
2005-01-05  Marco Pesenti Gritti  <marco@gnome.org>

        * 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

ChangeLog
backend/ev-document.c
backend/ev-document.h
data/evince-ui.xml
pdf/xpdf/pdf-document.cc
shell/ev-window.c

index 2f57ed08c6a9ac77930f684a935a96e47b57bac7..0bf53936183fee3af5c96452c0c72c58933bfb3e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2005-01-05  Marco Pesenti Gritti  <marco@gnome.org>
+
+       * 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  <marco@gnome.org>
 
        * shell/ev-view.c: (ev_view_zoom):
index e80f95fccf2567a50dd204ce7e824f0ca66c31f3..2306a21a1b24796aa2bfb27e680205320276d2e1 100644 (file)
@@ -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)
 {
index 84b9e979ace66501dc580e5d9f1786251fdb0e5e..c0a4b46c09c40c6dca94ed8ec5983a50f5dcbbc9 100644 (file)
@@ -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,
index be37be0cae8d9a3db8ab452fbaaacc08e53b581b..8452c689235e11701b2e3de26a47878d5fd04b0f 100644 (file)
@@ -2,9 +2,11 @@
   <menubar name="MainMenu">
     <menu name="FileMenu" action="File">
       <menuitem name="FileOpenMenu" action="FileOpen"/>
-      <separator name="FileSep1"/>
+      <separator/>
+      <menuitem name="FileSaveAsMenu" action="FileSaveAs"/>
+      <separator/>
       <menuitem name="FilePrintMenu" action="FilePrint"/>
-      <separator name="FileSep2"/>
+      <separator/>
       <menuitem name="FileCloseWindowMenu" action="FileCloseWindow"/>
     </menu>
 
index 76229dbcfedeb9b530d580f2cc30ae46b4db4553..ed3b5054b06a501174331aed7d02c064eba98c92 100644 (file)
@@ -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;
index 007ca8893ac86d434178bde2ad9beb9d35b3695e..5b1375cc78eaa77e34b15e1d38c12d7cecaabc9e 100644 (file)
@@ -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"), "<control>O",
          N_("Open a file"),
          G_CALLBACK (ev_window_cmd_file_open) },
-        { "FilePrint", GTK_STOCK_PRINT, N_("_Print"), "<control>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"), "<control>P",
          N_("Print this document"),
          G_CALLBACK (ev_window_cmd_file_print) },
        { "FileCloseWindow", GTK_STOCK_CLOSE, N_("_Close"), "<control>W",