Commit 21a73f79 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Imported Upstream version 0.2.0

parent 6bc684ea
......@@ -8,6 +8,7 @@ Other contributors are (in alphabetical order):
Aepelzen <abietz@gmx.de>
Pavel Borzenkov <pavel.borzenkov@gmail.com>
Géraud Le Falher <daureg@gmail.com>
Glen Winters <lamouche@gmail.com>
Ivan Sichmann Freitas <ivansichfreitas@gmail.com>
Felix Herrmann <felix@herrmann-koenigsberg.de>
int3 <jezreel@gmail.com>
......
......@@ -6,7 +6,7 @@ include common.mk
PROJECT = zathura
OSOURCE = $(wildcard *.c)
HEADER = $(wildcard *.h)
HEADERINST = version.h zathura.h document.h macros.h
HEADERINST = version.h document.h macros.h page.h types.h plugin-api.h links.h
ifneq (${WITH_SQLITE},0)
INCS += $(SQLITE_INC)
......@@ -21,6 +21,16 @@ ifneq ($(wildcard ${VALGRIND_SUPPRESSION_FILE}),)
VALGRIND_ARGUMENTS += --suppressions=${VALGRIND_SUPPRESSION_FILE}
endif
ifeq (,$(findstring -DZATHURA_PLUGINDIR,${CPPFLAGS}))
CPPFLAGS += -DZATHURA_PLUGINDIR=\"${PLUGINDIR}\"
endif
ifeq (,$(findstring -DGETTEXT_PACKAGE,${CPPFLAGS}))
CPPFLAGS += -DGETTEXT_PACKAGE=\"${PROJECT}\"
endif
ifeq (,$(findstring -DLOCALEDIR,${CPPFLAGS}))
CPPFLAGS += -DLOCALEDIR=\"${LOCALEDIR}\"
endif
OBJECTS = $(patsubst %.c, %.o, $(SOURCE))
DOBJECTS = $(patsubst %.c, %.do, $(SOURCE))
......@@ -144,7 +154,7 @@ endif
install-manpages: build-manpages
$(ECHO) installing manual pages
$(QUIET)mkdir -p ${DESTDIR}${MANPREFIX}/man1 ${DESTDIR}${MANPREFIX}/man5
$(QUIET)mkdir -m 755 -p ${DESTDIR}${MANPREFIX}/man1 ${DESTDIR}${MANPREFIX}/man5
ifneq "$(wildcard ${PROJECT}.1)" ""
$(QUIET)install -m 644 ${PROJECT}.1 ${DESTDIR}${MANPREFIX}/man1
endif
......@@ -154,17 +164,17 @@ endif
install-headers: ${PROJECT}.pc
$(ECHO) installing header files
$(QUIET)mkdir -p ${DESTDIR}${INCLUDEDIR}/${PROJECT}
$(QUIET)mkdir -m 755 -p ${DESTDIR}${INCLUDEDIR}/${PROJECT}
$(QUIET)install -m 644 ${HEADERINST} ${DESTDIR}${INCLUDEDIR}/${PROJECT}
$(ECHO) installing pkgconfig file
$(QUIET)mkdir -p ${DESTDIR}${LIBDIR}/pkgconfig
$(QUIET)mkdir -m 755 -p ${DESTDIR}${LIBDIR}/pkgconfig
$(QUIET)install -m 644 ${PROJECT}.pc ${DESTDIR}${LIBDIR}/pkgconfig
install: all install-headers install-manpages
$(ECHO) installing executable file
$(QUIET)mkdir -p ${DESTDIR}${PREFIX}/bin
$(QUIET)mkdir -m 755 -p ${DESTDIR}${PREFIX}/bin
$(QUIET)install -m 755 ${PROJECT} ${DESTDIR}${PREFIX}/bin
$(QUIET)mkdir -p ${DESTDIR}${DESKTOPPREFIX}
$(QUIET)mkdir -m 755 -p ${DESTDIR}${DESKTOPPREFIX}
$(ECHO) installing desktop file
$(QUIET)install -m 644 ${PROJECT}.desktop ${DESTDIR}${DESKTOPPREFIX}
$(MAKE) -C po install
......@@ -175,7 +185,7 @@ uninstall-headers:
$(ECHO) removing pkgconfig file
$(QUIET)rm -f ${DESTDIR}${LIBDIR}/pkgconfig/${PROJECT}.pc
uninstall:
uninstall: uninstall-headers
$(ECHO) removing executable file
$(QUIET)rm -f ${DESTDIR}${PREFIX}/bin/${PROJECT}
$(ECHO) removing manual pages
......
......@@ -7,7 +7,7 @@ Requirements
------------
gtk2 (>= 2.18.6)
girara
sqlite3
sqlite3 (>= 3.5.9)
check (for tests)
intltool
......@@ -20,7 +20,9 @@ And also note that rst2man from python-docutils is needed to build the man pages
If it is not installed, the man pages won't be built.
If you don't want to build with support for sqlite databases, you can set
WITH_SQLITE=0 and sqlite support won't be available.
WITH_SQLITE=0 and sqlite support won't be available. Please note that sqlite3
with metadata support is required, i.e. sqlite3 has to be built with
SQLITE_ENABLE_COLUMN_METADATA defined.
Installation
------------
......
......@@ -34,7 +34,8 @@ zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page)
girara_list_append(zathura->bookmarks.bookmarks, bookmark);
if (zathura->database != NULL) {
if (zathura_db_add_bookmark(zathura->database, zathura->document->file_path, bookmark) == false) {
const char* path = zathura_document_get_path(zathura->document);
if (zathura_db_add_bookmark(zathura->database, path, bookmark) == false) {
girara_warning("Failed to add bookmark to database.");
}
}
......@@ -54,7 +55,8 @@ zathura_bookmark_remove(zathura_t* zathura, const gchar* id)
}
if (zathura->database != NULL) {
if (zathura_db_remove_bookmark(zathura->database, zathura->document->file_path, bookmark->id) == false) {
const char* path = zathura_document_get_path(zathura->document);
if (zathura_db_remove_bookmark(zathura->database, path, bookmark->id) == false) {
girara_warning("Failed to remove bookmark from database.");
}
}
......
......@@ -10,19 +10,20 @@
#include <glib/gi18n.h>
#include "callbacks.h"
#include "links.h"
#include "zathura.h"
#include "render.h"
#include "document.h"
#include "utils.h"
#include "shortcuts.h"
#include "page-widget.h"
#include "page.h"
gboolean
cb_destroy(GtkWidget* UNUSED(widget), zathura_t* zathura)
{
if (zathura != NULL && zathura->document != NULL) {
zathura_document_free(zathura->document);
zathura->document = NULL;
document_close(zathura, false);
}
gtk_main_quit();
......@@ -50,8 +51,7 @@ void
cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpointer data)
{
zathura_t* zathura = data;
if (zathura == NULL || zathura->document == NULL || zathura->document->pages == NULL
|| zathura->ui.page_widget == NULL) {
if (zathura == NULL || zathura->document == NULL || zathura->ui.page_widget == NULL) {
return;
}
......@@ -73,28 +73,32 @@ cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpoi
center.y = (view_rect.height + 1) / 2;
center.height = center.width = (2 * page_padding) + 1;
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
double scale = zathura_document_get_scale(zathura->document);
bool updated = false;
/* find page that fits */
for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) {
zathura_page_t* page = zathura->document->pages[page_id];
for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) {
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
GdkRectangle page_rect;
gtk_widget_translate_coordinates(page->drawing_area,
GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
gtk_widget_translate_coordinates(page_widget,
zathura->ui.session->gtk.view, 0, 0, &page_rect.x, &page_rect.y);
page_rect.width = page->width * zathura->document->scale;
page_rect.height = page->height * zathura->document->scale;
page_rect.width = zathura_page_get_width(page) * scale;
page_rect.height = zathura_page_get_height(page) * scale;
if (gdk_rectangle_intersect(&view_rect, &page_rect, NULL) == TRUE) {
page->visible = true;
zathura_page_set_visibility(page, true);
if (zathura->global.update_page_number == true && updated == false
&& gdk_rectangle_intersect(&center, &page_rect, NULL) == TRUE) {
zathura->document->current_page_number = page_id;
zathura_document_set_current_page_number(zathura->document, page_id);
updated = true;
}
} else {
page->visible = false;
zathura_page_set_visibility(page, false);
}
zathura_page_widget_update_view_time(ZATHURA_PAGE(page->drawing_area));
zathura_page_widget_update_view_time(ZATHURA_PAGE(page_widget));
}
statusbar_page_number_update(zathura);
......@@ -117,7 +121,7 @@ cb_pages_per_row_value_changed(girara_session_t* session, const char* UNUSED(nam
page_widget_set_mode(zathura, pages_per_row);
if (zathura->document != NULL) {
unsigned int current_page = zathura->document->current_page_number;
unsigned int current_page = zathura_document_get_current_page_number(zathura->document);
page_set_delayed(zathura, current_page);
}
}
......@@ -144,14 +148,8 @@ cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path,
return;
}
if (index_element->type == ZATHURA_LINK_TO_PAGE) {
sc_toggle_index(zathura->ui.session, NULL, NULL, 0);
page_set_delayed(zathura, index_element->target.page_number);
} else if (index_element->type == ZATHURA_LINK_EXTERNAL) {
if (girara_xdg_open(index_element->target.uri) == false) {
girara_notify(zathura->ui.session, GIRARA_ERROR, _("Failed to run xdg-open."));
}
}
sc_toggle_index(zathura->ui.session, NULL, NULL, 0);
zathura_link_evaluate(zathura, index_element->link);
}
g_object_unref(model);
......@@ -183,26 +181,20 @@ cb_sc_follow(GtkEntry* entry, girara_session_t* session)
/* set pages to draw links */
bool invalid_index = 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];
if (page == NULL || page->visible == false) {
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) {
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
if (page == NULL || zathura_page_get_visibility(page) == false) {
continue;
}
g_object_set(page->drawing_area, "draw-links", FALSE, NULL);
GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
g_object_set(page_widget, "draw-links", FALSE, NULL);
if (eval == true) {
zathura_link_t* link = zathura_page_widget_link_get(ZATHURA_PAGE(page->drawing_area), index);
zathura_link_t* link = zathura_page_widget_link_get(ZATHURA_PAGE(page_widget), index);
if (link != NULL) {
switch (link->type) {
case ZATHURA_LINK_TO_PAGE:
page_set_delayed(zathura, link->target.page_number);
break;
case ZATHURA_LINK_EXTERNAL:
girara_xdg_open(link->target.value);
break;
}
zathura_link_evaluate(zathura, link);
invalid_index = false;
}
}
......@@ -317,7 +309,7 @@ cb_view_resized(GtkWidget* UNUSED(widget), GtkAllocation* allocation, zathura_t*
/* adjust only if the allocation changed */
if (width != allocation->width || height != allocation->height) {
girara_argument_t argument = { zathura->document->adjust_mode, NULL };
girara_argument_t argument = { zathura_document_get_adjust_mode(zathura->document), NULL };
sc_adjust_window(zathura->ui.session, &argument, NULL, 0);
width = allocation->width;
......@@ -344,3 +336,28 @@ cb_setting_recolor_change(girara_session_t* session, const char* name,
render_all(zathura);
}
}
bool
cb_unknown_command(girara_session_t* session, const char* input)
{
g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false);
g_return_val_if_fail(input != NULL, false);
zathura_t* zathura = session->global.data;
if (zathura->document == NULL) {
return false;
}
/* check for number */
for (unsigned int i = 0; i < strlen(input); i++) {
if (g_ascii_isdigit(input[i]) == FALSE) {
return false;
}
}
page_set(zathura, atoi(input) - 1);
return true;
}
......@@ -7,6 +7,7 @@
#include <girara/types.h>
#include <girara/macros.h>
#include "internal.h"
#include "document.h"
#include "zathura.h"
......@@ -110,4 +111,14 @@ bool cb_view_resized(GtkWidget* widget, GtkAllocation* allocation, zathura_t* za
void cb_setting_recolor_change(girara_session_t* session, const char* name,
girara_setting_type_t type, void* value, void* data);
/**
* Unknown command handler which is used to handle the strict numeric goto
* command
*
* @param session The girara session
* @param input The command input
* @return true if the input has been handled
*/
bool cb_unknown_command(girara_session_t* session, const char* input);
#endif // CALLBACKS_H
This diff is collapsed.
......@@ -60,6 +60,15 @@ bool cmd_info(girara_session_t* session, girara_list_t* argument_list);
*/
bool cmd_help(girara_session_t* session, girara_list_t* argument_list);
/**
* Shows current search results
*
* @param session The used girara session
* @param argument_list List of passed arguments
* @return true if no error occured
*/
bool cmd_hlsearch(girara_session_t* session, girara_list_t* argument_list);
/**
* Opens a document file
*
......@@ -78,6 +87,15 @@ bool cmd_open(girara_session_t* session, girara_list_t* argument_list);
*/
bool cmd_print(girara_session_t* session, girara_list_t* argument_list);
/**
* Hides current search results
*
* @param session The used girara session
* @param argument_list List of passed arguments
* @return true if no error occured
*/
bool cmd_nohlsearch(girara_session_t* session, girara_list_t* argument_list);
/**
* Close zathura
*
......
......@@ -5,10 +5,13 @@
#include <stdlib.h>
#include <unistd.h>
#include <libgen.h>
#include <glib/gi18n.h>
#include "bookmarks.h"
#include "document.h"
#include "completion.h"
#include "utils.h"
#include "page.h"
#include <girara/session.h>
#include <girara/settings.h>
......@@ -244,7 +247,7 @@ cc_bookmarks(girara_session_t* session, const char* input)
const size_t input_length = strlen(input);
GIRARA_LIST_FOREACH(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark)
if (input_length <= strlen(bookmark->id) && !strncmp(input, bookmark->id, input_length)) {
gchar* paged = g_strdup_printf("Page %d", bookmark->page);
gchar* paged = g_strdup_printf(_("Page %d"), bookmark->page);
girara_completion_group_add_element(group, bookmark->id, paged);
g_free(paged);
}
......@@ -270,46 +273,107 @@ error_free:
girara_completion_t*
cc_export(girara_session_t* session, const char* input)
{
if (input == NULL) {
return NULL;
}
g_return_val_if_fail(session != NULL, NULL);
g_return_val_if_fail(session->global.data != NULL, NULL);
zathura_t* zathura = session->global.data;
girara_completion_t* completion = girara_completion_init();
girara_completion_group_t* group = girara_completion_group_create(session, NULL);
if (input == NULL || zathura->document == NULL) {
goto error_ret;
}
if (completion == NULL || group == NULL) {
girara_completion_t* completion = NULL;
girara_completion_group_t* attachment_group = NULL;
girara_completion_group_t* image_group = NULL;
completion = girara_completion_init();
if (completion == NULL) {
goto error_free;
}
attachment_group = girara_completion_group_create(session, _("Attachments"));
if (attachment_group == NULL) {
goto error_free;
}
/* add attachments */
const size_t input_length = strlen(input);
girara_list_t* attachments = zathura_document_attachments_get(zathura->document, NULL);
if (attachments == NULL) {
if (attachments != NULL) {
bool added = false;
GIRARA_LIST_FOREACH(attachments, const char*, iter, attachment)
if (input_length <= strlen(attachment) && !strncmp(input, attachment, input_length)) {
char* attachment_string = g_strdup_printf("attachment-%s", attachment);
girara_completion_group_add_element(attachment_group, attachment_string, NULL);
g_free(attachment_string);
added = true;
}
GIRARA_LIST_FOREACH_END(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark);
if (added == true) {
girara_completion_add_group(completion, attachment_group);
} else {
girara_completion_group_free(attachment_group);
attachment_group = NULL;
}
girara_list_free(attachments);
}
/* add images */
image_group = girara_completion_group_create(session, _("Images"));
if (image_group == NULL) {
goto error_free;
}
GIRARA_LIST_FOREACH(attachments, const char*, iter, attachment)
if (input_length <= strlen(attachment) && !strncmp(input, attachment, input_length)) {
girara_completion_group_add_element(group, attachment, NULL);
bool added = false;
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) {
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
if (page == NULL) {
continue;
}
GIRARA_LIST_FOREACH_END(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark);
girara_completion_add_group(completion, group);
girara_list_free(attachments);
girara_list_t* images = zathura_page_images_get(page, NULL);
if (images != NULL) {
unsigned int image_number = 1;
GIRARA_LIST_FOREACH(images, zathura_image_t*, iter, UNUSED(image))
char* image_string = g_strdup_printf("image-p%d-%d", page_id + 1, image_number);
girara_completion_group_add_element(image_group, image_string, NULL);
g_free(image_string);
added = true;
image_number++;
GIRARA_LIST_FOREACH_END(images, zathura_image_t*, iter, image);
girara_list_free(images);
}
}
if (added == true) {
girara_completion_add_group(completion, image_group);
} else {
girara_completion_group_free(image_group);
image_group = NULL;
}
return completion;
error_free:
if (completion) {
if (completion != NULL) {
girara_completion_free(completion);
}
if (group) {
girara_completion_group_free(group);
if (attachment_group != NULL) {
girara_completion_group_free(attachment_group);
}
if (image_group != NULL) {
girara_completion_group_free(image_group);
}
error_ret:
return NULL;
}
This diff is collapsed.
......@@ -2,12 +2,12 @@
# zathura make config
ZATHURA_VERSION_MAJOR = 0
ZATHURA_VERSION_MINOR = 1
ZATHURA_VERSION_REV = 2
ZATHURA_VERSION_MINOR = 2
ZATHURA_VERSION_REV = 0
# If the API changes, the API version and the ABI version have to be bumped.
ZATHURA_API_VERSION = 1
ZATHURA_API_VERSION = 2
# If the ABI breaks for any reason, this has to be bumped.
ZATHURA_ABI_VERSION = 1
ZATHURA_ABI_VERSION = 2
VERSION = ${ZATHURA_VERSION_MAJOR}.${ZATHURA_VERSION_MINOR}.${ZATHURA_VERSION_REV}
# the GTK+ version to use
......@@ -16,12 +16,12 @@ ZATHURA_GTK_VERSION ?= 2
# minimum required zathura version
# If you want to disable the check, set GIRARA_VERSION_CHECK to 0.
GIRARA_MIN_VERSION = 0.1.2
GIRARA_MIN_VERSION = 0.1.3
GIRARA_VERSION_CHECK ?= $(shell pkg-config --atleast-version=$(GIRARA_MIN_VERSION) girara-gtk${ZATHURA_GTK_VERSION}; echo $$?)
# database
# To disable support for the sqlite backend set WITH_SQLITE to 0.
WITH_SQLITE ?= $(shell (pkg-config --exists sqlite3 && echo 1) || echo 0)
WITH_SQLITE ?= $(shell (pkg-config --atleast-version=3.5.9 sqlite3 && echo 1) || echo 0)
# paths
PREFIX ?= /usr
......@@ -40,7 +40,13 @@ RSTTOMAN ?= /usr/bin/rst2man
# libs
GTK_INC ?= $(shell pkg-config --cflags gtk+-${ZATHURA_GTK_VERSION}.0)
GTK_LIB ?= $(shell pkg-config --libs gtk+-${ZATHURA_GTK_VERSION}.0 gthread-2.0)
GTK_LIB ?= $(shell pkg-config --libs gtk+-${ZATHURA_GTK_VERSION}.0)
GTHREAD_INC ?= $(shell pkg-config --cflags gthread-2.0)
GTHREAD_LIB ?= $(shell pkg-config --libs gthread-2.0)
GMODULE_INC ?= $(shell pkg-config --cflags gmodule-no-export-2.0)
GMODULE_LIB ?= $(shell pkg-config --libs gmodule-no-export-2.0)
GIRARA_INC ?= $(shell pkg-config --cflags girara-gtk${ZATHURA_GTK_VERSION})
GIRARA_LIB ?= $(shell pkg-config --libs girara-gtk${ZATHURA_GTK_VERSION})
......@@ -50,25 +56,12 @@ SQLITE_INC ?= $(shell pkg-config --cflags sqlite3)
SQLITE_LIB ?= $(shell pkg-config --libs sqlite3)
endif
#set it to an empty value if you don't need to link against ld for dlopen and friends
DL_LIB ?= -ldl
INCS = ${GIRARA_INC} ${GTK_INC}
LIBS = ${GIRARA_LIB} ${GTK_LIB} ${DL_LIB} -lpthread -lm
INCS = ${GIRARA_INC} ${GTK_INC} ${GTHREAD_INC} ${GMODULE_INC}
LIBS = ${GIRARA_LIB} ${GTK_LIB} ${GTHREAD_LIB} ${GMODULE_LIB} -lpthread -lm
# flags
CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length -Wextra $(INCS)
ifeq (,$(findstring -DZATHURA_PLUGINDIR,${CPPFLAGS}))
CPPFLAGS += -DZATHURA_PLUGINDIR=\"${PLUGINDIR}\"
endif
ifeq (,$(findstring -DGETTEXT_PACKAGE,${CPPFLAGS}))
CPPFLAGS += -DGETTEXT_PACKAGE=\"${PROJECT}\"
endif
ifeq (,$(findstring -DLOCALEDIR,${CPPFLAGS}))
CPPFLAGS += -DLOCALEDIR=\"${LOCALEDIR}\"
endif
# debug
DFLAGS ?= -g
......
......@@ -20,12 +20,20 @@
#define KEY_OFFSET "offset"
#define KEY_SCALE "scale"
#define KEY_ROTATE "rotate"
#define KEY_PAGES_PER_ROW "pages-per-row"
#define KEY_POSITION_X "position-x"
#define KEY_POSITION_Y "position-y"
#ifdef __GNU__
#include <sys/file.h>
#define file_lock_set(fd, cmd) flock(fd, cmd)
#else
#define file_lock_set(fd, cmd) \
{ \
struct flock lock = { .l_type = cmd, .l_start = 0, .l_whence = SEEK_SET, .l_len = 0}; \
fcntl(fd, F_SETLK, lock); \
}
#endif
static void zathura_database_interface_init(ZathuraDatabaseInterface* iface);
......@@ -40,9 +48,9 @@ static bool plain_remove_bookmark(zathura_database_t* db, const char* file,
static girara_list_t* plain_load_bookmarks(zathura_database_t* db,
const char* file);
static bool plain_set_fileinfo(zathura_database_t* db, const char* file,
unsigned int page, unsigned int offset, double scale, unsigned int rotation);
zathura_fileinfo_t* file_info);
static bool plain_get_fileinfo(zathura_database_t* db, const char* file,
unsigned int* page, unsigned int* offset, double* scale, unsigned int* rotation);
zathura_fileinfo_t* file_info);
static void plain_set_property(GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec);
......@@ -362,34 +370,49 @@ plain_load_bookmarks(zathura_database_t* db, const char* file)
}
static bool
plain_set_fileinfo(zathura_database_t* db, const char* file, unsigned int
page, unsigned int offset, double scale, unsigned int rotation)
plain_set_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
file_info)
{
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
if (priv->history == NULL) {
if (priv->history == NULL || file_info == NULL || file == NULL) {
return false;
}
char* tmp = g_strdup_printf("%f", scale);
char* name = prepare_filename(file);
g_key_file_set_integer(priv->history, name, KEY_PAGE, page);
g_key_file_set_integer(priv->history, name, KEY_OFFSET, offset);
g_key_file_set_string (priv->history, name, KEY_SCALE, tmp);
g_key_file_set_integer(priv->history, name, KEY_ROTATE, rotation);
g_key_file_set_integer(priv->history, name, KEY_PAGE, file_info->current_page);
g_key_file_set_integer(priv->history, name, KEY_OFFSET, file_info->page_offset);
g_free(name);
char* tmp = g_strdup_printf("%f", file_info->scale);
g_key_file_set_string (priv->history, name, KEY_SCALE, tmp);
g_free(tmp);
g_key_file_set_integer(priv->history, name, KEY_ROTATE, file_info->rotation);
g_key_file_set_integer(priv->history, name, KEY_PAGES_PER_ROW, file_info->pages_per_row);
tmp = g_strdup_printf("%f", file_info->position_x);
g_key_file_set_string(priv->history, name, KEY_POSITION_X, tmp);
g_free(tmp);
tmp = g_strdup_printf("%f", file_info->position_y);
g_key_file_set_string(priv->history, name, KEY_POSITION_Y, tmp);
g_free(tmp);
g_free(name);
zathura_db_write_key_file_to_file(priv->history_path, priv->history);
return true;
}
static bool
plain_get_fileinfo(zathura_database_t* db, const char* file, unsigned int*
page, unsigned int* offset, double* scale, unsigned int* rotation)
plain_get_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
file_info)
{
if (db == NULL || file == NULL || file_info == NULL) {
return false;
}
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
if (priv->history == NULL) {
return false;
......@@ -397,16 +420,33 @@ plain_get_fileinfo(zathura_database_t* db, const char* file, unsigned int*
char* name = prepare_filename(file);
if (g_key_file_has_group(priv->history, name) == FALSE) {
g_free(name);
return false;
}
*page = g_key_file_get_integer(priv->history, name, KEY_PAGE, NULL);
*offset = g_key_file_get_integer(priv->history, name, KEY_OFFSET, NULL);
*rotation = g_key_file_get_integer(priv->history, name, KEY_ROTATE, NULL);
file_info->current_page = g_key_file_get_integer(priv->history, name, KEY_PAGE, NULL);
file_info->page_offset = g_key_file_get_integer(priv->history, name, KEY_OFFSET, NULL);
file_info->rotation = g_key_file_get_integer(priv->history, name, KEY_ROTATE, NULL);
file_info->pages_per_row = g_key_file_get_integer(priv->history, name, KEY_PAGES_PER_ROW, NULL);
char* scale_string = g_key_file_get_string(priv->history, name, KEY_SCALE, NULL);
*scale = strtod(scale_string, NULL);
g_free(scale_string);
if (scale_string != NULL) {
file_info->scale = strtod(scale_string, NULL);
g_free(scale_string);
}
char* position_x_string = g_key_file_get_string(priv->history, name, KEY_POSITION_X, NULL);
if (position_x_string != NULL) {
file_info->position_x = strtod(position_x_string, NULL);
g_free(position_x_string);
}
char* position_y_string = g_key_file_get_string(priv->history, name, KEY_POSITION_Y, NULL);
if (position_y_string != NULL) {
file_info->position_y = strtod(position_y_string, NULL);
g_free(position_y_string);
}
g_free(name);
return true;
......@@ -441,7 +481,7 @@ zathura_db_read_key_file_from_file(const char* path)
}
/* open file */
FILE* file = fopen(path, "r");
FILE* file = fopen(path, "rw");
if (file == NULL) {
return NULL;
}
......@@ -550,4 +590,6 @@ cb_zathura_db_watch_file(GFileMonitor* UNUSED(monitor), GFile* file, GFile* UNUS
priv->history = zathura_db_read_key_file_from_file(priv->history_path);
}
g_free(path);
}
......@@ -20,9 +20,9 @@ static bool sqlite_remove_bookmark(zathura_database_t* db, const char* file,
static girara_list_t* sqlite_load_bookmarks(zathura_database_t* db,
const char* file);
static bool sqlite_set_fileinfo(zathura_database_t* db, const char* file,
unsigned int page, unsigned int offset, double scale, unsigned int rotation);
zathura_fileinfo_t* file_info);
static bool sqlite_get_fileinfo(zathura_database_t* db, const char* file,
unsigned int* page, unsigned int* offset, double* scale, unsigned int* rotation);
zathura_fileinfo_t* file_info);
static void sqlite_set_property(GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec);