Factor out bookmark list creation

This commit is contained in:
Sebastian Ramacher 2018-03-04 15:45:22 +01:00
parent 8c245cd254
commit 5d898adda6
4 changed files with 29 additions and 5 deletions

View file

@ -397,9 +397,7 @@ plain_load_bookmarks(zathura_database_t* db, const char* file)
return NULL; return NULL;
} }
girara_list_t* result = girara_sorted_list_new2((girara_compare_function_t) girara_list_t* result = bookmarks_list_new();
zathura_bookmarks_compare, (girara_free_function_t)
zathura_bookmark_free);
gsize num_keys; gsize num_keys;
char** keys = g_key_file_get_keys(priv->bookmarks, name, &num_keys, NULL); char** keys = g_key_file_get_keys(priv->bookmarks, name, &num_keys, NULL);

View file

@ -471,8 +471,7 @@ sqlite_load_bookmarks(zathura_database_t* db, const char* file)
return NULL; return NULL;
} }
girara_list_t* result = girara_sorted_list_new2((girara_compare_function_t) zathura_bookmarks_compare, girara_list_t* result = bookmarks_list_new();
(girara_free_function_t) zathura_bookmark_free);
if (result == NULL) { if (result == NULL) {
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return NULL; return NULL;

View file

@ -76,3 +76,24 @@ zathura_db_get_recent_files(zathura_database_t* db, int max, const char* basepat
return ZATHURA_DATABASE_GET_INTERFACE(db)->get_recent_files(db, max, basepath); return ZATHURA_DATABASE_GET_INTERFACE(db)->get_recent_files(db, max, basepath);
} }
static int
bookmarks_compare(const void* l, const void* r)
{
const zathura_bookmark_t* lhs = l;
const zathura_bookmark_t* rhs = r;
return zathura_bookmarks_compare(lhs, rhs);
}
static void
bookmarks_free(void* p)
{
zathura_bookmark_t* bookmark = p;
zathura_bookmark_free(bookmark);
}
girara_list_t* bookmarks_list_new(void)
{
return girara_sorted_list_new2(bookmarks_compare, bookmarks_free);
}

View file

@ -140,5 +140,11 @@ bool zathura_db_get_fileinfo(zathura_database_t* db, const char* file,
*/ */
girara_list_t* zathura_db_get_recent_files(zathura_database_t* db, int max, const char* basepath); girara_list_t* zathura_db_get_recent_files(zathura_database_t* db, int max, const char* basepath);
/**
* Create list of bookmarks.
* @return empty list of bookmarks
*/
girara_list_t* bookmarks_list_new(void);
#endif // DATABASE_H #endif // DATABASE_H