Commit 3d027dd7 authored by Moritz Lipp's avatar Moritz Lipp
Browse files

Set page

parent 2cfe3f86
......@@ -72,6 +72,22 @@ sc_goto(girara_session_t* session, girara_argument_t* argument)
bool
sc_navigate(girara_session_t* session, girara_argument_t* argument)
{
if(!session || !argument || !Zathura.document) {
return false;
}
unsigned int number_of_pages = Zathura.document->number_of_pages;
unsigned int new_page = Zathura.document->current_page_number;
if(argument->n == NEXT) {
new_page = (new_page + 1) % number_of_pages;
}
else if(argument->n == PREVIOUS) {
new_page = (new_page + number_of_pages - 1) % number_of_pages;
}
page_set(new_page);
return false;
}
......
......@@ -51,6 +51,60 @@ init_zathura()
return true;
}
bool
document_open(const char* path, const char* password)
{
if(!path) {
return false;
}
zathura_document_t* document = zathura_document_open(path, password);
if(!document) {
return false;
}
Zathura.document = document;
if(!page_set(0)) {
return false;
}
return true;
}
bool
document_close()
{
if(!Zathura.document) {
return false;
}
zathura_document_free(Zathura.document);
return true;
}
bool
page_set(unsigned int page_id)
{
if(!Zathura.document) {
return false;
}
if(page_id >= Zathura.document->number_of_pages) {
return false;
}
Zathura.document->current_page_number = page_id;
char* page_number = g_strdup_printf("[%d/%d]", page_id + 1, Zathura.document->number_of_pages);
girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.page_number, page_number);
g_free(page_number);
return true;
}
/* main function */
int main(int argc, char* argv[])
{
......@@ -64,21 +118,10 @@ int main(int argc, char* argv[])
}
if(argc > 1) {
zathura_document_t* document = zathura_document_open(argv[1], NULL);
if(!document) {
if(!document_open(argv[1], NULL)) {
printf("error: could not open document\n");
return -1;
}
zathura_page_t* page = zathura_page_get(document, 0);
if(!page) {
zathura_document_free(document);
return -2;
}
zathura_page_free(page);
zathura_document_free(document);
}
gdk_threads_enter();
......
......@@ -6,6 +6,8 @@
#include <stdbool.h>
#include <girara.h>
#include "ft/document.h"
enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT,
DELETE_LAST_WORD, DELETE_LAST_CHAR, DEFAULT, ERROR, WARNING, NEXT_GROUP,
PREVIOUS_GROUP, ZOOM_IN, ZOOM_OUT, ZOOM_ORIGINAL, ZOOM_SPECIFIC, FORWARD,
......@@ -34,6 +36,8 @@ struct
girara_statusbar_item_t* page_number; /**> page number statusbar entry */
} statusbar;
} UI;
zathura_document_t* document; /**> The current document */
} Zathura;
/**
......@@ -44,4 +48,28 @@ struct
bool init_zathura();
/**
* Opens a file
*
* @param path The path to the file
* @param password The password of the file
*
* @return If no error occured true, otherwise false, is returned.
*/
bool document_open(const char* path, const char* password);
/**
* Closes the current opened document
*
* @return If no error occured true, otherwise false, is returned.
*/
bool document_close();
/**
* Opens the page with the given number
*
* @return If no error occured true, otherwise false, is returned.
*/
bool page_set(unsigned int page_id);
#endif // ZATHURA_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment