ae857e50b58690b7d76d0f37724b8d8bd3365414
[geeqie.git] / src / view-file.h
1 /*
2  * Copyright (C) 2008 - 2016 The Geeqie Team
3  *
4  * Author: Laurent Monin
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 #ifndef VIEW_FILE_H
22 #define VIEW_FILE_H
23
24 #include <ctime>
25 #include <functional>
26
27 #include <glib.h>
28 #include <gtk/gtk.h>
29
30 #include "typedefs.h"
31
32 struct FileData;
33 struct LayoutWindow;
34 struct ThumbLoader;
35
36 struct ViewFile
37 {
38         FileViewType type;      /**< @todo (xsdg): Turn this into a union (see VFLIST and VFICON). */
39
40         gpointer info;
41
42         GtkWidget *widget;
43         GtkWidget *listview;
44         GtkWidget *scrolled;
45         GtkWidget *filter;
46         GtkWidget *filter_check[FILEDATA_MARKS_SIZE];
47
48         struct {
49                 GtkWidget *combo;
50                 GtkWidget *frame;
51                 gint count;
52                 gint last_selected;
53                 gboolean case_sensitive;
54         } file_filter;
55
56         FileData *dir_fd;
57         GList *list;
58
59         SortType sort_method;
60         gboolean sort_ascend;
61         gboolean sort_case;
62
63         /* func list */
64         void (*func_thumb_status)(ViewFile *vf, gdouble val, const gchar *text, gpointer data);
65         gpointer data_thumb_status;
66
67         void (*func_status)(ViewFile *vf, gpointer data);
68         gpointer data_status;
69
70         LayoutWindow *layout;
71
72         GtkWidget *popup;
73
74         /* thumbs updates*/
75         gboolean thumbs_running;
76         ThumbLoader *thumbs_loader;
77         FileData *thumbs_filedata;
78
79         /* marks */
80         gboolean marks_enabled;
81         gint active_mark;
82         gint clicked_mark;
83
84         /* stars */
85         FileData *stars_filedata;
86         guint stars_id;
87
88         /* refresh */
89         guint refresh_idle_id; /**< event source id */
90         time_t time_refresh_set; /**< time when refresh_idle_id was set */
91
92         GList *editmenu_fd_list; /**< file list for edit menu */
93
94         guint read_metadata_in_idle_id;
95 };
96
97 struct ViewFileInfoList
98 {
99         FileData *click_fd;
100         FileData *select_fd;
101
102         gboolean thumbs_enabled;
103
104         guint select_idle_id; /**< event source id */
105 };
106
107 struct ViewFileInfoIcon
108 {
109         /* table stuff */
110         gint columns;
111         gint rows;
112
113         GList *selection;
114         FileData *prev_selection;
115
116         GtkWidget *tip_window;
117         guint tip_delay_id; /**< event source id */
118         FileData *tip_fd;
119
120         FileData *click_fd;
121
122         FileData *focus_fd;
123         gint focus_row;
124         gint focus_column;
125
126         gboolean show_text;
127 };
128
129 #define VFLIST(_vf_) ((ViewFileInfoList *)(_vf_->info))
130 #define VFICON(_vf_) ((ViewFileInfoIcon *)(_vf_->info))
131
132 const gint VIEW_FILE_COLUMN_POINTER = 0; // @todo Use inline constexpr in C++17
133
134 void vf_send_update(ViewFile *vf);
135
136 ViewFile *vf_new(FileViewType type, FileData *dir_fd);
137
138 void vf_set_status_func(ViewFile *vf, void (*func)(ViewFile *vf, gpointer data), gpointer data);
139 void vf_set_thumb_status_func(ViewFile *vf, void (*func)(ViewFile *vf, gdouble val, const gchar *text, gpointer data), gpointer data);
140
141 void vf_set_layout(ViewFile *vf, LayoutWindow *layout);
142
143 gboolean vf_set_fd(ViewFile *vf, FileData *fd);
144 gboolean vf_refresh(ViewFile *vf);
145 void vf_refresh_idle(ViewFile *vf);
146
147 void vf_thumb_set(ViewFile *vf, gboolean enable);
148 void vf_marks_set(ViewFile *vf, gboolean enable);
149 void vf_star_rating_set(ViewFile *vf, gboolean enable);
150 void vf_sort_set(ViewFile *vf, SortType type, gboolean ascend, gboolean case_sensitive);
151
152 guint vf_marks_get_filter(ViewFile *vf);
153 void vf_mark_filter_toggle(ViewFile *vf, gint mark);
154
155 guint vf_class_get_filter(ViewFile *vf);
156
157 GList *vf_selection_get_one(ViewFile *vf, FileData *fd);
158 GList *vf_pop_menu_file_list(ViewFile *vf);
159 GtkWidget *vf_pop_menu(ViewFile *vf);
160
161 FileData *vf_index_get_data(ViewFile *vf, gint row);
162 gint vf_index_by_fd(ViewFile *vf, FileData *in_fd);
163 guint vf_count(ViewFile *vf, gint64 *bytes);
164 GList *vf_get_list(ViewFile *vf);
165
166 guint vf_selection_count(ViewFile *vf, gint64 *bytes);
167 GList *vf_selection_get_list(ViewFile *vf);
168 GList *vf_selection_get_list_by_index(ViewFile *vf);
169 using ViewFileSelectionCallback = std::function<void(FileData *)>;
170 void vf_selection_foreach(ViewFile *vf, const ViewFileSelectionCallback &func);
171
172 void vf_select_all(ViewFile *vf);
173 void vf_select_none(ViewFile *vf);
174 void vf_select_invert(ViewFile *vf);
175 void vf_select_by_fd(ViewFile *vf, FileData *fd);
176 void vf_select_list(ViewFile *vf, GList *list);
177
178 void vf_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode);
179 void vf_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode);
180
181 void vf_refresh_idle_cancel(ViewFile *vf);
182 void vf_notify_cb(FileData *fd, NotifyType type, gpointer data);
183
184 void vf_thumb_update(ViewFile *vf);
185 void vf_thumb_cleanup(ViewFile *vf);
186 void vf_thumb_stop(ViewFile *vf);
187 void vf_read_metadata_in_idle(ViewFile *vf);
188 void vf_file_filter_set(ViewFile *vf, gboolean enable);
189 GRegex *vf_file_filter_get_filter(ViewFile *vf);
190
191 void vf_star_update(ViewFile *vf);
192 gboolean vf_stars_cb(gpointer data);
193 void vf_star_stop(ViewFile *vf);
194 void vf_star_cleanup(ViewFile *vf);
195
196 #endif /* VIEW_FILE_H */
197 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */