Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
pwmt
zathura
Commits
f57fe5df
Commit
f57fe5df
authored
Apr 18, 2011
by
Sebastian Ramacher
Browse files
update document.c/.h
parent
daa523aa
Changes
6
Hide whitespace changes
Inline
Side-by-side
config.h
View file @
f57fe5df
...
@@ -7,6 +7,8 @@
...
@@ -7,6 +7,8 @@
/**
/**
* This function loads the default values of the configuration
* This function loads the default values of the configuration
*
* @param zathura the zathura session
*/
*/
void
config_load_default
(
zathura_t
*
zathura
);
void
config_load_default
(
zathura_t
*
zathura
);
...
...
document.c
View file @
f57fe5df
...
@@ -18,10 +18,8 @@
...
@@ -18,10 +18,8 @@
#define LENGTH(x) (sizeof(x)/sizeof((x)[0]))
#define LENGTH(x) (sizeof(x)/sizeof((x)[0]))
zathura_document_plugin_t
*
zathura_document_plugins
=
NULL
;
void
void
zathura_document_plugins_load
(
void
)
zathura_document_plugins_load
(
zathura_t
*
zathura
)
{
{
/* read all files in the plugin directory */
/* read all files in the plugin directory */
DIR
*
dir
=
opendir
(
PLUGIN_DIR
);
DIR
*
dir
=
opendir
(
PLUGIN_DIR
);
...
@@ -76,7 +74,7 @@ zathura_document_plugins_load(void)
...
@@ -76,7 +74,7 @@ zathura_document_plugins_load(void)
register_plugin
(
plugin
);
register_plugin
(
plugin
);
bool
r
=
zathura_document_plugin_register
(
plugin
,
handle
);
bool
r
=
zathura_document_plugin_register
(
zathura
,
plugin
,
handle
);
if
(
r
==
false
)
{
if
(
r
==
false
)
{
fprintf
(
stderr
,
"error: could not register plugin (%s)
\n
"
,
path
);
fprintf
(
stderr
,
"error: could not register plugin (%s)
\n
"
,
path
);
...
@@ -107,60 +105,54 @@ error_continue:
...
@@ -107,60 +105,54 @@ error_continue:
}
}
void
void
zathura_document_plugins_free
(
void
)
zathura_document_plugins_free
(
zathura_t
*
zathura
)
{
{
/* free registered plugins */
if
(
zathura
==
NULL
)
{
zathura_document_plugin_t
*
plugin
=
zathura_document_plugins
;
return
;
while
(
plugin
)
{
zathura_document_plugin_t
*
tmp
=
plugin
->
next
;
free
(
plugin
->
file_extension
);
free
(
plugin
);
plugin
=
tmp
;
}
}
zathura_document_plugins
=
NULL
;
girara_list_iterator_t
*
iter
=
girara_list_iterator
(
zathura
->
plugins
.
plugins
);
if
(
iter
==
NULL
)
{
return
;
}
do
{
zathura_document_plugin_t
*
plugin
=
(
zathura_document_plugin_t
*
)
girara_list_iterator_data
(
iter
);
free
(
plugin
->
file_extension
);
free
(
plugin
);
}
while
(
girara_list_iterator_next
(
iter
));
girara_list_iterator_free
(
iter
);
}
}
bool
bool
zathura_document_plugin_register
(
zathura_document_plugin_t
*
new_plugin
,
void
*
handle
)
zathura_document_plugin_register
(
zathura_t
*
zathura
,
zathura_document_plugin_t
*
new_plugin
,
void
*
handle
)
{
{
if
(
(
new_plugin
==
NULL
)
||
(
new_plugin
->
file_extension
==
NULL
)
||
(
new_plugin
->
open_function
==
NULL
)
if
(
(
new_plugin
==
NULL
)
||
(
new_plugin
->
file_extension
==
NULL
)
||
(
new_plugin
->
open_function
==
NULL
)
||
(
handle
==
NULL
)
)
{
||
(
handle
==
NULL
)
)
{
fprintf
(
stderr
,
"plugin: could not register
\n
"
);
girara_error
(
"plugin: could not register
\n
"
);
return
false
;
return
false
;
}
}
/* search existing plugins */
/* search existing plugins */
zathura_document_plugin_t
*
plugin
=
zathura_document_plugins
;
girara_list_iterator_t
*
iter
=
girara_list_iterator
(
zathura
->
plugins
.
plugins
);
while
(
plugin
)
{
if
(
iter
)
{
if
(
!
strcmp
(
plugin
->
file_extension
,
new_plugin
->
file_extension
))
{
do
{
fprintf
(
stderr
,
"plugin: already registered for filetype %s
\n
"
,
plugin
->
file_extension
);
zathura_document_plugin_t
*
plugin
=
(
zathura_document_plugin_t
*
)
girara_list_iterator_data
(
iter
);
return
false
;
if
(
!
strcmp
(
plugin
->
file_extension
,
new_plugin
->
file_extension
))
{
}
girara_error
(
"plugin: already registered for filetype %s
\n
"
,
plugin
->
file_extension
);
girara_list_iterator_free
(
iter
);
if
(
plugin
->
next
==
NULL
)
{
return
false
;
break
;
}
}
}
while
(
girara_list_iterator_next
(
iter
));
girara_list_iterator_free
(
iter
);
plugin
=
plugin
->
next
;
}
}
girara_list_append
(
zathura
->
plugins
.
plugins
,
new_plugin
);
/* create new plugin */
new_plugin
->
handle
=
handle
;
new_plugin
->
next
=
NULL
;
/* append to list */
if
(
plugin
==
NULL
)
{
zathura_document_plugins
=
new_plugin
;
}
else
{
plugin
->
next
=
new_plugin
;
}
return
true
;
return
true
;
}
}
zathura_document_t
*
zathura_document_t
*
zathura_document_open
(
const
char
*
path
,
const
char
*
password
)
zathura_document_open
(
zathura_t
*
zathura
,
const
char
*
path
,
const
char
*
password
)
{
{
if
(
!
path
)
{
if
(
!
path
)
{
goto
error_out
;
goto
error_out
;
...
@@ -224,14 +216,19 @@ zathura_document_open(const char* path, const char* password)
...
@@ -224,14 +216,19 @@ zathura_document_open(const char* path, const char* password)
document
->
functions
.
page_form_fields_get
=
NULL
;
document
->
functions
.
page_form_fields_get
=
NULL
;
document
->
functions
.
page_render
=
NULL
;
document
->
functions
.
page_render
=
NULL
;
/* init plugin with associated file type */
girara_list_iterator_t
*
iter
=
girara_list_iterator
(
zathura
->
plugins
.
plugins
);
zathura_document_plugin_t
*
plugin
=
zathura_document_plugins
;
if
(
iter
==
NULL
)
{
while
(
plugin
)
{
return
;
}
do
{
zathura_document_plugin_t
*
plugin
=
(
zathura_document_plugin_t
*
)
girara_list_iterator_data
(
iter
);
if
(
!
strcmp
(
file_extension
,
plugin
->
file_extension
))
{
if
(
!
strcmp
(
file_extension
,
plugin
->
file_extension
))
{
girara_list_iterator_free
(
iter
);
if
(
plugin
->
open_function
)
{
if
(
plugin
->
open_function
)
{
if
(
plugin
->
open_function
(
document
))
{
if
(
plugin
->
open_function
(
document
))
{
/* update statusbar */
/* update statusbar */
girara_statusbar_item_set_text
(
Z
athura
.
UI
.
session
,
Z
athura
.
UI
.
statusbar
.
file
,
real_path
);
girara_statusbar_item_set_text
(
z
athura
->
ui
.
session
,
z
athura
->
ui
.
statusbar
.
file
,
real_path
);
/* read all pages */
/* read all pages */
document
->
pages
=
calloc
(
document
->
number_of_pages
,
sizeof
(
zathura_page_t
*
));
document
->
pages
=
calloc
(
document
->
number_of_pages
,
sizeof
(
zathura_page_t
*
));
...
@@ -250,16 +247,15 @@ zathura_document_open(const char* path, const char* password)
...
@@ -250,16 +247,15 @@ zathura_document_open(const char* path, const char* password)
return
document
;
return
document
;
}
else
{
}
else
{
fprintf
(
stderr
,
"
error
:
could not open file
\n
"
);
girara_
error
(
"
could not open file
\n
"
);
goto
error_free
;
goto
error_free
;
}
}
}
}
}
}
}
while
(
girara_list_iterator_next
(
iter
));
girara_list_iterator_free
(
iter
);
plugin
=
plugin
->
next
;
girara_error
(
"unknown file type
\n
"
);
}
fprintf
(
stderr
,
"error: unknown file type
\n
"
);
error_free:
error_free:
...
...
document.h
View file @
f57fe5df
...
@@ -7,12 +7,13 @@
...
@@ -7,12 +7,13 @@
#include <stdbool.h>
#include <stdbool.h>
#include <girara-datastructures.h>
#include <girara-datastructures.h>
#include "zathura.h"
#define PLUGIN_DIR "/usr/lib/zathura"
#define PLUGIN_DIR "/usr/lib/zathura"
#define PLUGIN_REGISTER_FUNCTION "plugin_register"
#define PLUGIN_REGISTER_FUNCTION "plugin_register"
typedef
struct
zathura_list_s
zathura_list_t
;
typedef
struct
zathura_list_s
zathura_list_t
;
typedef
struct
zathura_document_s
zathura_document_t
;
//
typedef struct zathura_document_s zathura_document_t;
typedef
bool
(
*
zathura_document_open_t
)(
zathura_document_t
*
document
);
typedef
bool
(
*
zathura_document_open_t
)(
zathura_document_t
*
document
);
...
@@ -24,7 +25,6 @@ typedef struct zathura_document_plugin_s
...
@@ -24,7 +25,6 @@ typedef struct zathura_document_plugin_s
char
*
file_extension
;
/**> File extension */
char
*
file_extension
;
/**> File extension */
zathura_document_open_t
open_function
;
/**> Document open function */
zathura_document_open_t
open_function
;
/**> Document open function */
void
*
handle
;
/**> DLL handle */
void
*
handle
;
/**> DLL handle */
struct
zathura_document_plugin_s
*
next
;
/**> Next plugin */
// TODO: Use list_t
}
zathura_document_plugin_t
;
}
zathura_document_plugin_t
;
/**
/**
...
@@ -139,7 +139,7 @@ typedef struct zathura_form_s
...
@@ -139,7 +139,7 @@ typedef struct zathura_form_s
/**
/**
* Page
* Page
*/
*/
typedef
struct
zathura_page_s
struct
zathura_page_s
{
{
double
height
;
/**> Page height */
double
height
;
/**> Page height */
double
width
;
/**> Page width */
double
width
;
/**> Page width */
...
@@ -150,7 +150,7 @@ typedef struct zathura_page_s
...
@@ -150,7 +150,7 @@ typedef struct zathura_page_s
GtkWidget
*
event_box
;
/**> Widget wrapper for mouse events */
GtkWidget
*
event_box
;
/**> Widget wrapper for mouse events */
GtkWidget
*
drawing_area
;
/**> Drawing area */
GtkWidget
*
drawing_area
;
/**> Drawing area */
GStaticMutex
lock
;
/**> Lock */
GStaticMutex
lock
;
/**> Lock */
}
zathura_page_t
;
};
/**
/**
* Document
* Document
...
@@ -226,18 +226,22 @@ struct zathura_document_s
...
@@ -226,18 +226,22 @@ struct zathura_document_s
/**
/**
* Load all document plugins
* Load all document plugins
*
* @param zathura the zathura session
*/
*/
void
zathura_document_plugins_load
(
void
);
void
zathura_document_plugins_load
(
zathura_t
*
zathura
);
/**
/**
* Free all document plugins
* Free all document plugins
*
* @param zathura the zathura session
*/
*/
void
zathura_document_plugins_free
(
void
);
void
zathura_document_plugins_free
(
zathura_t
*
zathura
);
/**
/**
* Register document plugin
* Register document plugin
*/
*/
bool
zathura_document_plugin_register
(
zathura_document_plugin_t
*
new_plugin
,
void
*
handle
);
bool
zathura_document_plugin_register
(
zathura_t
*
zathura
,
zathura_document_plugin_t
*
new_plugin
,
void
*
handle
);
/**
/**
* Open the document
* Open the document
...
@@ -246,7 +250,7 @@ bool zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, voi
...
@@ -246,7 +250,7 @@ bool zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, voi
* @param password Password of the document or NULL
* @param password Password of the document or NULL
* @return The document object
* @return The document object
*/
*/
zathura_document_t
*
zathura_document_open
(
const
char
*
path
,
const
char
*
password
);
zathura_document_t
*
zathura_document_open
(
zathura_t
*
zathura
,
const
char
*
path
,
const
char
*
password
);
/**
/**
* Free the document
* Free the document
...
...
render.h
View file @
f57fe5df
...
@@ -7,16 +7,16 @@
...
@@ -7,16 +7,16 @@
#include <stdlib.h>
#include <stdlib.h>
#include <girara-datastructures.h>
#include <girara-datastructures.h>
#include "
document
.h"
#include "
zathura
.h"
#include "callbacks.h"
#include "callbacks.h"
typedef
struct
render_thread_s
struct
render_thread_s
{
{
girara_list_t
*
list
;
/**> The list of pages */
girara_list_t
*
list
;
/**> The list of pages */
GThread
*
thread
;
/**> The thread object */
GThread
*
thread
;
/**> The thread object */
GMutex
*
lock
;
/**> Lock */
GMutex
*
lock
;
/**> Lock */
GCond
*
cond
;
/**> Condition */
GCond
*
cond
;
/**> Condition */
}
render_thread_t
;
};
/**
/**
* This function initializes a render thread
* This function initializes a render thread
...
...
zathura.c
View file @
f57fe5df
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include "shortcuts.h"
#include "shortcuts.h"
#include "zathura.h"
#include "zathura.h"
#include "utils.h"
#include "utils.h"
#include "render.h"
/* function implementation */
/* function implementation */
zathura_t
*
zathura_t
*
...
@@ -21,6 +22,10 @@ zathura_init(int argc, char* argv[])
...
@@ -21,6 +22,10 @@ zathura_init(int argc, char* argv[])
return
NULL
;
return
NULL
;
}
}
/* plugins */
zathura
->
plugins
.
plugins
=
girara_list_new
();
zathura
->
plugins
.
path
=
NULL
;
/* UI */
/* UI */
if
((
zathura
->
ui
.
session
=
girara_session_create
())
==
NULL
)
{
if
((
zathura
->
ui
.
session
=
girara_session_create
())
==
NULL
)
{
goto
error_out
;
goto
error_out
;
...
@@ -74,7 +79,7 @@ zathura_init(int argc, char* argv[])
...
@@ -74,7 +79,7 @@ zathura_init(int argc, char* argv[])
zathura
->
ui
.
session
->
events
.
buffer_changed
=
buffer_changed
;
zathura
->
ui
.
session
->
events
.
buffer_changed
=
buffer_changed
;
/* load plugins */
/* load plugins */
zathura_document_plugins_load
();
zathura_document_plugins_load
(
zathura
);
/* configuration */
/* configuration */
config_load_default
(
zathura
);
config_load_default
(
zathura
);
...
@@ -108,7 +113,7 @@ zathura_free(zathura_t* zathura)
...
@@ -108,7 +113,7 @@ zathura_free(zathura_t* zathura)
document_close
(
zathura
);
document_close
(
zathura
);
/* free registered plugins */
/* free registered plugins */
zathura_document_plugins_free
();
zathura_document_plugins_free
(
zathura
);
}
}
bool
bool
...
@@ -118,7 +123,7 @@ document_open(zathura_t* zathura, const char* path, const char* password)
...
@@ -118,7 +123,7 @@ document_open(zathura_t* zathura, const char* path, const char* password)
goto
error_out
;
goto
error_out
;
}
}
zathura_document_t
*
document
=
zathura_document_open
(
path
,
password
);
zathura_document_t
*
document
=
zathura_document_open
(
zathura
,
path
,
password
);
if
(
!
document
)
{
if
(
!
document
)
{
goto
error_out
;
goto
error_out
;
...
...
zathura.h
View file @
f57fe5df
...
@@ -6,9 +6,6 @@
...
@@ -6,9 +6,6 @@
#include <stdbool.h>
#include <stdbool.h>
#include <girara.h>
#include <girara.h>
#include "render.h"
#include "document.h"
enum
{
NEXT
,
PREVIOUS
,
LEFT
,
RIGHT
,
UP
,
DOWN
,
BOTTOM
,
TOP
,
HIDE
,
HIGHLIGHT
,
enum
{
NEXT
,
PREVIOUS
,
LEFT
,
RIGHT
,
UP
,
DOWN
,
BOTTOM
,
TOP
,
HIDE
,
HIGHLIGHT
,
DELETE_LAST_WORD
,
DELETE_LAST_CHAR
,
DEFAULT
,
ERROR
,
WARNING
,
NEXT_GROUP
,
DELETE_LAST_WORD
,
DELETE_LAST_CHAR
,
DEFAULT
,
ERROR
,
WARNING
,
NEXT_GROUP
,
PREVIOUS_GROUP
,
ZOOM_IN
,
ZOOM_OUT
,
ZOOM_ORIGINAL
,
ZOOM_SPECIFIC
,
FORWARD
,
PREVIOUS_GROUP
,
ZOOM_IN
,
ZOOM_OUT
,
ZOOM_ORIGINAL
,
ZOOM_SPECIFIC
,
FORWARD
,
...
@@ -24,6 +21,16 @@ enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT,
...
@@ -24,6 +21,16 @@ enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT,
#define NORMAL (1 << 3)
#define NORMAL (1 << 3)
#define INSERT (1 << 4)
#define INSERT (1 << 4)
/* forward declaration for types from document.h */
struct
zathura_document_s
;
struct
zathura_page_s
;
typedef
struct
zathura_document_s
zathura_document_t
;
typedef
struct
zathura_page_s
zathura_page_t
;
/* forward declaration for types from render.h */
struct
render_thread_s
;
typedef
struct
render_thread_s
render_thread_t
;
typedef
struct
zathura_s
typedef
struct
zathura_s
{
{
struct
struct
...
@@ -46,6 +53,12 @@ typedef struct zathura_s
...
@@ -46,6 +53,12 @@ typedef struct zathura_s
render_thread_t
*
render_thread
;
/**> The thread responsible for rendering the pages */
render_thread_t
*
render_thread
;
/**> The thread responsible for rendering the pages */
}
sync
;
}
sync
;
struct
{
girara_list_t
*
plugins
;
girara_list_t
*
path
;
}
plugins
;
zathura_document_t
*
document
;
/**> The current document */
zathura_document_t
*
document
;
/**> The current document */
}
zathura_t
;
}
zathura_t
;
...
...
Write
Preview
Supports
Markdown
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