File: pqiv.h

package info (click to toggle)
pqiv 2.6-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 500 kB
  • ctags: 659
  • sloc: ansic: 6,227; sh: 318; makefile: 4
file content (236 lines) | stat: -rw-r--r-- 7,901 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/**
 * pqiv
 *
 * Copyright (c) 2013-2014, Phillip Berndt
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

// This file contains the definition of files, image types and
// the plugin infrastructure. It should be included in file type
// handlers.

#ifndef _PQIV_H_INCLUDED
#define _PQIV_H_INCLUDED

#include <glib.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include "lib/bostree.h"

#ifndef PQIV_VERSION
#define PQIV_VERSION "2.6"
#endif

#define FILE_FLAGS_ANIMATION      (guint)(1)
#define FILE_FLAGS_MEMORY_IMAGE   (guint)(1<<1)

// The structure for images {{{
typedef struct file_type_handler_struct_t file_type_handler_t;
typedef struct {
	// File type
	const file_type_handler_t *file_type;

	// Special flags
	// FILE_FLAGS_ANIMATION        -> Animation functions are invoked
	//                                Set by file type handlers
	// FILE_FLAGS_MEMORY_IMAGE     -> File lives in memory
	guint file_flags;

	// The file name to display
	// Must be different from file_name, because it is free()d seperately
	gchar *display_name;

	// The name to sort by
	// Must be set if option_sort is set; in backends the simplest approach
	// is to only touch this if it is not NULL
	gchar *sort_name;

	// The URI or file name of the file
	gchar *file_name;

	// If the file is a memory image, the actual image data
	GBytes *file_data;

	// The file monitor structure is used for inotify-watching of
	// the files
	GFileMonitor *file_monitor;

	// This flag stores whether this image is currently loaded
	// and valid. i.e. if it is set, you can assume that
	// private_data contains a representation of the image;
	// if not, you can NOT assume that it does not.
	gboolean is_loaded : 1;

	// This flag determines whether this file should be reloaded
	// despite is_loaded being set
	gboolean force_reload : 1;

	// Cached image size
	guint width;
	guint height;

	// File-type specific data, allocated and freed by the file type handlers
	void *private;
} file_t;
// }}}
// Definition of the built-in file types {{{

// If you want to implement your own file type, you'll have to implement the
// following functions and a non-static initialization function named
// file_type_NAME_initializer that fills a file_type_handler_t with pointers to
// the functions. Store the file in backends/NAME.c and adjust the Makefile to
// add the required libraries if your backend is listed in the $(BACKENDS)
// variable.

typedef enum { PARAMETER, RECURSION, INOTIFY, BROWSE_ORIGINAL_PARAMETER, FILTER_OUTPUT } load_images_state_t;

// Allocation function: Allocate the ->private structure within a file and add the
// image(s) to the list of available images via load_images_handle_parameter_add_file()
// If an image is not to be loaded for any reason, the file structure should be
// deallocated using file_free()
// Returns a pointer to the first added image
// Optional, you can also set the pointer to this function to NULL.
// If new file_t structures are needed, use image_loader_duplicate_file
typedef BOSNode *(*file_type_alloc_fn_t)(load_images_state_t state, file_t *file);

// Deallocation, if a file is removed from the images list. Free the ->private structure.
// Only called if ->private is non-NULL.
typedef void (*file_type_free_fn_t)(file_t *file);

// Actually load a file into memory
typedef void (*file_type_load_fn_t)(file_t *file, GInputStream *data, GError **error_pointer);

// Unload a file
typedef void (*file_type_unload_fn_t)(file_t *file);

// Animation support: Initialize memory for animations, return ms until first frame
// Optional, you can also set the pointer to this function to NULL.
typedef double (*file_type_animation_initialize_fn_t)(file_t *file);

// Animation support: Advance to the next frame, return ms until next frame
// Optional, you can also set the pointer to this function to NULL.
typedef double (*file_type_animation_next_frame_fn_t)(file_t *file);

// Draw the current view to a cairo context
typedef void (*file_type_draw_fn_t)(file_t *file, cairo_t *cr);

struct file_type_handler_struct_t {
	// All files will be filtered with this filter. If it lets it pass,
	// a handler is assigned to a file. If none do, the file is
	// discarded if it was found during directory traversal or
	// loaded using the first image backend if it was an explicit
	// parameter.
	GtkFileFilter *file_types_handled;

	// Pointers to the functions defined above
	file_type_alloc_fn_t alloc_fn;
	file_type_free_fn_t free_fn;
	file_type_load_fn_t load_fn;
	file_type_unload_fn_t unload_fn;
	file_type_animation_initialize_fn_t animation_initialize_fn;
	file_type_animation_next_frame_fn_t animation_next_frame_fn;
	file_type_draw_fn_t draw_fn;
};

// Initialization function: Tell pqiv about a backend
typedef void (*file_type_initializer_fn_t)(file_type_handler_t *info);

// pqiv symbols available to plugins {{{

// Global cancellable that should be used for every i/o operation
extern GCancellable *image_loader_cancellable;

// Current scale level. For backends that don't support cairo natively.
extern gdouble current_scale_level;

// Load a file from disc/memory/network
GInputStream *image_loader_stream_file(file_t *file, GError **error_pointer);

// Duplicate a file_t; the private section does not get duplicated, only the pointer gets copied
file_t *image_loader_duplicate_file(file_t *file, gchar *custom_display_name, gchar *custom_sort_name);

// Add a file to the list of loaded files
// Should be called at least once in a file_type_alloc_fn_t, with the state being
// forwarded unaltered.
BOSNode *load_images_handle_parameter_add_file(load_images_state_t state, file_t *file);

// Load all data from an input stream into memory, conveinience function
GBytes *g_input_stream_read_completely(GInputStream *input_stream, GCancellable *cancellable, GError **error_pointer);

// Free a file
void file_free(file_t *file);

// }}}

// File type handlers, used in the initializer and file type guessing
extern file_type_handler_t file_type_handlers[];

/* }}} */

