Commit a7b3d73f authored by Moritz Lipp's avatar Moritz Lipp

Merge branch 'release/0.2.7'

parents 6d22f33f 0f005c0d
...@@ -18,3 +18,4 @@ doc/ ...@@ -18,3 +18,4 @@ doc/
zathura.1 zathura.1
zathurarc.5 zathurarc.5
.version-checks/ .version-checks/
dbus-interface-definitions.c
Copyright (c) 2009-2013 pwmt.org Copyright (c) 2009-2014 pwmt.org
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
......
...@@ -4,22 +4,22 @@ include config.mk ...@@ -4,22 +4,22 @@ include config.mk
include common.mk include common.mk
PROJECT = zathura PROJECT = zathura
OSOURCE = $(wildcard *.c) OSOURCE = $(filter-out dbus-interface-definitions.c, $(wildcard *.c))
HEADER = $(wildcard *.h) HEADER = $(wildcard *.h)
HEADERINST = version.h document.h macros.h page.h types.h plugin-api.h links.h HEADERINST = version.h document.h macros.h page.h types.h plugin-api.h links.h
ifneq (${WITH_SQLITE},0) ifneq (${WITH_SQLITE},0)
INCS += $(SQLITE_INC) INCS += $(SQLITE_INC)
LIBS += $(SQLITE_LIB) LIBS += $(SQLITE_LIB)
SOURCE = $(OSOURCE) SOURCE = $(OSOURCE)
CPPFLAGS += -DWITH_SQLITE CPPFLAGS += -DWITH_SQLITE
else else
SOURCE = $(filter-out database-sqlite.c,$(OSOURCE)) SOURCE = $(filter-out database-sqlite.c,$(OSOURCE))
endif endif
ifneq ($(WITH_MAGIC),0) ifneq ($(WITH_MAGIC),0)
INCS += $(MAGIC_INC) INCS += $(MAGIC_INC)
LIBS += $(MAGIC_LIB) LIBS += $(MAGIC_LIB)
CPPFLAGS += -DWITH_MAGIC CPPFLAGS += -DWITH_MAGIC
endif endif
...@@ -37,13 +37,13 @@ ifeq (,$(findstring -DLOCALEDIR,${CPPFLAGS})) ...@@ -37,13 +37,13 @@ ifeq (,$(findstring -DLOCALEDIR,${CPPFLAGS}))
CPPFLAGS += -DLOCALEDIR=\"${LOCALEDIR}\" CPPFLAGS += -DLOCALEDIR=\"${LOCALEDIR}\"
endif endif
OBJECTS = $(patsubst %.c, %.o, $(SOURCE)) OBJECTS = $(patsubst %.c, %.o, $(SOURCE)) dbus-interface-definitions.o
DOBJECTS = $(patsubst %.c, %.do, $(SOURCE)) DOBJECTS = $(patsubst %.o, %.do, $(OBJECTS))
all: options ${PROJECT} po build-manpages all: options ${PROJECT} po build-manpages
# pkg-config based version checks # pkg-config based version checks
.version-checks/%: .version-checks/%: config.mk
$(QUIET)test $($(*)_VERSION_CHECK) -eq 0 || \ $(QUIET)test $($(*)_VERSION_CHECK) -eq 0 || \
pkg-config --atleast-version $($(*)_MIN_VERSION) $($(*)_PKG_CONFIG_NAME) || ( \ pkg-config --atleast-version $($(*)_MIN_VERSION) $($(*)_PKG_CONFIG_NAME) || ( \
echo "The minium required version of $(*) is $($(*)_MIN_VERSION)" && \ echo "The minium required version of $(*) is $($(*)_MIN_VERSION)" && \
...@@ -64,7 +64,15 @@ version.h: version.h.in config.mk ...@@ -64,7 +64,15 @@ version.h: version.h.in config.mk
-e 's/ZVMINOR/${ZATHURA_VERSION_MINOR}/' \ -e 's/ZVMINOR/${ZATHURA_VERSION_MINOR}/' \
-e 's/ZVREV/${ZATHURA_VERSION_REV}/' \ -e 's/ZVREV/${ZATHURA_VERSION_REV}/' \
-e 's/ZVAPI/${ZATHURA_API_VERSION}/' \ -e 's/ZVAPI/${ZATHURA_API_VERSION}/' \
-e 's/ZVABI/${ZATHURA_ABI_VERSION}/' version.h.in > version.h -e 's/ZVABI/${ZATHURA_ABI_VERSION}/' version.h.in > version.h.tmp
$(QUIET)mv version.h.tmp version.h
dbus-interface-definitions.c: data/org.pwmt.zathura.xml
$(QUIET)echo '#include "dbus-interface-definitions.h"' > dbus-interface-definitions.c.tmp
$(QUIET)echo 'const char* DBUS_INTERFACE_XML =' >> dbus-interface-definitions.c.tmp
$(QUIET)sed 's/^\(.*\)$$/"\1\\n"/' data/org.pwmt.zathura.xml >> dbus-interface-definitions.c.tmp
$(QUIET)echo ';' >> dbus-interface-definitions.c.tmp
$(QUIET)mv dbus-interface-definitions.c.tmp dbus-interface-definitions.c
%.o: %.c %.o: %.c
$(ECHO) CC $< $(ECHO) CC $<
...@@ -84,8 +92,18 @@ ${PROJECT}: ${OBJECTS} ...@@ -84,8 +92,18 @@ ${PROJECT}: ${OBJECTS}
$(QUIET)${CC} ${SFLAGS} ${LDFLAGS} -o $@ ${OBJECTS} ${LIBS} $(QUIET)${CC} ${SFLAGS} ${LDFLAGS} -o $@ ${OBJECTS} ${LIBS}
clean: clean:
$(QUIET)rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \ $(QUIET)rm -rf ${PROJECT} \
${DOBJECTS} ${PROJECT}-debug .depend ${PROJECT}.pc doc version.h \ ${OBJECTS} \
${PROJECT}-${VERSION}.tar.gz \
${DOBJECTS} \
${PROJECT}-debug \
.depend \
${PROJECT}.pc \
doc \
version.h \
version.h.tmp \
dbus-interface-definitions.c \
dbus-interface-definitions.c.tmp \
*gcda *gcno $(PROJECT).info gcov *.tmp \ *gcda *gcno $(PROJECT).info gcov *.tmp \
.version-checks .version-checks
ifneq "$(wildcard ${RSTTOMAN})" "" ifneq "$(wildcard ${RSTTOMAN})" ""
...@@ -107,7 +125,7 @@ ${PROJECT}.pc: ${PROJECT}.pc.in config.mk ...@@ -107,7 +125,7 @@ ${PROJECT}.pc: ${PROJECT}.pc.in config.mk
$(QUIET)echo abiversion=${ZATHURA_ABI_VERSION} >> ${PROJECT}.pc $(QUIET)echo abiversion=${ZATHURA_ABI_VERSION} >> ${PROJECT}.pc
$(QUIET)echo includedir=${INCLUDEDIR} >> ${PROJECT}.pc $(QUIET)echo includedir=${INCLUDEDIR} >> ${PROJECT}.pc
$(QUIET)echo plugindir=${PLUGINDIR} >> ${PROJECT}.pc $(QUIET)echo plugindir=${PLUGINDIR} >> ${PROJECT}.pc
$(QUIET)echo GTK_VERSION=${ZATHURA_GTK_VERSION} >> ${PROJECT}.pc $(QUIET)echo GTK_VERSION=3 >> ${PROJECT}.pc
$(QUIET)cat ${PROJECT}.pc.in >> ${PROJECT}.pc $(QUIET)cat ${PROJECT}.pc.in >> ${PROJECT}.pc
valgrind: debug valgrind: debug
...@@ -129,6 +147,7 @@ dist: clean build-manpages ...@@ -129,6 +147,7 @@ dist: clean build-manpages
${PROJECT}.desktop version.h.in \ ${PROJECT}.desktop version.h.in \
${PROJECT}.1 ${PROJECT}rc.5 \ ${PROJECT}.1 ${PROJECT}rc.5 \
${PROJECT}-${VERSION} ${PROJECT}-${VERSION}
$(QUIET)cp -r data ${PROJECT}-${VERSION}
$(QUIET)cp tests/Makefile tests/config.mk tests/*.c \ $(QUIET)cp tests/Makefile tests/config.mk tests/*.c \
${PROJECT}-${VERSION}/tests ${PROJECT}-${VERSION}/tests
$(QUIET)cp po/Makefile po/*.po ${PROJECT}-${VERSION}/po $(QUIET)cp po/Makefile po/*.po ${PROJECT}-${VERSION}/po
...@@ -184,7 +203,12 @@ install-headers: ${PROJECT}.pc ...@@ -184,7 +203,12 @@ install-headers: ${PROJECT}.pc
$(QUIET)mkdir -m 755 -p ${DESTDIR}${LIBDIR}/pkgconfig $(QUIET)mkdir -m 755 -p ${DESTDIR}${LIBDIR}/pkgconfig
$(QUIET)install -m 644 ${PROJECT}.pc ${DESTDIR}${LIBDIR}/pkgconfig $(QUIET)install -m 644 ${PROJECT}.pc ${DESTDIR}${LIBDIR}/pkgconfig
install: all install-headers install-manpages install-dbus:
$(ECHO) installing D-Bus interface definitions
$(QUIET)mkdir -m 755 -p $(DESTDIR)$(DBUSINTERFACEDIR)
$(QUIET)install -m 644 data/org.pwmt.zathura.xml $(DESTDIR)$(DBUSINTERFACEDIR)
install: all install-headers install-manpages install-dbus
$(ECHO) installing executable file $(ECHO) installing executable file
$(QUIET)mkdir -m 755 -p ${DESTDIR}${PREFIX}/bin $(QUIET)mkdir -m 755 -p ${DESTDIR}${PREFIX}/bin
$(QUIET)install -m 755 ${PROJECT} ${DESTDIR}${PREFIX}/bin $(QUIET)install -m 755 ${PROJECT} ${DESTDIR}${PREFIX}/bin
...@@ -207,9 +231,12 @@ uninstall: uninstall-headers ...@@ -207,9 +231,12 @@ uninstall: uninstall-headers
$(QUIET)rm -f ${DESTDIR}${MANPREFIX}/man5/${PROJECT}rc.5 $(QUIET)rm -f ${DESTDIR}${MANPREFIX}/man5/${PROJECT}rc.5
$(ECHO) removing desktop file $(ECHO) removing desktop file
$(QUIET)rm -f ${DESTDIR}${DESKTOPPREFIX}/${PROJECT}.desktop $(QUIET)rm -f ${DESTDIR}${DESKTOPPREFIX}/${PROJECT}.desktop
$(ECHO) removing D-Bus interface definitions
$(QUIET)rm -f $(DESTDIR)$(DBUSINTERFACEDIR)/org.pwmt.zathura.xml
$(MAKE) -C po uninstall $(MAKE) -C po uninstall
-include $(wildcard .depend/*.dep) -include $(wildcard .depend/*.dep)
.PHONY: all options clean doc debug valgrind gdb dist doc install uninstall test \ .PHONY: all options clean doc debug valgrind gdb dist doc install uninstall \
po install-headers uninstall-headers update-po install-manpages build-manpages test po install-headers uninstall-headers update-po install-manpages \
build-manpages install-dbus
...@@ -5,9 +5,9 @@ girara user interface library and several document libraries. ...@@ -5,9 +5,9 @@ girara user interface library and several document libraries.
Requirements Requirements
------------ ------------
gtk2 (>= 2.18) or gtk3 gtk3
glib (>= 2.28) glib (>= 2.28)
girara girara (>= 0.1.8)
sqlite3 (optional, >= 3.5.9) sqlite3 (optional, >= 3.5.9)
check (for tests) check (for tests)
intltool intltool
......
...@@ -146,20 +146,6 @@ page_is_visible(zathura_document_t *document, unsigned int page_number) ...@@ -146,20 +146,6 @@ page_is_visible(zathura_document_t *document, unsigned int page_number)
fabs(pos_y - page_y) < 0.5 * (double)(view_height + cell_height) / (double)doc_height); fabs(pos_y - page_y) < 0.5 * (double)(view_height + cell_height) / (double)doc_height);
} }
GtkAdjustment*
zathura_adjustment_clone(GtkAdjustment* adjustment)
{
gdouble value = gtk_adjustment_get_value(adjustment);
gdouble lower = gtk_adjustment_get_lower(adjustment);
gdouble upper = gtk_adjustment_get_upper(adjustment);
gdouble step_increment = gtk_adjustment_get_step_increment(adjustment);
gdouble page_increment = gtk_adjustment_get_page_increment(adjustment);
gdouble page_size = gtk_adjustment_get_page_size(adjustment);
return GTK_ADJUSTMENT(gtk_adjustment_new(value, lower, upper, step_increment,
page_increment, page_size));
}
void void
zathura_adjustment_set_value(GtkAdjustment* adjustment, gdouble value) zathura_adjustment_set_value(GtkAdjustment* adjustment, gdouble value)
{ {
......
...@@ -69,17 +69,6 @@ void page_number_to_position(zathura_document_t* document, unsigned int page_num ...@@ -69,17 +69,6 @@ void page_number_to_position(zathura_document_t* document, unsigned int page_num
*/ */
bool page_is_visible(zathura_document_t *document, unsigned int page_number); bool page_is_visible(zathura_document_t *document, unsigned int page_number);
/**
* Clone a GtkAdjustment
*
* Creates a new adjustment with the same value, lower and upper bounds, step
* and page increments and page_size as the original adjustment.
*
* @param adjustment Adjustment instance to be cloned
* @return Pointer to the new adjustment
*/
GtkAdjustment* zathura_adjustment_clone(GtkAdjustment* adjustment);
/** /**
* Set the adjustment value while enforcing its limits * Set the adjustment value while enforcing its limits
* *
......
...@@ -48,7 +48,10 @@ zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page) ...@@ -48,7 +48,10 @@ zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page)
return old; return old;
} }
zathura_bookmark_t* bookmark = g_malloc0(sizeof(zathura_bookmark_t)); zathura_bookmark_t* bookmark = g_try_malloc0(sizeof(zathura_bookmark_t));
if (bookmark == NULL) {
return NULL;
}
bookmark->id = g_strdup(id); bookmark->id = g_strdup(id);
bookmark->page = page; bookmark->page = page;
......
...@@ -50,7 +50,8 @@ cb_buffer_changed(girara_session_t* session) ...@@ -50,7 +50,8 @@ cb_buffer_changed(girara_session_t* session)
} }
static void static void
update_visible_pages(zathura_t* zathura) { update_visible_pages(zathura_t* zathura)
{
const unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document); const 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++) { for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) {
...@@ -539,6 +540,11 @@ cb_page_widget_text_selected(ZathuraPage* page, const char* text, void* data) ...@@ -539,6 +540,11 @@ cb_page_widget_text_selected(ZathuraPage* page, const char* text, void* data)
g_return_if_fail(data != NULL); g_return_if_fail(data != NULL);
zathura_t* zathura = data; zathura_t* zathura = data;
girara_mode_t mode = girara_mode_get(zathura->ui.session);
if (mode != zathura->modes.normal && mode != zathura->modes.fullscreen) {
return;
}
GdkAtom* selection = get_selection(zathura); GdkAtom* selection = get_selection(zathura);
/* copy to clipboard */ /* copy to clipboard */
......
...@@ -239,7 +239,7 @@ cmd_open(girara_session_t* session, girara_list_t* argument_list) ...@@ -239,7 +239,7 @@ cmd_open(girara_session_t* session, girara_list_t* argument_list)
} }
document_open(zathura, girara_list_nth(argument_list, 0), document_open(zathura, girara_list_nth(argument_list, 0),
(argc == 2) ? girara_list_nth(argument_list, 1) : NULL, (argc == 2) ? girara_list_nth(argument_list, 1) : NULL,
ZATHURA_PAGE_NUMBER_UNSPECIFIED); ZATHURA_PAGE_NUMBER_UNSPECIFIED);
} else { } else {
girara_notify(session, GIRARA_ERROR, _("No arguments given.")); girara_notify(session, GIRARA_ERROR, _("No arguments given."));
...@@ -400,7 +400,10 @@ cmd_search(girara_session_t* session, const char* input, girara_argument_t* argu ...@@ -400,7 +400,10 @@ cmd_search(girara_session_t* session, const char* input, girara_argument_t* argu
} }
} }
girara_argument_t* arg = g_malloc0(sizeof(girara_argument_t)); girara_argument_t* arg = g_try_malloc0(sizeof(girara_argument_t));
if (arg == NULL) {
return false;
}
arg->n = FORWARD; arg->n = FORWARD;
sc_search(session, arg, NULL, 0); sc_search(session, arg, NULL, 0);
......
This diff is collapsed.
...@@ -3,9 +3,6 @@ ...@@ -3,9 +3,6 @@
#ifndef CONFIG_H #ifndef CONFIG_H
#define CONFIG_H #define CONFIG_H
#define GLOBAL_RC "/etc/zathurarc"
#define ZATHURA_RC "zathurarc"
#include "zathura.h" #include "zathura.h"
/** /**
...@@ -21,6 +18,6 @@ void config_load_default(zathura_t* zathura); ...@@ -21,6 +18,6 @@ void config_load_default(zathura_t* zathura);
* @param zathura The zathura session * @param zathura The zathura session
* @param path Path to the configuration file * @param path Path to the configuration file
*/ */
void config_load_file(zathura_t* zathura, char* path); void config_load_files(zathura_t* zathura);
#endif // CONFIG_H #endif // CONFIG_H
...@@ -3,31 +3,28 @@ ...@@ -3,31 +3,28 @@
ZATHURA_VERSION_MAJOR = 0 ZATHURA_VERSION_MAJOR = 0
ZATHURA_VERSION_MINOR = 2 ZATHURA_VERSION_MINOR = 2
ZATHURA_VERSION_REV = 6 ZATHURA_VERSION_REV = 7
# If the API changes, the API version and the ABI version have to be bumped. # If the API changes, the API version and the ABI version have to be bumped.
ZATHURA_API_VERSION = 2 ZATHURA_API_VERSION = 2
# If the ABI breaks for any reason, this has to be bumped. # If the ABI breaks for any reason, this has to be bumped.
ZATHURA_ABI_VERSION = 2 ZATHURA_ABI_VERSION = 2
VERSION = ${ZATHURA_VERSION_MAJOR}.${ZATHURA_VERSION_MINOR}.${ZATHURA_VERSION_REV} VERSION = ${ZATHURA_VERSION_MAJOR}.${ZATHURA_VERSION_MINOR}.${ZATHURA_VERSION_REV}
# the GTK+ version to use
ZATHURA_GTK_VERSION ?= 3
# version checks # version checks
# If you want to disable any of the checks, set *_VERSION_CHECK to 0. # If you want to disable any of the checks, set *_VERSION_CHECK to 0.
# girara # girara
GIRARA_VERSION_CHECK ?= 1 GIRARA_VERSION_CHECK ?= 1
GIRARA_MIN_VERSION = 0.1.8 GIRARA_MIN_VERSION = 0.1.8
GIRARA_PKG_CONFIG_NAME = girara-gtk$(ZATHURA_GTK_VERSION) GIRARA_PKG_CONFIG_NAME = girara-gtk3
# glib # glib
GLIB_VERSION_CHECK ?= 1 GLIB_VERSION_CHECK ?= 1
GLIB_MIN_VERSION = 2.28 GLIB_MIN_VERSION = 2.28
GLIB_PKG_CONFIG_NAME = glib-2.0 GLIB_PKG_CONFIG_NAME = glib-2.0
# GTK # GTK
GTK_VERSION_CHECK ?= 1 GTK_VERSION_CHECK ?= 1
GTK_MIN_VERSION = 2.18 GTK_MIN_VERSION = 3.0
GTK_PKG_CONFIG_NAME = gtk+-$(ZATHURA_GTK_VERSION).0 GTK_PKG_CONFIG_NAME = gtk+-3.0
# database # database
# To disable support for the sqlite backend set WITH_SQLITE to 0. # To disable support for the sqlite backend set WITH_SQLITE to 0.
...@@ -43,6 +40,8 @@ MANPREFIX ?= ${PREFIX}/share/man ...@@ -43,6 +40,8 @@ MANPREFIX ?= ${PREFIX}/share/man
DESKTOPPREFIX ?= ${PREFIX}/share/applications DESKTOPPREFIX ?= ${PREFIX}/share/applications
LIBDIR ?= ${PREFIX}/lib LIBDIR ?= ${PREFIX}/lib
INCLUDEDIR ?= ${PREFIX}/include INCLUDEDIR ?= ${PREFIX}/include
DBUSINTERFACEDIR ?= ${PREFIX}/share/dbus-1/interfaces
VIMFTPLUGINDIR ?= ${PREFIX}/share/vim/addons/ftplugin
# plugin directory # plugin directory
PLUGINDIR ?= ${LIBDIR}/zathura PLUGINDIR ?= ${LIBDIR}/zathura
...@@ -53,8 +52,8 @@ LOCALEDIR ?= ${PREFIX}/share/locale ...@@ -53,8 +52,8 @@ LOCALEDIR ?= ${PREFIX}/share/locale
RSTTOMAN ?= /usr/bin/rst2man RSTTOMAN ?= /usr/bin/rst2man
# libs # libs
GTK_INC ?= $(shell pkg-config --cflags gtk+-${ZATHURA_GTK_VERSION}.0) GTK_INC ?= $(shell pkg-config --cflags gtk+-3.0)
GTK_LIB ?= $(shell pkg-config --libs gtk+-${ZATHURA_GTK_VERSION}.0) GTK_LIB ?= $(shell pkg-config --libs gtk+-3.0)
GTHREAD_INC ?= $(shell pkg-config --cflags gthread-2.0) GTHREAD_INC ?= $(shell pkg-config --cflags gthread-2.0)
GTHREAD_LIB ?= $(shell pkg-config --libs gthread-2.0) GTHREAD_LIB ?= $(shell pkg-config --libs gthread-2.0)
...@@ -65,8 +64,8 @@ GMODULE_LIB ?= $(shell pkg-config --libs gmodule-no-export-2.0) ...@@ -65,8 +64,8 @@ GMODULE_LIB ?= $(shell pkg-config --libs gmodule-no-export-2.0)
GLIB_INC ?= $(shell pkg-config --cflags glib-2.0) GLIB_INC ?= $(shell pkg-config --cflags glib-2.0)
GLIB_LIB ?= $(shell pkg-config --libs glib-2.0) GLIB_LIB ?= $(shell pkg-config --libs glib-2.0)
GIRARA_INC ?= $(shell pkg-config --cflags girara-gtk${ZATHURA_GTK_VERSION}) GIRARA_INC ?= $(shell pkg-config --cflags girara-gtk3)
GIRARA_LIB ?= $(shell pkg-config --libs girara-gtk${ZATHURA_GTK_VERSION}) GIRARA_LIB ?= $(shell pkg-config --libs girara-gtk3)
ifneq (${WITH_SQLITE},0) ifneq (${WITH_SQLITE},0)
SQLITE_INC ?= $(shell pkg-config --cflags sqlite3) SQLITE_INC ?= $(shell pkg-config --cflags sqlite3)
......
/* See LICENSE file for license and copyright information */
#define _BSD_SOURCE
#define _XOPEN_SOURCE 700
#include "content-type.h"
#include "macros.h"
#include <girara/utils.h>
#ifdef WITH_MAGIC
#include <magic.h>
#else
#include <sys/types.h>
#include <sys/wait.h>
#endif
#include <stdio.h>
#include <glib.h>
#include <gio/gio.h>
/** Read a most GT_MAX_READ bytes before falling back to file. */
static const size_t GT_MAX_READ = 1 << 16;
#ifdef WITH_MAGIC
static const char*
guess_type_magic(const char* path) {
const char* mime_type = NULL;
/* creat magic cookie */
const int flags =
MAGIC_MIME_TYPE |
MAGIC_SYMLINK |
MAGIC_NO_CHECK_APPTYPE |
MAGIC_NO_CHECK_CDF |
MAGIC_NO_CHECK_ELF |
MAGIC_NO_CHECK_ENCODING;
magic_t magic = magic_open(flags);
if (magic == NULL) {
girara_debug("failed creating the magic cookie");
goto cleanup;
}
/* ... and load mime database */
if (magic_load(magic, NULL) < 0) {
girara_debug("failed loading the magic database: %s", magic_error(magic));
goto cleanup;
}
/* get the mime type */
mime_type = magic_file(magic, path);
if (mime_type == NULL) {
girara_debug("failed guessing filetype: %s", magic_error(magic));
goto cleanup;
}
/* dup so we own the memory */
mime_type = g_strdup(mime_type);
girara_debug("magic detected filetype: %s", mime_type);
cleanup:
if (magic != NULL) {
magic_close(magic);
}
return mime_type;
}
static const char*
guess_type_file(const char* UNUSED(path))
{
return NULL;
}
#else
static const char*
guess_type_magic(const char* UNUSED(path)) {
return NULL;
}
static const char*
guess_type_file(const char* path)
{
GString* command = g_string_new("file -b --mime-type ");
char* tmp = g_shell_quote(path);
g_string_append(command, tmp);
g_free(tmp);
GError* error = NULL;
char* out = NULL;
int ret = 0;
g_spawn_command_line_sync(command->str, &out, NULL, &ret, &error);
g_string_free(command, TRUE);
if (error != NULL) {
girara_warning("failed to execute command: %s", error->message);
g_error_free(error);
g_free(out);
return NULL;
}
if (WEXITSTATUS(ret) != 0) {
girara_warning("file failed with error code: %d", WEXITSTATUS(ret));
g_free(out);
return NULL;
}
g_strdelimit(out, "\n\r", '\0');
return out;
}
#endif
static const char*
guess_type_glib(const char* path)
{
gboolean uncertain = FALSE;
const char* content_type = g_content_type_guess(path, NULL, 0, &uncertain);
if (content_type == NULL) {
girara_debug("g_content_type failed\n");
} else {
if (uncertain == FALSE) {
girara_debug("g_content_type detected filetype: %s", content_type);
return content_type;
}
girara_debug("g_content_type is uncertain, guess: %s", content_type);
}
FILE* f = fopen(path, "rb");
if (f == NULL) {
return NULL;
}
const int fd = fileno(f);
guchar* content = NULL;
size_t length = 0u;
ssize_t bytes_read = -1;
while (uncertain == TRUE && length < GT_MAX_READ && bytes_read != 0) {
g_free((void*)content_type);
content_type = NULL;
guchar* temp_content = g_try_realloc(content, length + BUFSIZ);
if (temp_content == NULL) {
break;
}
content = temp_content;
bytes_read = read(fd, content + length, BUFSIZ);
if (bytes_read == -1) {
break;
}
length += bytes_read;
content_type = g_content_type_guess(NULL, content, length, &uncertain);
girara_debug("new guess: %s uncertain: %d, read: %zu", content_type, uncertain, length);
}
fclose(f);
g_free(content);
if (uncertain == FALSE) {
return content_type;
}
g_free((void*)content_type);
return NULL;
}
const char*
guess_content_type(const char* path)
{
/* try libmagic first */
const char* content_type = guess_type_magic(path);
if (content_type != NULL) {
return content_type;
}
/* else fallback to g_content_type_guess method */
content_type = guess_type_glib(path);
if (content_type != NULL) {
return content_type;
}
/* and if libmagic is not available, try file as last resort */
return guess_type_file(path);
}
/* See LICENSE file for license and copyright information */
#ifndef ZATHURA_CONTENT_TYPE_H
#define ZATHURA_CONTENT_TYPE_H
const char* guess_content_type(const char* path);
#endif
<!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN'
'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>
<node>
<interface name='org.pwmt.zathura'>
<!-- Open a document in a running zathura instance. -->
<method name='OpenDocument'>
<arg type='s' name='path' direction='in' />
<arg type='s' name='password' direction='in' />
<arg type='i' name='page' direction='in' />
<arg type='b' name='return' direction='out' />
</method>
<!-- Close open document. -->
<method name='CloseDocument'>
<arg type='b' name='return' direction='out' />
</method>
<!-- Go to a specific page . -->
<method name='GotoPage'>
<arg type='u' name='page' direction='in' />
<arg type='b' name='return' direction='out' />
</method>
<!-- Go to a page and highlight rectangles there. -->
<method name='HighlightRects'>
<arg type='u' name='page' direction='in' />
<arg type='a(dddd)' name='rectangles' direction='in' />
<arg type='a(udddd)' name='secondary_rectangles' direction='in' />
<arg type='b' name='return' direction='out' />
</method>
<property type='s' name='filename' access='read' />
<property type='u' name='pagenumber' access='read' />
<property type='u' name='numberofpages' access='read' />
</interface>
</node>
" See LICENSE file for license and copyright information
" This is a sample plugin that can be used for synctex forward synchronization.
" It currently uses latexsuite to obtain the file name of the document. If you
" are not using latexsuite, it should be enough to adopt the calculation of
" 'output' accordingly.
" avoid re-execution
if exists("b:did_zathura_synctex_plugin") || !exists("*Tex_GetMainFileName")
finish
endif
let b:did_zathura_synctex_plugin = 1
function! Zathura_SyncTexForward()
let source = expand("%:p")
let input = shellescape(line(".").":".col(".").":".source)
let output = Tex_GetMainFileName(":p:r").".pdf"
let execstr = "zathura --synctex-forward=".input." ".shellescape(output)
silent call system(execstr)
endfunction
nmap <buffer> <Leader>f :call Zathura_SyncTexForward()<Enter>
This diff is collapsed.
...@@ -388,14 +388,21 @@ sqlite_load_bookmarks(zathura_database_t* db, const char* file) ...@@ -388,14 +388,21 @@ sqlite_load_bookmarks(zathura_database_t* db, const char* file)
girara_list_t* result = girara_sorted_list_new2((girara_compare_function_t) zathura_bookmarks_compare, girara_list_t* result = girara_sorted_list_new2((girara_compare_function_t) zathura_bookmarks_compare,
(girara_free_function_t) zathura_bookmark_free); (girara_free_function_t) zathura_bookmark_free);
if (result != NULL) {
sqlite3_finalize(stmt);
return NULL;
}
while (sqlite3_step(stmt) == SQLITE_ROW) { while (sqlite3_step(stmt) == SQLITE_ROW) {
zathura_bookmark_t* bookmark = g_malloc0(sizeof(zathura_bookmark_t)); zathura_bookmark_t* bookmark = g_try_malloc0(sizeof(zathura_bookmark_t));
if (bookmark == NULL) {
continue;
}
bookmark->id = g_strdup((const char*) sqlite3_column_text(stmt, 0)); bookmark->id = g_strdup((const char*) sqlite3_column_text(stmt, 0));
bookmark->page = sqlite3_column_int(stmt, 1); bookmark->page = sqlite3_column_int(stmt, 1);
bookmark->x = sqlite3_column_double(stmt, 2); bookmark->x