1 /* vifm
2  * Copyright (C) 2001 Ken Steen.
3  * Copyright (C) 2011 xaizek.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19 
20 #ifndef VIFM__UI__QUICKVIEW_H__
21 #define VIFM__UI__QUICKVIEW_H__
22 
23 #include <stddef.h> /* size_t */
24 #include <stdio.h> /* FILE */
25 
26 #include "../utils/test_helpers.h"
27 #include "colors.h"
28 
29 struct dir_entry_t;
30 struct view_t;
31 
32 /* Description of area used for preview. */
33 typedef struct
34 {
35 	struct view_t *source; /* View which does the preview. */
36 	struct view_t *view;   /* View which displays the preview. */
37 	col_attr_t def_col;    /* Default color of the area. */
38 	int x;                 /* Relative x coordinate of the top-left corner. */
39 	int y;                 /* Relative y coordinate of the top-left corner. */
40 	int w;                 /* Width of the area. */
41 	int h;                 /* Height of the area. */
42 }
43 preview_area_t;
44 
45 /* Enables quick view (just enables, no drawing) if possible.  Returns zero on
46  * success, otherwise non-zero is returned and error message is printed on the
47  * statusbar.*/
48 int qv_ensure_is_shown(void);
49 
50 /* Checks whether quick view can be shown.  Returns non-zero if so, otherwise
51  * zero is returned and error message is printed on the statusbar. */
52 int qv_can_show(void);
53 
54 /* Draws current file of the view in other view.  Does nothing if drawing
55  * doesn't make sense (e.g. only one pane is visible). */
56 void qv_draw(struct view_t *view);
57 
58 /* Draws file entry on an area. */
59 void qv_draw_on(const struct dir_entry_t *entry, const preview_area_t *parea);
60 
61 /* Toggles state of the quick view. */
62 void qv_toggle(void);
63 
64 /* Quits preview pane or view modes. */
65 void qv_hide(void);
66 
67 /* Expands and executes viewer command.  Returns file containing results of the
68  * viewer. */
69 FILE * qv_execute_viewer(const char viewer[]);
70 
71 /* Performs view clearing with the given command, which can be NULL in which
72  * case only internal clearing is done. */
73 void qv_cleanup(struct view_t *view, const char cmd[]);
74 
75 /* Gets viewer command for a file considering its type (directory vs. file).
76  * Returns NULL if no suitable viewer available, otherwise returns pointer to
77  * string stored internally. */
78 const char * qv_get_viewer(const char path[]);
79 
80 /* Previews directory, actual preview is to be read from returned stream.
81  * Returns the stream or NULL on error. */
82 FILE * qv_view_dir(const char path[]);
83 
84 /* Decides on path that should be explored when cursor points to the given
85  * entry. */
86 void qv_get_path_to_explore(const struct dir_entry_t *entry, char buf[],
87 		size_t buf_len);
88 
89 /* Informs this unit that it's data was probably erased from the screen. */
90 void qv_ui_updated(void);
91 
92 TSTATIC_DEFS(
93 	struct strlist_t;
94 	struct strlist_t read_lines(FILE *fp, int max_lines, int *complete);
95 )
96 
97 #endif /* VIFM__UI__QUICKVIEW_H__ */
98 
99 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
100 /* vim: set cinoptions+=t0 filetype=c : */
101