Commit 4b559e58 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Implement support to use both database backends.

parent 925c9973
......@@ -4,17 +4,14 @@ include config.mk
include common.mk
PROJECT = zathura
OSOURCE = $(shell find . -maxdepth 1 -iname "*.c" -a ! -iname "database-*")
OSOURCE = $(shell find . -maxdepth 1 -iname "*.c" -a ! -iname "database-sqlite.c")
HEADER = $(shell find . -maxdepth 1 -iname "*.h")
ifeq (${DATABASE}, sqlite)
ifneq (${WITH_SQLITE},0)
INCS += $(SQLITE_INC)
LIBS += $(SQLITE_LIB)
SOURCE = $(OSOURCE) database-sqlite.c
else
ifeq (${DATABASE}, plain)
SOURCE = $(OSOURCE) database-plain.c
endif
CPPFLAGS += -DWITH_SQLITE
endif
OBJECTS = $(patsubst %.c, %.o, $(SOURCE))
......@@ -45,9 +42,6 @@ version.h: version.h.in config.mk
@mkdir -p .depend
$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep
# force recompilation of database.o if DATABASE has changed
database.o: database-${DATABASE}.o
${OBJECTS}: config.mk version.h
${DOBJECTS}: config.mk version.h
......@@ -91,7 +85,7 @@ dist: clean
$(QUIET)mkdir -p ${PROJECT}-${VERSION}/tests
$(QUIET)cp LICENSE Makefile config.mk common.mk README AUTHORS Doxyfile \
${PROJECT}.1.rst ${PROJECT}rc.5.rst ${OSOURCE} ${HEADER} ${PROJECT}.pc.in \
${PROJECT}.desktop version.h.in database-*.c \
${PROJECT}.desktop version.h.in database-sqlite.c \
${PROJECT}-${VERSION}
$(QUIET)cp tests/Makefile tests/config.mk tests/*.c \
${PROJECT}-${VERSION}/tests
......
......@@ -47,7 +47,6 @@ config_load_default(zathura_t* zathura)
int int_value = 0;
float float_value = 0;
char* string_value = NULL;
bool bool_value = false;
girara_session_t* gsession = zathura->ui.session;
......@@ -65,18 +64,19 @@ 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);
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, true, "Padding between pages", NULL, NULL);
girara_setting_add(gsession, "page-padding", &int_value, INT, true, "Padding between pages", NULL, 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);
girara_setting_add(gsession, "recolor-darkcolor", NULL, STRING, false, "Recoloring (dark color)", cb_color_change, NULL);
girara_setting_set(gsession, "recolor-darkcolor", "#FFFFFF");
......@@ -91,8 +91,7 @@ config_load_default(zathura_t* zathura)
girara_setting_add(gsession, "highlight-transparency", &float_value, FLOAT, false, "Transparency for highlighting", NULL, NULL);
bool_value = true;
girara_setting_add(gsession, "render-loading", &bool_value, BOOLEAN, false, "Render 'Loading ...'", NULL, NULL);
string_value = "best-fit";
girara_setting_add(gsession, "adjust-open", string_value, STRING, false, "Adjust to when opening file", NULL, NULL);
girara_setting_add(gsession, "adjust-open", "best-fit", STRING, false, "Adjust to when opening file", NULL, NULL);
bool_value = false;
girara_setting_add(gsession, "show-hidden", &bool_value, BOOLEAN, false, "Show hidden files and directories", NULL, NULL);
......
......@@ -10,6 +10,10 @@ VERSION = ${ZATHURA_VERSION_MAJOR}.${ZATHURA_VERSION_MINOR}.${ZATHURA_VERSION_RE
# the GTK version to use
ZATHURA_GTK_VERSION ?= 2
# database
# build with sqlite support
WITH_SQLITE ?= 1
# paths
PREFIX ?= /usr
MANPREFIX ?= ${PREFIX}/share/man
......@@ -26,8 +30,10 @@ GTK_LIB ?= $(shell pkg-config --libs gtk+-${ZATHURA_GTK_VERSION}.0 gthread-2.0)
GIRARA_INC ?= $(shell pkg-config --cflags girara-gtk${ZATHURA_GTK_VERSION})
GIRARA_LIB ?= $(shell pkg-config --libs girara-gtk${ZATHURA_GTK_VERSION})
ifneq (${WITH_SQLITE},0)
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
......@@ -54,6 +60,3 @@ SFLAGS ?= -s
# set to something != 0 if you want verbose build output
VERBOSE ?= 0
# database
# possible values are sqlite and plain
DATABASE ?= plain
This diff is collapsed.
/* See LICENSE file for license and copyright information */
#ifndef ZATHURA_DATABASE_PLAIN_H
#define ZATHURA_DATABASE_PLAIN_H
#include "database.h"
#define ZATHURA_TYPE_PLAINDATABASE \
(zathura_plaindatabase_get_type ())
#define ZATHURA_PLAINDATABASE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), ZATHURA_TYPE_PLAINDATABASE, ZathuraPlainDatabase))
#define ZATHURA_IS_PLAINDATABASE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZATHURA_TYPE_PLAINDATABASE))
#define ZATHURA_PLAINDATABASE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), ZATHURA_TYPE_PLAINDATABASE, ZathuraPlainDatabaseClass))
#define ZATHURA_IS_PLAINDATABASE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), ZATHURA_TYPE_PLAINDATABASE))
#define ZATHURA_PLAINDATABASE_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), ZATHURA_TYPE_PLAINDATABASE, ZathuraPlainDatabaseClass))
typedef struct _ZathuraPlainDatabase ZathuraPlainDatabase;
typedef struct _ZathuraPlainDatabaseClass ZathuraPlainDatabaseClass;
struct _ZathuraPlainDatabase
{
GObject parent_instance;
};
struct _ZathuraPlainDatabaseClass
{
GObjectClass parent_class;
};
GType zathura_plaindatabase_get_type(void);
/**
* Initialize database system.
*
* @param dir Path to the directory where the database file should be located.
* @return A valid zathura_database_t instance or NULL on failure
*/
zathura_database_t* zathura_plaindatabase_new(const char* dir);
#endif
/* See LICENSE file for license and copyright information */
#include <glib.h>
#include <sqlite3.h>
#include <girara/utils.h>
#include <girara/datastructures.h>
#include <string.h>
#include "database.h"
#include "database-sqlite.h"
#define DATABASE "bookmarks.sqlite"
struct zathura_database_s
{
static void zathura_database_interface_init(ZathuraDatabaseInterface* iface);
G_DEFINE_TYPE_WITH_CODE(ZathuraSQLDatabase, zathura_sqldatabase, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE(ZATHURA_TYPE_DATABASE, zathura_database_interface_init))
static void sqlite_finalize(GObject* object);
static bool sqlite_add_bookmark(zathura_database_t* db, const char* file,
zathura_bookmark_t* bookmark);
static bool sqlite_remove_bookmark(zathura_database_t* db, const char* file, const
char* id);
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, int offset, double scale, int rotation);
static bool sqlite_get_fileinfo(zathura_database_t* db, const char* file, unsigned
int* page, int* offset, double* scale, int* rotation);
static void sqlite_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec);
typedef struct zathura_sqldatabase_private_s {
sqlite3* session;
} zathura_sqldatabase_private_t;
#define ZATHURA_SQLDATABASE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZATHURA_TYPE_SQLDATABASE, zathura_sqldatabase_private_t))
enum
{
PROP_0,
PROP_PATH
};
static void
zathura_database_interface_init(ZathuraDatabaseInterface* iface)
{
/* initialize interface */
iface->add_bookmark = sqlite_add_bookmark;
iface->remove_bookmark = sqlite_remove_bookmark;
iface->load_bookmarks = sqlite_load_bookmarks;
iface->set_fileinfo = sqlite_set_fileinfo;
iface->get_fileinfo = sqlite_get_fileinfo;
}
static void
zathura_sqldatabase_class_init(ZathuraSQLDatabaseClass* class)
{
/* add private members */
g_type_class_add_private(class, sizeof(zathura_sqldatabase_private_t));
/* override methods */
GObjectClass* object_class = G_OBJECT_CLASS(class);
object_class->finalize = sqlite_finalize;
object_class->set_property = sqlite_set_property;
g_object_class_install_property(object_class, PROP_PATH,
g_param_spec_string("path", "path", "path to the database", NULL, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}
static void
zathura_sqldatabase_init(ZathuraSQLDatabase* db)
{
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
priv->session = NULL;
}
zathura_database_t*
zathura_db_init(const char* dir)
zathura_sqldatabase_new(const char* path)
{
if (dir == NULL) {
g_return_val_if_fail(path != NULL && strlen(path) != 0, NULL);
zathura_database_t* db = g_object_new(ZATHURA_TYPE_SQLDATABASE, "path", path, NULL);
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
if (priv->session == NULL) {
g_object_unref(db);
return NULL;
}
return db;
}
char* path = g_build_filename(dir, DATABASE, NULL);
if (path == NULL) {
return NULL;
static void
sqlite_finalize(GObject* object)
{
ZathuraSQLDatabase* db = ZATHURA_SQLDATABASE(object);
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
if (priv->session) {
sqlite3_close(priv->session);
}
zathura_database_t* db = g_malloc0(sizeof(zathura_database_t));
G_OBJECT_CLASS(zathura_sqldatabase_parent_class)->finalize(object);
}
static void
sqlite_db_init(ZathuraSQLDatabase* db, const char* path)
{
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
/* create bookmarks database */
static const char SQL_BOOKMARK_INIT[] =
......@@ -44,43 +120,41 @@ zathura_db_init(const char* dir)
"scale FLOAT,"
"rotation INTEGER);";
if (sqlite3_open(path, &(db->session)) != SQLITE_OK) {
sqlite3* session = NULL;
if (sqlite3_open(path, &session) != SQLITE_OK) {
girara_error("Could not open database: %s\n", path);
goto error_free;
return;
}
if (sqlite3_exec(db->session, SQL_BOOKMARK_INIT, NULL, 0, NULL) != SQLITE_OK) {
if (sqlite3_exec(session, SQL_BOOKMARK_INIT, NULL, 0, NULL) != SQLITE_OK) {
girara_error("Failed to initialize database: %s\n", path);
goto error_free;
sqlite3_close(session);
return;
}
if (sqlite3_exec(db->session, SQL_FILEINFO_INIT, NULL, 0, NULL) != SQLITE_OK) {
if (sqlite3_exec(session, SQL_FILEINFO_INIT, NULL, 0, NULL) != SQLITE_OK) {
girara_error("Failed to initialize database: %s\n", path);
goto error_free;
sqlite3_close(session);
return;
}
return db;
error_free:
zathura_db_free(db);
g_free(path);
return NULL;
priv->session = session;
}
void
zathura_db_free(zathura_database_t* db)
static void
sqlite_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec)
{
if (db == NULL) {
return;
}
if (db->session != NULL) {
sqlite3_close(db->session);
ZathuraSQLDatabase* db = ZATHURA_SQLDATABASE(object);
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
switch (prop_id) {
case PROP_PATH:
g_return_if_fail(priv->session == NULL);
sqlite_db_init(db, g_value_get_string(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
g_free(db);
}
static sqlite3_stmt*
......@@ -106,16 +180,16 @@ prepare_statement(sqlite3* session, const char* statement)
return pp_stmt;
}
bool
zathura_db_add_bookmark(zathura_database_t* db, const char* file,
static bool
sqlite_add_bookmark(zathura_database_t* db, const char* file,
zathura_bookmark_t* bookmark)
{
g_return_val_if_fail(db && file && bookmark, false);
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
static const char SQL_BOOKMARK_ADD[] =
"REPLACE INTO bookmarks (file, id, page) VALUES (?, ?, ?);";
sqlite3_stmt* stmt = prepare_statement(db->session, SQL_BOOKMARK_ADD);
sqlite3_stmt* stmt = prepare_statement(priv->session, SQL_BOOKMARK_ADD);
if (stmt == NULL) {
return false;
}
......@@ -133,16 +207,16 @@ zathura_db_add_bookmark(zathura_database_t* db, const char* file,
return res == SQLITE_DONE;
}
bool
zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const char*
static bool
sqlite_remove_bookmark(zathura_database_t* db, const char* file, const char*
id)
{
g_return_val_if_fail(db && file && id, false);
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
static const char SQL_BOOKMARK_ADD[] =
"DELETE FROM bookmarks WHERE file = ? AND id = ?;";
sqlite3_stmt* stmt = prepare_statement(db->session, SQL_BOOKMARK_ADD);
sqlite3_stmt* stmt = prepare_statement(priv->session, SQL_BOOKMARK_ADD);
if (stmt == NULL) {
return false;
}
......@@ -159,15 +233,15 @@ zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const char*
return res == SQLITE_DONE;
}
girara_list_t*
zathura_db_load_bookmarks(zathura_database_t* db, const char* file)
static girara_list_t*
sqlite_load_bookmarks(zathura_database_t* db, const char* file)
{
g_return_val_if_fail(db && file, NULL);
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
static const char SQL_BOOKMARK_SELECT[] =
"SELECT id, page FROM bookmarks WHERE file = ?;";
sqlite3_stmt* stmt = prepare_statement(db->session, SQL_BOOKMARK_SELECT);
sqlite3_stmt* stmt = prepare_statement(priv->session, SQL_BOOKMARK_SELECT);
if (stmt == NULL) {
return NULL;
}
......@@ -180,11 +254,6 @@ zathura_db_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_free_function_t) zathura_bookmark_free);
if (result == NULL) {
sqlite3_finalize(stmt);
return NULL;
}
while (sqlite3_step(stmt) == SQLITE_ROW) {
zathura_bookmark_t* bookmark = g_malloc0(sizeof(zathura_bookmark_t));
......@@ -197,16 +266,16 @@ zathura_db_load_bookmarks(zathura_database_t* db, const char* file)
return result;
}
bool
zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned int
static bool
sqlite_set_fileinfo(zathura_database_t* db, const char* file, unsigned int
page, int offset, double scale, int rotation)
{
g_return_val_if_fail(db && file, false);
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
static const char SQL_FILEINFO_SET[] =
"REPLACE INTO fileinfo (file, page, offset, scale, rotation) VALUES (?, ?, ?, ?, ?);";
sqlite3_stmt* stmt = prepare_statement(db->session, SQL_FILEINFO_SET);
sqlite3_stmt* stmt = prepare_statement(priv->session, SQL_FILEINFO_SET);
if (stmt == NULL) {
return false;
}
......@@ -226,16 +295,16 @@ zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned int
return res == SQLITE_DONE;
}
bool
zathura_db_get_fileinfo(zathura_database_t* db, const char* file, unsigned int*
static bool
sqlite_get_fileinfo(zathura_database_t* db, const char* file, unsigned int*
page, int* offset, double* scale, int* rotation)
{
g_return_val_if_fail(db && file && page && offset && scale && rotation, false);
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
static const char SQL_FILEINFO_GET[] =
"SELECT page, offset, scale, rotation FROM fileinfo WHERE file = ?;";
sqlite3_stmt* stmt = prepare_statement(db->session, SQL_FILEINFO_GET);
sqlite3_stmt* stmt = prepare_statement(priv->session, SQL_FILEINFO_GET);
if (stmt == NULL) {
return false;
}
......@@ -259,4 +328,3 @@ zathura_db_get_fileinfo(zathura_database_t* db, const char* file, unsigned int*
sqlite3_finalize(stmt);
return true;
}
/* See LICENSE file for license and copyright information */
#ifndef ZATHURA_DATABASE_SQLITE_H
#define ZATHURA_DATABASE_SQLITE_H
#include "database.h"
#define ZATHURA_TYPE_SQLDATABASE \
(zathura_sqldatabase_get_type ())
#define ZATHURA_SQLDATABASE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), ZATHURA_TYPE_SQLDATABASE, ZathuraSQLDatabase))
#define ZATHURA_IS_SQLDATABASE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZATHURA_TYPE_SQLDATABASE))
#define ZATHURA_SQLDATABASE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), ZATHURA_TYPE_SQLDATABASE, ZathuraSQLDatabaseClass))
#define ZATHURA_IS_SQLDATABASE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), ZATHURA_TYPE_SQLDATABASE))
#define ZATHURA_SQLDATABASE_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), ZATHURA_TYPE_SQLDATABASE, ZathuraSQLDatabaseClass))
typedef struct _ZathuraSQLDatabase ZathuraSQLDatabase;
typedef struct _ZathuraSQLDatabaseClass ZathuraSQLDatabaseClass;
struct _ZathuraSQLDatabase
{
GObject parent_instance;
};
struct _ZathuraSQLDatabaseClass
{
GObjectClass parent_class;
};
GType zathura_sqldatabase_get_type(void);
/**
* Initialize database system.
*
* @param dir Path to the sqlite database.
* @return A valid zathura_database_t instance or NULL on failure
*/
zathura_database_t* zathura_sqldatabase_new(const char* path);
#endif
/* See LICENSE file for license and copyright information */
#include "database.h"
G_DEFINE_INTERFACE(ZathuraDatabase, zathura_database, G_TYPE_OBJECT)
static void
zathura_database_default_init(ZathuraDatabaseInterface* GIRARA_UNUSED(iface))
{
}
void zathura_db_free(zathura_database_t* db)
{
if (db == NULL) {
return;
}
g_object_unref(db);
}
bool zathura_db_add_bookmark(zathura_database_t* db, const char* file,
zathura_bookmark_t* bookmark)
{
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file && bookmark, false);
return ZATHURA_DATABASE_GET_INTERFACE(db)->add_bookmark(db, file, bookmark);
}
bool zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const
char* id)
{
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file && id, false);
return ZATHURA_DATABASE_GET_INTERFACE(db)->remove_bookmark(db, file, id);
}
girara_list_t* zathura_db_load_bookmarks(zathura_database_t* db, const char*
file)
{
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file, NULL);
return ZATHURA_DATABASE_GET_INTERFACE(db)->load_bookmarks(db, file);
}
bool zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned
int page, int offset, double scale, int rotation)
{
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file, false);
return ZATHURA_DATABASE_GET_INTERFACE(db)->set_fileinfo(db, file, page, offset, scale, rotation);
}
bool zathura_db_get_fileinfo(zathura_database_t* db, const char* file, unsigned
int* page, int* offset, double* scale, int* rotation)
{
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file && page && offset && scale && rotation, false);
return ZATHURA_DATABASE_GET_INTERFACE(db)->get_fileinfo(db, file, page, offset, scale, rotation);
}
......@@ -5,17 +5,39 @@
#include <stdbool.h>
#include <girara/types.h>
#include <glib-object.h>
#include "zathura.h"
#include "bookmarks.h"
/**
* Initialize database system.
*
* @param dir Path to the directory where the database file should be located.
* @return A valid zathura_database_t instance or NULL on failure
*/
zathura_database_t* zathura_db_init(const char* dir);
#define ZATHURA_TYPE_DATABASE \
(zathura_database_get_type ())
#define ZATHURA_DATABASE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), ZATHURA_TYPE_DATABASE, ZathuraDatabase))
#define ZATHURA_IS_DATABASE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZATHURA_TYPE_DATABASE))
#define ZATHURA_DATABASE_GET_INTERFACE(obj) \
(G_TYPE_INSTANCE_GET_INTERFACE ((obj), ZATHURA_TYPE_DATABASE, ZathuraDatabaseInterface))
typedef struct _ZathuraDatabase ZathuraDatabase;
typedef struct _ZathuraDatabaseInterface ZathuraDatabaseInterface;
struct _ZathuraDatabaseInterface
{
GTypeInterface parent_iface;
/* interface methords */
bool (*add_bookmark)(ZathuraDatabase* db, const char* file, zathura_bookmark_t* bookmark);
bool (*remove_bookmark)(ZathuraDatabase* db, const char* file, const char* id);
girara_list_t* (*load_bookmarks)(ZathuraDatabase* db, const char* file);
bool (*set_fileinfo)(ZathuraDatabase* db, const char* file, unsigned
int page, int offset, double scale, int rotation);
bool (*get_fileinfo)(ZathuraDatabase* db, const char* file, unsigned
int* page, int* offset, double* scale, int* rotation);
};
GType zathura_database_get_type(void);
/**
* Free database instance.
......
......@@ -17,7 +17,10 @@
#include "bookmarks.h"
#include "callbacks.h"
#include "config.h"
#include "database.h"
#ifdef WITH_SQLITE
#include "database-sqlite.h"
#endif
#include "database-plain.h"
#include "document.h"
#include "shortcuts.h"
#include "zathura.h"
......@@ -231,7 +234,24 @@ zathura_init(int argc, char* argv[])
gtk_table_set_col_spacings(GTK_TABLE(zathura->ui.page_widget), zathura->global.page_padding);
/* database */
zathura->database = zathura_db_init(zathura->config.data_dir);
char* database = NULL;
girara_setting_get(zathura->ui.session, "database", &database);
if (g_strcmp0(database, "plain") == 0) {
girara_info("Using plain database backend.");
zathura->database = zathura_plaindatabase_new(zathura->config.data_dir);
#ifdef WITH_SQLITE
} else if (g_strcmp0(database, "sqlite") == 0) {
girara_info("Using sqlite database backend.");
char* tmp = g_build_filename(zathura->config.data_dir, "bookmarks.sqlite", NULL);
zathura->database = zathura_sqldatabase_new(tmp);
g_free(tmp);
#endif
} else {
girara_error("Database backend '%s' is not supported.", database);
}
g_free(database);
if (zathura->database == NULL) {
girara_error("Unable to initialize database. Bookmarks won't be available.");
}
......
......@@ -26,8 +26,7 @@ typedef struct zathura_document_s zathura_document_t;
typedef struct zathura_page_s zathura_page_t;
/* forward declaration for types form database.h */
struct zathura_database_s;
typedef struct zathura_database_s zathura_database_t;
typedef struct _ZathuraDatabase zathura_database_t;
/* forward declaration for types from render.h */
struct render_thread_s;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment