summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 767c59e)
raw | patch | inline | side by side (parent: 767c59e)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 10 Nov 2011 14:34:28 +0000 (15:34 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 10 Nov 2011 14:34:28 +0000 (15:34 +0100) |
- In the widget, this is available as 'gtk_tpdfv_reload()' which closes and
reopens the PDF file; updating internal settings accordingly.
- In the GUI, this may be triggered by pressing the 'r' key.
reopens the PDF file; updating internal settings accordingly.
- In the GUI, this may be triggered by pressing the 'r' key.
src/gtk-tpdfv.c | patch | blob | history | |
src/gtk-tpdfv.h | patch | blob | history | |
src/tpdfview.c | patch | blob | history |
diff --git a/src/gtk-tpdfv.c b/src/gtk-tpdfv.c
index 771dff99871ebd2f2490207790760175caa684e9..ee68357d1253de739f77b7002a4785f2b3f4346b 100644 (file)
--- a/src/gtk-tpdfv.c
+++ b/src/gtk-tpdfv.c
* Private helper functions.
*/
-static gboolean
-tpdfv_init(gtk_tpdfv_t *pdf, const char *filename)
+static void
+tpdfv_open(gtk_tpdfv_t *pdf)
{
GError *err = NULL;
+ if ((! pdf) || (! pdf->filename))
+ return;
+
+ pdf->doc = poppler_document_new_from_file(pdf->filename,
+ /* password = */ NULL, &err);
+ if (! pdf->doc) {
+ fprintf(stderr, "Failed to open PDF: %s.\n", err->message);
+ return;
+ }
+
+ pdf->total_pages = poppler_document_get_n_pages(pdf->doc);
+ if (pdf->current_page_no >= pdf->total_pages)
+ pdf->current_page_no = pdf->total_pages - 1;
+} /* tpdfv_open */
+
+static void
+tpdfv_close(gtk_tpdfv_t *pdf)
+{
+ if (! pdf)
+ return;
+
+ g_object_unref(pdf->doc);
+ pdf->doc = NULL;
+ pdf->current_page = NULL;
+} /* tpdfv_close */
+
+static gboolean
+tpdfv_init(gtk_tpdfv_t *pdf, const char *filename)
+{
if (strstr(filename, "://"))
pdf->filename = strdup(filename);
else {
return FALSE;
}
- pdf->doc = poppler_document_new_from_file(pdf->filename,
- /* password = */ NULL, &err);
- if (! pdf->doc) {
- fprintf(stderr, "Failed to open PDF: %s.\n", err->message);
- return FALSE;
- }
+ pdf->doc = NULL;
+ tpdfv_open(pdf);
pdf->current_page_no = 0;
pdf->current_page = poppler_document_get_page(pdf->doc,
return FALSE;
}
- pdf->total_pages = poppler_document_get_n_pages(pdf->doc);
-
pdf->zoom_mode = TPDFV_ZOOM_CUSTOM;
pdf->zoom_factor = 1.0;
pdf->delta_x = pdf->delta_y = 0.0;
if (! pdf)
return;
- g_object_unref(pdf->doc);
- pdf->doc = NULL;
+ tpdfv_close(pdf);
pdf->current_page = NULL;
free(pdf->filename);
pdf->filename = NULL;
pdf = GTK_TPDFV_GET_PRIVATE(widget);
- if (poppler_page_get_index(pdf->current_page)
- != pdf->current_page_no) {
+ if ((! pdf->current_page) || (poppler_page_get_index(pdf->current_page)
+ != pdf->current_page_no)) {
pdf->current_page = poppler_document_get_page(pdf->doc,
pdf->current_page_no);
return GTK_WIDGET(tpdfv);
} /* gtk_tpdfv_new */
+void
+gtk_tpdfv_reload(GtkWidget *widget)
+{
+ gtk_tpdfv_t *pdf;
+
+ pdf = GTK_TPDFV_GET_PRIVATE(widget);
+ tpdfv_close(pdf);
+ tpdfv_open(pdf);
+ do_redraw(widget);
+} /* gtk_tpdfv_reload */
+
void
gtk_tpdfv_page_up(GtkWidget *widget)
{
diff --git a/src/gtk-tpdfv.h b/src/gtk-tpdfv.h
index 7d260bd28e5491c213567de01a31dd338cc2d8fb..f97224c4b6f87a4b8ada1b7764e4b1d6ae542814 100644 (file)
--- a/src/gtk-tpdfv.h
+++ b/src/gtk-tpdfv.h
GtkWidget *
gtk_tpdfv_new(const char *filename);
+/*
+ * gtk_tpdfv_reload:
+ * Reload the previously opened PDF file.
+ */
+void
+gtk_tpdfv_reload(GtkWidget *widget);
+
/*
* gtk_tpdfv_page_up, gtk_tpdfv_page_down,
* gtk_tpdfv_first_page, gtk_tpdfv_last_page:
diff --git a/src/tpdfview.c b/src/tpdfview.c
index b92d5440799e212cf3314c8be6da87d544b0ade4..0d3755958a800a9bb511ccacde5ef3e02678a2e2 100644 (file)
--- a/src/tpdfview.c
+++ b/src/tpdfview.c
gtk_main_quit();
break;
+ case GDK_r:
+ gtk_tpdfv_reload(tpdfv);
+ break;
+
/* navigation */
case GDK_Page_Up:
gtk_tpdfv_page_up(tpdfv);