mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 08:36:01 +01:00
Merge branch 'develop' of pwmt.org:zathura into develop
This commit is contained in:
commit
5acf8da4de
22 changed files with 118 additions and 53 deletions
31
bookmarks.c
31
bookmarks.c
|
@ -5,18 +5,28 @@
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "document.h"
|
#include "document.h"
|
||||||
|
|
||||||
|
#include <girara/datastructures.h>
|
||||||
|
#include <girara/utils.h>
|
||||||
|
|
||||||
|
static int
|
||||||
|
bookmark_compare_find(const void* item, const void* data)
|
||||||
|
{
|
||||||
|
const zathura_bookmark_t* bookmark = item;
|
||||||
|
const char* id = data;
|
||||||
|
|
||||||
|
return g_strcmp0(bookmark->id, id);
|
||||||
|
}
|
||||||
|
|
||||||
zathura_bookmark_t*
|
zathura_bookmark_t*
|
||||||
zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page)
|
zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail(zathura && zathura->document && zathura->bookmarks.bookmarks, NULL);
|
g_return_val_if_fail(zathura && zathura->document && zathura->bookmarks.bookmarks, NULL);
|
||||||
g_return_val_if_fail(id, NULL);
|
g_return_val_if_fail(id, NULL);
|
||||||
|
|
||||||
GIRARA_LIST_FOREACH(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark)
|
zathura_bookmark_t* old = girara_list_find(zathura->bookmarks.bookmarks, bookmark_compare_find, id);
|
||||||
if (strcmp(bookmark->id, id) == 0) {
|
if (old != NULL) {
|
||||||
girara_list_iterator_free(iter);
|
return NULL;
|
||||||
return NULL;
|
}
|
||||||
}
|
|
||||||
GIRARA_LIST_FOREACH_END(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark);
|
|
||||||
|
|
||||||
zathura_bookmark_t* bookmark = g_malloc0(sizeof(zathura_bookmark_t));
|
zathura_bookmark_t* bookmark = g_malloc0(sizeof(zathura_bookmark_t));
|
||||||
bookmark->id = g_strdup(id);
|
bookmark->id = g_strdup(id);
|
||||||
|
@ -58,14 +68,7 @@ zathura_bookmark_get(zathura_t* zathura, const gchar* id)
|
||||||
g_return_val_if_fail(zathura && zathura->bookmarks.bookmarks, NULL);
|
g_return_val_if_fail(zathura && zathura->bookmarks.bookmarks, NULL);
|
||||||
g_return_val_if_fail(id, NULL);
|
g_return_val_if_fail(id, NULL);
|
||||||
|
|
||||||
GIRARA_LIST_FOREACH(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark)
|
return girara_list_find(zathura->bookmarks.bookmarks, bookmark_compare_find, id);
|
||||||
if (strcmp(bookmark->id, id) == 0) {
|
|
||||||
girara_list_iterator_free(iter);
|
|
||||||
return bookmark;
|
|
||||||
}
|
|
||||||
GIRARA_LIST_FOREACH_END(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
/* See LICENSE file for license and copyright information */
|
/* See LICENSE file for license and copyright information */
|
||||||
|
|
||||||
#include <girara.h>
|
#include <girara/statusbar.h>
|
||||||
|
#include <girara/session.h>
|
||||||
|
#include <girara/settings.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#define CALLBACKS_H
|
#define CALLBACKS_H
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <girara.h>
|
#include <girara/types.h>
|
||||||
|
|
||||||
#include "zathura.h"
|
#include "zathura.h"
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
#include "document.h"
|
#include "document.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
#include <girara/session.h>
|
||||||
|
#include <girara/datastructures.h>
|
||||||
|
|
||||||
bool
|
bool
|
||||||
cmd_bookmark_create(girara_session_t* session, girara_list_t* argument_list)
|
cmd_bookmark_create(girara_session_t* session, girara_list_t* argument_list)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#define COMMANDS_H
|
#define COMMANDS_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <girara.h>
|
#include <girara/types.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a bookmark
|
* Create a bookmark
|
||||||
|
|
|
@ -10,6 +10,11 @@
|
||||||
#include "completion.h"
|
#include "completion.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
#include <girara/session.h>
|
||||||
|
#include <girara/completion.h>
|
||||||
|
#include <girara/utils.h>
|
||||||
|
#include <girara/datastructures.h>
|
||||||
|
|
||||||
girara_completion_t*
|
girara_completion_t*
|
||||||
cc_open(girara_session_t* session, const char* input)
|
cc_open(girara_session_t* session, const char* input)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#ifndef COMPLETION_H
|
#ifndef COMPLETION_H
|
||||||
#define COMPLETION_H
|
#define COMPLETION_H
|
||||||
|
|
||||||
#include <girara.h>
|
#include <girara/types.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Completion for the open command - Creates a list of accesible directories or
|
* Completion for the open command - Creates a list of accesible directories or
|
||||||
|
|
6
config.c
6
config.c
|
@ -7,6 +7,12 @@
|
||||||
#include "shortcuts.h"
|
#include "shortcuts.h"
|
||||||
#include "zathura.h"
|
#include "zathura.h"
|
||||||
|
|
||||||
|
#include <girara/settings.h>
|
||||||
|
#include <girara/session.h>
|
||||||
|
#include <girara/shortcuts.h>
|
||||||
|
#include <girara/config.h>
|
||||||
|
#include <girara/commands.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
config_load_default(zathura_t* zathura)
|
config_load_default(zathura_t* zathura)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
/* See LICENSE file for license and copyright information */
|
/* See LICENSE file for license and copyright information */
|
||||||
|
|
||||||
#include <girara.h>
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <girara/utils.h>
|
||||||
|
#include <girara/datastructures.h>
|
||||||
|
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
#include <girara.h>
|
#include <girara/utils.h>
|
||||||
|
#include <girara/datastructures.h>
|
||||||
|
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#define DATABASE_H
|
#define DATABASE_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <girara.h>
|
#include <girara/types.h>
|
||||||
|
|
||||||
#include "zathura.h"
|
#include "zathura.h"
|
||||||
#include "bookmarks.h"
|
#include "bookmarks.h"
|
||||||
|
|
72
document.c
72
document.c
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -15,6 +16,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
#include "document.h"
|
#include "document.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
@ -22,6 +24,10 @@
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
|
||||||
|
#include <girara/datastructures.h>
|
||||||
|
#include <girara/utils.h>
|
||||||
|
#include <girara/statusbar.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register document plugin
|
* Register document plugin
|
||||||
*/
|
*/
|
||||||
|
@ -144,6 +150,47 @@ zathura_document_plugin_register(zathura_t* zathura, zathura_document_plugin_t*
|
||||||
return atleastone;
|
return atleastone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const gchar*
|
||||||
|
guess_type(const char* path)
|
||||||
|
{
|
||||||
|
gboolean uncertain;
|
||||||
|
const gchar* content_type = g_content_type_guess(path, NULL, 0, &uncertain);
|
||||||
|
if (content_type == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE* f = fopen(path, "r");
|
||||||
|
if (f == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int fd = fileno(f);
|
||||||
|
guchar* content = NULL;
|
||||||
|
size_t length = 0u;
|
||||||
|
while (uncertain == TRUE) {
|
||||||
|
g_free((void*)content_type);
|
||||||
|
content_type = NULL;
|
||||||
|
|
||||||
|
content = g_realloc(content, length + BUFSIZ);
|
||||||
|
const ssize_t r = read(fd, content + length, BUFSIZ);
|
||||||
|
if (r == -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
length += r;
|
||||||
|
content_type = g_content_type_guess(NULL, content, length, &uncertain);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
if (uncertain == TRUE) {
|
||||||
|
g_free((void*)content_type);
|
||||||
|
content_type = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free(content);
|
||||||
|
return content_type;
|
||||||
|
}
|
||||||
|
|
||||||
zathura_document_t*
|
zathura_document_t*
|
||||||
zathura_document_open(zathura_t* zathura, const char* path, const char* password)
|
zathura_document_open(zathura_t* zathura, const char* path, const char* password)
|
||||||
{
|
{
|
||||||
|
@ -156,33 +203,12 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean uncertain;
|
const gchar* content_type = guess_type(path);
|
||||||
const gchar* content_type = g_content_type_guess(path, NULL, 0, &uncertain);
|
|
||||||
if (content_type == NULL) {
|
if (content_type == NULL) {
|
||||||
girara_error("Could not determine file type");
|
girara_error("Could not determine file type.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uncertain == TRUE) {
|
|
||||||
g_free((void*)content_type);
|
|
||||||
content_type = NULL;
|
|
||||||
|
|
||||||
gchar* contents = NULL;
|
|
||||||
gsize length = 0;
|
|
||||||
if (g_file_get_contents(path, &contents, &length, NULL) == FALSE) {
|
|
||||||
girara_error("Could not determine file type");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
content_type = g_content_type_guess(NULL, (guchar*) contents, length, &uncertain);
|
|
||||||
g_free(contents);
|
|
||||||
if (content_type == NULL || uncertain == TRUE) {
|
|
||||||
g_free((void*)content_type);
|
|
||||||
girara_error("Could not determine file type");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* determine real path */
|
/* determine real path */
|
||||||
long path_max;
|
long path_max;
|
||||||
#ifdef PATH_MAX
|
#ifdef PATH_MAX
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include <girara-datastructures.h>
|
#include <girara/types.h>
|
||||||
#include "zathura.h"
|
#include "zathura.h"
|
||||||
|
|
||||||
#define PLUGIN_REGISTER_FUNCTION "plugin_register"
|
#define PLUGIN_REGISTER_FUNCTION "plugin_register"
|
||||||
|
|
3
print.c
3
print.c
|
@ -4,6 +4,9 @@
|
||||||
#include "document.h"
|
#include "document.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
|
||||||
|
#include <girara/utils.h>
|
||||||
|
#include <girara/statusbar.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
print(zathura_t* zathura)
|
print(zathura_t* zathura)
|
||||||
{
|
{
|
||||||
|
|
3
render.c
3
render.c
|
@ -1,6 +1,9 @@
|
||||||
/* See LICENSE file for license and copyright information */
|
/* See LICENSE file for license and copyright information */
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <girara/datastructures.h>
|
||||||
|
#include <girara/utils.h>
|
||||||
|
#include <girara/session.h>
|
||||||
|
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
#include "zathura.h"
|
#include "zathura.h"
|
||||||
|
|
2
render.h
2
render.h
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <girara-datastructures.h>
|
#include <girara/types.h>
|
||||||
|
|
||||||
#include "zathura.h"
|
#include "zathura.h"
|
||||||
#include "callbacks.h"
|
#include "callbacks.h"
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
/* See LICENSE file for license and copyright information */
|
/* See LICENSE file for license and copyright information */
|
||||||
|
|
||||||
#include <girara.h>
|
#include <girara/session.h>
|
||||||
|
#include <girara/settings.h>
|
||||||
|
#include <girara/datastructures.h>
|
||||||
|
#include <girara/shortcuts.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#include "callbacks.h"
|
#include "callbacks.h"
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#ifndef SHORTCUTS_H
|
#ifndef SHORTCUTS_H
|
||||||
#define SHORTCUTS_H
|
#define SHORTCUTS_H
|
||||||
|
|
||||||
#include <girara.h>
|
#include <girara/types.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abort the current action and return to normal mode
|
* Abort the current action and return to normal mode
|
||||||
|
|
2
utils.c
2
utils.c
|
@ -12,6 +12,8 @@
|
||||||
#include "zathura.h"
|
#include "zathura.h"
|
||||||
#include "document.h"
|
#include "document.h"
|
||||||
|
|
||||||
|
#include <girara/datastructures.h>
|
||||||
|
|
||||||
#define BLOCK_SIZE 64
|
#define BLOCK_SIZE 64
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
2
utils.h
2
utils.h
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <girara.h>
|
#include <girara/types.h>
|
||||||
|
|
||||||
#include "document.h"
|
#include "document.h"
|
||||||
|
|
||||||
|
|
12
zathura.c
12
zathura.c
|
@ -1,11 +1,16 @@
|
||||||
/* See LICENSE file for license and copyright information */
|
/* See LICENSE file for license and copyright information */
|
||||||
|
|
||||||
#define _BSD_SOURCE
|
#define _BSD_SOURCE
|
||||||
#define _XOPEN_SOURCE 500
|
#define _XOPEN_SOURCE 700
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <girara.h>
|
#include <girara/datastructures.h>
|
||||||
|
#include <girara/utils.h>
|
||||||
|
#include <girara/session.h>
|
||||||
|
#include <girara/statusbar.h>
|
||||||
|
#include <girara/settings.h>
|
||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
|
|
||||||
#include "bookmarks.h"
|
#include "bookmarks.h"
|
||||||
|
@ -348,8 +353,9 @@ document_info_open(gpointer data)
|
||||||
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 {
|
||||||
|
document_info->zathura->stdin_support.file = g_strdup(file);
|
||||||
}
|
}
|
||||||
document_info->zathura->stdin_support.file = file;
|
|
||||||
} else {
|
} else {
|
||||||
file = g_strdup(document_info->path);
|
file = g_strdup(document_info->path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
#define ZATHURA_H
|
#define ZATHURA_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <girara.h>
|
#include <girara/types.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#ifdef UNUSED
|
#ifdef UNUSED
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__)
|
||||||
|
|
Loading…
Reference in a new issue