Began to implement the index view

This commit is contained in:
Moritz Lipp 2011-02-10 11:33:28 +08:00
parent c41f945994
commit 31027cbaad
8 changed files with 127 additions and 23 deletions

View file

@ -214,12 +214,6 @@ zathura_document_index_generate(zathura_document_t* document)
return document->functions.document_index_generate(document);
}
bool
zathura_document_index_free(zathura_list_t* list)
{
return false;
}
zathura_list_t*
zathura_document_attachments_get(zathura_document_t* document)
{

View file

@ -117,7 +117,6 @@ 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);
girara_tree_node_t* zathura_document_index_generate(zathura_document_t* document);
bool zathura_document_index_free(zathura_list_t* list);
zathura_list_t* zathura_document_attachments_get(zathura_document_t* document);
bool zathura_document_attachments_free(zathura_list_t* list);

View file

@ -103,32 +103,32 @@ build_index(pdf_document_t* pdf, girara_tree_node_t* root, PopplerIndexIter* ite
}
gchar* markup = g_markup_escape_text(action->any.title, -1);
zathura_index_element_t* indexelement = zathura_index_element_new(markup);
zathura_index_element_t* index_element = zathura_index_element_new(markup);
if (action->type == POPPLER_ACTION_URI) {
indexelement->type = ZATHURA_LINK_EXTERNAL;
indexelement->target.uri = g_strdup(action->uri.uri);
index_element->type = ZATHURA_LINK_EXTERNAL;
index_element->target.uri = g_strdup(action->uri.uri);
} else if (action->type == POPPLER_ACTION_GOTO_DEST) {
indexelement->type = ZATHURA_LINK_TO_PAGE;
index_element->type = ZATHURA_LINK_TO_PAGE;
if (action->goto_dest.dest->type == POPPLER_DEST_NAMED) {
PopplerDest* dest = poppler_document_find_dest(pdf->document, action->goto_dest.dest->named_dest);
if (dest) {
indexelement->target.page_number = dest->page_num - 1;
index_element->target.page_number = dest->page_num - 1;
poppler_dest_free(dest);
}
} else {
indexelement->target.page_number = action->goto_dest.dest->page_num - 1;
index_element->target.page_number = action->goto_dest.dest->page_num - 1;
}
} else {
poppler_action_free(action);
zathura_index_element_free(indexelement);
zathura_index_element_free(index_element);
continue;
}
poppler_action_free(action);
girara_tree_node_t* node = girara_node_append_data(root, indexelement);
girara_tree_node_t* node = girara_node_append_data(root, index_element);
PopplerIndexIter* child = poppler_index_iter_get_child(iter);
if (child) {

View file

@ -7,6 +7,7 @@
#include "shortcuts.h"
#include "zathura.h"
#include "render.h"
#include "utils.h"
bool
sc_abort(girara_session_t* session, girara_argument_t* argument, unsigned int t)
@ -67,7 +68,7 @@ sc_follow(girara_session_t* session, girara_argument_t* argument, unsigned int t
bool
sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t)
{
if (!session || !argument) {
if (session == NULL || argument == NULL || Zathura.document == NULL) {
return false;
}
@ -99,7 +100,7 @@ sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t)
bool
sc_navigate(girara_session_t* session, girara_argument_t* argument, unsigned int t)
{
if (!session || !argument || !Zathura.document) {
if (session == NULL || argument == NULL || Zathura.document == NULL) {
return false;
}
@ -202,6 +203,88 @@ sc_navigate_index(girara_session_t* session, girara_argument_t* argument, unsign
bool
sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned int t)
{
if (session == NULL || Zathura.document == NULL) {
return false;
}
girara_tree_node_t* document_index = NULL;
GtkWidget* treeview = NULL;
GtkTreeModel* model = NULL;
GtkCellRenderer* renderer = NULL;
if (Zathura.UI.index == NULL) {
/* create new index widget */
Zathura.UI.index = gtk_scrolled_window_new(NULL, NULL);
if (Zathura.UI.index == NULL) {
goto error_ret;
}
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.UI.index),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
/* create index */
document_index = zathura_document_index_generate(Zathura.document);
if (document_index == NULL) {
// TODO: Error message
goto error_free;
}
model = GTK_TREE_MODEL(gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER));
if (model == NULL) {
goto error_free;
}
treeview = gtk_tree_view_new_with_model(model);
if (treeview == NULL) {
goto error_free;
}
g_object_unref(model);
renderer = gtk_cell_renderer_text_new();
if (renderer == NULL) {
goto error_free;
}
document_index_build(model, NULL, document_index);
girara_node_free(document_index);
/* setup widget */
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW (treeview), 0, "Title", renderer, "markup", 0, NULL);
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE);
g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
g_object_set(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0)), "expand", TRUE, NULL);
gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview), gtk_tree_path_new_first(), NULL, FALSE);
/*g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(cb_index_row_activated), NULL); TODO*/
gtk_container_add(GTK_CONTAINER(Zathura.UI.index), treeview);
gtk_widget_show(treeview);
}
if (GTK_WIDGET_VISIBLE(GTK_WIDGET(Zathura.UI.index))) {
girara_set_view(session, Zathura.UI.page_view);
gtk_widget_hide(GTK_WIDGET(Zathura.UI.index));
} else {
girara_set_view(session, Zathura.UI.index);
gtk_widget_show(GTK_WIDGET(Zathura.UI.index));
}
return false;
error_free:
if (Zathura.UI.index != NULL) {
g_object_unref(Zathura.UI.index);
Zathura.UI.index = NULL;
}
if (document_index != NULL) {
girara_node_free(document_index);
}
error_ret:
return false;
}
@ -212,10 +295,11 @@ sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument, unsig
return false;
}
if(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar)))
if (GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar))) {
gtk_widget_hide(GTK_WIDGET(session->gtk.inputbar));
else
} else {
gtk_widget_show(GTK_WIDGET(session->gtk.inputbar));
}
return false;
}
@ -247,10 +331,11 @@ sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument, unsi
return false;
}
if(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.statusbar)))
if (GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.statusbar))) {
gtk_widget_hide(GTK_WIDGET(session->gtk.statusbar));
else
} else {
gtk_widget_show(GTK_WIDGET(session->gtk.statusbar));
}
return false;
}
@ -271,7 +356,7 @@ sc_quit(girara_session_t* session, girara_argument_t* argument, unsigned int t)
bool
sc_zoom(girara_session_t* session, girara_argument_t* argument, unsigned int t)
{
if (session == NULL || argument == NULL) {
if (session == NULL || argument == NULL || Zathura.document == NULL) {
return false;
}

15
utils.c
View file

@ -8,6 +8,7 @@
#include <sys/wait.h>
#include "utils.h"
#include "zathura.h"
#define BLOCK_SIZE 64
@ -157,8 +158,20 @@ page_blank(unsigned int width, unsigned int height)
gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
gtk_widget_show(image);
/*free(buffer);*/
/*free(buffer);*/ // XXX: Read documentation
g_object_unref(pixbuf);
return image;
}
void
document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_t* tree)
{
girara_list_t* list = girara_node_get_children(tree);
girara_list_iterator_t* it = girara_list_iterator(list);
do {
zathura_index_element_t* index_element = (zathura_index_element_t*) girara_list_iterator_data(it);
printf("%s\n", index_element->title);
} while ((it = girara_list_iterator_next(it)));
}

11
utils.h
View file

@ -5,6 +5,7 @@
#include <stdbool.h>
#include <gtk/gtk.h>
#include <girara.h>
/**
* Checks if the given file exists
@ -40,4 +41,14 @@ bool execute_command(char* const argv[], char** output);
*/
GtkWidget* page_blank(unsigned int width, unsigned int height);
/**
* Generates the document index based upon the list retreived from the document
* object.
*
* @param model The tree model
* @param tree_it The Tree iterator
* @param list_it The index list iterator
*/
void document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_t* tree);
#endif // UTILS_H

View file

@ -26,6 +26,7 @@ init_zathura()
Zathura.UI.statusbar.buffer = NULL;
Zathura.UI.statusbar.page_number = NULL;
Zathura.UI.page_view = NULL;
Zathura.UI.index = NULL;
/* page view */
Zathura.UI.page_view = gtk_vbox_new(FALSE, 0);

View file

@ -38,6 +38,7 @@ struct
} statusbar;
GtkWidget *page_view; /**> Widget that contains all rendered pages */
GtkWidget *index; /**> Widget to show the index of the document */
} UI;
struct