// The means to control pqiv remotely {{{
typedef enum {
	ACTION_NOP,
	ACTION_SHIFT_Y,
	ACTION_SHIFT_X,
	ACTION_SET_SLIDESHOW_INTERVAL_RELATIVE,
	ACTION_SET_SLIDESHOW_INTERVAL_ABSOLUTE,
	ACTION_SET_SCALE_LEVEL_RELATIVE,
	ACTION_SET_SCALE_LEVEL_ABSOLUTE,
	ACTION_TOGGLE_SCALE_MODE,
	ACTION_TOGGLE_SHUFFLE_MODE,
	ACTION_RELOAD,
	ACTION_RESET_SCALE_LEVEL,
	ACTION_TOGGLE_FULLSCREEN,
	ACTION_FLIP_HORIZONTALLY,
	ACTION_FLIP_VERTICALLY,
	ACTION_ROTATE_LEFT,
	ACTION_ROTATE_RIGHT,
	ACTION_TOGGLE_INFO_BOX,
	ACTION_JUMP_DIALOG,
	ACTION_TOGGLE_SLIDESHOW,
	ACTION_HARDLINK_CURRENT_IMAGE,
	ACTION_GOTO_DIRECTORY_RELATIVE,
	ACTION_GOTO_FILE_RELATIVE,
	ACTION_QUIT,
	ACTION_NUMERIC_COMMAND,
	ACTION_COMMAND,
	ACTION_ADD_FILE,
	ACTION_GOTO_FILE_BYINDEX,
	ACTION_GOTO_FILE_BYNAME,
	ACTION_REMOVE_FILE_BYINDEX,
	ACTION_REMOVE_FILE_BYNAME,
	ACTION_OUTPUT_FILE_LIST,
	ACTION_SET_CURSOR_VISIBILITY,
	ACTION_SET_STATUS_OUTPUT,
	ACTION_SET_SCALE_MODE_FIT_PX,
	ACTION_SET_SHIFT_X,
	ACTION_SET_SHIFT_Y,
	ACTION_BIND_KEY,
	ACTION_SEND_KEYS,
	ACTION_SET_SHIFT_ALIGN_CORNER
} pqiv_action_t;

typedef union {
	int pint;
	double pdouble;
	char *pcharptr;
	struct {
		short p1;
		short p2;
	} p2short;
} pqiv_action_parameter_t;
void action(pqiv_action_t action, pqiv_action_parameter_t parameter);
// }}}

#endif