Commit e5f36e40 authored by Moritz Lipp's avatar Moritz Lipp

Merge branch 'release/0.2.4'

parents b17c05c9 3978dc30
......@@ -22,9 +22,7 @@ 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. Please note that sqlite3
with meta data support is required, i.e. sqlite3 has to be built with
SQLITE_ENABLE_COLUMN_METADATA defined.
WITH_SQLITE=0 and sqlite support won't be available.
The use of magic to detect mime types is optional and can be disabled by setting
WITH_MAGIC=0.
......
......@@ -4,9 +4,11 @@
#include "bookmarks.h"
#include "database.h"
#include "document.h"
#include "adjustment.h"
#include <girara/datastructures.h>
#include <girara/utils.h>
#include <girara/session.h>
static int
bookmark_compare_find(const void* item, const void* data)
......@@ -23,14 +25,35 @@ zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page)
g_return_val_if_fail(zathura && zathura->document && zathura->bookmarks.bookmarks, NULL);
g_return_val_if_fail(id, NULL);
zathura_bookmark_t* old = girara_list_find(zathura->bookmarks.bookmarks, bookmark_compare_find, id);
double x = zathura_adjustment_get_ratio(gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)));
double y = zathura_adjustment_get_ratio(gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)));
zathura_bookmark_t* old = zathura_bookmark_get(zathura, id);
if (old != NULL) {
return NULL;
old->page = page;
old->x = x;
old->y = y;
if (zathura->database != NULL) {
const char* path = zathura_document_get_path(zathura->document);
if (zathura_db_remove_bookmark(zathura->database, path, old->id) == false) {
girara_warning("Failed to remove old bookmark from database.");
}
if (zathura_db_add_bookmark(zathura->database, path, old) == false) {
girara_warning("Failed to add new bookmark to database.");
}
}
return old;
}
zathura_bookmark_t* bookmark = g_malloc0(sizeof(zathura_bookmark_t));
bookmark->id = g_strdup(id);
bookmark->page = page;
bookmark->x = x;
bookmark->y = y;
girara_list_append(zathura->bookmarks.bookmarks, bookmark);
if (zathura->database != NULL) {
......
......@@ -10,6 +10,8 @@ struct zathura_bookmark_s
{
gchar* id;
unsigned int page;
double x;
double y;
};
typedef struct zathura_bookmark_s zathura_bookmark_t;
......
......@@ -95,9 +95,9 @@ cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpoi
if (gdk_rectangle_intersect(&view_rect, &page_rect, NULL) == TRUE) {
if (zathura_page_get_visibility(page) == false) {
zathura_page_set_visibility(page, true);
zathura_page_widget_update_view_time(ZATHURA_PAGE(page_widget));
zathura_page_cache_add(zathura, zathura_page_get_index(page));
zathura_page_set_visibility(page, true);
zathura_page_widget_update_view_time(ZATHURA_PAGE(page_widget));
zathura_page_cache_add(zathura, zathura_page_get_index(page));
}
if (zathura->global.update_page_number == true && updated == false
&& gdk_rectangle_intersect(&center, &page_rect, NULL) == TRUE) {
......@@ -106,6 +106,19 @@ cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpoi
}
} else {
zathura_page_set_visibility(page, false);
/* if the page is not visible and not cached, but still has a surface, we
* need to get rid of the surface */
if (zathura_page_widget_have_surface(ZATHURA_PAGE(page_widget)) == true &&
zathura_page_cache_is_cached(zathura, zathura_page_get_index(page)) == false) {
zathura_page_widget_update_surface(ZATHURA_PAGE(page_widget), NULL);
}
girara_list_t* results = NULL;
g_object_get(page_widget, "search-results", &results, NULL);
if (results != NULL) {
g_object_set(page_widget, "search-current", 0, NULL);
}
}
}
......@@ -267,10 +280,7 @@ cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path,
}
sc_toggle_index(zathura->ui.session, NULL, NULL, 0);
/* zathura_jumplist_save is called when entering index mode */
zathura_link_evaluate(zathura, index_element->link);
zathura_jumplist_add(zathura);
}
g_object_unref(model);
......@@ -326,9 +336,7 @@ handle_link(GtkEntry* entry, girara_session_t* session,
invalid_index = false;
switch (action) {
case ZATHURA_LINK_ACTION_FOLLOW:
zathura_jumplist_save(zathura);
zathura_link_evaluate(zathura, link);
zathura_jumplist_add(zathura);
break;
case ZATHURA_LINK_ACTION_DISPLAY:
zathura_link_display(zathura, link);
......@@ -527,7 +535,7 @@ cb_unknown_command(girara_session_t* session, const char* input)
}
}
zathura_jumplist_save(zathura);
zathura_jumplist_add(zathura);
page_set(zathura, atoi(input) - 1);
zathura_jumplist_add(zathura);
......
......@@ -18,6 +18,7 @@
#include "plugin.h"
#include "internal.h"
#include "render.h"
#include "adjustment.h"
#include <girara/session.h>
#include <girara/settings.h>
......@@ -44,19 +45,24 @@ cmd_bookmark_create(girara_session_t* session, girara_list_t* argument_list)
const char* bookmark_name = girara_list_nth(argument_list, 0);
zathura_bookmark_t* bookmark = zathura_bookmark_get(zathura, bookmark_name);
if (bookmark != NULL) {
bookmark->page = zathura_document_get_current_page_number(zathura->document) + 1;
girara_notify(session, GIRARA_INFO, _("Bookmark successfuly updated: %s"), bookmark_name);
return true;
}
bool update = bookmark != NULL ? true : false;
bookmark = zathura_bookmark_add(zathura, bookmark_name, zathura_document_get_current_page_number(zathura->document) + 1);
if (bookmark == NULL) {
girara_notify(session, GIRARA_ERROR, _("Could not create bookmark: %s"), bookmark_name);
if (update == true) {
girara_notify(session, GIRARA_ERROR, _("Could not update bookmark: %s"), bookmark_name);
} else {
girara_notify(session, GIRARA_ERROR, _("Could not create bookmark: %s"), bookmark_name);
}
return false;
} else {
if (update == true) {
girara_notify(session, GIRARA_INFO, _("Bookmark successfully updated: %s"), bookmark_name);
} else {
girara_notify(session, GIRARA_INFO, _("Bookmark successfully created: %s"), bookmark_name);
}
}
girara_notify(session, GIRARA_INFO, _("Bookmark successfuly created: %s"), bookmark_name);
return true;
}
......@@ -111,7 +117,20 @@ cmd_bookmark_open(girara_session_t* session, girara_list_t* argument_list)
return false;
}
return page_set(zathura, bookmark->page - 1);
zathura_jumplist_add(zathura);
if (bookmark->x != DBL_MIN && bookmark->y != DBL_MIN) {
GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
zathura_adjustment_set_value_from_ratio(hadjustment, bookmark->x);
zathura_adjustment_set_value_from_ratio(vadjustment, bookmark->y);
zathura_document_set_current_page_number(zathura->document, bookmark->page - 1);
statusbar_page_number_update(zathura);
} else {
page_set(zathura, bookmark->page - 1);
}
zathura_jumplist_add(zathura);
return true;
}
bool
......@@ -339,7 +358,6 @@ cmd_search(girara_session_t* session, const char* input, girara_argument_t* argu
return false;
}
bool firsthit = true;
zathura_error_t error = ZATHURA_ERROR_OK;
/* set search direction */
......@@ -352,10 +370,6 @@ cmd_search(girara_session_t* session, const char* input, girara_argument_t* argu
bool nohlsearch = false;
girara_setting_get(session, "nohlsearch", &nohlsearch);
if (nohlsearch == false) {
document_draw_search_results(zathura, true);
}
/* search pages */
for (unsigned int page_id = 0; page_id < number_of_pages; ++page_id) {
unsigned int index = (page_id + current_page_number) % number_of_pages;
......@@ -383,20 +397,21 @@ cmd_search(girara_session_t* session, const char* input, girara_argument_t* argu
}
g_object_set(page_widget, "search-results", result, NULL);
if (firsthit == true) {
if (page_id != 0) {
page_set_delayed(zathura, zathura_page_get_index(page));
}
if (argument->n == BACKWARD) {
/* start at bottom hit in page */
g_object_set(page_widget, "search-current", girara_list_size(result) - 1, NULL);
} else {
g_object_set(page_widget, "search-current", 0, NULL);
}
firsthit = false;
if (argument->n == BACKWARD) {
/* start at bottom hit in page */
g_object_set(page_widget, "search-current", girara_list_size(result) - 1, NULL);
} else {
g_object_set(page_widget, "search-current", 0, NULL);
}
}
girara_argument_t* arg = g_malloc0(sizeof(girara_argument_t));
arg->n = FORWARD;
sc_search(session, arg, NULL, 0);
g_free(arg);
return true;
}
......
......@@ -27,10 +27,18 @@ cb_jumplist_change(girara_session_t* session, const char* name,
g_return_if_fail(session->global.data != NULL);
g_return_if_fail(name != NULL);
zathura_t* zathura = session->global.data;
if (g_strcmp0(name, "jumplist-size") == 0) {
int* max_size = (int*) value;
zathura->jumplist.max_size = *max_size;
if (g_strcmp0(name, "jumplist-size") != 0) {
return;
}
if (*(int *)value < 0) {
zathura->jumplist.max_size = 0;
} else {
zathura->jumplist.max_size = *(int *)value;
}
zathura_jumplist_trim(zathura);
}
static void
......@@ -157,7 +165,7 @@ config_load_default(zathura_t* zathura)
girara_setting_add(gsession, "zoom-max", &int_value, INT, false, _("Zoom maximum"), NULL, NULL);
int_value = ZATHURA_PAGE_CACHE_DEFAULT_SIZE;
girara_setting_add(gsession, "page-cache-size", &int_value, INT, true, _("Maximum number of pages to keep in the cache"), NULL, NULL);
int_value = 20;
int_value = 2000;
girara_setting_add(gsession, "jumplist-size", &int_value, INT, false, _("Number of positions to remember in the jumplist"), cb_jumplist_change, NULL);
girara_setting_add(gsession, "recolor-darkcolor", NULL, STRING, false, _("Recoloring (dark color)"), cb_color_change, NULL);
......@@ -209,6 +217,8 @@ config_load_default(zathura_t* zathura)
bool_value = false;
girara_setting_add(gsession, "window-title-basename", &bool_value, BOOLEAN, false, _("Use basename of the file in the window title"), NULL, NULL);
bool_value = false;
girara_setting_add(gsession, "window-title-page", &bool_value, BOOLEAN, false, _("Display the page number in the window title"), NULL, NULL);
bool_value = false;
girara_setting_add(gsession, "statusbar-basename", &bool_value, BOOLEAN, false, _("Use basename of the file in the statusbar"), NULL, NULL);
bool_value = false;
girara_setting_add(gsession, "synctex", &bool_value, BOOLEAN, false, _("Enable synctex support"), NULL, NULL);
......
......@@ -3,7 +3,7 @@
ZATHURA_VERSION_MAJOR = 0
ZATHURA_VERSION_MINOR = 2
ZATHURA_VERSION_REV = 3
ZATHURA_VERSION_REV = 4
# If the API changes, the API version and the ABI version have to be bumped.
ZATHURA_API_VERSION = 2
# If the ABI breaks for any reason, this has to be bumped.
......
......@@ -15,18 +15,19 @@
#include "database-plain.h"
#define BOOKMARKS "bookmarks"
#define HISTORY "history"
#define INPUT_HISTORY "input-history"
#define KEY_PAGE "page"
#define KEY_OFFSET "offset"
#define KEY_SCALE "scale"
#define KEY_ROTATE "rotate"
#define KEY_PAGES_PER_ROW "pages-per-row"
#define KEY_FIRST_PAGE_COLUMN "first-page-column"
#define KEY_POSITION_X "position-x"
#define KEY_POSITION_Y "position-y"
#define BOOKMARKS "bookmarks"
#define HISTORY "history"
#define INPUT_HISTORY "input-history"
#define KEY_PAGE "page"
#define KEY_OFFSET "offset"
#define KEY_SCALE "scale"
#define KEY_ROTATE "rotate"
#define KEY_PAGES_PER_ROW "pages-per-row"
#define KEY_FIRST_PAGE_COLUMN "first-page-column"
#define KEY_POSITION_X "position-x"
#define KEY_POSITION_Y "position-y"
#define KEY_JUMPLIST "jumplist"
#ifdef __GNU__
#include <sys/file.h>
......@@ -46,28 +47,23 @@ G_DEFINE_TYPE_WITH_CODE(ZathuraPlainDatabase, zathura_plaindatabase, G_TYPE_OBJE
G_IMPLEMENT_INTERFACE(ZATHURA_TYPE_DATABASE, zathura_database_interface_init)
G_IMPLEMENT_INTERFACE(GIRARA_TYPE_INPUT_HISTORY_IO, io_interface_init))
static void plain_finalize(GObject* object);
static bool plain_add_bookmark(zathura_database_t* db, const char* file,
zathura_bookmark_t* bookmark);
static bool plain_remove_bookmark(zathura_database_t* db, const char* file,
const char* id);
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,
zathura_fileinfo_t* file_info);
static bool plain_get_fileinfo(zathura_database_t* db, const char* file,
zathura_fileinfo_t* file_info);
static void plain_set_property(GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec);
static void plain_io_append(GiraraInputHistoryIO* db, const char*);
static void plain_finalize(GObject* object);
static bool plain_add_bookmark(zathura_database_t* db, const char* file, zathura_bookmark_t* bookmark);
static bool plain_remove_bookmark(zathura_database_t* db, const char* file, const char* id);
static girara_list_t* plain_load_bookmarks(zathura_database_t* db, const char* file);
static girara_list_t* plain_load_jumplist(zathura_database_t* db, const char* file);
static bool plain_save_jumplist(zathura_database_t* db, const char* file, girara_list_t* jumplist);
static bool plain_set_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t* file_info);
static bool plain_get_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t* file_info);
static void plain_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec);
static void plain_io_append(GiraraInputHistoryIO* db, const char*);
static girara_list_t* plain_io_read(GiraraInputHistoryIO* db);
/* forward declaration */
static bool zathura_db_check_file(const char* path);
static GKeyFile* zathura_db_read_key_file_from_file(const char* path);
static void zathura_db_write_key_file_to_file(const char* file, GKeyFile* key_file);
static void cb_zathura_db_watch_file(GFileMonitor* monitor, GFile* file, GFile*
other_file, GFileMonitorEvent event, zathura_database_t* database);
static bool zathura_db_check_file(const char* path);
static GKeyFile* zathura_db_read_key_file_from_file(const char* path);
static void zathura_db_write_key_file_to_file(const char* file, GKeyFile* key_file);
static void cb_zathura_db_watch_file(GFileMonitor* monitor, GFile* file, GFile* other_file, GFileMonitorEvent event, zathura_database_t* database);
typedef struct zathura_plaindatabase_private_s {
char* bookmark_path;
......@@ -110,6 +106,8 @@ zathura_database_interface_init(ZathuraDatabaseInterface* iface)
iface->add_bookmark = plain_add_bookmark;
iface->remove_bookmark = plain_remove_bookmark;
iface->load_bookmarks = plain_load_bookmarks;
iface->load_jumplist = plain_load_jumplist;
iface->save_jumplist = plain_save_jumplist;
iface->set_fileinfo = plain_set_fileinfo;
iface->get_fileinfo = plain_get_fileinfo;
}
......@@ -328,7 +326,18 @@ plain_add_bookmark(zathura_database_t* db, const char* file,
}
char* name = prepare_filename(file);
g_key_file_set_integer(priv->bookmarks, name, bookmark->id, bookmark->page);
char* val_list[] = { g_strdup_printf("%d", bookmark->page),
g_ascii_dtostr(g_malloc(G_ASCII_DTOSTR_BUF_SIZE), G_ASCII_DTOSTR_BUF_SIZE, bookmark->x),
g_ascii_dtostr(g_malloc(G_ASCII_DTOSTR_BUF_SIZE), G_ASCII_DTOSTR_BUF_SIZE, bookmark->y) };
gsize num_vals = sizeof(val_list)/sizeof(char *);
g_key_file_set_string_list(priv->bookmarks, name, bookmark->id, (const char**)val_list, num_vals);
for (unsigned int i = 0; i < num_vals; ++i) {
g_free(val_list[i]);
}
g_free(name);
zathura_db_write_key_file_to_file(priv->bookmark_path, priv->bookmarks);
......@@ -337,8 +346,7 @@ plain_add_bookmark(zathura_database_t* db, const char* file,
}
static bool
plain_remove_bookmark(zathura_database_t* db, const char* file, const char*
GIRARA_UNUSED(id))
plain_remove_bookmark(zathura_database_t* db, const char* file, const char* id)
{
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
if (priv->bookmarks == NULL || priv->bookmark_path == NULL) {
......@@ -347,12 +355,13 @@ plain_remove_bookmark(zathura_database_t* db, const char* file, const char*
char* name = prepare_filename(file);
if (g_key_file_has_group(priv->bookmarks, name) == TRUE) {
g_key_file_remove_group(priv->bookmarks, name, NULL);
if (g_key_file_remove_key(priv->bookmarks, name, id, NULL) == TRUE) {
zathura_db_write_key_file_to_file(priv->bookmark_path, priv->bookmarks);
g_free(name);
zathura_db_write_key_file_to_file(priv->bookmark_path, priv->bookmarks);
g_free(name);
return true;
return true;
}
}
g_free(name);
......@@ -377,21 +386,37 @@ plain_load_bookmarks(zathura_database_t* db, const char* file)
zathura_bookmarks_compare, (girara_free_function_t)
zathura_bookmark_free);
gsize length;
char** keys = g_key_file_get_keys(priv->bookmarks, name, &length, NULL);
gsize num_keys;
char** keys = g_key_file_get_keys(priv->bookmarks, name, &num_keys, NULL);
if (keys == NULL) {
girara_list_free(result);
g_free(name);
return NULL;
}
for (gsize i = 0; i < length; i++) {
char **val_list = NULL;
gsize num_vals = 0;
for (gsize i = 0; i < num_keys; i++) {
zathura_bookmark_t* bookmark = g_malloc0(sizeof(zathura_bookmark_t));
bookmark->id = g_strdup(keys[i]);
bookmark->page = g_key_file_get_integer(priv->bookmarks, name, keys[i], NULL);
val_list = g_key_file_get_string_list(priv->bookmarks, name, keys[i], &num_vals, NULL);
bookmark->page = atoi(val_list[0]);
if (num_vals == 3) {
bookmark->x = g_ascii_strtod(val_list[1], NULL);
bookmark->y = g_ascii_strtod(val_list[2], NULL);
} else if (num_vals == 1) {
bookmark->x = DBL_MIN;
bookmark->y = DBL_MIN;
} else {
girara_debug("This must be a BUG");
}
girara_list_append(result, bookmark);
g_strfreev(val_list);
}
g_free(name);
......@@ -400,6 +425,73 @@ plain_load_bookmarks(zathura_database_t* db, const char* file)
return result;
}
static girara_list_t*
get_jumplist_from_str(const char* str)
{
g_return_val_if_fail(str != NULL, NULL);
if (*str == 0) {
return girara_list_new2(g_free);
}
girara_list_t* result = girara_list_new2(g_free);
char* copy = g_strdup(str);
char* token = strtok(copy, " ");
while (token != NULL) {
zathura_jump_t* jump = g_malloc0(sizeof(zathura_jump_t));
jump->page = strtoul(token, NULL, 0);
token = strtok(NULL, " ");
jump->x = strtod(token, NULL);
token = strtok(NULL, " ");
jump->y = strtod(token, NULL);
girara_list_append(result, jump);
token = strtok(NULL, " ");
}
g_free(copy);
return result;
}
static girara_list_t*
plain_load_jumplist(zathura_database_t* db, const char* file)
{
g_return_val_if_fail(db != NULL && file != NULL, NULL);
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
char* str_value = g_key_file_get_string(priv->history, file, KEY_JUMPLIST, NULL);
if (str_value == NULL) {
return girara_list_new2(g_free);
}
return get_jumplist_from_str(str_value);
}
static bool
plain_save_jumplist(zathura_database_t* db, const char* file, girara_list_t* jumplist)
{
g_return_val_if_fail(db != NULL && file != NULL && jumplist != NULL, false);
GString* str_val = g_string_new(NULL);
GIRARA_LIST_FOREACH(jumplist, zathura_jump_t*, iter, jump)
g_string_append(str_val, g_strdup_printf("%d ", jump->page));
g_string_append(str_val, g_strdup_printf("%.20f ", jump->x));
g_string_append(str_val, g_strdup_printf("%.20f ", jump->y));
GIRARA_LIST_FOREACH_END(jumplist, zathura_jump_t*, iter, jump);
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
g_key_file_set_string(priv->history, file, KEY_JUMPLIST, str_val->str);
zathura_db_write_key_file_to_file(priv->history_path, priv->history);
g_string_free(str_val, TRUE);
return true;
}
static bool
plain_set_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
file_info)
......@@ -414,7 +506,7 @@ plain_set_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
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);
char* tmp = g_strdup_printf("%f", file_info->scale);
char* tmp = g_strdup_printf("%.20f", file_info->scale);
g_key_file_set_string (priv->history, name, KEY_SCALE, tmp);
g_free(tmp);
......@@ -422,11 +514,11 @@ plain_set_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
g_key_file_set_integer(priv->history, name, KEY_PAGES_PER_ROW, file_info->pages_per_row);
g_key_file_set_integer(priv->history, name, KEY_FIRST_PAGE_COLUMN, file_info->first_page_column);
tmp = g_strdup_printf("%f", file_info->position_x);
tmp = g_strdup_printf("%.20f", 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);
tmp = g_strdup_printf("%.20f", file_info->position_y);
g_key_file_set_string(priv->history, name, KEY_POSITION_Y, tmp);
g_free(tmp);
......@@ -579,7 +671,7 @@ zathura_db_write_key_file_to_file(const char* file, GKeyFile* key_file)
}
/* open file */
int fd = open(file, O_RDWR);
int fd = open(file, O_RDWR | O_TRUNC);
if (fd == -1) {
g_free(content);
return;
......@@ -647,7 +739,7 @@ plain_io_read(GiraraInputHistoryIO* db)
girara_list_t* res = girara_list_new2(g_free);
char** tmp = g_strsplit(content, "\n", 0);
for (size_t i = 0; tmp[i] != NULL; ++i) {
if (strlen(tmp[i]) == 0 || strchr(":/", tmp[i][0]) == NULL) {
if (strlen(tmp[i]) == 0 || strchr(":/?", tmp[i][0]) == NULL) {
continue;
}
girara_list_append(res, g_strdup(tmp[i]));
......@@ -688,7 +780,7 @@ plain_io_append(GiraraInputHistoryIO* db, const char* input)
/* write input history file */
for (size_t i = 0; tmp[i] != NULL; ++i) {
if (strlen(tmp[i]) == 0 || strchr(":/", tmp[i][0]) == NULL || strcmp(tmp[i], input) == 0) {
if (strlen(tmp[i]) == 0 || strchr(":/?", tmp[i][0]) == NULL || strcmp(tmp[i], input) == 0) {
continue;
}
fprintf(file, "%s\n", tmp[i]);
......
......@@ -15,20 +15,17 @@ G_DEFINE_TYPE_WITH_CODE(ZathuraSQLDatabase, zathura_sqldatabase, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE(ZATHURA_TYPE_DATABASE, zathura_database_interface_init)
G_IMPLEMENT_INTERFACE(GIRARA_TYPE_INPUT_HISTORY_IO, io_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,
zathura_fileinfo_t* file_info);
static bool sqlite_get_fileinfo(zathura_database_t* db, const char* file,
zathura_fileinfo_t* file_info);
static void sqlite_set_property(GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec);
static void sqlite_io_append(GiraraInputHistoryIO* db, const char*);
static bool check_column(sqlite3* session, const char* table, const char* col, bool* result);
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 girara_list_t* sqlite_load_jumplist(zathura_database_t* db, const char* file);
static bool sqlite_save_jumplist(zathura_database_t* db, const char* file, girara_list_t* jumplist);
static bool sqlite_set_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t* file_info);
static bool sqlite_get_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t* file_info);
static void sqlite_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec);
static void sqlite_io_append(GiraraInputHistoryIO* db, const char*);
static girara_list_t* sqlite_io_read(GiraraInputHistoryIO* db);
typedef struct zathura_sqldatabase_private_s {
......@@ -50,6 +47,8 @@ zathura_database_interface_init(ZathuraDatabaseInterface* iface)
iface->add_bookmark = sqlite_add_bookmark;
iface->remove_bookmark = sqlite_remove_bookmark;
iface->load_bookmarks = sqlite_load_bookmarks;
iface->load_jumplist = sqlite_load_jumplist;
iface->save_jumplist = sqlite_save_jumplist;
iface->set_fileinfo = sqlite_set_fileinfo;
iface->get_fileinfo = sqlite_get_fileinfo;
}
......@@ -117,14 +116,26 @@ sqlite_db_init(ZathuraSQLDatabase* db, const char* path)
{
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
/* create bookmarks database */
/* create bookmarks table */
static const char SQL_BOOKMARK_INIT[] =
"CREATE TABLE IF NOT EXISTS bookmarks ("
"file TEXT,"
"id TEXT,"
"page INTEGER,"
"hadj_ratio FLOAT,"
"vadj_ratio FLOAT,"
"PRIMARY KEY(file, id));";
static const char SQL_JUMPLIST_INIT[] =
"CREATE TABLE IF NOT EXISTS jumplist ("
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
"file TEXT,"
"page INTEGER,"
"hadj_ratio FLOAT,"
"vadj_ratio FLOAT"
");";
/* create fileinfo table */
static const char SQL_FILEINFO_INIT[] =
"CREATE TABLE IF NOT EXISTS fileinfo ("
"file TEXT PRIMARY KEY,"
......@@ -138,19 +149,27 @@ sqlite_db_init(ZathuraSQLDatabase* db, const char* path)
"position_y FLOAT"
");";
/* create history table */
static const char SQL_HISTORY_INIT[] =
"CREATE TABLE IF NOT EXISTS history ("
"time TIMESTAMP,"
"line TEXT,"
"PRIMARY KEY(line));";
/* update fileinfo table (part 1) */
static const char SQL_FILEINFO_ALTER[] =
"ALTER TABLE fileinfo ADD COLUMN pages_per_row INTEGER;"
"ALTER TABLE fileinfo ADD COLUMN position_x FLOAT;"
"ALTER TABLE fileinfo ADD COLUMN position_y FLOAT;";
/* update fileinfo table (part 2) */
static const char SQL_FILEINFO_ALTER2[] =
"ALTER TABLE fileinfo ADD COLUMN first_page_column INTEGER;";
static const char SQL_HISTORY_INIT[] =
"CREATE TABLE IF NOT EXISTS history ("
"time TIMESTAMP,"
"line TEXT,"
"PRIMARY KEY(line));";
/* update bookmark table */
static const char SQL_BOOKMARK_ALTER[] =
"ALTER TABLE bookmarks ADD COLUMN hadj_ratio FLOAT;"
"ALTER TABLE bookmarks ADD COLUMN vadj_ratio FLOAT;";
sqlite3* session = NULL;
if (sqlite3_open(path, &session) != SQLITE_OK) {
......@@ -158,12 +177,19 @@ sqlite_db_init(ZathuraSQLDatabase* db, const char* path)
return;
}
/* create tables if they don't exist */
if (sqlite3_exec(session, SQL_BOOKMARK_INIT, NULL, 0, NULL) != SQLITE_OK) {
girara_error("Failed to initialize database: %s\n", path);
sqlite3_close(session);
return;
}
if (sqlite3_exec(session, SQL_JUMPLIST_INIT, NULL, 0, NULL) != SQLITE_OK) {
girara_error("Failed to initialize database: %s\n", path);
sqlite3_close(session);
return;
}
if (