Remove invisible pages from the memory.

This commit is contained in:
Sebastian Ramacher 2012-03-24 16:15:34 +01:00
parent 0e2e9d912b
commit 64905f282b
6 changed files with 147 additions and 61 deletions

View File

@ -94,6 +94,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpoi
} else {
page->visible = false;
}
zathura_page_widget_update_view_time(ZATHURA_PAGE(page->drawing_area));
}
statusbar_page_number_update(zathura);

View File

@ -80,19 +80,22 @@ config_load_default(zathura_t* zathura)
girara_mode_set(gsession, zathura->modes.normal);
/* zathura settings */
girara_setting_add(gsession, "database", "plain", STRING, true, _("Database backend"), NULL, NULL);
girara_setting_add(gsession, "database", "plain", STRING, true, _("Database backend"), NULL, NULL);
int_value = 10;
girara_setting_add(gsession, "zoom-step", &int_value, INT, false, _("Zoom step"), NULL, NULL);
girara_setting_add(gsession, "zoom-step", &int_value, INT, false, _("Zoom step"), NULL, NULL);
int_value = 1;
girara_setting_add(gsession, "page-padding", &int_value, INT, false, _("Padding between pages"), cb_page_padding_changed, NULL);
girara_setting_add(gsession, "page-padding", &int_value, INT, false, _("Padding between pages"), cb_page_padding_changed, NULL);
int_value = 1;
girara_setting_add(gsession, "pages-per-row", &int_value, INT, false, _("Number of pages per row"), cb_pages_per_row_value_changed, NULL);
girara_setting_add(gsession, "pages-per-row", &int_value, INT, false, _("Number of pages per row"), cb_pages_per_row_value_changed, NULL);
float_value = 40;
girara_setting_add(gsession, "scroll-step", &float_value, FLOAT, false, _("Scroll step"), NULL, NULL);
girara_setting_add(gsession, "scroll-step", &float_value, FLOAT, false, _("Scroll step"), NULL, NULL);
int_value = 10;
girara_setting_add(gsession, "zoom-min", &int_value, INT, false, _("Zoom minimum"), NULL, NULL);
girara_setting_add(gsession, "zoom-min", &int_value, INT, false, _("Zoom minimum"), NULL, NULL);
int_value = 1000;
girara_setting_add(gsession, "zoom-max", &int_value, INT, false, _("Zoom maximum"), NULL, NULL);
girara_setting_add(gsession, "zoom-max", &int_value, INT, false, _("Zoom maximum"), NULL, NULL);
int_value = 30;
girara_setting_add(gsession, "page-store-threshold", &int_value, INT, false, _("Store unvisible pages only for some time (in seconds)"), NULL, NULL);
girara_setting_add(gsession, "page-store-interval", &int_value, INT, true, _("Amount of seconds between the checks for invisible pages"), NULL, NULL);
girara_setting_add(gsession, "recolor-darkcolor", NULL, STRING, false, _("Recoloring (dark color)"), cb_color_change, NULL);
girara_setting_set(gsession, "recolor-darkcolor", "#FFFFFF");

View File

@ -34,6 +34,7 @@ typedef struct zathura_page_widget_private_s {
girara_list_t* images; /**< List of images on the page */
bool images_got; /**< True if we already tried to retrieve the list of images */
zathura_image_t* current_image; /**< Image data of selected image */
gint64 last_view;
} zathura_page_widget_private_t;
#define ZATHURA_PAGE_GET_PRIVATE(obj) \
@ -721,3 +722,29 @@ cb_menu_image_copy(GtkMenuItem* item, ZathuraPage* page)
priv->current_image = NULL;
}
void
zathura_page_widget_update_view_time(ZathuraPage* widget)
{
g_return_if_fail(ZATHURA_IS_PAGE(widget) == TRUE);
zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(widget);
if (priv->page->visible == true) {
priv->last_view = g_get_real_time();
}
}
void
zathura_page_widget_purge_unused(ZathuraPage* widget, gint64 threshold)
{
g_return_if_fail(ZATHURA_IS_PAGE(widget) == TRUE);
zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(widget);
if (priv->page->visible == true || priv->surface == NULL || threshold <= 0) {
return;
}
const gint64 now = g_get_real_time();
if (now - priv->last_view >= threshold * G_USEC_PER_SEC) {
zathura_page_widget_update_surface(widget, NULL);
}
}

