Update style

This commit is contained in:
Moritz Lipp 2012-10-09 01:12:18 +02:00
parent 41cb60e5c6
commit 89e7832047
20 changed files with 451 additions and 460 deletions

View file

@ -87,7 +87,8 @@ zathura_bookmark_free(zathura_bookmark_t* bookmark)
} }
bool bool
zathura_bookmarks_load(zathura_t* zathura, const gchar* file) { zathura_bookmarks_load(zathura_t* zathura, const gchar* file)
{
g_return_val_if_fail(zathura, false); g_return_val_if_fail(zathura, false);
g_return_val_if_fail(file, false); g_return_val_if_fail(file, false);

View file

@ -84,7 +84,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpoi
GdkRectangle page_rect; GdkRectangle page_rect;
GtkWidget* page_widget = zathura_page_get_widget(zathura, page); GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
gtk_widget_translate_coordinates(page_widget, gtk_widget_translate_coordinates(page_widget,
zathura->ui.session->gtk.view, 0, 0, &page_rect.x, &page_rect.y); zathura->ui.session->gtk.view, 0, 0, &page_rect.x, &page_rect.y);
page_rect.width = zathura_page_get_width(page) * scale; page_rect.width = zathura_page_get_width(page) * scale;
page_rect.height = zathura_page_get_height(page) * scale; page_rect.height = zathura_page_get_height(page) * scale;
@ -156,7 +156,7 @@ cb_first_page_column_value_changed(girara_session_t* session, const char* UNUSED
void void
cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path, cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path,
GtkTreeViewColumn* UNUSED(column), void* data) GtkTreeViewColumn* UNUSED(column), void* data)
{ {
zathura_t* zathura = data; zathura_t* zathura = data;
if (tree_view == NULL || zathura == NULL || zathura->ui.session == NULL) { if (tree_view == NULL || zathura == NULL || zathura->ui.session == NULL) {
@ -269,13 +269,13 @@ password_dialog(gpointer data)
if (dialog != NULL) { if (dialog != NULL) {
girara_dialog( girara_dialog(
dialog->zathura->ui.session, dialog->zathura->ui.session,
"Incorrect password. Enter password:", "Incorrect password. Enter password:",
true, true,
NULL, NULL,
(girara_callback_inputbar_activate_t) cb_password_dialog, (girara_callback_inputbar_activate_t) cb_password_dialog,
dialog dialog
); );
} }
return FALSE; return FALSE;
@ -323,8 +323,8 @@ cb_password_dialog(GtkEntry* entry, zathura_password_dialog_info_t* dialog)
error_free: error_free:
g_free(dialog->path); g_free(dialog->path);
free(dialog); free(dialog);
error_ret: error_ret:
@ -355,7 +355,7 @@ cb_view_resized(GtkWidget* UNUSED(widget), GtkAllocation* allocation, zathura_t*
void void
cb_setting_recolor_change(girara_session_t* session, const char* name, cb_setting_recolor_change(girara_session_t* session, const char* name,
girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
{ {
g_return_if_fail(value != NULL); g_return_if_fail(value != NULL);
g_return_if_fail(session != NULL); g_return_if_fail(session != NULL);
@ -373,7 +373,7 @@ cb_setting_recolor_change(girara_session_t* session, const char* name,
void void
cb_setting_recolor_keep_hue_change(girara_session_t* session, const char* name, cb_setting_recolor_keep_hue_change(girara_session_t* session, const char* name,
girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
{ {
g_return_if_fail(value != NULL); g_return_if_fail(value != NULL);
g_return_if_fail(session != NULL); g_return_if_fail(session != NULL);

View file

@ -165,15 +165,15 @@ cmd_info(girara_session_t* session, girara_list_t* UNUSED(argument_list))
GString* string = g_string_new(NULL); GString* string = g_string_new(NULL);
GIRARA_LIST_FOREACH(information, zathura_document_information_entry_t*, iter, entry) GIRARA_LIST_FOREACH(information, zathura_document_information_entry_t*, iter, entry)
if (entry != NULL) { if (entry != NULL) {
for (unsigned int i = 0; i < LENGTH(meta_fields); i++) { for (unsigned int i = 0; i < LENGTH(meta_fields); i++) {
if (meta_fields[i].field == entry->type) { if (meta_fields[i].field == entry->type) {
char* text = g_strdup_printf("<b>%s:</b> %s\n", meta_fields[i].name, entry->value); char* text = g_strdup_printf("<b>%s:</b> %s\n", meta_fields[i].name, entry->value);
g_string_append(string, text); g_string_append(string, text);
g_free(text); g_free(text);
}
} }
} }
}
GIRARA_LIST_FOREACH_END(information, zathura_document_information_entry_t*, iter, entry); GIRARA_LIST_FOREACH_END(information, zathura_document_information_entry_t*, iter, entry);
if (strlen(string->str) > 0) { if (strlen(string->str) > 0) {
@ -190,7 +190,7 @@ cmd_info(girara_session_t* session, girara_list_t* UNUSED(argument_list))
bool bool
cmd_help(girara_session_t* UNUSED(session), girara_list_t* cmd_help(girara_session_t* UNUSED(session), girara_list_t*
UNUSED(argument_list)) UNUSED(argument_list))
{ {
return true; return true;
} }
@ -426,7 +426,7 @@ cmd_export(girara_session_t* session, girara_list_t* argument_list)
} else { } else {
girara_notify(session, GIRARA_INFO, _("Wrote attachment '%s' to '%s'."), file_identifier, export_path); girara_notify(session, GIRARA_INFO, _("Wrote attachment '%s' to '%s'."), file_identifier, export_path);
} }
/* image */ /* image */
} else if (strncmp(file_identifier, "image-p", strlen("image-p")) == 0 && strlen(file_identifier) >= 10) { } else if (strncmp(file_identifier, "image-p", strlen("image-p")) == 0 && strlen(file_identifier) >= 10) {
/* parse page id */ /* parse page id */
const char* input = file_identifier + strlen("image-p"); const char* input = file_identifier + strlen("image-p");
@ -479,7 +479,7 @@ image_error:
girara_notify(session, GIRARA_ERROR, _("Unknown image '%s'."), file_identifier); girara_notify(session, GIRARA_ERROR, _("Unknown image '%s'."), file_identifier);
goto error_ret; goto error_ret;
/* unknown */ /* unknown */
} else { } else {
girara_notify(session, GIRARA_ERROR, _("Unknown attachment or image '%s'."), file_identifier); girara_notify(session, GIRARA_ERROR, _("Unknown attachment or image '%s'."), file_identifier);
} }
@ -502,10 +502,10 @@ cmd_exec(girara_session_t* session, girara_list_t* argument_list)
const char* path = zathura_document_get_path(zathura->document); const char* path = zathura_document_get_path(zathura->document);
GIRARA_LIST_FOREACH(argument_list, char*, iter, value) GIRARA_LIST_FOREACH(argument_list, char*, iter, value)
char* r = NULL; char* r = NULL;
if ((r = replace_substring(value, "$FILE", path)) != NULL) { if ((r = replace_substring(value, "$FILE", path)) != NULL) {
girara_list_iterator_set(iter, r); girara_list_iterator_set(iter, r);
} }
GIRARA_LIST_FOREACH_END(argument_list, char*, iter, value); GIRARA_LIST_FOREACH_END(argument_list, char*, iter, value);
} }
@ -553,9 +553,9 @@ cmd_version(girara_session_t* session, girara_list_t* UNUSED(argument_list))
zathura_t* zathura = session->global.data; zathura_t* zathura = session->global.data;
char* string = zathura_get_version_string(zathura, true); char* string = zathura_get_version_string(zathura, true);
if (string == NULL) { if (string == NULL) {
return false; return false;
} }
/* display information */ /* display information */
girara_notify(session, GIRARA_INFO, "%s", string); girara_notify(session, GIRARA_INFO, "%s", string);

View file

@ -32,7 +32,7 @@ compare_case_insensitive(const char* str1, const char* str2)
static girara_list_t* static girara_list_t*
list_files(zathura_t* zathura, const char* current_path, const char* current_file, list_files(zathura_t* zathura, const char* current_path, const char* current_file,
unsigned int current_file_length, bool is_dir, bool check_file_ext) unsigned int current_file_length, bool is_dir, bool check_file_ext)
{ {
if (zathura == NULL || zathura->ui.session == NULL || current_path == NULL) { if (zathura == NULL || zathura->ui.session == NULL || current_path == NULL) {
return NULL; return NULL;
@ -45,7 +45,7 @@ list_files(zathura_t* zathura, const char* current_path, const char* current_fil
} }
girara_list_t* res = girara_sorted_list_new2((girara_compare_function_t)compare_case_insensitive, girara_list_t* res = girara_sorted_list_new2((girara_compare_function_t)compare_case_insensitive,
(girara_free_function_t)g_free); (girara_free_function_t)g_free);
bool show_hidden = false; bool show_hidden = false;
girara_setting_get(zathura->ui.session, "show-hidden", &show_hidden); girara_setting_get(zathura->ui.session, "show-hidden", &show_hidden);
@ -179,7 +179,7 @@ list_files_for_cc(zathura_t* zathura, const char* input, bool check_file_ext)
} }
GIRARA_LIST_FOREACH(names, const char*, iter, file) GIRARA_LIST_FOREACH(names, const char*, iter, file)
girara_completion_group_add_element(group, file, NULL); girara_completion_group_add_element(group, file, NULL);
GIRARA_LIST_FOREACH_END(names, const char*, iter, file); GIRARA_LIST_FOREACH_END(names, const char*, iter, file);
girara_list_free(names); girara_list_free(names);
} }
@ -246,11 +246,11 @@ cc_bookmarks(girara_session_t* session, const char* input)
const size_t input_length = strlen(input); const size_t input_length = strlen(input);
GIRARA_LIST_FOREACH(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark) GIRARA_LIST_FOREACH(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark)
if (input_length <= strlen(bookmark->id) && !strncmp(input, bookmark->id, input_length)) { if (input_length <= strlen(bookmark->id) && !strncmp(input, bookmark->id, input_length)) {
gchar* paged = g_strdup_printf(_("Page %d"), bookmark->page); gchar* paged = g_strdup_printf(_("Page %d"), bookmark->page);
girara_completion_group_add_element(group, bookmark->id, paged); girara_completion_group_add_element(group, bookmark->id, paged);
g_free(paged); g_free(paged);
} }
GIRARA_LIST_FOREACH_END(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark); GIRARA_LIST_FOREACH_END(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark);
girara_completion_add_group(completion, group); girara_completion_add_group(completion, group);
@ -302,12 +302,12 @@ cc_export(girara_session_t* session, const char* input)
bool added = false; bool added = false;
GIRARA_LIST_FOREACH(attachments, const char*, iter, attachment) GIRARA_LIST_FOREACH(attachments, const char*, iter, attachment)
if (input_length <= strlen(attachment) && !strncmp(input, attachment, input_length)) { if (input_length <= strlen(attachment) && !strncmp(input, attachment, input_length)) {
char* attachment_string = g_strdup_printf("attachment-%s", attachment); char* attachment_string = g_strdup_printf("attachment-%s", attachment);
girara_completion_group_add_element(attachment_group, attachment_string, NULL); girara_completion_group_add_element(attachment_group, attachment_string, NULL);
g_free(attachment_string); g_free(attachment_string);
added = true; added = true;
} }
GIRARA_LIST_FOREACH_END(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark); GIRARA_LIST_FOREACH_END(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark);
if (added == true) { if (added == true) {
@ -339,12 +339,12 @@ cc_export(girara_session_t* session, const char* input)
if (images != NULL) { if (images != NULL) {
unsigned int image_number = 1; unsigned int image_number = 1;
GIRARA_LIST_FOREACH(images, zathura_image_t*, iter, UNUSED(image)) GIRARA_LIST_FOREACH(images, zathura_image_t*, iter, UNUSED(image))
char* image_string = g_strdup_printf("image-p%d-%d", page_id + 1, image_number); char* image_string = g_strdup_printf("image-p%d-%d", page_id + 1, image_number);
girara_completion_group_add_element(image_group, image_string, NULL); girara_completion_group_add_element(image_group, image_string, NULL);
g_free(image_string); g_free(image_string);
added = true; added = true;
image_number++; image_number++;
GIRARA_LIST_FOREACH_END(images, zathura_image_t*, iter, image); GIRARA_LIST_FOREACH_END(images, zathura_image_t*, iter, image);
girara_list_free(images); girara_list_free(images);
} }

View file

@ -20,7 +20,7 @@
static void static void
cb_jumplist_change(girara_session_t* session, const char* name, cb_jumplist_change(girara_session_t* session, const char* name,
girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
{ {
g_return_if_fail(value != NULL); g_return_if_fail(value != NULL);
g_return_if_fail(session != NULL); g_return_if_fail(session != NULL);
@ -35,7 +35,7 @@ cb_jumplist_change(girara_session_t* session, const char* name,
static void static void
cb_color_change(girara_session_t* session, const char* name, cb_color_change(girara_session_t* session, const char* name,
girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
{ {
g_return_if_fail(value != NULL); g_return_if_fail(value != NULL);
g_return_if_fail(session != NULL); g_return_if_fail(session != NULL);
@ -59,7 +59,7 @@ cb_color_change(girara_session_t* session, const char* name,
static void static void
cb_page_padding_changed(girara_session_t* session, const char* UNUSED(name), cb_page_padding_changed(girara_session_t* session, const char* UNUSED(name),
girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
{ {
g_return_if_fail(value != NULL); g_return_if_fail(value != NULL);
g_return_if_fail(session != NULL); g_return_if_fail(session != NULL);
@ -80,7 +80,7 @@ cb_page_padding_changed(girara_session_t* session, const char* UNUSED(name),
static void static void
cb_nohlsearch_changed(girara_session_t* session, const char* UNUSED(name), cb_nohlsearch_changed(girara_session_t* session, const char* UNUSED(name),
girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
{ {
g_return_if_fail(value != NULL); g_return_if_fail(value != NULL);
g_return_if_fail(session != NULL); g_return_if_fail(session != NULL);
@ -93,7 +93,7 @@ cb_nohlsearch_changed(girara_session_t* session, const char* UNUSED(name),
static void static void
cb_incsearch_changed(girara_session_t* session, const char* UNUSED(name), cb_incsearch_changed(girara_session_t* session, const char* UNUSED(name),
girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
{ {
g_return_if_fail(value != NULL); g_return_if_fail(value != NULL);
g_return_if_fail(session != NULL); g_return_if_fail(session != NULL);

View file

@ -39,28 +39,28 @@
static void zathura_database_interface_init(ZathuraDatabaseInterface* iface); static void zathura_database_interface_init(ZathuraDatabaseInterface* iface);
G_DEFINE_TYPE_WITH_CODE(ZathuraPlainDatabase, zathura_plaindatabase, G_TYPE_OBJECT, G_DEFINE_TYPE_WITH_CODE(ZathuraPlainDatabase, zathura_plaindatabase, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE(ZATHURA_TYPE_DATABASE, zathura_database_interface_init)) G_IMPLEMENT_INTERFACE(ZATHURA_TYPE_DATABASE, zathura_database_interface_init))
static void plain_finalize(GObject* object); static void plain_finalize(GObject* object);
static bool plain_add_bookmark(zathura_database_t* db, const char* file, static bool plain_add_bookmark(zathura_database_t* db, const char* file,
zathura_bookmark_t* bookmark); zathura_bookmark_t* bookmark);
static bool plain_remove_bookmark(zathura_database_t* db, const char* file, static bool plain_remove_bookmark(zathura_database_t* db, const char* file,
const char* id); const char* id);
static girara_list_t* plain_load_bookmarks(zathura_database_t* db, static girara_list_t* plain_load_bookmarks(zathura_database_t* db,
const char* file); const char* file);
static bool plain_set_fileinfo(zathura_database_t* db, const char* file, static bool plain_set_fileinfo(zathura_database_t* db, const char* file,
zathura_fileinfo_t* file_info); zathura_fileinfo_t* file_info);
static bool plain_get_fileinfo(zathura_database_t* db, const char* file, static bool plain_get_fileinfo(zathura_database_t* db, const char* file,
zathura_fileinfo_t* file_info); zathura_fileinfo_t* file_info);
static void plain_set_property(GObject* object, guint prop_id, static void plain_set_property(GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec); const GValue* value, GParamSpec* pspec);
/* forward declaration */ /* forward declaration */
static bool zathura_db_check_file(const char* path); static bool zathura_db_check_file(const char* path);
static GKeyFile* zathura_db_read_key_file_from_file(const char* path); static GKeyFile* zathura_db_read_key_file_from_file(const char* path);
static void zathura_db_write_key_file_to_file(const char* file, GKeyFile* key_file); static void zathura_db_write_key_file_to_file(const char* file, GKeyFile* key_file);
static void cb_zathura_db_watch_file(GFileMonitor* monitor, GFile* file, GFile* static void cb_zathura_db_watch_file(GFileMonitor* monitor, GFile* file, GFile*
other_file, GFileMonitorEvent event, zathura_database_t* database); other_file, GFileMonitorEvent event, zathura_database_t* database);
typedef struct zathura_plaindatabase_private_s { typedef struct zathura_plaindatabase_private_s {
char* bookmark_path; char* bookmark_path;
@ -75,8 +75,7 @@ typedef struct zathura_plaindatabase_private_s {
#define ZATHURA_PLAINDATABASE_GET_PRIVATE(obj) \ #define ZATHURA_PLAINDATABASE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZATHURA_TYPE_PLAINDATABASE, zathura_plaindatabase_private_t)) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZATHURA_TYPE_PLAINDATABASE, zathura_plaindatabase_private_t))
enum enum {
{
PROP_0, PROP_0,
PROP_PATH PROP_PATH
}; };
@ -118,8 +117,8 @@ zathura_plaindatabase_class_init(ZathuraPlainDatabaseClass* class)
object_class->set_property = plain_set_property; object_class->set_property = plain_set_property;
g_object_class_install_property(object_class, PROP_PATH, g_object_class_install_property(object_class, PROP_PATH,
g_param_spec_string("path", "path", "path to directory where the bookmarks and history are locates", g_param_spec_string("path", "path", "path to directory where the bookmarks and history are locates",
NULL, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); NULL, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
} }
static void static void
@ -171,10 +170,10 @@ plain_db_init(ZathuraPlainDatabase* db, const char* dir)
g_object_unref(bookmark_file); g_object_unref(bookmark_file);
g_signal_connect( g_signal_connect(
G_OBJECT(priv->bookmark_monitor), G_OBJECT(priv->bookmark_monitor),
"changed", "changed",
G_CALLBACK(cb_zathura_db_watch_file), G_CALLBACK(cb_zathura_db_watch_file),
db db
); );
priv->bookmarks = zathura_db_read_key_file_from_file(priv->bookmark_path); priv->bookmarks = zathura_db_read_key_file_from_file(priv->bookmark_path);
@ -198,10 +197,10 @@ plain_db_init(ZathuraPlainDatabase* db, const char* dir)
g_object_unref(history_file); g_object_unref(history_file);
g_signal_connect( g_signal_connect(
G_OBJECT(priv->history_monitor), G_OBJECT(priv->history_monitor),
"changed", "changed",
G_CALLBACK(cb_zathura_db_watch_file), G_CALLBACK(cb_zathura_db_watch_file),
db db
); );
priv->history = zathura_db_read_key_file_from_file(priv->history_path); priv->history = zathura_db_read_key_file_from_file(priv->history_path);
@ -289,7 +288,7 @@ plain_finalize(GObject* object)
static bool static bool
plain_add_bookmark(zathura_database_t* db, const char* file, plain_add_bookmark(zathura_database_t* db, const char* file,
zathura_bookmark_t* bookmark) zathura_bookmark_t* bookmark)
{ {
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db); zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
if (priv->bookmarks == NULL || priv->bookmark_path == NULL || if (priv->bookmarks == NULL || priv->bookmark_path == NULL ||
@ -308,7 +307,7 @@ plain_add_bookmark(zathura_database_t* db, const char* file,
static bool static bool
plain_remove_bookmark(zathura_database_t* db, const char* file, const char* plain_remove_bookmark(zathura_database_t* db, const char* file, const char*
GIRARA_UNUSED(id)) GIRARA_UNUSED(id))
{ {
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db); zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
if (priv->bookmarks == NULL || priv->bookmark_path == NULL) { if (priv->bookmarks == NULL || priv->bookmark_path == NULL) {
@ -344,8 +343,8 @@ plain_load_bookmarks(zathura_database_t* db, const char* file)
} }
girara_list_t* result = girara_sorted_list_new2((girara_compare_function_t) girara_list_t* result = girara_sorted_list_new2((girara_compare_function_t)
zathura_bookmarks_compare, (girara_free_function_t) zathura_bookmarks_compare, (girara_free_function_t)
zathura_bookmark_free); zathura_bookmark_free);
gsize length; gsize length;
char** keys = g_key_file_get_keys(priv->bookmarks, name, &length, NULL); char** keys = g_key_file_get_keys(priv->bookmarks, name, &length, NULL);
@ -372,7 +371,7 @@ plain_load_bookmarks(zathura_database_t* db, const char* file)
static bool static bool
plain_set_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t* plain_set_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
file_info) file_info)
{ {
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db); zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
if (priv->history == NULL || file_info == NULL || file == NULL) { if (priv->history == NULL || file_info == NULL || file == NULL) {
@ -409,7 +408,7 @@ plain_set_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
static bool static bool
plain_get_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t* plain_get_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
file_info) file_info)
{ {
if (db == NULL || file == NULL || file_info == NULL) { if (db == NULL || file == NULL || file_info == NULL) {
return false; return false;
@ -519,9 +518,9 @@ zathura_db_read_key_file_from_file(const char* path)
GError* error = NULL; GError* error = NULL;
if (g_key_file_load_from_data(key_file, content, contentlen, if (g_key_file_load_from_data(key_file, content, contentlen,
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error) == G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error) ==
FALSE) { FALSE) {
if (error->code != 1) /* ignore empty file */ { if (error->code != 1) { /* ignore empty file */
free(content); free(content);
g_key_file_free(key_file); g_key_file_free(key_file);
g_error_free(error); g_error_free(error);
@ -568,7 +567,7 @@ zathura_db_write_key_file_to_file(const char* file, GKeyFile* key_file)
static void static void
cb_zathura_db_watch_file(GFileMonitor* UNUSED(monitor), GFile* file, GFile* UNUSED(other_file), cb_zathura_db_watch_file(GFileMonitor* UNUSED(monitor), GFile* file, GFile* UNUSED(other_file),
GFileMonitorEvent event, zathura_database_t* database) GFileMonitorEvent event, zathura_database_t* database)
{ {
if (event != G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT || database == NULL) { if (event != G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT || database == NULL) {
return; return;

View file

@ -10,21 +10,21 @@
static void zathura_database_interface_init(ZathuraDatabaseInterface* iface); static void zathura_database_interface_init(ZathuraDatabaseInterface* iface);
G_DEFINE_TYPE_WITH_CODE(ZathuraSQLDatabase, zathura_sqldatabase, G_TYPE_OBJECT, G_DEFINE_TYPE_WITH_CODE(ZathuraSQLDatabase, zathura_sqldatabase, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE(ZATHURA_TYPE_DATABASE, zathura_database_interface_init)) G_IMPLEMENT_INTERFACE(ZATHURA_TYPE_DATABASE, zathura_database_interface_init))
static void sqlite_finalize(GObject* object); static void sqlite_finalize(GObject* object);
static bool sqlite_add_bookmark(zathura_database_t* db, const char* file, static bool sqlite_add_bookmark(zathura_database_t* db, const char* file,
zathura_bookmark_t* bookmark); zathura_bookmark_t* bookmark);
static bool sqlite_remove_bookmark(zathura_database_t* db, const char* file, static bool sqlite_remove_bookmark(zathura_database_t* db, const char* file,
const char* id); const char* id);
static girara_list_t* sqlite_load_bookmarks(zathura_database_t* db, static girara_list_t* sqlite_load_bookmarks(zathura_database_t* db,
const char* file); const char* file);
static bool sqlite_set_fileinfo(zathura_database_t* db, const char* file, static bool sqlite_set_fileinfo(zathura_database_t* db, const char* file,
zathura_fileinfo_t* file_info); zathura_fileinfo_t* file_info);
static bool sqlite_get_fileinfo(zathura_database_t* db, const char* file, static bool sqlite_get_fileinfo(zathura_database_t* db, const char* file,
zathura_fileinfo_t* file_info); zathura_fileinfo_t* file_info);
static void sqlite_set_property(GObject* object, guint prop_id, static void sqlite_set_property(GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec); const GValue* value, GParamSpec* pspec);
typedef struct zathura_sqldatabase_private_s { typedef struct zathura_sqldatabase_private_s {
sqlite3* session; sqlite3* session;
@ -33,8 +33,7 @@ typedef struct zathura_sqldatabase_private_s {
#define ZATHURA_SQLDATABASE_GET_PRIVATE(obj) \ #define ZATHURA_SQLDATABASE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZATHURA_TYPE_SQLDATABASE, zathura_sqldatabase_private_t)) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZATHURA_TYPE_SQLDATABASE, zathura_sqldatabase_private_t))
enum enum {
{
PROP_0, PROP_0,
PROP_PATH PROP_PATH
}; };
@ -62,7 +61,7 @@ zathura_sqldatabase_class_init(ZathuraSQLDatabaseClass* class)
object_class->set_property = sqlite_set_property; object_class->set_property = sqlite_set_property;
g_object_class_install_property(object_class, PROP_PATH, g_object_class_install_property(object_class, PROP_PATH,
g_param_spec_string("path", "path", "path to the database", NULL, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); g_param_spec_string("path", "path", "path to the database", NULL, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
} }
static void static void
@ -107,23 +106,23 @@ sqlite_db_init(ZathuraSQLDatabase* db, const char* path)
/* create bookmarks database */ /* create bookmarks database */
static const char SQL_BOOKMARK_INIT[] = static const char SQL_BOOKMARK_INIT[] =
"CREATE TABLE IF NOT EXISTS bookmarks (" "CREATE TABLE IF NOT EXISTS bookmarks ("
"file TEXT," "file TEXT,"
"id TEXT," "id TEXT,"
"page INTEGER," "page INTEGER,"
"PRIMARY KEY(file, id));"; "PRIMARY KEY(file, id));";
static const char SQL_FILEINFO_INIT[] = static const char SQL_FILEINFO_INIT[] =
"CREATE TABLE IF NOT EXISTS fileinfo (" "CREATE TABLE IF NOT EXISTS fileinfo ("
"file TEXT PRIMARY KEY," "file TEXT PRIMARY KEY,"
"page INTEGER," "page INTEGER,"
"offset INTEGER," "offset INTEGER,"
"scale FLOAT," "scale FLOAT,"
"rotation INTEGER," "rotation INTEGER,"
"pages_per_row INTEGER," "pages_per_row INTEGER,"
"first_page_column INTEGER," "first_page_column INTEGER,"
"position_x FLOAT," "position_x FLOAT,"
"position_y FLOAT" "position_y FLOAT"
");"; ");";
static const char SQL_FILEINFO_ALTER[] = static const char SQL_FILEINFO_ALTER[] =
"ALTER TABLE fileinfo ADD COLUMN pages_per_row INTEGER;" "ALTER TABLE fileinfo ADD COLUMN pages_per_row INTEGER;"
@ -211,7 +210,7 @@ prepare_statement(sqlite3* session, const char* statement)
static bool static bool
sqlite_add_bookmark(zathura_database_t* db, const char* file, sqlite_add_bookmark(zathura_database_t* db, const char* file,
zathura_bookmark_t* bookmark) zathura_bookmark_t* bookmark)
{ {
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db); zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
@ -239,7 +238,7 @@ sqlite_add_bookmark(zathura_database_t* db, const char* file,
static bool static bool
sqlite_remove_bookmark(zathura_database_t* db, const char* file, const char* sqlite_remove_bookmark(zathura_database_t* db, const char* file, const char*
id) id)
{ {
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db); zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
@ -284,7 +283,7 @@ sqlite_load_bookmarks(zathura_database_t* db, const char* file)
} }
girara_list_t* result = girara_sorted_list_new2((girara_compare_function_t) zathura_bookmarks_compare, girara_list_t* result = girara_sorted_list_new2((girara_compare_function_t) zathura_bookmarks_compare,
(girara_free_function_t) zathura_bookmark_free); (girara_free_function_t) zathura_bookmark_free);
while (sqlite3_step(stmt) == SQLITE_ROW) { while (sqlite3_step(stmt) == SQLITE_ROW) {
zathura_bookmark_t* bookmark = g_malloc0(sizeof(zathura_bookmark_t)); zathura_bookmark_t* bookmark = g_malloc0(sizeof(zathura_bookmark_t));
@ -302,7 +301,7 @@ sqlite_load_bookmarks(zathura_database_t* db, const char* file)
static bool static bool
sqlite_set_fileinfo(zathura_database_t* db, const char* file, sqlite_set_fileinfo(zathura_database_t* db, const char* file,
zathura_fileinfo_t* file_info) zathura_fileinfo_t* file_info)
{ {
if (db == NULL || file == NULL || file_info == NULL) { if (db == NULL || file == NULL || file_info == NULL) {
return false; return false;
@ -340,7 +339,7 @@ sqlite_set_fileinfo(zathura_database_t* db, const char* file,
static bool static bool
sqlite_get_fileinfo(zathura_database_t* db, const char* file, sqlite_get_fileinfo(zathura_database_t* db, const char* file,
zathura_fileinfo_t* file_info) zathura_fileinfo_t* file_info)
{ {
if (db == NULL || file == NULL || file_info == NULL) { if (db == NULL || file == NULL || file_info == NULL) {
return false; return false;

View file

@ -21,7 +21,7 @@ zathura_db_free(zathura_database_t* db)
bool bool
zathura_db_add_bookmark(zathura_database_t* db, const char* file, zathura_db_add_bookmark(zathura_database_t* db, const char* file,
zathura_bookmark_t* bookmark) zathura_bookmark_t* bookmark)
{ {
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && bookmark != NULL, false); g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && bookmark != NULL, false);
@ -30,7 +30,7 @@ zathura_db_add_bookmark(zathura_database_t* db, const char* file,
bool bool
zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const char* zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const char*
id) id)
{ {
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && id != NULL, false); g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && id != NULL, false);
@ -45,9 +45,9 @@ zathura_db_load_bookmarks(zathura_database_t* db, const char* file)
return ZATHURA_DATABASE_GET_INTERFACE(db)->load_bookmarks(db, file); return ZATHURA_DATABASE_GET_INTERFACE(db)->load_bookmarks(db, file);
} }
bool bool
zathura_db_set_fileinfo(zathura_database_t* db, const char* file, zathura_db_set_fileinfo(zathura_database_t* db, const char* file,
zathura_fileinfo_t* file_info) zathura_fileinfo_t* file_info)
{ {
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && file_info != NULL, false); g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && file_info != NULL, false);
@ -56,7 +56,7 @@ zathura_db_set_fileinfo(zathura_database_t* db, const char* file,
bool bool
zathura_db_get_fileinfo(zathura_database_t* db, const char* file, zathura_db_get_fileinfo(zathura_database_t* db, const char* file,
zathura_fileinfo_t* file_info) zathura_fileinfo_t* file_info)
{ {
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && file_info != NULL, false); g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && file_info != NULL, false);

View file

@ -36,8 +36,7 @@ static const gchar* guess_type(const char* path);
/** /**
* Document * Document
*/ */
struct zathura_document_s struct zathura_document_s {
{
char* file_path; /**< File path of the document */ char* file_path; /**< File path of the document */
const char* password; /**< Password of the document */ const char* password; /**< Password of the document */
unsigned int current_page_number; /**< Current page number */ unsigned int current_page_number; /**< Current page number */
@ -62,7 +61,7 @@ struct zathura_document_s
zathura_document_t* zathura_document_t*
zathura_document_open(zathura_plugin_manager_t* plugin_manager, const char* zathura_document_open(zathura_plugin_manager_t* plugin_manager, const char*
path, const char* password, zathura_error_t* error) path, const char* password, zathura_error_t* error)
{ {
if (path == NULL) { if (path == NULL) {
return NULL; return NULL;

13
links.c
View file

@ -10,8 +10,7 @@
#include "document.h" #include "document.h"
#include "utils.h" #include "utils.h"
struct zathura_link_s struct zathura_link_s {
{
zathura_rectangle_t position; /**< Position of the link */ zathura_rectangle_t position; /**< Position of the link */
zathura_link_type_t type; /**< Link type */ zathura_link_type_t type; /**< Link type */
zathura_link_target_t target; /**< Link target */ zathura_link_target_t target; /**< Link target */
@ -23,7 +22,7 @@ static void link_launch(zathura_t* zathura, zathura_link_t* link);
zathura_link_t* zathura_link_t*
zathura_link_new(zathura_link_type_t type, zathura_rectangle_t position, zathura_link_new(zathura_link_type_t type, zathura_rectangle_t position,
zathura_link_target_t target) zathura_link_target_t target)
{ {
zathura_link_t* link = g_malloc0(sizeof(zathura_link_t)); zathura_link_t* link = g_malloc0(sizeof(zathura_link_t));
@ -130,12 +129,12 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link)
/* get page */ /* get page */
zathura_page_t* page = zathura_document_get_page(zathura->document, zathura_page_t* page = zathura_document_get_page(zathura->document,
link->target.page_number); link->target.page_number);
if (page == NULL) { if (page == NULL) {
return; return;
} }
zathura_document_set_current_page_number(zathura->document, link->target.page_number); zathura_document_set_current_page_number(zathura->document, link->target.page_number);
/* get page offset */ /* get page offset */
page_offset_t offset; page_offset_t offset;
@ -152,8 +151,8 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link)
position_set_delayed(zathura, offset.x, offset.y); position_set_delayed(zathura, offset.x, offset.y);
statusbar_page_number_update(zathura); statusbar_page_number_update(zathura);
} }
break; break;
default: default:
break; break;
} }

92
marks.c
View file

@ -28,7 +28,7 @@ struct zathura_mark_s {
bool bool
sc_mark_add(girara_session_t* session, girara_argument_t* UNUSED(argument), sc_mark_add(girara_session_t* session, girara_argument_t* UNUSED(argument),
girara_event_t* UNUSED(event), unsigned int UNUSED(t)) girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, FALSE); g_return_val_if_fail(session != NULL, FALSE);
g_return_val_if_fail(session->gtk.view != NULL, FALSE); g_return_val_if_fail(session->gtk.view != NULL, FALSE);
@ -36,14 +36,14 @@ sc_mark_add(girara_session_t* session, girara_argument_t* UNUSED(argument),
/* redirect signal handler */ /* redirect signal handler */
g_signal_handler_disconnect(G_OBJECT(session->gtk.view), session->signals.view_key_pressed); g_signal_handler_disconnect(G_OBJECT(session->gtk.view), session->signals.view_key_pressed);
session->signals.view_key_pressed = g_signal_connect(G_OBJECT(session->gtk.view), "key-press-event", session->signals.view_key_pressed = g_signal_connect(G_OBJECT(session->gtk.view), "key-press-event",
G_CALLBACK(cb_marks_view_key_press_event_add), session); G_CALLBACK(cb_marks_view_key_press_event_add), session);
return true; return true;
} }
bool bool
sc_mark_evaluate(girara_session_t* session, girara_argument_t* UNUSED(argument), sc_mark_evaluate(girara_session_t* session, girara_argument_t* UNUSED(argument),
girara_event_t* UNUSED(event), unsigned int UNUSED(t)) girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, FALSE); g_return_val_if_fail(session != NULL, FALSE);
g_return_val_if_fail(session->gtk.view != NULL, FALSE); g_return_val_if_fail(session->gtk.view != NULL, FALSE);
@ -51,14 +51,14 @@ sc_mark_evaluate(girara_session_t* session, girara_argument_t* UNUSED(argument),
/* redirect signal handler */ /* redirect signal handler */
g_signal_handler_disconnect(G_OBJECT(session->gtk.view), session->signals.view_key_pressed); g_signal_handler_disconnect(G_OBJECT(session->gtk.view), session->signals.view_key_pressed);
session->signals.view_key_pressed = g_signal_connect(G_OBJECT(session->gtk.view), "key-press-event", session->signals.view_key_pressed = g_signal_connect(G_OBJECT(session->gtk.view), "key-press-event",
G_CALLBACK(cb_marks_view_key_press_event_evaluate), session); G_CALLBACK(cb_marks_view_key_press_event_evaluate), session);
return true; return true;
} }
bool bool
cb_marks_view_key_press_event_add(GtkWidget* UNUSED(widget), GdkEventKey* event, cb_marks_view_key_press_event_add(GtkWidget* UNUSED(widget), GdkEventKey* event,
girara_session_t* session) girara_session_t* session)
{ {
g_return_val_if_fail(session != NULL, FALSE); g_return_val_if_fail(session != NULL, FALSE);
g_return_val_if_fail(session->gtk.view != NULL, FALSE); g_return_val_if_fail(session->gtk.view != NULL, FALSE);
@ -68,11 +68,11 @@ cb_marks_view_key_press_event_add(GtkWidget* UNUSED(widget), GdkEventKey* event,
/* reset signal handler */ /* reset signal handler */
g_signal_handler_disconnect(G_OBJECT(session->gtk.view), session->signals.view_key_pressed); g_signal_handler_disconnect(G_OBJECT(session->gtk.view), session->signals.view_key_pressed);
session->signals.view_key_pressed = g_signal_connect(G_OBJECT(session->gtk.view), "key-press-event", session->signals.view_key_pressed = g_signal_connect(G_OBJECT(session->gtk.view), "key-press-event",
G_CALLBACK(girara_callback_view_key_press_event), session); G_CALLBACK(girara_callback_view_key_press_event), session);
/* evaluate key */ /* evaluate key */
if (((event->keyval >= 0x41 && event->keyval <= 0x5A) || (event->keyval >= if (((event->keyval >= 0x41 && event->keyval <= 0x5A) || (event->keyval >=
0x61 && event->keyval <= 0x7A)) == false) { 0x61 && event->keyval <= 0x7A)) == false) {
return false; return false;
} }
@ -92,11 +92,11 @@ bool cb_marks_view_key_press_event_evaluate(GtkWidget* UNUSED(widget), GdkEventK
/* reset signal handler */ /* reset signal handler */
g_signal_handler_disconnect(G_OBJECT(session->gtk.view), session->signals.view_key_pressed); g_signal_handler_disconnect(G_OBJECT(session->gtk.view), session->signals.view_key_pressed);
session->signals.view_key_pressed = g_signal_connect(G_OBJECT(session->gtk.view), "key-press-event", session->signals.view_key_pressed = g_signal_connect(G_OBJECT(session->gtk.view), "key-press-event",
G_CALLBACK(girara_callback_view_key_press_event), session); G_CALLBACK(girara_callback_view_key_press_event), session);
/* evaluate key */ /* evaluate key */
if (((event->keyval >= 0x41 && event->keyval <= 0x5A) || (event->keyval >= if (((event->keyval >= 0x41 && event->keyval <= 0x5A) || (event->keyval >=
0x61 && event->keyval <= 0x7A)) == false) { 0x61 && event->keyval <= 0x7A)) == false) {
return true; return true;
} }
@ -129,7 +129,7 @@ cmd_marks_add(girara_session_t* session, girara_list_t* argument_list)
char key = key_string[0]; char key = key_string[0];
if (((key >= 0x41 && key <= 0x5A) || (key >= if (((key >= 0x41 && key <= 0x5A) || (key >=
0x61 && key <= 0x7A)) == false) { 0x61 && key <= 0x7A)) == false) {
return false; return false;
} }
@ -154,32 +154,32 @@ cmd_marks_delete(girara_session_t* session, girara_list_t* argument_list)
} }
GIRARA_LIST_FOREACH(argument_list, char*, iter, key_string) GIRARA_LIST_FOREACH(argument_list, char*, iter, key_string)
if (key_string == NULL) { if (key_string == NULL) {
continue;
}
for (unsigned int i = 0; i < strlen(key_string); i++) {
char key = key_string[i];
if (((key >= 0x41 && key <= 0x5A) || (key >=
0x61 && key <= 0x7A)) == false) {
continue; continue;
} }
for (unsigned int i = 0; i < strlen(key_string); i++) { /* search for existing mark */
char key = key_string[i]; girara_list_iterator_t* mark_iter = girara_list_iterator(zathura->global.marks);
if (((key >= 0x41 && key <= 0x5A) || (key >= do {
0x61 && key <= 0x7A)) == false) { zathura_mark_t* mark = (zathura_mark_t*) girara_list_iterator_data(mark_iter);
if (mark == NULL) {
continue; continue;
} }
/* search for existing mark */ if (mark->key == key) {
girara_list_iterator_t* mark_iter = girara_list_iterator(zathura->global.marks); girara_list_remove(zathura->global.marks, mark);
do { continue;
zathura_mark_t* mark = (zathura_mark_t*) girara_list_iterator_data(mark_iter); }
if (mark == NULL) { } while (girara_list_iterator_next(mark_iter) != NULL);
continue; girara_list_iterator_free(mark_iter);
} }
if (mark->key == key) {
girara_list_remove(zathura->global.marks, mark);
continue;
}
} while (girara_list_iterator_next(mark_iter) != NULL);
girara_list_iterator_free(mark_iter);
}
GIRARA_LIST_FOREACH_END(argument_list, char*, iter, key_string); GIRARA_LIST_FOREACH_END(argument_list, char*, iter, key_string);
return true; return true;
@ -206,12 +206,12 @@ mark_add(zathura_t* zathura, int key)
/* search for existing mark */ /* search for existing mark */
GIRARA_LIST_FOREACH(zathura->global.marks, zathura_mark_t*, iter, mark) GIRARA_LIST_FOREACH(zathura->global.marks, zathura_mark_t*, iter, mark)
if (mark->key == key) { if (mark->key == key) {
mark->position_x = position_x; mark->position_x = position_x;
mark->position_y = position_y; mark->position_y = position_y;
mark->scale = scale; mark->scale = scale;
return; return;
} }
GIRARA_LIST_FOREACH_END(zathura->global.marks, zathura_mark_t*, iter, mark); GIRARA_LIST_FOREACH_END(zathura->global.marks, zathura_mark_t*, iter, mark);
/* add new mark */ /* add new mark */
@ -234,19 +234,19 @@ mark_evaluate(zathura_t* zathura, int key)
/* search for existing mark */ /* search for existing mark */
GIRARA_LIST_FOREACH(zathura->global.marks, zathura_mark_t*, iter, mark) GIRARA_LIST_FOREACH(zathura->global.marks, zathura_mark_t*, iter, mark)
if (mark != NULL && mark->key == key) { if (mark != NULL && mark->key == key) {
double old_scale = zathura_document_get_scale(zathura->document); double old_scale = zathura_document_get_scale(zathura->document);
zathura_document_set_scale(zathura->document, mark->scale); zathura_document_set_scale(zathura->document, mark->scale);
readjust_view_after_zooming(zathura, old_scale, true); readjust_view_after_zooming(zathura, old_scale, true);
render_all(zathura); render_all(zathura);
position_set_delayed(zathura, mark->position_x, mark->position_y); position_set_delayed(zathura, mark->position_x, mark->position_y);
cb_view_vadjustment_value_changed(NULL, zathura); cb_view_vadjustment_value_changed(NULL, zathura);
zathura->global.update_page_number = true; zathura->global.update_page_number = true;
return; return;
} }
GIRARA_LIST_FOREACH_END(zathura->global.marks, zathura_mark_t*, iter, mark); GIRARA_LIST_FOREACH_END(zathura->global.marks, zathura_mark_t*, iter, mark);
} }

View file

@ -74,8 +74,7 @@ static gboolean cb_zathura_page_widget_popup_menu(GtkWidget* widget);
static void cb_menu_image_copy(GtkMenuItem* item, ZathuraPage* page); static void cb_menu_image_copy(GtkMenuItem* item, ZathuraPage* page);
static void cb_menu_image_save(GtkMenuItem* item, ZathuraPage* page); static void cb_menu_image_save(GtkMenuItem* item, ZathuraPage* page);
enum properties_e enum properties_e {
{
PROP_0, PROP_0,
PROP_PAGE, PROP_PAGE,
PROP_ZATHURA, PROP_ZATHURA,
@ -115,25 +114,25 @@ zathura_page_widget_class_init(ZathuraPageClass* class)
/* add properties */ /* add properties */
g_object_class_install_property(object_class, PROP_PAGE, g_object_class_install_property(object_class, PROP_PAGE,
g_param_spec_pointer("page", "page", "the page to draw", G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); g_param_spec_pointer("page", "page", "the page to draw", G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property(object_class, PROP_ZATHURA, g_object_class_install_property(object_class, PROP_ZATHURA,
g_param_spec_pointer("zathura", "zathura", "the zathura instance", G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); g_param_spec_pointer("zathura", "zathura", "the zathura instance", G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property(object_class, PROP_DRAW_LINKS, g_object_class_install_property(object_class, PROP_DRAW_LINKS,
g_param_spec_boolean("draw-links", "draw-links", "Set to true if links should be drawn", FALSE, G_PARAM_WRITABLE)); g_param_spec_boolean("draw-links", "draw-links", "Set to true if links should be drawn", FALSE, G_PARAM_WRITABLE));
g_object_class_install_property(object_class, PROP_LINKS_OFFSET, g_object_class_install_property(object_class, PROP_LINKS_OFFSET,
g_param_spec_int("offset-links", "offset-links", "Offset for the link numbers", 0, INT_MAX, 0, G_PARAM_WRITABLE)); g_param_spec_int("offset-links", "offset-links", "Offset for the link numbers", 0, INT_MAX, 0, G_PARAM_WRITABLE));
g_object_class_install_property(object_class, PROP_LINKS_NUMBER, g_object_class_install_property(object_class, PROP_LINKS_NUMBER,
g_param_spec_int("number-of-links", "number-of-links", "Number of links", 0, INT_MAX, 0, G_PARAM_READABLE)); g_param_spec_int("number-of-links", "number-of-links", "Number of links", 0, INT_MAX, 0, G_PARAM_READABLE));
g_object_class_install_property(object_class, PROP_SEARCH_RESULTS, g_object_class_install_property(object_class, PROP_SEARCH_RESULTS,
g_param_spec_pointer("search-results", "search-results", "Set to the list of search results", G_PARAM_WRITABLE | G_PARAM_READABLE)); g_param_spec_pointer("search-results", "search-results", "Set to the list of search results", G_PARAM_WRITABLE | G_PARAM_READABLE));
g_object_class_install_property(object_class, PROP_SEARCH_RESULTS_CURRENT, g_object_class_install_property(object_class, PROP_SEARCH_RESULTS_CURRENT,
g_param_spec_int("search-current", "search-current", "The current search result", -1, INT_MAX, 0, G_PARAM_WRITABLE | G_PARAM_READABLE)); g_param_spec_int("search-current", "search-current", "The current search result", -1, INT_MAX, 0, G_PARAM_WRITABLE | G_PARAM_READABLE));
g_object_class_install_property(object_class, PROP_SEARCH_RESULTS_LENGTH, g_object_class_install_property(object_class, PROP_SEARCH_RESULTS_LENGTH,
g_param_spec_int("search-length", "search-length", "The number of search results", -1, INT_MAX, 0, G_PARAM_READABLE)); g_param_spec_int("search-length", "search-length", "The number of search results", -1, INT_MAX, 0, G_PARAM_READABLE));
g_object_class_install_property(object_class, PROP_DRAW_SEACH_RESULTS, g_object_class_install_property(object_class, PROP_DRAW_SEACH_RESULTS,
g_param_spec_boolean("draw-search-results", "draw-search-results", "Set to true if search results should be drawn", FALSE, G_PARAM_WRITABLE)); g_param_spec_boolean("draw-search-results", "draw-search-results", "Set to true if search results should be drawn", FALSE, G_PARAM_WRITABLE));
g_object_class_install_property(object_class, PROP_LAST_VIEW, g_object_class_install_property(object_class, PROP_LAST_VIEW,
g_param_spec_int("last-view", "last-view", "Last time the page has been viewed", -1, INT_MAX, 0, G_PARAM_READABLE)); g_param_spec_int("last-view", "last-view", "Last time the page has been viewed", -1, INT_MAX, 0, G_PARAM_READABLE));
} }
static void static void
@ -167,7 +166,7 @@ zathura_page_widget_init(ZathuraPage* widget)
/* we want mouse events */ /* we want mouse events */
gtk_widget_add_events(GTK_WIDGET(widget), gtk_widget_add_events(GTK_WIDGET(widget),
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK); GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK);
} }
GtkWidget* GtkWidget*
@ -225,10 +224,10 @@ zathura_page_widget_set_property(GObject* object, guint prop_id, const GValue* v
if (priv->links.retrieved == true && priv->links.list != NULL) { if (priv->links.retrieved == true && priv->links.list != NULL) {
GIRARA_LIST_FOREACH(priv->links.list, zathura_link_t*, iter, link) GIRARA_LIST_FOREACH(priv->links.list, zathura_link_t*, iter, link)
if (link != NULL) { if (link != NULL) {
zathura_rectangle_t rectangle = recalc_rectangle(priv->page, zathura_link_get_position(link)); zathura_rectangle_t rectangle = recalc_rectangle(priv->page, zathura_link_get_position(link));
redraw_rect(pageview, &rectangle); redraw_rect(pageview, &rectangle);
} }
GIRARA_LIST_FOREACH_END(priv->links.list, zathura_link_t*, iter, link); GIRARA_LIST_FOREACH_END(priv->links.list, zathura_link_t*, iter, link);
} }
break; break;
@ -381,24 +380,24 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo)
if (priv->links.draw == true && priv->links.n != 0) { if (priv->links.draw == true && priv->links.n != 0) {
unsigned int link_counter = 0; unsigned int link_counter = 0;
GIRARA_LIST_FOREACH(priv->links.list, zathura_link_t*, iter, link) GIRARA_LIST_FOREACH(priv->links.list, zathura_link_t*, iter, link)
if (link != NULL) { if (link != NULL) {
zathura_rectangle_t rectangle = recalc_rectangle(priv->page, zathura_link_get_position(link)); zathura_rectangle_t rectangle = recalc_rectangle(priv->page, zathura_link_get_position(link));
/* draw position */ /* draw position */
GdkColor color = priv->zathura->ui.colors.highlight_color; GdkColor color = priv->zathura->ui.colors.highlight_color;
cairo_set_source_rgba(cairo, color.red/65535.0, color.green/65535.0, color.blue/65535.0, transparency); cairo_set_source_rgba(cairo, color.red/65535.0, color.green/65535.0, color.blue/65535.0, transparency);
cairo_rectangle(cairo, rectangle.x1, rectangle.y1, cairo_rectangle(cairo, rectangle.x1, rectangle.y1,
(rectangle.x2 - rectangle.x1), (rectangle.y2 - rectangle.y1)); (rectangle.x2 - rectangle.x1), (rectangle.y2 - rectangle.y1));
cairo_fill(cairo); cairo_fill(cairo);
/* draw text */ /* draw text */
cairo_set_source_rgba(cairo, 0, 0, 0, 1); cairo_set_source_rgba(cairo, 0, 0, 0, 1);
cairo_set_font_size(cairo, 10); cairo_set_font_size(cairo, 10);
cairo_move_to(cairo, rectangle.x1 + 1, rectangle.y2 - 1); cairo_move_to(cairo, rectangle.x1 + 1, rectangle.y2 - 1);
char* link_number = g_strdup_printf("%i", priv->links.offset + ++link_counter); char* link_number = g_strdup_printf("%i", priv->links.offset + ++link_counter);
cairo_show_text(cairo, link_number); cairo_show_text(cairo, link_number);
g_free(link_number); g_free(link_number);
} }
GIRARA_LIST_FOREACH_END(priv->links.list, zathura_link_t*, iter, link); GIRARA_LIST_FOREACH_END(priv->links.list, zathura_link_t*, iter, link);
} }
@ -406,20 +405,20 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo)
if (priv->search.list != NULL && priv->search.draw == true) { if (priv->search.list != NULL && priv->search.draw == true) {
int idx = 0; int idx = 0;
GIRARA_LIST_FOREACH(priv->search.list, zathura_rectangle_t*, iter, rect) GIRARA_LIST_FOREACH(priv->search.list, zathura_rectangle_t*, iter, rect)
zathura_rectangle_t rectangle = recalc_rectangle(priv->page, *rect); zathura_rectangle_t rectangle = recalc_rectangle(priv->page, *rect);
/* draw position */ /* draw position */
if (idx == priv->search.current) { if (idx == priv->search.current) {
GdkColor color = priv->zathura->ui.colors.highlight_color_active; GdkColor color = priv->zathura->ui.colors.highlight_color_active;
cairo_set_source_rgba(cairo, color.red/65535.0, color.green/65535.0, color.blue/65535.0, transparency); cairo_set_source_rgba(cairo, color.red/65535.0, color.green/65535.0, color.blue/65535.0, transparency);
} else { } else {
GdkColor color = priv->zathura->ui.colors.highlight_color; GdkColor color = priv->zathura->ui.colors.highlight_color;
cairo_set_source_rgba(cairo, color.red/65535.0, color.green/65535.0, color.blue/65535.0, transparency); cairo_set_source_rgba(cairo, color.red/65535.0, color.green/65535.0, color.blue/65535.0, transparency);
} }
cairo_rectangle(cairo, rectangle.x1, rectangle.y1, cairo_rectangle(cairo, rectangle.x1, rectangle.y1,
(rectangle.x2 - rectangle.x1), (rectangle.y2 - rectangle.y1)); (rectangle.x2 - rectangle.x1), (rectangle.y2 - rectangle.y1));
cairo_fill(cairo); cairo_fill(cairo);
++idx; ++idx;
GIRARA_LIST_FOREACH_END(priv->search.list, zathura_rectangle_t*, iter, rect); GIRARA_LIST_FOREACH_END(priv->search.list, zathura_rectangle_t*, iter, rect);
} }
/* draw selection */ /* draw selection */
@ -427,7 +426,7 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo)
GdkColor color = priv->zathura->ui.colors.highlight_color; GdkColor color = priv->zathura->ui.colors.highlight_color;
cairo_set_source_rgba(cairo, color.red/65535.0, color.green/65535.0, color.blue/65535.0, transparency); cairo_set_source_rgba(cairo, color.red/65535.0, color.green/65535.0, color.blue/65535.0, transparency);
cairo_rectangle(cairo, priv->mouse.selection.x1, priv->mouse.selection.y1, cairo_rectangle(cairo, priv->mouse.selection.x1, priv->mouse.selection.y1,
(priv->mouse.selection.x2 - priv->mouse.selection.x1), (priv->mouse.selection.y2 - priv->mouse.selection.y1)); (priv->mouse.selection.x2 - priv->mouse.selection.x1), (priv->mouse.selection.y2 - priv->mouse.selection.y1));
cairo_fill(cairo); cairo_fill(cairo);
} }
} else { } else {
@ -503,7 +502,7 @@ zathura_page_widget_size_allocate(GtkWidget* widget, GdkRectangle* allocation)
static void static void
redraw_rect(ZathuraPage* widget, zathura_rectangle_t* rectangle) redraw_rect(ZathuraPage* widget, zathura_rectangle_t* rectangle)
{ {
/* cause the rect to be drawn */ /* cause the rect to be drawn */
GdkRectangle grect; GdkRectangle grect;
grect.x = rectangle->x1; grect.x = rectangle->x1;
grect.y = rectangle->y1; grect.y = rectangle->y1;
@ -522,8 +521,8 @@ redraw_all_rects(ZathuraPage* widget, girara_list_t* rectangles)
zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(widget); zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(widget);
GIRARA_LIST_FOREACH(rectangles, zathura_rectangle_t*, iter, rect) GIRARA_LIST_FOREACH(rectangles, zathura_rectangle_t*, iter, rect)
zathura_rectangle_t rectangle = recalc_rectangle(priv->page, *rect); zathura_rectangle_t rectangle = recalc_rectangle(priv->page, *rect);
redraw_rect(widget, &rectangle); redraw_rect(widget, &rectangle);
GIRARA_LIST_FOREACH_END(rectangles, zathura_recantgle_t*, iter, rect); GIRARA_LIST_FOREACH_END(rectangles, zathura_recantgle_t*, iter, rect);
} }
@ -607,11 +606,11 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
if (priv->links.list != NULL && priv->links.n > 0) { if (priv->links.list != NULL && priv->links.n > 0) {
GIRARA_LIST_FOREACH(priv->links.list, zathura_link_t*, iter, link) GIRARA_LIST_FOREACH(priv->links.list, zathura_link_t*, iter, link)
zathura_rectangle_t rect = recalc_rectangle(priv->page, zathura_link_get_position(link)); zathura_rectangle_t rect = recalc_rectangle(priv->page, zathura_link_get_position(link));
if (rect.x1 <= button->x && rect.x2 >= button->x if (rect.x1 <= button->x && rect.x2 >= button->x
&& rect.y1 <= button->y && rect.y2 >= button->y) { && rect.y1 <= button->y && rect.y2 >= button->y) {
zathura_link_evaluate(priv->zathura, link); zathura_link_evaluate(priv->zathura, link);
} }
GIRARA_LIST_FOREACH_END(priv->links.list, zathura_link_t*, iter, link); GIRARA_LIST_FOREACH_END(priv->links.list, zathura_link_t*, iter, link);
} }
} else { } else {
@ -721,10 +720,10 @@ zathura_page_widget_popup_menu(GtkWidget* widget, GdkEventButton* event)
/* search for underlaying image */ /* search for underlaying image */
zathura_image_t* image = NULL; zathura_image_t* image = NULL;
GIRARA_LIST_FOREACH(priv->images.list, zathura_image_t*, iter, image_it) GIRARA_LIST_FOREACH(priv->images.list, zathura_image_t*, iter, image_it)
zathura_rectangle_t rect = recalc_rectangle(priv->page, image_it->position); zathura_rectangle_t rect = recalc_rectangle(priv->page, image_it->position);
if (rect.x1 <= event->x && rect.x2 >= event->x && rect.y1 <= event->y && rect.y2 >= event->y) { if (rect.x1 <= event->x && rect.x2 >= event->x && rect.y1 <= event->y && rect.y2 >= event->y) {
image = image_it; image = image_it;
} }
GIRARA_LIST_FOREACH_END(priv->images.list, zathura_image_t*, iter, image_it); GIRARA_LIST_FOREACH_END(priv->images.list, zathura_image_t*, iter, image_it);
if (image == NULL) { if (image == NULL) {
@ -799,7 +798,7 @@ cb_menu_image_copy(GtkMenuItem* item, ZathuraPage* page)
cairo_destroy(cairo); cairo_destroy(cairo);
GdkPixbuf* pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0, GdkPixbuf* pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0,
0, width, height); 0, width, height);
gtk_clipboard_set_image(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), pixbuf); gtk_clipboard_set_image(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), pixbuf);
gtk_clipboard_set_image(gtk_clipboard_get(GDK_SELECTION_PRIMARY), pixbuf); gtk_clipboard_set_image(gtk_clipboard_get(GDK_SELECTION_PRIMARY), pixbuf);
@ -823,11 +822,11 @@ cb_menu_image_save(GtkMenuItem* item, ZathuraPage* page)
unsigned int image_id = 1; unsigned int image_id = 1;
GIRARA_LIST_FOREACH(priv->images.list, zathura_image_t*, iter, image_it) GIRARA_LIST_FOREACH(priv->images.list, zathura_image_t*, iter, image_it)
if (image_it == priv->images.current) { if (image_it == priv->images.current) {
break; break;
} }
image_id++; image_id++;
GIRARA_LIST_FOREACH_END(priv->images.list, zathura_image_t*, iter, image_it); GIRARA_LIST_FOREACH_END(priv->images.list, zathura_image_t*, iter, image_it);
/* set command */ /* set command */

226
plugin.c
View file

@ -14,8 +14,7 @@
/** /**
* Document plugin structure * Document plugin structure
*/ */
struct zathura_plugin_s struct zathura_plugin_s {
{
girara_list_t* content_types; /**< List of supported content types */ girara_list_t* content_types; /**< List of supported content types */
zathura_plugin_register_function_t register_function; /**< Document open function */ zathura_plugin_register_function_t register_function; /**< Document open function */
zathura_plugin_functions_t functions; /**< Document functions */ zathura_plugin_functions_t functions; /**< Document functions */
@ -28,8 +27,7 @@ struct zathura_plugin_s
/** /**
* Plugin mapping * Plugin mapping
*/ */
typedef struct zathura_type_plugin_mapping_s typedef struct zathura_type_plugin_mapping_s {
{
const gchar* type; /**< Plugin type */ const gchar* type; /**< Plugin type */
zathura_plugin_t* plugin; /**< Mapped plugin */ zathura_plugin_t* plugin; /**< Mapped plugin */
} zathura_type_plugin_mapping_t; } zathura_type_plugin_mapping_t;
@ -37,8 +35,7 @@ typedef struct zathura_type_plugin_mapping_s
/** /**
* Plugin manager * Plugin manager
*/ */
struct zathura_plugin_manager_s struct zathura_plugin_manager_s {
{
girara_list_t* plugins; /**< List of plugins */ girara_list_t* plugins; /**< List of plugins */
girara_list_t* path; /**< List of plugin paths */ girara_list_t* path; /**< List of plugin paths */
girara_list_t* type_plugin_mapping; /**< List of type -> plugin mappings */ girara_list_t* type_plugin_mapping; /**< List of type -> plugin mappings */
@ -91,120 +88,117 @@ zathura_plugin_manager_load(zathura_plugin_manager_t* plugin_manager)
} }
GIRARA_LIST_FOREACH(plugin_manager->path, char*, iter, plugindir) GIRARA_LIST_FOREACH(plugin_manager->path, char*, iter, plugindir)
/* read all files in the plugin directory */ /* read all files in the plugin directory */
GDir* dir = g_dir_open(plugindir, 0, NULL); GDir* dir = g_dir_open(plugindir, 0, NULL);
if (dir == NULL) { if (dir == NULL) {
girara_error("could not open plugin directory: %s", plugindir); girara_error("could not open plugin directory: %s", plugindir);
girara_list_iterator_next(iter); girara_list_iterator_next(iter);
continue;
}
char* name = NULL;
while ((name = (char*) g_dir_read_name(dir)) != NULL) {
char* path = g_build_filename(plugindir, name, NULL);
if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == 0) {
girara_info("%s is not a regular file. Skipping.", path);
g_free(path);
continue; continue;
} }
char* name = NULL; zathura_plugin_t* plugin = NULL;
while ((name = (char*) g_dir_read_name(dir)) != NULL) {
char* path = g_build_filename(plugindir, name, NULL);
if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == 0) {
girara_info("%s is not a regular file. Skipping.", path);
g_free(path);
continue;
}
zathura_plugin_t* plugin = NULL; /* load plugin */
GModule* handle = g_module_open(path, G_MODULE_BIND_LOCAL);
if (handle == NULL) {
girara_error("could not load plugin %s (%s)", path, g_module_error());
g_free(path);
continue;
}
/* load plugin */ /* resolve symbols and check API and ABI version*/
GModule* handle = g_module_open(path, G_MODULE_BIND_LOCAL); zathura_plugin_api_version_t api_version = NULL;
if (handle == NULL) { if (g_module_symbol(handle, PLUGIN_API_VERSION_FUNCTION, (gpointer*) &api_version) == FALSE ||
girara_error("could not load plugin %s (%s)", path, g_module_error()); api_version == NULL) {
g_free(path); girara_error("could not find '%s' function in plugin %s", PLUGIN_API_VERSION_FUNCTION, path);
continue; g_free(path);
} g_module_close(handle);
continue;
}
/* resolve symbols and check API and ABI version*/ if (api_version() != ZATHURA_API_VERSION) {
zathura_plugin_api_version_t api_version = NULL; girara_error("plugin %s has been built againt zathura with a different API version (plugin: %d, zathura: %d)",
if (g_module_symbol(handle, PLUGIN_API_VERSION_FUNCTION, (gpointer*) &api_version) == FALSE || path, api_version(), ZATHURA_API_VERSION);
api_version == NULL) g_free(path);
{ g_module_close(handle);
girara_error("could not find '%s' function in plugin %s", PLUGIN_API_VERSION_FUNCTION, path); continue;
g_free(path); }
g_module_close(handle);
continue;
}
if (api_version() != ZATHURA_API_VERSION) { zathura_plugin_abi_version_t abi_version = NULL;
girara_error("plugin %s has been built againt zathura with a different API version (plugin: %d, zathura: %d)", if (g_module_symbol(handle, PLUGIN_ABI_VERSION_FUNCTION, (gpointer*) &abi_version) == FALSE ||
path, api_version(), ZATHURA_API_VERSION); abi_version == NULL) {
g_free(path); girara_error("could not find '%s' function in plugin %s", PLUGIN_ABI_VERSION_FUNCTION, path);
g_module_close(handle); g_free(path);
continue; g_module_close(handle);
} continue;
}
zathura_plugin_abi_version_t abi_version = NULL; if (abi_version() != ZATHURA_ABI_VERSION) {
if (g_module_symbol(handle, PLUGIN_ABI_VERSION_FUNCTION, (gpointer*) &abi_version) == FALSE || girara_error("plugin %s has been built againt zathura with a different ABI version (plugin: %d, zathura: %d)",
abi_version == NULL) path, abi_version(), ZATHURA_ABI_VERSION);
{ g_free(path);
girara_error("could not find '%s' function in plugin %s", PLUGIN_ABI_VERSION_FUNCTION, path); g_module_close(handle);
g_free(path); continue;
g_module_close(handle); }
continue;
}
if (abi_version() != ZATHURA_ABI_VERSION) { zathura_plugin_register_service_t register_service = NULL;
girara_error("plugin %s has been built againt zathura with a different ABI version (plugin: %d, zathura: %d)", if (g_module_symbol(handle, PLUGIN_REGISTER_FUNCTION, (gpointer*) &register_service) == FALSE ||
path, abi_version(), ZATHURA_ABI_VERSION); register_service == NULL) {
g_free(path); girara_error("could not find '%s' function in plugin %s", PLUGIN_REGISTER_FUNCTION, path);
g_module_close(handle); g_free(path);
continue; g_module_close(handle);
} continue;
}
zathura_plugin_register_service_t register_service = NULL; plugin = g_malloc0(sizeof(zathura_plugin_t));
if (g_module_symbol(handle, PLUGIN_REGISTER_FUNCTION, (gpointer*) &register_service) == FALSE || plugin->content_types = girara_list_new2(g_free);
register_service == NULL) plugin->handle = handle;
{
girara_error("could not find '%s' function in plugin %s", PLUGIN_REGISTER_FUNCTION, path);
g_free(path);
g_module_close(handle);
continue;
}
plugin = g_malloc0(sizeof(zathura_plugin_t)); register_service(plugin);
plugin->content_types = girara_list_new2(g_free);
plugin->handle = handle;
register_service(plugin); /* register functions */
if (plugin->register_function == NULL) {
girara_error("plugin has no document functions register function");
g_free(path);
g_free(plugin);
g_module_close(handle);
continue;
}
/* register functions */ plugin->register_function(&(plugin->functions));
if (plugin->register_function == NULL) { plugin->path = path;
girara_error("plugin has no document functions register function");
g_free(path);
g_free(plugin);
g_module_close(handle);
continue;
}
plugin->register_function(&(plugin->functions)); bool ret = register_plugin(plugin_manager, plugin);
plugin->path = path; if (ret == false) {
girara_error("could not register plugin %s", path);
zathura_plugin_free(plugin);
} else {
girara_info("successfully loaded plugin %s", path);
bool ret = register_plugin(plugin_manager, plugin); zathura_plugin_version_function_t plugin_major = NULL, plugin_minor = NULL, plugin_rev = NULL;
if (ret == false) { g_module_symbol(handle, PLUGIN_VERSION_MAJOR_FUNCTION, (gpointer*) &plugin_major);
girara_error("could not register plugin %s", path); g_module_symbol(handle, PLUGIN_VERSION_MINOR_FUNCTION, (gpointer*) &plugin_minor);
zathura_plugin_free(plugin); g_module_symbol(handle, PLUGIN_VERSION_REVISION_FUNCTION, (gpointer*) &plugin_rev);
} else { if (plugin_major != NULL && plugin_minor != NULL && plugin_rev != NULL) {
girara_info("successfully loaded plugin %s", path); plugin->version.major = plugin_major();
plugin->version.minor = plugin_minor();
zathura_plugin_version_function_t plugin_major = NULL, plugin_minor = NULL, plugin_rev = NULL; plugin->version.rev = plugin_rev();
g_module_symbol(handle, PLUGIN_VERSION_MAJOR_FUNCTION, (gpointer*) &plugin_major); girara_debug("plugin '%s': version %u.%u.%u", path,
g_module_symbol(handle, PLUGIN_VERSION_MINOR_FUNCTION, (gpointer*) &plugin_minor); plugin->version.major, plugin->version.minor,
g_module_symbol(handle, PLUGIN_VERSION_REVISION_FUNCTION, (gpointer*) &plugin_rev); plugin->version.rev);
if (plugin_major != NULL && plugin_minor != NULL && plugin_rev != NULL) {
plugin->version.major = plugin_major();
plugin->version.minor = plugin_minor();
plugin->version.rev = plugin_rev();
girara_debug("plugin '%s': version %u.%u.%u", path,
plugin->version.major, plugin->version.minor,
plugin->version.rev);
}
} }
} }
g_dir_close(dir); }
g_dir_close(dir);
GIRARA_LIST_FOREACH_END(zathura->plugins.path, char*, iter, plugindir); GIRARA_LIST_FOREACH_END(zathura->plugins.path, char*, iter, plugindir);
} }
@ -217,10 +211,10 @@ zathura_plugin_manager_get_plugin(zathura_plugin_manager_t* plugin_manager, cons
zathura_plugin_t* plugin = NULL; zathura_plugin_t* plugin = NULL;
GIRARA_LIST_FOREACH(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping) GIRARA_LIST_FOREACH(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping)
if (g_content_type_equals(type, mapping->type)) { if (g_content_type_equals(type, mapping->type)) {
plugin = mapping->plugin; plugin = mapping->plugin;
break; break;
} }
GIRARA_LIST_FOREACH_END(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping); GIRARA_LIST_FOREACH_END(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping);
return plugin; return plugin;
@ -272,11 +266,11 @@ register_plugin(zathura_plugin_manager_t* plugin_manager, zathura_plugin_t* plug
bool at_least_one = false; bool at_least_one = false;
GIRARA_LIST_FOREACH(plugin->content_types, gchar*, iter, type) GIRARA_LIST_FOREACH(plugin->content_types, gchar*, iter, type)
if (plugin_mapping_new(plugin_manager, type, plugin) == false) { if (plugin_mapping_new(plugin_manager, type, plugin) == false) {
girara_error("plugin: already registered for filetype %s\n", type); girara_error("plugin: already registered for filetype %s\n", type);
} else { } else {
at_least_one = true; at_least_one = true;
} }
GIRARA_LIST_FOREACH_END(plugin->content_types, gchar*, iter, type); GIRARA_LIST_FOREACH_END(plugin->content_types, gchar*, iter, type);
if (at_least_one == true) { if (at_least_one == true) {
@ -294,10 +288,10 @@ plugin_mapping_new(zathura_plugin_manager_t* plugin_manager, const gchar* type,
g_return_val_if_fail(plugin != NULL, false); g_return_val_if_fail(plugin != NULL, false);
GIRARA_LIST_FOREACH(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping) GIRARA_LIST_FOREACH(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping)
if (g_content_type_equals(type, mapping->type)) { if (g_content_type_equals(type, mapping->type)) {
girara_list_iterator_free(iter); girara_list_iterator_free(iter);
return false; return false;
} }
GIRARA_LIST_FOREACH_END(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping); GIRARA_LIST_FOREACH_END(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping);
zathura_type_plugin_mapping_t* mapping = g_malloc(sizeof(zathura_type_plugin_mapping_t)); zathura_type_plugin_mapping_t* mapping = g_malloc(sizeof(zathura_type_plugin_mapping_t));

22
print.c
View file

@ -9,12 +9,12 @@
#include <girara/statusbar.h> #include <girara/statusbar.h>
static void cb_print_draw_page(GtkPrintOperation* print_operation, static void cb_print_draw_page(GtkPrintOperation* print_operation,
GtkPrintContext* context, gint page_number, zathura_t* zathura); GtkPrintContext* context, gint page_number, zathura_t* zathura);
static void cb_print_end(GtkPrintOperation* print_operation, GtkPrintContext* static void cb_print_end(GtkPrintOperation* print_operation, GtkPrintContext*
context, zathura_t* zathura); context, zathura_t* zathura);
static void cb_print_request_page_setup(GtkPrintOperation* print_operation, static void cb_print_request_page_setup(GtkPrintOperation* print_operation,
GtkPrintContext* context, gint page_number, GtkPageSetup* setup, zathura_t* GtkPrintContext* context, gint page_number, GtkPageSetup* setup, zathura_t*
zathura); zathura);
void void
print(zathura_t* zathura) print(zathura_t* zathura)
@ -45,7 +45,7 @@ print(zathura_t* zathura)
/* print */ /* print */
GtkPrintOperationResult result = gtk_print_operation_run(print_operation, GtkPrintOperationResult result = gtk_print_operation_run(print_operation,
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL); GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL);
if (result == GTK_PRINT_OPERATION_RESULT_APPLY) { if (result == GTK_PRINT_OPERATION_RESULT_APPLY) {
if (zathura->print.settings != NULL) { if (zathura->print.settings != NULL) {
@ -67,7 +67,7 @@ print(zathura_t* zathura)
static void static void
cb_print_end(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext* cb_print_end(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext*
UNUSED(context), zathura_t* zathura) UNUSED(context), zathura_t* zathura)
{ {
if (zathura == NULL || zathura->ui.session == NULL || zathura->document == NULL) { if (zathura == NULL || zathura->ui.session == NULL || zathura->document == NULL) {
return; return;
@ -77,13 +77,13 @@ cb_print_end(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext*
if (file_path != NULL) { if (file_path != NULL) {
girara_statusbar_item_set_text(zathura->ui.session, girara_statusbar_item_set_text(zathura->ui.session,
zathura->ui.statusbar.file, file_path); zathura->ui.statusbar.file, file_path);
} }
} }
static void static void
cb_print_draw_page(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext* cb_print_draw_page(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext*
context, gint page_number, zathura_t* zathura) context, gint page_number, zathura_t* zathura)
{ {
if (context == NULL || zathura == NULL || zathura->document == NULL || if (context == NULL || zathura == NULL || zathura->document == NULL ||
zathura->ui.session == NULL || zathura->ui.statusbar.file == NULL) { zathura->ui.session == NULL || zathura->ui.statusbar.file == NULL) {
@ -93,7 +93,7 @@ cb_print_draw_page(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext*
/* update statusbar */ /* update statusbar */
char* tmp = g_strdup_printf("Printing %d...", page_number); char* tmp = g_strdup_printf("Printing %d...", page_number);
girara_statusbar_item_set_text(zathura->ui.session, girara_statusbar_item_set_text(zathura->ui.session,
zathura->ui.statusbar.file, tmp); zathura->ui.statusbar.file, tmp);
g_free(tmp); g_free(tmp);
/* render page */ /* render page */
@ -111,8 +111,8 @@ cb_print_draw_page(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext*
static void static void
cb_print_request_page_setup(GtkPrintOperation* UNUSED(print_operation), cb_print_request_page_setup(GtkPrintOperation* UNUSED(print_operation),
GtkPrintContext* UNUSED(context), gint page_number, GtkPageSetup* setup, GtkPrintContext* UNUSED(context), gint page_number, GtkPageSetup* setup,
zathura_t* zathura) zathura_t* zathura)
{ {
if (zathura == NULL || zathura->document == NULL) { if (zathura == NULL || zathura->document == NULL) {
return; return;

View file

@ -17,8 +17,7 @@ static void render_job(void* data, void* user_data);
static bool render(zathura_t* zathura, zathura_page_t* page); static bool render(zathura_t* zathura, zathura_page_t* page);
static gint render_thread_sort(gconstpointer a, gconstpointer b, gpointer data); static gint render_thread_sort(gconstpointer a, gconstpointer b, gpointer data);
struct render_thread_s struct render_thread_s {
{
GThreadPool* pool; /**< Pool of threads */ GThreadPool* pool; /**< Pool of threads */
GStaticMutex mutex; /**< Render lock */ GStaticMutex mutex; /**< Render lock */
bool about_to_close; /**< Render thread is to be freed */ bool about_to_close; /**< Render thread is to be freed */

View file

@ -20,7 +20,7 @@
bool bool
sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument), sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument),
girara_event_t* UNUSED(event), unsigned int UNUSED(t)) girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
@ -52,7 +52,7 @@ sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument),
bool bool
sc_adjust_window(girara_session_t* session, girara_argument_t* argument, sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
girara_event_t* UNUSED(event), unsigned int UNUSED(t)) girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
@ -173,7 +173,7 @@ error_ret:
bool bool
sc_change_mode(girara_session_t* session, girara_argument_t* argument, sc_change_mode(girara_session_t* session, girara_argument_t* argument,
girara_event_t* UNUSED(event), unsigned int UNUSED(t)) girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
@ -238,7 +238,7 @@ sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, girara
bool bool
sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument), sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument),
girara_event_t* UNUSED(event), unsigned int UNUSED(t)) girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
@ -332,14 +332,14 @@ sc_mouse_scroll(girara_session_t* session, girara_argument_t* argument, girara_e
GtkAdjustment* y_adj = NULL; GtkAdjustment* y_adj = NULL;
switch (event->type) { switch (event->type) {
/* scroll */ /* scroll */
case GIRARA_EVENT_SCROLL_UP: case GIRARA_EVENT_SCROLL_UP:
case GIRARA_EVENT_SCROLL_DOWN: case GIRARA_EVENT_SCROLL_DOWN:
case GIRARA_EVENT_SCROLL_LEFT: case GIRARA_EVENT_SCROLL_LEFT:
case GIRARA_EVENT_SCROLL_RIGHT: case GIRARA_EVENT_SCROLL_RIGHT:
return sc_scroll(session, argument, NULL, t); return sc_scroll(session, argument, NULL, t);
/* drag */ /* drag */
case GIRARA_EVENT_BUTTON_PRESS: case GIRARA_EVENT_BUTTON_PRESS:
x = event->x; x = event->x;
y = event->y; y = event->y;
@ -360,7 +360,7 @@ sc_mouse_scroll(girara_session_t* session, girara_argument_t* argument, girara_e
set_adjustment(y_adj, gtk_adjustment_get_value(y_adj) - (event->y - y)); set_adjustment(y_adj, gtk_adjustment_get_value(y_adj) - (event->y - y));
break; break;
/* unhandled events */ /* unhandled events */
default: default:
break; break;
} }
@ -398,7 +398,7 @@ sc_mouse_zoom(girara_session_t* session, girara_argument_t* argument, girara_eve
bool bool
sc_navigate(girara_session_t* session, girara_argument_t* argument, sc_navigate(girara_session_t* session, girara_argument_t* argument,
girara_event_t* UNUSED(event), unsigned int t) girara_event_t* UNUSED(event), unsigned int t)
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
@ -446,7 +446,7 @@ sc_navigate(girara_session_t* session, girara_argument_t* argument,
bool bool
sc_print(girara_session_t* session, girara_argument_t* UNUSED(argument), sc_print(girara_session_t* session, girara_argument_t* UNUSED(argument),
girara_event_t* UNUSED(event), unsigned int UNUSED(t)) girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
@ -464,7 +464,7 @@ sc_print(girara_session_t* session, girara_argument_t* UNUSED(argument),
bool bool
sc_recolor(girara_session_t* session, girara_argument_t* UNUSED(argument), sc_recolor(girara_session_t* session, girara_argument_t* UNUSED(argument),
girara_event_t* UNUSED(event), unsigned int UNUSED(t)) girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
@ -478,7 +478,7 @@ sc_recolor(girara_session_t* session, girara_argument_t* UNUSED(argument),
bool bool
sc_reload(girara_session_t* session, girara_argument_t* UNUSED(argument), sc_reload(girara_session_t* session, girara_argument_t* UNUSED(argument),
girara_event_t* UNUSED(event), unsigned int UNUSED(t)) girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
@ -499,7 +499,7 @@ sc_reload(girara_session_t* session, girara_argument_t* UNUSED(argument),
bool bool
sc_rotate(girara_session_t* session, girara_argument_t* argument, sc_rotate(girara_session_t* session, girara_argument_t* argument,
girara_event_t* UNUSED(event), unsigned int t) girara_event_t* UNUSED(event), unsigned int t)
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
@ -532,7 +532,7 @@ sc_rotate(girara_session_t* session, girara_argument_t* argument,
bool bool
sc_scroll(girara_session_t* session, girara_argument_t* argument, sc_scroll(girara_session_t* session, girara_argument_t* argument,
girara_event_t* UNUSED(event), unsigned int UNUSED(t)) girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
@ -544,7 +544,7 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument,
GtkAdjustment* adjustment = NULL; GtkAdjustment* adjustment = NULL;
if ( (argument->n == LEFT) || (argument->n == FULL_LEFT) || (argument->n == HALF_LEFT) || if ( (argument->n == LEFT) || (argument->n == FULL_LEFT) || (argument->n == HALF_LEFT) ||
(argument->n == RIGHT) || (argument->n == FULL_RIGHT) || (argument->n == HALF_RIGHT)) { (argument->n == RIGHT) || (argument->n == FULL_RIGHT) || (argument->n == HALF_RIGHT)) {
adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view)); adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
} else { } else {
adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view)); adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
@ -704,7 +704,7 @@ sc_jumplist(girara_session_t* session, girara_argument_t* argument, girara_event
bool bool
sc_search(girara_session_t* session, girara_argument_t* argument, sc_search(girara_session_t* session, girara_argument_t* argument,
girara_event_t* UNUSED(event), unsigned int UNUSED(t)) girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
@ -730,7 +730,7 @@ sc_search(girara_session_t* session, girara_argument_t* argument,
int num_search_results = 0, current = -1; int num_search_results = 0, current = -1;
g_object_get(page_widget, "search-current", &current, g_object_get(page_widget, "search-current", &current,
"search-length", &num_search_results, NULL); "search-length", &num_search_results, NULL);
if (num_search_results == 0 || current == -1) { if (num_search_results == 0 || current == -1) {
continue; continue;
} }
@ -796,7 +796,7 @@ sc_search(girara_session_t* session, girara_argument_t* argument,
bool bool
sc_navigate_index(girara_session_t* session, girara_argument_t* argument, sc_navigate_index(girara_session_t* session, girara_argument_t* argument,
girara_event_t* UNUSED(event), unsigned int UNUSED(t)) girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
@ -833,7 +833,7 @@ sc_navigate_index(girara_session_t* session, girara_argument_t* argument,
gtk_tree_model_get_iter(model, &iter, path); gtk_tree_model_get_iter(model, &iter, path);
/* select last child */ /* select last child */
gtk_tree_model_iter_nth_child(model, &child_iter, &iter, gtk_tree_model_iter_nth_child(model, &child_iter, &iter,
gtk_tree_model_iter_n_children(model, &iter)-1); gtk_tree_model_iter_n_children(model, &iter)-1);
gtk_tree_path_free(path); gtk_tree_path_free(path);
path = gtk_tree_model_get_path(model, &child_iter); path = gtk_tree_model_get_path(model, &child_iter);
} }
@ -841,7 +841,7 @@ sc_navigate_index(girara_session_t* session, girara_argument_t* argument,
break; break;
case COLLAPSE: case COLLAPSE:
if (gtk_tree_view_collapse_row(tree_view, path) == FALSE if (gtk_tree_view_collapse_row(tree_view, path) == FALSE
&& gtk_tree_path_get_depth(path) > 1) { && gtk_tree_path_get_depth(path) > 1) {
gtk_tree_path_up(path); gtk_tree_path_up(path);
gtk_tree_view_collapse_row(tree_view, path); gtk_tree_view_collapse_row(tree_view, path);
} }
@ -857,7 +857,7 @@ sc_navigate_index(girara_session_t* session, girara_argument_t* argument,
break; break;
} }
} while((is_valid_path = (gtk_tree_path_get_depth(path) > 1)) } while((is_valid_path = (gtk_tree_path_get_depth(path) > 1))
&& gtk_tree_path_up(path)); && gtk_tree_path_up(path));
} }
break; break;
case EXPAND: case EXPAND:
@ -891,7 +891,7 @@ sc_navigate_index(girara_session_t* session, girara_argument_t* argument,
bool bool
sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argument), sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argument),
girara_event_t* UNUSED(event), unsigned int UNUSED(t)) girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
@ -915,7 +915,7 @@ sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argument),
} }
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(zathura->ui.index), gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(zathura->ui.index),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
/* create index */ /* create index */
document_index = zathura_document_index_generate(zathura->document, NULL); document_index = zathura_document_index_generate(zathura->document, NULL);
@ -1010,7 +1010,7 @@ error_ret:
bool bool
sc_toggle_page_mode(girara_session_t* session, girara_argument_t* sc_toggle_page_mode(girara_session_t* session, girara_argument_t*
UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t)) UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
@ -1039,7 +1039,7 @@ sc_toggle_page_mode(girara_session_t* session, girara_argument_t*
bool bool
sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* sc_toggle_fullscreen(girara_session_t* session, girara_argument_t*
UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t)) UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);
@ -1112,7 +1112,7 @@ sc_toggle_fullscreen(girara_session_t* session, girara_argument_t*
bool bool
sc_quit(girara_session_t* session, girara_argument_t* UNUSED(argument), sc_quit(girara_session_t* session, girara_argument_t* UNUSED(argument),
girara_event_t* UNUSED(event), unsigned int UNUSED(t)) girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
@ -1126,7 +1126,7 @@ sc_quit(girara_session_t* session, girara_argument_t* UNUSED(argument),
bool bool
sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t* sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t*
UNUSED(event), unsigned int t) UNUSED(event), unsigned int t)
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false); g_return_val_if_fail(session->global.data != NULL, false);

View file

@ -103,7 +103,8 @@ synctex_record_hits(zathura_t* zathura, int page_idx, girara_list_t* hits, bool
} }
static double static double
scan_float(GScanner* scanner) { scan_float(GScanner* scanner)
{
switch (g_scanner_get_next_token(scanner)) { switch (g_scanner_get_next_token(scanner)) {
case G_TOKEN_FLOAT: case G_TOKEN_FLOAT:
return g_scanner_cur_value(scanner).v_float; return g_scanner_cur_value(scanner).v_float;

View file

@ -72,14 +72,14 @@ girara_list_t*
zathura_document_information_entry_list_new() zathura_document_information_entry_list_new()
{ {
girara_list_t* list = girara_list_new2((girara_free_function_t) girara_list_t* list = girara_list_new2((girara_free_function_t)
zathura_document_information_entry_free); zathura_document_information_entry_free);
return list; return list;
} }
zathura_document_information_entry_t* zathura_document_information_entry_t*
zathura_document_information_entry_new(zathura_document_information_type_t type, zathura_document_information_entry_new(zathura_document_information_type_t type,
const char* value) const char* value)
{ {
if (value == NULL) { if (value == NULL) {
return NULL; return NULL;

79
utils.c
View file

@ -34,8 +34,7 @@ file_get_extension(const char* path)
} }
unsigned int i = strlen(path); unsigned int i = strlen(path);
for (; i > 0; i--) for (; i > 0; i--) {
{
if (*(path + i) != '.') { if (*(path + i) != '.') {
continue; continue;
} else { } else {
@ -146,31 +145,31 @@ execute_command(char* const argv[], char** output)
void void
document_index_build(GtkTreeModel* model, GtkTreeIter* parent, document_index_build(GtkTreeModel* model, GtkTreeIter* parent,
girara_tree_node_t* tree) girara_tree_node_t* tree)
{ {
girara_list_t* list = girara_node_get_children(tree); girara_list_t* list = girara_node_get_children(tree);
GIRARA_LIST_FOREACH(list, girara_tree_node_t*, iter, node) GIRARA_LIST_FOREACH(list, girara_tree_node_t*, iter, node)
zathura_index_element_t* index_element = (zathura_index_element_t*)girara_node_get_data(node); zathura_index_element_t* index_element = (zathura_index_element_t*)girara_node_get_data(node);
zathura_link_type_t type = zathura_link_get_type(index_element->link); zathura_link_type_t type = zathura_link_get_type(index_element->link);
zathura_link_target_t target = zathura_link_get_target(index_element->link); zathura_link_target_t target = zathura_link_get_target(index_element->link);
gchar* description = NULL; gchar* description = NULL;
if (type == ZATHURA_LINK_GOTO_DEST) { if (type == ZATHURA_LINK_GOTO_DEST) {
description = g_strdup_printf("Page %d", target.page_number + 1); description = g_strdup_printf("Page %d", target.page_number + 1);
} else { } else {
description = g_strdup(target.value); description = g_strdup(target.value);
} }
GtkTreeIter tree_iter; GtkTreeIter tree_iter;
gtk_tree_store_append(GTK_TREE_STORE(model), &tree_iter, parent); gtk_tree_store_append(GTK_TREE_STORE(model), &tree_iter, parent);
gtk_tree_store_set(GTK_TREE_STORE(model), &tree_iter, 0, index_element->title, 1, description, 2, index_element, -1); gtk_tree_store_set(GTK_TREE_STORE(model), &tree_iter, 0, index_element->title, 1, description, 2, index_element, -1);
g_object_weak_ref(G_OBJECT(model), (GWeakNotify) zathura_index_element_free, index_element); g_object_weak_ref(G_OBJECT(model), (GWeakNotify) zathura_index_element_free, index_element);
g_free(description); g_free(description);
if (girara_node_get_num_children(node) > 0) { if (girara_node_get_num_children(node) > 0) {
document_index_build(model, &tree_iter, node); document_index_build(model, &tree_iter, node);
} }
GIRARA_LIST_FOREACH_END(list, gchar*, iter, name); GIRARA_LIST_FOREACH_END(list, gchar*, iter, name);
} }
@ -183,7 +182,7 @@ page_calculate_offset(zathura_t* zathura, zathura_page_t* page, page_offset_t* o
GtkWidget* widget = zathura_page_get_widget(zathura, page); GtkWidget* widget = zathura_page_get_widget(zathura, page);
g_return_if_fail(gtk_widget_translate_coordinates(widget, g_return_if_fail(gtk_widget_translate_coordinates(widget,
zathura->ui.page_widget, 0, 0, &(offset->x), &(offset->y)) == true); zathura->ui.page_widget, 0, 0, &(offset->x), &(offset->y)) == true);
} }
zathura_rectangle_t rotate_rectangle(zathura_rectangle_t rectangle, unsigned int degree, int height, int width) zathura_rectangle_t rotate_rectangle(zathura_rectangle_t rectangle, unsigned int degree, int height, int width)
@ -274,7 +273,7 @@ void
set_adjustment(GtkAdjustment* adjustment, gdouble value) set_adjustment(GtkAdjustment* adjustment, gdouble value)
{ {
gtk_adjustment_set_value(adjustment, MAX(gtk_adjustment_get_lower(adjustment), gtk_adjustment_set_value(adjustment, MAX(gtk_adjustment_get_lower(adjustment),
MIN(gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_page_size(adjustment), value))); MIN(gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_page_size(adjustment), value)));
} }
void void
@ -357,9 +356,9 @@ document_draw_search_results(zathura_t* zathura, bool value)
char* char*
zathura_get_version_string(zathura_t* zathura, bool markup) zathura_get_version_string(zathura_t* zathura, bool markup)
{ {
if (zathura == NULL) { if (zathura == NULL) {
return NULL; return NULL;
} }
GString* string = g_string_new(NULL); GString* string = g_string_new(NULL);
@ -368,30 +367,30 @@ zathura_get_version_string(zathura_t* zathura, bool markup)
g_string_append(string, zathura_version); g_string_append(string, zathura_version);
g_free(zathura_version); g_free(zathura_version);
char* format = (markup == true) ? "\n<i>(plugin)</i> %s (%d.%d.%d) <i>(%s)</i>" : "\n(plugin) %s (%d.%d.%d) (%s)"; char* format = (markup == true) ? "\n<i>(plugin)</i> %s (%d.%d.%d) <i>(%s)</i>" : "\n(plugin) %s (%d.%d.%d) (%s)";
/* plugin information */ /* plugin information */
girara_list_t* plugins = zathura_plugin_manager_get_plugins(zathura->plugins.manager); girara_list_t* plugins = zathura_plugin_manager_get_plugins(zathura->plugins.manager);
if (plugins != NULL) { if (plugins != NULL) {
GIRARA_LIST_FOREACH(plugins, zathura_plugin_t*, iter, plugin) GIRARA_LIST_FOREACH(plugins, zathura_plugin_t*, iter, plugin)
char* name = zathura_plugin_get_name(plugin); char* name = zathura_plugin_get_name(plugin);
zathura_plugin_version_t version = zathura_plugin_get_version(plugin); zathura_plugin_version_t version = zathura_plugin_get_version(plugin);
char* text = g_strdup_printf(format, char* text = g_strdup_printf(format,
(name == NULL) ? "-" : name, (name == NULL) ? "-" : name,
version.major, version.major,
version.minor, version.minor,
version.rev, version.rev,
zathura_plugin_get_path(plugin) zathura_plugin_get_path(plugin)
); );
g_string_append(string, text); g_string_append(string, text);
g_free(text); g_free(text);
GIRARA_LIST_FOREACH_END(plugins, zathura_plugin_t*, iter, plugin); GIRARA_LIST_FOREACH_END(plugins, zathura_plugin_t*, iter, plugin);
} }
char* version = string->str; char* version = string->str;
g_string_free(string, FALSE); g_string_free(string, FALSE);
return version; return version;
} }
char* char*

View file

@ -33,21 +33,18 @@
#include "page-widget.h" #include "page-widget.h"
#include "plugin.h" #include "plugin.h"
typedef struct zathura_document_info_s typedef struct zathura_document_info_s {
{
zathura_t* zathura; zathura_t* zathura;
const char* path; const char* path;
const char* password; const char* password;
} zathura_document_info_t; } zathura_document_info_t;
typedef struct page_set_delayed_s typedef struct page_set_delayed_s {
{
zathura_t* zathura; zathura_t* zathura;
unsigned int page; unsigned int page;
} page_set_delayed_t; } page_set_delayed_t;
typedef struct position_set_delayed_s typedef struct position_set_delayed_s {
{
zathura_t* zathura; zathura_t* zathura;
double position_x; double position_x;
double position_y; double position_y;
@ -234,7 +231,7 @@ zathura_init(zathura_t* zathura)
/* bookmarks */ /* bookmarks */
zathura->bookmarks.bookmarks = girara_sorted_list_new2((girara_compare_function_t) zathura_bookmarks_compare, zathura->bookmarks.bookmarks = girara_sorted_list_new2((girara_compare_function_t) zathura_bookmarks_compare,
(girara_free_function_t) zathura_bookmark_free); (girara_free_function_t) zathura_bookmark_free);
/* add even to purge old pages */ /* add even to purge old pages */
int interval = 30; int interval = 30;
@ -368,14 +365,14 @@ zathura_set_plugin_dir(zathura_t* zathura, const char* dir)
if (dir != NULL) { if (dir != NULL) {
girara_list_t* paths = girara_split_path_array(dir); girara_list_t* paths = girara_split_path_array(dir);
GIRARA_LIST_FOREACH(paths, char*, iter, path) GIRARA_LIST_FOREACH(paths, char*, iter, path)
zathura_plugin_manager_add_dir(zathura->plugins.manager, path); zathura_plugin_manager_add_dir(zathura->plugins.manager, path);
GIRARA_LIST_FOREACH_END(paths, char*, iter, path); GIRARA_LIST_FOREACH_END(paths, char*, iter, path);
girara_list_free(paths); girara_list_free(paths);
} else { } else {
#ifdef ZATHURA_PLUGINDIR #ifdef ZATHURA_PLUGINDIR
girara_list_t* paths = girara_split_path_array(ZATHURA_PLUGINDIR); girara_list_t* paths = girara_split_path_array(ZATHURA_PLUGINDIR);
GIRARA_LIST_FOREACH(paths, char*, iter, path) GIRARA_LIST_FOREACH(paths, char*, iter, path)
zathura_plugin_manager_add_dir(zathura->plugins.manager, path); zathura_plugin_manager_add_dir(zathura->plugins.manager, path);
GIRARA_LIST_FOREACH_END(paths, char*, iter, path); GIRARA_LIST_FOREACH_END(paths, char*, iter, path);
girara_list_free(paths); girara_list_free(paths);
#endif #endif
@ -478,7 +475,7 @@ document_info_open(gpointer data)
file = prepare_document_open_from_stdin(document_info->zathura); file = prepare_document_open_from_stdin(document_info->zathura);
if (file == NULL) { if (file == NULL) {
girara_notify(document_info->zathura->ui.session, GIRARA_ERROR, girara_notify(document_info->zathura->ui.session, GIRARA_ERROR,
"Could not read file from stdin and write it to a temporary file."); "Could not read file from stdin and write it to a temporary file.");
} else { } else {
document_info->zathura->stdin_support.file = g_strdup(file); document_info->zathura->stdin_support.file = g_strdup(file);
} }
@ -515,7 +512,7 @@ document_open(zathura_t* zathura, const char* path, const char* password)
if (path != NULL) { if (path != NULL) {
password_dialog_info->path = g_strdup(path); password_dialog_info->path = g_strdup(path);
girara_dialog(zathura->ui.session, "Enter password:", true, NULL, girara_dialog(zathura->ui.session, "Enter password:", true, NULL,
(girara_callback_inputbar_activate_t) cb_password_dialog, password_dialog_info); (girara_callback_inputbar_activate_t) cb_password_dialog, password_dialog_info);
goto error_out; goto error_out;
} else { } else {
free(password_dialog_info); free(password_dialog_info);
@ -755,8 +752,7 @@ document_save(zathura_t* zathura, const char* path, bool overwrite)
g_return_val_if_fail(path, false); g_return_val_if_fail(path, false);
gchar* file_path = girara_fix_path(path); gchar* file_path = girara_fix_path(path);
if ((overwrite == false) && g_file_test(file_path, G_FILE_TEST_EXISTS)) if ((overwrite == false) && g_file_test(file_path, G_FILE_TEST_EXISTS)) {
{
girara_error("File already exists: %s. Use :write! to overwrite it.", file_path); girara_error("File already exists: %s. Use :write! to overwrite it.", file_path);
g_free(file_path); g_free(file_path);
return false; return false;
@ -960,14 +956,14 @@ page_widget_set_mode(zathura_t* zathura, unsigned int pages_per_row, unsigned in
pages_per_row = 1; pages_per_row = 1;
} }
/* ensure: 0 < first_page_column <= pages_per_row */ /* ensure: 0 < first_page_column <= pages_per_row */
if (first_page_column < 1) { if (first_page_column < 1) {
first_page_column = 1; first_page_column = 1;
} }
if (first_page_column > pages_per_row) { if (first_page_column > pages_per_row) {
first_page_column = ((first_page_column - 1) % pages_per_row) + 1; first_page_column = ((first_page_column - 1) % pages_per_row) + 1;
} }
if (zathura->document == NULL) { if (zathura->document == NULL) {
return; return;
@ -1054,7 +1050,8 @@ position_set_delayed(zathura_t* zathura, double position_x, double position_y)
zathura_jump_t* zathura_jump_t*
zathura_jumplist_current(zathura_t* zathura) { zathura_jumplist_current(zathura_t* zathura)
{
if (zathura->jumplist.cur != NULL) { if (zathura->jumplist.cur != NULL) {
return girara_list_iterator_data(zathura->jumplist.cur); return girara_list_iterator_data(zathura->jumplist.cur);
} else { } else {
@ -1063,21 +1060,24 @@ zathura_jumplist_current(zathura_t* zathura) {
} }
void void
zathura_jumplist_forward(zathura_t* zathura) { zathura_jumplist_forward(zathura_t* zathura)
{
if (girara_list_iterator_has_next(zathura->jumplist.cur)) { if (girara_list_iterator_has_next(zathura->jumplist.cur)) {
girara_list_iterator_next(zathura->jumplist.cur); girara_list_iterator_next(zathura->jumplist.cur);
} }
} }
void void
zathura_jumplist_backward(zathura_t* zathura) { zathura_jumplist_backward(zathura_t* zathura)
{
if (girara_list_iterator_has_previous(zathura->jumplist.cur)) { if (girara_list_iterator_has_previous(zathura->jumplist.cur)) {
girara_list_iterator_previous(zathura->jumplist.cur); girara_list_iterator_previous(zathura->jumplist.cur);
} }
} }
void void
zathura_jumplist_append_jump(zathura_t* zathura) { zathura_jumplist_append_jump(zathura_t* zathura)
{
zathura_jump_t *jump = g_malloc(sizeof(zathura_jump_t)); zathura_jump_t *jump = g_malloc(sizeof(zathura_jump_t));
if (jump != NULL) { if (jump != NULL) {
jump->page = 0; jump->page = 0;
@ -1109,7 +1109,8 @@ zathura_jumplist_append_jump(zathura_t* zathura) {
} }
void void
zathura_jumplist_add(zathura_t* zathura) { zathura_jumplist_add(zathura_t* zathura)
{
if (zathura->jumplist.list != NULL) { if (zathura->jumplist.list != NULL) {
unsigned int pagenum = zathura_document_get_current_page_number(zathura->document); unsigned int pagenum = zathura_document_get_current_page_number(zathura->document);
zathura_jump_t* cur = zathura_jumplist_current(zathura); zathura_jump_t* cur = zathura_jumplist_current(zathura);
@ -1125,7 +1126,8 @@ zathura_jumplist_add(zathura_t* zathura) {
void void
zathura_jumplist_save(zathura_t* zathura) { zathura_jumplist_save(zathura_t* zathura)
{
zathura_jump_t* cur = zathura_jumplist_current(zathura); zathura_jump_t* cur = zathura_jumplist_current(zathura);
unsigned int pagenum = zathura_document_get_current_page_number(zathura->document); unsigned int pagenum = zathura_document_get_current_page_number(zathura->document);