basic infrastructure for early error and dangerous operations checking
[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_DEST_EXISTS = 1 << 0,
155         CHANGE_ERROR_MASK  = (~0) << 1, /* the values below are fatal errors */
156         CHANGE_NO_PERM     = 1 << 1
157 } ChangeError;
158
159
160 #define MAX_SPLIT_IMAGES 4
161
162 typedef struct _ImageLoader ImageLoader;
163 typedef struct _ThumbLoader ThumbLoader;
164
165 typedef struct _CollectInfo CollectInfo;
166 typedef struct _CollectionData CollectionData;
167 typedef struct _CollectTable CollectTable;
168 typedef struct _CollectWindow CollectWindow;
169
170 typedef struct _ImageWindow ImageWindow;
171
172 typedef struct _FileData FileData;
173 typedef struct _FileDataChangeInfo FileDataChangeInfo;
174
175 typedef struct _LayoutWindow LayoutWindow;
176
177 typedef struct _ViewDir ViewDir;
178 typedef struct _ViewDirInfoList ViewDirInfoList;
179 typedef struct _ViewDirInfoTree ViewDirInfoTree;
180
181 typedef struct _ViewFile ViewFile;
182 typedef struct _ViewFileInfoList ViewFileInfoList;
183 typedef struct _ViewFileInfoIcon ViewFileInfoIcon;
184
185 typedef struct _SlideShowData SlideShowData;
186 typedef struct _FullScreenData FullScreenData;
187
188 typedef struct _PixmapFolders PixmapFolders;
189 typedef struct _Histogram Histogram;
190
191 typedef struct _SecureSaveInfo SecureSaveInfo;
192
193 typedef struct _ExifData ExifData;
194
195 typedef struct _Editor Editor;
196 struct _Editor {
197         gchar *name;
198         gchar *command;
199 };
200
201 struct _ImageLoader
202 {
203         GdkPixbuf *pixbuf;
204         FileData *fd;
205         gchar *path;
206
207         gint bytes_read;
208         gint bytes_total;
209
210         gint requested_width;
211         gint requested_height;
212         gint shrunk;
213
214         gint done;
215         gint idle_id;
216         gint idle_priority;
217
218         GdkPixbufLoader *loader;
219         gint load_fd;
220
221         void (*func_area_ready)(ImageLoader *, guint x, guint y, guint w, guint h, gpointer);
222         void (*func_error)(ImageLoader *, gpointer);
223         void (*func_done)(ImageLoader *, gpointer);
224         void (*func_percent)(ImageLoader *, gdouble, gpointer);
225
226         gpointer data_area_ready;
227         gpointer data_error;
228         gpointer data_done;
229         gpointer data_percent;
230
231         gint idle_done_id;
232
233         guchar *read_buffer;
234         gint read_buffer_size;
235         gint idle_read_loop_count;
236 };
237
238 typedef void (* ThumbLoaderFunc)(ThumbLoader *tl, gpointer data);
239
240 struct _ThumbLoader
241 {
242         gint standard_loader;
243
244         ImageLoader *il;
245         FileData *fd;           /* fd->pixbuf contains final (scaled) image when done */
246
247         gint cache_enable;
248         gint cache_hit;
249         gdouble percent_done;
250
251         gint max_w;
252         gint max_h;
253
254         ThumbLoaderFunc func_done;
255         ThumbLoaderFunc func_error;
256         ThumbLoaderFunc func_progress;
257
258         gpointer data;
259
260         gint idle_done_id;
261 };
262
263 struct _CollectInfo
264 {
265         FileData *fd;
266         GdkPixbuf *pixbuf;
267         guint flag_mask;
268 };
269
270 struct _CollectionData
271 {
272         gchar *path;
273         gchar *name;
274         GList *list;
275         SortType sort_method;
276
277         ThumbLoader *thumb_loader;
278         CollectInfo *thumb_info;
279
280         void (*info_updated_func)(CollectionData *, CollectInfo *, gpointer);
281         gpointer info_updated_data;
282
283         gint ref;
284
285         /* geometry */
286         gint window_read;
287         gint window_x;
288         gint window_y;
289         gint window_w;
290         gint window_h;
291
292         /* contents changed since save flag */
293         gint changed;
294
295         GHashTable *existence;
296 };
297
298 struct _CollectTable
299 {
300         GtkWidget *scrolled;
301         GtkWidget *listview;
302         gint columns;
303         gint rows;
304
305         CollectionData *cd;
306
307         GList *selection;
308         CollectInfo *prev_selection;
309
310         CollectInfo *click_info;
311
312         GtkWidget *tip_window;
313         gint tip_delay_id;
314         CollectInfo *tip_info;
315
316         GdkWindow *marker_window;
317         CollectInfo *marker_info;
318
319         GtkWidget *status_label;
320         GtkWidget *extra_label;
321
322         gint focus_row;
323         gint focus_column;
324         CollectInfo *focus_info;
325
326         GtkWidget *popup;
327         CollectInfo *drop_info;
328         GList *drop_list;
329
330         gint sync_idle_id;
331         gint drop_idle_id;
332
333         gint show_text;
334 };
335
336 struct _CollectWindow
337 {
338         GtkWidget *window;
339         CollectTable *table;
340         GtkWidget *status_box;
341         GList *list;
342
343         GtkWidget *close_dialog;
344
345         CollectionData *cd;
346 };
347
348 typedef gint (* ImageTileRequestFunc)(ImageWindow *imd, gint x, gint y,
349                                       gint width, gint height, GdkPixbuf *pixbuf, gpointer);
350 typedef void (* ImageTileDisposeFunc)(ImageWindow *imd, gint x, gint y,
351                                       gint width, gint height, GdkPixbuf *pixbuf, gpointer);
352
353 struct _ImageWindow
354 {
355         GtkWidget *widget;      /* use this to add it and show it */
356         GtkWidget *pr;
357         GtkWidget *frame;
358
359         FileData *image_fd;
360
361         gint unknown;           /* failed to load image */
362
363         ImageLoader *il;        /* FIXME - image loader should probably go to FileData, but it must first support
364                                    sending callbacks to multiple ImageWindows in parallel */
365
366         gint has_frame;
367
368         /* top level (not necessarily parent) window */
369         gint top_window_sync;   /* resize top_window when image dimensions change */
370         GtkWidget *top_window;  /* window that gets title, and window to resize when 'fitting' */
371         gchar *title;           /* window title to display left of file name */
372         gchar *title_right;     /* window title to display right of file name */
373         gint title_show_zoom;   /* option to include zoom in window title */
374
375         gint completed;
376         ImageState state;       /* mask of IMAGE_STATE_* flags about current image */
377
378         void (*func_update)(ImageWindow *imd, gpointer data);
379         void (*func_complete)(ImageWindow *imd, gint preload, gpointer data);
380         void (*func_state)(ImageWindow *imd, ImageState state, gpointer data);
381         ImageTileRequestFunc func_tile_request;
382         ImageTileDisposeFunc func_tile_dispose;
383
384         gpointer data_update;
385         gpointer data_complete;
386         gpointer data_state;
387         gpointer data_tile;
388
389         /* button, scroll functions */
390         void (*func_button)(ImageWindow *, GdkEventButton *event, gpointer);
391         void (*func_drag)(ImageWindow *, GdkEventButton *event, gdouble dx, gdouble dy, gpointer);
392         void (*func_scroll)(ImageWindow *, GdkEventScroll *event, gpointer);
393
394         gpointer data_button;
395         gpointer data_drag;
396         gpointer data_scroll;
397
398         /* scroll notification (for scroll bar implementation) */
399         void (*func_scroll_notify)(ImageWindow *, gint x, gint y, gint width, gint height, gpointer);
400
401         gpointer data_scroll_notify;
402
403         /* collection info */
404         CollectionData *collection;
405         CollectInfo *collection_info;
406
407         /* color profiles */
408         gint color_profile_enable;
409         gint color_profile_input;
410         gint color_profile_screen;
411         gint color_profile_use_image;
412         gint color_profile_from_image;
413         gpointer cm;
414
415         AlterType delay_alter_type;
416
417         FileData *read_ahead_fd;
418         ImageLoader *read_ahead_il;
419
420         gint prev_color_row;
421
422         gint auto_refresh;
423
424         gint delay_flip;
425         gint orientation;
426         gint desaturate;
427
428         gint overlay_show_zoom; /* set to true if overlay is showing zoom ratio */
429 };
430
431 #define FILEDATA_MARKS_SIZE 6
432
433 struct _FileDataChangeInfo {
434         FileDataChangeType type;
435         gchar *source;
436         gchar *dest;
437         gint error;
438 };
439
440 struct _FileData {
441         gint magick;
442         gint type;
443         gchar *original_path; /* key to file_data_pool hash table */
444         gchar *path;
445         const gchar *name;
446         const gchar *extension;
447         gchar *collate_key_name;
448         gchar *collate_key_name_nocase;
449         gint64 size;
450         time_t date;
451         guint marks;
452         GList *sidecar_files;
453         FileData *parent; /* parent file if this is a sidecar file, NULL otherwise */
454         FileDataChangeInfo *change; /* for rename, move ... */
455         GdkPixbuf *thumb_pixbuf;
456
457         GdkPixbuf *pixbuf; /* full-size image, only complete images, NULL during loading
458                               all FileData with non-NULL pixbuf are referenced by image_cache */
459
460         gint ref;
461         gint version; /* increased when any field in this structure is changed */
462         gint disable_grouping;
463
464         gint user_orientation;
465         gint exif_orientation;
466         
467         ExifData *exif;
468 };
469
470 struct _LayoutWindow
471 {
472         FileData *dir_fd;
473
474         /* base */
475
476         GtkWidget *window;
477
478         GtkWidget *main_box;
479
480         GtkWidget *group_box;
481         GtkWidget *h_pane;
482         GtkWidget *v_pane;
483
484         /* menus, path selector */
485
486         GtkActionGroup *action_group;
487         GtkUIManager *ui_manager;
488
489         GtkWidget *path_entry;
490
491         /* image */
492
493         LayoutLocation image_location;
494
495         ImageWindow *image;
496
497         ImageWindow *split_images[MAX_SPLIT_IMAGES];
498         ImageSplitMode split_mode;
499         gint active_split_image;
500
501         GtkWidget *split_image_widget;
502         GtkSizeGroup *split_image_sizegroup;
503
504         gint connect_zoom, connect_scroll;
505
506         /* tools window (float) */
507
508         GtkWidget *tools;
509         GtkWidget *tools_pane;
510
511         gint tools_float;
512         gint tools_hidden;
513
514         /* toolbar */
515
516         GtkWidget *toolbar;
517         gint toolbar_hidden;
518
519         GtkWidget *thumb_button;
520         gint thumbs_enabled;
521         gint marks_enabled;
522
523         /* dir view */
524
525         LayoutLocation dir_location;
526
527         ViewDir *vd;
528         GtkWidget *dir_view;
529
530         DirViewType dir_view_type;
531
532         /* file view */
533
534         LayoutLocation file_location;
535
536         ViewFile *vf;
537         FileViewType file_view_type;
538
539         GtkWidget *file_view;
540
541         SortType sort_method;
542         gint sort_ascend;
543
544         /* status bar */
545
546         GtkWidget *info_box;
547         GtkWidget *info_progress_bar;
548         GtkWidget *info_sort;
549         GtkWidget *info_color;
550         GtkWidget *info_status;
551         GtkWidget *info_details;
552         GtkWidget *info_zoom;
553
554         /* slide show */
555
556         SlideShowData *slideshow;
557
558         /* full screen */
559
560         FullScreenData *full_screen;
561
562         /* dividers */
563
564         gint div_h;
565         gint div_v;
566         gint div_float;
567
568         /* misc */
569
570         GtkWidget *utility_box;
571         GtkWidget *bar_sort;
572         GtkWidget *bar_exif;
573         GtkWidget *bar_info;
574
575         gint bar_sort_enabled;
576         gint bar_exif_enabled;
577         gint bar_info_enabled;
578
579         gint bar_exif_width;
580         gint bar_exif_advanced;
581         gint bar_info_width;
582 };
583
584 struct _ViewDir
585 {
586         DirViewType type;
587         gpointer info;
588
589         GtkWidget *widget;
590         GtkWidget *view;
591
592         FileData *dir_fd;
593
594         FileData *click_fd;
595
596         FileData *drop_fd;
597         GList *drop_list;
598         gint drop_scroll_id;
599
600         /* func list */
601         void (*select_func)(ViewDir *vd, const gchar *path, gpointer data);
602         gpointer select_data;
603
604         void (*dnd_drop_update_func)(ViewDir *vd);
605         void (*dnd_drop_leave_func)(ViewDir *vd);
606
607         LayoutWindow *layout;
608
609         GtkWidget *popup;
610
611         PixmapFolders *pf;
612 };
613
614 struct _ViewDirInfoList
615 {
616         GList *list;
617 };
618
619 struct _ViewDirInfoTree
620 {
621         gint drop_expand_id;
622         gint busy_ref;
623 };
624
625
626 struct _ViewFile
627 {
628         FileViewType type;
629         gpointer info;
630
631         GtkWidget *widget;
632         GtkWidget *listview;
633
634         FileData *dir_fd;
635         GList *list;
636
637         SortType sort_method;
638         gint sort_ascend;
639
640         /* func list */
641         void (*func_thumb_status)(ViewFile *vf, gdouble val, const gchar *text, gpointer data);
642         gpointer data_thumb_status;
643
644         void (*func_status)(ViewFile *vf, gpointer data);
645         gpointer data_status;
646
647         LayoutWindow *layout;
648
649         GtkWidget *popup;
650
651         /* thumbs updates*/
652         gint thumbs_running;
653         ThumbLoader *thumbs_loader;
654         FileData *thumbs_filedata;
655
656         /* marks */
657         gint marks_enabled;
658         gint active_mark;
659         gint clicked_mark;
660         
661         /* refresh */
662         gint refresh_idle_id;
663 };
664
665 struct _ViewFileInfoList
666 {
667         FileData *click_fd;
668         FileData *select_fd;
669
670         gint thumbs_enabled;
671
672         gint select_idle_id;
673 };
674
675 struct _IconData;
676
677 struct _ViewFileInfoIcon
678 {
679         /* table stuff */
680         gint columns;
681         gint rows;
682
683         GList *selection;
684         struct _IconData *prev_selection;
685
686         GtkWidget *tip_window;
687         gint tip_delay_id;
688         struct _IconData *tip_id;
689
690         struct _IconData *click_id;
691
692         struct _IconData *focus_id;
693         gint focus_row;
694         gint focus_column;
695
696         gint show_text;
697 };
698
699 struct _SlideShowData
700 {
701         ImageWindow *imd;
702
703         GList *filelist;
704         CollectionData *cd;
705         FileData *dir_fd;
706         LayoutWindow *layout;
707
708         GList *list;
709         GList *list_done;
710
711         FileData *slide_fd;
712
713         guint slide_count;
714         gint timeout_id;
715
716         gint from_selection;
717
718         void (*stop_func)(SlideShowData *, gpointer);
719         gpointer stop_data;
720
721         gint paused;
722 };
723
724 struct _FullScreenData
725 {
726         GtkWidget *window;
727         ImageWindow *imd;
728
729         GtkWidget *normal_window;
730         ImageWindow *normal_imd;
731
732         gint hide_mouse_id;
733         gint busy_mouse_id;
734         gint cursor_state;
735
736         gint saver_block_id;
737
738         void (*stop_func)(FullScreenData *, gpointer);
739         gpointer stop_data;
740 };
741
742 struct _PixmapFolders
743 {
744         GdkPixbuf *close;
745         GdkPixbuf *open;
746         GdkPixbuf *deny;
747         GdkPixbuf *parent;
748 };
749
750 struct _SecureSaveInfo {
751         FILE *fp; /**< file stream pointer */
752         gchar *file_name; /**< final file name */
753         gchar *tmp_file_name; /**< temporary file name */
754         gint err; /**< set to non-zero value in case of error */
755         gint secure_save; /**< use secure save for this file, internal use only */
756         gint preserve_perms; /**< whether to preserve perms, TRUE by default */
757         gint preserve_mtime; /**< whether to preserve mtime, FALSE by default */
758         gint unlink_on_error; /**< whether to remove temporary file on save failure, TRUE by default */
759 };
760
761
762 #endif