View File

@ -30,9 +30,9 @@ struct zathura_page_widget_class_s {
#define ZATHURA_PAGE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), ZATHURA_TYPE_PAGE, ZathuraPage))
#define ZATHURA_PAGE_CLASS(obj) \
(G_TYPE_CHECK_CLASS_CAST ((obj), ZATHURA_PAGE, ZathuraPageClass))
(G_TYPE_CHECK_CLASS_CAST ((obj), ZATHURA_TYPE_PAGE, ZathuraPageClass))
#define ZATHURA_IS_PAGE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZATHURA_PAGE))
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZATHURA_TYPE_PAGE))
#define ZATHURA_IS_PAGE_WDIGET_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE ((obj), ZATHURA_TYPE_PAGE))
#define ZATHURA_PAGE_GET_CLASS \
@ -78,4 +78,19 @@ void zathura_page_widget_clear_rectangles(ZathuraPage* widget);
*/
zathura_link_t* zathura_page_widget_link_get(ZathuraPage* widget, unsigned int index);
/**
* Update the last view time of the page.
*
* @param widget the widget
*/
void zathura_page_widget_update_view_time(ZathuraPage* widget);
/**
* If the page has not been viewed for some time, purge the surface.
*
* @param widget the widget
* @param threshold the threshold (in seconds)
*/
void zathura_page_widget_purge_unused(ZathuraPage* widget, gint64 threshold);
#endif

116
po/de.po
View File

