Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@gnome.org>2005-01-05 10:48:33 (GMT)
committer Marco Pesenti Gritti <marco@src.gnome.org>2005-01-05 10:48:33 (GMT)
commitac441ddbd092eb55a71966c253833d8273a78f7c (patch)
tree82e129c4cb320c908aa90f5e5e3e5eeb6f31e8a6
parentd8ee8d47ba0982593a9774bb326944349a784b89 (diff)
Implement "Save a copy..." menu item
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
-rw-r--r--ChangeLog10
-rw-r--r--backend/ev-document.c9
-rw-r--r--backend/ev-document.h6
-rw-r--r--data/evince-ui.xml6
-rw-r--r--pdf/xpdf/pdf-document.cc20
-rw-r--r--shell/ev-window.c118
6 files changed, 166 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 2f57ed0..0bf5393 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
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):
Queue a resize when zoom changes
diff --git a/backend/ev-document.c b/backend/ev-document.c
index e80f95f..2306a21 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 84b9e97..c0a4b46 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 be37be0..8452c68 100644
--- a/data/evince-ui.xml
+++ b/data/evince-ui.xml
@@ -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>
diff --git a/pdf/xpdf/pdf-document.cc b/pdf/xpdf/pdf-document.cc
index 76229db..ed3b505 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 007ca88..5b1375c 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"), "<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",