From 14535b8f41401fadc58a1dec2e909ae03089f1a6 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sat, 15 Oct 2011 18:26:04 +0200 Subject: [PATCH] use a sorted list for bookmarks --- completion.c | 2 -- database-sqlite.c | 10 +++++----- zathura.c | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/completion.c b/completion.c index 768cd1c..72bf1f0 100644 --- a/completion.c +++ b/completion.c @@ -159,8 +159,6 @@ cc_bookmarks(girara_session_t* session, const char* input) } const size_t input_length = input ? strlen(input) : 0; - girara_list_sort(zathura->bookmarks.bookmarks, (girara_compare_function_t) g_strcmp0); - 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); diff --git a/database-sqlite.c b/database-sqlite.c index 8801df2..61e698b 100644 --- a/database-sqlite.c +++ b/database-sqlite.c @@ -97,7 +97,7 @@ prepare_statement(sqlite3* session, const char* statement) const char* pz_tail = NULL; sqlite3_stmt* pp_stmt = NULL; - if (sqlite3_prepare(session, statement, -1, &pp_stmt, &pz_tail) != SQLITE_OK) { + if (sqlite3_prepare_v2(session, statement, -1, &pp_stmt, &pz_tail) != SQLITE_OK) { girara_error("Failed to prepare query: %s", statement); sqlite3_finalize(pp_stmt); return NULL; @@ -134,7 +134,7 @@ zathura_db_add_bookmark(zathura_database_t* db, const char* file, int res = sqlite3_step(stmt); sqlite3_finalize(stmt); - return res == SQLITE_OK; + return res == SQLITE_DONE; } bool @@ -144,7 +144,7 @@ zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const char* g_return_val_if_fail(db && file && id, false); static const char SQL_BOOKMARK_ADD[] = - "DELETE FROM bookmarks WHERE file = ? && id = ?;"; + "DELETE FROM bookmarks WHERE file = ? AND id = ?;"; sqlite3_stmt* stmt = prepare_statement(db->session, SQL_BOOKMARK_ADD); if (stmt == NULL) { @@ -160,7 +160,7 @@ zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const char* int res = sqlite3_step(stmt); sqlite3_finalize(stmt); - return res == SQLITE_OK; + return res == SQLITE_DONE; } girara_list_t* @@ -229,7 +229,7 @@ zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned int int res = sqlite3_step(stmt); sqlite3_finalize(stmt); - return res == SQLITE_OK; + return res == SQLITE_DONE; } bool diff --git a/zathura.c b/zathura.c index afab9a7..f7ede62 100644 --- a/zathura.c +++ b/zathura.c @@ -211,8 +211,8 @@ zathura_init(int argc, char* argv[]) } /* bookmarks */ - zathura->bookmarks.bookmarks = girara_list_new(); - girara_list_set_free_function(zathura->bookmarks.bookmarks, (girara_free_function_t) zathura_bookmark_free); + zathura->bookmarks.bookmarks = girara_sorted_list_new2((girara_compare_function_t) g_strcmp0, + (girara_free_function_t) zathura_bookmark_free); /* open document if passed */ if (argc > 1) {