@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: zathura 0.1.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-03-23 19:24+0100\n"
"POT-Creation-Date: 2012-03-24 16:14+0100\n"
"PO-Revision-Date: 2012-03-05 17:26+0100\n"
"Last-Translator: Sebastian Ramacher <s.ramacher@gmx.at>\n"
"Language-Team: pwmt.org <mail@pwmt.org>\n"
@ -13,90 +13,90 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: ../callbacks.c:151
#: ../callbacks.c:152
msgid "Failed to run xdg-open."
msgstr "Konnte xdg-open nicht ausführen."
#: ../callbacks.c:177
#: ../callbacks.c:178
#, c-format
msgid "Invalid input '%s' given."
msgstr "Ungültige Eingabe '%s' angegeben."
#: ../callbacks.c:211
#: ../callbacks.c:212
#, c-format
msgid "Invalid index '%s' given."
msgstr "Ungültiger Index '%s' angegeben."
#: ../commands.c:28 ../commands.c:63 ../commands.c:90 ../commands.c:132
#: ../commands.c:220 ../commands.c:237 ../commands.c:263 ../commands.c:337
#: ../commands.c:29 ../commands.c:64 ../commands.c:91 ../commands.c:133
#: ../commands.c:229 ../commands.c:246 ../commands.c:272 ../commands.c:346
#: ../shortcuts.c:807
msgid "No document opened."
msgstr "Kein Dokument geöffnet."
#: ../commands.c:34 ../commands.c:69 ../commands.c:96 ../commands.c:343
#: ../commands.c:35 ../commands.c:70 ../commands.c:97 ../commands.c:352
msgid "Invalid number of arguments given."
msgstr "Ungültige Anzahl an Argumenten angegeben."
#: ../commands.c:42
#: ../commands.c:43
#, c-format
msgid "Bookmark successfuly updated: %s"
msgstr "Lesezeichen erfolgreich aktualisiert: %s."
#: ../commands.c:48
#: ../commands.c:49
#, c-format
msgid "Could not create bookmark: %s"
msgstr "Konnte Lesezeichen nicht erstellen: %s"
#: ../commands.c:52
#: ../commands.c:53
#, c-format
msgid "Bookmark successfuly created: %s"
msgstr "Lesezeichen erfolgreich erstellt: %s"
#: ../commands.c:75
#: ../commands.c:76
#, c-format
msgid "Removed bookmark: %s"
msgstr "Lesezeichen entfernt: %s"
#: ../commands.c:77
#: ../commands.c:78
#, c-format
msgid "Failed to remove bookmark: %s"
msgstr "Konnte Lesezeichen nicht entfernen: %s"
#: ../commands.c:103
#: ../commands.c:104
#, c-format
msgid "No such bookmark: %s"
msgstr "Lesezeichen existiert nicht: %s"
#: ../commands.c:172
#: ../commands.c:173
msgid "No information available."
msgstr "Keine Information verfügbar."
#: ../commands.c:196
#: ../commands.c:197
msgid "Too many arguments."
msgstr "Zu viele Argumente angegeben."
#: ../commands.c:205
#: ../commands.c:206
msgid "No arguments given."
msgstr "Keine Argumente angegeben."
#: ../commands.c:243 ../commands.c:269
#: ../commands.c:252 ../commands.c:278
msgid "Document saved."
msgstr "Dokument gespeichert."
#: ../commands.c:245 ../commands.c:271
#: ../commands.c:254 ../commands.c:280
msgid "Failed to save document."
msgstr "Konnte Dokument nicht speichern."
#: ../commands.c:248 ../commands.c:274
#: ../commands.c:257 ../commands.c:283
msgid "Invalid number of arguments."
msgstr "Ungültige Anzahl an Argumenten."
#: ../commands.c:356
#: ../commands.c:365
#, c-format
msgid "Couldn't write attachment '%s' to '%s'."
msgstr "Konnte Anhang '%s' nicht nach '%s' schreiben."
#: ../commands.c:358
#: ../commands.c:367
#, c-format
msgid "Wrote attachment '%s' to '%s'."
msgstr "Anhang '%s' nach '%s' geschrieben."
@ -131,95 +131,107 @@ msgid "Zoom maximum"
msgstr "Maximale Vergrößerungsstufe"
#: ../config.c:97
msgid "Store unvisible pages only for some time (in seconds)"
msgstr ""
#: ../config.c:98
msgid "Amount of seconds between the checks for invisible pages"
msgstr ""
#: ../config.c:100
msgid "Recoloring (dark color)"
msgstr "Neufärben (Dunkle Farbe)"
#: ../config.c:99
#: ../config.c:102
msgid "Recoloring (light color)"
msgstr "Neufärben (Helle Farbe)"
#: ../config.c:101
#: ../config.c:104
msgid "Color for highlighting"
msgstr "Farbe für eine Markierung"
#: ../config.c:103
#: ../config.c:106
msgid "Color for highlighting (active)"
msgstr "Farbe für die aktuelle Markierung"
#: ../config.c:107
#: ../config.c:110
msgid "Recolor pages"
msgstr ""
#: ../config.c:109
#: ../config.c:112
msgid "Wrap scrolling"
msgstr ""
#: ../config.c:111
#: ../config.c:114
msgid "Transparency for highlighting"
msgstr "Transparenz einer Markierung"
#: ../config.c:113
#: ../config.c:116
msgid "Render 'Loading ...'"
msgstr "Zeige 'Lädt...'-Text beim Zeichnen einer Seite"
#: ../config.c:114
#: ../config.c:117
msgid "Adjust to when opening file"
msgstr "Seite einpassen"
#: ../config.c:116
#: ../config.c:119
msgid "Show hidden files and directories"
msgstr "Zeige versteckte Dateien und Ordner an"
#: ../config.c:118
#: ../config.c:121
msgid "Show directories"
msgstr "Zeige Ordner an"
#: ../config.c:120
#: ../config.c:123
msgid "Always open on first page"
msgstr "Öffne Dokument immer auf der ersten Seite"
#. define default inputbar commands
#: ../config.c:240
#: ../config.c:243
msgid "Add a bookmark"
msgstr "Füge Lesezeichen hinzu"
#: ../config.c:241
#: ../config.c:244
msgid "Delete a bookmark"
msgstr "Lösche ein Lesezeichen"
#: ../config.c:242
#: ../config.c:245
msgid "List all bookmarks"
msgstr "Liste all Lesezeichen auf"
#: ../config.c:243
#: ../config.c:246
msgid "Close current file"
msgstr "Schließe das aktuelle Dokument"
#: ../config.c:244
#: ../config.c:247
msgid "Show file information"
msgstr "Zeige Dokumentinformationen an"
#: ../config.c:245
#: ../config.c:248
msgid "Show help"
msgstr "Zeige Hilfe an"
#: ../config.c:246
#: ../config.c:249
msgid "Open document"
msgstr "Öffne Dokument"
#: ../config.c:247
#: ../config.c:250
msgid "Close zathura"
msgstr ""
#: ../config.c:251
msgid "Print document"
msgstr "Drucke Dokument"
#: ../config.c:248
#: ../config.c:252
msgid "Save document"
msgstr "Speichere Dokument"
#: ../config.c:249
#: ../config.c:253
msgid "Save document (and force overwriting)"
msgstr "Speichere Dokument (und überschreibe bestehende)"
#: ../config.c:250
#: ../config.c:254
msgid "Save attachments"
msgstr "Speichere Anhänge"
@ -231,12 +243,12 @@ msgstr "Speichere Anhänge"
msgid "%s not implemented"
msgstr "%s ist nicht implementiert."
#: ../page-widget.c:570
#: ../page-widget.c:571
#, c-format
msgid "Copied selected text to clipbard: %s"
msgstr "Der gewählte Text wurde in die Zwischenablage kopiert: %s"
#: ../page-widget.c:662
#: ../page-widget.c:663
msgid "Copy image"
msgstr "Bild kopieren"
@ -244,30 +256,30 @@ msgstr "Bild kopieren"
msgid "This document does not contain any index"
msgstr "Dieses Dokument beinhaltet kein Inhaltsverzeichnis."
#: ../zathura.c:55
#: ../zathura.c:57
msgid "Reparents to window specified by xid"
msgstr "Reparentiert zathura an das Fenster mit der xid"
#: ../zathura.c:56
#: ../zathura.c:58
msgid "Path to the config directory"
msgstr "Pfad zum Konfigurationsverzeichnis"
#: ../zathura.c:57
#: ../zathura.c:59
msgid "Path to the data directory"
msgstr "Pfad zum Datenverzeichnis"
#: ../zathura.c:58
#: ../zathura.c:60
msgid "Path to the directories containing plugins"
msgstr "Pfad zum Pluginverzeichnis"
#: ../zathura.c:59
#: ../zathura.c:61
msgid "Fork into the background"
msgstr "Forkt den Prozess in den Hintergrund"
#: ../zathura.c:60
#: ../zathura.c:62
msgid "Log level (debug, info, warning, error)"
msgstr ""
#: ../zathura.c:226 ../zathura.c:601
#: ../zathura.c:228 ../zathura.c:608
msgid "[No name]"
msgstr ""

