use mmaped files image loader
[geeqie.git] / src / typedefs.h
1 /*
2  * Geeqie
3  * (C) 2006 John Ellis
4  * Copyright (C) 2008 The Geeqie Team
5  *
6  * Author: John Ellis
7  *
8  * This software is released under the GNU General Public License (GNU GPL).
9  * Please read the included file COPYING for more information.
10  * This software comes with no warranty of any kind, use at your own risk!
11  */
12
13
14 #ifndef TYPEDEFS_H
15 #define TYPEDEFS_H
16
17 typedef enum {
18         ZOOM_RESET_ORIGINAL     = 0,
19         ZOOM_RESET_FIT_WINDOW   = 1,
20         ZOOM_RESET_NONE         = 2
21 } ZoomMode;
22
23 typedef enum {
24         MOUSE_BUTTON_LEFT       = 1,
25         MOUSE_BUTTON_MIDDLE     = 2,
26         MOUSE_BUTTON_RIGHT      = 3,
27         MOUSE_BUTTON_WHEEL_UP   = 4,
28         MOUSE_BUTTON_WHEEL_DOWN = 5
29 } MouseButton;
30
31 typedef enum {
32         DIRVIEW_LIST,
33         DIRVIEW_TREE
34 } DirViewType;
35
36 typedef enum {
37         FILEVIEW_LIST,
38         FILEVIEW_ICON
39 } FileViewType;
40
41 typedef enum {
42         CMD_COPY = GQ_EDITOR_GENERIC_SLOTS,
43         CMD_MOVE,
44         CMD_RENAME,
45         CMD_DELETE,
46         CMD_FOLDER,
47         GQ_EDITOR_SLOTS
48 } SpecialEditor;
49
50 typedef enum {
51         SORT_NONE,
52         SORT_NAME,
53         SORT_SIZE,
54         SORT_TIME,
55         SORT_PATH,
56         SORT_NUMBER
57 } SortType;
58
59 typedef enum {
60         ALTER_NONE,             /* do nothing */
61         ALTER_ROTATE_90,
62         ALTER_ROTATE_90_CC,     /* counterclockwise */
63         ALTER_ROTATE_180,
64         ALTER_MIRROR,
65         ALTER_FLIP,
66         ALTER_DESATURATE
67 } AlterType;
68
69 typedef enum {
70         LAYOUT_HIDE   = 0,
71         LAYOUT_LEFT   = 1 << 0,
72         LAYOUT_RIGHT  = 1 << 1,
73         LAYOUT_TOP    = 1 << 2,
74         LAYOUT_BOTTOM = 1 << 3
75 } LayoutLocation;
76
77
78 typedef enum {
79         IMAGE_STATE_NONE        = 0,
80         IMAGE_STATE_IMAGE       = 1 << 0,
81         IMAGE_STATE_LOADING     = 1 << 1,
82         IMAGE_STATE_ERROR       = 1 << 2,
83         IMAGE_STATE_COLOR_ADJ   = 1 << 3,
84         IMAGE_STATE_ROTATE_AUTO = 1 << 4,
85         IMAGE_STATE_ROTATE_USER = 1 << 5,
86         IMAGE_STATE_DELAY_FLIP  = 1 << 6
87 } ImageState;
88
89 typedef enum {
90         SPLIT_NONE = 0,
91         SPLIT_VERT,
92         SPLIT_HOR,
93         SPLIT_QUAD,
94 } ImageSplitMode;
95
96 typedef enum {
97         FILEDATA_CHANGE_DELETE,
98         FILEDATA_CHANGE_MOVE,
99         FILEDATA_CHANGE_RENAME,
100         FILEDATA_CHANGE_COPY,
101         FILEDATA_CHANGE_UNSPECIFIED
102 } FileDataChangeType;
103
104 typedef enum {
105         MTS_MODE_MINUS,
106         MTS_MODE_SET,
107         MTS_MODE_OR,
108         MTS_MODE_AND
109 } MarkToSelectionMode;
110
111 typedef enum {
112         STM_MODE_RESET,
113         STM_MODE_SET,
114         STM_MODE_TOGGLE
115 } SelectionToMarkMode;
116
117 typedef enum {
118         FORMAT_CLASS_UNKNOWN,
119         FORMAT_CLASS_IMAGE,
120         FORMAT_CLASS_RAWIMAGE,
121         FORMAT_CLASS_META,
122         FILE_FORMAT_CLASSES
123 } FileFormatClass;
124
125 typedef enum {
126         SS_ERR_NONE = 0,
127         SS_ERR_DISABLED, /**< secsave is disabled. */
128         SS_ERR_OUT_OF_MEM, /**< memory allocation failure */
129
130         /* see err field in SecureSaveInfo */
131         SS_ERR_OPEN_READ,
132         SS_ERR_OPEN_WRITE,
133         SS_ERR_STAT,
134         SS_ERR_ACCESS,
135         SS_ERR_MKSTEMP,
136         SS_ERR_RENAME,
137         SS_ERR_OTHER,
138 } SecureSaveErrno;
139
140 typedef enum {
141         NOTIFY_PRIORITY_HIGH = 0,
142         NOTIFY_PRIORITY_MEDIUM,
143         NOTIFY_PRIORITY_LOW
144 } NotifyPriority;
145         
146 typedef enum {
147         NOTIFY_TYPE_INTERNAL = 0, /* changed internal data only, like marks */
148         NOTIFY_TYPE_REREAD,       /* changed file size, date, etc., file name remains unchanged */
149         NOTIFY_TYPE_CHANGE        /* generic change described by fd->change */
150 } NotifyType;
151
152 typedef enum {
153         CHANGE_OK                      = 0,
154         CHANGE_WARN_DEST_EXISTS        = 1 << 0,
155         CHANGE_WARN_NO_WRITE_PERM      = 1 << 1,
156         CHANGE_WARN_SAME               = 1 << 2,
157         CHANGE_WARN_CHANGED_EXT        = 1 << 3,
158         CHANGE_ERROR_MASK              = (~0) << 4, /* the values below are fatal errors */
159         CHANGE_NO_READ_PERM            = 1 << 4,
160         CHANGE_NO_WRITE_PERM_DIR       = 1 << 5,
161         CHANGE_NO_DEST_DIR             = 1 << 6,
162         CHANGE_NO_WRITE_PERM_DEST_DIR  = 1 << 7,
163         CHANGE_NO_WRITE_PERM_DEST      = 1 << 8,
164         CHANGE_DEST_EXISTS             = 1 << 9,
165         CHANGE_NO_SRC                  = 1 << 10,
166         CHANGE_GENERIC_ERROR           = 1 << 16
167 } ChangeError;
168
169 #define MAX_SPLIT_IMAGES 4
170
171 typedef struct _ImageLoader ImageLoader;
172 typedef struct _ThumbLoader ThumbLoader;
173
174 typedef struct _CollectInfo CollectInfo;
175 typedef struct _CollectionData CollectionData;
176 typedef struct _CollectTable CollectTable;
177 typedef struct _CollectWindow CollectWindow;
178
179 typedef struct _ImageWindow ImageWindow;
180
181 typedef struct _FileData FileData;
182 typedef struct _FileDataChangeInfo FileDataChangeInfo;
183
184 typedef struct _LayoutWindow LayoutWindow;
185
186 typedef struct _ViewDir ViewDir;
187 typedef struct _ViewDirInfoList ViewDirInfoList;
188 typedef struct _ViewDirInfoTree ViewDirInfoTree;
189
190 typedef struct _ViewFile ViewFile;
191 typedef struct _ViewFileInfoList ViewFileInfoList;
192 typedef struct _ViewFileInfoIcon ViewFileInfoIcon;
193
194 typedef struct _SlideShowData SlideShowData;
195 typedef struct _FullScreenData FullScreenData;
196
197 typedef struct _PixmapFolders PixmapFolders;
198 typedef struct _Histogram Histogram;
199
200 typedef struct _SecureSaveInfo SecureSaveInfo;
201
202 typedef struct _ExifData ExifData;
203
204 typedef struct _Editor Editor;
205 struct _Editor {
206         gchar *name;
207         gchar *command;
208 };
209
210 struct _ImageLoader
211 {
212         GdkPixbuf *pixbuf;
213         FileData *fd;
214         gchar *path;
215
216         gint bytes_read;
217         gint bytes_total;
218
219         gint preview;
220
221         gint requested_width;
222         gint requested_height;
223         gint shrunk;
224
225         gint done;
226         gint idle_id;
227         gint idle_priority;
228
229         GdkPixbufLoader *loader;
230
231         void (*func_area_ready)(ImageLoader *, guint x, guint y, guint w, guint h, gpointer);
232         void (*func_error)(ImageLoader *, gpointer);
233         void (*func_done)(ImageLoader *, gpointer);
234         void (*func_percent)(ImageLoader *, gdouble, gpointer);
235
236         gpointer data_area_ready;
237         gpointer data_error;
238         gpointer data_done;
239         gpointer data_percent;
240
241         gint idle_done_id;
242
243         guchar *mapped_file;
244         gint read_buffer_size;
245         gint idle_read_loop_count;
246 };
247
248 typedef void (* ThumbLoaderFunc)(ThumbLoader *tl, gpointer data);
249
250 struct _ThumbLoader
251 {
252         gint standard_loader;
253
254         ImageLoader *il;
255         FileData *fd;           /* fd->pixbuf contains final (scaled) image when done */
256
257         gint cache_enable;
258         gint cache_hit;
259         gdouble percent_done;
260
261         gint max_w;
262         gint max_h;
263
264         ThumbLoaderFunc func_done;
265         ThumbLoaderFunc func_error;
266         ThumbLoaderFunc func_progress;
267
268         gpointer data;
269
270         gint idle_done_id;
271 };
272
273 struct _CollectInfo
274 {
275         FileData *fd;
276         GdkPixbuf *pixbuf;
277         guint flag_mask;
278 };
279
280 struct _CollectionData
281 {
282         gchar *path;
283         gchar *name;
284         GList *list;
285         SortType sort_method;
286
287         ThumbLoader *thumb_loader;
288         CollectInfo *thumb_info;
289
290         void (*info_updated_func)(CollectionData *, CollectInfo *, gpointer);
291         gpointer info_updated_data;
292
293         gint ref;
294
295         /* geometry */
296         gint window_read;
297         gint window_x;
298         gint window_y;
299         gint window_w;
300         gint window_h;
301
302         /* contents changed since save flag */
303         gint changed;
304
305         GHashTable *existence;
306 };
307
308 struct _CollectTable
309 {
310         GtkWidget *scrolled;
311         GtkWidget *listview;
312         gint columns;
313         gint rows;
314
315         CollectionData *cd;
316
317         GList *selection;
318         CollectInfo *prev_selection;
319
320         CollectInfo *click_info;
321
322         GtkWidget *tip_window;
323         gint tip_delay_id;
324         CollectInfo *tip_info;
325
326         GdkWindow *marker_window;
327         CollectInfo *marker_info;
328
329         GtkWidget *status_label;
330         GtkWidget *extra_label;
331
332         gint focus_row;
333         gint focus_column;
334         CollectInfo *focus_info;
335
336         GtkWidget *popup;
337         CollectInfo *drop_info;
338         GList *drop_list;
339
340         gint sync_idle_id;
341         gint drop_idle_id;
342
343         gint show_text;
344 };
345
346 struct _CollectWindow
347 {
348         GtkWidget *window;
349         CollectTable *table;
350         GtkWidget *status_box;
351         GList *list;
352
353         GtkWidget *close_dialog;
354
355         CollectionData *cd;
356 };
357
358 typedef gint (* ImageTileRequestFunc)(ImageWindow *imd, gint x, gint y,
359                                       gint width, gint height, GdkPixbuf *pixbuf, gpointer);
360 typedef void (* ImageTileDisposeFunc)(ImageWindow *imd, gint x, gint y,
361                                       gint width, gint height, GdkPixbuf *pixbuf, gpointer);
362
363 struct _ImageWindow
364 {
365         GtkWidget *widget;      /* use this to add it and show it */
366         GtkWidget *pr;
367         GtkWidget *frame;
368
369         FileData *image_fd;
370
371         gint unknown;           /* failed to load image */
372
373         ImageLoader *il;        /* FIXME - image loader should probably go to FileData, but it must first support
374                                    sending callbacks to multiple ImageWindows in parallel */
375
376         gint has_frame;
377
378         /* top level (not necessarily parent) window */
379         gint top_window_sync;   /* resize top_window when image dimensions change */
380         GtkWidget *top_window;  /* window that gets title, and window to resize when 'fitting' */
381         gchar *title;           /* window title to display left of file name */
382         gchar *title_right;     /* window title to display right of file name */
383         gint title_show_zoom;   /* option to include zoom in window title */
384
385         gint completed;
386         ImageState state;       /* mask of IMAGE_STATE_* flags about current image */
387
388         void (*func_update)(ImageWindow *imd, gpointer data);
389         void (*func_complete)(ImageWindow *imd, gint preload, gpointer data);
390         void (*func_state)(ImageWindow *imd, ImageState state, gpointer data);
391         ImageTileRequestFunc func_tile_request;
392         ImageTileDisposeFunc func_tile_dispose;
393
394         gpointer data_update;
395         gpointer data_complete;
396         gpointer data_state;
397         gpointer data_tile;
398
399         /* button, scroll functions */
400         void (*func_button)(ImageWindow *, GdkEventButton *event, gpointer);
401         void (*func_drag)(ImageWindow *, GdkEventButton *event, gdouble dx, gdouble dy, gpointer);
402         void (*func_scroll)(ImageWindow *, GdkEventScroll *event, gpointer);
403
404         gpointer data_button;
405         gpointer data_drag;
406         gpointer data_scroll;
407
408         /* scroll notification (for scroll bar implementation) */
409         void (*func_scroll_notify)(ImageWindow *, gint x, gint y, gint width, gint height, gpointer);
410
411         gpointer data_scroll_notify;
412
413         /* collection info */
414         CollectionData *collection;
415         CollectInfo *collection_info;
416
417         /* color profiles */
418         gint color_profile_enable;
419         gint color_profile_input;
420         gint color_profile_screen;
421         gint color_profile_use_image;
422         gint color_profile_from_image;
423         gpointer cm;
424
425         AlterType delay_alter_type;
426
427         FileData *read_ahead_fd;
428         ImageLoader *read_ahead_il;
429
430         gint prev_color_row;
431
432         gint auto_refresh;
433
434         gint delay_flip;
435         gint orientation;
436         gint desaturate;
437
438         gint overlay_show_zoom; /* set to true if overlay is showing zoom ratio */
439 };
440
441 #define FILEDATA_MARKS_SIZE 6
442
443 struct _FileDataChangeInfo {
444         FileDataChangeType type;
445         gchar *source;
446         gchar *dest;
447         gint error;
448 };
449
450 struct _FileData {
451         gint magick;
452         gint type;
453         gchar *original_path; /* key to file_data_pool hash table */
454         gchar *path;
455         const gchar *name;
456         const gchar *extension;
457         gchar *collate_key_name;
458         gchar *collate_key_name_nocase;
459         gint64 size;
460         time_t date;
461         mode_t mode; /* this is needed at least for notification in view_dir because it is preserved after the file/directory is deleted */
462         guint marks;
463         GList *sidecar_files;
464         FileData *parent; /* parent file if this is a sidecar file, NULL otherwise */
465         FileDataChangeInfo *change; /* for rename, move ... */
466         GdkPixbuf *thumb_pixbuf;
467
468         GdkPixbuf *pixbuf; /* full-size image, only complete images, NULL during loading
469                               all FileData with non-NULL pixbuf are referenced by image_cache */
470
471         gint ref;
472         gint version; /* increased when any field in this structure is changed */
473         gint disable_grouping;
474
475         gint user_orientation;
476         gint exif_orientation;
477         
478         ExifData *exif;
479 };
480
481 struct _LayoutWindow
482 {
483         FileData *dir_fd;
484
485         /* base */
486
487         GtkWidget *window;
488
489         GtkWidget *main_box;
490
491         GtkWidget *group_box;
492         GtkWidget *h_pane;
493         GtkWidget *v_pane;
494
495         /* menus, path selector */
496
497         GtkActionGroup *action_group;
498         GtkUIManager *ui_manager;
499
500         GtkWidget *path_entry;
501
502         /* image */
503
504         LayoutLocation image_location;
505
506         ImageWindow *image;
507
508         ImageWindow *split_images[MAX_SPLIT_IMAGES];
509         ImageSplitMode split_mode;
510         gint active_split_image;
511
512         GtkWidget *split_image_widget;
513         GtkSizeGroup *split_image_sizegroup;
514
515         gint connect_zoom, connect_scroll;
516
517         /* tools window (float) */
518
519         GtkWidget *tools;
520         GtkWidget *tools_pane;
521
522         gint tools_float;
523         gint tools_hidden;
524
525         /* toolbar */
526
527         GtkWidget *toolbar;
528         gint toolbar_hidden;
529
530         GtkWidget *thumb_button;
531         gint thumbs_enabled;
532         gint marks_enabled;
533
534         /* dir view */
535
536         LayoutLocation dir_location;
537
538         ViewDir *vd;
539         GtkWidget *dir_view;
540
541         DirViewType dir_view_type;
542
543         /* file view */
544
545         LayoutLocation file_location;
546
547         ViewFile *vf;
548         FileViewType file_view_type;
549
550         GtkWidget *file_view;
551
552         SortType sort_method;
553         gint sort_ascend;
554
555         /* status bar */
556
557         GtkWidget *info_box;
558         GtkWidget *info_progress_bar;
559         GtkWidget *info_sort;
560         GtkWidget *info_color;
561         GtkWidget *info_status;
562         GtkWidget *info_details;
563         GtkWidget *info_zoom;
564
565         /* slide show */
566
567         SlideShowData *slideshow;
568
569         /* full screen */
570
571         FullScreenData *full_screen;
572
573         /* dividers */
574
575         gint div_h;
576         gint div_v;
577         gint div_float;
578
579         /* misc */
580
581         GtkWidget *utility_box;
582         GtkWidget *bar_sort;
583         GtkWidget *bar_exif;
584         GtkWidget *bar_info;
585
586         gint bar_sort_enabled;
587         gint bar_exif_enabled;
588         gint bar_info_enabled;
589
590         gint bar_exif_width;
591         gint bar_exif_advanced;
592         gint bar_info_width;
593 };
594
595 struct _ViewDir
596 {
597         DirViewType type;
598         gpointer info;
599
600         GtkWidget *widget;
601         GtkWidget *view;
602
603         FileData *dir_fd;
604
605         FileData *click_fd;
606
607         FileData *drop_fd;
608         GList *drop_list;
609         gint drop_scroll_id;
610
611         /* func list */
612         void (*select_func)(ViewDir *vd, const gchar *path, gpointer data);
613         gpointer select_data;
614
615         void (*dnd_drop_update_func)(ViewDir *vd);
616         void (*dnd_drop_leave_func)(ViewDir *vd);
617
618         LayoutWindow *layout;
619
620         GtkWidget *popup;
621
622         PixmapFolders *pf;
623 };
624
625 struct _ViewDirInfoList
626 {
627         GList *list;
628 };
629
630 struct _ViewDirInfoTree
631 {
632         gint drop_expand_id;
633         gint busy_ref;
634 };
635
636
637 struct _ViewFile
638 {
639         FileViewType type;
640         gpointer info;
641
642         GtkWidget *widget;
643         GtkWidget *listview;
644         GtkWidget *scrolled;
645         GtkWidget *filter;
646         GtkWidget *filter_check[FILEDATA_MARKS_SIZE];
647
648         FileData *dir_fd;
649         GList *list;
650
651         SortType sort_method;
652         gint sort_ascend;
653
654         /* func list */
655         void (*func_thumb_status)(ViewFile *vf, gdouble val, const gchar *text, gpointer data);
656         gpointer data_thumb_status;
657
658         void (*func_status)(ViewFile *vf, gpointer data);
659         gpointer data_status;
660
661         LayoutWindow *layout;
662
663         GtkWidget *popup;
664
665         /* thumbs updates*/
666         gint thumbs_running;
667         ThumbLoader *thumbs_loader;
668         FileData *thumbs_filedata;
669
670         /* marks */
671         gint marks_enabled;
672         gint active_mark;
673         gint clicked_mark;
674         
675         /* refresh */
676         gint refresh_idle_id;
677 };
678
679 struct _ViewFileInfoList
680 {
681         FileData *click_fd;
682         FileData *select_fd;
683
684         gint thumbs_enabled;
685
686         gint select_idle_id;
687 };
688
689 struct _IconData;
690
691 struct _ViewFileInfoIcon
692 {
693         /* table stuff */
694         gint columns;
695         gint rows;
696
697         GList *selection;
698         struct _IconData *prev_selection;
699
700         GtkWidget *tip_window;
701         gint tip_delay_id;
702         struct _IconData *tip_id;
703
704         struct _IconData *click_id;
705
706         struct _IconData *focus_id;
707         gint focus_row;
708         gint focus_column;
709
710         gint show_text;
711 };
712
713 struct _SlideShowData
714 {
715         ImageWindow *imd;
716
717         GList *filelist;
718         CollectionData *cd;
719         FileData *dir_fd;
720         LayoutWindow *layout;
721
722         GList *list;
723         GList *list_done;
724
725         FileData *slide_fd;
726
727         guint slide_count;
728         gint timeout_id;
729
730         gint from_selection;
731
732         void (*stop_func)(SlideShowData *, gpointer);
733         gpointer stop_data;
734
735         gint paused;
736 };
737
738 struct _FullScreenData
739 {
740         GtkWidget *window;
741         ImageWindow *imd;
742
743         GtkWidget *normal_window;
744         ImageWindow *normal_imd;
745
746         gint hide_mouse_id;
747         gint busy_mouse_id;
748         gint cursor_state;
749
750         gint saver_block_id;
751
752         void (*stop_func)(FullScreenData *, gpointer);
753         gpointer stop_data;
754 };
755
756 struct _PixmapFolders
757 {
758         GdkPixbuf *close;
759         GdkPixbuf *open;
760         GdkPixbuf *deny;
761         GdkPixbuf *parent;
762 };
763
764 struct _SecureSaveInfo {
765         FILE *fp; /**< file stream pointer */
766         gchar *file_name; /**< final file name */
767         gchar *tmp_file_name; /**< temporary file name */
768         gint err; /**< set to non-zero value in case of error */
769         gint secure_save; /**< use secure save for this file, internal use only */
770         gint preserve_perms; /**< whether to preserve perms, TRUE by default */
771         gint preserve_mtime; /**< whether to preserve mtime, FALSE by default */
772         gint unlink_on_error; /**< whether to remove temporary file on save failure, TRUE by default */
773 };
774
775
776 #endif