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
7629a30a
Commit
7629a30a
authored
Mar 05, 2011
by
Moritz Lipp
Browse files
Register document plugin and free registered plugins
parent
ef394442
Changes
9
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
7629a30a
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
include
config.mk
include
config.mk
PROJECT
=
zathura
PROJECT
=
zathura
SOURCE
=
$(
shell
find
.
-iname
"*.c"
-a
!
-iwholename
"*./doc*"
)
SOURCE
=
$(
shell
find
.
-iname
"*.c"
-a
!
-iwholename
"*./doc*
|*./ft*
"
)
OBJECTS
=
$(
patsubst
%.c, %.o,
$(SOURCE)
)
OBJECTS
=
$(
patsubst
%.c, %.o,
$(SOURCE)
)
DOBJECTS
=
$(
patsubst
%.c, %.do,
$(SOURCE)
)
DOBJECTS
=
$(
patsubst
%.c, %.do,
$(SOURCE)
)
...
...
callbacks.c
View file @
7629a30a
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#include "zathura.h"
#include "zathura.h"
#include "render.h"
#include "render.h"
#include "
ft/
document.h"
#include "document.h"
gboolean
gboolean
cb_destroy
(
GtkWidget
*
widget
,
gpointer
data
)
cb_destroy
(
GtkWidget
*
widget
,
gpointer
data
)
...
@@ -18,6 +18,9 @@ cb_destroy(GtkWidget* widget, gpointer data)
...
@@ -18,6 +18,9 @@ cb_destroy(GtkWidget* widget, gpointer data)
document_close
();
document_close
();
/* free registered plugins */
zathura_document_plugin_free
();
return
TRUE
;
return
TRUE
;
}
}
...
...
ft/
document.c
→
document.c
View file @
7629a30a
...
@@ -10,17 +10,70 @@
...
@@ -10,17 +10,70 @@
#include <limits.h>
#include <limits.h>
#include "document.h"
#include "document.h"
#include "pdf/pdf.h"
#include "utils.h"
#include "djvu/djvu.h"
#include "zathura.h"
#include "../utils.h"
#include "../zathura.h"
#define LENGTH(x) (sizeof(x)/sizeof((x)[0]))
#define LENGTH(x) (sizeof(x)/sizeof((x)[0]))
zathura_document_plugin_t
zathura_document_plugins
[]
=
{
zathura_document_plugin_t
*
zathura_document_plugins
=
NULL
;
{
"pdf"
,
pdf_document_open
},
{
"djvu"
,
djvu_document_open
},
bool
};
zathura_document_register_plugin
(
char
*
file_extension
,
zathura_document_open_t
open_function
)
{
if
(
(
file_extension
==
NULL
)
||
(
open_function
==
NULL
)
)
{
fprintf
(
stderr
,
"plugin: could not register
\n
"
);
return
false
;
}
/* search existing plugins */
zathura_document_plugin_t
*
plugin
=
zathura_document_plugins
;
while
(
plugin
)
{
if
(
!
strcmp
(
plugin
->
file_extension
,
file_extension
))
{
fprintf
(
stderr
,
"plugin: already registered for filetype %s
\n
"
,
file_extension
);
return
false
;
}
if
(
plugin
->
next
==
NULL
)
{
break
;
}
plugin
=
plugin
->
next
;
}
/* create new plugin */
zathura_document_plugin_t
*
new_plugin
=
malloc
(
sizeof
(
zathura_document_plugin_t
));
if
(
new_plugin
==
NULL
)
{
return
false
;
}
new_plugin
->
file_extension
=
file_extension
;
new_plugin
->
open_function
=
open_function
;
new_plugin
->
next
=
NULL
;
/* append to list */
if
(
plugin
==
NULL
)
{
zathura_document_plugins
=
new_plugin
;
}
else
{
plugin
->
next
=
new_plugin
;
}
return
true
;
}
void
zathura_document_plugin_free
(
void
)
{
/* free registered plugins */
zathura_document_plugin_t
*
plugin
=
zathura_document_plugins
;
while
(
plugin
)
{
zathura_document_plugin_t
*
tmp
=
plugin
->
next
;
free
(
plugin
);
plugin
=
tmp
;
}
zathura_document_plugins
=
NULL
;
}
zathura_document_t
*
zathura_document_t
*
zathura_document_open
(
const
char
*
path
,
const
char
*
password
)
zathura_document_open
(
const
char
*
path
,
const
char
*
password
)
...
@@ -88,11 +141,11 @@ zathura_document_open(const char* path, const char* password)
...
@@ -88,11 +141,11 @@ zathura_document_open(const char* path, const char* password)
document
->
functions
.
page_render
=
NULL
;
document
->
functions
.
page_render
=
NULL
;
/* init plugin with associated file type */
/* init plugin with associated file type */
for
(
unsigned
int
i
=
0
;
i
<
LENGTH
(
zathura_document_plugins
);
i
++
)
zathura_document_plugin_t
*
plugin
=
zathura_document_plugins
;
{
while
(
plugin
)
{
if
(
!
strcmp
(
file_extension
,
zathura_document_
plugin
s
[
i
].
file_extension
))
{
if
(
!
strcmp
(
file_extension
,
plugin
->
file_extension
))
{
if
(
zathura_document_
plugin
s
[
i
].
open_function
)
{
if
(
plugin
->
open_function
)
{
if
(
zathura_document_
plugin
s
[
i
].
open_function
(
document
))
{
if
(
plugin
->
open_function
(
document
))
{
/* update statusbar */
/* update statusbar */
girara_statusbar_item_set_text
(
Zathura
.
UI
.
session
,
Zathura
.
UI
.
statusbar
.
file
,
real_path
);
girara_statusbar_item_set_text
(
Zathura
.
UI
.
session
,
Zathura
.
UI
.
statusbar
.
file
,
real_path
);
...
@@ -122,6 +175,8 @@ zathura_document_open(const char* path, const char* password)
...
@@ -122,6 +175,8 @@ zathura_document_open(const char* path, const char* password)
}
}
}
}
}
}
plugin
=
plugin
->
next
;
}
}
fprintf
(
stderr
,
"error: unknown file type
\n
"
);
fprintf
(
stderr
,
"error: unknown file type
\n
"
);
...
...
ft/
document.h
→
document.h
View file @
7629a30a
...
@@ -15,8 +15,9 @@ typedef bool (*zathura_document_open_t)(zathura_document_t* document);
...
@@ -15,8 +15,9 @@ typedef bool (*zathura_document_open_t)(zathura_document_t* document);
typedef
struct
zathura_document_plugin_s
typedef
struct
zathura_document_plugin_s
{
{
const
char
*
file_extension
;
char
*
file_extension
;
zathura_document_open_t
open_function
;
zathura_document_open_t
open_function
;
struct
zathura_document_plugin_s
*
next
;
}
zathura_document_plugin_t
;
}
zathura_document_plugin_t
;
struct
zathura_list_s
struct
zathura_list_s
...
@@ -113,6 +114,9 @@ struct zathura_document_s
...
@@ -113,6 +114,9 @@ struct zathura_document_s
zathura_page_t
**
pages
;
zathura_page_t
**
pages
;
};
};
bool
zathura_document_plugin_register
(
char
*
file_extension
,
zathura_document_open_t
open_function
);
void
zathura_document_plugin_free
(
void
);
zathura_document_t
*
zathura_document_open
(
const
char
*
path
,
const
char
*
password
);
zathura_document_t
*
zathura_document_open
(
const
char
*
path
,
const
char
*
password
);
bool
zathura_document_free
(
zathura_document_t
*
document
);
bool
zathura_document_free
(
zathura_document_t
*
document
);
bool
zathura_document_save_as
(
zathura_document_t
*
document
,
const
char
*
path
);
bool
zathura_document_save_as
(
zathura_document_t
*
document
,
const
char
*
path
);
...
...
ft/djvu/djvu.h
View file @
7629a30a
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
#include <stdbool.h>
#include <stdbool.h>
#include <libdjvu/ddjvuapi.h>
#include <libdjvu/ddjvuapi.h>
#include "../document.h"
#include "../
../
document.h"
typedef
struct
djvu_document_s
typedef
struct
djvu_document_s
{
{
...
...
ft/pdf/pdf.h
View file @
7629a30a
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
#include <stdbool.h>
#include <stdbool.h>
#include <poppler.h>
#include <poppler.h>
#include "../document.h"
#include "../
../
document.h"
typedef
struct
pdf_document_s
typedef
struct
pdf_document_s
{
{
...
...
render.h
View file @
7629a30a
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#include <stdlib.h>
#include <stdlib.h>
#include <girara-datastructures.h>
#include <girara-datastructures.h>
#include "
ft/
document.h"
#include "document.h"
#include "callbacks.h"
#include "callbacks.h"
typedef
struct
render_thread_s
typedef
struct
render_thread_s
...
...
zathura.c
View file @
7629a30a
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
#include "callbacks.h"
#include "callbacks.h"
#include "config.h"
#include "config.h"
#include "
ft/
document.h"
#include "document.h"
#include "shortcuts.h"
#include "shortcuts.h"
#include "zathura.h"
#include "zathura.h"
#include "utils.h"
#include "utils.h"
...
...
zathura.h
View file @
7629a30a
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#include <girara.h>
#include <girara.h>
#include <render.h>
#include <render.h>
#include "
ft/
document.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
,
...
...
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