Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
pwmt
zathura
Commits
a6596fb9
Commit
a6596fb9
authored
Sep 01, 2011
by
Sebastian Ramacher
Browse files
initial bookmarks implementation
parent
bb466fc8
Changes
4
Hide whitespace changes
Inline
Side-by-side
bookmarks.c
0 → 100644
View file @
a6596fb9
/* See LICENSE file for license and copyright information */
#include <string.h>
#include "bookmarks.h"
zathura_bookmark_t
*
zathura_bookmark_add
(
zathura_t
*
zathura
,
const
gchar
*
id
,
unsigned
int
page
)
{
g_return_val_if_fail
(
zathura
&&
zathura
->
bookmarks
.
bookmarks
,
NULL
);
g_return_val_if_fail
(
id
,
NULL
);
GIRARA_LIST_FOREACH
(
zathura
->
bookmarks
.
bookmarks
,
zathura_bookmark_t
*
,
iter
,
bookmark
)
if
(
strcmp
(
bookmark
->
id
,
id
)
==
0
)
{
girara_list_iterator_free
(
iter
);
return
NULL
;
}
GIRARA_LIST_FOREACH_END
(
zathura
->
bookmarks
.
bookmarks
,
zathura_bookmark_t
*
,
iter
,
bookmark
)
zathura_bookmark_t
*
bookmark
=
g_malloc0
(
sizeof
(
zathura_bookmark_t
));
bookmark
->
id
=
g_strdup
(
id
);
bookmark
->
page
=
page
;
girara_list_append
(
zathura
->
bookmarks
.
bookmarks
,
bookmark
);
return
bookmark
;
}
void
zathura_bookmark_remove
(
zathura_t
*
zathura
,
const
gchar
*
id
)
{
g_return_if_fail
(
zathura
&&
zathura
->
bookmarks
.
bookmarks
);
g_return_if_fail
(
id
);
zathura_bookmark_t
*
bookmark
=
zathura_bookmark_get
(
zathura
,
id
);
if
(
bookmark
)
{
girara_list_remove
(
zathura
->
bookmarks
.
bookmarks
,
bookmark
);
}
}
zathura_bookmark_t
*
zathura_bookmark_get
(
zathura_t
*
zathura
,
const
gchar
*
id
)
{
g_return_val_if_fail
(
zathura
&&
zathura
->
bookmarks
.
bookmarks
,
NULL
);
g_return_val_if_fail
(
id
,
NULL
);
GIRARA_LIST_FOREACH
(
zathura
->
bookmarks
.
bookmarks
,
zathura_bookmark_t
*
,
iter
,
bookmark
)
if
(
strcmp
(
bookmark
->
id
,
id
)
==
0
)
{
girara_list_iterator_free
(
iter
);
return
bookmark
;
}
GIRARA_LIST_FOREACH_END
(
zathura
->
bookmarks
.
bookmarks
,
zathura_bookmark_t
*
,
iter
,
bookmark
)
return
NULL
;
}
void
zathura_bookmark_free
(
zathura_bookmark_t
*
bookmark
)
{
if
(
!
bookmark
)
{
return
;
}
g_free
(
bookmark
->
id
);
g_free
(
bookmark
);
}
bookmarks.h
0 → 100644
View file @
a6596fb9
/* See LICENSE file for license and copyright information */
#ifndef BOOKMARKS_H
#define BOOKMARKS_H
#include <stdbool.h>
#include "zathura.h"
struct
zathura_bookmark_s
{
gchar
*
id
;
unsigned
int
page
;
};
typedef
struct
zathura_bookmark_s
zathura_bookmark_t
;
zathura_bookmark_t
*
zathura_bookmark_add
(
zathura_t
*
zathura
,
const
gchar
*
id
,
unsigned
int
page
);
void
zathura_bookmark_remove
(
zathura_t
*
zathura
,
const
gchar
*
id
);
zathura_bookmark_t
*
zathura_bookmark_get
(
zathura_t
*
zathura
,
const
gchar
*
id
);
void
zathura_bookmark_free
(
zathura_bookmark_t
*
bookmark
);
bool
zathura_bookmarks_load
(
zathura_t
*
zathura
,
const
gchar
*
file
);
bool
zathura_bookmarks_save
(
zathura_t
*
zathura
,
const
gchar
*
file
);
#endif // BOOKMARKS_H
zathura.c
View file @
a6596fb9
...
...
@@ -4,6 +4,7 @@
#include <girara.h>
#include "bookmarks.h"
#include "callbacks.h"
#include "config.h"
#include "document.h"
...
...
@@ -189,6 +190,10 @@ zathura_init(int argc, char* argv[])
free
(
string_value
);
}
/* bookmarks */
zathura
->
bookmarks
.
bookmarks
=
girara_list_new
();
girara_list_set_free_function
(
zathura
->
bookmarks
.
bookmarks
,
(
girara_free_function_t
)
zathura_bookmark_free
);
/* open document if passed */
if
(
argc
>
1
)
{
zathura_document_info_t
*
document_info
=
malloc
(
sizeof
(
zathura_document_info_t
));
...
...
@@ -231,6 +236,9 @@ zathura_free(zathura_t* zathura)
document_close
(
zathura
);
/* bookmarks */
girara_list_free
(
zathura
->
bookmarks
.
bookmarks
);
/* free print settings */
g_object_unref
(
zathura
->
print
.
settings
);
g_object_unref
(
zathura
->
print
.
page_setup
);
...
...
zathura.h
View file @
a6596fb9
...
...
@@ -84,6 +84,12 @@ typedef struct zathura_s
girara_mode_t
insert
;
/**> Insert mode */
}
modes
;
struct
{
gchar
*
file
;
/**> bookmarks file */
girara_list_t
*
bookmarks
;
/**> bookmarks */
}
bookmarks
;
zathura_document_t
*
document
;
/**> The current document */
}
zathura_t
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment