mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 13:05:59 +01:00
Init document, some changes
This commit is contained in:
parent
f1438f5f85
commit
4857d62fde
7 changed files with 151 additions and 17 deletions
|
@ -4,10 +4,63 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "document.h"
|
||||
#include "../utils.h"
|
||||
#include "pdf/pdf.h"
|
||||
|
||||
#define LENGTH(x) (sizeof(x)/sizeof((x)[0]))
|
||||
|
||||
zathura_document_plugin_t zathura_document_plugins[] = {
|
||||
{ "pdf", pdf_document_open },
|
||||
};
|
||||
|
||||
zathura_document_t*
|
||||
zathura_document_create(const char* path)
|
||||
zathura_document_open(const char* path, const char* password)
|
||||
{
|
||||
if(!path) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!file_exists(path)) {
|
||||
fprintf(stderr, "error: file does not exist\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* file_extension = file_get_extension(path);
|
||||
if(!file_extension) {
|
||||
fprintf(stderr, "error: could not determine file type\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
zathura_document_t* document = malloc(sizeof(zathura_document_t));
|
||||
if(!document) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
document->file_path = path;
|
||||
document->password = password;
|
||||
document->current_page_number = 0;
|
||||
document->number_of_pages = 0;
|
||||
document->scale = 100;
|
||||
document->rotate = 0;
|
||||
|
||||
document->functions.document_free = NULL;
|
||||
document->functions.document_index_generate = NULL;
|
||||
document->functions.document_save_as = NULL;
|
||||
document->functions.document_attachments_get = NULL;
|
||||
document->functions.page_get = NULL;
|
||||
document->functions.page_free = NULL;
|
||||
document->functions.page_search_text = NULL;
|
||||
document->functions.page_links_get = NULL;
|
||||
document->functions.page_form_fields_get = NULL;
|
||||
document->functions.page_render = NULL;
|
||||
|
||||
/* init plugin with associated file type */
|
||||
for(unsigned int i = 0; i < LENGTH(zathura_document_plugins); i++)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -23,7 +76,11 @@ zathura_document_free(zathura_document_t* document)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
return document->functions.document_free(document);
|
||||
bool r = document->functions.document_free(document);
|
||||
|
||||
free(document);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -86,7 +143,7 @@ zathura_document_attachments_free(zathura_list_t* list)
|
|||
zathura_page_t*
|
||||
zathura_page_get(zathura_document_t* document, unsigned int page)
|
||||
{
|
||||
if(!document) {
|
||||
if(!document || !page) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -98,6 +155,21 @@ zathura_page_get(zathura_document_t* document, unsigned int page)
|
|||
return document->functions.page_get(document, page);
|
||||
}
|
||||
|
||||
bool
|
||||
zathura_page_free(zathura_page_t* page)
|
||||
{
|
||||
if(!page || !page->document) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!page->document->functions.page_free) {
|
||||
fprintf(stderr, "error: %s not implemented\n", __FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
|
||||
return page->document->functions.page_free(page);
|
||||
}
|
||||
|
||||
zathura_list_t*
|
||||
zathura_page_search_text(zathura_page_t* page, const char* text)
|
||||
{
|
||||
|
|
|
@ -9,6 +9,14 @@
|
|||
typedef struct zathura_list_s zathura_list_t;
|
||||
typedef struct zathura_document_s zathura_document_t;
|
||||
|
||||
typedef bool (*zathura_document_open_t)(zathura_document_t* document);
|
||||
|
||||
typedef struct zathura_document_plugin_s
|
||||
{
|
||||
const char* file_type;
|
||||
zathura_document_open_t open_function;
|
||||
} zathura_document_plugin_t;
|
||||
|
||||
struct zathura_list_s
|
||||
{
|
||||
void* data;
|
||||
|
@ -62,8 +70,8 @@ typedef struct zathura_page_s
|
|||
|
||||
struct zathura_document_s
|
||||
{
|
||||
char* file_path;
|
||||
char* password;
|
||||
const char* file_path;
|
||||
const char* password;
|
||||
unsigned int current_page_number;
|
||||
unsigned int number_of_pages;
|
||||
int scale;
|
||||
|
@ -71,20 +79,21 @@ struct zathura_document_s
|
|||
|
||||
struct
|
||||
{
|
||||
bool (*document_free)(zathura_document_t* document);
|
||||
zathura_list_t* (*document_index_generate)(zathura_document_t* document);
|
||||
bool (*document_save_as)(zathura_document_t* document, const char* path);
|
||||
zathura_list_t* (*document_attachments_get)(zathura_document_t* document);
|
||||
|
||||
zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page);
|
||||
zathura_list_t* (*page_search_text)(zathura_page_t* page, const char* text);
|
||||
zathura_list_t* (*page_links_get)(zathura_page_t* page);
|
||||
zathura_list_t* (*page_form_fields_get)(zathura_page_t* page);
|
||||
cairo_surface_t* (*page_render)(zathura_page_t* page);
|
||||
|
||||
zathura_list_t* (*document_index_generate)(zathura_document_t* document);
|
||||
bool (*document_save_as)(zathura_document_t* document, const char* path);
|
||||
zathura_list_t* (*document_attachments_get)(zathura_document_t* document);
|
||||
bool (*document_free)(zathura_document_t* document);
|
||||
bool (*page_free)(zathura_page_t* page);
|
||||
} functions;
|
||||
};
|
||||
|
||||
zathura_document_t* zathura_document_create(const char* path);
|
||||
zathura_document_t* zathura_document_open(const char* path, const char* password);
|
||||
bool zathura_document_free(zathura_document_t* document);
|
||||
bool zathura_document_save_as(zathura_document_t* document, const char* path);
|
||||
zathura_list_t* zathura_document_index_generate(zathura_document_t* document);
|
||||
|
@ -93,6 +102,7 @@ zathura_list_t* zathura_document_attachments_get(zathura_document_t* document);
|
|||
bool zathura_document_attachments_free(zathura_list_t* list);
|
||||
|
||||
zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page);
|
||||
bool zathura_page_free(zathura_page_t* page);
|
||||
zathura_list_t* zathura_page_search_text(zathura_page_t* page, const char* text);
|
||||
zathura_list_t* zathura_page_links_get(zathura_page_t* page);
|
||||
bool zathura_page_links_free(zathura_list_t* list);
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
/* See LICENSE file for license and copyright information */
|
||||
|
||||
#include "pdf.h"
|
||||
|
||||
bool
|
||||
pdf_document_open(zathura_document_t* document)
|
||||
{
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
/* See LICENSE file for license and copyright information */
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "../document.h"
|
||||
|
||||
bool pdf_document_open(zathura_document_t* document);
|
22
utils.c
22
utils.c
|
@ -0,0 +1,22 @@
|
|||
/* See LICENSE file for license and copyright information */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
bool
|
||||
file_exists(const char* path)
|
||||
{
|
||||
if(!access(path, F_OK)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const char*
|
||||
file_get_extension(const char* path)
|
||||
{
|
||||
return NULL;
|
||||
}
|
5
utils.h
5
utils.h
|
@ -3,4 +3,9 @@
|
|||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool file_exists(const char* path);
|
||||
const char* file_get_extension(const char* path);
|
||||
|
||||
#endif // UTILS_H
|
||||
|
|
19
zathura.c
19
zathura.c
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "callbacks.h"
|
||||
#include "config.h"
|
||||
#include "ft/document.h"
|
||||
#include "shortcuts.h"
|
||||
#include "zathura.h"
|
||||
|
||||
|
@ -43,14 +44,22 @@ int main(int argc, char* argv[])
|
|||
gdk_threads_init();
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
if(!init_zathura()) {
|
||||
printf("error: coult not initialize zathura\n");
|
||||
/*if(!init_zathura()) {*/
|
||||
/*printf("error: coult not initialize zathura\n");*/
|
||||
/*return -1;*/
|
||||
/*}*/
|
||||
|
||||
if(argc > 1) {
|
||||
zathura_document_t* document = zathura_document_open(argv[1], NULL);
|
||||
if(!document) {
|
||||
return -1;
|
||||
}
|
||||
zathura_document_free(document);
|
||||
}
|
||||
|
||||
gdk_threads_enter();
|
||||
gtk_main();
|
||||
gdk_threads_leave();
|
||||
/*gdk_threads_enter();*/
|
||||
/*gtk_main();*/
|
||||
/*gdk_threads_leave();*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue