use the correct sorting function

This commit is contained in:
Sebastian Ramacher 2011-10-15 18:42:30 +02:00
parent 09041f7d78
commit 712e4bd408
5 changed files with 28 additions and 4 deletions

View file

@ -97,3 +97,18 @@ zathura_bookmarks_load(zathura_t* zathura, const gchar* file) {
return true;
}
int
zathura_bookmarks_compare(zathura_bookmark_t* lhs, zathura_bookmark_t* rhs)
{
if (lhs == NULL && rhs == NULL) {
return 0;
}
if (lhs == NULL) {
return -1;
}
if (rhs == NULL) {
return 1;
}
return g_strcmp0(lhs->id, rhs->id);
}

View file

@ -53,4 +53,12 @@ void zathura_bookmark_free(zathura_bookmark_t* bookmark);
*/
bool zathura_bookmarks_load(zathura_t* zathura, const gchar* file);
/**
* Compare two bookmarks.
* @param lhs a bookmark
* @param rhs a bookmark
* @returns g_strcmp0(lhs->id, rhs->id)
*/
int zathura_bookmarks_compare(zathura_bookmark_t* lhs, zathura_bookmark_t* rhs);
#endif // BOOKMARKS_H

View file

@ -194,7 +194,8 @@ zathura_db_load_bookmarks(zathura_database_t* db, const char* file)
return NULL;
}
girara_list_t* result = girara_list_new();
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) {
return NULL;
}

View file

@ -182,12 +182,12 @@ zathura_db_load_bookmarks(zathura_database_t* db, const char* file)
return NULL;
}
girara_list_t* result = girara_list_new();
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;
}
girara_list_set_free_function(result, (girara_free_function_t) zathura_bookmark_free);
while (sqlite3_step(stmt) == SQLITE_ROW) {
zathura_bookmark_t* bookmark = g_malloc0(sizeof(zathura_bookmark_t));

View file

@ -211,7 +211,7 @@ zathura_init(int argc, char* argv[])
}
/* bookmarks */
zathura->bookmarks.bookmarks = girara_sorted_list_new2((girara_compare_function_t) g_strcmp0,
zathura->bookmarks.bookmarks = girara_sorted_list_new2((girara_compare_function_t) zathura_bookmarks_compare,
(girara_free_function_t) zathura_bookmark_free);
/* open document if passed */