2010-11-10 20:31:15 +01:00
|
|
|
/* See LICENSE file for license and copyright information */
|
|
|
|
|
2011-10-01 23:29:40 +02:00
|
|
|
#include <string.h>
|
2012-03-24 18:27:10 +01:00
|
|
|
#include <stdlib.h>
|
2012-03-04 18:45:58 +01:00
|
|
|
#include <glib/gi18n.h>
|
2011-10-01 23:29:40 +02:00
|
|
|
|
2010-11-10 20:31:15 +01:00
|
|
|
#include "commands.h"
|
2012-03-24 10:38:48 +01:00
|
|
|
#include "shortcuts.h"
|
2011-09-03 13:40:28 +02:00
|
|
|
#include "bookmarks.h"
|
|
|
|
#include "database.h"
|
2011-10-01 23:29:40 +02:00
|
|
|
#include "document.h"
|
2011-03-12 11:32:24 +01:00
|
|
|
#include "zathura.h"
|
2011-04-29 00:28:19 +02:00
|
|
|
#include "print.h"
|
2011-09-03 13:40:28 +02:00
|
|
|
#include "document.h"
|
2011-10-01 23:29:40 +02:00
|
|
|
#include "utils.h"
|
2012-03-16 14:37:54 +01:00
|
|
|
#include "page-widget.h"
|
2012-03-26 14:44:56 +02:00
|
|
|
#include "page.h"
|
2012-06-13 16:08:33 +02:00
|
|
|
#include "plugin.h"
|
2012-04-06 13:54:17 +02:00
|
|
|
#include "internal.h"
|
2012-04-22 19:12:45 +02:00
|
|
|
#include "render.h"
|
Bookmark the exact position, not just the page number (along with a number of fixes).
This patch adds some enhancements/fixes to the bookmarking feature of Zathura:
- Bookmark the exact vertical and horizontal adjustments values, along with
the page number. This is done in a backward-compatible way for both the
plain and sqlite database backends, so that bookmarks that was taken
previously (bookmarking only the page number) will still work as expected
and won't be lost.
- Fix the issue of not being able to remove bookmarks from the plain
database; removing a bookmark in plain_remove_bookmark using
g_key_file_remove_key corrupts the bookmarks file. This is due to not
truncating the entire bookmarks file in zathura_db_write_key_file_to_file
prior to overriding it with a new one not containing the removed line.
This is why, I guess, plain_remove_bookmark hadn't been implemented as
expected using g_key_file_remove_key, because apparently, someone thought
that the problem is caused by this API.
- Fix not being able to update existing bookmarks persistently; updating a
bookmark works only during the current session, but after the file is
closed and reopened, the updated bookmark still has it's old value. This
is due to changing only the bookmark structure in memory; the proper way
to do it, is to call zathura_db_remove_bookmark on the old bookmark, then
follow that by a call to zathura_db_add_bookmark on a bookmark structure
containing the new position and the same old ID.
- Make zathura_bookmark_add updates the bookmark if it already exists,
rather than doing this externally in cmd_bookmark_create. This allows us
to have all the relevant girara_notify messages in cmd_bookmark_create.
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
2013-06-21 06:12:12 +02:00
|
|
|
#include "adjustment.h"
|
2010-11-10 20:31:15 +01:00
|
|
|
|
2011-10-23 17:01:15 +02:00
|
|
|
#include <girara/session.h>
|
2012-04-22 19:12:45 +02:00
|
|
|
#include <girara/settings.h>
|
2012-08-14 11:45:11 +02:00
|
|
|
#include <girara/commands.h>
|
2011-10-23 17:01:15 +02:00
|
|
|
#include <girara/datastructures.h>
|
2012-01-13 18:54:09 +01:00
|
|
|
#include <girara/utils.h>
|
2011-10-23 17:01:15 +02:00
|
|
|
|
2010-11-10 20:31:15 +01:00
|
|
|
bool
|
2011-10-06 18:07:02 +02:00
|
|
|
cmd_bookmark_create(girara_session_t* session, girara_list_t* argument_list)
|
2010-11-10 20:31:15 +01:00
|
|
|
{
|
2011-10-06 18:07:02 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
if (zathura->document == NULL) {
|
2012-03-04 18:45:58 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("No document opened."));
|
2011-10-06 18:07:02 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned int argc = girara_list_size(argument_list);
|
|
|
|
if (argc != 1) {
|
2012-03-04 18:45:58 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("Invalid number of arguments given."));
|
2011-10-06 18:07:02 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* bookmark_name = girara_list_nth(argument_list, 0);
|
|
|
|
zathura_bookmark_t* bookmark = zathura_bookmark_get(zathura, bookmark_name);
|
Bookmark the exact position, not just the page number (along with a number of fixes).
This patch adds some enhancements/fixes to the bookmarking feature of Zathura:
- Bookmark the exact vertical and horizontal adjustments values, along with
the page number. This is done in a backward-compatible way for both the
plain and sqlite database backends, so that bookmarks that was taken
previously (bookmarking only the page number) will still work as expected
and won't be lost.
- Fix the issue of not being able to remove bookmarks from the plain
database; removing a bookmark in plain_remove_bookmark using
g_key_file_remove_key corrupts the bookmarks file. This is due to not
truncating the entire bookmarks file in zathura_db_write_key_file_to_file
prior to overriding it with a new one not containing the removed line.
This is why, I guess, plain_remove_bookmark hadn't been implemented as
expected using g_key_file_remove_key, because apparently, someone thought
that the problem is caused by this API.
- Fix not being able to update existing bookmarks persistently; updating a
bookmark works only during the current session, but after the file is
closed and reopened, the updated bookmark still has it's old value. This
is due to changing only the bookmark structure in memory; the proper way
to do it, is to call zathura_db_remove_bookmark on the old bookmark, then
follow that by a call to zathura_db_add_bookmark on a bookmark structure
containing the new position and the same old ID.
- Make zathura_bookmark_add updates the bookmark if it already exists,
rather than doing this externally in cmd_bookmark_create. This allows us
to have all the relevant girara_notify messages in cmd_bookmark_create.
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
2013-06-21 06:12:12 +02:00
|
|
|
bool update = bookmark != NULL ? true : false;
|
2011-10-06 18:07:02 +02:00
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
bookmark = zathura_bookmark_add(zathura, bookmark_name, zathura_document_get_current_page_number(zathura->document) + 1);
|
2011-10-06 18:07:02 +02:00
|
|
|
if (bookmark == NULL) {
|
Bookmark the exact position, not just the page number (along with a number of fixes).
This patch adds some enhancements/fixes to the bookmarking feature of Zathura:
- Bookmark the exact vertical and horizontal adjustments values, along with
the page number. This is done in a backward-compatible way for both the
plain and sqlite database backends, so that bookmarks that was taken
previously (bookmarking only the page number) will still work as expected
and won't be lost.
- Fix the issue of not being able to remove bookmarks from the plain
database; removing a bookmark in plain_remove_bookmark using
g_key_file_remove_key corrupts the bookmarks file. This is due to not
truncating the entire bookmarks file in zathura_db_write_key_file_to_file
prior to overriding it with a new one not containing the removed line.
This is why, I guess, plain_remove_bookmark hadn't been implemented as
expected using g_key_file_remove_key, because apparently, someone thought
that the problem is caused by this API.
- Fix not being able to update existing bookmarks persistently; updating a
bookmark works only during the current session, but after the file is
closed and reopened, the updated bookmark still has it's old value. This
is due to changing only the bookmark structure in memory; the proper way
to do it, is to call zathura_db_remove_bookmark on the old bookmark, then
follow that by a call to zathura_db_add_bookmark on a bookmark structure
containing the new position and the same old ID.
- Make zathura_bookmark_add updates the bookmark if it already exists,
rather than doing this externally in cmd_bookmark_create. This allows us
to have all the relevant girara_notify messages in cmd_bookmark_create.
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
2013-06-21 06:12:12 +02:00
|
|
|
if (update == true) {
|
|
|
|
girara_notify(session, GIRARA_ERROR, _("Could not update bookmark: %s"), bookmark_name);
|
|
|
|
} else {
|
|
|
|
girara_notify(session, GIRARA_ERROR, _("Could not create bookmark: %s"), bookmark_name);
|
|
|
|
}
|
2011-10-06 18:07:02 +02:00
|
|
|
return false;
|
Bookmark the exact position, not just the page number (along with a number of fixes).
This patch adds some enhancements/fixes to the bookmarking feature of Zathura:
- Bookmark the exact vertical and horizontal adjustments values, along with
the page number. This is done in a backward-compatible way for both the
plain and sqlite database backends, so that bookmarks that was taken
previously (bookmarking only the page number) will still work as expected
and won't be lost.
- Fix the issue of not being able to remove bookmarks from the plain
database; removing a bookmark in plain_remove_bookmark using
g_key_file_remove_key corrupts the bookmarks file. This is due to not
truncating the entire bookmarks file in zathura_db_write_key_file_to_file
prior to overriding it with a new one not containing the removed line.
This is why, I guess, plain_remove_bookmark hadn't been implemented as
expected using g_key_file_remove_key, because apparently, someone thought
that the problem is caused by this API.
- Fix not being able to update existing bookmarks persistently; updating a
bookmark works only during the current session, but after the file is
closed and reopened, the updated bookmark still has it's old value. This
is due to changing only the bookmark structure in memory; the proper way
to do it, is to call zathura_db_remove_bookmark on the old bookmark, then
follow that by a call to zathura_db_add_bookmark on a bookmark structure
containing the new position and the same old ID.
- Make zathura_bookmark_add updates the bookmark if it already exists,
rather than doing this externally in cmd_bookmark_create. This allows us
to have all the relevant girara_notify messages in cmd_bookmark_create.
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
2013-06-21 06:12:12 +02:00
|
|
|
} else {
|
|
|
|
if (update == true) {
|
|
|
|
girara_notify(session, GIRARA_INFO, _("Bookmark successfully updated: %s"), bookmark_name);
|
|
|
|
} else {
|
|
|
|
girara_notify(session, GIRARA_INFO, _("Bookmark successfully created: %s"), bookmark_name);
|
|
|
|
}
|
2011-10-06 18:07:02 +02:00
|
|
|
}
|
|
|
|
|
2010-11-10 20:31:15 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-04-19 10:38:59 +02:00
|
|
|
cmd_bookmark_delete(girara_session_t* session, girara_list_t* argument_list)
|
2010-11-10 20:31:15 +01:00
|
|
|
{
|
2011-09-03 13:40:28 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
if (zathura->document == NULL) {
|
2012-03-04 18:45:58 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("No document opened."));
|
2011-09-03 13:40:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned int argc = girara_list_size(argument_list);
|
|
|
|
if (argc != 1) {
|
2012-03-04 18:45:58 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("Invalid number of arguments given."));
|
2011-09-03 13:40:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* bookmark = girara_list_nth(argument_list, 0);
|
|
|
|
if (zathura_bookmark_remove(zathura, bookmark)) {
|
2012-03-04 18:45:58 +01:00
|
|
|
girara_notify(session, GIRARA_INFO, _("Removed bookmark: %s"), bookmark);
|
2011-09-03 13:40:28 +02:00
|
|
|
} else {
|
2012-03-04 18:45:58 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("Failed to remove bookmark: %s"), bookmark);
|
2011-09-03 13:40:28 +02:00
|
|
|
}
|
|
|
|
|
2010-11-10 20:31:15 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-10-06 18:01:15 +02:00
|
|
|
cmd_bookmark_open(girara_session_t* session, girara_list_t* argument_list)
|
2010-11-10 20:31:15 +01:00
|
|
|
{
|
2011-10-06 18:01:15 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
if (zathura->document == NULL) {
|
2012-03-04 18:45:58 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("No document opened."));
|
2011-10-06 18:01:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned int argc = girara_list_size(argument_list);
|
|
|
|
if (argc != 1) {
|
2012-03-04 18:45:58 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("Invalid number of arguments given."));
|
2011-10-06 18:01:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* bookmark_name = girara_list_nth(argument_list, 0);
|
|
|
|
zathura_bookmark_t* bookmark = zathura_bookmark_get(zathura, bookmark_name);
|
|
|
|
if (bookmark == NULL) {
|
2012-03-04 18:45:58 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("No such bookmark: %s"), bookmark_name);
|
2011-10-06 18:01:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-09 22:11:44 +02:00
|
|
|
zathura_jumplist_add(zathura);
|
Bookmark the exact position, not just the page number (along with a number of fixes).
This patch adds some enhancements/fixes to the bookmarking feature of Zathura:
- Bookmark the exact vertical and horizontal adjustments values, along with
the page number. This is done in a backward-compatible way for both the
plain and sqlite database backends, so that bookmarks that was taken
previously (bookmarking only the page number) will still work as expected
and won't be lost.
- Fix the issue of not being able to remove bookmarks from the plain
database; removing a bookmark in plain_remove_bookmark using
g_key_file_remove_key corrupts the bookmarks file. This is due to not
truncating the entire bookmarks file in zathura_db_write_key_file_to_file
prior to overriding it with a new one not containing the removed line.
This is why, I guess, plain_remove_bookmark hadn't been implemented as
expected using g_key_file_remove_key, because apparently, someone thought
that the problem is caused by this API.
- Fix not being able to update existing bookmarks persistently; updating a
bookmark works only during the current session, but after the file is
closed and reopened, the updated bookmark still has it's old value. This
is due to changing only the bookmark structure in memory; the proper way
to do it, is to call zathura_db_remove_bookmark on the old bookmark, then
follow that by a call to zathura_db_add_bookmark on a bookmark structure
containing the new position and the same old ID.
- Make zathura_bookmark_add updates the bookmark if it already exists,
rather than doing this externally in cmd_bookmark_create. This allows us
to have all the relevant girara_notify messages in cmd_bookmark_create.
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
2013-06-21 06:12:12 +02:00
|
|
|
if (bookmark->x != DBL_MIN && bookmark->y != DBL_MIN) {
|
|
|
|
GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
|
|
|
|
GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
|
|
|
|
zathura_adjustment_set_value_from_ratio(hadjustment, bookmark->x);
|
|
|
|
zathura_adjustment_set_value_from_ratio(vadjustment, bookmark->y);
|
|
|
|
zathura_document_set_current_page_number(zathura->document, bookmark->page - 1);
|
|
|
|
statusbar_page_number_update(zathura);
|
|
|
|
} else {
|
|
|
|
page_set(zathura, bookmark->page - 1);
|
|
|
|
}
|
2013-06-09 22:11:44 +02:00
|
|
|
zathura_jumplist_add(zathura);
|
|
|
|
|
|
|
|
return true;
|
2010-11-10 20:31:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-21 00:46:03 +02:00
|
|
|
cmd_close(girara_session_t* session, girara_list_t* UNUSED(argument_list))
|
2010-11-10 20:31:15 +01:00
|
|
|
{
|
2011-04-18 18:29:50 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
2011-08-30 23:40:13 +02:00
|
|
|
if (zathura->document == NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-04-18 18:29:50 +02:00
|
|
|
|
2012-02-20 20:07:24 +01:00
|
|
|
document_close(zathura, false);
|
2011-03-12 11:32:24 +01:00
|
|
|
|
2010-11-10 20:31:15 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-10-01 23:29:40 +02:00
|
|
|
cmd_info(girara_session_t* session, girara_list_t* UNUSED(argument_list))
|
2010-11-10 20:31:15 +01:00
|
|
|
{
|
2011-10-01 23:29:40 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
if (zathura->document == NULL) {
|
2012-03-04 18:45:58 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("No document opened."));
|
2011-10-01 23:29:40 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct meta_field {
|
|
|
|
char* name;
|
2012-03-30 18:24:00 +02:00
|
|
|
zathura_document_information_type_t field;
|
2011-10-01 23:29:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct meta_field meta_fields[] = {
|
2012-03-30 18:24:00 +02:00
|
|
|
{ "Title", ZATHURA_DOCUMENT_INFORMATION_TITLE },
|
|
|
|
{ "Author", ZATHURA_DOCUMENT_INFORMATION_AUTHOR },
|
|
|
|
{ "Subject", ZATHURA_DOCUMENT_INFORMATION_SUBJECT },
|
|
|
|
{ "Keywords", ZATHURA_DOCUMENT_INFORMATION_KEYWORDS },
|
|
|
|
{ "Creator", ZATHURA_DOCUMENT_INFORMATION_CREATOR },
|
|
|
|
{ "Producer", ZATHURA_DOCUMENT_INFORMATION_PRODUCER },
|
|
|
|
{ "Creation date", ZATHURA_DOCUMENT_INFORMATION_CREATION_DATE },
|
|
|
|
{ "Modiciation date", ZATHURA_DOCUMENT_INFORMATION_MODIFICATION_DATE }
|
2011-10-01 23:29:40 +02:00
|
|
|
};
|
|
|
|
|
2012-03-30 18:24:00 +02:00
|
|
|
girara_list_t* information = zathura_document_get_information(zathura->document, NULL);
|
|
|
|
if (information == NULL) {
|
|
|
|
girara_notify(session, GIRARA_INFO, _("No information available."));
|
|
|
|
return false;
|
2011-10-01 23:29:40 +02:00
|
|
|
}
|
|
|
|
|
2012-03-30 18:24:00 +02:00
|
|
|
GString* string = g_string_new(NULL);
|
2011-10-01 23:29:40 +02:00
|
|
|
|
2012-03-30 18:24:00 +02:00
|
|
|
GIRARA_LIST_FOREACH(information, zathura_document_information_entry_t*, iter, entry)
|
2012-10-09 01:12:18 +02:00
|
|
|
if (entry != NULL) {
|
|
|
|
for (unsigned int i = 0; i < LENGTH(meta_fields); i++) {
|
|
|
|
if (meta_fields[i].field == entry->type) {
|
|
|
|
char* text = g_strdup_printf("<b>%s:</b> %s\n", meta_fields[i].name, entry->value);
|
|
|
|
g_string_append(string, text);
|
|
|
|
g_free(text);
|
2012-03-30 18:24:00 +02:00
|
|
|
}
|
2011-10-01 23:29:40 +02:00
|
|
|
}
|
2012-10-09 01:12:18 +02:00
|
|
|
}
|
2012-03-30 18:24:00 +02:00
|
|
|
GIRARA_LIST_FOREACH_END(information, zathura_document_information_entry_t*, iter, entry);
|
2011-10-01 23:29:40 +02:00
|
|
|
|
|
|
|
if (strlen(string->str) > 0) {
|
|
|
|
g_string_erase(string, strlen(string->str) - 1, 1);
|
2011-11-19 17:14:02 +01:00
|
|
|
girara_notify(session, GIRARA_INFO, "%s", string->str);
|
2012-03-06 21:55:10 +01:00
|
|
|
} else {
|
|
|
|
girara_notify(session, GIRARA_INFO, _("No information available."));
|
2011-10-01 23:29:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
g_string_free(string, TRUE);
|
|
|
|
|
|
|
|
return false;
|
2010-11-10 20:31:15 +01:00
|
|
|
}
|
|
|
|
|
2011-09-01 13:15:27 +02:00
|
|
|
bool
|
2011-09-21 00:46:03 +02:00
|
|
|
cmd_help(girara_session_t* UNUSED(session), girara_list_t*
|
2012-10-09 01:12:18 +02:00
|
|
|
UNUSED(argument_list))
|
2011-09-01 13:15:27 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-22 19:12:45 +02:00
|
|
|
bool
|
|
|
|
cmd_hlsearch(girara_session_t* session, girara_list_t* UNUSED(argument_list))
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
|
|
|
|
document_draw_search_results(zathura, true);
|
|
|
|
render_all(zathura);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-25 00:24:43 +02:00
|
|
|
bool
|
|
|
|
cmd_open(girara_session_t* session, girara_list_t* argument_list)
|
|
|
|
{
|
2011-08-31 00:08:33 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
|
|
|
|
const int argc = girara_list_size(argument_list);
|
|
|
|
if (argc > 2) {
|
2012-03-04 18:45:58 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("Too many arguments."));
|
2011-08-31 00:08:33 +02:00
|
|
|
return false;
|
2011-10-12 16:18:40 +02:00
|
|
|
} else if (argc >= 1) {
|
2012-02-20 20:07:24 +01:00
|
|
|
if (zathura->document != NULL) {
|
|
|
|
document_close(zathura, false);
|
2011-09-03 13:40:28 +02:00
|
|
|
}
|
|
|
|
|
2013-03-17 10:56:43 +01:00
|
|
|
document_open(zathura, girara_list_nth(argument_list, 0),
|
|
|
|
(argc == 2) ? girara_list_nth(argument_list, 1) : NULL,
|
|
|
|
ZATHURA_PAGE_NUMBER_UNSPECIFIED);
|
2011-10-12 16:18:40 +02:00
|
|
|
} else {
|
2012-03-04 18:45:58 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("No arguments given."));
|
2011-08-31 00:08:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-25 00:24:43 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-24 10:38:48 +01:00
|
|
|
bool
|
|
|
|
cmd_quit(girara_session_t* session, girara_list_t* UNUSED(argument_list))
|
|
|
|
{
|
|
|
|
sc_quit(session, NULL, NULL, 0);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-10 20:31:15 +01:00
|
|
|
bool
|
2011-09-21 00:46:03 +02:00
|
|
|
cmd_print(girara_session_t* session, girara_list_t* UNUSED(argument_list))
|
2010-11-10 20:31:15 +01:00
|
|
|
{
|
2011-04-29 00:28:19 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
|
2011-09-21 09:22:12 +02:00
|
|
|
if (zathura->document == NULL) {
|
2012-03-05 17:27:17 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("No document opened."));
|
2011-09-21 09:22:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
2011-04-29 00:28:19 +02:00
|
|
|
|
2012-05-08 16:47:34 +02:00
|
|
|
print(zathura);
|
2011-04-29 00:28:19 +02:00
|
|
|
|
2010-11-10 20:31:15 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-22 19:12:45 +02:00
|
|
|
bool
|
|
|
|
cmd_nohlsearch(girara_session_t* session, girara_list_t* UNUSED(argument_list))
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
|
|
|
|
document_draw_search_results(zathura, false);
|
|
|
|
render_all(zathura);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-10 20:31:15 +01:00
|
|
|
bool
|
2011-04-19 10:38:59 +02:00
|
|
|
cmd_save(girara_session_t* session, girara_list_t* argument_list)
|
2010-11-10 20:31:15 +01:00
|
|
|
{
|
2011-09-01 11:51:49 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
|
2011-09-21 09:22:12 +02:00
|
|
|
if (zathura->document == NULL) {
|
2012-03-05 17:27:17 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("No document opened."));
|
2011-09-21 09:22:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
2011-09-01 11:51:49 +02:00
|
|
|
|
|
|
|
if (girara_list_size(argument_list) == 1) {
|
2012-03-05 15:04:29 +01:00
|
|
|
if (document_save(zathura, girara_list_nth(argument_list, 0), false) == true) {
|
2012-03-05 12:25:34 +01:00
|
|
|
girara_notify(session, GIRARA_INFO, _("Document saved."));
|
2012-03-04 23:54:03 +01:00
|
|
|
} else {
|
2012-03-05 12:25:34 +01:00
|
|
|
girara_notify(session, GIRARA_INFO, _("Failed to save document."));
|
2012-03-04 23:54:03 +01:00
|
|
|
}
|
2011-10-12 16:18:40 +02:00
|
|
|
} else {
|
2012-03-04 18:45:58 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("Invalid number of arguments."));
|
2011-09-01 11:51:49 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
cmd_savef(girara_session_t* session, girara_list_t* argument_list)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
|
2011-09-21 09:22:12 +02:00
|
|
|
if (zathura->document == NULL) {
|
2012-03-05 17:27:17 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("No document opened."));
|
2011-09-03 13:40:28 +02:00
|
|
|
return false;
|
2011-09-21 09:22:12 +02:00
|
|
|
}
|
2011-09-01 11:51:49 +02:00
|
|
|
|
|
|
|
if (girara_list_size(argument_list) == 1) {
|
2012-03-04 23:54:03 +01:00
|
|
|
if (document_save(zathura, girara_list_nth(argument_list, 0), true) == true) {
|
2012-03-05 12:25:34 +01:00
|
|
|
girara_notify(session, GIRARA_INFO, _("Document saved."));
|
2012-03-04 23:54:03 +01:00
|
|
|
} else {
|
2012-03-05 12:25:34 +01:00
|
|
|
girara_notify(session, GIRARA_INFO, _("Failed to save document."));
|
2012-03-04 23:54:03 +01:00
|
|
|
}
|
2011-10-12 16:18:40 +02:00
|
|
|
} else {
|
2012-03-04 18:45:58 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("Invalid number of arguments."));
|
2011-09-01 11:51:49 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-10 20:31:15 +01:00
|
|
|
return true;
|
|
|
|
}
|
2011-10-22 16:35:38 +02:00
|
|
|
|
|
|
|
bool
|
2011-12-09 14:48:16 +01:00
|
|
|
cmd_search(girara_session_t* session, const char* input, girara_argument_t* argument)
|
2011-10-22 16:35:38 +02:00
|
|
|
{
|
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(input != NULL, false);
|
|
|
|
g_return_val_if_fail(argument != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
|
2012-02-07 12:08:00 +01:00
|
|
|
if (zathura->document == NULL || strlen(input) == 0) {
|
2011-10-22 16:35:38 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-27 13:30:04 +02:00
|
|
|
zathura_error_t error = ZATHURA_ERROR_OK;
|
2012-02-18 09:21:34 +01:00
|
|
|
|
2012-12-18 04:09:09 +01:00
|
|
|
/* set search direction */
|
|
|
|
zathura->global.search_direction = argument->n;
|
2012-03-27 21:59:35 +02:00
|
|
|
|
|
|
|
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
|
|
|
|
unsigned int current_page_number = zathura_document_get_current_page_number(zathura->document);
|
|
|
|
|
2012-04-22 19:12:45 +02:00
|
|
|
/* reset search highlighting */
|
|
|
|
bool nohlsearch = false;
|
|
|
|
girara_setting_get(session, "nohlsearch", &nohlsearch);
|
|
|
|
|
|
|
|
/* search pages */
|
2012-03-27 21:59:35 +02:00
|
|
|
for (unsigned int page_id = 0; page_id < number_of_pages; ++page_id) {
|
2012-03-30 18:24:00 +02:00
|
|
|
unsigned int index = (page_id + current_page_number) % number_of_pages;
|
2012-03-27 21:59:35 +02:00
|
|
|
zathura_page_t* page = zathura_document_get_page(zathura->document, index);
|
2012-02-07 18:19:48 +01:00
|
|
|
if (page == NULL) {
|
2012-02-07 12:08:00 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-04-03 09:02:45 +02:00
|
|
|
GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
|
2012-03-26 14:44:56 +02:00
|
|
|
g_object_set(page_widget, "draw-links", FALSE, NULL);
|
2012-02-07 12:08:00 +01:00
|
|
|
|
2012-09-22 12:50:11 +02:00
|
|
|
render_lock(zathura->sync.render_thread);
|
2012-02-18 09:21:34 +01:00
|
|
|
girara_list_t* result = zathura_page_search_text(page, input, &error);
|
2012-09-22 12:50:11 +02:00
|
|
|
render_unlock(zathura->sync.render_thread);
|
|
|
|
|
2012-02-07 12:08:00 +01:00
|
|
|
if (result == NULL || girara_list_size(result) == 0) {
|
|
|
|
girara_list_free(result);
|
2012-03-26 14:44:56 +02:00
|
|
|
g_object_set(page_widget, "search-results", NULL, NULL);
|
2012-02-18 09:21:34 +01:00
|
|
|
|
2012-03-27 13:30:04 +02:00
|
|
|
if (error == ZATHURA_ERROR_NOT_IMPLEMENTED) {
|
2012-02-18 09:21:34 +01:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
2012-02-07 12:08:00 +01:00
|
|
|
}
|
|
|
|
|
2012-03-26 14:44:56 +02:00
|
|
|
g_object_set(page_widget, "search-results", result, NULL);
|
2013-06-08 02:46:58 +02:00
|
|
|
|
|
|
|
if (argument->n == BACKWARD) {
|
|
|
|
/* start at bottom hit in page */
|
|
|
|
g_object_set(page_widget, "search-current", girara_list_size(result) - 1, NULL);
|
|
|
|
} else {
|
|
|
|
g_object_set(page_widget, "search-current", 0, NULL);
|
2012-02-07 18:19:48 +01:00
|
|
|
}
|
2012-02-07 12:08:00 +01:00
|
|
|
}
|
|
|
|
|
2013-06-08 02:46:58 +02:00
|
|
|
girara_argument_t* arg = g_malloc0(sizeof(girara_argument_t));
|
|
|
|
|
|
|
|
arg->n = FORWARD;
|
|
|
|
sc_search(session, arg, NULL, 0);
|
|
|
|
g_free(arg);
|
|
|
|
|
2011-10-22 16:35:38 +02:00
|
|
|
return true;
|
|
|
|
}
|
2012-01-13 18:54:09 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
cmd_export(girara_session_t* session, girara_list_t* argument_list)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
if (zathura->document == NULL) {
|
2012-03-04 18:45:58 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("No document opened."));
|
2012-01-13 18:54:09 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-24 18:27:10 +01:00
|
|
|
if (girara_list_size(argument_list) != 2) {
|
2012-03-04 18:45:58 +01:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("Invalid number of arguments given."));
|
2012-01-13 18:54:09 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-01 11:54:52 +02:00
|
|
|
const char* file_identifier = girara_list_nth(argument_list, 0);
|
2012-02-11 17:53:28 +01:00
|
|
|
const char* file_name = girara_list_nth(argument_list, 1);
|
|
|
|
|
2012-05-01 11:54:52 +02:00
|
|
|
if (file_name == NULL || file_identifier == NULL) {
|
2012-02-11 17:53:28 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-01 11:54:52 +02:00
|
|
|
char* export_path = girara_fix_path(file_name);
|
|
|
|
if (export_path == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attachment */
|
|
|
|
if (strncmp(file_identifier, "attachment-", strlen("attachment-")) == 0) {
|
|
|
|
if (zathura_document_attachment_save(zathura->document, file_identifier + strlen("attachment-"), export_path) == false) {
|
|
|
|
girara_notify(session, GIRARA_ERROR, _("Couldn't write attachment '%s' to '%s'."), file_identifier, file_name);
|
|
|
|
} else {
|
|
|
|
girara_notify(session, GIRARA_INFO, _("Wrote attachment '%s' to '%s'."), file_identifier, export_path);
|
|
|
|
}
|
2012-10-09 01:12:18 +02:00
|
|
|
/* image */
|
2012-05-01 11:54:52 +02:00
|
|
|
} else if (strncmp(file_identifier, "image-p", strlen("image-p")) == 0 && strlen(file_identifier) >= 10) {
|
|
|
|
/* parse page id */
|
|
|
|
const char* input = file_identifier + strlen("image-p");
|
|
|
|
int page_id = atoi(input);
|
|
|
|
if (page_id == 0) {
|
|
|
|
goto image_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse image id */
|
|
|
|
input = strstr(input, "-");
|
|
|
|
if (input == NULL) {
|
|
|
|
goto image_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int image_id = atoi(input + 1);
|
|
|
|
if (image_id == 0) {
|
|
|
|
goto image_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get image */
|
|
|
|
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id - 1);
|
|
|
|
if (page == NULL) {
|
|
|
|
goto image_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
girara_list_t* images = zathura_page_images_get(page, NULL);
|
|
|
|
if (images == NULL) {
|
|
|
|
goto image_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
zathura_image_t* image = girara_list_nth(images, image_id - 1);
|
|
|
|
if (image == NULL) {
|
|
|
|
goto image_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_surface_t* surface = zathura_page_image_get_cairo(page, image, NULL);
|
|
|
|
if (surface == NULL) {
|
|
|
|
goto image_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cairo_surface_write_to_png(surface, export_path) == CAIRO_STATUS_SUCCESS) {
|
|
|
|
girara_notify(session, GIRARA_INFO, _("Wrote image '%s' to '%s'."), file_identifier, export_path);
|
|
|
|
} else {
|
|
|
|
girara_notify(session, GIRARA_ERROR, _("Couldn't write image '%s' to '%s'."), file_identifier, file_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
goto error_ret;
|
|
|
|
|
|
|
|
image_error:
|
|
|
|
|
|
|
|
girara_notify(session, GIRARA_ERROR, _("Unknown image '%s'."), file_identifier);
|
|
|
|
goto error_ret;
|
2012-10-09 01:12:18 +02:00
|
|
|
/* unknown */
|
2012-01-13 18:54:09 +01:00
|
|
|
} else {
|
2012-05-01 11:54:52 +02:00
|
|
|
girara_notify(session, GIRARA_ERROR, _("Unknown attachment or image '%s'."), file_identifier);
|
2012-01-13 18:54:09 +01:00
|
|
|
}
|
|
|
|
|
2012-05-01 11:54:52 +02:00
|
|
|
error_ret:
|
|
|
|
|
|
|
|
g_free(export_path);
|
2012-02-11 17:53:28 +01:00
|
|
|
|
2012-01-13 18:54:09 +01:00
|
|
|
return true;
|
|
|
|
}
|
2012-03-24 18:27:10 +01:00
|
|
|
|
2012-08-14 11:45:11 +02:00
|
|
|
bool
|
|
|
|
cmd_exec(girara_session_t* session, girara_list_t* argument_list)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
|
|
|
|
if (zathura->document != NULL) {
|
|
|
|
const char* path = zathura_document_get_path(zathura->document);
|
|
|
|
|
|
|
|
GIRARA_LIST_FOREACH(argument_list, char*, iter, value)
|
2012-10-09 01:12:18 +02:00
|
|
|
char* r = NULL;
|
|
|
|
if ((r = replace_substring(value, "$FILE", path)) != NULL) {
|
|
|
|
girara_list_iterator_set(iter, r);
|
|
|
|
}
|
2012-08-14 11:45:11 +02:00
|
|
|
GIRARA_LIST_FOREACH_END(argument_list, char*, iter, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return girara_exec_with_argument_list(session, argument_list);
|
|
|
|
}
|
|
|
|
|
2012-03-24 18:27:10 +01:00
|
|
|
bool
|
|
|
|
cmd_offset(girara_session_t* session, girara_list_t* argument_list)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
if (zathura->document == NULL) {
|
|
|
|
girara_notify(session, GIRARA_ERROR, _("No document opened."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no argument: take current page as offset */
|
2013-05-08 18:28:32 +02:00
|
|
|
int page_offset = zathura_document_get_current_page_number(zathura->document);
|
2012-03-24 18:27:10 +01:00
|
|
|
|
|
|
|
/* retrieve offset from argument */
|
|
|
|
if (girara_list_size(argument_list) == 1) {
|
|
|
|
const char* value = girara_list_nth(argument_list, 0);
|
|
|
|
if (value != NULL) {
|
|
|
|
page_offset = atoi(value);
|
|
|
|
if (page_offset == 0 && strcmp(value, "0") != 0) {
|
|
|
|
girara_notify(session, GIRARA_WARNING, _("Argument must be a number."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-08 18:28:32 +02:00
|
|
|
zathura_document_set_page_offset(zathura->document, page_offset);
|
2012-03-24 18:27:10 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-06-13 16:08:33 +02:00
|
|
|
|
|
|
|
bool
|
|
|
|
cmd_version(girara_session_t* session, girara_list_t* UNUSED(argument_list))
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
|
2012-07-12 10:37:58 +02:00
|
|
|
char* string = zathura_get_version_string(zathura, true);
|
2012-10-09 01:12:18 +02:00
|
|
|
if (string == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-13 16:08:33 +02:00
|
|
|
|
|
|
|
/* display information */
|
2012-07-12 10:37:58 +02:00
|
|
|
girara_notify(session, GIRARA_INFO, "%s", string);
|
2012-06-13 16:08:33 +02:00
|
|
|
|
2012-07-12 10:37:58 +02:00
|
|
|
g_free(string);
|
2012-06-13 16:08:33 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|