Multiple printer support, destination links

Added following functionality:
  * Multiple printer can be set in the configuration file or a new
    one can be named while executing the print command
  * It is possible to use ~ in the open and export command
  * Clicking on destination links works now
  * Show/Hide inputbar

Fixes and other changes:
  * Updated the dependencies to the right versions
  * Switched j/k in the scrolling command
  * Added command shortcuts
  * Fixed the rotation
  * Link command is for the preset only for showing external
    links
  * Added some command explanation in the man page
  * Adjust window on startup
This commit is contained in:
Moritz Lipp 2009-09-19 10:43:41 +02:00
parent 96b0393531
commit 582f926b82
4 changed files with 156 additions and 52 deletions

2
README
View file

@ -6,7 +6,7 @@ Requirements
------------ ------------
poppler-glib (0.10) poppler-glib (0.10)
cairo (1.8.8) cairo (1.8.8)
gtk2 (2.17.2) gtk2 (2.16)
Configuration Configuration
------------- -------------

View file

@ -6,7 +6,10 @@ static const int SHOW_NOTIFICATION = 5;
static const int DEFAULT_WIDTH = 800; static const int DEFAULT_WIDTH = 800;
static const int DEFAULT_HEIGHT = 600; static const int DEFAULT_HEIGHT = 600;
static const char BROWSER[] = "firefox %s"; static const char BROWSER[] = "firefox %s";
static const char PRINTER[] = "EPSON_AL-CX11_192.168.88.80"; static const char *PRINTER[] = { "PRINTER_1",
"PRINTER_2",
"PRINTER_3"
};
/* look */ /* look */
static const char font[] = "monospace normal 9"; static const char font[] = "monospace normal 9";
@ -46,11 +49,12 @@ Shortcut shortcuts[] = {
{GDK_CONTROL_MASK, GDK_e, sc_rotate, { LEFT } }, {GDK_CONTROL_MASK, GDK_e, sc_rotate, { LEFT } },
{GDK_CONTROL_MASK, GDK_p, sc_focus_inputbar, { .data = ":print all" } }, {GDK_CONTROL_MASK, GDK_p, sc_focus_inputbar, { .data = ":print all" } },
{GDK_CONTROL_MASK, GDK_q, sc_quit, {0} }, {GDK_CONTROL_MASK, GDK_q, sc_quit, {0} },
{GDK_CONTROL_MASK, GDK_m, sc_toggle_inputbar, {0} },
{0, GDK_n, sc_search, { FORWARD } }, {0, GDK_n, sc_search, { FORWARD } },
{0, GDK_N, sc_search, { BACKWARD } }, {0, GDK_N, sc_search, { BACKWARD } },
{0, GDK_h, sc_scroll, { LEFT } }, {0, GDK_h, sc_scroll, { LEFT } },
{0, GDK_j, sc_scroll, { DOWN } }, {0, GDK_j, sc_scroll, { UP } },
{0, GDK_k, sc_scroll, { UP } }, {0, GDK_k, sc_scroll, { DOWN } },
{0, GDK_l, sc_scroll, { RIGHT } }, {0, GDK_l, sc_scroll, { RIGHT } },
{0, GDK_Page_Up, sc_scroll, { TOP } }, {0, GDK_Page_Up, sc_scroll, { TOP } },
{0, GDK_Page_Down, sc_scroll, { BOTTOM } }, {0, GDK_Page_Down, sc_scroll, { BOTTOM } },
@ -68,14 +72,25 @@ Shortcut shortcuts[] = {
Command commands[] = { Command commands[] = {
// command, function // command, function
{"export", cmd_export}, {"export", cmd_export},
{"e", cmd_export},
{"form", cmd_form}, {"form", cmd_form},
{"f", cmd_form},
{"goto", cmd_goto}, {"goto", cmd_goto},
{"g", cmd_goto},
{"info", cmd_info}, {"info", cmd_info},
{"i", cmd_info},
{"links", cmd_links}, {"links", cmd_links},
{"l", cmd_links},
{"open", cmd_open}, {"open", cmd_open},
{"o", cmd_open},
{"print", cmd_print}, {"print", cmd_print},
{"p", cmd_print},
{"rotate", cmd_rotate}, {"rotate", cmd_rotate},
{"r", cmd_rotate},
{"save", cmd_save}, {"save", cmd_save},
{"s", cmd_save},
{"quit", cmd_quit}, {"quit", cmd_quit},
{"q", cmd_quit},
{"zoom", cmd_zoom}, {"zoom", cmd_zoom},
{"z", cmd_zoom},
}; };

View file

@ -7,6 +7,23 @@ zathura \- a pdf viewer
.SH DESCRIPTION .SH DESCRIPTION
zathura is a pdf viewer based on the poppler pdf rendering library zathura is a pdf viewer based on the poppler pdf rendering library
.SH USAGE .SH USAGE
.SS show and edit form fields
the form command separates between two actions: show, for showing and numerating all available forms on the current page; and set for modifying the value of the given form field:
.TP
.I form show
shows all values
.TP
.I form set [value number] [value]
modifying the value in the form field with the given value number
.SS export image and attachments
the export command expects the type of objects you want to export (images or attachments) and a existing path where it will save the files
.TP
.I export [image|attachments] [path]
.SS printing documents
the printing command is kept very simple and works with lp. it expects the range of sites you want to print and the id of a printer specified in the config.h file or the name of it
.TP
.I print [all|x|x-y] [printer id|printer name]
.SH DEFAULT SETTINGS
.SS Commands .SS Commands
.TP .TP
.B export .B export
@ -77,10 +94,10 @@ search backwards
scroll left scroll left
.TP .TP
.B j .B j
scroll down scroll up
.TP .TP
.B k .B k
scroll up scroll down
.TP .TP
.B l .B l
scroll right scroll right

114
zathura.c
View file

@ -106,6 +106,7 @@ void sc_zoom(Argument*);
void sc_adjust_window(Argument*); void sc_adjust_window(Argument*);
void sc_rotate(Argument*); void sc_rotate(Argument*);
void sc_search(Argument*); void sc_search(Argument*);
void sc_toggle_inputbar(Argument*);
void sc_quit(Argument*); void sc_quit(Argument*);
/* command declarations */ /* command declarations */
@ -441,13 +442,23 @@ save_images(int page, char* directory)
PopplerRectangle image_field; PopplerRectangle image_field;
gint image_id; gint image_id;
char* file; char* file;
char* filename;
image_mapping = (PopplerImageMapping*) images->data; image_mapping = (PopplerImageMapping*) images->data;
image_field = image_mapping->area; image_field = image_mapping->area;
image_id = image_mapping->image_id; image_id = image_mapping->image_id;
image = poppler_page_get_image(document_page, image_id); image = poppler_page_get_image(document_page, image_id);
file = g_strdup_printf("%sp%i_i%i.png", directory, page + 1, image_id); filename = g_strdup_printf("p%i_i%i.png", page + 1, image_id);
if(directory[0] == '~')
{
file = malloc(((int) strlen(filename) + (int) strlen(directory)
+ (int) strlen(getenv("HOME")) - 1) * sizeof(char));
file = g_strdup_printf("%s%s%s", getenv("HOME"), directory + 1, filename);
}
else
file = g_strdup_printf("%s%s", directory, filename);
cairo_surface_write_to_png(image, file); cairo_surface_write_to_png(image, file);
@ -467,6 +478,14 @@ save_attachments(char* directory)
for(attachments = attachment_list; attachments; attachments = g_list_next(attachments)) for(attachments = attachment_list; attachments; attachments = g_list_next(attachments))
{ {
PopplerAttachment *attachment = (PopplerAttachment*) attachments->data; PopplerAttachment *attachment = (PopplerAttachment*) attachments->data;
if(directory[0] == '~')
{
file = malloc(((int) strlen(attachment->name) + (int) strlen(directory)
+ (int) strlen(getenv("HOME")) - 1) * sizeof(char));
file = g_strdup_printf("%s%s%s", getenv("HOME"), directory + 1, attachment->name);
}
else
file = g_strdup_printf("%s%s", directory, attachment->name); file = g_strdup_printf("%s%s", directory, attachment->name);
poppler_attachment_save(attachment, file, NULL); poppler_attachment_save(attachment, file, NULL);
@ -695,9 +714,9 @@ void
sc_rotate(Argument *argument) sc_rotate(Argument *argument)
{ {
if(argument->n == LEFT) if(argument->n == LEFT)
Zathura.PDF.rotate = abs((Zathura.PDF.rotate - 90) % 360); Zathura.PDF.rotate = (270 + Zathura.PDF.rotate) % 360;
else if(argument->n == RIGHT) else if(argument->n == RIGHT)
Zathura.PDF.rotate = abs((Zathura.PDF.rotate + 90) % 360); Zathura.PDF.rotate = (450 + Zathura.PDF.rotate) % 360;
draw(); draw();
} }
@ -759,6 +778,25 @@ sc_search(Argument *argument)
update_notification(search_status, DEFAULT, g_strdup_printf("No match for %s", search_item)); update_notification(search_status, DEFAULT, g_strdup_printf("No match for %s", search_item));
} }
void
sc_toggle_inputbar(Argument *argument)
{
static gboolean visible = TRUE;
if(visible)
{
gtk_widget_hide(GTK_WIDGET(Zathura.inputbar));
visible = FALSE;
}
else
{
gtk_widget_show(GTK_WIDGET(Zathura.inputbar));
visible = TRUE;
}
cb_draw(Zathura.drawing_area, NULL);
}
void void
sc_quit(Argument *argument) sc_quit(Argument *argument)
{ {
@ -774,6 +812,12 @@ cmd_open(int argc, char** argv)
char* file = realpath(argv[0], NULL); char* file = realpath(argv[0], NULL);
if(argv[0][0] == '~')
{
file = realloc(file, ((int) strlen(argv[0]) + (int) strlen(getenv("HOME")) - 1) * sizeof(char));
file = g_strdup_printf("%s%s", getenv("HOME"), argv[0] + 1);
}
if(!g_file_test(file, G_FILE_TEST_IS_REGULAR)) if(!g_file_test(file, G_FILE_TEST_IS_REGULAR))
{ {
notify(ERROR, "File does not exist"); notify(ERROR, "File does not exist");
@ -807,14 +851,24 @@ cmd_print(int argc, char** argv)
char* print_command; char* print_command;
char* sites; char* sites;
char* printer;
if(strcmp(argv[0], "all") == 0) if(strcmp(argv[0], "all") == 0)
sites = g_strdup_printf("%i", Zathura.PDF.number_of_pages); sites = g_strdup_printf("%i", Zathura.PDF.number_of_pages);
else else
sites = argv[0]; sites = argv[0];
print_command = g_strdup_printf("lp -d '%s' -P %s %s", PRINTER, sites, Zathura.PDF.file); if(argc == 2)
{
if(atoi(argv[1]) != 0 && atoi(argv[1]) <= (sizeof(PRINTER) / sizeof(char*)))
printer = (char*) PRINTER[atoi(argv[1]) - 1];
else
printer = argv[1];
}
else
printer = (char*) PRINTER[0];
print_command = g_strdup_printf("lp -d '%s' -P %s %s", printer, sites, Zathura.PDF.file);
system(print_command); system(print_command);
} }
@ -1004,15 +1058,9 @@ cmd_links(int argc, char** argv)
GList *link_list; GList *link_list;
GList *links; GList *links;
int number_of_links; int number_of_links = 0;
link_list = poppler_page_get_link_mapping(Zathura.PDF.page); link_list = poppler_page_get_link_mapping(Zathura.PDF.page);
number_of_links = g_list_length(link_list);
if(number_of_links > 0)
notify(DEFAULT, g_strdup_printf("%d links found", number_of_links));
else
notify(WARNING, "No links found");
for(links = link_list; links; links = g_list_next(links)) for(links = link_list; links; links = g_list_next(links))
{ {
@ -1025,11 +1073,16 @@ cmd_links(int argc, char** argv)
if(action->type == POPPLER_ACTION_URI) if(action->type == POPPLER_ACTION_URI)
{ {
char* link_name = poppler_page_get_text(Zathura.PDF.page, POPPLER_SELECTION_WORD, &link_mapping->area); char* link_name = poppler_page_get_text(Zathura.PDF.page, POPPLER_SELECTION_WORD, &link_mapping->area);
link_name = g_strdup_printf("<a href=\"%s\">%s</a>", action->uri.uri, link_name); notify(DEFAULT, g_strdup_printf("<b><a href=\"%s\">%s</a>:</b> %s", action->uri.uri, link_name, action->uri.uri));
number_of_links++;
}
}
if(number_of_links > 0)
notify(DEFAULT, g_strdup_printf("%d links found", number_of_links));
else
notify(WARNING, "No links found");
notify(DEFAULT, g_strdup_printf("<b>%s:</b> %s", link_name, action->uri.uri));
}
}
poppler_page_free_link_mapping(link_list); poppler_page_free_link_mapping(link_list);
} }
@ -1086,7 +1139,6 @@ void
cb_draw(GtkWidget *widget, gpointer data) cb_draw(GtkWidget *widget, gpointer data)
{ {
gdk_window_clear(widget->window); gdk_window_clear(widget->window);
cairo_t *cairo = gdk_cairo_create(widget->window); cairo_t *cairo = gdk_cairo_create(widget->window);
cairo_set_source_surface(cairo, Zathura.PDF.surface, 0, 0); cairo_set_source_surface(cairo, Zathura.PDF.surface, 0, 0);
cairo_paint(cairo); cairo_paint(cairo);
@ -1198,8 +1250,6 @@ cb_drawing_area_button_pressed(GtkWidget* widget, GdkEventButton* event, gpointe
PopplerLinkMapping *link_mapping = (PopplerLinkMapping*) links->data; PopplerLinkMapping *link_mapping = (PopplerLinkMapping*) links->data;
PopplerAction *action = poppler_action_copy(link_mapping->action); PopplerAction *action = poppler_action_copy(link_mapping->action);
if(action->type == POPPLER_ACTION_URI)
{
double page_width, page_height; double page_width, page_height;
poppler_page_get_size(Zathura.PDF.page, &page_width, &page_height); poppler_page_get_size(Zathura.PDF.page, &page_width, &page_height);
PopplerRectangle* link_rectangle = &link_mapping->area; PopplerRectangle* link_rectangle = &link_mapping->area;
@ -1215,9 +1265,26 @@ cb_drawing_area_button_pressed(GtkWidget* widget, GdkEventButton* event, gpointe
if( (link_rectangle->x1 <= event->x) if( (link_rectangle->x1 <= event->x)
&& (link_rectangle->x2 >= event->x) && (link_rectangle->x2 >= event->x)
&& (link_rectangle->y1 <= event->y) && (link_rectangle->y1 <= event->y)
&& (link_rectangle->y2 >= event->y) && (link_rectangle->y2 >= event->y))
) {
if(action->type == POPPLER_ACTION_URI)
open_link(action->uri.uri); open_link(action->uri.uri);
else if(action->type == POPPLER_ACTION_GOTO_DEST)
{
PopplerDest* destination = action->goto_dest.dest;
if(destination->type == POPPLER_DEST_NAMED)
{
destination = poppler_document_find_dest(Zathura.PDF.document, destination->named_dest);
if(destination)
{
set_page(destination->page_num - 1);
draw();
update_status();
}
}
}
} }
} }
@ -1277,7 +1344,7 @@ cb_inputbar_key_released(GtkEntry *entry, GdkEventKey *event, gpointer data)
{ {
Argument argument; Argument argument;
argument.data = (char*) text + 1; argument.data = (char*) text + 1;
//sc_search(&argument); sc_search(&argument);
gtk_widget_grab_focus(GTK_WIDGET(Zathura.inputbar)); gtk_widget_grab_focus(GTK_WIDGET(Zathura.inputbar));
gtk_editable_set_position(GTK_EDITABLE(Zathura.inputbar), -1); gtk_editable_set_position(GTK_EDITABLE(Zathura.inputbar), -1);
} }
@ -1298,6 +1365,11 @@ main(int argc, char* argv[])
cmd_open(2, &argv[1]); cmd_open(2, &argv[1]);
gtk_widget_show_all(GTK_WIDGET(Zathura.window)); gtk_widget_show_all(GTK_WIDGET(Zathura.window));
Argument arg;
arg.n = ADJUST_BESTFIT;
sc_adjust_window(&arg);
gtk_main(); gtk_main();
return 0; return 0;