mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-13 08:43:47 +01:00
Merge branch 'develop' of pwmt.org:zathura into develop
This commit is contained in:
commit
e6d1cffce0
15
Makefile
15
Makefile
@ -4,10 +4,20 @@ include config.mk
|
|||||||
include common.mk
|
include common.mk
|
||||||
|
|
||||||
PROJECT = zathura
|
PROJECT = zathura
|
||||||
SOURCE = $(shell find . -iname "*.c")
|
SOURCE = $(shell find . -iname "*.c" -a ! -iname "database-*")
|
||||||
OBJECTS = $(patsubst %.c, %.o, $(SOURCE))
|
OBJECTS = $(patsubst %.c, %.o, $(SOURCE))
|
||||||
DOBJECTS = $(patsubst %.c, %.do, $(SOURCE))
|
DOBJECTS = $(patsubst %.c, %.do, $(SOURCE))
|
||||||
|
|
||||||
|
ifeq (${DATABASE}, sqlite)
|
||||||
|
INCS += $(SQLITE_INC)
|
||||||
|
LIBS += $(SQLITE_LIB)
|
||||||
|
SOURCE += database-sqlite.c
|
||||||
|
else
|
||||||
|
ifeq (${DATABASE}, plain)
|
||||||
|
SOURCE += database-plain.c
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
all: options ${PROJECT}
|
all: options ${PROJECT}
|
||||||
|
|
||||||
options:
|
options:
|
||||||
@ -27,6 +37,9 @@ options:
|
|||||||
@mkdir -p .depend
|
@mkdir -p .depend
|
||||||
$(QUIET)${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep
|
$(QUIET)${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep
|
||||||
|
|
||||||
|
# force recompilation of database.o if DATABASE has changed
|
||||||
|
database.o: database-${DATABASE}.o
|
||||||
|
|
||||||
${OBJECTS}: config.mk
|
${OBJECTS}: config.mk
|
||||||
${DOBJECTS}: config.mk
|
${DOBJECTS}: config.mk
|
||||||
|
|
||||||
|
12
README
12
README
@ -9,13 +9,13 @@ gtk2 (>= 2.18.6)
|
|||||||
girara
|
girara
|
||||||
sqlite3
|
sqlite3
|
||||||
|
|
||||||
Please note that you need to have a working pkg-config installation
|
Please note that you need to have a working pkg-config installation and that the
|
||||||
and that the Makefile is only compatible with GNU make. If you don't have a
|
Makefile is only compatible with GNU make. If you don't have a working
|
||||||
working pkg-config installation please set the GTK_INC, GTK_LIB, GIRARA_INC,
|
pkg-config installation please set the GTK_INC, GTK_LIB, GIRARA_INC, GIRARA_LIB,
|
||||||
GIRARA_LIB, SQLITE_INC and SQLITE_LIB variables accordingly.
|
SQLITE_INC and SQLITE_LIB variables accordingly.
|
||||||
|
|
||||||
And also note that rst2man from python-docutils is needed to build
|
And also note that rst2man from python-docutils is needed to build zathurarc.5.
|
||||||
zathurarc.5. If it is not installed, zathurarc.5 won't be built.
|
If it is not installed, zathurarc.5 won't be built.
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
@ -24,8 +24,8 @@ SQLITE_LIB ?= $(shell pkg-config --libs sqlite3)
|
|||||||
|
|
||||||
DL_LIB ?= -ldl
|
DL_LIB ?= -ldl
|
||||||
|
|
||||||
INCS = ${GIRARA_INC} ${GTK_INC} $(SQLITE_INC)
|
INCS = ${GIRARA_INC} ${GTK_INC}
|
||||||
LIBS = ${GIRARA_LIB} ${GTK_LIB} $(SQLITE_LIB) $(DL_LIB) -lpthread -lm
|
LIBS = ${GIRARA_LIB} ${GTK_LIB} $(DL_LIB) -lpthread -lm
|
||||||
|
|
||||||
# flags
|
# flags
|
||||||
CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length -Wextra $(INCS) -DZATHURA_PLUGINDIR=\"${PLUGINDIR}\"
|
CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length -Wextra $(INCS) -DZATHURA_PLUGINDIR=\"${PLUGINDIR}\"
|
||||||
@ -44,3 +44,7 @@ SFLAGS ?= -s
|
|||||||
|
|
||||||
# set to something != 0 if you want verbose build output
|
# set to something != 0 if you want verbose build output
|
||||||
VERBOSE ?= 0
|
VERBOSE ?= 0
|
||||||
|
|
||||||
|
# database
|
||||||
|
# possible values are sqlite and plain
|
||||||
|
DATABASE ?= sqlite
|
||||||
|
@ -6,15 +6,25 @@
|
|||||||
|
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
|
||||||
|
#define DATABASE "bookmarks.sqlite"
|
||||||
|
|
||||||
struct zathura_database_s
|
struct zathura_database_s
|
||||||
{
|
{
|
||||||
sqlite3* session;
|
sqlite3* session;
|
||||||
};
|
};
|
||||||
|
|
||||||
zathura_database_t*
|
zathura_database_t*
|
||||||
zathura_db_init(const char* path)
|
zathura_db_init(const char* dir)
|
||||||
{
|
{
|
||||||
|
char* path = g_build_filename(dir, DATABASE, NULL);
|
||||||
|
if (path == NULL) {
|
||||||
|
goto error_ret;
|
||||||
|
}
|
||||||
|
|
||||||
zathura_database_t* db = g_malloc0(sizeof(zathura_database_t));
|
zathura_database_t* db = g_malloc0(sizeof(zathura_database_t));
|
||||||
|
if (db == NULL) {
|
||||||
|
goto error_free;
|
||||||
|
}
|
||||||
|
|
||||||
/* create bookmarks database */
|
/* create bookmarks database */
|
||||||
static const char SQL_BOOKMARK_INIT[] =
|
static const char SQL_BOOKMARK_INIT[] =
|
||||||
@ -33,23 +43,30 @@ zathura_db_init(const char* path)
|
|||||||
|
|
||||||
if (sqlite3_open(path, &(db->session)) != SQLITE_OK) {
|
if (sqlite3_open(path, &(db->session)) != SQLITE_OK) {
|
||||||
girara_error("Could not open database: %s\n", path);
|
girara_error("Could not open database: %s\n", path);
|
||||||
zathura_db_free(db);
|
goto error_free;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sqlite3_exec(db->session, SQL_BOOKMARK_INIT, NULL, 0, NULL) != SQLITE_OK) {
|
if (sqlite3_exec(db->session, SQL_BOOKMARK_INIT, NULL, 0, NULL) != SQLITE_OK) {
|
||||||
girara_error("Failed to initialize database: %s\n", path);
|
girara_error("Failed to initialize database: %s\n", path);
|
||||||
zathura_db_free(db);
|
goto error_free;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sqlite3_exec(db->session, SQL_FILEINFO_INIT, NULL, 0, NULL) != SQLITE_OK) {
|
if (sqlite3_exec(db->session, SQL_FILEINFO_INIT, NULL, 0, NULL) != SQLITE_OK) {
|
||||||
girara_error("Failed to initialize database: %s\n", path);
|
girara_error("Failed to initialize database: %s\n", path);
|
||||||
zathura_db_free(db);
|
goto error_free;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return db;
|
return db;
|
||||||
|
|
||||||
|
error_free:
|
||||||
|
|
||||||
|
zathura_db_free(db);
|
||||||
|
|
||||||
|
error_ret:
|
||||||
|
|
||||||
|
g_free(path);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -59,7 +76,10 @@ zathura_db_free(zathura_database_t* db)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_close(db->session);
|
if (db->session != NULL) {
|
||||||
|
sqlite3_close(db->session);
|
||||||
|
}
|
||||||
|
|
||||||
g_free(db);
|
g_free(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +107,8 @@ prepare_statement(sqlite3* session, const char* statement)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
zathura_db_add_bookmark(zathura_database_t* db, const char* file, zathura_bookmark_t* bookmark)
|
zathura_db_add_bookmark(zathura_database_t* db, const char* file,
|
||||||
|
zathura_bookmark_t* bookmark)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail(db && file && bookmark, false);
|
g_return_val_if_fail(db && file && bookmark, false);
|
||||||
|
|
||||||
@ -113,7 +134,8 @@ zathura_db_add_bookmark(zathura_database_t* db, const char* file, zathura_bookma
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const char* id)
|
zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const char*
|
||||||
|
id)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail(db && file && id, false);
|
g_return_val_if_fail(db && file && id, false);
|
||||||
|
|
||||||
@ -175,7 +197,8 @@ zathura_db_load_bookmarks(zathura_database_t* db, const char* file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned int page, int offset, float scale)
|
zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned int
|
||||||
|
page, int offset, float scale)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail(db && file, false);
|
g_return_val_if_fail(db && file, false);
|
||||||
|
|
||||||
@ -202,7 +225,8 @@ zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned int p
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
zathura_db_get_fileinfo(zathura_database_t* db, const char* file, unsigned int* page, int* offset, float* scale)
|
zathura_db_get_fileinfo(zathura_database_t* db, const char* file, unsigned int*
|
||||||
|
page, int* offset, float* scale)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail(db && file && page && offset && scale, false);
|
g_return_val_if_fail(db && file && page && offset && scale, false);
|
||||||
|
|
||||||
|
19
database.h
19
database.h
@ -11,10 +11,10 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize database system.
|
* Initialize database system.
|
||||||
* @param path Path to the database file.
|
* @param path Path to the directory where the database file should be located.
|
||||||
* @return A valid zathura_database_t instance or NULL on failure
|
* @return A valid zathura_database_t instance or NULL on failure
|
||||||
*/
|
*/
|
||||||
zathura_database_t* zathura_db_init(const char* path);
|
zathura_database_t* zathura_db_init(const char* dir);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free database instance.
|
* Free database instance.
|
||||||
@ -29,7 +29,8 @@ void zathura_db_free(zathura_database_t* db);
|
|||||||
* @param bookmark The bookmark instance.
|
* @param bookmark The bookmark instance.
|
||||||
* @return true on success, false otherwise
|
* @return true on success, false otherwise
|
||||||
*/
|
*/
|
||||||
bool zathura_db_add_bookmark(zathura_database_t* db, const char* file, zathura_bookmark_t* bookmark);
|
bool zathura_db_add_bookmark(zathura_database_t* db, const char* file,
|
||||||
|
zathura_bookmark_t* bookmark);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add or update bookmark in the database.
|
* Add or update bookmark in the database.
|
||||||
@ -38,7 +39,8 @@ bool zathura_db_add_bookmark(zathura_database_t* db, const char* file, zathura_b
|
|||||||
* @param bookmark The bookmark instance.
|
* @param bookmark The bookmark instance.
|
||||||
* @return true on success, false otherwise
|
* @return true on success, false otherwise
|
||||||
*/
|
*/
|
||||||
bool zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const char* id);
|
bool zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const
|
||||||
|
char* id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all bookmarks from the database belonging to a specific file.
|
* Loads all bookmarks from the database belonging to a specific file.
|
||||||
@ -46,7 +48,8 @@ bool zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const
|
|||||||
* @param file The file for which the bookmarks should be loaded.
|
* @param file The file for which the bookmarks should be loaded.
|
||||||
* @return List of zathura_bookmark_t* or NULL on failure.
|
* @return List of zathura_bookmark_t* or NULL on failure.
|
||||||
*/
|
*/
|
||||||
girara_list_t* zathura_db_load_bookmarks(zathura_database_t* db, const char* file);
|
girara_list_t* zathura_db_load_bookmarks(zathura_database_t* db, const char*
|
||||||
|
file);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set file info (last site, ...) in the database.
|
* Set file info (last site, ...) in the database.
|
||||||
@ -57,7 +60,8 @@ girara_list_t* zathura_db_load_bookmarks(zathura_database_t* db, const char* fil
|
|||||||
* @param scale The last scale.
|
* @param scale The last scale.
|
||||||
* @return true on success, false otherwise.
|
* @return true on success, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned int page, int offset, float scale);
|
bool zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned
|
||||||
|
int page, int offset, float scale);
|
||||||
|
|
||||||
/* Get file info (last site, ...) from the database.
|
/* Get file info (last site, ...) from the database.
|
||||||
* @param db The database instance
|
* @param db The database instance
|
||||||
@ -67,6 +71,7 @@ bool zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned
|
|||||||
* @param scale The last scale.
|
* @param scale The last scale.
|
||||||
* @return true on success, false otherwise.
|
* @return true on success, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool zathura_db_get_fileinfo(zathura_database_t* db, const char* file, unsigned int* page, int* offset, float* scale);
|
bool zathura_db_get_fileinfo(zathura_database_t* db, const char* file, unsigned
|
||||||
|
int* page, int* offset, float* scale);
|
||||||
|
|
||||||
#endif // DATABASE_H
|
#endif // DATABASE_H
|
||||||
|
@ -205,12 +205,10 @@ zathura_init(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* database */
|
/* database */
|
||||||
char* database_path = g_build_filename(zathura->config.data_dir, "bookmarks.sqlite", NULL);
|
zathura->database = zathura_db_init(zathura->config.data_dir);
|
||||||
zathura->database = zathura_db_init(database_path);
|
|
||||||
if (zathura->database == NULL) {
|
if (zathura->database == NULL) {
|
||||||
girara_error("Unable to initialize database. Bookmarks won't be available.");
|
girara_error("Unable to initialize database. Bookmarks won't be available.");
|
||||||
}
|
}
|
||||||
g_free(database_path);
|
|
||||||
|
|
||||||
/* bookmarks */
|
/* bookmarks */
|
||||||
zathura->bookmarks.bookmarks = girara_list_new();
|
zathura->bookmarks.bookmarks = girara_list_new();
|
||||||
|
Loading…
Reference in New Issue
Block a user