View File

@ -27,6 +27,7 @@
#include "zathura.h"
#include "utils.h"
#include "render.h"
#include "page-widget.h"
typedef struct zathura_document_info_s
{
@ -36,6 +37,7 @@ typedef struct zathura_document_info_s
} zathura_document_info_t;
static gboolean document_info_open(gpointer data);
static gboolean purge_pages(gpointer data);
/* function implementation */
zathura_t*
@ -272,6 +274,11 @@ zathura_init(int argc, char* argv[])
gdk_threads_add_idle(document_info_open, document_info);
}
/* add even to purge old pages */
int interval = 30;
girara_setting_get(zathura->ui.session, "page-store-interval", &interval);
g_timeout_add_seconds(interval, purge_pages, zathura);
return zathura;
error_free:
@ -716,3 +723,24 @@ page_widget_set_mode(zathura_t* zathura, unsigned int pages_per_row)
gtk_widget_show_all(zathura->ui.page_widget);
}
static
gboolean purge_pages(gpointer data)
{
zathura_t* zathura = data;
if (zathura == NULL || zathura->document == NULL) {
return TRUE;
}
int threshold = 0;
girara_setting_get(zathura->ui.session, "page-store-threshold", &threshold);
if (threshold <= 0) {
return TRUE;
}
for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) {
zathura_page_t* page = zathura->document->pages[page_id];
zathura_page_widget_purge_unused(ZATHURA_PAGE(page->drawing_area), threshold);
}
return TRUE;
}